Skip to content

Commit

Permalink
fix: process manifest before other resources (#1740)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Feb 17, 2023
1 parent 85c2c63 commit 24284a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
16 changes: 14 additions & 2 deletions jadx-core/src/main/java/jadx/api/JadxDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,21 @@ private void appendResourcesSaveTasks(List<Runnable> tasks, File outDir) {
if (args.isSkipFilesSave()) {
return;
}
// process AndroidManifest.xml first to load complete resource ids table
for (ResourceFile resourceFile : getResources()) {
if (resourceFile.getType() == ResourceType.MANIFEST) {
new ResourcesSaver(outDir, resourceFile).run();
}
}

Set<String> inputFileNames = args.getInputFiles().stream().map(File::getAbsolutePath).collect(Collectors.toSet());
for (ResourceFile resourceFile : getResources()) {
if (resourceFile.getType() != ResourceType.ARSC
ResourceType resType = resourceFile.getType();
if (resType == ResourceType.MANIFEST) {
// already processed
continue;
}
if (resType != ResourceType.ARSC
&& inputFileNames.contains(resourceFile.getOriginalName())) {
// ignore resource made from input file
continue;
Expand Down Expand Up @@ -382,7 +394,7 @@ public List<JavaClass> getClassesWithInners() {
return Utils.collectionMap(root.getClasses(), this::convertClassNode);
}

public List<ResourceFile> getResources() {
public synchronized List<ResourceFile> getResources() {
if (resources == null) {
if (root == null) {
return Collections.emptyList();
Expand Down
5 changes: 3 additions & 2 deletions jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Random;
import java.util.Set;

import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -51,7 +52,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
private boolean isLastEnd = true;
private boolean isOneLine = true;
private int namespaceDepth = 0;
private int[] resourceIds;
private @Nullable int[] resourceIds;

private final RootNode rootNode;
private String appPackageName;
Expand Down Expand Up @@ -358,7 +359,7 @@ private String getAttributeName(int id) {
// As the outcome of https://github.com/skylot/jadx/issues/1208
// Android seems to favor entries from AndroidResMap and only if
// there is no entry uses the values form the XML string pool
if (0 <= id && id < resourceIds.length) {
if (resourceIds != null && 0 <= id && id < resourceIds.length) {
int resId = resourceIds[id];
String str = ValuesParser.getAndroidResMap().get(resId);
if (str != null) {
Expand Down
6 changes: 5 additions & 1 deletion jadx-core/src/main/java/jadx/core/xmlgen/ResourcesSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public ResourcesSaver(File outDir, ResourceFile resourceFile) {

@Override
public void run() {
saveResources(resourceFile.loadContent());
try {
saveResources(resourceFile.loadContent());
} catch (Throwable e) {
LOG.warn("Failed to save resource: {}", resourceFile.getOriginalName(), e);
}
}

private void saveResources(ResContainer rc) {
Expand Down

0 comments on commit 24284a6

Please sign in to comment.