Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert instruction in the binary #5

Open
winter2020 opened this issue Nov 21, 2018 · 1 comment
Open

Insert instruction in the binary #5

winter2020 opened this issue Nov 21, 2018 · 1 comment

Comments

@winter2020
Copy link

winter2020 commented Nov 21, 2018

Could this tool insert some instruction for example nop in the specific addresses without any other unnecessary modification of the binary? Could you show some example code?

@utds3lab
Copy link
Owner

utds3lab commented Dec 5, 2018

Apologies for the late reply.

It is possible to insert nop at specific locations in the code. However, Multiverse is designed in a way that it is not possible to only modify a subset of the code.

If you only want to replace certain instructions in a binary with nops, it would be better to write a simple script that patches those bytes in a binary. This approach shouldn't require any special tools (besides readelf to identify section offsets) as long as you have already identified the addresses you want to replace beforehand.

If instead you wish to insert nops in between currently existing instructions, you have the challenge that you are shifting code and therefore changing code offsets in a binary, which means everything after the inserted nops is at a different offset than in the original binary. In this case, a rewriter needs to handle references to code locations, either via offsets or absolute addresses. In Multiverse, this isn't a problem because we are rewriting everything and we translate code references at the point they are used in the rewritten code.

If you still wish to use Multiverse to insert nops, a simple example that inserts a nop before every instruction can be found here. In order to only insert nops before certain instructions, the count_instruction function only needs to be changed to check whether the instruction passed to it is at one of the desired addresses. Something like:

template = 'nop'
addresses = [<addresses you want>]
if inst.address in addresses:
  return _asm(template)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants