fix: prevent collisions in method ids for java-input

This commit is contained in:
Skylot
2021-08-13 15:43:57 +01:00
parent 7c0671c81b
commit 55bb20cf29
9 changed files with 51 additions and 31 deletions
@@ -11,7 +11,7 @@ public class InfoStorage {
private final Map<FieldInfo, FieldInfo> fields = new HashMap<>();
// use only one MethodInfo instance
private final Map<MethodInfo, MethodInfo> uniqueMethods = new HashMap<>();
// can contain same method with different ids (from different dex files)
// can contain same method with different ids (from different files)
private final Map<Integer, MethodInfo> methods = new HashMap<>();
public ClassInfo getCls(ArgType type) {
@@ -1,6 +1,10 @@
package jadx.core.dex.info;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
@@ -39,9 +43,11 @@ public final class MethodInfo implements Comparable<MethodInfo> {
public static MethodInfo fromRef(RootNode root, IMethodRef methodRef) {
InfoStorage infoStorage = root.getInfoStorage();
int uniqId = methodRef.getUniqId();
MethodInfo prevMth = infoStorage.getByUniqId(uniqId);
if (prevMth != null) {
return prevMth;
if (uniqId != 0) {
MethodInfo prevMth = infoStorage.getByUniqId(uniqId);
if (prevMth != null) {
return prevMth;
}
}
methodRef.load();
ArgType parentClsType = ArgType.parse(methodRef.getParentClassType());
@@ -50,7 +56,9 @@ public final class MethodInfo implements Comparable<MethodInfo> {
List<ArgType> args = Utils.collectionMap(methodRef.getArgTypes(), ArgType::parse);
MethodInfo newMth = new MethodInfo(parentClass, methodRef.getName(), args, returnType);
MethodInfo uniqMth = infoStorage.putMethod(newMth);
infoStorage.putByUniqId(uniqId, uniqMth);
if (uniqId != 0) {
infoStorage.putByUniqId(uniqId, uniqMth);
}
return uniqMth;
}
@@ -31,8 +31,12 @@ public abstract class BaseExternalTest extends IntegrationTest {
protected abstract String getSamplesDir();
protected JadxArgs prepare(String inputFile) {
return prepare(new File(getSamplesDir(), inputFile));
}
protected JadxArgs prepare(File input) {
JadxArgs args = new JadxArgs();
args.getInputFiles().add(new File(getSamplesDir(), inputFile));
args.getInputFiles().add(input);
args.setOutDir(new File("../jadx-external-tests-tmp"));
return args;
}
@@ -47,6 +51,7 @@ public abstract class BaseExternalTest extends IntegrationTest {
protected void decompile(JadxArgs jadxArgs, @Nullable String clsPatternStr, @Nullable String mthPatternStr) {
JadxDecompiler jadx = new JadxDecompiler(jadxArgs);
jadx.getPluginManager().unload("java-convert");
jadx.load();
if (clsPatternStr == null) {