Skip to content

Commit

Permalink
fix: allow APK files without code (no contained dex files) (PR #455)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpstotz authored and skylot committed Feb 22, 2019
1 parent 9856b6d commit 91691fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public static ClassNode searchAppResClass(RootNode root, ResourceStorage resStor
}
LOG.info("App 'R' class not found, put all resources ids to : '{}'", fullName);
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);
return resCls;
}
Expand Down Expand Up @@ -81,18 +85,18 @@ private static ClassNode makeClass(RootNode root, String clsName, ResourceStorag
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<>();
if (rClsExists) {
for (ClassNode innerClass : cls.getInnerClasses()) {
for (ClassNode innerClass : resCls.getInnerClasses()) {
innerClsMap.put(innerClass.getShortName(), innerClass);
}
}
for (ResourceEntry resource : resStorage.getResources()) {
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);
cls.addInnerClass(newTypeCls);
resCls.addInnerClass(newTypeCls);
if (rClsExists) {
newTypeCls.addAttr(AType.COMMENTS, "added by JADX");
}
Expand Down
3 changes: 1 addition & 2 deletions jadx-core/src/main/java/jadx/core/utils/files/InputFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private void searchDexFiles(boolean skipSources) throws IOException, DecodeExcep
if (skipSources) {
return;
}

throw new DecodeException("Unsupported input file format: " + file);
LOG.warn("No dex files found in {}", file);
}

private void addDexFile(Dex dexBuf) {
Expand Down

0 comments on commit 91691fb

Please sign in to comment.