1

For a CTF I have a fairly slow recursive function. I just need to cached the previous results in a dictionary and get them instead. I did it but had to reverse engineer the code. I was wondering if there is a better solution.

LD_PRELOAD won't work as it is a static binary. If I could copy the assembly and call the function in a C program with asm I could get it done but is there a better solution or a way to patch the binary and create a function that caches the slow one? We could path the binary or use somethings to hook the function call.

2

You can definitely edit the binary and implement a new function that handles caching and calls the original function as needed. Then just replace any call to your new cache-implementing function instead. You'll need to be careful when implementing the cache for a recursive function and decide if you wanna cache all intermediate results or only final results.

If you're looking for a fast solution, though, you may want to consider using an emulator as a way of running that function's code inside your program. Either using Unicorn, any other emulator or even IDAs app call for function execution.

  • 1
    Thank you very much you got me on the right track. The easiest solution was to use Unicorn. I tried a lot and the other reasonable one was frida but I have yet to manage to get it working. This link helped me a lot: http://eternal.red/2018/unicorn-engine-tutorial/ – letFunny Feb 27 at 9:43
  • Glad I could help :) – NirIzr Feb 27 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.