Small fixes
This commit is contained in:
@@ -51,6 +51,11 @@ public class Code extends Attribute
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
public void setMaxStack(int maxStack)
|
||||
{
|
||||
this.maxStack = maxStack;
|
||||
}
|
||||
|
||||
private int getMaxLocalsFromSig()
|
||||
{
|
||||
Method m = super.getAttributes().getMethod();
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.execution.Frame;
|
||||
import info.sigterm.deob.execution.InstructionContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -22,5 +23,7 @@ public class NOP extends Instruction
|
||||
@Override
|
||||
public void execute(Frame frame)
|
||||
{
|
||||
InstructionContext ctx = new InstructionContext(this, frame);
|
||||
frame.addInstructionContext(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,10 @@ public class MethodInliner implements Deobfuscator
|
||||
ins.getInstructions().add(invokeIdx++, storeIns);
|
||||
}
|
||||
|
||||
inline(m, i, invokedMethod, /*start*/lvtIndex);
|
||||
int maxStack = code.getMaxStack() + invokedMethod.getCode().getMaxStack(); // not really right but ok
|
||||
code.setMaxStack(maxStack);
|
||||
|
||||
inline(m, i, invokedMethod, lvtIndex);
|
||||
++inlineCount;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package info.sigterm.deob.deobfuscators;
|
||||
|
||||
import info.sigterm.deob.ClassFile;
|
||||
import info.sigterm.deob.ClassGroup;
|
||||
import info.sigterm.deob.Deobfuscator;
|
||||
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.InvokeStatic;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.apache.commons.collections4.map.MultiValueMap;
|
||||
|
||||
// find static methods that are only called from methods of one class
|
||||
public class MethodMover implements Deobfuscator
|
||||
{
|
||||
private MultiValueMap<Method, Method> calls = new MultiValueMap<>();
|
||||
|
||||
private void buildCalls(ClassGroup group)
|
||||
{
|
||||
calls.clear();
|
||||
|
||||
for (ClassFile cf : group.getClasses())
|
||||
{
|
||||
for (Method m : cf.getMethods().getMethods())
|
||||
{
|
||||
Code code = m.getCode();
|
||||
|
||||
if (code == null)
|
||||
continue;
|
||||
|
||||
Instructions ins = code.getInstructions();
|
||||
for (Instruction i : ins.getInstructions())
|
||||
{
|
||||
if (!(i instanceof InvokeStatic))
|
||||
continue;
|
||||
|
||||
InvokeStatic is = (InvokeStatic) i;
|
||||
List<Method> methods = is.getMethods();
|
||||
|
||||
if (methods.isEmpty())
|
||||
continue;
|
||||
|
||||
Method method = methods.get(0);
|
||||
|
||||
calls.put(method, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void look()
|
||||
{
|
||||
for (Method m : calls.keySet())
|
||||
{
|
||||
Collection<Method> values = calls.getCollection(m);
|
||||
|
||||
boolean set = false;
|
||||
ClassFile caller = null;
|
||||
|
||||
for (Method m2 : values)
|
||||
{
|
||||
if (!set)
|
||||
{
|
||||
set = true;
|
||||
caller = m2.getMethods().getClassFile();
|
||||
}
|
||||
|
||||
if (caller != m2.getMethods().getClassFile())
|
||||
{
|
||||
caller = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (caller == null)
|
||||
continue;
|
||||
|
||||
System.out.println(caller.getName() + " always calls " + m.getName() + " sz " + values.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ClassGroup group)
|
||||
{
|
||||
group.buildClassGraph();
|
||||
buildCalls(group);
|
||||
look();
|
||||
}
|
||||
}
|
||||
@@ -674,6 +674,8 @@ public class ModularArithmeticDeobfuscation implements Deobfuscator
|
||||
@Override
|
||||
public void run(ClassGroup group)
|
||||
{
|
||||
group.buildClassGraph();
|
||||
|
||||
Execution execution = new Execution(group);
|
||||
execution.populateInitialMethods();
|
||||
execution.run();
|
||||
|
||||
Reference in New Issue
Block a user