Skip to content

Commit

Permalink
fix: accept empty resources.arsc (#2998)
Browse files Browse the repository at this point in the history
* fix: accept empty resources.arsc

* fix: accept empty resources.arsc (fix isFrameworkApk=true)
  • Loading branch information
IgorEisberg committed Feb 19, 2023
1 parent 0a3c759 commit 1206118
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ public void emptyFrameworkDirectory() throws AndrolibException {

public boolean isFrameworkApk(ResTable resTable) {
for (ResPackage pkg : resTable.listMainPackages()) {
if (pkg.getId() < 64) {
if (pkg.getId() > 0 && pkg.getId() < 64) {
return true;
}
}
Expand Down
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

0 comments on commit 1206118

Please sign in to comment.