简体   繁体   English

我可以将汇编语言命令和数据添加到现有二进制文件中吗?

[英]Can I add assembly language commands and data into an existing binary?

This question is mostly about my experience with Hopper - The OS X and Linux Disassembler although conceptually I think it would also apply to other Disassemblers like IDA . 这个问题主要是关于我在Hopper上的经验-OS X和Linux Disassembler,尽管从概念上讲,我认为它也适用于IDA等其他Disassembler。 The tools allow one to see the assembly code representation of the (hex) code that's in a binary file: 这些工具使您可以查看二进制文件中(十六进制)代码的汇编代码表示形式:

汇编代码表示

It also allows a way to modify the assembly instructions, such as replacing a je command with a jne command. 它还允许修改汇编指令的方法,例如用jne命令替换je命令。 They have a hex view , too, so it's easy to see what changes are actually happening - but from what I can tell, these are basically just a nice front-end for hex-editing - meaning I tell it to change JE to JNE and a 74 becomes a 75 . 它们也具有hex view ,因此很容易看到实际发生的更改-但据我所知,这些基本上只是十六进制编辑的一个不错的前端-意味着我告诉它将JE更改为JNE74变成75

However, Hopper has an option that says "Produce New Executable": 但是,Hopper的选项显示为“产生新的可执行文件”:

在此处输入图片说明

And the assembly editor dialog says "Assemble and Go Next": 程序集编辑器对话框中显示“ Assemble and Go Next”:

在此处输入图片说明

I think the answer to this question is "No" - but just so I understand - there isn't a way to add code to a assembled / compiled binary file, right? 我认为这个问题的答案是“否”-但据我了解-没有办法代码添加到已组装/已编译的二进制文件中,对吗? The rest of the commands saved into a compiled program are referencing file offsets to other sections - so it would not be possible to add additional commands into a procedure, because they would mess up the offset for commands that come afterwards - causing code that comes earlier to jmp to the wrong place and all sorts of bad things like right - right? 保存到已编译程序中的其余命令正在引用其他部分的文件偏移量-因此将不可能在过程中添加其他命令,因为它们会混淆随后出现的命令的偏移量-导致代码提前出现jmp错误的地方,以及各种对的坏事-对吗? Editing existing commands, NOOP s, changing strings, anything without changing the "footprint" of the program are OK - but not adding code - correct? 编辑现有命令, NOOP ,更改字符串,不更改程序“足迹”的任何操作都可以-但不能添加代码-对吗? The only way it seems like it might be possible to add code in would be at the very end of the file, but even then I'm somewhat doubtful that it would work. 似乎可以添加代码的唯一方法是在文件的末尾,但是即使那样,我仍然怀疑它是否可以工作。

Do I understanding the capabilities of disassemblers correctly, in that: They can show the code, and even give representations of the functions used to create them (sometimes) but they are not really compilers per se? 我是否正确地理解了反汇编程序的功能,即:它们可以显示代码,甚至可以提供用于创建它们的功能的表示(有时),但是它们本身并不是真正的编译器? Or, are they good enough to actually keep up with all the offsets / references and actually rewrite them and truly produce a new executable with additional code and strings injected right in the middle? 或者,它们是否足够好,可以跟上所有偏移量/引用并实际重写它们,并真正产生一个带有附加代码和字符串的新可执行文件?

ps: I apologize in advance if what I'm asking sounds malicious ( I don't think it does ) my goal is not to pirate software, but just to understand how programs are written, compiled, and interpreted. ps:如果要问的听起来是恶意的,我事先道歉(我认为不是),我的目标不是盗版软件,而只是了解程序的编写,编译和解释方式。 I'd like to eventually be able to write programs directly in assembly for ATMega chips, and as a beginner to assembly looking through existing programs has been far more interesting than reading tutorials online (although I'm doing both). 我希望最终能够直接在汇编中为ATMega芯片编写程序,而作为汇编的初学者,通过现有程序查看与在线阅读教程相比要有趣得多(尽管我同时做这两者)。

A disassembler like IDA can produce a source file of the executable. 像IDA这样的反汇编程序可以生成可执行文件的源文件。 However, in my experience this is not really working out of the box, so you can't simply disassemble a file and then reproduce the executable, without doing a lot of manual work. 但是,以我的经验来看,这并不是开箱即用的,因此您不能简单地反汇编文件然后重现可执行文件,而无需进行大量手动工作。 For complex programs, it is not guaranteed to have a full dissassemble either, because the disassembler may not recognize all of the code and data sections correctly. 对于复杂的程序,也不保证完全进行反汇编,因为反汇编器可能无法正确识别所有代码和数据段。 So before you can assemble the output, you have to do a lot of reverse engineering to make it work. 因此,在组装输出之前,必须进行大量的逆向工程才能使其正常工作。 Of course, once you made it work, you can add code as you want. 当然,一旦使它起作用,就可以根据需要添加代码。

Since IDA is very advanced, I don't think that Hopper can do it either. 由于IDA非常先进,因此我也不认为Hopper可以做到。

Depending on the kind of changes you need, it might be easier to inject the code in memory with a seperate application or replacing a library with your own version. 根据您需要的更改类型,使用单独的应用程序将代码注入内存中或用您自己的版本替换库可能会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM