use of net.runelite.asm.attributes.code.instructions.AConstNull 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);
}
use of net.runelite.asm.attributes.code.instructions.AConstNull in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test12.
// 020 aload_0
// 021 aload_0
// 022 iload_1
// 023 ldc 1129258489
// 024 imul // this, this, mul
// 025 swap // this, mul s, this
// 026 iload_1
// 027 iconst_1
// 028 imul // this, mul s, this, mul
// 029 iconst_1
// 030 imul
// 031 putfield class81/field1351 I // this, mul
// 032 iconst_1
// 033 imul
// 034 ldc -1692330935
// 035 imul
// 036 putfield class81/field1326 I
@Test
public void test12() {
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);
LDC constant2 = new LDC(ins, -1692330935);
Instruction[] body = { // this
new AConstNull(ins), // this
new AConstNull(ins), new ILoad(ins, 0), constant1, new IMul(ins), // null, mul, null
new Swap(ins), new ILoad(ins, 0), // putfield
new Pop2(ins), constant2, 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;
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
}
use of net.runelite.asm.attributes.code.instructions.AConstNull in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test11.
// 020 aload_0
// 021 aload_0
// 022 iload_1
// 023 ldc 1129258489
// 024 imul
// 025 dup_x1
// 026 ldc -1692330935
// 027 imul
// 028 putfield class81/field1351 I
// 029 ldc 1641298955
// 030 imul // this pops other side of dup_x1
// 031 ldc 1043501435
// 032 imul
// 033 putfield class81/field1326 I
@Test
public void test11() {
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 MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
Assert.assertEquals(1, constant3.getConstantAsInt());
Assert.assertEquals(1, constant4.getConstantAsInt());
}
use of net.runelite.asm.attributes.code.instructions.AConstNull in project runelite by runelite.
the class LvtTest method testReuseIndex.
@Test
public void testReuseIndex() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
Instruction[] body = { // var0 = null
new AConstNull(ins), new AStore(ins, 0), // this forces a reindex to varn
new LDC(ins, 0), new IStore(ins, 0), // var2 = null
new AConstNull(ins), new AStore(ins, 2), // this forces a reindex to varn+1
new LDC(ins, 0), new IStore(ins, 2), // var0 = 0L
new LDC(ins, 0L), new LStore(ins, 0), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
Lvt lvt = new Lvt();
lvt.run(group);
AStore astore1 = (AStore) body[1];
IStore istore1 = (IStore) body[3];
AStore astore2 = (AStore) body[5];
IStore istore2 = (IStore) body[7];
LStore lstore1 = (LStore) body[9];
int astore1Idx = astore1.getVariableIndex();
int istore1Idx = istore1.getVariableIndex();
int astore2Idx = astore2.getVariableIndex();
int istore2Idx = istore2.getVariableIndex();
int lstore1Idx = lstore1.getVariableIndex();
logger.debug("{} -> {}", astore1, astore1.getVariableIndex());
logger.debug("{} -> {}", istore1, istore1.getVariableIndex());
logger.debug("{} -> {}", astore2, astore2.getVariableIndex());
logger.debug("{} -> {}", istore2, istore2.getVariableIndex());
logger.debug("{} -> {}", lstore1, lstore1.getVariableIndex());
Assert.assertNotEquals(astore1Idx, istore1Idx);
Assert.assertNotEquals(astore2Idx, istore2Idx);
// assert that the lstore doesn't overwrite an existing index
Assert.assertNotEquals(lstore1Idx + 1, astore1Idx);
Assert.assertNotEquals(lstore1Idx + 1, istore1Idx);
Assert.assertNotEquals(lstore1Idx + 1, astore2Idx);
Assert.assertNotEquals(lstore1Idx + 1, istore2Idx);
}
use of net.runelite.asm.attributes.code.instructions.AConstNull 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);
}
Aggregations