Add special case for delegates
This commit is contained in:
parent
76241db427
commit
c23d770fbc
|
@ -64,7 +64,7 @@ namespace de4dot.deobfuscators {
|
||||||
this.arg = arg;
|
this.arg = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool updateNewType() {
|
public bool updateNewType(ModuleDefinition module) {
|
||||||
if (types.Count == 0)
|
if (types.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ namespace de4dot.deobfuscators {
|
||||||
theNewType = key.TypeReference;
|
theNewType = key.TypeReference;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
theNewType = getCommonBaseClass(theNewType, key.TypeReference);
|
theNewType = getCommonBaseClass(module, theNewType, key.TypeReference);
|
||||||
if (theNewType == null)
|
if (theNewType == null)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -177,14 +177,14 @@ namespace de4dot.deobfuscators {
|
||||||
methodReturnInfo = new TypeInfo<ParameterDefinition>(method.MethodReturnType.Parameter2);
|
methodReturnInfo = new TypeInfo<ParameterDefinition>(method.MethodReturnType.Parameter2);
|
||||||
deobfuscateMethod(method);
|
deobfuscateMethod(method);
|
||||||
|
|
||||||
if (methodReturnInfo.updateNewType()) {
|
if (methodReturnInfo.updateNewType(module)) {
|
||||||
getUpdatedMethod(method).newReturnType = methodReturnInfo.newType;
|
getUpdatedMethod(method).newReturnType = methodReturnInfo.newType;
|
||||||
method.MethodReturnType.ReturnType = methodReturnInfo.newType;
|
method.MethodReturnType.ReturnType = methodReturnInfo.newType;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var info in argInfos.Values) {
|
foreach (var info in argInfos.Values) {
|
||||||
if (info.updateNewType()) {
|
if (info.updateNewType(module)) {
|
||||||
getUpdatedMethod(method).newArgTypes[DotNetUtils.getArgIndex(method, info.arg)] = info.newType;
|
getUpdatedMethod(method).newArgTypes[DotNetUtils.getArgIndex(method, info.arg)] = info.newType;
|
||||||
info.arg.ParameterType = info.newType;
|
info.arg.ParameterType = info.newType;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
@ -290,6 +290,7 @@ namespace de4dot.deobfuscators {
|
||||||
case Code.Call:
|
case Code.Call:
|
||||||
case Code.Calli:
|
case Code.Calli:
|
||||||
case Code.Callvirt:
|
case Code.Callvirt:
|
||||||
|
case Code.Newobj:
|
||||||
pushedArgs = getPushedArgInstructions(instructions, i);
|
pushedArgs = getPushedArgInstructions(instructions, i);
|
||||||
var calledMethod = instr.Operand as MethodReference;
|
var calledMethod = instr.Operand as MethodReference;
|
||||||
if (calledMethod == null)
|
if (calledMethod == null)
|
||||||
|
@ -588,7 +589,7 @@ namespace de4dot.deobfuscators {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
var removeThese = new List<FieldDefinition>();
|
var removeThese = new List<FieldDefinition>();
|
||||||
foreach (var info in fieldWrites.Values) {
|
foreach (var info in fieldWrites.Values) {
|
||||||
if (info.updateNewType()) {
|
if (info.updateNewType(module)) {
|
||||||
removeThese.Add(info.arg);
|
removeThese.Add(info.arg);
|
||||||
getUpdatedField(info.arg).newFieldType = info.newType;
|
getUpdatedField(info.arg).newFieldType = info.newType;
|
||||||
info.arg.FieldType = info.newType;
|
info.arg.FieldType = info.newType;
|
||||||
|
@ -709,7 +710,11 @@ namespace de4dot.deobfuscators {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static TypeReference getCommonBaseClass(TypeReference a, TypeReference b) {
|
static TypeReference getCommonBaseClass(ModuleDefinition module, TypeReference a, TypeReference b) {
|
||||||
|
if (DotNetUtils.isDelegate(a) && DotNetUtils.isDelegateType(DotNetUtils.getType(module, b)))
|
||||||
|
return b;
|
||||||
|
if (DotNetUtils.isDelegate(b) && DotNetUtils.isDelegateType(DotNetUtils.getType(module, a)))
|
||||||
|
return a;
|
||||||
return null; //TODO:
|
return null; //TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user