use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class ReflectionTransformer method transformInvokeVirtual.
// invokevirtual java/lang/reflect/Method/invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
private void transformInvokeVirtual(Instructions instructions, Instruction i) {
if (!(i instanceof InvokeVirtual)) {
return;
}
InvokeVirtual iv = (InvokeVirtual) i;
if (iv.getMethod().getClazz().getName().equals("java/lang/reflect/Method") && iv.getMethod().getName().equals("invoke")) {
InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "invoke", new Signature("(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;")));
instructions.replace(iv, is);
logger.info("Transformed Method.invoke call");
}
}
use of net.runelite.asm.signature.Signature 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.signature.Signature in project runelite by runelite.
the class MappingExecutorUtil method resolve.
public static InstructionContext resolve(InstructionContext ctx, // pushed from ctx
StackContext from) {
if (ctx.getInstruction() instanceof SetFieldInstruction) {
StackContext s = ctx.getPops().get(0);
return resolve(s.getPushed(), s);
}
if (ctx.getInstruction() instanceof ConversionInstruction) {
// assume it pops one and pushes one
StackContext s = ctx.getPops().get(0);
return resolve(s.getPushed(), s);
}
if (ctx.getInstruction() instanceof DupInstruction) {
DupInstruction d = (DupInstruction) ctx.getInstruction();
StackContext s = d.getOriginal(from);
return resolve(s.getPushed(), s);
}
if (ctx.getInstruction() instanceof ArrayLoad) {
// might be multidimensional array
// the array
StackContext s = ctx.getPops().get(1);
return resolve(s.getPushed(), s);
}
if (ctx.getInstruction() instanceof LVTInstruction) {
LVTInstruction lvt = (LVTInstruction) ctx.getInstruction();
Variables variables = ctx.getVariables();
if (lvt.store()) {
// is this right?
StackContext s = ctx.getPops().get(0);
return resolve(s.getPushed(), s);
} else {
// variable being loaded
VariableContext vctx = variables.get(lvt.getVariableIndex());
assert vctx != null;
InstructionContext storedCtx = vctx.getInstructionWhichStored();
if (storedCtx == null)
// initial parameter
return ctx;
if (vctx.isIsParameter()) {
// this storedCtx is the invoke instruction which called this method.
assert storedCtx.getInstruction() instanceof InvokeInstruction;
// In PME non static functions are never stepped into/aren't inline obfuscated
assert storedCtx.getInstruction() instanceof InvokeStatic;
// Figure out parameter index from variable index.
// signature of current method
Signature sig = ctx.getFrame().getMethod().getDescriptor();
int paramIndex = 0;
for (int lvtIndex = 0; /* static */
paramIndex < sig.size(); lvtIndex += sig.getTypeOfArg(paramIndex++).getSize()) if (lvtIndex == lvt.getVariableIndex())
break;
assert paramIndex < sig.size();
// Get stack context that was popped by the invoke
// pops[0] is the first thing popped, which is the last parameter.
StackContext sctx = storedCtx.getPops().get(sig.size() - 1 - paramIndex);
return resolve(sctx.getPushed(), sctx);
}
return resolve(storedCtx, null);
}
}
if (ctx.getInstruction() instanceof InvokeStatic) {
if (from.returnSource != null) {
return resolve(from.returnSource.getPushed(), from.returnSource);
}
}
return ctx;
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class ClassGroupFactory method addVoidMethod.
private static void addVoidMethod(ClassFile cf, String name) {
Method method = new Method(cf, name, new Signature("()V"));
method.setStatic();
cf.addMethod(method);
Code code = new Code(method);
method.setCode(code);
Instructions ins = code.getInstructions();
ins.addInstruction(new VReturn(ins));
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class InvokeVirtual method removeParameter.
@Override
public void removeParameter(int idx) {
net.runelite.asm.pool.Class clazz = method.getClazz();
// create new signature
Signature sig = new Signature(method.getType());
sig.remove(idx);
// create new method pool object
method = new Method(clazz, method.getName(), sig);
}
Aggregations