use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ClientErrorTransformer method transform.
private void transform(Method m) {
if (!m.isStatic() || m.getDescriptor().size() != 2 || !m.getDescriptor().getTypeOfArg(0).equals(Type.STRING) || !m.getDescriptor().getTypeOfArg(1).equals(Type.THROWABLE))
return;
Code code = m.getCode();
Instructions ins = code.getInstructions();
/*
Makes it so the old code in this method is logically dead,
letting the mapper map it but making it so it's never executed.
*/
// load throwable
Instruction aload0 = new ALoad(ins, 1);
IfNull ifNull = new IfNull(ins, InstructionType.IFNULL);
ifNull.setTo(ins.createLabelFor(ins.getInstructions().get(0)));
// load throwable
Instruction aload1 = new ALoad(ins, 1);
InvokeVirtual printStackTrace = new InvokeVirtual(ins, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("java/lang/Throwable"), "printStackTrace", new Signature("()V")));
Instruction ret = new VReturn(ins);
ins.addInstruction(0, aload0);
ins.addInstruction(1, ifNull);
ins.addInstruction(2, aload1);
ins.addInstruction(3, printStackTrace);
ins.addInstruction(4, ret);
done = true;
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ReflectionTransformer method transform.
private void transform(Method method) {
Code code = method.getCode();
if (code == null) {
return;
}
Instructions ins = code.getInstructions();
for (Instruction i : new ArrayList<>(ins.getInstructions())) {
transformFindClass(i);
transformMethodName(ins, i);
transformGetParameterTypes(ins, i);
transformGetDeclaredField(ins, i);
transformSetInt(ins, i);
transformGetInt(ins, i);
transformInvokeVirtual(ins, i);
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class BufferFinder method findModPow.
// Find encryptRsa in buffer
private boolean findModPow(Code code) {
if (code == null) {
return false;
}
Instructions instructions = code.getInstructions();
for (Instruction i : instructions.getInstructions()) {
if (!(i instanceof InvokeVirtual)) {
continue;
}
InvokeVirtual iv = (InvokeVirtual) i;
net.runelite.asm.pool.Method method = iv.getMethod();
if (method.getName().equals("modPow")) {
return true;
}
}
return false;
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class RuneliteBufferTransformer method injectLengthHeader.
/**
* inject the length header after the packet opcode
*
* @param group
*/
private void injectLengthHeader(ClassGroup group) {
RWOpcodeFinder rw = new RWOpcodeFinder(group);
rw.find();
Method writeOpcode = rw.getWriteOpcode();
Code code = writeOpcode.getCode();
Instructions instructions = code.getInstructions();
List<Instruction> ins = instructions.getInstructions();
Instruction start = ins.get(0);
Instruction end = ins.stream().filter(i -> i.getType() == RETURN).findFirst().get();
Label labelForStart = instructions.createLabelFor(start);
Label labelForEnd = instructions.createLabelFor(end);
final net.runelite.asm.pool.Field runelitePacketField = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(findClient(group).getName()), RUNELITE_PACKET, Type.BOOLEAN);
int idx = ins.indexOf(labelForStart);
instructions.addInstruction(idx++, new GetStatic(instructions, runelitePacketField));
instructions.addInstruction(idx++, new IfEq(instructions, labelForStart));
net.runelite.asm.pool.Method method = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(writeOpcode.getClassFile().getName()), RUNELITE_FINISH_PACKET, new Signature("()V"));
instructions.addInstruction(idx++, new ALoad(instructions, 0));
instructions.addInstruction(idx++, new InvokeVirtual(instructions, method));
idx = ins.indexOf(labelForEnd);
instructions.addInstruction(idx++, new GetStatic(instructions, runelitePacketField));
instructions.addInstruction(idx++, new IfEq(instructions, labelForEnd));
method = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(writeOpcode.getClassFile().getName()), RUNELITE_INIT_PACKET, new Signature("()V"));
instructions.addInstruction(idx++, new ALoad(instructions, 0));
instructions.addInstruction(idx++, new InvokeVirtual(instructions, method));
logger.info("Injected finish/init packet calls into {}", writeOpcode);
}
use of net.runelite.asm.attributes.code.Instruction 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);
}
}
}
Aggregations