Interesting work using pme to detect method equality
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
package net.runelite.deob.deobfuscators.rename;
|
||||
|
||||
public class MappingException extends Exception
|
||||
{
|
||||
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class MappingExecutorUtil
|
||||
return map1.equals(map2);
|
||||
}
|
||||
|
||||
public static ParallelExecutorMapping map(Method m1, Method m2) throws MappingException
|
||||
public static ParallelExecutorMapping map(Method m1, Method m2)
|
||||
{
|
||||
ClassGroup group1 = m1.getMethods().getClassFile().getGroup();
|
||||
ClassGroup group2 = m2.getMethods().getClassFile().getGroup();
|
||||
@@ -169,16 +169,16 @@ public class MappingExecutorUtil
|
||||
// continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mi1.map(mappings, p1, p2);
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
p1.getFrame().stop();
|
||||
p2.getFrame().stop();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// try
|
||||
// {
|
||||
mi1.map(mappings, p1, p2);
|
||||
// }
|
||||
// catch (Throwable ex)
|
||||
// {
|
||||
// p1.getFrame().stop();
|
||||
// p2.getFrame().stop();
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
|
||||
e.paused = e2.paused = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.runelite.deob.deobfuscators.rename;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import net.runelite.deob.ClassFile;
|
||||
import net.runelite.deob.Method;
|
||||
import net.runelite.deob.Methods;
|
||||
import net.runelite.deob.signature.Signature;
|
||||
|
||||
public class MethodSignatureMapper
|
||||
{
|
||||
private Map<Method, Method> map = new HashMap<>();
|
||||
|
||||
private long count(Methods methods, Signature sig)
|
||||
{
|
||||
return methods.getMethods().stream().filter(m -> m.getDescriptor().equals(sig)).count();
|
||||
}
|
||||
|
||||
private Method get(Methods methods, Signature sig)
|
||||
{
|
||||
Optional<Method> o = methods.getMethods().stream().filter(m -> m.getDescriptor().equals(sig)).findFirst();
|
||||
return o.isPresent() ? o.get() : null;
|
||||
}
|
||||
|
||||
public void map(ClassFile c1, ClassFile c2)
|
||||
{
|
||||
for (Method m : c1.getMethods().getMethods())
|
||||
{
|
||||
if (m.isStatic() || m.getName().equals("<init>") || count(c1.getMethods(), m.getDescriptor()) > 1)
|
||||
continue;
|
||||
|
||||
Method other = get(c2.getMethods(), m.getDescriptor());
|
||||
if (other == null)
|
||||
continue;
|
||||
|
||||
map.put(m, other);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Method, Method> getMap()
|
||||
{
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -349,15 +349,8 @@ public class Rename2
|
||||
if (m1.getName().equals("<clinit>") || m1.getName().equals("<init>"))
|
||||
return;
|
||||
|
||||
ParallelExecutorMapping mapping = null;
|
||||
try
|
||||
{
|
||||
mapping = MappingExecutorUtil.map(m1, m2);
|
||||
}
|
||||
catch (MappingException ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
ParallelExecutorMapping mapping = MappingExecutorUtil.map(m1, m2);
|
||||
|
||||
System.out.println("EXEC " + count++ + " " + mname(m1) + " " + mname(m2) + " " + mapping);
|
||||
|
||||
for (Entry<Object, Object> e : mapping.getMap().entrySet())
|
||||
|
||||
@@ -0,0 +1,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.deob.ClassFile;
|
||||
import net.runelite.deob.ClassGroup;
|
||||
import net.runelite.deob.Method;
|
||||
import net.runelite.deob.signature.Signature;
|
||||
|
||||
public class StaticMethodSignatureMapper
|
||||
{
|
||||
private Multimap<Method, Method> map = ArrayListMultimap.create();
|
||||
|
||||
private List<Method> getStaticMethods(ClassGroup group)
|
||||
{
|
||||
List<Method> methods = new ArrayList<>();
|
||||
for (ClassFile cf : group.getClasses())
|
||||
for (Method m : cf.getMethods().getMethods())
|
||||
if (m.isStatic() && !m.getName().equals("<clinit>"))
|
||||
methods.add(m);
|
||||
return methods;
|
||||
}
|
||||
|
||||
private List<Method> getStaticMethodsOfSignature(ClassGroup group, Signature sig)
|
||||
{
|
||||
return getStaticMethods(group).stream().filter(m -> m.getDescriptor().equals(sig)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void map(ClassGroup group1, ClassGroup group2)
|
||||
{
|
||||
for (Method m : getStaticMethods(group1))
|
||||
{
|
||||
map.putAll(m, getStaticMethodsOfSignature(group2, m.getDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
public Multimap<Method, Method> getMap()
|
||||
{
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public class ParallellMappingExecutor
|
||||
if (oldf1.otherStatic == oldf2 && oldf2.otherStatic == oldf1)
|
||||
{
|
||||
mappings.map(oldf1.getMethod(), oldf2.getMethod());
|
||||
System.out.println("STEP OUT " + oldf1.getMethod() + " <-> " + oldf2.getMethod());
|
||||
// System.out.println("STEP OUT " + oldf1.getMethod() + " <-> " + oldf2.getMethod());
|
||||
}
|
||||
|
||||
// if (e.frames.size() - s1 != e2.frames.size() - s2)
|
||||
@@ -279,7 +279,7 @@ public class ParallellMappingExecutor
|
||||
stepf2.otherStatic = stepf1;
|
||||
|
||||
doubleStep.add(stepf1.getMethod());
|
||||
System.out.println("STEP " + stepf1.getMethod() + " <-> " + stepf2.getMethod());
|
||||
//System.out.println("STEP " + stepf1.getMethod() + " <-> " + stepf2.getMethod());
|
||||
|
||||
return step();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user