Attempt to map non static methods using PME too
This commit is contained in:
@@ -1,44 +1,42 @@
|
|||||||
package net.runelite.deob.deobfuscators.rename;
|
package net.runelite.deob.deobfuscators.rename;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import java.util.Map;
|
import com.google.common.collect.Multimap;
|
||||||
import java.util.Optional;
|
|
||||||
import net.runelite.deob.ClassFile;
|
import net.runelite.deob.ClassFile;
|
||||||
import net.runelite.deob.Method;
|
import net.runelite.deob.Method;
|
||||||
import net.runelite.deob.Methods;
|
|
||||||
import net.runelite.deob.signature.Signature;
|
|
||||||
|
|
||||||
public class MethodSignatureMapper
|
public class MethodSignatureMapper
|
||||||
{
|
{
|
||||||
private Map<Method, Method> map = new HashMap<>();
|
private Multimap<Method, Method> map = ArrayListMultimap.create();
|
||||||
|
|
||||||
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)
|
public void map(ClassFile c1, ClassFile c2)
|
||||||
{
|
{
|
||||||
for (Method m : c1.getMethods().getMethods())
|
for (Method m : c1.getMethods().getMethods())
|
||||||
{
|
{
|
||||||
if (m.isStatic() || count(c1.getMethods(), m.getDescriptor()) > 1)
|
if (m.isStatic() || m.getCode() == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Method other = get(c2.getMethods(), m.getDescriptor());
|
boolean isConstructor = m.getName().equals("<init>");
|
||||||
if (other == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
map.put(m, other);
|
for (Method m2 : c2.getMethods().getMethods())
|
||||||
|
{
|
||||||
|
if (m2.getCode() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!m.getDescriptor().equals(m2.getDescriptor()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
boolean isConstructor2 = m2.getName().equals("<init>");
|
||||||
|
|
||||||
|
if (isConstructor != isConstructor2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
map.put(m, m2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Method, Method> getMap()
|
public Multimap<Method, Method> getMap()
|
||||||
{
|
{
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.runelite.deob.deobfuscators.rename;
|
package net.runelite.deob.deobfuscators.rename;
|
||||||
|
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -116,8 +117,8 @@ public class MapStaticTest
|
|||||||
ClassGroup group1 = JarUtil.loadJar(new File(JAR1));
|
ClassGroup group1 = JarUtil.loadJar(new File(JAR1));
|
||||||
ClassGroup group2 = JarUtil.loadJar(new File(JAR2));
|
ClassGroup group2 = JarUtil.loadJar(new File(JAR2));
|
||||||
|
|
||||||
Method m1 = group1.findClass("class92").findMethod("method2176");
|
Method m1 = group1.findClass("client").findMethod("method273");
|
||||||
Method m2 = group2.findClass("client").findMethod("method540");
|
Method m2 = group2.findClass("client").findMethod("method235");
|
||||||
|
|
||||||
HashMap<Object, Object> all = new HashMap();
|
HashMap<Object, Object> all = new HashMap();
|
||||||
List<ParallelExecutorMapping> pmes = new ArrayList<>();
|
List<ParallelExecutorMapping> pmes = new ArrayList<>();
|
||||||
@@ -209,25 +210,6 @@ public class MapStaticTest
|
|||||||
map(all, pmes, m1, m2);
|
map(all, pmes, m1, m2);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 250; ++i)
|
|
||||||
{
|
|
||||||
ClassFile c1 = group1.findClass("class" + i);
|
|
||||||
ClassFile c2 = group2.findClass("class" + i);
|
|
||||||
|
|
||||||
if (c1 == null || c2 == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
MethodSignatureMapper msm = new MethodSignatureMapper();
|
|
||||||
msm.map(c1, c2);
|
|
||||||
|
|
||||||
Map<Method, Method> map = msm.getMap();
|
|
||||||
for (Entry<Method, Method> e : map.entrySet())
|
|
||||||
{
|
|
||||||
HashMap<Object, Object> all = new HashMap();
|
|
||||||
map(all, pmes, e.getKey(), e.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ParallelExecutorMapping finalm = new ParallelExecutorMapping(group1, group2);
|
ParallelExecutorMapping finalm = new ParallelExecutorMapping(group1, group2);
|
||||||
for (ParallelExecutorMapping pme : pmes)
|
for (ParallelExecutorMapping pme : pmes)
|
||||||
finalm.merge(pme);
|
finalm.merge(pme);
|
||||||
@@ -245,16 +227,16 @@ public class MapStaticTest
|
|||||||
System.out.println("GROUP 2 " + sg2);
|
System.out.println("GROUP 2 " + sg2);
|
||||||
|
|
||||||
|
|
||||||
// for (Method m : group1.findClass("client").getMethods().getMethods())
|
for (Method m : group1.findClass("client").getMethods().getMethods())
|
||||||
// {
|
{
|
||||||
// if (!finalm.getMap().containsKey(m))
|
if (!finalm.getMap().containsKey(m))
|
||||||
// System.out.println("missing " + m);
|
System.out.println("missing " + m);
|
||||||
// }
|
}
|
||||||
// for (Field m : group1.findClass("client").getFields().getFields())
|
for (Field m : group1.findClass("client").getFields().getFields())
|
||||||
// {
|
{
|
||||||
// if (!finalm.getMap().containsKey(m))
|
if (!finalm.getMap().containsKey(m))
|
||||||
// System.out.println("missing " + m);
|
System.out.println("missing " + m);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
@@ -275,11 +257,24 @@ public class MapStaticTest
|
|||||||
MethodSignatureMapper msm = new MethodSignatureMapper();
|
MethodSignatureMapper msm = new MethodSignatureMapper();
|
||||||
msm.map(c1, c2);
|
msm.map(c1, c2);
|
||||||
|
|
||||||
Map<Method, Method> map = msm.getMap();
|
Multimap<Method, Method> map = msm.getMap();
|
||||||
for (Entry<Method, Method> e : map.entrySet())
|
for (Method m : msm.getMap().keySet())
|
||||||
{
|
{
|
||||||
HashMap<Object, Object> all = new HashMap();
|
Collection<Method> methods = msm.getMap().get(m);
|
||||||
map(all, pmes, e.getKey(), e.getValue());
|
|
||||||
|
for (Method other : methods)
|
||||||
|
{
|
||||||
|
ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other);
|
||||||
|
|
||||||
|
if (pme.getMap().isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pme.map(m, other);
|
||||||
|
|
||||||
|
pmes.add(pme);
|
||||||
|
}
|
||||||
|
//HashMap<Object, Object> all = new HashMap();
|
||||||
|
//map(all, pmes, e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ParallelExecutorMapping finalm = new ParallelExecutorMapping(one, two);
|
ParallelExecutorMapping finalm = new ParallelExecutorMapping(one, two);
|
||||||
|
|||||||
Reference in New Issue
Block a user