From 8efd637a8729c545652c0224c21c163dc9c1f32f Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 12 Feb 2016 15:34:52 -0500 Subject: [PATCH] Attempt to map non static methods using PME too --- .../rename/MethodSignatureMapper.java | 44 ++++++------- .../deobfuscators/rename/MapStaticTest.java | 65 +++++++++---------- 2 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java b/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java index bfcf70b700..ae88ea1d94 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MethodSignatureMapper.java @@ -1,44 +1,42 @@ package net.runelite.deob.deobfuscators.rename; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; 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 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 o = methods.getMethods().stream().filter(m -> m.getDescriptor().equals(sig)).findFirst(); - return o.isPresent() ? o.get() : null; - } + private Multimap map = ArrayListMultimap.create(); public void map(ClassFile c1, ClassFile c2) { for (Method m : c1.getMethods().getMethods()) { - if (m.isStatic() || count(c1.getMethods(), m.getDescriptor()) > 1) + if (m.isStatic() || m.getCode() == null) continue; - Method other = get(c2.getMethods(), m.getDescriptor()); - if (other == null) - continue; + boolean isConstructor = m.getName().equals(""); - 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(""); + + if (isConstructor != isConstructor2) + continue; + + map.put(m, m2); + } } } - public Map getMap() + public Multimap getMap() { return map; } diff --git a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java index adc9405a94..a833c2446e 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/rename/MapStaticTest.java @@ -1,5 +1,6 @@ package net.runelite.deob.deobfuscators.rename; +import com.google.common.collect.Multimap; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -116,8 +117,8 @@ public class MapStaticTest ClassGroup group1 = JarUtil.loadJar(new File(JAR1)); ClassGroup group2 = JarUtil.loadJar(new File(JAR2)); - Method m1 = group1.findClass("class92").findMethod("method2176"); - Method m2 = group2.findClass("client").findMethod("method540"); + Method m1 = group1.findClass("client").findMethod("method273"); + Method m2 = group2.findClass("client").findMethod("method235"); HashMap all = new HashMap(); List pmes = new ArrayList<>(); @@ -209,25 +210,6 @@ public class MapStaticTest 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 map = msm.getMap(); - for (Entry e : map.entrySet()) - { - HashMap all = new HashMap(); - map(all, pmes, e.getKey(), e.getValue()); - } - } - ParallelExecutorMapping finalm = new ParallelExecutorMapping(group1, group2); for (ParallelExecutorMapping pme : pmes) finalm.merge(pme); @@ -245,16 +227,16 @@ public class MapStaticTest System.out.println("GROUP 2 " + sg2); -// for (Method m : group1.findClass("client").getMethods().getMethods()) -// { -// if (!finalm.getMap().containsKey(m)) -// System.out.println("missing " + m); -// } -// for (Field m : group1.findClass("client").getFields().getFields()) -// { -// if (!finalm.getMap().containsKey(m)) -// System.out.println("missing " + m); -// } + for (Method m : group1.findClass("client").getMethods().getMethods()) + { + if (!finalm.getMap().containsKey(m)) + System.out.println("missing " + m); + } + for (Field m : group1.findClass("client").getFields().getFields()) + { + if (!finalm.getMap().containsKey(m)) + System.out.println("missing " + m); + } } //@Test @@ -275,11 +257,24 @@ public class MapStaticTest MethodSignatureMapper msm = new MethodSignatureMapper(); msm.map(c1, c2); - Map map = msm.getMap(); - for (Entry e : map.entrySet()) + Multimap map = msm.getMap(); + for (Method m : msm.getMap().keySet()) { - HashMap all = new HashMap(); - map(all, pmes, e.getKey(), e.getValue()); + Collection methods = msm.getMap().get(m); + + for (Method other : methods) + { + ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other); + + if (pme.getMap().isEmpty()) + continue; + + pme.map(m, other); + + pmes.add(pme); + } + //HashMap all = new HashMap(); + //map(all, pmes, e.getKey(), e.getValue()); } } ParallelExecutorMapping finalm = new ParallelExecutorMapping(one, two);