XXX WIP save
This commit is contained in:
@@ -136,10 +136,10 @@ public class Execution
|
||||
System.out.println("Processed " + fcount + " frames");
|
||||
}
|
||||
|
||||
public Collection<InstructionContext> getInstructonContexts(Instruction i)
|
||||
{
|
||||
return contexts.getCollection(i);
|
||||
}
|
||||
// public Collection<InstructionContext> getInstructonContexts(Instruction i)
|
||||
// {
|
||||
// return contexts.getCollection(i);
|
||||
// }
|
||||
|
||||
public void addExecutionVisitor(ExecutionVisitor ev)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package net.runelite.deob.deobfuscators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.runelite.asm.ClassFile;
|
||||
import net.runelite.asm.ClassGroup;
|
||||
import net.runelite.deob.Deob;
|
||||
@@ -11,17 +17,9 @@ import net.runelite.asm.attributes.code.instruction.types.InvokeInstruction;
|
||||
import net.runelite.asm.attributes.code.instruction.types.LVTInstruction;
|
||||
import net.runelite.asm.execution.Execution;
|
||||
import net.runelite.asm.execution.InstructionContext;
|
||||
import net.runelite.asm.signature.Signature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.runelite.asm.execution.StackContext;
|
||||
import net.runelite.asm.signature.Signature;
|
||||
import net.runelite.asm.signature.util.VirtualMethods;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
public class UnusedParameters implements Deobfuscator
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package net.runelite.deob.deobfuscators.arithmetic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.runelite.asm.ClassGroup;
|
||||
import net.runelite.deob.Deobfuscator;
|
||||
import net.runelite.asm.attributes.code.Instruction;
|
||||
@@ -13,67 +10,73 @@ import net.runelite.asm.attributes.code.instructions.IMul;
|
||||
import net.runelite.asm.attributes.code.instructions.LMul;
|
||||
import net.runelite.asm.attributes.code.instructions.NOP;
|
||||
import net.runelite.asm.execution.Execution;
|
||||
import net.runelite.asm.execution.Frame;
|
||||
import net.runelite.asm.execution.InstructionContext;
|
||||
import net.runelite.asm.execution.StackContext;
|
||||
|
||||
public class MultiplyOneDeobfuscator implements Deobfuscator
|
||||
{
|
||||
private int count;
|
||||
|
||||
private void visit(InstructionContext ictx)
|
||||
{
|
||||
Instruction instruction = ictx.getInstruction();
|
||||
|
||||
if (!(instruction instanceof IMul) && !(instruction instanceof LMul))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Instructions ins = ictx.getInstruction().getInstructions();
|
||||
if (ins == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<Instruction> ilist = ins.getInstructions();
|
||||
|
||||
if (!ilist.contains(ictx.getInstruction()))
|
||||
{
|
||||
return; // already done
|
||||
}
|
||||
StackContext one = ictx.getPops().get(0);
|
||||
StackContext two = ictx.getPops().get(1);
|
||||
|
||||
int removeIdx = -1;
|
||||
if (one.getPushed().getInstruction() instanceof PushConstantInstruction
|
||||
&& DMath.equals((Number) ((PushConstantInstruction) one.getPushed().getInstruction()).getConstant().getObject(), 1))
|
||||
{
|
||||
removeIdx = 0;
|
||||
}
|
||||
else if (two.getPushed().getInstruction() instanceof PushConstantInstruction
|
||||
&& DMath.equals((Number) ((PushConstantInstruction) two.getPushed().getInstruction()).getConstant().getObject(), 1))
|
||||
{
|
||||
removeIdx = 1;
|
||||
}
|
||||
|
||||
if (removeIdx == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MultiplicationDeobfuscator.isOnlyPath(e, ictx, removeIdx == 0 ? one : two))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ictx.removeStack(removeIdx);
|
||||
ins.replace(ictx.getInstruction(), new NOP(ins));
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ClassGroup group)
|
||||
{
|
||||
group.buildClassGraph();
|
||||
|
||||
Execution e = new Execution(group);
|
||||
e.addExecutionVisitor(i -> visit(i));
|
||||
e.populateInitialMethods();
|
||||
e.run();
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (Frame frame : e.processedFrames)
|
||||
for (InstructionContext ictx : frame.getInstructions())
|
||||
{
|
||||
Instruction instruction = ictx.getInstruction();
|
||||
|
||||
if (!(instruction instanceof IMul) && !(instruction instanceof LMul))
|
||||
continue;
|
||||
|
||||
Instructions ins = ictx.getInstruction().getInstructions();
|
||||
if (ins == null)
|
||||
continue;
|
||||
|
||||
List<Instruction> ilist = ins.getInstructions();
|
||||
|
||||
if (!ilist.contains(ictx.getInstruction()))
|
||||
continue; // already done
|
||||
|
||||
StackContext one = ictx.getPops().get(0);
|
||||
StackContext two = ictx.getPops().get(1);
|
||||
|
||||
int removeIdx = -1;
|
||||
if (one.getPushed().getInstruction() instanceof PushConstantInstruction
|
||||
&& DMath.equals((Number) ((PushConstantInstruction) one.getPushed().getInstruction()).getConstant().getObject(), 1))
|
||||
{
|
||||
removeIdx = 0;
|
||||
}
|
||||
else if (two.getPushed().getInstruction() instanceof PushConstantInstruction
|
||||
&& DMath.equals((Number) ((PushConstantInstruction) two.getPushed().getInstruction()).getConstant().getObject(), 1))
|
||||
{
|
||||
removeIdx = 1;
|
||||
}
|
||||
|
||||
if (removeIdx == -1)
|
||||
continue;
|
||||
|
||||
if (!MultiplicationDeobfuscator.isOnlyPath(e, ictx, removeIdx == 0 ? one : two))
|
||||
continue;
|
||||
|
||||
ictx.removeStack(removeIdx);
|
||||
ins.replace(ictx.getInstruction(), new NOP(ins));
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
System.out.println("Removed " + count + " 1 multiplications");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user