seemed promising. doesn't really help.

This commit is contained in:
Adam
2015-11-16 19:48:51 -05:00
parent ceafe5acec
commit 139b31f2ac
4 changed files with 83 additions and 74 deletions

View File

@@ -45,7 +45,7 @@ public class Rename
}
Map<Integer, Integer> mapping = isoTest.findIsomorphism(g1, g2);
Map<Integer, Instruction> map1 = f1.getMethodCtx().getIdMap(), map2 = f2.getMethodCtx().getIdMap();
Map<Integer, List<Method>> map1 = f1.getMethodCtx().getIdMap(), map2 = f2.getMethodCtx().getIdMap();
for (Entry<Integer, Integer> e : mapping.entrySet())
{
@@ -55,24 +55,26 @@ public class Rename
// continue;
// }
Instruction i1 = map1.get(e.getKey());
Instruction i2 = map2.get(e.getValue());
List<Method> i1 = map1.get(e.getKey());
List<Method> i2 = map2.get(e.getValue());
assert i1.getClass() == i2.getClass();
//assert i1.getClass() == i2.getClass();
InvokeInstruction ii1 = (InvokeInstruction) i1, ii2 = (InvokeInstruction) i2;
//InvokeInstruction ii1 = (InvokeInstruction) i1, ii2 = (InvokeInstruction) i2;
assert ii1.getMethods().size() == ii2.getMethods().size();
//assert ii1.getMethods().size() == ii2.getMethods().size();
for (int i = 0; i < ii1.getMethods().size(); ++i)
assert i1.size() == i2.size();
for (int i = 0; i < i1.size(); ++i)
{
Method m1 = ii1.getMethods().get(i), m2 = ii2.getMethods().get(i);
Method m1 = i1.get(i), m2 = i2.get(i);
// assert objMap.containsKey(m1) == false || objMap.get(m1) == m2;
objMap.put(m1, m2);
}
System.out.println("MATCH " + ii1.getMethods().get(0).getName() + " -> " + ii2.getMethods().get(0).getName());
System.out.println("MATCH " + i1.get(0).getName() + " -> " + i2.get(0).getName());
}
return true;

View File

@@ -24,7 +24,7 @@ public class Execution
processedFrames = new LinkedList<>();
public Set<Method> methods = new HashSet<>(); // all methods
public Set<Instruction> executed = new HashSet<>(); // executed instructions
private MultiValueMap<InstructionContext, Method> invokes = new MultiValueMap<>();
private MultiValueMap<MIKey, Method> invokes = new MultiValueMap<>();
private Encryption encryption;
public MultiValueMap<Instruction, InstructionContext> contexts = new MultiValueMap<>();
private Map<Method, MethodContext> methodContexts = new HashMap<>();
@@ -101,11 +101,13 @@ public class Execution
private boolean hasInvoked(InstructionContext from, Method to)
{
Collection<Method> methods = invokes.getCollection(from);
Frame frame = from.getFrame();
MIKey key = new MIKey(frame.prevVertex.intValue(), from);
Collection<Method> methods = invokes.getCollection(key);
if (methods != null && methods.contains(to))
return true;
invokes.put(from, to);
invokes.put(key, to);
return false;
}
@@ -119,8 +121,8 @@ public class Execution
if (!this.isFollowInvokes() && !to.isStatic())
return;
// if (hasInvoked(from, to))
// return;
if (hasInvoked(from, to))
return;
Frame f = new Frame(this, to);
f.initialize(from);
@@ -151,11 +153,9 @@ public class Execution
assert frames.get(0) == frame;
frames.remove(0);
processedFrames.add(frame);
System.out.println(fcount + "/" + frames.size());
}
else
{
System.out.println("deferring");
// another frame takes priority
}
}

View File

@@ -0,0 +1,51 @@
package net.runelite.deob.execution;
import java.util.Objects;
class MIKey
{
private int prevVertex;
private InstructionContext ictx;
public MIKey(int prevVertex, InstructionContext ictx)
{
this.prevVertex = prevVertex;
this.ictx = ictx;
}
@Override
public int hashCode()
{
int hash = 7;
hash = 97 * hash + this.prevVertex;
hash = 97 * hash + Objects.hashCode(this.ictx);
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final MIKey other = (MIKey) obj;
if (this.prevVertex != other.prevVertex)
{
return false;
}
if (!Objects.equals(this.ictx, other.ictx))
{
return false;
}
return true;
}
}

