Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception occurred while writing code_item for method return of #1834 - think its not #1718 #2496

Closed
beaumontk opened this issue Jan 15, 2021 · 8 comments

Comments

@beaumontk
Copy link

Information

  1. Apktool Version (apktool -version) - 2.5.0
  2. Operating System (Mac, Linux, Windows) - Windows 7
  3. APK From? (Playstore, ROM, Other) - https://bitbucket.org/iBotPeaches/apktool/downloads/

Stacktrace/Logcat

C:\kb\java_myApps\android\apktool_jadx\garmin_connect\apktool>"C:\Program Files\Java\jre1.8.0_181\bin\java.exe" -Xmx512m -jar C:\kb\apktool_2.3.4\apktool_2.5.0.jar -f b C:\kb\java_myApps\android\apktool_jadx\garmin_connect\apktool\Connect_v
4_38_1_b5720_SAP -o C:\kb\java_myApps\android\apktool_jadx\garmin_connect\apktool\KB_garmin_connect.apk
I: Using Apktool 2.5.0
I: Smaling smali folder into classes.dex...
Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Lk2/a/a/a/v/e/c;->values()[Lk2/a/a/a/v/e/c;
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:1046)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:345)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:300)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:61)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:36)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:420)
at brut.androlib.Androlib.buildSources(Androlib.java:351)
at brut.androlib.Androlib.build(Androlib.java:303)
at brut.androlib.Androlib.build(Androlib.java:270)
at brut.apktool.Main.cmdBuild(Main.java:259)
at brut.apktool.Main.main(Main.java:85)
Caused by: org.jf.util.ExceptionWithContext: Error while writing instruction at code offset 0x2
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1319)
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java
:1042)
... 10 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:356)
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1279)
... 11 more

C:\kb\java_myApps\android\apktool_jadx\garmin_connect\apktool>"C:\Program Files\Java\jre1.8.0_181\bin\java.exe" -Xmx512m -jar C:\kb\apktool_2.3.4\apktool_2.4.1.jar -f --verbose b C:\kb\java_myApps\android\apktool_jadx\garmin_connect\apktool
\Connect_v4_38_1_b5720_SAP -o C:\kb\java_myApps\android\apktool_jadx\garmin_connect\apktool\KB_garmin_connect.apk
Jan 15, 2021 1:53:20 PM brut.androlib.Androlib build
INFO: Using Apktool 2.4.1
Jan 15, 2021 1:53:21 PM brut.androlib.Androlib buildSourcesSmali
INFO: Smaling smali folder into classes.dex...
Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Lk2/a/a/a/v/e/c;->values()[Lk2/a/a/a/v/e/c;
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:917)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:341)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:297)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:61)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:36)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:418)
at brut.androlib.Androlib.buildSources(Androlib.java:349)
at brut.androlib.Androlib.build(Androlib.java:301)
at brut.androlib.Androlib.build(Androlib.java:268)
at brut.apktool.Main.cmdBuild(Main.java:251)
at brut.apktool.Main.main(Main.java:79)
Caused by: org.jf.util.ExceptionWithContext: Error while writing instruction at code offset 0x2
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1190)
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:913)
... 10 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:356)
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1150)
... 11 more

Include stacktrace here

Steps to Reproduce

  1. apktool

Frameworks

If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files
(.apks that live in /system/framework or /system/priv-app)

APK

If this APK can be freely shared, please upload/attach a link to it.

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? yes
  2. If you are trying to install a modified apk, did you resign it? no
  3. Are you using the latest apktool version? yes
@beaumontk
Copy link
Author

beaumontk commented Jan 15, 2021

Building APK from split APKs generated by https://www.andnixsh.com/2020/06/sap-split-apks-packer-by-kirlif-windows.html
apktool decoded ok and then Built ok. Crashed only when re-built after small change in unrelated smali

So, restarted and decodes and builds ok! Clearly connected to my change in unrelated smali

caused by logging instruction in unrelated smali:
#KB
const-string v0, "KBDBG_001a_smali_Logger_init"
invoke-static {v0, v0}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I
#KB

Log package missing?

Found another occurrence: seems to be caused by an invalid instruction in .smali file.
But I can't see an error in my Log command

More news:
The problem occurs in the smali folder, but not in the smali_classes2 folder.

@pashamcr
Copy link
Contributor

@beaumontk
Unsigned short value out of range: 65536
https://developer.android.com/studio/build/multidex
transfer the modified smali to another dex

@beaumontk
Copy link
Author

beaumontk commented Jan 16, 2021

So move eg. XXX.smal from smali folder to smali_classes2 folder?
Had no idea that this was possible!
Thanks a lot

Aah! Not so simple! Duplicate the directory or move the whole directory?
Presumably would be possible to create a new smali_classesX directory?

Working now! Thanks again

@iBotPeaches
Copy link
Owner

As mentioned, the method limit was hit (unsigned short max) and thus moving files to a new dex file resolved it.

Closing.

@beaumontk
Copy link
Author

Maybe this problem could be handled in a more dignified and explanatory way?

@Salman-Farid
Copy link

So move eg. XXX.smal from smali folder to smali_classes2 folder? Had no idea that this was possible! Thanks a lot

Aah! Not so simple! Duplicate the directory or move the whole directory? Presumably would be possible to create a new smali_classesX directory?

Working now! Thanks again

brother what did you do to solve this problem can you explain.?

So move eg. XXX.smal from smali folder to smali_classes2 folder? Had no idea that this was possible! Thanks a lot

Aah! Not so simple! Duplicate the directory or move the whole directory? Presumably would be possible to create a new smali_classesX directory?

Working now! Thanks again

@Salman-Farid
Copy link

Salman-Farid commented Oct 8, 2021

@beaumontk

brother what did you do to solve this ? I'm using kali linux and same problem.

@iBotPeaches
Copy link
Owner

@beaumontk

brother what did you do to solve this ? I'm using kali linux and same problem.

The solve was in the answer you quoted.

Repository owner locked as resolved and limited conversation to collaborators Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants