Commit 91691fbd authored by Jan S's avatar Jan S Committed by skylot

fix: allow APK files without code (no contained dex files) (PR #455)

parent 9856b6d3
...@@ -54,6 +54,10 @@ public class AndroidResourcesUtils { ...@@ -54,6 +54,10 @@ public class AndroidResourcesUtils {
} }
LOG.info("App 'R' class not found, put all resources ids to : '{}'", fullName); LOG.info("App 'R' class not found, put all resources ids to : '{}'", fullName);
resCls = makeClass(root, fullName, resStorage); resCls = makeClass(root, fullName, resStorage);
if (resCls == null) {
// We are in an APK without code therefore we don't have to update an 'R' class with the resources
return null;
}
addResourceFields(resCls, resStorage, false); addResourceFields(resCls, resStorage, false);
return resCls; return resCls;
} }
...@@ -81,18 +85,18 @@ public class AndroidResourcesUtils { ...@@ -81,18 +85,18 @@ public class AndroidResourcesUtils {
return rCls; return rCls;
} }
private static void addResourceFields(ClassNode cls, ResourceStorage resStorage, boolean rClsExists) { private static void addResourceFields(ClassNode resCls, ResourceStorage resStorage, boolean rClsExists) {
Map<String, ClassNode> innerClsMap = new TreeMap<>(); Map<String, ClassNode> innerClsMap = new TreeMap<>();
if (rClsExists) { if (rClsExists) {
for (ClassNode innerClass : cls.getInnerClasses()) { for (ClassNode innerClass : resCls.getInnerClasses()) {
innerClsMap.put(innerClass.getShortName(), innerClass); innerClsMap.put(innerClass.getShortName(), innerClass);
} }
} }
for (ResourceEntry resource : resStorage.getResources()) { for (ResourceEntry resource : resStorage.getResources()) {
ClassNode typeCls = innerClsMap.computeIfAbsent(resource.getTypeName(), name -> { ClassNode typeCls = innerClsMap.computeIfAbsent(resource.getTypeName(), name -> {
ClassNode newTypeCls = new ClassNode(cls.dex(), cls.getFullName() + "$" + name, ClassNode newTypeCls = new ClassNode(resCls.dex(), resCls.getFullName() + "$" + name,
AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC | AccessFlags.ACC_FINAL); AccessFlags.ACC_PUBLIC | AccessFlags.ACC_STATIC | AccessFlags.ACC_FINAL);
cls.addInnerClass(newTypeCls); resCls.addInnerClass(newTypeCls);
if (rClsExists) { if (rClsExists) {
newTypeCls.addAttr(AType.COMMENTS, "added by JADX"); newTypeCls.addAttr(AType.COMMENTS, "added by JADX");
} }
......
...@@ -77,8 +77,7 @@ public class InputFile { ...@@ -77,8 +77,7 @@ public class InputFile {
if (skipSources) { if (skipSources) {
return; return;
} }
LOG.warn("No dex files found in {}", file);
throw new DecodeException("Unsupported input file format: " + file);
} }
private void addDexFile(Dex dexBuf) { private void addDexFile(Dex dexBuf) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment