Fix constant parameter corrupting instructions. Make unused blocks faster.
This commit is contained in:
@@ -30,10 +30,10 @@ public class Deob
|
|||||||
ClassGroup group = loadJar(args[0]);
|
ClassGroup group = loadJar(args[0]);
|
||||||
long bstart, bdur;
|
long bstart, bdur;
|
||||||
|
|
||||||
bstart = System.currentTimeMillis();
|
// bstart = System.currentTimeMillis();
|
||||||
new RenameUnique().run(group);
|
// new RenameUnique().run(group);
|
||||||
bdur = System.currentTimeMillis() - bstart;
|
// bdur = System.currentTimeMillis() - bstart;
|
||||||
System.out.println("rename unique took " + bdur/1000L + " seconds");
|
// System.out.println("rename unique took " + bdur/1000L + " seconds");
|
||||||
|
|
||||||
// remove except RuntimeException
|
// remove except RuntimeException
|
||||||
bstart = System.currentTimeMillis();
|
bstart = System.currentTimeMillis();
|
||||||
@@ -63,10 +63,10 @@ public class Deob
|
|||||||
System.out.println("constant param took " + bdur/1000L + " seconds");
|
System.out.println("constant param took " + bdur/1000L + " seconds");
|
||||||
|
|
||||||
// remove unhit blocks
|
// remove unhit blocks
|
||||||
bstart = System.currentTimeMillis();
|
// bstart = System.currentTimeMillis();
|
||||||
new UnusedBlocks().run(group);
|
// new UnusedBlocks().run(group);
|
||||||
bdur = System.currentTimeMillis() - bstart;
|
// bdur = System.currentTimeMillis() - bstart;
|
||||||
System.out.println("unused blocks took " + bdur/1000L + " seconds");
|
// System.out.println("unused blocks took " + bdur/1000L + " seconds");
|
||||||
|
|
||||||
// remove unused parameters
|
// remove unused parameters
|
||||||
bstart = System.currentTimeMillis();
|
bstart = System.currentTimeMillis();
|
||||||
@@ -78,10 +78,10 @@ public class Deob
|
|||||||
//new Jumps().run(group);
|
//new Jumps().run(group);
|
||||||
|
|
||||||
// remove unused fields
|
// remove unused fields
|
||||||
bstart = System.currentTimeMillis();
|
// bstart = System.currentTimeMillis();
|
||||||
new UnusedFields().run(group);
|
// new UnusedFields().run(group);
|
||||||
bdur = System.currentTimeMillis() - bstart;
|
// bdur = System.currentTimeMillis() - bstart;
|
||||||
System.out.println("unused fields took " + bdur/1000L + " seconds");
|
// System.out.println("unused fields took " + bdur/1000L + " seconds");
|
||||||
|
|
||||||
//new ModularArithmeticDeobfuscation().run(group);
|
//new ModularArithmeticDeobfuscation().run(group);
|
||||||
|
|
||||||
|
|||||||
@@ -424,6 +424,7 @@ public class ConstantParameter implements Deobfuscator
|
|||||||
boolean branch = op.branch; // branch that is always taken
|
boolean branch = op.branch; // branch that is always taken
|
||||||
|
|
||||||
Instructions instructions = ins.getInstructions();
|
Instructions instructions = ins.getInstructions();
|
||||||
|
instructions.buildJumpGraph();
|
||||||
|
|
||||||
// remove the if
|
// remove the if
|
||||||
if (ctx.getInstruction() instanceof If)
|
if (ctx.getInstruction() instanceof If)
|
||||||
@@ -450,6 +451,7 @@ public class ConstantParameter implements Deobfuscator
|
|||||||
}
|
}
|
||||||
assert to.getInstructions() == instructions;
|
assert to.getInstructions() == instructions;
|
||||||
assert ins != to;
|
assert ins != to;
|
||||||
|
assert instructions.getInstructions().contains(to);
|
||||||
|
|
||||||
// move things that jump here to instead jump to 'to'
|
// move things that jump here to instead jump to 'to'
|
||||||
for (Instruction fromI : ins.from)
|
for (Instruction fromI : ins.from)
|
||||||
@@ -463,10 +465,16 @@ public class ConstantParameter implements Deobfuscator
|
|||||||
|
|
||||||
instructions.remove(ins);
|
instructions.remove(ins);
|
||||||
|
|
||||||
|
assert instructions.getInstructions().contains(to);
|
||||||
|
|
||||||
if (branch)
|
if (branch)
|
||||||
{
|
{
|
||||||
|
Goto gotoins = new Goto(instructions, to);
|
||||||
|
to.from.add(gotoins);
|
||||||
|
gotoins.jump.add(to);
|
||||||
|
|
||||||
// insert goto
|
// insert goto
|
||||||
instructions.getInstructions().add(idx, new Goto(instructions, to));
|
instructions.getInstructions().add(idx, gotoins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,40 +8,43 @@ import info.sigterm.deob.attributes.code.Instructions;
|
|||||||
import info.sigterm.deob.block.Block;
|
import info.sigterm.deob.block.Block;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class UnusedBlocks implements Deobfuscator
|
public class UnusedBlocks implements Deobfuscator
|
||||||
{
|
{
|
||||||
|
private List<Method> methods = new ArrayList<>();
|
||||||
|
|
||||||
public int pass(ClassGroup group)
|
public int pass(ClassGroup group)
|
||||||
{
|
{
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
for (ClassFile cf : group.getClasses())
|
methods:
|
||||||
|
for (Method m : new ArrayList<>(methods))
|
||||||
{
|
{
|
||||||
for (Method m : new ArrayList<>(cf.getMethods().getMethods()))
|
if (m.getCode() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Instructions ins = m.getCode().getInstructions();
|
||||||
|
ins.buildBlocks();
|
||||||
|
|
||||||
|
for (int i = 0; i < ins.getBlocks().size(); ++i)
|
||||||
{
|
{
|
||||||
if (m.getCode() == null)
|
Block block = ins.getBlocks().get(i);
|
||||||
|
|
||||||
|
// first block is the entrypoint, so its always used
|
||||||
|
if (i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Instructions ins = m.getCode().getInstructions();
|
Block prev = ins.getBlocks().get(i - 1);
|
||||||
ins.buildBlocks();
|
|
||||||
|
|
||||||
for (int i = 0; i < ins.getBlocks().size(); ++i)
|
if (prev.end.isTerminal() && block.begin.from.isEmpty() && block.handlers.isEmpty())
|
||||||
{
|
{
|
||||||
Block block = ins.getBlocks().get(i);
|
ins.remove(block);
|
||||||
|
++removed;
|
||||||
// first block is the entrypoint, so its always used
|
continue methods;
|
||||||
if (i == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Block prev = ins.getBlocks().get(i - 1);
|
|
||||||
|
|
||||||
if (prev.end.isTerminal() && block.begin.from.isEmpty() && block.handlers.isEmpty())
|
|
||||||
{
|
|
||||||
ins.remove(block);
|
|
||||||
++removed;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
methods.remove(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Removed " + removed + " unused blocks");
|
System.out.println("Removed " + removed + " unused blocks");
|
||||||
@@ -51,6 +54,14 @@ public class UnusedBlocks implements Deobfuscator
|
|||||||
@Override
|
@Override
|
||||||
public void run(ClassGroup group)
|
public void run(ClassGroup group)
|
||||||
{
|
{
|
||||||
|
for (ClassFile cf : group.getClasses())
|
||||||
|
{
|
||||||
|
for (Method m : cf.getMethods().getMethods())
|
||||||
|
{
|
||||||
|
methods.add(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (pass(group) > 0);
|
while (pass(group) > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,6 +189,8 @@ public class Frame
|
|||||||
public void jump(Instruction to)
|
public void jump(Instruction to)
|
||||||
{
|
{
|
||||||
assert to != null;
|
assert to != null;
|
||||||
|
assert to.getInstructions() == method.getCode().getInstructions();
|
||||||
|
assert method.getCode().getInstructions().getInstructions().contains(to);
|
||||||
|
|
||||||
if (hasJumped(cur, to))
|
if (hasJumped(cur, to))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user