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

Fixes handling of applications without packages in resources #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kiber-io
Copy link

After one of the latest changes the handling of applications that don't contain packages in the .arsc file broke down:

ERROR:
java.io.IOException: Can not decode without package
	at com.reandroid.arsc.chunk.xml.ResXmlDocument.serialize(ResXmlDocument.java:509)
	at com.reandroid.apk.ApkModuleXmlDecoder.serializeXml(ApkModuleXmlDecoder.java:250)
	at com.reandroid.apk.ApkModuleXmlDecoder.decodeAndroidManifestXml(ApkModuleXmlDecoder.java:229)
	at com.reandroid.apk.ApkModuleXmlDecoder.decodeAndroidManifest(ApkModuleXmlDecoder.java:198)
	at com.reandroid.apk.ApkModuleDecoder.decode(ApkModuleDecoder.java:56)
	at com.reandroid.apkeditor.decompile.Decompiler.run(Decompiler.java:71)
	at com.reandroid.apkeditor.decompile.Decompiler.execute(Decompiler.java:210)
	at com.reandroid.apkeditor.Main.execute(Main.java:81)
	at com.reandroid.apkeditor.Main.execute(Main.java:64)
	at com.reandroid.apkeditor.Main.main(Main.java:36)

And on build:

Exception in thread "main" java.lang.IllegalArgumentException: java.io.IOException: Can not decode without package
	at com.reandroid.apk.xmlencoder.XMLEncodeSource.getBytes(XMLEncodeSource.java:53)
	at com.reandroid.archive.ByteInputSource.openStream(ByteInputSource.java:38)
	at com.reandroid.apk.ApkModule.getAndroidManifest(ApkModule.java:787)
	at com.reandroid.apkeditor.smali.SmaliCompiler.buildDexFiles(SmaliCompiler.java:54)
	at com.reandroid.apk.ApkModuleEncoder.encodeDexFiles(ApkModuleEncoder.java:152)
	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:181)
	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: java.io.IOException: Can not decode without package
	at com.reandroid.arsc.chunk.xml.ResXmlDocument.parse(ResXmlDocument.java:470)
	at com.reandroid.apk.xmlencoder.XMLEncodeSource.encode(XMLEncodeSource.java:77)
	at com.reandroid.apk.xmlencoder.XMLEncodeSource.getArray(XMLEncodeSource.java:65)
Caused by: java.io.IOException: Can not decode without package

	at com.reandroid.apk.xmlencoder.XMLEncodeSource.getBytes(XMLEncodeSource.java:51)
	... 11 more

@@ -841,7 +841,7 @@ private void ensureLoadedManifestLinked() {
}
packageBlock = tableBlock.pickOne(manifestBlock.guessCurrentPackageId());
if(packageBlock == null) {
packageBlock = tableBlock.pickOne();
packageBlock = tableBlock.pickOrEmptyPackage();
}
if(packageBlock != null) {
manifestBlock.setPackageBlock(packageBlock);
Copy link
Owner

@REAndroid REAndroid Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you,

there are some cases where packages will be constructed latter, can you experiment with this one ?
put setApkFile out of if block

        if(packageBlock != null) {
            manifestBlock.setPackageBlock(packageBlock);
        }
        manifestBlock.setApkFile(this);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ...
The purpose of ensureLoadedManifestLinked() is to check multiple times that manifest has correct package. In both cases ( pickOneOrEmpty & setApkFile) the manifest will claim having correct package even if new package is produced latter.

My other idea is :

        if(packageBlock != null && !packageBlock.isEmpty()) {
            TableBlock linkedTable = packageBlock.getTableBlock();
            if(linkedTable == tableBlock) {
                return;
            }
        }
        packageBlock = tableBlock.pickOne(manifestBlock.guessCurrentPackageId());
        if(packageBlock == null) {
            packageBlock = tableBlock.pickOrEmptyPackage();
        }

REAndroid added a commit that referenced this pull request Aug 2, 2024
REAndroid added a commit that referenced this pull request Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants