use of net.runelite.asm.attributes.code.instructions.LDC in project runelite by runelite.
the class CodeVisitor method visitInsn.
@Override
public void visitInsn(int opcode) {
switch(opcode) {
case DCONST_0:
{
Instruction i = new LDC(code.getInstructions(), 0d);
code.getInstructions().addInstruction(i);
break;
}
case DCONST_1:
{
Instruction i = new LDC(code.getInstructions(), 1d);
code.getInstructions().addInstruction(i);
break;
}
case FCONST_0:
{
Instruction i = new LDC(code.getInstructions(), 0f);
code.getInstructions().addInstruction(i);
break;
}
case FCONST_1:
{
Instruction i = new LDC(code.getInstructions(), 1f);
code.getInstructions().addInstruction(i);
break;
}
case FCONST_2:
{
Instruction i = new LDC(code.getInstructions(), 2f);
code.getInstructions().addInstruction(i);
break;
}
case ICONST_M1:
{
Instruction i = new LDC(code.getInstructions(), -1);
code.getInstructions().addInstruction(i);
break;
}
case ICONST_0:
{
Instruction i = new LDC(code.getInstructions(), 0);
code.getInstructions().addInstruction(i);
break;
}
case ICONST_1:
{
{
Instruction i = new LDC(code.getInstructions(), 1);
code.getInstructions().addInstruction(i);
break;
}
}
case ICONST_2:
{
Instruction i = new LDC(code.getInstructions(), 2);
code.getInstructions().addInstruction(i);
break;
}
case ICONST_3:
{
Instruction i = new LDC(code.getInstructions(), 3);
code.getInstructions().addInstruction(i);
break;
}
case ICONST_4:
{
Instruction i = new LDC(code.getInstructions(), 4);
code.getInstructions().addInstruction(i);
break;
}
case ICONST_5:
{
Instruction i = new LDC(code.getInstructions(), 5);
code.getInstructions().addInstruction(i);
break;
}
case LCONST_0:
{
Instruction i = new LDC(code.getInstructions(), 0L);
code.getInstructions().addInstruction(i);
break;
}
case LCONST_1:
{
Instruction i = new LDC(code.getInstructions(), 1L);
code.getInstructions().addInstruction(i);
break;
}
default:
createInstructionFromOpcode(opcode);
}
}
use of net.runelite.asm.attributes.code.instructions.LDC in project runelite by runelite.
the class CodeVisitor method visitLdcInsn.
@Override
public void visitLdcInsn(Object cst) {
Object entry = cst;
if (cst instanceof org.objectweb.asm.Type) {
org.objectweb.asm.Type t = (org.objectweb.asm.Type) cst;
entry = new net.runelite.asm.pool.Class((String) t.getClassName());
}
LDC ldc = new LDC(code.getInstructions(), entry);
code.getInstructions().addInstruction(ldc);
}
use of net.runelite.asm.attributes.code.instructions.LDC 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.instructions.LDC in project runelite by runelite.
the class MultiplicationDeobfuscator method parseExpression.
public static MultiplicationExpression parseExpression(InstructionContext ctx, Class want) {
MultiplicationExpression me = new MultiplicationExpression();
if (ctx.getInstruction() instanceof LVTInstruction) {
LVTInstruction lvt = (LVTInstruction) ctx.getInstruction();
// loading a variable
if (!lvt.store()) {
// var index
int idx = lvt.getVariableIndex();
// variables at time of execution
Variables vars = ctx.getVariables();
// get the variable
VariableContext vctx = vars.get(idx);
if (// ?
vctx.getRead().size() == 1) {
// this is an istore
InstructionContext storeCtx = vctx.getInstructionWhichStored();
if (storeCtx.getInstruction() instanceof LVTInstruction) {
// invoking funcs can put stuff in lvt
LVTInstruction storelvt = (LVTInstruction) storeCtx.getInstruction();
if (storelvt instanceof IInc)
throw new IllegalStateException();
assert storelvt.store();
InstructionContext pushed = storeCtx.getPops().get(0).getPushed();
return parseExpression(pushed, want);
}
}
}
}
if (ctx.getInstruction() instanceof PushConstantInstruction) {
if (ctx.getInstruction() instanceof BiPush || ctx.getInstruction() instanceof SiPush) {
throw new IllegalStateException();
}
me.instructions.add(ctx);
return me;
}
for (StackContext sctx : ctx.getPops()) {
if (ctx.getInstruction().getClass() == want) {
if (!isOnlyPath(ctx, sctx))
continue;
}
InstructionContext i = sctx.getPushed();
// if this instruction is imul, look at pops
if (ctx.getInstruction().getClass() == want) {
if (i.getInstruction() instanceof Swap) {
logger.debug("Resolving swap");
Swap swap = (Swap) i.getInstruction();
sctx = swap.getOriginal(sctx);
i = sctx.getPushed();
}
if (i.getInstruction() instanceof PushConstantInstruction) {
// bipush/sipush are always not obfuscated
if (i.getInstruction() instanceof BiPush || i.getInstruction() instanceof SiPush)
continue;
// a constant of imul
me.instructions.add(i);
} else if (i.getInstruction().getClass() == want) {
// chained imul, append to me
try {
MultiplicationExpression other = parseExpression(i, want);
if (other.dupmagic != null) {
assert me.dupmagic == null;
me.dupmagic = other.dupmagic;
}
me.instructions.addAll(other.instructions);
me.dupedInstructions.addAll(other.dupedInstructions);
me.subexpressions.addAll(other.subexpressions);
} catch (IllegalStateException ex) {
// this is ok? just don't include it?
}
} else if (i.getInstruction() instanceof IAdd || i.getInstruction() instanceof ISub || i.getInstruction() instanceof LAdd || i.getInstruction() instanceof LSub) {
// imul using result of iadd or isub. evaluate expression
try {
MultiplicationExpression other = parseExpression(i, want);
assert other.dupmagic == null;
// subexpr
me.subexpressions.add(other);
} catch (IllegalStateException ex) {
assert me.subexpressions.isEmpty();
// subexpression is too complex. we can still simplify the top level though
}
} else if (i.getInstruction() instanceof DupInstruction) {
DupInstruction dup = (DupInstruction) i.getInstruction();
// find other branch of the dup instruction
// sctx = what dup pushed, find other
// other side of dup
StackContext otherCtx = dup.getOtherBranch(sctx);
// what popped other side of dup. is this right?
InstructionContext otherCtxI = otherCtx.getPopped().get(0);
if (otherCtxI.getInstruction().getClass() == want) {
// assert otherCtxI.getInstruction() instanceof IMul;
// other side of that imul
InstructionContext pushConstant = otherCtxI.getPops().get(0).getPushed();
assert pushConstant.getInstruction() instanceof LDC;
me.dupmagic = pushConstant;
// original
StackContext orig = dup.getOriginal(sctx);
try {
MultiplicationExpression other = parseExpression(orig.getPushed(), want);
// done to it affect that, too. so multiply it by existing values?
if (orig.getPushed().getInstruction() instanceof IAdd || orig.getPushed().getInstruction() instanceof ISub || orig.getPushed().getInstruction() instanceof LAdd || orig.getPushed().getInstruction() instanceof LSub) {
me.subexpressions.add(other);
} else {
assert other.dupmagic == null;
me.instructions.addAll(other.instructions);
me.dupedInstructions.addAll(other.instructions);
me.subexpressions.addAll(other.subexpressions);
}
} catch (IllegalStateException ex) {
assert me.subexpressions.isEmpty();
}
}
} else if (i.getInstruction() instanceof GetFieldInstruction) {
me.fieldInstructions.add(i);
// non constant, ignore
} else {
// System.out.println("imul pops something I don't know " + i.getInstruction());
}
} else // this is an iadd/sub
if (ctx.getInstruction() instanceof IAdd || ctx.getInstruction() instanceof ISub || ctx.getInstruction() instanceof LAdd || ctx.getInstruction() instanceof LSub) {
// parse this side of the add/sub
MultiplicationExpression other = parseExpression(i, want);
me.subexpressions.add(other);
} else {
// System.out.println(ctx.getInstruction() + " pops something I dont know " + i.getInstruction());
}
}
if (me.instructions.isEmpty() && me.subexpressions.isEmpty())
throw new IllegalStateException();
return me;
}
use of net.runelite.asm.attributes.code.instructions.LDC in project runelite by runelite.
the class FieldInliner method inlineUse.
public int inlineUse() {
int count = 0;
for (Field f : fields) {
// replace getfield with constant push
List<FieldInstruction> fins = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof GetFieldInstruction).collect(Collectors.toList());
Object value = f.getValue();
for (FieldInstruction fin : fins) {
// remove fin, add push constant
Instruction i = (Instruction) fin;
Instruction pushIns = new LDC(i.getInstructions(), value);
List<Instruction> instructions = i.getInstructions().getInstructions();
int idx = instructions.indexOf(i);
assert idx != -1;
i.getInstructions().remove(i);
instructions.add(idx, pushIns);
++count;
}
f.getClassFile().removeField(f);
}
return count;
}
Aggregations