组装显示很多重复代码?

发布于 2025-02-03 06:41:55 字数 1471 浏览 2 评论 0原文

因此,我正在研究一些二进制以组装到C ++代码。这是为了一个项目。

当我拆卸二进制文件时,我会得到很多重复的装配代码,但我不确定它在做什么。几乎就像它只是指着它正在下降。

   0x0000000000000000 <+0>:     push   %rbp
   0x0000000000000001 <+1>:     mov    %rsp,%rbp
   0x0000000000000004 <+4>:     lea    0x0(%rip),%rsi        # 0xb <main+11>
   0x000000000000000b <+11>:    lea    0x0(%rip),%rdi        # 0x12 <main+18>
   0x0000000000000012 <+18>:    callq  0x17 <main+23>
   0x0000000000000017 <+23>:    callq  0x1c <main+28>
   0x000000000000001c <+28>:    mov    %eax,0x0(%rip)        # 0x22 <main+34>
   0x0000000000000022 <+34>:    mov    0x0(%rip),%eax        # 0x28 <main+40>
   0x0000000000000028 <+40>:    cmp    $0x1,%eax
   0x000000000000002b <+43>:    je     0x40 <main+64>
   0x000000000000002d <+45>:    lea    0x0(%rip),%rsi        # 0x34 <main+52>
   0x0000000000000034 <+52>:    lea    0x0(%rip),%rdi        # 0x3b <main+59>
   0x000000000000003b <+59>:    callq  0x40 <main+64>
   0x0000000000000040 <+64>:    mov    0x0(%rip),%eax        # 0x46 <main+70>
   0x0000000000000046 <+70>:    cmp    $0x1,%eax

因此,重复代码是“ lea”和“ callq”。根据我阅读的方式,它只是指向下一行。例如,第一个LEA以#0xB&lt; main+11&gt;结束。这是其下方的线,一个指向其下方的线,依此类推。谁能帮助我看的东西?

该项目中至少有一百个行,所以我不是在寻找免费的A,我只需要帮助理解。

编辑:我正在使用一个.o文件,而无需访问原始.CPP文件,任务是使用GDB并祝福我读取汇编输出并将其重新集结到一个与原始代码相同的.cpp文件中。

So I'm working on some binary to assembly to c++ code. It's for a project.

When I disassemble the binary I'm getting a lot of repeating assembly code and I'm not sure what it's doing. It's almost like it's just pointing it's way down.

   0x0000000000000000 <+0>:     push   %rbp
   0x0000000000000001 <+1>:     mov    %rsp,%rbp
   0x0000000000000004 <+4>:     lea    0x0(%rip),%rsi        # 0xb <main+11>
   0x000000000000000b <+11>:    lea    0x0(%rip),%rdi        # 0x12 <main+18>
   0x0000000000000012 <+18>:    callq  0x17 <main+23>
   0x0000000000000017 <+23>:    callq  0x1c <main+28>
   0x000000000000001c <+28>:    mov    %eax,0x0(%rip)        # 0x22 <main+34>
   0x0000000000000022 <+34>:    mov    0x0(%rip),%eax        # 0x28 <main+40>
   0x0000000000000028 <+40>:    cmp    $0x1,%eax
   0x000000000000002b <+43>:    je     0x40 <main+64>
   0x000000000000002d <+45>:    lea    0x0(%rip),%rsi        # 0x34 <main+52>
   0x0000000000000034 <+52>:    lea    0x0(%rip),%rdi        # 0x3b <main+59>
   0x000000000000003b <+59>:    callq  0x40 <main+64>
   0x0000000000000040 <+64>:    mov    0x0(%rip),%eax        # 0x46 <main+70>
   0x0000000000000046 <+70>:    cmp    $0x1,%eax

So the repeating code is the "lea" and "callq". Based on the way I'm reading it, it's just pointing to the next line down. For example, the first lea ends with #0xb <main+11> which is the line right below it, and that one points to the line below it, and so on. Can anyone help with what I'm looking at?

There's at least a hundred extra lines in the project, so I'm not looking for a free A, I just need help understanding.

Edit: I am working with a .o file without access to the original .cpp file and the task is to use GDB and Bless to help me read the Assembly output and reassemble it into a .cpp file that works the same as the original code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2025-02-10 06:41:55

,重复代码是“ lea”和“ callq”。

地址表明您是在拆卸.o文件,而不是可执行文件(您应该始终在询问其输出时显示您使用的命令)。

尝试objdump -dr foo.o而不是 - 图片应该变得更加清晰。

无论如何,PS GDB并不是真正查看.o文件的正确工具。

更新:

我尝试了objdump -dr project1.o,并获得了几乎相同的输出

看起来更接近:它是不是相同的输出。 objdump将显示重新信号,其中显示他call实际上将转到位置。

您还应该能够将project1.o链接到可执行文件中(例如gcc project1.o -o project1),然后运行gdb project1然后disas main。您会看到 拆卸更有意义,并且与objdump的输出匹配。

So the repeating code is the "lea" and "callq".

The addresses suggest that you are disassembling .o file, not an executable (you should always show the command you used when asking about its output).

Try objdump -dr foo.o instead -- the picture should become much clearer.

P.S. GDB isn't really the right tool for looking at .o files anyway.

Update:

I tried the objdump -dr Project1.o and got pretty much the same output

Look closer: it's not the same output. objdump will display relocations, which show where he CALL will actually go to.

You should also be able to link Project1.o into an executable (something like gcc Project1.o -o Project1), and run gdb Project1 and then disas main. You will see that that disassembly makes more sense, and also matches the output of objdump.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文