2

How do I import and use an .SO file that I extracted from apk file? I've used ctypes library in Linux but it gave me error on every way I tried it.

There are 2 version of the .so files: arm64, and armeabi. When i tried import the armeabi version, which is 32-bit, it gave me

wrong ELF class: ELFCLASS32

and so I try the arm64, and somehow I got

cannot open shared object file: No such file or directory

I can assure you it is not a typo path, I tried to copy it using the same path. but I cannot import it because no such file.

code:

import ctypes

def main():

     TestLib = ctypes.CDLL('/home/manalkaff/Desktop/arm64-v8a/nativelibrary.so')

if __name__ == '__main__':

     main()

Is this how I am supposed to do it? Or there is another way?

4

2 回答 2

2

You can try to decompile and port your shared object to x86. To do this you should load your binary in Ghidra and extract all the functions except utility ones like JNI initialization etc. which will be inserted by compiler automatically if required. Then rebuild using compiler and IDE of your choice like Clion + Clang. Not forget to fix some errors and switch to Windows API if Android API was used. This will require some time and effort though, depending on amount of functions and size of binary (except support stuff once again).

于 2020-08-18T13:32:13.673 回答
1

You can't load and execute ARM code on x86 CPU. You need a virtual machine that will emulate ARM CPU for that.

Even after loading the .so file on Linux ARM, you might still be missing some Android dependencies. Use ldd copied.so to see which.

于 2020-01-04T19:03:04.483 回答