提交 c93e7fb9 编写于 作者: S Skylot

fix: detect loaded class duplication (#1107)

上级 34378889
...@@ -5,6 +5,7 @@ import java.util.Comparator; ...@@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
...@@ -20,6 +21,7 @@ import jadx.api.plugins.input.data.IClassData; ...@@ -20,6 +21,7 @@ import jadx.api.plugins.input.data.IClassData;
import jadx.api.plugins.input.data.ILoadResult; import jadx.api.plugins.input.data.ILoadResult;
import jadx.core.Jadx; import jadx.core.Jadx;
import jadx.core.clsp.ClspGraph; import jadx.core.clsp.ClspGraph;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.info.ClassInfo; import jadx.core.dex.info.ClassInfo;
import jadx.core.dex.info.ConstStorage; import jadx.core.dex.info.ConstStorage;
import jadx.core.dex.info.FieldInfo; import jadx.core.dex.info.FieldInfo;
...@@ -60,8 +62,8 @@ public class RootNode { ...@@ -60,8 +62,8 @@ public class RootNode {
private final ICodeCache codeCache; private final ICodeCache codeCache;
private final List<ClassNode> classes = new ArrayList<>();
private final Map<ClassInfo, ClassNode> clsMap = new HashMap<>(); private final Map<ClassInfo, ClassNode> clsMap = new HashMap<>();
private List<ClassNode> classes = new ArrayList<>();
private ClspGraph clsp; private ClspGraph clsp;
@Nullable @Nullable
...@@ -91,6 +93,18 @@ public class RootNode { ...@@ -91,6 +93,18 @@ public class RootNode {
} }
}); });
} }
if (classes.size() != clsMap.size()) {
// class name duplication detected
classes.stream().collect(Collectors.groupingBy(ClassNode::getClassInfo))
.entrySet().stream()
.filter(entry -> entry.getValue().size() > 1)
.forEach(entry -> {
LOG.warn("Found duplicated class: {}, count: {}. Only one will be loaded!", entry.getKey(),
entry.getValue().size());
entry.getValue().forEach(cls -> cls.addAttr(AType.COMMENTS, "WARNING: Classes with same name are omitted"));
});
}
classes = new ArrayList<>(clsMap.values());
// sort classes by name, expect top classes before inner // sort classes by name, expect top classes before inner
classes.sort(Comparator.comparing(ClassNode::getFullName)); classes.sort(Comparator.comparing(ClassNode::getFullName));
initInnerClasses(); initInnerClasses();
......
...@@ -82,9 +82,11 @@ public class JavaConvertLoader { ...@@ -82,9 +82,11 @@ public class JavaConvertLoader {
.filter(aarMatcher::matches) .filter(aarMatcher::matches)
.forEach(path -> ZipSecurity.readZipEntries(path.toFile(), (entry, in) -> { .forEach(path -> ZipSecurity.readZipEntries(path.toFile(), (entry, in) -> {
try { try {
if (entry.getName().endsWith(".jar")) { String entryName = entry.getName();
if (entryName.endsWith(".jar")) {
Path tempJar = saveInputStreamToFile(in, ".jar"); Path tempJar = saveInputStreamToFile(in, ".jar");
result.addTempPath(tempJar); result.addTempPath(tempJar);
LOG.debug("Loading jar: {} ...", entryName);
convertJar(result, tempJar); convertJar(result, tempJar);
} }
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册