2014-12-31 36 views
1

我正在學習由Jeff Duntemann編寫的書:逐步裝配。下面是提供的源代碼:無法訪問內存0xe,Ubuntu上的kdbg

SECTION .data   ; Section containing initialised data 

    EatMsg: db "Eat at Joe's!",10 
    EatLen: equ $-EatMsg  

SECTION .bss   ; Section containing uninitialized data 

SECTION .text   ; Section containing code 

global _start   ; Linker needs this to find the entry point! 

_start: 
    nop   ; This no-op keeps gdb happy... 
    mov eax,4  ; Specify sys_write call 
    mov ebx,1  ; Specify File Descriptor 1: Standard Output 
    mov ecx,EatMsg  ; Pass offset of the message 
    mov edx,EatLen  ; Pass the length of the message 
    int 80H   ; Make kernel call 

    MOV eax,1  ; Code for Exit Syscall 
    mov ebx,0  ; Return a code of zero 
    int 80H   ; Make kernel call 

我的Ubuntu 12.04在64位的MacOS約塞米蒂的頂部上VirtualBoxVM運行32位。

我打電話:

kdbg eatsyscall 

推出工具KDbg。

手錶部分我有2種表現形式:EatMsgEatLen

當我運行使用工具KDbg爲EatMsg我看到代碼:但EatLen我看到:不能訪問存儲器在0xe

我有2個問題:

這是什麼544497989 v和爲什麼EatLen我看到「無法訪問」消息?

回答

3

544497989EatMsg的地址,它只是內存位置,即一些巨大的數字。如果你知道C或C++,它是&eatMsg的等價的,如果你的聲明是char * eatMsg = "Eat at Joe's!";

EatLenEatMsg長度:$代表「在這一點上的地址」,這是EatMsg所有字節後的下一個位置。所以$-EatMsg是「EatMsg的所有字節後面的地址減去EatMsg開頭的地址」=「EatMsg的長度」= 14十進制= 0x0E十六進制。

您的調試器可能會將此長度解釋爲地址。像這些小值不能作爲地址引用。你應該僅僅把它作爲一個值來顯示,而不是解釋爲地址。

+0

但544497989不是2的冪。地址不應該是2的冪? –

+0

根本沒有。對於某些數據和體系結構,需要2 *(或4或8)的*倍數,但對於'db'則不是這種情況。 – geert3

+1

實際上,以十六進制表示的544497989(十進制)是20746145h--空間的ASCII代碼,'t','a','E' - 由於多字節值被存儲爲「小端」,所以它顯示爲「向後」。如果您每次檢查一個字節,它將以「正確」的順序出現。 –