remove stack of ifs in illegal state ex deob, get rid of using pcs in
frame to execute, need to remove more of this later, make jumps jump to instructions, doesn't yet work
This commit is contained in:
@@ -11,16 +11,22 @@ 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 info.sigterm.deob.execution.Execution;
|
||||
import info.sigterm.deob.execution.Frame;
|
||||
import info.sigterm.deob.execution.InstructionContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class IllegalStateExceptions
|
||||
{
|
||||
/* find if, new, ..., athrow, replace with goto */
|
||||
public void run(ClassGroup group)
|
||||
private int checkOnce(Execution execution, ClassGroup group)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (ClassFile cf : group.getClasses())
|
||||
{
|
||||
for (Method m : new ArrayList<>(cf.getMethods().getMethods()))
|
||||
@@ -55,13 +61,43 @@ public class IllegalStateExceptions
|
||||
else if (ins instanceof If0)
|
||||
to = ((If0) ins).getTo();
|
||||
|
||||
// remove stack of if.
|
||||
boolean found = false;
|
||||
for (Frame f : execution.processedFrames)
|
||||
if (f.getMethod() == m)
|
||||
for (InstructionContext ic : f.getInstructions())
|
||||
if (ic.getInstruction() == ins) // this is the if
|
||||
{
|
||||
found = true;
|
||||
|
||||
if (ins instanceof If)
|
||||
ic.removeStack(1);
|
||||
ic.removeStack(0);
|
||||
}
|
||||
assert found;
|
||||
|
||||
// instruction is no longer at 'i' because we've just removed stuff...
|
||||
i = ilist.indexOf(ins);
|
||||
|
||||
// remove up to athrow
|
||||
do
|
||||
while (!(ins instanceof AThrow))
|
||||
{
|
||||
// modify instructions which jump to here to instead jump to 'to'
|
||||
|
||||
for (Instruction from : ins.from)
|
||||
{
|
||||
from.jump.remove(ins);
|
||||
//ins.from.remove(from);
|
||||
|
||||
from.replace(ins, to);
|
||||
|
||||
from.jump.add(to);
|
||||
}
|
||||
ins.from.clear();
|
||||
|
||||
instructions.remove(ins);
|
||||
ins = ilist.get(i); // don't need to ++i because
|
||||
}
|
||||
while (!(ins instanceof AThrow));
|
||||
|
||||
// remove athrow
|
||||
instructions.remove(ins);
|
||||
@@ -70,9 +106,30 @@ public class IllegalStateExceptions
|
||||
ilist.add(i, new Goto(instructions, to));
|
||||
|
||||
++count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Removed " + count + " illegal state exceptions");
|
||||
return count;
|
||||
}
|
||||
|
||||
public void run(ClassGroup group)
|
||||
{
|
||||
Execution execution = new Execution(group);
|
||||
execution.run();
|
||||
|
||||
int count = 0;
|
||||
int passes = 0;
|
||||
int i;
|
||||
do
|
||||
{
|
||||
i = checkOnce(execution, group);
|
||||
|
||||
count += i;
|
||||
++passes;
|
||||
}
|
||||
while (i > 0);
|
||||
|
||||
System.out.println("Removed " + count + " illegal state exceptions in " + passes + " passes");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user