Use less memory in constant param. Seems to run with -Xmx512m

This commit is contained in:
Adam
2016-04-08 14:35:52 -04:00
parent 7336c49d21
commit 08950e3717
2 changed files with 73 additions and 56 deletions

View File

@@ -28,57 +28,57 @@ public class Deob
ClassGroup group = JarUtil.loadJar(new File(args[0]));
// run(group, new RenameUnique());
//
// // remove except RuntimeException
// run(group, new RuntimeExceptions());
//
// // remove unused methods
// run(group, new UnreachedCode());
// run(group, new UnusedMethods());
//
// // remove illegal state exceptions, frees up some parameters
// run(group, new IllegalStateExceptions());
//
// // remove constant logically dead parameters
// run(group, new ConstantParameter());
//
// // remove unhit blocks
// run(group, new UnreachedCode());
// run(group, new UnusedMethods());
run(group, new RenameUnique());
// remove except RuntimeException
run(group, new RuntimeExceptions());
// remove unused methods
run(group, new UnreachedCode());
run(group, new UnusedMethods());
// remove illegal state exceptions, frees up some parameters
run(group, new IllegalStateExceptions());
// remove constant logically dead parameters
run(group, new ConstantParameter());
// remove unhit blocks
run(group, new UnreachedCode());
run(group, new UnusedMethods());
// remove unused parameters
run(group, new UnusedParameters());
//
// // remove unused fields
// run(group, new UnusedFields());
//
// // remove unused methods, again?
// run(group, new UnusedMethods());
//
// run(group, new FieldInliner());
//
// run(group, new UnusedClass());
//
// ModArith mod = new ModArith();
// mod.run(group);
//
// int last = -1, cur;
// while ((cur = mod.runOnce()) > 0)
// {
// new MultiplicationDeobfuscator().run(group);
//
// new MultiplyOneDeobfuscator().run(group);
//
// new MultiplyZeroDeobfuscator().run(group);
//
// if (last == cur)
// break;
//
// last = cur;
// }
//
// mod.annotateEncryption();
// remove unused fields
run(group, new UnusedFields());
// remove unused methods, again?
run(group, new UnusedMethods());
run(group, new FieldInliner());
run(group, new UnusedClass());
ModArith mod = new ModArith();
mod.run(group);
int last = -1, cur;
while ((cur = mod.runOnce()) > 0)
{
new MultiplicationDeobfuscator().run(group);
new MultiplyOneDeobfuscator().run(group);
new MultiplyZeroDeobfuscator().run(group);
if (last == cur)
break;
last = cur;
}
mod.annotateEncryption();
JarUtil.saveJar(group, new File(args[1]));

View File

@@ -25,6 +25,7 @@ import net.runelite.asm.attributes.Annotations;
import net.runelite.asm.attributes.Attributes;
import net.runelite.asm.attributes.annotation.Annotation;
import net.runelite.asm.attributes.annotation.Element;
import net.runelite.asm.execution.MethodContext;
import net.runelite.asm.signature.Type;
import org.apache.commons.collections4.map.MultiValueMap;
@@ -34,7 +35,7 @@ class ConstantMethodParameter
public int paramIndex;
public int lvtIndex;
public Object value;
List<InstructionContext> operations = new ArrayList<>();
List<Instruction> operations = new ArrayList<>();
Boolean result;
@Override
@@ -269,12 +270,17 @@ public class ConstantParameter implements Deobfuscator
}
else
{
parameter.operations.add(ins);
parameter.operations.add(ins.getInstruction());
parameter.result = result;
}
}
}
private void buildContexts(InstructionContext context)
{
//
}
private boolean doLogicalComparison(Object value, ComparisonInstruction comparison, Object otherValue)
{
Instruction ins = (Instruction) comparison;
@@ -314,16 +320,22 @@ public class ConstantParameter implements Deobfuscator
}
// remove logically dead comparisons
private int removeDeadOperations()
private int removeDeadOperations(MethodContext mctx)
{
int count = 0;
for (ConstantMethodParameter cmp : parameters)
{
if (!cmp.methods.contains(mctx.getMethod()))
continue;
annotateObfuscatedSignature(cmp);
for (InstructionContext ctx : cmp.operations) // comparisons
for (Instruction ins : cmp.operations) // comparisons
{
Instruction ins = ctx.getInstruction();
if (ins.getInstructions() == null || ins.getInstructions().getCode().getAttributes().getMethod() != mctx.getMethod())
continue;
InstructionContext ctx = mctx.getInstructonContexts(ins).toArray(new InstructionContext[0])[0];
boolean branch = cmp.result; // branch that is always taken
if (ins.getInstructions() == null)
@@ -403,17 +415,22 @@ public class ConstantParameter implements Deobfuscator
annotation.addElement(element);
}
}
private int count;
@Override
public void run(ClassGroup group)
{
Execution execution = new Execution(group);
execution.addExecutionVisitor((i) -> findParameters(i));
execution.addExecutionVisitor((i) -> findDeadParameters(i));
execution.addExecutionVisitor(i -> findParameters(i));
execution.addExecutionVisitor(i -> findDeadParameters(i));
execution.populateInitialMethods();
execution.run();
int count = removeDeadOperations();
execution = new Execution(group);
execution.addMethodContextVisitor(m -> count += removeDeadOperations(m));
execution.populateInitialMethods();
execution.run();
System.out.println("Removed " + count + " logically dead conditional jumps");
}