Skip to content

Commit

Permalink
fix: produce more deterministic code
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Apr 22, 2019
1 parent f1539d2 commit 89b8090
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
6 changes: 3 additions & 3 deletions jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private void addMethod(CodeWriter code, MethodNode mth) throws CodegenException
private void insertDecompilationProblems(CodeWriter code, AttrNode node) {
List<JadxError> errors = node.getAll(AType.JADX_ERROR);
if (!errors.isEmpty()) {
errors.forEach(err -> {
errors.stream().sorted().forEach(err -> {
code.startLine("/* JADX ERROR: ").add(err.getError());
Throwable cause = err.getCause();
if (cause != null) {
Expand All @@ -345,8 +345,8 @@ private void insertDecompilationProblems(CodeWriter code, AttrNode node) {
}
List<String> warns = node.getAll(AType.JADX_WARN);
if (!warns.isEmpty()) {
warns.stream().distinct()
.forEach(warn -> code.startLine("/* JADX WARNING: ").addMultiLine(warn).add(" */"));
warns.stream().distinct().sorted()
.forEach(warn -> code.startLine("/* JADX WARNING: ").addMultiLine(warn).add(" */"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.IdentityHashMap;
import java.util.List;
Expand Down Expand Up @@ -121,6 +122,7 @@ public String toString() {
if (list.isEmpty()) {
return "";
}
list.sort(String::compareTo);
return "A[" + Utils.listToString(list) + ']';
}
}
10 changes: 6 additions & 4 deletions jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.android.dex.ClassData;
import com.android.dex.ClassData.Field;
Expand Down Expand Up @@ -60,7 +58,7 @@ public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
private ClassNode parentClass;

private ProcessState state = ProcessState.NOT_LOADED;
private final Set<ClassNode> dependencies = new HashSet<>();
private List<ClassNode> dependencies = Collections.emptyList();

// cache maps
private Map<MethodInfo, MethodNode> mthInfoMap = Collections.emptyMap();
Expand Down Expand Up @@ -527,10 +525,14 @@ public void setState(ProcessState state) {
this.state = state;
}

public Set<ClassNode> getDependencies() {
public List<ClassNode> getDependencies() {
return dependencies;
}

public void setDependencies(List<ClassNode> dependencies) {
this.dependencies = dependencies;
}

@Override
public int hashCode() {
return clsInfo.hashCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package jadx.core.dex.visitors;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import jadx.core.dex.attributes.AType;
Expand All @@ -26,12 +30,16 @@ public class DependencyCollector extends AbstractVisitor {
@Override
public boolean visit(ClassNode cls) throws JadxException {
DexNode dex = cls.dex();
Set<ClassNode> depList = cls.getDependencies();
processClass(cls, dex, depList);
Set<ClassNode> depSet = new HashSet<>();
processClass(cls, dex, depSet);
for (ClassNode inner : cls.getInnerClasses()) {
processClass(inner, dex, depList);
processClass(inner, dex, depSet);
}
depList.remove(cls);
depSet.remove(cls);

List<ClassNode> depList = new ArrayList<>(depSet);
depList.sort(Comparator.comparing(c -> c.getClassInfo().getFullName()));
cls.setDependencies(depList);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,15 @@ public void visit(MethodNode mth) {
}

private void runMultiVariableSearch(MethodNode mth) {
long startTime = System.currentTimeMillis();
TypeSearch typeSearch = new TypeSearch(mth);
boolean success;
try {
success = typeSearch.run();
boolean success = typeSearch.run();
if (!success) {
mth.addWarn("Multi-variable type inference failed");
}
} catch (Exception e) {
success = false;
mth.addWarn("Multi-variable type inference failed. Error: " + Utils.getStackTrace(e));
}
long time = System.currentTimeMillis() - startTime;
mth.addComment("JADX DEBUG: Multi-variable type inference result: " + (success ? "success" : "failure")
+ ", time: " + time + " ms");
}

private boolean setImmutableType(SSAVar ssaVar) {
Expand Down

0 comments on commit 89b8090

Please sign in to comment.