如何在反汇编代码中扩展一个函数?

huangapple go评论81阅读模式
英文:

How to extend a function in dissembled code?

问题

如何在IDA(PRO 7.5 SP3)中扩展函数的代码?我想在反汇编代码中添加一些新指令到现有函数中。我知道有一个“更改函数结束”选项(快捷键E),但问题是,在函数代码之后立即有另一个函数代码,所以扩展所讨论的函数时,我只是覆盖了一些现有的可能很重要的代码。

我附上了所讨论代码的截图:

如何在反汇编代码中扩展一个函数?

所以我是否正确地认为解决方案是首先在函数结束之前的代码中“制造”一些自由空间(稍微移动后续函数旁边的所有代码),然后通过修补添加一些新指令。但如何,正如我所说,“制造”这些新指令的自由空间?

谢谢帮助。

附言:

如果问题有点初级,对不起,但我是这个主题的新手。

英文:

How can I extend/expand the code of a function in the IDA (PRO 7.5 SP3)? I'd like to add some new instructions to the existing function in the disassemble code. I know, that there is a change function end option (hotkey E) but the problem is that immediately after the function code there is another function code so expanding the function in question i'm just overwriting some existing and potentially important code.

I'm attaching the screenshot of the code in question:

如何在反汇编代码中扩展一个函数?

So am i right that the solution here would be to first "make" some free space in the code just before the function end (moving a bit all the later code, next to the function) and only then add some new instruction by patching. But how to, as I said "make" this free space for the new instructions?

Thx for help.

P.S.

Sorry if the question is a maybe bit lame but i'm a newbie in the topic.

答案1

得分: 2

通常的做法是在代码的其他地方找到一些空闲空间,并设置一个跳转指令。

然而,在这里有一些可用的空间,可以通过压缩现有代码并删除不必要的安全检查来腾出空间。

从401067开始,覆盖为:

    401067 xor eax, eax
    401069 leave
    40106a ret

这样剩下40106b - 401087可用,共29字节。

英文:

The usual approach is to find some free space elsewhere in the code and put a jump to it.

However, there is a bit of space available here by compacting the existing code and removing the unnecessary security check.

Starting at 401067, overwrite with

    401067 xor eax, eax
    401069 leave
    40106a ret

That leaves 40106b - 401087 available, which is 29 bytes.

答案2

得分: 1

这个函数非常简单,你可以重新编写整个内容以使用26字节:

401040 推入636261h
401045 将eax,esp
401047 推入0eh
401049 推入eax
40104a 推入偏移_Format
40104f 调用_printf
401054 异或eax,eax
401056 增加esp,16
401059 返回

然后你还有46字节可用。

英文:

This function is so simple, you can rewrite the whole thing to use 26 bytes:

401040 push 636261h
401045 mov eax, esp
401047 push 0eh
401049 push eax
40104a push offset _Format
40104f call _printf
401054 xor eax, eax
401056 add esp, 16
401059 ret

Then you have 46 bytes available.

huangapple
  • 本文由 发表于 2023年7月24日 19:25:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定