REAndroid / APKEditor

Powerful android apk editor - aapt/aapt2 independent
Apache License 2.0
645 stars 95 forks source link

dexlib2 cannot write code #89

Closed commonuserlol closed 3 months ago

commonuserlol commented 3 months ago

Describe the bug After small smali modifications (loadLibrary call insertion) dexlib2 crashes with exception

To Reproduce Steps to reproduce the behavior:

  1. Used version: 1.3.6
  2. Operating system: Linux
  3. Command: java -Xmx1G -jar ~/apkeditor.jar b -i /tmp/unpack

Log/Stacktrace

00.000 I: [BUILD] Building ...
   Input: /tmp/unpack
 Output: /tmp/unpack_out.apk
 ----------------------------
00.071 I: [BUILD] Scanning XML directory ...
00.145 I: [BUILD] Scanning: unpack
00.750 I: [BUILD] Initializing android framework ...
00.750 I: [BUILD] Loading android framework for version: 33
01.106 I: [BUILD] Initialized framework: android-33 (UpsideDownCake)
01.109 I: [BUILD] Encoding attrs ...
01.414 I: [BUILD] Encoding values ...
03.512 I: [BUILD] Scan: package_1/res
03.678 I: [BUILD] Scanned 1628 files: package_1/res
03.780 I: [BUILD] Add manifest: AndroidManifest.xml
03.781 I: [BUILD] Building dex ...
04.223 I: [BUILD] (1/7) Smali: classes.dex
Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Landroidx/annotation/InspectableProperty$ValueType;->values()[Landroidx/annotation/InspectableProperty$ValueType;
    at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:1056)
    at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:353)
    at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:308)
    at org.jf.smali.Smali.assemble(Smali.java:93)
    at org.jf.smali.Smali.assemble(Smali.java:65)
    at com.reandroid.apkeditor.smali.SmaliCompiler.build(SmaliCompiler.java:88)
    at com.reandroid.apkeditor.smali.SmaliCompiler.build(SmaliCompiler.java:68)
    at com.reandroid.apkeditor.smali.SmaliCompiler.buildDexFiles(SmaliCompiler.java:60)
    at com.reandroid.apk.ApkModuleEncoder.encodeDexFiles(ApkModuleEncoder.java:143)
    at com.reandroid.apk.ApkModuleEncoder.scanDirectory(ApkModuleEncoder.java:45)
    at com.reandroid.apkeditor.compile.Builder.buildXml(Builder.java:116)
    at com.reandroid.apkeditor.compile.Builder.run(Builder.java:47)
    at com.reandroid.apkeditor.compile.Builder.execute(Builder.java:176)
    at com.reandroid.apkeditor.Main.execute(Main.java:85)
    at com.reandroid.apkeditor.Main.execute(Main.java:64)
    at com.reandroid.apkeditor.Main.main(Main.java:36)
Caused by: org.jf.util.ExceptionWithContext: Error while writing instruction at code offset 0x2
    at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1329)
    at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:1052)
    ... 15 more
Caused by: org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65536
    at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116)
    at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:364)
    at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1289)
    ... 16 more

Used apk file https://apkcombo.com/race-master-3d-car-racing/com.easygames.race/download/apk (just apk, not xapk)

Additional context Both apktool and apkeditor crashing on this