Skip to content

Commit 24284a6

Browse files
committed
fix: process manifest before other resources (#1740)
1 parent 85c2c63 commit 24284a6

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

jadx-core/src/main/java/jadx/api/JadxDecompiler.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,21 @@ private void appendResourcesSaveTasks(List<Runnable> tasks, File outDir) {
309309
if (args.isSkipFilesSave()) {
310310
return;
311311
}
312+
// process AndroidManifest.xml first to load complete resource ids table
313+
for (ResourceFile resourceFile : getResources()) {
314+
if (resourceFile.getType() == ResourceType.MANIFEST) {
315+
new ResourcesSaver(outDir, resourceFile).run();
316+
}
317+
}
318+
312319
Set<String> inputFileNames = args.getInputFiles().stream().map(File::getAbsolutePath).collect(Collectors.toSet());
313320
for (ResourceFile resourceFile : getResources()) {
314-
if (resourceFile.getType() != ResourceType.ARSC
321+
ResourceType resType = resourceFile.getType();
322+
if (resType == ResourceType.MANIFEST) {
323+
// already processed
324+
continue;
325+
}
326+
if (resType != ResourceType.ARSC
315327
&& inputFileNames.contains(resourceFile.getOriginalName())) {
316328
// ignore resource made from input file
317329
continue;
@@ -382,7 +394,7 @@ public List<JavaClass> getClassesWithInners() {
382394
return Utils.collectionMap(root.getClasses(), this::convertClassNode);
383395
}
384396

385-
public List<ResourceFile> getResources() {
397+
public synchronized List<ResourceFile> getResources() {
386398
if (resources == null) {
387399
if (root == null) {
388400
return Collections.emptyList();

jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Random;
99
import java.util.Set;
1010

11+
import org.jetbrains.annotations.Nullable;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
1314

@@ -51,7 +52,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
5152
private boolean isLastEnd = true;
5253
private boolean isOneLine = true;
5354
private int namespaceDepth = 0;
54-
private int[] resourceIds;
55+
private @Nullable int[] resourceIds;
5556

5657
private final RootNode rootNode;
5758
private String appPackageName;
@@ -358,7 +359,7 @@ private String getAttributeName(int id) {
358359
// As the outcome of https://github.com/skylot/jadx/issues/1208
359360
// Android seems to favor entries from AndroidResMap and only if
360361
// there is no entry uses the values form the XML string pool
361-
if (0 <= id && id < resourceIds.length) {
362+
if (resourceIds != null && 0 <= id && id < resourceIds.length) {
362363
int resId = resourceIds[id];
363364
String str = ValuesParser.getAndroidResMap().get(resId);
364365
if (str != null) {

jadx-core/src/main/java/jadx/core/xmlgen/ResourcesSaver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public ResourcesSaver(File outDir, ResourceFile resourceFile) {
2929

3030
@Override
3131
public void run() {
32-
saveResources(resourceFile.loadContent());
32+
try {
33+
saveResources(resourceFile.loadContent());
34+
} catch (Throwable e) {
35+
LOG.warn("Failed to save resource: {}", resourceFile.getOriginalName(), e);
36+
}
3337
}
3438

3539
private void saveResources(ResContainer rc) {

0 commit comments

Comments
 (0)