Skip to content

Commit 0e22692

Browse files
authored
Remove Apktool Dummys. (#3258)
* refactor: properly parse dummy resources * feat: remove dummys
1 parent bb9519a commit 0e22692

File tree

5 files changed

+4
-77
lines changed

5 files changed

+4
-77
lines changed

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResPackage.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ boolean isSynthesized(ResID resId) {
127127
return mSynthesizedRes.contains(resId);
128128
}
129129

130-
public void removeResSpec(ResResSpec spec) {
131-
mResSpecs.remove(spec.getId());
132-
}
133-
134130
public void addResSpec(ResResSpec spec) throws AndrolibException {
135131
if (mResSpecs.put(spec.getId(), spec) != null) {
136132
throw new AndrolibException("Multiple resource specs: " + spec);

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResResSpec.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ public ResTypeSpec getType() {
105105
return mType;
106106
}
107107

108-
public boolean isDummyResSpec() {
109-
return getName().startsWith("APKTOOL_DUMMY_");
110-
}
111-
112108
public void addResource(ResResource res) throws AndrolibException {
113109
addResource(res, false);
114110
}

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResTypeSpec.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,11 @@ public final class ResTypeSpec {
3030
private final String mName;
3131
private final Map<String, ResResSpec> mResSpecs = new LinkedHashMap<>();
3232

33-
private final ResTable mResTable;
34-
private final ResPackage mPackage;
35-
3633
private final int mId;
37-
private final int mEntryCount;
3834

39-
public ResTypeSpec(String name, ResTable resTable, ResPackage package_, int id, int entryCount) {
35+
public ResTypeSpec(String name, int id) {
4036
this.mName = name;
41-
this.mResTable = resTable;
42-
this.mPackage = package_;
4337
this.mId = id;
44-
this.mEntryCount = entryCount;
4538
}
4639

4740
public String getName() {
@@ -68,10 +61,6 @@ public ResResSpec getResSpecUnsafe(String name) {
6861
return mResSpecs.get(name);
6962
}
7063

71-
public void removeResSpec(ResResSpec spec) {
72-
mResSpecs.remove(spec.getName());
73-
}
74-
7564
public void addResSpec(ResResSpec spec) throws AndrolibException {
7665
if (mResSpecs.put(spec.getName(), spec) != null) {
7766
throw new AndrolibException(String.format("Multiple res specs: %s/%s", getName(), spec.getName()));

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResScalarValue.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ public void serializeToResValuesXml(XmlSerializer serializer,
8181
}
8282
}
8383

84-
// Dummy attributes should be <item> with type attribute
85-
if (res.getResSpec().isDummyResSpec()) {
86-
item = true;
87-
}
88-
8984
// Android does not allow values (false) for ids.xml anymore
9085
// https://issuetracker.google.com/issues/80475496
9186
// But it decodes as a ResBoolean, which makes no sense. So force it to empty

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlag
6363

6464
private ResPackage[] readResourceTable() throws IOException, AndrolibException {
6565
Set<ResPackage> pkgs = new LinkedHashSet<>();
66+
6667
ResTypeSpec typeSpec;
6768

6869
chunkLoop:
@@ -112,10 +113,6 @@ private ResPackage[] readResourceTable() throws IOException, AndrolibException {
112113
}
113114
}
114115

115-
if (mPkg != null && mPkg.getResSpecCount() > 0) {
116-
addMissingResSpecs();
117-
}
118-
119116
return pkgs.toArray(new ResPackage[0]);
120117
}
121118

@@ -245,7 +242,7 @@ private ResTypeSpec readTableSpecType() throws AndrolibException, IOException {
245242
mHeader.checkForUnreadHeader(mIn);
246243

247244
mIn.skipBytes(entryCount * 4); // flags
248-
mTypeSpec = new ResTypeSpec(mTypeNames.getString(id - 1), mResTable, mPkg, id, entryCount);
245+
mTypeSpec = new ResTypeSpec(mTypeNames.getString(id - 1), id);
249246
mPkg.addType(mTypeSpec);
250247

251248
return mTypeSpec;
@@ -264,7 +261,6 @@ private ResType readTableType() throws IOException, AndrolibException {
264261
int entryCount = mIn.readInt();
265262
mIn.skipInt(); // entriesStart
266263

267-
mMissingResSpecMap = new LinkedHashMap<>();
268264
ResConfigFlags flags = readConfigFlags();
269265

270266
mHeader.checkForUnreadHeader(mIn);
@@ -297,12 +293,11 @@ private ResType readTableType() throws IOException, AndrolibException {
297293
mType = flags.isInvalid && !mKeepBroken ? null : mPkg.getOrCreateConfig(flags);
298294

299295
for (int i : entryOffsetMap.keySet()) {
296+
mResId = (mResId & 0xffff0000) | i;
300297
int offset = entryOffsetMap.get(i);
301298
if (offset == NO_ENTRY) {
302299
continue;
303300
}
304-
mMissingResSpecMap.put(i, false);
305-
mResId = (mResId & 0xffff0000) | i;
306301

307302
// As seen in some recent APKs - there are more entries reported than can fit in the chunk.
308303
if (mIn.position() == mHeader.endPosition) {
@@ -369,14 +364,6 @@ private void readEntry(EntryData entryData) throws AndrolibException {
369364
ResResSpec spec;
370365
if (mPkg.hasResSpec(resId)) {
371366
spec = mPkg.getResSpec(resId);
372-
373-
if (spec.isDummyResSpec()) {
374-
removeResSpec(spec);
375-
376-
spec = new ResResSpec(resId, mSpecNames.getString(specNamesId), mPkg, mTypeSpec);
377-
mPkg.addResSpec(spec);
378-
mTypeSpec.addResSpec(spec);
379-
}
380367
} else {
381368
spec = new ResResSpec(resId, mSpecNames.getString(specNamesId), mPkg, mTypeSpec);
382369
mPkg.addResSpec(spec);
@@ -598,41 +585,6 @@ private void addTypeSpec(ResTypeSpec resTypeSpec) {
598585
mResTypeSpecs.put(resTypeSpec.getId(), resTypeSpec);
599586
}
600587

601-
private void addMissingResSpecs() throws AndrolibException {
602-
int resId = mResId & 0xffff0000;
603-
604-
for (int i : mMissingResSpecMap.keySet()) {
605-
if (mMissingResSpecMap.get(i)) continue;
606-
607-
ResResSpec spec = new ResResSpec(new ResID(resId | i), "APKTOOL_DUMMY_" + Integer.toHexString(i), mPkg, mTypeSpec);
608-
609-
// If we already have this resID don't add it again.
610-
if (! mPkg.hasResSpec(new ResID(resId | i))) {
611-
mPkg.addResSpec(spec);
612-
mTypeSpec.addResSpec(spec);
613-
614-
if (mType == null) {
615-
mType = mPkg.getOrCreateConfig(new ResConfigFlags());
616-
}
617-
618-
// We are going to make dummy attributes a null reference (@null) now instead of a boolean false.
619-
// This is because aapt2 is much more strict when it comes to what we can put in an application.
620-
ResValue value = new ResReferenceValue(mPkg, 0, "");
621-
622-
ResResource res = new ResResource(mType, spec, value);
623-
mType.addResource(res);
624-
spec.addResource(res);
625-
}
626-
}
627-
}
628-
629-
private void removeResSpec(ResResSpec spec) {
630-
if (mPkg.hasResSpec(spec.getId())) {
631-
mPkg.removeResSpec(spec);
632-
mTypeSpec.removeResSpec(spec);
633-
}
634-
}
635-
636588
private ARSCHeader nextChunk() throws IOException {
637589
return mHeader = ARSCHeader.read(mIn);
638590
}
@@ -658,7 +610,6 @@ private void checkChunkType(int expectedType) throws AndrolibException {
658610
private ResType mType;
659611
private int mResId;
660612
private int mTypeIdOffset = 0;
661-
private HashMap<Integer, Boolean> mMissingResSpecMap;
662613
private final HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();
663614

664615
private final static short ENTRY_FLAG_COMPLEX = 0x0001;

0 commit comments

Comments
 (0)