Skip to content

fix: accept empty resources.arsc #2998

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

Merged
merged 2 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.nio.charset.StandardCharsets;

public class SmaliMod {
public static boolean assembleSmaliFile(File smaliFile,DexBuilder dexBuilder, int apiLevel, boolean verboseErrors,
public static boolean assembleSmaliFile(File smaliFile, DexBuilder dexBuilder, int apiLevel, boolean verboseErrors,
boolean printTokens) throws IOException, RecognitionException {

CommonTokenStream tokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ResPackage loadMainPkg(ResTable resTable, ExtFile apkFile)

switch (pkgs.length) {
case 0:
pkg = null;
pkg = new ResPackage(resTable, 0, null);
break;
case 1:
pkg = pkgs[0];
Expand All @@ -80,10 +80,6 @@ public ResPackage loadMainPkg(ResTable resTable, ExtFile apkFile)
break;
}

if (pkg == null) {
throw new AndrolibException("arsc files with zero packages or no arsc file found.");
}

resTable.addPackage(pkg, true);
return pkg;
}
Expand Down Expand Up @@ -168,9 +164,11 @@ public void adjustPackageManifest(ResTable resTable, String filePath)
resTable.setPackageId(resPackage.getId());
resTable.setPackageOriginal(pkgOriginal);

// 1) Check if pkgOriginal === mPackageRenamed
// 2) Check if pkgOriginal is ignored via IGNORED_PACKAGES
if (pkgOriginal.equalsIgnoreCase(mPackageRenamed) || (Arrays.asList(IGNORED_PACKAGES).contains(pkgOriginal))) {
// 1) Check if pkgOriginal is null (empty resources.arsc)
// 2) Check if pkgOriginal === mPackageRenamed
// 3) Check if pkgOriginal is ignored via IGNORED_PACKAGES
if (pkgOriginal == null || pkgOriginal.equalsIgnoreCase(mPackageRenamed)
|| (Arrays.asList(IGNORED_PACKAGES).contains(pkgOriginal))) {
LOGGER.info("Regular manifest package...");
} else {
LOGGER.info("Renamed manifest package found! Replacing " + mPackageRenamed + " with " + pkgOriginal);
Expand Down Expand Up @@ -708,7 +706,7 @@ public Duo<ResFileDecoder, AXmlResourceParser> getManifestFileDecoder(boolean wi
if (withResources) {
axmlParser.setAttrDecoder(new ResAttrDecoder());
}
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser,getResXmlSerializer()));
decoders.setDecoder("xml", new XmlPullStreamDecoder(axmlParser, getResXmlSerializer()));

return new Duo<>(new ResFileDecoder(decoders), axmlParser);
}
Expand Down Expand Up @@ -772,7 +770,7 @@ private void generatePublicXml(ResPackage pkg, Directory out,
}
}

private ResPackage[] getResPackagesFromApk(ExtFile apkFile,ResTable resTable, boolean keepBroken)
private ResPackage[] getResPackagesFromApk(ExtFile apkFile, ResTable resTable, boolean keepBroken)
throws AndrolibException {
try {
Directory dir = apkFile.getDirectory();
Expand Down