0

I am using some DLL files in my Java application using JNI library.

The dlls are not written by me and I do not have access to their source codes. They are so buggy and throw lots of exceptions. Needless to say that they are making my java application unstable since unhandled exceptions in native side crash the java application.

I was thinking to reverse engineer the dll files and add some try and catch clause there or maybe just find the culprit line and add some prevention there.

The exceptions are mainly due to dereferencing a null pointer which I believe I can fix them by a couple of instructions (cmp and jmp)

So what I am trying to ask are as follow:

  1. Is it practically doable?
  2. Is IDA the right tool to do so?

Edit : Another solution that I am guessing could fix the problem is to write a new native class and wrap all native functions that i am using in the new functions with error handling. But I have a lot of native functions and this solution could be tedious and cumbersome. So, still, reverse engineering DLLs is my number one solution. Comments are really welcome. Please share your views.

  • Actually what you want could easily be done by writing your own DLL, simply making sure that the respective functions follow the same calling conventions and have the same prototypes (which can be deduced from the Java side of things) use that own DLL and make that load the third-party DLL and pass all calls through - but guarded. However, be warned that this will merely hide the problems, not fix them (neither would your desired solution, though). – 0xC0000022L Jul 9 at 16:24
  • The number of native functions correlates obviously with the details of your JNI interface. And that alone should make it relatively straightforward to come up with all necessary prototypes to wrap. No reverse engineering in the stricter sense required. If you want to patch the other DLL in-memory, that's also possible and that would of course require some RCE ... or at least debugging at assembly level. – 0xC0000022L Jul 10 at 8:53
  • @0xC0000022L Thanks, I think I should go with writing a new wrapper dll. And I am going to take a look at RCE, as I don’t know what it is :) – Iman Jul 10 at 15:00

Your Answer

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

Browse other questions tagged or ask your own question.