use of net.runelite.asm.execution.Execution in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test13.
// sipush 512
// ldc -688421113
// imul
// ldc -585812297
// imul
// putstatic class134/field2009 I
@Test
public void test13() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
LDC constant1 = new LDC(ins, -688421113);
LDC constant2 = new LDC(ins, -585812297);
Instruction[] body = { new SiPush(ins, (short) 512), 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());
}
use of net.runelite.asm.execution.Execution in project runelite by runelite.
the class MultiplyOneDeobfuscatorTest method test2.
// iconst_1
// iconst_m1
// iload 5
// if_icmpeq LABEL0x56d1
// iload 5
// iconst_1
// if_icmpne LABEL0x56e8
// goto LABEL0x56d1
// LABEL0x56d1:
// getstatic class139/field2130 I
// ldc_w -1440517609
// imul
// goto LABEL0x5708
// LABEL0x56e8:
// getstatic class139/field2130 I
// ldc_w -1440517609
// imul
// getstatic client/field377 I
// iadd
// iconst_2
// idiv
// LABEL0x5708:
// imul
// putstatic client/field377 I
//
// client.field377 = 1 * (-1 != var5 && var5 != 1?(class139.field2130 + client.field377) / 2:class139.field2130);
@Test
public void test2() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
// vars[0] = 3
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0), new LDC(ins, 2), new IStore(ins, 1) };
for (Instruction i : prepareVariables) ins.addInstruction(i);
Label label = new Label(ins), label2 = new Label(ins), label3 = new Label(ins);
LDC one = new LDC(ins, 1);
IMul mul = new IMul(ins);
Instruction[] body = { one, new LDC(ins, -1), new ILoad(ins, 0), new IfICmpEq(ins, label), new Goto(ins, label2), label, new ILoad(ins, 1), new LDC(ins, -1440517609), new IDiv(ins), new Goto(ins, label3), label2, new ILoad(ins, 1), new LDC(ins, -1440517609), new IDiv(ins), label3, mul, new VReturn(ins) };
for (Instruction i : body) ins.addInstruction(i);
// check execution runs ok
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
Deobfuscator d = new MultiplyOneDeobfuscator(false);
d.run(group);
Assert.assertTrue(one.getInstructions() == null);
Assert.assertTrue(mul.getInstructions() == null);
}
use of net.runelite.asm.execution.Execution in project runelite by runelite.
the class InvokeSpecial method execute.
@Override
public InstructionContext execute(Frame frame) {
InstructionContext ins = new InstructionContext(this, frame);
Stack stack = frame.getStack();
int count = method.getType().size();
for (int i = 0; i < count; ++i) {
StackContext arg = stack.pop();
ins.pop(arg);
}
StackContext object = stack.pop();
ins.pop(object);
if (!method.getType().isVoid()) {
StackContext ctx = new StackContext(ins, method.getType().getReturnValue(), Value.UNKNOWN);
stack.push(ctx);
ins.push(ctx);
}
if (myMethod != null) {
ins.invoke(myMethod);
assert myMethod.getCode() != null;
// add possible method call to execution
Execution execution = frame.getExecution();
execution.invoke(ins, myMethod);
frame.getExecution().order(frame, myMethod);
}
return ins;
}
use of net.runelite.asm.execution.Execution in project runelite by runelite.
the class Deob method run.
private static void run(ClassGroup group, Deobfuscator deob) {
Stopwatch stopwatch = Stopwatch.createStarted();
deob.run(group);
stopwatch.stop();
logger.info("{} took {}", deob.getClass().getSimpleName(), stopwatch);
// check code is still correct
if (CHECK_EXEC) {
Execution execution = new Execution(group);
execution.populateInitialMethods();
execution.run();
}
}
use of net.runelite.asm.execution.Execution in project runelite by runelite.
the class ModArith method runOnce.
public int runOnce() {
group.buildClassGraph();
pairs.clear();
fieldInfo.clear();
execution = new Execution(group);
execution.addMethodContextVisitor(i -> findUses(i));
execution.addMethodContextVisitor(i -> findConstants(i));
execution.populateInitialMethods();
execution.run();
guess();
int i = 0;
Encryption encr = new Encryption();
for (Pair pair : pairs) {
logger.debug("Processing {} getter {} setter {}", pair.field.getName(), pair.getter, pair.setter);
encr.addPair(pair);
// sum total
encryption.addPair(pair);
++i;
}
logger.info("Done processing {}", i);
if (i > 0) {
insertGetterSetterMuls(encr);
}
return i;
}
Aggregations