illegal state exception deob, ff doesnt fully like it yet though
This commit is contained in:
@@ -230,6 +230,12 @@ public class Method
|
|||||||
code.buildCallGraph();
|
code.buildCallGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearCallGraph()
|
||||||
|
{
|
||||||
|
callsTo.clear();
|
||||||
|
callsFrom.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isUsed()
|
public boolean isUsed()
|
||||||
{
|
{
|
||||||
if (!callsFrom.isEmpty())
|
if (!callsFrom.isEmpty())
|
||||||
|
|||||||
@@ -98,9 +98,7 @@ public class Instructions
|
|||||||
|
|
||||||
public void buildBlocks()
|
public void buildBlocks()
|
||||||
{
|
{
|
||||||
for (Instruction i : instructions)
|
clearBlockGraph();
|
||||||
i.block = null;
|
|
||||||
blocks.clear();
|
|
||||||
|
|
||||||
Block current = null;
|
Block current = null;
|
||||||
for (Instruction i : instructions)
|
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
|
public void write(DataOutputStream out) throws IOException
|
||||||
{
|
{
|
||||||
// generate pool indexes
|
// generate pool indexes
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ public class Goto extends Instruction implements JumpingInstruction
|
|||||||
length += 2;
|
length += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Goto(Instructions instructions, Instruction to)
|
||||||
|
{
|
||||||
|
super(instructions, InstructionType.GOTO, 0);
|
||||||
|
this.to = to;
|
||||||
|
length += 2;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve()
|
public void resolve()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -67,4 +67,9 @@ public class If extends Instruction implements JumpingInstruction
|
|||||||
if (to == oldi)
|
if (to == oldi)
|
||||||
to = newi;
|
to = newi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Instruction getTo()
|
||||||
|
{
|
||||||
|
return to;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,4 +68,9 @@ public class If0 extends Instruction implements JumpingInstruction
|
|||||||
if (to == oldi)
|
if (to == oldi)
|
||||||
to = newi;
|
to = newi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Instruction getTo()
|
||||||
|
{
|
||||||
|
return to;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,4 +45,9 @@ public class New extends Instruction
|
|||||||
|
|
||||||
frame.addInstructionContext(ins);
|
frame.addInstructionContext(ins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class getNewClass()
|
||||||
|
{
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user