Skip to content

Commit

Permalink
fix: add dummy class if class loading exception occur (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 17, 2019
1 parent 902247f commit d3ecc1f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions jadx-core/src/main/java/jadx/core/dex/nodes/DexNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.core.utils.ErrorsCounter;
import jadx.core.utils.files.DexFile;

public class DexNode implements IDexNode {
Expand Down Expand Up @@ -56,15 +56,33 @@ public void loadClasses() {
for (ClassDef cls : dexBuf.classDefs()) {
try {
addClassNode(new ClassNode(this, cls));
} catch (JadxRuntimeException e) {
// TODO: Add dummy class node displaying the error message
LOG.error("Class loading failed - {}", e.getMessage(), e);
} catch (Exception e) {
addDummyClass(cls, e);
}
}
// sort classes by name, expect top classes before inner
classes.sort(Comparator.comparing(ClassNode::getFullName));
}

private void addDummyClass(ClassDef classDef, Exception exc) {
int typeIndex = classDef.getTypeIndex();
String name = null;
try {
ClassInfo clsInfo = ClassInfo.fromDex(this, typeIndex);
if (clsInfo != null) {
name = clsInfo.getShortName();
}
} catch (Exception e) {
LOG.error("Failed to get name for class with type {}", typeIndex, e);
}
if (name == null || name.isEmpty()) {
name = "CLASS_" + typeIndex;
}
ClassNode clsNode = new ClassNode(this, name, classDef.getAccessFlags());
ErrorsCounter.classError(clsNode, "Load error", exc);
addClassNode(clsNode);
}

public void addClassNode(ClassNode clsNode) {
classes.add(clsNode);
clsMap.put(clsNode.getClassInfo(), clsNode);
Expand Down

0 comments on commit d3ecc1f

Please sign in to comment.