use of net.runelite.asm.attributes.code.instruction.types.LVTInstruction in project runelite by runelite.
the class Method method findLVTInstructionsForVariable.
@SuppressWarnings("unchecked")
public <T extends Instruction & LVTInstruction> List<T> findLVTInstructionsForVariable(int index) {
List<T> list = new ArrayList<>();
if (getCode() == null) {
return null;
}
for (Instruction ins : getCode().getInstructions().getInstructions()) {
if (ins instanceof LVTInstruction) {
LVTInstruction lv = (LVTInstruction) ins;
if (lv.getVariableIndex() != index) {
continue;
}
list.add((T) ins);
}
}
return list;
}
use of net.runelite.asm.attributes.code.instruction.types.LVTInstruction in project runelite by runelite.
the class Code method getMaxLocals.
/**
* calculates the size of the lvt required for this method
* @return
*/
public int getMaxLocals() {
int max = -1;
for (Instruction ins : instructions.getInstructions()) {
if (ins instanceof LVTInstruction) {
LVTInstruction lvt = (LVTInstruction) ins;
int sizeRequired = lvt.getVariableIndex() + lvt.type().getSlots();
if (sizeRequired > max) {
max = sizeRequired;
}
}
}
int fromSig = getMaxLocalsFromSig();
if (fromSig > max)
max = fromSig;
return max;
}
use of net.runelite.asm.attributes.code.instruction.types.LVTInstruction 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.attributes.code.instruction.types.LVTInstruction 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.attributes.code.instruction.types.LVTInstruction in project runelite by runelite.
the class PacketHandler method findReorderableReads.
public void findReorderableReads() {
for (PacketRead pr : reads) {
// InstructionContext invokeCtx = pr.getInvokeCtx();
List<Instruction> instructions = pr.getInvoke().getInstructions().getInstructions();
// look for an lvt store immediately after
int invokeIdx = instructions.indexOf(pr.getInvoke());
assert invokeIdx != -1;
Instruction next = instructions.get(invokeIdx + 1);
if (next instanceof LVTInstruction) {
LVTInstruction lvt = (LVTInstruction) next;
if (lvt.store()) {
logger.info("Found lvt store {} for {}", next, pr.getInvoke());
pr.setStore(next);
}
}
}
}
Aggregations