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

StringIndexOutOfBoundsException (getHTML) #2244

Closed
ghost opened this issue Nov 30, 2019 · 3 comments
Closed

StringIndexOutOfBoundsException (getHTML) #2244

ghost opened this issue Nov 30, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 30, 2019

"D:\Software\Java\8\x64\jdk1.8.0_151\bin\java.exe" -d64 -jar "D:/DOS/android/bin/apktool.jar"
--force --output "project_calcalist_5049" decode  "D:/DOS/android/calcalist_5049.apk"

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 -Duser.language=en -Xmn512m -Xms512m -Xmx2048
m -Xverify:none -XX:+UseParallelGC -XX:ParallelGCThreads=2 -Dfile.encoding=UTF8 -Duser.language
=en
I: Using Apktool 2.4.1-b05f19-SNAPSHOT on calcalist_5049.apk
I: Loading resource table...
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range
: 24
        at java.lang.String.substring(String.java:1963)
        at brut.androlib.res.decoder.StringBlock.getHTML(StringBlock.java:164)
        at brut.androlib.res.decoder.ARSCDecoder.readValue(ARSCDecoder.java:360)
        at brut.androlib.res.decoder.ARSCDecoder.readEntryData(ARSCDecoder.java:276)
        at brut.androlib.res.decoder.ARSCDecoder.readTableType(ARSCDecoder.java:252)
        at brut.androlib.res.decoder.ARSCDecoder.readTableTypeSpec(ARSCDecoder.java:175)
        at brut.androlib.res.decoder.ARSCDecoder.readTablePackage(ARSCDecoder.java:131)
        at brut.androlib.res.decoder.ARSCDecoder.readTableHeader(ARSCDecoder.java:82)
        at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48)
        at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:786)
        at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:67)
        at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:59)
        at brut.androlib.Androlib.getResTable(Androlib.java:66)
        at brut.androlib.ApkDecoder.setTargetSdkVersion(ApkDecoder.java:236)
        at brut.androlib.ApkDecoder.decode(ApkDecoder.java:118)
        at brut.apktool.Main.cmdDecode(Main.java:170)
        at brut.apktool.Main.main(Main.java:76)

I'm trying to process this APK:
https://apkpure.com/%D7%9B%D7%9C%D7%9B%D7%9C%D7%99%D7%A1%D7%98/com.opentech.calcalist/download/160-APK?from=versions%2Fversion

I'm using an APKTool version 2.4.1-197d46-SNAPSHOT from source.
(can download from https://github.com/eladkarako/icompile/tree/master/unofficial-apktool)

@Ticklefish
Copy link

Ticklefish commented Nov 30, 2019

This APK is badly constructed unfortunately. That error isn't something apktool can overcome, I think.

I tried decompiling the file without processing "resources.arsc" but got an error saying:

Exception in thread "main" brut.androlib.AndrolibException: brut.directory.DirectoryException: Error copying file: resources.arsc

This might have been done deliberately to stop people from modding the APK.

@iBotPeaches
Copy link
Owner

Some weird strings crashing the decoder. I replicate.

"အသံပြန်ဖွင့်ပါ"

Marking as bug.

@iBotPeaches iBotPeaches changed the title Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range (when loading resource table) StringIndexOutOfBoundsException (getHTML) Nov 29, 2020
@iBotPeaches
Copy link
Owner

Perhaps modifying the following code to your usage can help with normalizing things for you with native functions?
https://github.com/eladkarako/Overkill-UTF-8-Support-For-Windows-And-Java-With-Full-Code-And-Usage-Example/blob/520ea39f4dda215db6879281b2f95a5ad0276eeb/_compile.cmd#L43

I don't think the issue is having to do with output, but rather the actual low level decoding of a UTF8/UTF16 string. We are reading the StringBlock with a custom parser to handle the needed changes - https://github.com/iBotPeaches/Apktool/blob/master/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/StringBlock.java

So this is a lot of if/loops and more. Its buggy and needs to be patched with the idea of multibyte characters, surrogate characters and more. Unicode, et all.

@ghost ghost closed this as completed Mar 24, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants