this wont work because exception handlers arent run so it wont see all returns

This commit is contained in:
Adam
2016-02-13 17:07:01 -05:00
parent 8efd637a87
commit 66e9960596
4 changed files with 84 additions and 53 deletions

View File

@@ -11,11 +11,13 @@ import net.runelite.deob.attributes.code.instruction.types.DupInstruction;
import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction;
import net.runelite.deob.attributes.code.instruction.types.LVTInstruction;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.attributes.code.instruction.types.ReturnInstruction;
import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction;
import net.runelite.deob.attributes.code.instructions.InvokeStatic;
import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Frame;
import net.runelite.deob.execution.InstructionContext;
import net.runelite.deob.execution.MethodContext;
import net.runelite.deob.execution.ParallellMappingExecutor;
import net.runelite.deob.execution.StackContext;
import net.runelite.deob.execution.VariableContext;
@@ -86,6 +88,9 @@ public class MappingExecutorUtil
frame.other = frame2;
frame2.other = frame;
MethodContext ctx1 = frame.getMethodCtx(),
ctx2 = frame2.getMethodCtx();
ParallellMappingExecutor parallel = new ParallellMappingExecutor(e, e2);
ParallelExecutorMapping mappings = new ParallelExecutorMapping(m1.getMethods().getClassFile().getGroup(),
m2.getMethods().getClassFile().getGroup());
@@ -184,9 +189,31 @@ public class MappingExecutorUtil
e.paused = e2.paused = false;
}
// if (mappings.getMap().isEmpty() == false)
// {
// checkReturns(m1, ctx1);
// }
return mappings;
}
//static boolean hit;
private static boolean checkReturns(Method method, MethodContext ctx)
{
List<Instruction> ins = method.getCode().getInstructions().getInstructions().stream().filter(i -> i instanceof ReturnInstruction).collect(Collectors.toList());
List<Instruction> exc = ctx.instructions.stream().map(i -> i.getInstruction()).collect(Collectors.toList());
for (Instruction i : ins)
{
if (!exc.contains(i))
{
return false;
}
}
return true;
}
//private static boolean containsMappableInstruction
public static boolean isMappable(InvokeInstruction ii)
{

View File

@@ -236,9 +236,12 @@ public class Frame
}
InstructionContext ictx = this.instructions.get(this.instructions.size() - 1);
assert ictx.getInstruction() == oldCur;
execution.contexts.put(oldCur, ictx);
this.ctx.instructions.add(ictx);
execution.executed.add(oldCur);
processExceptions(oldCur);

View File

@@ -1,7 +1,8 @@
package net.runelite.deob.execution;
import java.util.ArrayList;
import java.util.Collection;
import net.runelite.deob.Field;
import java.util.List;
import net.runelite.deob.attributes.code.Instruction;
import org.apache.commons.collections4.map.MultiValueMap;
@@ -9,6 +10,7 @@ public class MethodContext
{
private Execution execution;
private MultiValueMap<InstructionContext, Instruction> visited = new MultiValueMap<>();
public List<InstructionContext> instructions = new ArrayList<>();
public MethodContext(Execution execution)
{

View File

@@ -117,8 +117,8 @@ public class MapStaticTest
ClassGroup group1 = JarUtil.loadJar(new File(JAR1));
ClassGroup group2 = JarUtil.loadJar(new File(JAR2));
Method m1 = group1.findClass("client").findMethod("method273");
Method m2 = group2.findClass("client").findMethod("method235");
Method m1 = group1.findClass("client").findMethod("method585");
Method m2 = group2.findClass("class44").findMethod("method930");
HashMap<Object, Object> all = new HashMap();
List<ParallelExecutorMapping> pmes = new ArrayList<>();
@@ -200,15 +200,15 @@ public class MapStaticTest
assert m1s.size() == m2s.size();
List<ParallelExecutorMapping> pmes = new ArrayList<>();
for (int i = 0; i < m1s.size(); ++i)
{
Method m1 = m1s.get(i), m2 = m2s.get(i);
assert m1.getPoolMethod().equals(m2.getPoolMethod());
HashMap<Object, Object> all = new HashMap();
map(all, pmes, m1, m2);
}
// for (int i = 0; i < m1s.size(); ++i)
// {
// Method m1 = m1s.get(i), m2 = m2s.get(i);
//
// assert m1.getPoolMethod().equals(m2.getPoolMethod());
//
// HashMap<Object, Object> all = new HashMap();
// map(all, pmes, m1, m2);
// }
ParallelExecutorMapping finalm = new ParallelExecutorMapping(group1, group2);
for (ParallelExecutorMapping pme : pmes)
@@ -246,10 +246,20 @@ public class MapStaticTest
// ClassGroup two = JarUtil.loadJar(new File(JAR2));
List<ParallelExecutorMapping> pmes = new ArrayList<>();
for (int i = 0; i < 250; ++i)
for (int i = -1; i < 250; ++i)
{
ClassFile c1 = one.findClass("class" + i);
ClassFile c2 = two.findClass("class" + i);
ClassFile c1, c2;
if (i == -1)
{
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;
@@ -258,20 +268,22 @@ public class MapStaticTest
msm.map(c1, c2);
Multimap<Method, Method> map = msm.getMap();
for (Method m : msm.getMap().keySet())
for (Method m : map.keySet())
{
Collection<Method> methods = msm.getMap().get(m);
Collection<Method> methods = map.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<Object, Object> all = new HashMap();
map(all, pmes, m, other);
// 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());
@@ -305,17 +317,17 @@ public class MapStaticTest
{
for (Method other : methods)
{
ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other);
HashMap<Object, Object> all = new HashMap();
map(all, pmes, m, other);
if (pme.getMap().isEmpty())
continue;
// HashMap<Object, Object> all = new HashMap();
// map(all, pmes, m, other);
pme.map(m, other);
pmes.add(pme);
//System.out.println(m + " " + other + " " + pme.getMap().size());
// ParallelExecutorMapping pme = MappingExecutorUtil.map(m, other);
//
// if (pme.getMap().isEmpty())
// continue;
//
// pme.map(m, other);
//
// pmes.add(pme);
}
}
}
@@ -378,25 +390,12 @@ public class MapStaticTest
if (m1.getName().equals("vmethod3096"))
return;
if (m1.getName().equals("method32"))
{
int i=5;
}
ParallelExecutorMapping mappings = MappingExecutorUtil.map(m1, m2);
ParallelExecutorMapping
// try
// {
mappings = MappingExecutorUtil.map(m1, m2);
// }
// catch (Throwable ex)
// {
// ex.printStackTrace();
// System.err.println("Error mapping " + m1 + " to " + m2);
// //if (test)
// // throw ex;
// return;
// }
if (mappings.getMap().isEmpty())
return;
mappings.map(m1, m2);
result.add(mappings);
for (Entry<Object, Object> e : mappings.getMap().entrySet())