use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction in project runelite by runelite.
the class ArrayStore method map.
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
assert ctx.getInstruction().getClass() == other.getInstruction().getClass();
Field myField = this.getMyField(ctx), otherField = ((ArrayStore) other.getInstruction()).getMyField(other);
mapping.map(this, myField, otherField);
// map value
StackContext // value set to.
object1 = ctx.getPops().get(0), object2 = other.getPops().get(0);
InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1);
InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2);
if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
assert MappingExecutorUtil.isMaybeEqual(f1, f2);
if (f1 != null && f2 != null) {
mapping.map(this, f1, f2);
}
}
}
use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction in project runelite by runelite.
the class InvokeVirtual method isSame.
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc) {
if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass()) {
return false;
}
InvokeVirtual thisIi = (InvokeVirtual) thisIc.getInstruction(), otherIi = (InvokeVirtual) otherIc.getInstruction();
if (!MappingExecutorUtil.isMaybeEqual(thisIi.method.getType(), otherIi.method.getType())) {
return false;
}
List<net.runelite.asm.Method> thisMethods = thisIi.getMethods(), otherMethods = otherIi.getMethods();
if (thisMethods.size() != otherMethods.size()) {
return false;
}
for (int i = 0; i < thisMethods.size(); ++i) {
net.runelite.asm.Method m1 = thisMethods.get(i);
net.runelite.asm.Method m2 = otherMethods.get(i);
// were loaded, which might not be the same
if (!MappingExecutorUtil.isMaybeEqual(m1.getDescriptor(), m2.getDescriptor())) {
return false;
}
// descriptors for all methods must be the same
break;
}
/* check arguments */
assert thisIc.getPops().size() == otherIc.getPops().size();
for (int i = 0; i < thisIc.getPops().size(); ++i) {
StackContext s1 = thisIc.getPops().get(i), s2 = otherIc.getPops().get(i);
InstructionContext base1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
InstructionContext base2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
if (!MappingExecutorUtil.isMaybeEqual(f1, f2)) {
return false;
}
}
}
/* check field that was invoked on */
StackContext object1 = thisIc.getPops().get(thisIi.method.getType().size()), object2 = otherIc.getPops().get(otherIi.method.getType().size());
InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1);
InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2);
if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
if (!MappingExecutorUtil.isMaybeEqual(f1, f2)) {
return false;
}
}
return true;
}
use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction in project runelite by runelite.
the class InvokeStatic method map.
@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
List<net.runelite.asm.Method> myMethods = this.getMethods(), otherMethods = ((InvokeStatic) other.getInstruction()).getMethods();
assert myMethods.size() == otherMethods.size();
for (int i = 0; i < myMethods.size(); ++i) {
mapping.map(this, myMethods.get(i), otherMethods.get(i));
}
for (int i = 0; i < ctx.getPops().size(); ++i) {
StackContext s1 = ctx.getPops().get(i), s2 = other.getPops().get(i);
InstructionContext base1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
InstructionContext base2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
if (f1 != null && f2 != null) {
mapping.map(this, f1, f2);
}
}
}
}
use of net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction 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.types.GetFieldInstruction 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;
}
Aggregations