簡體   English   中英

x86-64 匯編代碼未運行

[英]x86-64 Assembly code not running

我是組裝新手。 我試圖通過參考一本名為“編寫安全工具和漏洞利用”的書來學習。 任何熟悉這本書的人都知道匯編代碼是為 32 位編寫的,但我是在 64 位系統上構建的。

因此,我重寫了代碼以在 64 位上運行。 成功編譯代碼后,當我嘗試運行程序時未完成所需的輸出。 相反,我沒有收到任何輸出。

我正在 AMD64 Debian Linux 系統上構建它。 這是我試圖從以下位置接收輸出的代碼:

global _start
_start:
xor             rax,rax

jmp short string
code:
pop             rsi
push byte       15
push            rsi
push byte       1
mov             al,4
push            rax
int             0x80

xor             rax,rax
push            rax
push            rax
mov             al,1
int             0x80

string:
call code
db  'Hello, world !',0x0a

我使用以下命令編譯它

$> nasm -f elf64 hello.asm $> ld -s -o hello hello.o

當我嘗試運行時沒有輸出。

關於我哪里出錯的任何建議?

您的代碼中主要存在一個大問題,您似乎認為系統調用通過int 0x80的調用約定(傳遞參數)是通過將其壓入堆棧來傳遞的。 但是,實際上,您需要查看寄存器eaxebxecx (有關更多詳細信息,請參見此處)。

因此,編寫代碼的正確方法是:

global _start
_start:
xor             rax,rax

jmp short string
code:
pop           rsi
mov           rdx, 15   
mov             rcx, rsi
mov             rbx, 1
mov             al,4
int             0x80

xor             rax,rax
mov             rbx, rax
mov             al,1
int             0x80

string:
call code
db  'Hello, world !',0x0a

然后,只需執行以下操作:

$> nasm -f elf64 hello.asm
$> gcc -nostdlib -o hello hello.o

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM