Skip to content

Commit

Permalink
fix: decoding references to private resources
Browse files Browse the repository at this point in the history
  • Loading branch information
MrIkso committed Sep 7, 2021
1 parent 9bdf385 commit 63faad1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import brut.androlib.AndrolibException;
import brut.androlib.err.UndefinedResObjectException;
import brut.androlib.res.decoder.ARSCDecoder;
import org.apache.commons.lang3.StringUtils;

import java.util.LinkedHashMap;
Expand All @@ -28,11 +29,13 @@
public class ResResSpec {
private final ResID mId;
private final String mName;
private final int mFlags;
private final ResPackage mPackage;
private final ResTypeSpec mType;
private final Map<ResConfigFlags, ResResource> mResources = new LinkedHashMap<>();

public ResResSpec(ResID id, String name, ResPackage pkg, ResTypeSpec type) {
public ResResSpec(ResID id, String name, int mFlags, ResPackage pkg, ResTypeSpec type) {
this.mFlags = mFlags;
this.mId = id;
String cleanName;

Expand Down Expand Up @@ -72,13 +75,19 @@ public boolean hasDefaultResource() {
return mResources.containsKey(new ResConfigFlags());
}

public boolean isPublicResource() {
return (getFlags() & ARSCDecoder.ENTRY_FLAG_PUBLIC) != 0;
}

public String getFullName(ResPackage relativeToPackage, boolean excludeType) {
return getFullName(getPackage().equals(relativeToPackage), excludeType);
}

public String getFullName(boolean excludePackage, boolean excludeType) {
return (excludePackage ? "" : getPackage().getName() + ":")
+ (excludeType ? "" : getType().getName() + "/") + getName();
String privateSuffix = isPublicResource() ? "" : "*";
String packageName = excludePackage ? "" : getPackage().getName() + ":";
return (packageName.isEmpty() ? "" : privateSuffix + packageName)
+ (excludeType ? "" : getType().getName() + "/") + getName();
}

public ResID getId() {
Expand All @@ -97,6 +106,10 @@ public ResTypeSpec getType() {
return mType;
}

public int getFlags() {
return mFlags;
}

public boolean isDummyResSpec() {
return getName().startsWith("APKTOOL_DUMMY_");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ private void readEntry(EntryData entryData) throws AndrolibException {
if (spec.isDummyResSpec()) {
removeResSpec(spec);

spec = new ResResSpec(resId, mSpecNames.getString(specNamesId), mPkg, mTypeSpec);
spec = new ResResSpec(resId, mSpecNames.getString(specNamesId), entryData.mFlags, mPkg, mTypeSpec);
mPkg.addResSpec(spec);
mTypeSpec.addResSpec(spec);
}
} else {
spec = new ResResSpec(resId, mSpecNames.getString(specNamesId), mPkg, mTypeSpec);
spec = new ResResSpec(resId, mSpecNames.getString(specNamesId), entryData.mFlags, mPkg, mTypeSpec);
mPkg.addResSpec(spec);
mTypeSpec.addResSpec(spec);
}
Expand Down Expand Up @@ -511,7 +511,7 @@ private void addMissingResSpecs() throws AndrolibException {
continue;
}

ResResSpec spec = new ResResSpec(new ResID(resId | i), "APKTOOL_DUMMY_" + Integer.toHexString(i), mPkg, mTypeSpec);
ResResSpec spec = new ResResSpec(new ResID(resId | i), "APKTOOL_DUMMY_" + Integer.toHexString(i), ENTRY_FLAG_PUBLIC, mPkg, mTypeSpec);

// If we already have this resID dont add it again.
if (! mPkg.hasResSpec(new ResID(resId | i))) {
Expand Down Expand Up @@ -575,7 +575,7 @@ private void nextChunkCheckType(int expectedType) throws IOException, AndrolibEx
private final HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();

private final static short ENTRY_FLAG_COMPLEX = 0x0001;
private final static short ENTRY_FLAG_PUBLIC = 0x0002;
public final static short ENTRY_FLAG_PUBLIC = 0x0002;
private final static short ENTRY_FLAG_WEAK = 0x0004;

public static class Header {
Expand Down

0 comments on commit 63faad1

Please sign in to comment.