one/zero? obs arent handling stuff right, add test. now im setting null on instructions some places they fail

This commit is contained in:
Adam
2015-10-22 09:53:56 -04:00
parent bd2e62c22f
commit 2f5f9861ef
5 changed files with 100 additions and 11 deletions

View File

@@ -92,9 +92,9 @@ public class Deob
{
new MultiplicationDeobfuscator().run(group);
new MultiplyOneDeobfuscator().run(group);
//new MultiplyOneDeobfuscator().run(group);
new MultiplyZeroDeobfuscator().run(group);
//new MultiplyZeroDeobfuscator().run(group);
if (last == cur)
{

View File

@@ -84,17 +84,10 @@ public class Instructions
public void remove(Instruction ins)
{
// for (Instruction i : instructions)
// {
// if (i instanceof JumpingInstruction)
// {
// JumpingInstruction j = (JumpingInstruction) i;
// assert !j.getJumps().contains(ins);
// }
// }
assert ins.getInstructions() == this;
ins.remove();
instructions.remove(ins);
ins.setInstructions(null);
}
public void remove(Block block)
@@ -293,5 +286,7 @@ public class Instructions
for (net.runelite.deob.attributes.code.Exception e : code.getExceptions().getExceptions())
e.replace(oldi, newi);
oldi.setInstructions(null);
}
}

View File

@@ -23,6 +23,12 @@ public class SiPush extends Instruction implements PushConstantInstruction
super(instructions, type, pc);
}
public SiPush(Instructions instructions, short value)
{
super(instructions, InstructionType.SIPUSH, -1);
s = value;
}
@Override
public void load(DataInputStream is) throws IOException
{

View File

@@ -474,7 +474,15 @@ public class ModArith implements Deobfuscator
Pair p = this.guess2(f, col2, set);
if (p != null)
{
if (this.deobfuscatedFields.contains(f))
continue;
pairs.add(p);
this.deobfuscatedFields.add(f);
}
}
}
}

View File

@@ -0,0 +1,80 @@
package net.runelite.deob.deobfuscators.arithmetic;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.ClassGroupFactory;
import net.runelite.deob.Deobfuscator;
import net.runelite.deob.attributes.Code;
import net.runelite.deob.attributes.code.Instruction;
import net.runelite.deob.attributes.code.Instructions;
import net.runelite.deob.attributes.code.instructions.Goto;
import net.runelite.deob.attributes.code.instructions.IConst_1;
import net.runelite.deob.attributes.code.instructions.IConst_2;
import net.runelite.deob.attributes.code.instructions.IConst_3;
import net.runelite.deob.attributes.code.instructions.ILoad;
import net.runelite.deob.attributes.code.instructions.IMul;
import net.runelite.deob.attributes.code.instructions.IStore_0;
import net.runelite.deob.attributes.code.instructions.If0;
import net.runelite.deob.attributes.code.instructions.NOP;
import net.runelite.deob.attributes.code.instructions.SiPush;
import net.runelite.deob.attributes.code.instructions.VReturn;
import net.runelite.deob.execution.Execution;
import org.junit.Assert;
import org.junit.Test;
public class MultiplyOneDeobfuscatorTest
{
@Test
public void test()
{
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
// vars[0] = 3
Instruction[] prepareVariables = {
new IConst_3(ins),
new IStore_0(ins)
};
for (Instruction i : prepareVariables)
ins.addInstruction(i);
NOP label = new NOP(ins),
label2 = new NOP(ins);
IConst_1 one = new IConst_1(ins);
Instruction body[] = {
new SiPush(ins, (short) 256),
new ILoad(ins, 0),
new If0(ins, label),
new IConst_2(ins),
new Goto(ins, label2),
label,
one,
label2,
new IMul(ins),
new VReturn(ins)
};
for (Instruction i : body)
ins.addInstruction(i);
// check execution runs ok
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
Deobfuscator d = new MultiplyOneDeobfuscator();
d.run(group);
Assert.assertTrue(one.getInstructions() != null);
}
}