I dont like this

This commit is contained in:
Adam
2015-07-31 12:47:40 -04:00
parent a7902d53e9
commit 7b4de7d8db

View File

@@ -11,7 +11,9 @@ import info.sigterm.deob.execution.InstructionContext;
import info.sigterm.deob.execution.StackContext; import info.sigterm.deob.execution.StackContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.map.MultiValueMap; import org.apache.commons.collections4.map.MultiValueMap;
@@ -20,6 +22,7 @@ class ConstantMethodParameter
public Method method; public Method method;
public int paramNum; public int paramNum;
public Object value; public Object value;
public InstructionContext invoke; // invoking instruction
} }
class MethodGroup class MethodGroup
@@ -42,7 +45,8 @@ public class ConstantParameter implements Deobfuscator
{ {
private MultiValueMap<Method, ConstantMethodParameter> parameters = new MultiValueMap<>(); private MultiValueMap<Method, ConstantMethodParameter> parameters = new MultiValueMap<>();
// methods can be in more than one group because of multiple inheritance with interfaces // methods can be in more than one group because of multiple inheritance with interfaces
private MultiValueMap<Method, MethodGroup> methodGroups = new MultiValueMap<>(); //private MultiValueMap<Method, MethodGroup> methodGroups = new MultiValueMap<>();
private List<MethodGroup> methodGroups = new ArrayList<>();
private void findConstantParameter(Execution execution, Method method, InstructionContext invokeCtx) private void findConstantParameter(Execution execution, Method method, InstructionContext invokeCtx)
{ {
@@ -65,6 +69,7 @@ public class ConstantParameter implements Deobfuscator
cmp.method = method; cmp.method = method;
cmp.paramNum = i; cmp.paramNum = i;
cmp.value = pc.getConstant().getObject(); cmp.value = pc.getConstant().getObject();
cmp.invoke = invokeCtx;
parameters.put(method, cmp); parameters.put(method, cmp);
} }
@@ -78,7 +83,8 @@ public class ConstantParameter implements Deobfuscator
if (params != null) if (params != null)
for (ConstantMethodParameter p : params) for (ConstantMethodParameter p : params)
out.add(p.paramNum); if (!out.contains(p.paramNum))
out.add(p.paramNum);
return out; return out;
} }
@@ -116,20 +122,24 @@ public class ConstantParameter implements Deobfuscator
{ {
Collection<ConstantMethodParameter> params = parameters.getCollection(m); Collection<ConstantMethodParameter> params = parameters.getCollection(m);
if (params != null) if (params != null)
group.cmps.addAll(params); for (ConstantMethodParameter c : params)
if (parameterIndexes.contains(c.paramNum))
group.cmps.add(c);
} }
// insert // insert
for (Method m : methods) methodGroups.add(group);
methodGroups.put(m, group); //for (Method m : methods)
// methodGroups.put(m, group);
} }
} }
private void findLogicallyDeadOperations() private void findLogicallyDeadOperations()
{ {
for (Object ogroup : methodGroups.values()) for (MethodGroup group : methodGroups)
//for (Object ogroup : methodGroups.values())
{ {
MethodGroup group = (MethodGroup) ogroup; // MethodGroup group = (MethodGroup) ogroup;
for (Method m : group.methods) for (Method m : group.methods)
for (int parameterIndex : group.constantParameters) for (int parameterIndex : group.constantParameters)
{ {
@@ -139,6 +149,7 @@ public class ConstantParameter implements Deobfuscator
// iterate instructions of method and find comparisons to parameter // iterate instructions of method and find comparisons to parameter
// remove if all are logically dead. rely on unused parameter deob to remove // remove if all are logically dead. rely on unused parameter deob to remove
// the parameter. // the parameter.
System.out.println(cmps.size() + " calls to " + m.getMethods().getClassFile().getName() + "." + m.getName() + " with index " + parameterIndex);
} }
} }
} }
@@ -146,15 +157,14 @@ public class ConstantParameter implements Deobfuscator
@Override @Override
public void run(ClassGroup group) public void run(ClassGroup group)
{ {
group.buildClassGraph(); // required for getMethods in the invoke stuff group.buildClassGraph(); // required for getMethods in the invoke stuff by execution...
Execution execution = new Execution(group); Execution execution = new Execution(group);
execution.populateInitialMethods(); execution.populateInitialMethods();
execution.run(); execution.run();
findParameters(execution); findParameters(execution);
findLogicallyDeadOperations();
System.out.println("finished with " + methodGroups.size() + " groups");
} }
} }