在 CentOS 下使用反汇编指令,你需要安装一个汇编器/反汇编器,比如 nasm(Netwide Assembler)或 gas(GNU Assembler)。这里以 nasm 为例,介绍如何在 CentOS 下使用反汇编指令。
nasm:sudo yum update sudo yum 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 -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 可执行文件的反汇编代码。