use of net.runelite.asm.attributes.Code in project runelite by runelite.
the class RWOpcodeFinder method find.
public void find() {
IsaacCipherFinder ic = new IsaacCipherFinder(group);
ic.find();
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
find(ic, m, code);
}
}
logger.debug("Found readOpcode {}, writeOpcode {}", readOpcode, writeOpcode);
}
use of net.runelite.asm.attributes.Code in project runelite by runelite.
the class IsaacCipherFinder method find.
public void find() {
Method highest = null;
int count = 0;
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
int i = find(m, code);
if (i > count) {
count = i;
highest = m;
}
}
}
assert highest != null;
isaacCipher = highest.getClassFile();
// find nextInt
for (Method method : isaacCipher.getMethods()) {
if (method.getDescriptor().size() == 0 && method.getDescriptor().getReturnValue().equals(Type.INT)) {
getNext = method;
}
}
logger.debug("Found cipher {}, getNext {}", isaacCipher, getNext);
}
use of net.runelite.asm.attributes.Code in project runelite by runelite.
the class Frame method initialize.
public void initialize() {
// initialize LVT
int pos = 0;
if (!method.isStatic()) {
variables.set(pos++, new VariableContext(Type.getType(method.getClassFile().getPoolClass())).markParameter());
}
Signature descriptor = method.getDescriptor();
for (int i = 0; i < descriptor.size(); ++i) {
Type argumentType = descriptor.getTypeOfArg(i);
variables.set(pos, new VariableContext(argumentType).markParameter());
pos += argumentType.getSize();
}
Code code = method.getCode();
cur = code.getInstructions().getInstructions().get(0);
}
use of net.runelite.asm.attributes.Code in project runelite by runelite.
the class DupDeobfuscatorTest method test.
@Test
public void test() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(5);
Instruction[] prepareVariables = { new LDC(ins, 1), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 1129258489), constant2 = new LDC(ins, -1692330935), constant3 = new LDC(ins, 1641298955), constant4 = new LDC(ins, 1043501435);
Instruction[] body = { // this
new AConstNull(ins), // this
new AConstNull(ins), new ILoad(ins, 0), constant1, new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), // putfield
new Pop2(ins), constant3, new IMul(ins), constant4, new IMul(ins), // putfield
new Pop2(ins), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
assert constant3.getConstantAsInt() * constant4.getConstantAsInt() * constant1.getConstantAsInt() == 1;
Deobfuscator d = new DupDeobfuscator();
d.run(group);
// assert the dup_x1 was removed
long dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup_X1).count();
Assert.assertEquals(0, dupCount);
}
use of net.runelite.asm.attributes.Code in project runelite by runelite.
the class DupDeobfuscatorTest method test2.
// 035 aload_0 // this
// 036 dup // this this
// 037 getfield class153/field2097 I // this I
// 038 ldc 830083863
// 039 imul // this I
// 040 ldc 830083863
// 041 iadd // this I
// 042 dup_x1 // I this I
@Test
public void test2() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(3);
Instruction[] body = { // this
new AConstNull(ins), // this this
new Dup(ins), new GetField(ins, new Field(new Class("test"), "field", Type.INT)), // this this I I
new LDC(ins, 830083863), // this this I
new IMul(ins), new LDC(ins, 830083863), new IAdd(ins), new Dup_X1(ins), new LDC(ins, 636900519), // pops dup
new IMul(ins), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
Deobfuscator d = new DupDeobfuscator();
d.run(group);
// assert the dup wasn't duplicated
long dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup).count();
Assert.assertEquals(1, dupCount);
// assert the dup_x1 was removed
dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup_X1).count();
Assert.assertEquals(0, dupCount);
}
Aggregations