Skip to content

Commit

Permalink
perf(res): speed up rename of deobfuscated resources
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 26, 2020
1 parent d06ba95 commit d1e5186
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
27 changes: 20 additions & 7 deletions jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,30 @@ public void initClassPath() {
}

private void updateObfuscatedFiles(ResTableParser parser, List<ResourceFile> resources) {
if (args.isSkipResources()) {
return;
}
long start = System.currentTimeMillis();
int renamedCount = 0;
ResourceStorage resStorage = parser.getResStorage();
ValuesParser valuesParser = new ValuesParser(this, parser.getStrings(), resStorage.getResourcesNames());
for (int i = 0; i < resources.size(); i++) {
ResourceFile resource = resources.get(i);
for (ResourceEntry ri : parser.getResStorage().getResources()) {
if (resource.getOriginalName().equals(valuesParser.getValueString(ri))) {
resource.setAlias(ri);
break;
}
Map<String, ResourceEntry> entryNames = new HashMap<>();
for (ResourceEntry resEntry : resStorage.getResources()) {
String val = valuesParser.getSimpleValueString(resEntry);
if (val != null) {
entryNames.put(val, resEntry);
}
}
for (ResourceFile resource : resources) {
ResourceEntry resEntry = entryNames.get(resource.getOriginalName());
if (resEntry != null) {
resource.setAlias(resEntry);
renamedCount++;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Renamed obfuscated resources: {}, duration: {}ms", renamedCount, System.currentTimeMillis() - start);
}
}

private void initInnerClasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ private static void decodeAndroid(RootNode root) throws IOException {
}
}

@Nullable
public String getSimpleValueString(ResourceEntry ri) {
RawValue simpleValue = ri.getSimpleValue();
if (simpleValue == null) {
return null;
}
return decodeValue(simpleValue);
}

@Nullable
public String getValueString(ResourceEntry ri) {
RawValue simpleValue = ri.getSimpleValue();
Expand Down

0 comments on commit d1e5186

Please sign in to comment.