Radare2 - 插入 asm 指令而不覆盖

逆向工程 拆卸 x86 雷达2 小精灵 修补
2021-07-11 15:54:35

为了在 Linux 上修补 x86 elf 文件,我正在努力将特定的汇编指令插入二进制文件而不覆盖任何预先存在的指令。

我一直在阅读关于这个问题的相当广泛的 Radare2 文档,到目前为止,没有发现文档中描述的命令(wa, wo, wexi可视模式下,甚至在可视化汇编器中)让我有能力执行它。
所有这些命令实际上都会覆盖位于写入新指令的偏移量处的指令。

知道mov我计划插入指令最多占用8 个字节,因此我通过r2命令相应地扩展了二进制文件的大小

r+ 8

我的目标是在目标偏移量处移动所有指令,以便为指令插入“腾出空间”,但找不到任何完成工作的命令。

这是我的目标的典型示例:

原始二进制转储的一部分:

0x0804848a    c745f8000000.  mov dword [local_8h], 0                                                                                    
0x08048491    c745f4000000.  mov dword [local_ch], 0                                                                                    
0x08048498    8b4508         mov eax, dword [arg_8h]
0x0804849b    890424         mov dword [esp], eax                                                                                       
0x0804849e    e8e1feffff     call sym.imp.strlen        

修补后的二进制转储:

0x0804848a    c745f8000000.  mov dword [local_8h], 0                                                                                   
0x08048491    c745f4000000.  mov dword [local_ch], 0                                                                                   
0x08048498    c745fc000000.  mov dword [local_4h], 0   ; inserted instruction                                                                           
0x0804849f    8b4508         mov eax, dword [arg_8h]   ; following instructions get shifted from here
0x08048492    890424         mov dword [esp], eax                                                                                      
0x08048495    e8e1feffff     call sym.imp.strlen  

这甚至可能吗?

1个回答

在插入一些汇编指令之前,有时您必须放大.text 部分。尝试如下:

oo+  ; reopen file with write permission
iO r/.text/biggersize ; biggersize = size of section..text + 8
s 0x08048498
wen 8
wx c745fc000000