these const push instructions are also push instructions. need to fix jumps to the logically dead conditionals.

This commit is contained in:
Adam
2015-08-02 11:50:20 -04:00
parent 516fa7805f
commit 1ac0cef696
16 changed files with 247 additions and 39 deletions

View File

@@ -43,14 +43,13 @@ public class Deob
long start = System.currentTimeMillis();
ClassGroup group = loadJar(args[0]);
long bstart, bdur;
new ConstantParameter().run(group);
// long bstart = System.currentTimeMillis();
// bstart = System.currentTimeMillis();
// new RenameUnique().run(group);
// long bdur = System.currentTimeMillis() - bstart;
// bdur = System.currentTimeMillis() - bstart;
// System.out.println("rename unique took " + bdur/1000L + " seconds");
//
// // remove except RuntimeException
// bstart = System.currentTimeMillis();
// new RuntimeExceptions().run(group);
@@ -59,18 +58,21 @@ public class Deob
// new UnusedBlocks().run(group);
// bdur = System.currentTimeMillis() - bstart;
// System.out.println("runtime exception took " + bdur/1000L + " seconds");
//
// // remove unused methods
// bstart = System.currentTimeMillis();
// new UnusedMethods().run(group);
// bdur = System.currentTimeMillis() - bstart;
// System.out.println("unused methods took " + bdur/1000L + " seconds");
//
// remove unused methods
bstart = System.currentTimeMillis();
new UnusedMethods().run(group);
bdur = System.currentTimeMillis() - bstart;
System.out.println("unused methods took " + bdur/1000L + " seconds");
// // remove illegal state exceptions, frees up some parameters
// bstart = System.currentTimeMillis();
// new IllegalStateExceptions().run(group);
// bdur = System.currentTimeMillis() - bstart;
// System.out.println("illegal state exception took " + bdur/1000L + " seconds");
// remove constant logically dead parameters
new ConstantParameter().run(group);
//
// // remove unhit blocks
// bstart = System.currentTimeMillis();
@@ -103,7 +105,7 @@ public class Deob
public static boolean isObfuscated(String name)
{
return name.startsWith("method") || name.startsWith("vmethod") || name.startsWith("field") || name.startsWith("class");
return name.length() <= 2 || name.startsWith("method") || name.startsWith("vmethod") || name.startsWith("field") || name.startsWith("class");
}
private static ClassGroup loadJar(String jarfile) throws IOException

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class DConst_0 extends Instruction
public class DConst_0 extends Instruction implements PushConstantInstruction
{
public DConst_0(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class DConst_0 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Double(0.0d);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class DConst_1 extends Instruction
public class DConst_1 extends Instruction implements PushConstantInstruction
{
public DConst_1(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class DConst_1 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Double(1.0d);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class FConst_0 extends Instruction
public class FConst_0 extends Instruction implements PushConstantInstruction
{
public FConst_0(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class FConst_0 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Float(0.0f);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class FConst_1 extends Instruction
public class FConst_1 extends Instruction implements PushConstantInstruction
{
public FConst_1(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class FConst_1 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Float(1.0f);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class FConst_2 extends Instruction
public class FConst_2 extends Instruction implements PushConstantInstruction
{
public FConst_2(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class FConst_2 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Float(2.0f);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class IConst_0 extends Instruction
public class IConst_0 extends Instruction implements PushConstantInstruction
{
public IConst_0(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class IConst_0 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Integer(0);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class IConst_1 extends Instruction
public class IConst_1 extends Instruction implements PushConstantInstruction
{
public IConst_1(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class IConst_1 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Integer(1);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class IConst_2 extends Instruction
public class IConst_2 extends Instruction implements PushConstantInstruction
{
public IConst_2(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class IConst_2 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Integer(2);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class IConst_3 extends Instruction
public class IConst_3 extends Instruction implements PushConstantInstruction
{
public IConst_3(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class IConst_3 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Integer(3);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class IConst_4 extends Instruction
public class IConst_4 extends Instruction implements PushConstantInstruction
{
public IConst_4(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class IConst_4 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Integer(4);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class IConst_5 extends Instruction
public class IConst_5 extends Instruction implements PushConstantInstruction
{
public IConst_5(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class IConst_5 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Integer(5);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class IConst_M1 extends Instruction
public class IConst_M1 extends Instruction implements PushConstantInstruction
{
public IConst_M1(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class IConst_M1 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Integer(-1);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class LConst_0 extends Instruction
public class LConst_0 extends Instruction implements PushConstantInstruction
{
public LConst_0(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class LConst_0 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Long(0);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -3,14 +3,16 @@ package info.sigterm.deob.attributes.code.instructions;
import info.sigterm.deob.attributes.code.Instruction;
import info.sigterm.deob.attributes.code.InstructionType;
import info.sigterm.deob.attributes.code.Instructions;
import info.sigterm.deob.attributes.code.instruction.types.PushConstantInstruction;
import info.sigterm.deob.execution.Frame;
import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.Stack;
import info.sigterm.deob.execution.StackContext;
import info.sigterm.deob.pool.PoolEntry;
import java.io.IOException;
public class LConst_1 extends Instruction
public class LConst_1 extends Instruction implements PushConstantInstruction
{
public LConst_1(Instructions instructions, InstructionType type, int pc) throws IOException
{
@@ -30,4 +32,16 @@ public class LConst_1 extends Instruction
frame.addInstructionContext(ins);
}
@Override
public PoolEntry getConstant()
{
return new info.sigterm.deob.pool.Long(1);
}
@Override
public void setConstant(PoolEntry entry)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -134,7 +134,12 @@ public class ConstantParameter implements Deobfuscator
{
PushConstantInstruction pc = (PushConstantInstruction) ctx.getPushed().getInstruction();
if (!(pc.getConstant().getObject() instanceof Integer))
if (method.getMethods().getClassFile().getName().equals("client") && method.getName().equals("i"))
{
int i = 5;
}
if (!(pc.getConstant().getObject() instanceof Integer) && (!(pc.getConstant().getObject() instanceof Byte)))
continue;
ConstantMethodParameter cmp = new ConstantMethodParameter();
@@ -149,11 +154,6 @@ public class ConstantParameter implements Deobfuscator
if (c.equals(cmp))
continue outer;
if (method.getMethods().getClassFile().getName().equals("gy") && method.getName().equals("y"))
{
int i = 5;
}
parameters.add(cmp);
}
else
@@ -167,7 +167,7 @@ public class ConstantParameter implements Deobfuscator
if (c.methods.equals(methods) && c.lvtIndex == lvtOffset)
{
it.remove();;
it.remove();
}
}
}
@@ -241,7 +241,7 @@ public class ConstantParameter implements Deobfuscator
Instruction ins = (Instruction) comparison;
assert (comparison instanceof If0) == (otherValue == null);
assert otherValue == null || otherValue instanceof Integer;
assert otherValue == null || otherValue instanceof Integer || otherValue instanceof Byte;
switch (ins.getType())
{
@@ -514,26 +514,36 @@ public class ConstantParameter implements Deobfuscator
for (LogicallyDeadOp op : ops)
{
InstructionContext ctx = op.compCtx; // comparison
Instruction ins = ctx.getInstruction();
boolean branch = op.branch;
assert branch;
Instructions instructions = ctx.getInstruction().getInstructions();
Instructions instructions = ins.getInstructions();
// remove the if
if (ctx.getInstruction() instanceof If)
ctx.removeStack(1);
ctx.removeStack(0);
int idx = instructions.getInstructions().indexOf(ctx.getInstruction());
int idx = instructions.getInstructions().indexOf(ins);
if (idx == -1)
continue; // already removed?
JumpingInstruction jumpIns = (JumpingInstruction) ctx.getInstruction();
JumpingInstruction jumpIns = (JumpingInstruction) ins;
assert jumpIns.getJumps().size() == 1;
Instruction to = jumpIns.getJumps().get(0);
// move things that jump here to instead jump to 'to'
for (Instruction fromI : ins.from)
{
}
instructions.remove(ctx.getInstruction());
if (branch)
//assert branch;
//if (branch)
{
// insert goto
instructions.getInstructions().add(idx, new Goto(instructions, to));