在 Ubuntu 下使用反汇编指令,你需要安装一个汇编器/反汇编器,比如 nasm(Netwide Assembler)或 gas(GNU Assembler)。这里以 nasm 为例,介绍如何在 Ubuntu 下使用反汇编指令。
sudo apt update
nasm:sudo apt install nasm
hello.asm 的文件,包含以下内容:section .data
hello db 'Hello, World!', 0xa
section .text
global _start
_start:
mov edx, 13 ; message length
mov ecx, hello ; message to write
mov ebx, 1 ; file descriptor (stdout)
mov eax, 4 ; system call number (sys_write)
int 0x80 ; call kernel
mov eax, 1 ; system call number (sys_exit)
int 0x80 ; call kernel
这是一个简单的 “Hello, World!” 程序,使用 NASM 汇编语法编写。
nasm 反汇编文件:nasm -f elf32 hello.asm -o hello.o
这将生成一个名为 hello.o 的目标文件。
ld 链接目标文件:ld -m elf_i386 hello.o -o hello
这将生成一个名为 hello 的可执行文件。
./hello
你应该看到输出 “Hello, World!”。
如果你想查看反汇编后的代码,可以使用 objdump 命令:
objdump -d hello
这将显示 hello 可执行文件的反汇编代码。