Make msm work like smsm because classes aren't guaranteed to line up
This commit is contained in:
@@ -17,8 +17,6 @@ import net.runelite.asm.signature.Type;
|
||||
|
||||
public class Mapper
|
||||
{
|
||||
private static final int MAX_CLASSES = 250;
|
||||
|
||||
private final ClassGroup source, target;
|
||||
private ParallelExecutorMapping mapping;
|
||||
|
||||
@@ -46,41 +44,22 @@ public class Mapper
|
||||
|
||||
private ParallelExecutorMapping mapMethods(ClassGroup one, ClassGroup two)
|
||||
{
|
||||
MethodSignatureMapper msm = new MethodSignatureMapper();
|
||||
msm.map(one, two);
|
||||
|
||||
List<ParallelExecutorMapping> pmes = new ArrayList<>();
|
||||
for (int i = -1; i < MAX_CLASSES; ++i)
|
||||
|
||||
for (Method m : msm.getMap().keySet())
|
||||
{
|
||||
ClassFile c1, c2;
|
||||
Collection<Method> methods = msm.getMap().get(m);
|
||||
|
||||
if (i == -1)
|
||||
for (Method other : methods)
|
||||
{
|
||||
c1 = one.findClass("client");
|
||||
c2 = two.findClass("client");
|
||||
}
|
||||
else
|
||||
{
|
||||
c1 = one.findClass("class" + i);
|
||||
c2 = two.findClass("class" + i);
|
||||
}
|
||||
|
||||
if (c1 == null || c2 == null)
|
||||
continue;
|
||||
|
||||
MethodSignatureMapper msm = new MethodSignatureMapper();
|
||||
msm.map(c1, c2);
|
||||
|
||||
Multimap<Method, Method> map = msm.getMap();
|
||||
for (Method m : map.keySet())
|
||||
{
|
||||
Collection<Method> methods = map.get(m);
|
||||
|
||||
for (Method other : methods)
|
||||
{
|
||||
HashMap<Object, Object> all = new HashMap();
|
||||
map(all, pmes, m, other);
|
||||
}
|
||||
HashMap<Object, Object> all = new HashMap();
|
||||
map(all, pmes, m, other);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ParallelExecutorMapping finalm = new ParallelExecutorMapping(one, two);
|
||||
for (ParallelExecutorMapping pme : pmes)
|
||||
finalm.merge(pme);
|
||||
|
||||
@@ -2,40 +2,44 @@ package net.runelite.deob.deobfuscators.rename;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import net.runelite.asm.ClassFile;
|
||||
import net.runelite.asm.ClassGroup;
|
||||
import net.runelite.asm.Method;
|
||||
import net.runelite.asm.signature.Signature;
|
||||
|
||||
public class MethodSignatureMapper
|
||||
{
|
||||
private Multimap<Method, Method> map = ArrayListMultimap.create();
|
||||
|
||||
public void map(ClassFile c1, ClassFile c2)
|
||||
|
||||
private List<Method> getMethods(ClassGroup group)
|
||||
{
|
||||
for (Method m : c1.getMethods().getMethods())
|
||||
List<Method> methods = new ArrayList<>();
|
||||
for (ClassFile cf : group.getClasses())
|
||||
for (Method m : cf.getMethods().getMethods())
|
||||
if (!m.isStatic() && !m.getName().equals("<init>") && m.getCode() != null)
|
||||
methods.add(m);
|
||||
return methods;
|
||||
}
|
||||
|
||||
private List<Method> getMethodsOfSignature(ClassGroup group, ClassFile cf, Signature sig)
|
||||
{
|
||||
return getMethods(group).stream()
|
||||
.filter(m -> MappingExecutorUtil.isMaybeEqual(cf, m.getMethods().getClassFile()))
|
||||
.filter(m -> MappingExecutorUtil.isMaybeEqual(m.getDescriptor(), sig))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void map(ClassGroup group1, ClassGroup group2)
|
||||
{
|
||||
for (Method m : getMethods(group1))
|
||||
{
|
||||
if (m.isStatic() || m.getCode() == null)
|
||||
continue;
|
||||
|
||||
boolean isConstructor = m.getName().equals("<init>");
|
||||
|
||||
for (Method m2 : c2.getMethods().getMethods())
|
||||
{
|
||||
if (m2.getCode() == null)
|
||||
continue;
|
||||
|
||||
if (!MappingExecutorUtil.isMaybeEqual(m.getDescriptor(), m2.getDescriptor()))
|
||||
continue;
|
||||
|
||||
boolean isConstructor2 = m2.getName().equals("<init>");
|
||||
|
||||
if (isConstructor != isConstructor2)
|
||||
continue;
|
||||
|
||||
map.put(m, m2);
|
||||
}
|
||||
map.putAll(m, getMethodsOfSignature(group2, m.getMethods().getClassFile(), m.getDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Multimap<Method, Method> getMap()
|
||||
{
|
||||
return map;
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.junit.Test;
|
||||
public class MapperTest
|
||||
{
|
||||
private static final String JAR1 = "C:\\Users\\Adam\\.m2\\repository\\net\\runelite\\rs\\rs-client\\1.0-SNAPSHOT\\rs-client-1.0-SNAPSHOT.jar",
|
||||
JAR2 = "c:/rs/gamepack_v18_deobbed.jar";
|
||||
JAR2 = "d:/rs/07/gamepack_v19_deobfuscated.jar";
|
||||
// private static final String JAR1 = MapStaticTest.class.getResource("/adamin1.jar").getFile(),
|
||||
// JAR2 = MapStaticTest.class.getResource("/adamin2.jar").getFile();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user