use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class CodeVisitor method visitLabel.
@Override
public void visitLabel(Label label) {
Instruction i = code.getInstructions().findOrCreateLabel(label);
code.getInstructions().addInstruction(i);
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ModArith method insertGetterSetterMuls.
private void insertGetterSetterMuls(Encryption encr) {
// before setfield insert imul * getter
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
if (code == null) {
continue;
}
Instructions ins = code.getInstructions();
List<Instruction> ilist = ins.getInstructions();
for (int i = 0; i < ilist.size(); ++i) {
Instruction in = ilist.get(i);
if (in instanceof SetFieldInstruction) {
SetFieldInstruction sfi = (SetFieldInstruction) in;
Field f = sfi.getMyField();
if (f == null) {
continue;
}
Pair p = encr.getField(f.getPoolField());
if (p == null) {
continue;
}
// insert imul
if (p.getType() == Integer.class) {
ilist.add(i++, new LDC(ins, (int) p.getter));
ilist.add(i++, new IMul(ins));
} else if (p.getType() == Long.class) {
ilist.add(i++, new LDC(ins, (long) p.getter));
ilist.add(i++, new LMul(ins));
} else {
throw new IllegalStateException();
}
} else if (in instanceof GetFieldInstruction) {
GetFieldInstruction sfi = (GetFieldInstruction) in;
Field f = sfi.getMyField();
if (f == null) {
continue;
}
Pair p = encr.getField(f.getPoolField());
if (p == null) {
continue;
}
// imul
if (p.getType() == Integer.class) {
ilist.add(++i, new LDC(ins, (int) p.setter));
ilist.add(++i, new IMul(ins));
} else if (p.getType() == Long.class) {
ilist.add(++i, new LDC(ins, (long) p.setter));
ilist.add(++i, new LMul(ins));
} else {
throw new IllegalStateException();
}
}
}
}
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class MultiplicationDeobfuscator method visit.
private void visit(MethodContext ctx) {
for (InstructionContext ictx : ctx.getInstructionContexts()) {
Instruction instruction = ictx.getInstruction();
if (!(instruction instanceof IMul) && !(instruction instanceof LMul)) {
continue;
}
MultiplicationExpression expression;
try {
expression = parseExpression(ictx, instruction.getClass());
} catch (IllegalStateException ex) {
continue;
}
if (expression == null) {
continue;
}
if (done.contains(instruction)) {
continue;
}
done.add(instruction);
assert instruction instanceof IMul || instruction instanceof LMul;
if (instruction instanceof IMul) {
count += expression.simplify(1);
} else if (instruction instanceof LMul) {
count += expression.simplify(1L);
} else {
throw new IllegalStateException();
}
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class MultiplicationExpression method simplify.
int simplify(Number start) {
int count = 0;
Number result = start;
// calculate result
for (InstructionContext i : instructions) {
PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction();
Number value = (Number) pci.getConstant();
result = DMath.multiply(result, value);
}
if (dupmagic != null) {
// mul dupmagic by result of dup ins?
PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction();
Number value = (Number) pci.getConstant();
for (InstructionContext ic : dupedInstructions) {
PushConstantInstruction pci2 = (PushConstantInstruction) ic.getInstruction();
Number value2 = (Number) pci2.getConstant();
value = DMath.multiply(value, value2);
}
Instruction newIns = pci.setConstant(value);
assert newIns == (Instruction) pci;
}
// multiply subexpressions by result
if (!subexpressions.isEmpty()) {
for (MultiplicationExpression me : subexpressions) {
count += me.simplify(result);
}
if (dupmagic != null) {
PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction();
Number value = (Number) pci.getConstant();
value = DMath.multiply(value, DMath.modInverse(result));
pci.setConstant(value);
}
// constant has been distributed, outer numbers all go to 1
if (result instanceof Long)
result = 1L;
else
result = 1;
}
// set result on ins
for (InstructionContext i : instructions) {
PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction();
Instruction newIns = pci.setConstant(result);
++count;
assert newIns == pci;
// rest of the results go to 1
if (result instanceof Long)
result = 1L;
else
result = 1;
}
return count;
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ControlFlowDeobfuscator method runJumpLabel.
/**
* remove jumps followed immediately by the label they are jumping to
*
* @param code
*/
private void runJumpLabel(Code code) {
Instructions ins = code.getInstructions();
List<Instruction> instructions = ins.getInstructions();
for (int i = 0; i < instructions.size() - 1; ++i) {
Instruction i1 = instructions.get(i), i2 = instructions.get(i + 1);
if (!(i1 instanceof Goto)) {
continue;
}
Goto g = (Goto) i1;
assert g.getJumps().size() == 1;
if (g.getJumps().get(0) != i2) {
continue;
}
// remove jump
ins.remove(i1);
++removedJumps;
// i now points to i2, so next loop we go to next instruction
}
}
Aggregations