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