use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class MultiplyZeroDeobfuscator method visit.
private void visit(MethodContext mctx) {
for (InstructionContext ictx : mctx.getInstructionContexts()) {
Instruction instruction = ictx.getInstruction();
Instructions ins = instruction.getInstructions();
if (ins == null) {
continue;
}
if (!(instruction instanceof IMul) && !(instruction instanceof LMul)) {
continue;
}
List<Instruction> ilist = ins.getInstructions();
StackContext one = ictx.getPops().get(0);
StackContext two = ictx.getPops().get(1);
Instruction ione = one.getPushed().getInstruction(), itwo = two.getPushed().getInstruction();
boolean remove = false;
if (ione instanceof PushConstantInstruction) {
PushConstantInstruction pci = (PushConstantInstruction) ione;
Number value = (Number) pci.getConstant();
if (DMath.equals(value, 0)) {
remove = true;
}
}
if (itwo instanceof PushConstantInstruction) {
PushConstantInstruction pci = (PushConstantInstruction) itwo;
Number value = (Number) pci.getConstant();
if (DMath.equals(value, 0)) {
remove = true;
}
}
if (remove == false) {
continue;
}
if (!ilist.contains(instruction)) {
// already done
continue;
}
if (!MultiplicationDeobfuscator.isOnlyPath(ictx, null)) {
continue;
}
// remove both, remove imul, push 0
ictx.removeStack(1);
ictx.removeStack(0);
if (instruction instanceof IMul) {
ins.replace(instruction, new LDC(ins, 0));
} else if (instruction instanceof LMul) {
ins.replace(instruction, new LDC(ins, 0L));
} else {
throw new IllegalStateException();
}
++count;
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class Block method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Block ID ").append(id).append("\n");
if (flowsFrom != null) {
sb.append(" flows from ").append(flowsFrom.id).append("\n");
}
for (Instruction i : instructions) {
sb.append(" ").append(i.toString()).append("\n");
}
if (flowsInto != null) {
sb.append(" flows into ").append(flowsInto.id).append("\n");
}
sb.append("\n");
return sb.toString();
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ConstantParameter method removeDeadOperations.
// remove logically dead comparisons
private int removeDeadOperations(MethodContext mctx) {
int count = 0;
for (ConstantMethodParameter cmp : parameters.values()) {
if (cmp.invalid) {
continue;
}
if (!cmp.methods.contains(mctx.getMethod())) {
continue;
}
// only annotate garbage value of last param
if (cmp.paramIndex + 1 == mctx.getMethod().getDescriptor().size()) {
annotateObfuscatedSignature(cmp);
}
for (// comparisons
Instruction ins : // comparisons
cmp.operations) {
if (ins.getInstructions() == null || ins.getInstructions().getCode().getMethod() != mctx.getMethod()) {
continue;
}
InstructionContext ctx = mctx.getInstructonContexts(ins).toArray(new InstructionContext[0])[0];
// branch that is always taken
boolean branch = cmp.result;
if (ins.getInstructions() == null) {
// ins already removed?
continue;
}
Instructions instructions = ins.getInstructions();
// remove the if
if (ctx.getInstruction() instanceof If) {
ctx.removeStack(1);
}
ctx.removeStack(0);
int idx = instructions.getInstructions().indexOf(ins);
if (idx == -1) {
// already removed?
continue;
}
++count;
Instruction to;
if (branch) {
JumpingInstruction jumpIns = (JumpingInstruction) ins;
assert jumpIns.getJumps().size() == 1;
to = jumpIns.getJumps().get(0);
} else {
// just go to next instruction
to = instructions.getInstructions().get(idx + 1);
}
assert to.getInstructions() == instructions;
assert ins != to;
assert instructions.getInstructions().contains(to);
instructions.remove(ins);
assert instructions.getInstructions().contains(to);
if (branch) {
Goto gotoins = new Goto(instructions, instructions.createLabelFor(to));
// insert goto
instructions.getInstructions().add(idx, gotoins);
}
}
}
return count;
}
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, Expression expr1, Expression expr2) {
Instruction i1 = expr1.getHead().getInstruction();
Instruction i2 = expr2.getHead().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, expr1.getHead());
int hash2 = hash(method, expr2.getHead());
if (hash1 == hash2) {
logger.debug("Unable to differentiate {} from {}", expr1.getHead(), expr2.getHead());
}
return Integer.compare(hash1, hash2);
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ExprArgOrder method insert.
private void insert(Instructions ins, Instruction next, Expression expression) {
int count = 0;
if (expression.sortedExprs != null) {
for (Expression sub : expression.sortedExprs) {
if (count == 2) {
Instruction newOp;
if (isCommutative(expression.getType())) {
// there might be >2 sortedExprs so we can't reuse instructions
newOp = newInstruction(ins, expression.getHead().getInstruction(), expression.getType());
} else {
newOp = expression.getHead().getInstruction();
assert newOp.getInstructions() == null;
newOp.setInstructions(ins);
}
int idx = ins.getInstructions().indexOf(next);
assert idx != -1;
ins.addInstruction(idx, newOp);
count = 1;
}
insert(ins, next, sub);
++count;
}
}
List<Expression> reverseExpr = new ArrayList<>(expression.getExprs());
Collections.reverse(reverseExpr);
for (Expression sub : reverseExpr) {
insert(ins, next, sub);
}
insert(ins, expression.getHead(), next);
}
Aggregations