use of net.runelite.asm.execution.Execution 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.Execution 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.Execution in project runelite by runelite.
the class HandlerFinder method prepareFrame.
private void prepareFrame(Execution e, PacketHandlers handlers) {
List<Method> methods = handlers.getHandlers().stream().map(handler -> handler.getMethod()).distinct().collect(Collectors.toList());
for (Method method : methods) {
List<PacketHandler> phandlers = handlers.getHandlers().stream().filter(handler -> handler.getMethod() == method).collect(Collectors.toList());
prepareFrame(e, method, phandlers);
}
}
use of net.runelite.asm.execution.Execution in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test1.
// aload 2
// ldc_w 1587543155
// iload 4
// imul
// dup_x1
// ldc_w -2130376517
// imul
// putfield class2/field279 I
// ldc_w -67313687
// imul
// putstatic class29/field949 I
@Test
public void test1() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(5);
// vars[0] = 3
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 1587543155), constant2 = new LDC(ins, -2130376517), constant3 = new LDC(ins, -67313687);
Instruction[] body = { // for dup_x1 to place before this
new LDC(ins, 0), constant1, new ILoad(ins, 0), new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), new Pop(ins), new Pop(ins), constant3, new IMul(ins), new Pop(ins), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
// check execution runs ok
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
assert constant1.getConstantAsInt() * constant3.getConstantAsInt() == -1_095_175_765;
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
Assert.assertEquals(-1_095_175_765, constant3.getConstantAsInt());
}
use of net.runelite.asm.execution.Execution in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test4.
@Test
public void test4() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 1807370871);
LDC constant2 = new LDC(ins, 981643079);
Label label1 = new Label(ins);
Instruction[] body = { new ILoad(ins, 0), new LDC(ins, 2), new IMul(ins), new LDC(ins, 0), new IfEq(ins, label1), new Pop(ins), new LDC(ins, 3), label1, constant1, new IMul(ins), constant2, new IMul(ins), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
}
Aggregations