use of net.runelite.asm.execution.Frame in project runelite by runelite.
the class MappingExecutorUtil method map.
public static ParallelExecutorMapping map(Method m1, Method m2) {
ClassGroup group1 = m1.getClassFile().getGroup();
ClassGroup group2 = m2.getClassFile().getGroup();
Execution e = new Execution(group1);
e.step = true;
Frame frame = new Frame(e, m1);
frame.initialize();
e.frames.add(frame);
Execution e2 = new Execution(group2);
e2.step = true;
Frame frame2 = new Frame(e2, m2);
frame2.initialize();
e2.frames.add(frame2);
frame.other = frame2;
frame2.other = frame;
ParallellMappingExecutor parallel = new ParallellMappingExecutor(e, e2);
ParallelExecutorMapping mappings = new ParallelExecutorMapping(m1.getClassFile().getGroup(), m2.getClassFile().getGroup());
mappings.m1 = m1;
mappings.m2 = m2;
parallel.mappings = mappings;
int same = 0;
while (parallel.step()) {
// get what each frame is paused/exited on
InstructionContext p1 = parallel.getP1(), p2 = parallel.getP2();
assert p1.getInstruction() instanceof MappableInstruction;
assert p2.getInstruction() instanceof MappableInstruction;
MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(), mi2 = (MappableInstruction) p2.getInstruction();
boolean isSame = mi1.isSame(p1, p2);
assert isSame == mi2.isSame(p2, p1) : "isSame fail " + p1.getInstruction() + " <> " + p2.getInstruction();
if (!isSame) {
mappings.crashed = true;
p1.getFrame().stop();
p2.getFrame().stop();
continue;
}
++same;
mi1.map(mappings, p1, p2);
}
mappings.same = same;
return mappings;
}
use of net.runelite.asm.execution.Frame in project runelite by runelite.
the class MenuActionDeobfuscator method run.
private void run(Method method) {
if (method.getCode() == null) {
return;
}
Execution execution = new Execution(method.getClassFile().getGroup());
execution.addMethod(method);
execution.noInvoke = true;
Multimap<Integer, Comparison> comps = HashMultimap.create();
execution.addExecutionVisitor((InstructionContext ictx) -> {
Instruction i = ictx.getInstruction();
Frame frame = ictx.getFrame();
if (i instanceof If) {
// constant
InstructionContext ctx1 = ictx.getPops().get(0).getPushed();
// lvt
InstructionContext ctx2 = ictx.getPops().get(1).getPushed();
if (ctx1.getInstruction() instanceof PushConstantInstruction && ctx2.getInstruction() instanceof LVTInstruction) {
Comparison comparison = new Comparison();
comparison.cmp = i;
comparison.ldc = ctx1.getInstruction();
comparison.lvt = (LVTInstruction) ctx2.getInstruction();
comps.put(comparison.lvt.getVariableIndex(), comparison);
}
}
});
execution.run();
for (int i : comps.keySet()) {
Collection<Comparison> get = comps.get(i);
long l = get.stream().filter(c -> c.cmp.getType() == IF_ICMPGE || c.cmp.getType() == IF_ICMPGT || c.cmp.getType() == IF_ICMPLE || c.cmp.getType() == IF_ICMPLT).count();
List<Comparison> eqcmp = get.stream().filter(c -> c.cmp.getType() == IF_ICMPEQ || c.cmp.getType() == IF_ICMPNE).collect(Collectors.toList());
if (get.size() > THRESHOLD_EQ && l <= THRESHOLD_LT) {
logger.info("Sorting {} comparisons in {}", eqcmp.size(), method);
insert(method, eqcmp);
}
}
}
use of net.runelite.asm.execution.Frame in project runelite by runelite.
the class If method map.
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
assert ctx.getBranches().size() == other.getBranches().size();
// can be empty for packet handlers
if (!ctx.getBranches().isEmpty()) {
Frame branch1 = ctx.getBranches().get(0), branch2 = other.getBranches().get(0);
assert branch1.other == null;
assert branch2.other == null;
branch1.other = branch2;
branch2.other = branch1;
}
this.mapArguments(mapping, ctx, other, false);
}
use of net.runelite.asm.execution.Frame in project runelite by runelite.
the class If method execute.
@Override
public InstructionContext execute(Frame frame) {
InstructionContext ins = new InstructionContext(this, frame);
Stack stack = frame.getStack();
StackContext one = stack.pop();
StackContext two = stack.pop();
ins.pop(one, two);
Frame other = frame.dup();
other.jump(ins, to);
ins.branch(other);
return ins;
}
use of net.runelite.asm.execution.Frame in project runelite by runelite.
the class If method mapOtherBranch.
protected void mapOtherBranch(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
Frame f1 = ctx.getFrame(), f2 = other.getFrame(), branch1 = ctx.getBranches().get(0), branch2 = other.getBranches().get(0);
assert branch1.other == null;
assert branch2.other == null;
// currently f1 <-> f2
assert f1.other == f2;
assert f2.other == f1;
// change to f1 <-> branch2, f2 <-> branch1
f1.other = branch2;
branch2.other = f1;
f2.other = branch1;
branch1.other = f2;
this.mapArguments(mapping, ctx, other, true);
}
Aggregations