Kikto
Kikto

Reputation: 61

Possibilities of calling an android JNI function

I've extracted .so native JNI library from an android app that I've downloaded.

I have the following questions:

  1. If the JNI is compiled for x86, Is it possible (somehow) to call functions in the library from C code on linux?

  2. If the JNI is compiled for x86, is it possible (somehow) to execute functions from the library from linux (not android)?

  3. Is it possible to call functions from the .so from my android app and not only from the original app? Another way to phrase the question: in general is a dependency exist between a specific android app and its JNI library?

Thanks.

Upvotes: 0

Views: 128

Answers (1)

Botje
Botje

Reputation: 30817

Yes, you can transplant JNI libraries to a different environment. You simply start a JVM with a custom class that loads the library. However, there some very important caveats:

  • the architecture of the library must match that of the JVM. So you need a 32-bit intel JVM.
  • any native libraries that the JNI library links to must be present as well. And their dependencies.
  • any Java classes that the JNI library depends on must be present in your new environment as well. You can provide your own or 'acquire' the original implementation. This will mostly be a problem if the library uses Android-specific Java classes.

It is theoretically possible to do all of this without a running JVM, but you would be reimplementing a large part of a JVM anyway so it is not worth the trouble.

Upvotes: 1

Related Questions