View File

@@ -17,61 +17,13 @@ import net.runelite.deob.util.IdGen;
import org.apache.commons.collections4.map.MultiValueMap;
import org.apache.commons.lang3.mutable.MutableInt;
class MIKey
{
private int prevVertex;
private InstructionContext ictx;
public MIKey(int prevVertex, InstructionContext ictx)
{
this.prevVertex = prevVertex;
this.ictx = ictx;
}
@Override
public int hashCode()
{
int hash = 7;
hash = 97 * hash + this.prevVertex;
hash = 97 * hash + Objects.hashCode(this.ictx);
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final MIKey other = (MIKey) obj;
if (this.prevVertex != other.prevVertex)
{
return false;
}
if (!Objects.equals(this.ictx, other.ictx))
{
return false;
}
return true;
}
}
public class MethodContext
{
private Execution execution;
private MultiValueMap<MIKey, Instruction> visited = new MultiValueMap<>();
private IdGen ids = new IdGen();
private Map<Integer, Instruction> idMap = new HashMap<>();
private Map<Instruction, Integer> insMap = new HashMap<>();
private Map<Integer, List<Method>> idMap = new HashMap<>();
private Map<List<Method>, Integer> insMap = new HashMap<>();
private Graph graph = new SparseDirectedGraph();
public MethodContext(Execution execution)
@@ -79,7 +31,7 @@ public class MethodContext
this.execution = execution;
}
public Map<Integer, Instruction> getIdMap()
public Map<Integer, List<Method>> getIdMap()
{
return idMap;
}
@@ -101,11 +53,13 @@ public class MethodContext
return false;
}
private int getIdFor(Instruction i)
private int getIdFor(List<Method> i)
{
if (insMap.containsKey(i))
return insMap.get(i);
assert idMap.values().contains(i) == false;
int id = ids.get();
//graph.add(id);
@@ -121,6 +75,7 @@ public class MethodContext
if (!execution.isBuildGraph())
return;
List<Method> methods;
if (i instanceof InvokeInstruction)
{
if (i instanceof InvokeStatic)
@@ -128,7 +83,7 @@ public class MethodContext
InvokeInstruction ii = (InvokeInstruction) i;
List<Method> methods = ii.getMethods();
methods = ii.getMethods();
if (methods.isEmpty())
return;
}
@@ -146,7 +101,7 @@ public class MethodContext
if (frame.prevVertex.intValue() == -1)
{
int id = getIdFor(i);
int id = getIdFor(methods);
//int id = ids.get();
//graph.add(id);
frame.prevVertex.setValue(id);
@@ -154,7 +109,7 @@ public class MethodContext
return;
}
int id = getIdFor(i);
int id = getIdFor(methods);
//int id = ids.get();
//graph.add(id);
//idMap.put(id, i);
@@ -162,9 +117,10 @@ public class MethodContext
if (frame.prevVertex.intValue() == id)
return;
InvokeInstruction from = (InvokeInstruction) this.idMap.get(frame.prevVertex.intValue()), to = (InvokeInstruction) this.idMap.get(id);
System.out.println("Added edge " + from.getMethods().get(0).getMethods().getClassFile().getName() + "." + from.getMethods().get(0).getName() +
" to " + to.getMethods().get(0).getMethods().getClassFile().getName() + "." + to.getMethods().get(0).getName());
List<Method> from = this.idMap.get(frame.prevVertex.intValue()), to = this.idMap.get(id);
System.out.println("Added edge " + from.get(0).getMethods().getClassFile().getName() + "." + from.get(0).getName() +
" to " + to.get(0).getMethods().getClassFile().getName() + "." + to.get(0).getName() +
" (" + frame.prevVertex.intValue() + " -> " + id + ")");
DirectedEdge edge = new SimpleDirectedEdge(frame.prevVertex.intValue(), id);
graph.add(edge);