1/0 works once again, maybe.

This commit is contained in:
Adam
2015-10-22 11:01:43 -04:00
parent 2f5f9861ef
commit 5f6b01f4a0
4 changed files with 71 additions and 3 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

@@ -1,6 +1,9 @@
package net.runelite.deob.deobfuscators.arithmetic;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.runelite.deob.ClassGroup;
import net.runelite.deob.Deobfuscator;
import net.runelite.deob.attributes.code.Instruction;
@@ -35,6 +38,9 @@ public class MultiplyOneDeobfuscator implements Deobfuscator
continue;
Instructions ins = ictx.getInstruction().getInstructions();
if (ins == null)
continue;
List<Instruction> ilist = ins.getInstructions();
if (!ilist.contains(ictx.getInstruction()))
@@ -58,6 +64,9 @@ public class MultiplyOneDeobfuscator implements Deobfuscator
if (removeIdx == -1)
continue;
if (!MultiplicationDeobfuscator.isOnlyPath(e, ictx))
continue;
ictx.removeStack(removeIdx);
ins.replace(ictx.getInstruction(), new NOP(ins));
//ins.remove(ictx.getInstruction());

View File

@@ -31,6 +31,8 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator
{
Instruction instruction = ictx.getInstruction();
Instructions ins = instruction.getInstructions();
if (ins == null)
continue;
if (!(instruction instanceof IMul))
continue;
@@ -69,6 +71,9 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator
if (!ilist.contains(instruction))
continue; // already done
if (!MultiplicationDeobfuscator.isOnlyPath(e, ictx))
continue;
// remove both, remove imul, push 0
ictx.removeStack(1);

View File

@@ -24,7 +24,7 @@ import org.junit.Test;
public class MultiplyOneDeobfuscatorTest
{
@Test
public void test()
public void testDir()
{
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
@@ -77,4 +77,58 @@ public class MultiplyOneDeobfuscatorTest
Assert.assertTrue(one.getInstructions() != null);
}
@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);
IMul mul = new IMul(ins);
Instruction body[] = {
new SiPush(ins, (short) 256),
new ILoad(ins, 0),
new If0(ins, label),
label,
one,
label2,
mul,
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);
Assert.assertTrue(mul.getInstructions() == null);
}
}