Carol Ward
Carol Ward

Reputation: 731

How to track JNI method from Java to C?

So I'm trying to reverse engineer an application.

I'm tracking a JNI method called Test_Method that calls a C method from the shared object,

In the shared object, I can see that the method name Test_Method exists, but it doesn't have any cross-reference.

How do I find the method from the shared object that the JNI method from Java is calling to?

Upvotes: 1

Views: 431

Answers (2)

Alex Cohn
Alex Cohn

Reputation: 57173

Look for the list of exported functions of your DLL or so file. If it doesn't have a number of functions with Java_com… prefix, but has JNI_OnLoad instead, your native library then uses RegisterNatives(), and you must find the relevant table of JNINativeMethod structures that maps of the native methods to C functions.

Upvotes: 1

John Bollinger
John Bollinger

Reputation: 180181

The name of the native function that a corresponds to particular Java native method is deterministically related to the Java method name, the fully-qualified name of the class in which it resides, and its argument types if it is overloaded. The specifics are described in chapter 2 of the JNI specification, but rather than sorting through that, it might be easier to just use javac -h (JDK 8 or later) or the javah tool (deprecated since JDK 8, but still present at least in JDK 9) to generate it for you, in the form of a C or C++ header file.

Upvotes: 1

Related Questions