Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load library in Smali

Tags:

android

smali

If you put the library along the path file.apk:/lib/(arm64-v8a|x86|etc.)/libsun.so then it can be loaded using the following code:

const-string v0, "sun"
invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V

How can I load a library from file.apk:/assets/libsun.so?

like image 624
Noner Avatar asked Feb 18 '26 07:02

Noner


1 Answers

The simple answer is you can't. The loadlibrary implementation requires a file from the file-system. Normally all the ABI matching lib folder is extracted when the APK file is installed so all libraries are present in file-system and can be directly loaded.

Therefore you have to save the context to a file in file-system and then load this file using System.loadLibrary.

The only exception are libraries of apps that have the AndroidManifest.xml setting android:extractNativeLibs=false. In that case the libraries from lib/(arm64-v8a|x86|etc.) are stored without compression in the APK and aligned to 4K pages so that these libraries can directly be loaded from within the APK (the APK file is loaded as regular file and then starting from a certain offset the library data can be directly loaded without so this way totally ignores that the library is inside a ZIP file). But again you can't specify the path within the APK so that this is no help in your situation.

like image 126
Robert Avatar answered Feb 19 '26 21:02

Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!