Commit 89b80900 authored by Skylot's avatar Skylot

fix: produce more deterministic code

parent f1539d2e
......@@ -332,7 +332,7 @@ public class ClassGen {
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) {
......@@ -345,8 +345,8 @@ public class ClassGen {
}
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(" */"));
}
}
......
......@@ -2,6 +2,7 @@ package jadx.core.dex.attributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.IdentityHashMap;
import java.util.List;
......@@ -121,6 +122,7 @@ public class AttributeStorage {
if (list.isEmpty()) {
return "";
}
list.sort(String::compareTo);
return "A[" + Utils.listToString(list) + ']';
}
}
......@@ -3,10 +3,8 @@ package jadx.core.dex.nodes;
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;
......@@ -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();
......@@ -527,10 +525,14 @@ public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
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();
......
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;
......@@ -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;
}
......
......@@ -90,18 +90,15 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
}
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) {
......
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