【问题标题】:Disassembly a C code [closed]反汇编 C 代码 [关闭]
【发布时间】:2014-06-21 01:13:02
【问题描述】:

如何反汇编 C 代码?我已经在这里阅读了一些问题(stackoverflow)。但是如果你想反汇编你需要一个机器码,那么如何用 nasm 做到这一点?因此,如果我为 ex 创建。 C 中的 Hello World 怎么能做到这一点?

【问题讨论】:

  • 取决于您的 C 编译器。对于gcc,使用-S 标志。
  • 什么取决于编译器..啊,好吧

标签: c assembly nasm


【解决方案1】:

Nasm 是个坏主意。有几个选项。 IDA pro 给了我一些成功,但如果你真的了解你的程序集,你可以 nm 获取符号,然后从那里 hexdump 代码并手动将其组装出来。不过,真的不只是一种方法可以使用 nasm 来生成可重新编译的代码。

otool(或 objdump)将生成程序集。

如果你需要一些例子:这里:

#include <stdio.h>
main(argc, argv)
int argc; char * * argv;
{
    printf("Hello, World\n");
}

纳米输出:

hydrogen:tmp phyrrus9$ nm a.out
0000000100000000 T __mh_execute_header
0000000100000f40 T _main
                 U _printf
                 U dyld_stub_binder

otool 输出:

hydrogen:tmp phyrrus9$ otool -tv a.out
a.out:
(__TEXT,__text) section
_main:
0000000100000f40    pushq   %rbp
0000000100000f41    movq    %rsp, %rbp
0000000100000f44    subq    $0x10, %rsp
0000000100000f48    leaq    0x37(%rip), %rdi         ; this is our string
0000000100000f4f    movb    $0x0, %al
0000000100000f51    callq   0x100000f66              ; call printf
0000000100000f56    movl    $0x0, %ecx
0000000100000f5b    movl    %eax, 0xfffffffffffffffc(%rbp)
0000000100000f5e    movl    %ecx, %eax
0000000100000f60    addq    $0x10, %rsp
0000000100000f64    popq    %rbp
0000000100000f65    ret

hexdump 输出未显示。

实际组装:

hydrogen:tmp phyrrus9$ cat tmp.s
.section    __TEXT,__text,regular,pure_instructions
.globl  _main
.align  4, 0x90
_main:                                  ## @main
.cfi_startproc
## BB#0:
pushq   %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq    %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
subq    $16, %rsp
leaq    L_.str(%rip), %rdi
movb    $0, %al
callq   _printf
movl    $0, %ecx
movl    %eax, -4(%rbp)          ## 4-byte Spill
movl    %ecx, %eax
addq    $16, %rsp
popq    %rbp
ret
.cfi_endproc

.section    __TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
.asciz   "Hello, world!\n"


.subsections_via_symbols

希望这可以帮助您掌握。

【讨论】:

    猜你喜欢
    • 2016-12-22
    • 2012-01-24
    • 2011-05-04
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 2010-10-01
    • 2013-07-21
    • 1970-01-01
    相关资源
    最近更新 更多