use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class DupDeobfuscator method copy.
/**
* copy the instruction which pushed sctx and insert into instructions
* starting at index idx
*/
private int copy(StackContext sctx, Instructions instructions, int idx) {
InstructionContext ictx = sctx.getPushed();
if (ictx.getInstruction() instanceof DupInstruction) {
// we only care about one path
DupInstruction di = (DupInstruction) ictx.getInstruction();
sctx = di.getOriginal(sctx);
ictx = sctx.getPushed();
}
// the first thing popped was pushed last, so reverse
for (StackContext s : Lists.reverse(ictx.getPops())) {
idx = copy(s, instructions, idx);
}
// copy instruction
Instruction i = ictx.getInstruction();
logger.debug("Duplicating instruction {} at index {}", i, idx);
i = i.clone();
instructions.addInstruction(idx, i);
// move on to next instruction
return idx + 1;
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class PutField method canMap.
@Override
public boolean canMap(InstructionContext thisIc) {
StackContext value = thisIc.getPops().get(0);
Instruction i = value.getPushed().getInstruction();
// which are all constants, so we ignore those mappings here
if (thisIc.getFrame().getMethod().getName().equals("<init>")) {
if (i instanceof PushConstantInstruction || i instanceof AConstNull) {
return false;
}
}
return true;
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ExprArgOrder method hash.
private static void hash(Method method, MessageDigest sha256, InstructionContext ic) {
Instruction i = ic.getInstruction();
// this relies on all push constants are converted to ldc..
sha256.update((byte) i.getType().getCode());
if (i instanceof PushConstantInstruction) {
PushConstantInstruction pci = (PushConstantInstruction) i;
Object constant = pci.getConstant();
if (constant instanceof Number) {
long l = ((Number) constant).longValue();
sha256.update(Longs.toByteArray(l));
}
} else if (i instanceof LVTInstruction) {
int idx = ((LVTInstruction) i).getVariableIndex();
Signature signature = method.getDescriptor();
int lvt = method.isStatic() ? 0 : 1;
for (Type type : signature.getArguments()) {
if (idx == lvt) {
// Accessing a method parameter
sha256.update(Ints.toByteArray(idx));
break;
}
lvt += type.getSize();
}
}
for (StackContext sctx : ic.getPops()) {
hash(method, sha256, sctx.getPushed());
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ExprArgOrder method compare.
public static int compare(Method method, InstructionType type, InstructionContext ic1, InstructionContext ic2) {
Instruction i1 = ic1.getInstruction();
Instruction i2 = ic2.getInstruction();
if (type == IF_ICMPEQ || type == IF_ICMPNE || type == IADD || type == IMUL) {
if (!(i1 instanceof PushConstantInstruction) && (i2 instanceof PushConstantInstruction)) {
return 1;
}
if (i1 instanceof PushConstantInstruction && !(i2 instanceof PushConstantInstruction)) {
return -1;
}
}
if (type == IF_ACMPEQ || type == IF_ACMPNE) {
if (!(i1 instanceof AConstNull) && (i2 instanceof AConstNull)) {
return 1;
}
if (i1 instanceof AConstNull && !(i2 instanceof AConstNull)) {
return -1;
}
}
int hash1 = hash(method, ic1);
int hash2 = hash(method, ic2);
if (hash1 == hash2) {
logger.debug("Unable to differentiate {} from {}", ic1, ic2);
}
return Integer.compare(hash1, hash2);
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ExprArgOrder method visit.
private void visit(MethodContext ctx) {
Instructions ins = ctx.getMethod().getCode().getInstructions();
for (Instruction i : exprIns) {
Expression expression = exprs.get(i);
assert expression != null;
if (!canRemove(ctx, ins, i)) {
continue;
}
int idx = ins.getInstructions().indexOf(expression.getHead().getInstruction());
assert idx != -1;
// get next instruction
Instruction next = ins.getInstructions().get(idx + 1);
;
// remove expression
remove(ins, expression.getHead());
// sort expression
expression.sort(ctx);
// insert expression
insert(ins, next, expression);
++count;
}
exprIns.clear();
exprs.clear();
}
Aggregations