Replace old function with regenerated instructions #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
我们的进程(可能是动态库比较多?)mmap出来的位置至少比旧函数的地址大INT32_MAX,原代码中会限制32位的偏移。
这里设想一个方案,重新生成RIP relative的代码,如果原先地址范围过小不足以容纳hook后需要改变的,就重新生成64位的,用encoder的话可能会更符合汇编语法,如果更改偏移是不合法的,encode也会返回错误。
不过jne类似的指令,还是不能超过32位。这里是不是能够重新再生成这段指令,将jne的比较转为比较更复杂的,读取内存地址,再比较?上面的更改中只是简单将偏移范围改变。
测试代码里面我从libc里面找了几个满足lea,comp,mov RIP相对便宜的函数执行hook,跟以前的测试代码相比,还缺少了个jmp RIP。