If instance explicit, 'this' is 1st param
This commit is contained in:
parent
664f0f8cf1
commit
f3f8975f01
|
@ -330,9 +330,9 @@ namespace AssemblyData.methodsrewriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<TypeReference> getParameters(MethodDefinition method) {
|
static List<TypeReference> getParameters(MethodDefinition method) {
|
||||||
int count = method.Parameters.Count + (method.HasThis ? 1 : 0);
|
int count = method.Parameters.Count + (method.HasImplicitThis ? 1 : 0);
|
||||||
var list = new List<TypeReference>(count);
|
var list = new List<TypeReference>(count);
|
||||||
if (method.HasThis)
|
if (method.HasImplicitThis)
|
||||||
list.Add(method.DeclaringType);
|
list.Add(method.DeclaringType);
|
||||||
foreach (var argType in method.Parameters)
|
foreach (var argType in method.Parameters)
|
||||||
list.Add(argType.ParameterType);
|
list.Add(argType.ParameterType);
|
||||||
|
|
|
@ -674,12 +674,13 @@ namespace de4dot.blocks {
|
||||||
pops = 0;
|
pops = 0;
|
||||||
|
|
||||||
var method = (IMethodSignature)instr.Operand;
|
var method = (IMethodSignature)instr.Operand;
|
||||||
|
bool implicitThis = method.HasThis && !method.ExplicitThis;
|
||||||
if (hasReturnValue(method) || (instr.OpCode.Code == Code.Newobj && method.HasThis))
|
if (hasReturnValue(method) || (instr.OpCode.Code == Code.Newobj && method.HasThis))
|
||||||
pushes++;
|
pushes++;
|
||||||
|
|
||||||
if (method.HasParameters)
|
if (method.HasParameters)
|
||||||
pops += method.Parameters.Count;
|
pops += method.Parameters.Count;
|
||||||
if (method.HasThis && instr.OpCode.Code != Code.Newobj)
|
if (implicitThis && instr.OpCode.Code != Code.Newobj)
|
||||||
pops++;
|
pops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,20 +825,20 @@ namespace de4dot.blocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getArgIndex(MethodReference method, ParameterDefinition arg) {
|
public static int getArgIndex(MethodReference method, ParameterDefinition arg) {
|
||||||
return getArgIndex(method.HasThis, arg);
|
return getArgIndex(method.HasImplicitThis, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getArgIndex(bool hasThis, ParameterDefinition arg) {
|
public static int getArgIndex(bool implicitThis, ParameterDefinition arg) {
|
||||||
if (arg == null)
|
if (arg == null)
|
||||||
return -1;
|
return -1;
|
||||||
if (hasThis)
|
if (implicitThis)
|
||||||
return arg.Index + 1;
|
return arg.Index + 1;
|
||||||
return arg.Index;
|
return arg.Index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ParameterDefinition> getParameters(MethodReference method) {
|
public static List<ParameterDefinition> getParameters(MethodReference method) {
|
||||||
var args = new List<ParameterDefinition>(method.Parameters.Count + 1);
|
var args = new List<ParameterDefinition>(method.Parameters.Count + 1);
|
||||||
if (method.HasThis)
|
if (method.HasImplicitThis)
|
||||||
args.Add(new ParameterDefinition(method.DeclaringType));
|
args.Add(new ParameterDefinition(method.DeclaringType));
|
||||||
foreach (var arg in method.Parameters)
|
foreach (var arg in method.Parameters)
|
||||||
args.Add(arg);
|
args.Add(arg);
|
||||||
|
@ -864,7 +865,7 @@ namespace de4dot.blocks {
|
||||||
|
|
||||||
public static List<TypeReference> getArgs(MethodReference method) {
|
public static List<TypeReference> getArgs(MethodReference method) {
|
||||||
var args = new List<TypeReference>(method.Parameters.Count + 1);
|
var args = new List<TypeReference>(method.Parameters.Count + 1);
|
||||||
if (method.HasThis)
|
if (method.HasImplicitThis)
|
||||||
args.Add(method.DeclaringType);
|
args.Add(method.DeclaringType);
|
||||||
foreach (var arg in method.Parameters)
|
foreach (var arg in method.Parameters)
|
||||||
args.Add(arg.ParameterType);
|
args.Add(arg.ParameterType);
|
||||||
|
@ -887,7 +888,7 @@ namespace de4dot.blocks {
|
||||||
|
|
||||||
public static int getArgsCount(MethodReference method) {
|
public static int getArgsCount(MethodReference method) {
|
||||||
int count = method.Parameters.Count;
|
int count = method.Parameters.Count;
|
||||||
if (method.HasThis)
|
if (method.HasImplicitThis)
|
||||||
count++;
|
count++;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace de4dot.blocks.cflow {
|
||||||
public void init(Blocks blocks, Block block) {
|
public void init(Blocks blocks, Block block) {
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals);
|
instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if code was updated, false otherwise
|
// Returns true if code was updated, false otherwise
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace de4dot.blocks.cflow {
|
||||||
public bool deobfuscate() {
|
public bool deobfuscate() {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
foreach (var block in allBlocks) {
|
foreach (var block in allBlocks) {
|
||||||
instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals);
|
instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals);
|
||||||
var instrs = block.Instructions;
|
var instrs = block.Instructions;
|
||||||
for (int i = 0; i < instrs.Count; i++) {
|
for (int i = 0; i < instrs.Count; i++) {
|
||||||
var instr = instrs[i];
|
var instr = instrs[i];
|
||||||
|
|
|
@ -34,18 +34,18 @@ namespace de4dot.blocks.cflow {
|
||||||
public InstructionEmulator() {
|
public InstructionEmulator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InstructionEmulator(bool hasThis, bool initLocals, IList<ParameterDefinition> parameterDefinitions, IList<VariableDefinition> variableDefinitions) {
|
public InstructionEmulator(bool implicitThis, bool initLocals, IList<ParameterDefinition> parameterDefinitions, IList<VariableDefinition> variableDefinitions) {
|
||||||
init(hasThis, initLocals, parameterDefinitions, variableDefinitions);
|
init(implicitThis, initLocals, parameterDefinitions, variableDefinitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(bool hasThis, bool initLocals, IList<ParameterDefinition> parameterDefinitions, IList<VariableDefinition> variableDefinitions) {
|
public void init(bool implicitThis, bool initLocals, IList<ParameterDefinition> parameterDefinitions, IList<VariableDefinition> variableDefinitions) {
|
||||||
this.parameterDefinitions = parameterDefinitions;
|
this.parameterDefinitions = parameterDefinitions;
|
||||||
this.variableDefinitions = variableDefinitions;
|
this.variableDefinitions = variableDefinitions;
|
||||||
valueStack.init();
|
valueStack.init();
|
||||||
|
|
||||||
args.Clear();
|
args.Clear();
|
||||||
argBase = 0;
|
argBase = 0;
|
||||||
if (hasThis) {
|
if (implicitThis) {
|
||||||
argBase = 1;
|
argBase = 1;
|
||||||
args.Add(new UnknownValue());
|
args.Add(new UnknownValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ namespace de4dot.blocks.cflow {
|
||||||
foreach (var source in new List<Block>(block.Sources)) {
|
foreach (var source in new List<Block>(block.Sources)) {
|
||||||
if (!isBranchBlock(source))
|
if (!isBranchBlock(source))
|
||||||
continue;
|
continue;
|
||||||
instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals);
|
instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals);
|
||||||
instructionEmulator.emulate(source.Instructions);
|
instructionEmulator.emulate(source.Instructions);
|
||||||
|
|
||||||
var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.pop());
|
var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.pop());
|
||||||
|
@ -151,7 +151,7 @@ namespace de4dot.blocks.cflow {
|
||||||
foreach (var source in new List<Block>(block.Sources)) {
|
foreach (var source in new List<Block>(block.Sources)) {
|
||||||
if (!isBranchBlock(source))
|
if (!isBranchBlock(source))
|
||||||
continue;
|
continue;
|
||||||
instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals);
|
instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals);
|
||||||
instructionEmulator.emulate(source.Instructions);
|
instructionEmulator.emulate(source.Instructions);
|
||||||
|
|
||||||
var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.getLocal(switchVariable));
|
var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.getLocal(switchVariable));
|
||||||
|
@ -174,7 +174,7 @@ namespace de4dot.blocks.cflow {
|
||||||
foreach (var source in new List<Block>(block.Sources)) {
|
foreach (var source in new List<Block>(block.Sources)) {
|
||||||
if (!isBranchBlock(source))
|
if (!isBranchBlock(source))
|
||||||
continue;
|
continue;
|
||||||
instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals);
|
instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals);
|
||||||
instructionEmulator.emulate(source.Instructions);
|
instructionEmulator.emulate(source.Instructions);
|
||||||
|
|
||||||
var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.pop());
|
var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.pop());
|
||||||
|
@ -245,7 +245,7 @@ namespace de4dot.blocks.cflow {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool emulateGetTarget(Block switchBlock, out Block target) {
|
bool emulateGetTarget(Block switchBlock, out Block target) {
|
||||||
instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals);
|
instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals);
|
||||||
try {
|
try {
|
||||||
instructionEmulator.emulate(switchBlock.Instructions, 0, switchBlock.Instructions.Count - 1);
|
instructionEmulator.emulate(switchBlock.Instructions, 0, switchBlock.Instructions.Count - 1);
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ namespace de4dot.blocks.cflow {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool willHaveKnownTarget(Block switchBlock, Block source) {
|
bool willHaveKnownTarget(Block switchBlock, Block source) {
|
||||||
instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals);
|
instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals);
|
||||||
try {
|
try {
|
||||||
instructionEmulator.emulate(source.Instructions);
|
instructionEmulator.emulate(source.Instructions);
|
||||||
instructionEmulator.emulate(switchBlock.Instructions, 0, switchBlock.Instructions.Count - 1);
|
instructionEmulator.emulate(switchBlock.Instructions, 0, switchBlock.Instructions.Count - 1);
|
||||||
|
|
|
@ -113,7 +113,7 @@ namespace de4dot.code.deobfuscators {
|
||||||
public static Value[] getInitializedArray(int arraySize, MethodDefinition method, ref int newarrIndex, Code stelemOpCode) {
|
public static Value[] getInitializedArray(int arraySize, MethodDefinition method, ref int newarrIndex, Code stelemOpCode) {
|
||||||
var resultValueArray = new Value[arraySize];
|
var resultValueArray = new Value[arraySize];
|
||||||
|
|
||||||
var emulator = new InstructionEmulator(method.HasThis, false, method.Parameters, method.Body.Variables);
|
var emulator = new InstructionEmulator(method.HasImplicitThis, false, method.Parameters, method.Body.Variables);
|
||||||
var theArray = new UnknownValue();
|
var theArray = new UnknownValue();
|
||||||
emulator.push(theArray);
|
emulator.push(theArray);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user