illegal state exception deob, ff doesnt fully like it yet though

This commit is contained in:
Adam
2015-06-19 23:30:03 -04:00
parent d3142d83ce
commit 98d85c646b
7 changed files with 114 additions and 3 deletions

View File

@@ -230,6 +230,12 @@ public class Method
code.buildCallGraph();
}
public void clearCallGraph()
{
callsTo.clear();
callsFrom.clear();
}
public boolean isUsed()
{
if (!callsFrom.isEmpty())

View File

@@ -98,9 +98,7 @@ public class Instructions
public void buildBlocks()
{
for (Instruction i : instructions)
i.block = null;
blocks.clear();
clearBlockGraph();
Block current = null;
for (Instruction i : instructions)
@@ -122,6 +120,13 @@ public class Instructions
}
}
public void clearBlockGraph()
{
for (Instruction i : instructions)
i.block = null;
blocks.clear();
}
public void write(DataOutputStream out) throws IOException
{
// generate pool indexes

View File

@@ -24,6 +24,13 @@ public class Goto extends Instruction implements JumpingInstruction
length += 2;
}
public Goto(Instructions instructions, Instruction to)
{
super(instructions, InstructionType.GOTO, 0);
this.to = to;
length += 2;
}
@Override
public void resolve()
{

View File

@@ -67,4 +67,9 @@ public class If extends Instruction implements JumpingInstruction
if (to == oldi)
to = newi;
}
public Instruction getTo()
{
return to;
}
}

View File

@@ -68,4 +68,9 @@ public class If0 extends Instruction implements JumpingInstruction
if (to == oldi)
to = newi;
}
public Instruction getTo()
{
return to;
}
}

View File

@@ -45,4 +45,9 @@ public class New extends Instruction
frame.addInstructionContext(ins);
}
public Class getNewClass()
{
return clazz;
}
}

View File

@@ -0,0 +1,78 @@
package info.sigterm.deob.deobfuscators;
import info.sigterm.deob.ClassFile;
import info.sigterm.deob.ClassGroup;
import info.sigterm.deob.Method;
import info.sigterm.deob.attributes.Code;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instructions.AThrow;
import info.sigterm.deob.attributes.code.instructions.Goto;
import info.sigterm.deob.attributes.code.instructions.If;
import info.sigterm.deob.attributes.code.instructions.If0;
import info.sigterm.deob.attributes.code.instructions.New;
import java.util.ArrayList;
import java.util.List;
public class IllegalStateExceptions
{
/* find if, new, ..., athrow, replace with goto */
public void run(ClassGroup group)
{
int count = 0;
for (ClassFile cf : group.getClasses())
{
for (Method m : new ArrayList<>(cf.getMethods().getMethods()))
{
Code c = m.getCode();
if (c == null)
continue;
Instructions instructions = c.getInstructions();
instructions.clearBlockGraph();
List<Instruction> ilist = instructions.getInstructions();
for (int i = 0; i < ilist.size(); ++i)
{
Instruction ins = ilist.get(i);
if (!(ins instanceof If) && !(ins instanceof If0))
continue;
Instruction ins2 = ilist.get(i + 1);
if (!(ins2 instanceof New))
continue;
New new2 = (New) ins2;
info.sigterm.deob.pool.Class clazz = new2.getNewClass();
if (!clazz.getName().equals("java/lang/IllegalStateException"))
continue;
Instruction to = null;
if (ins instanceof If)
to = ((If) ins).getTo();
else if (ins instanceof If0)
to = ((If0) ins).getTo();
// remove up to athrow
do
{
instructions.remove(ins);
ins = ilist.get(i); // don't need to ++i because
}
while (!(ins instanceof AThrow));
// remove athrow
instructions.remove(ins);
// insert goto
ilist.add(i, new Goto(instructions, to));
++count;
}
}
}
System.out.println("Removed " + count + " illegal state exceptions");
}
}