5

I'd like to inject a jar library into an apk file to use it from smali code.

Here's what I did:

  1. Unpackaged the apk apktool d -f -r app-debug.apk
  2. Copied the jar file to the /libs directory of decompiled project
  3. Added the call to my library to the main activity on create hook like this:

    invoke-static {p0}, Lcom/example/injection/Inject;->test(Landroid/content/Context;)V
    
  4. Repacked the apk apktool b .

  5. Sign the generated apk using jarsigner
  6. Then I install the app from /dist/ dir using adb install app-debug.apk

The app installs sucessfuly, but instantly crashes. On each crash the logcat outputs following message:

4-14 00:37:45.397 3016-3162/? I/logserver: extract_appname, forward search, appname=com.example.ben.myapplication
04-14 00:37:45.397 3016-3162/? I/logserver: get_fault_appname, appname=com.example.ben.myapplication
04-14 00:37:45.400 3016-3161/? I/logserver: handle_notify_event, send msg [submit:trigger=0,bugtype=2,modulename=com.example.ben.myapplication,level=1,testtype=NORMAL,path=/data/log/unzip/ALE-L21_ALE-L21C432B584_0000000000_20180414003745_crash,mode=1;]
04-14 00:37:45.688 23691-23691/com.example.ben.myapplication I/Process: Sending signal. PID: 23691 SIG: 9

I run this on device , so I can't really access the crash report, but It's obviously because the com/example/injection/Inject is not found.

I've done injection before, but instead of adding jars I added the smali classes into the project, but I would like to try and add jar libs instead. Is there a way to do this?

Ben
  • 3,989
  • 9
  • 48
  • 84

1 Answers1

0

The libs folder is for native libraries, not for JAR files. JAR files contain .class files that can be executed in a desktop JRE, but not on Android, since Android uses a different byte code format. In order to run JRE byte code on Android, the DX compiler is used to generate DEX (Dalvik executable) files. If you want to inject the classes contained in the JAR file into an APK (and you've obtained SMALI IR code via apk-tool), you'll have to use DX to generate a dex file from the jar, then use the baksmali tool to generate smali files that you'll then have to integrate into the folder structure of the decompiled APK.

FD_
  • 12,947
  • 4
  • 35
  • 62