Speed up DeepSea string decrypter detector

This commit is contained in:
de4dot 2012-11-11 07:54:26 +01:00
parent 062e2755bf
commit 5a9d76e8c7

View File

@ -185,7 +185,7 @@ namespace de4dot.code.deobfuscators.DeepSea {
Method = method; Method = method;
} }
public static bool isPossibleDecrypterMethod(MethodDef method) { public static bool isPossibleDecrypterMethod(MethodDef method, bool firstTime) {
if (!checkMethodSignature(method)) if (!checkMethodSignature(method))
return false; return false;
var fields = getFields(method); var fields = getFields(method);
@ -405,8 +405,8 @@ namespace de4dot.code.deobfuscators.DeepSea {
this.Method = method; this.Method = method;
} }
public static bool isPossibleDecrypterMethod(MethodDef method) { public static bool isPossibleDecrypterMethod(MethodDef method, bool firstTime) {
if (!checkFields(method.DeclaringType.Fields)) if (!firstTime || !checkFields(method.DeclaringType.Fields))
return false; return false;
return DotNetUtils.isMethod(method, "System.String", "(System.Int32,System.Int32)"); return DotNetUtils.isMethod(method, "System.String", "(System.Int32,System.Int32)");
} }
@ -557,8 +557,8 @@ namespace de4dot.code.deobfuscators.DeepSea {
get { return DecrypterVersion.V1_3; } get { return DecrypterVersion.V1_3; }
} }
public static bool isPossibleDecrypterMethod(MethodDef method) { public static bool isPossibleDecrypterMethod(MethodDef method, bool firstTime) {
if (!checkFields(method.DeclaringType.Fields)) if (!firstTime || !checkFields(method.DeclaringType.Fields))
return false; return false;
return DotNetUtils.isMethod(method, "System.String", "(System.Int32)"); return DotNetUtils.isMethod(method, "System.String", "(System.Int32)");
} }
@ -735,27 +735,29 @@ namespace de4dot.code.deobfuscators.DeepSea {
continue; continue;
bool deobfuscatedCctor = false; bool deobfuscatedCctor = false;
bool firstTime = true;
foreach (var method in type.Methods) { foreach (var method in type.Methods) {
if (!method.IsStatic || method.Body == null) if (!method.IsStatic || method.Body == null)
continue; continue;
IDecrypterInfo info = null; IDecrypterInfo info = null;
if (DecrypterInfo13.isPossibleDecrypterMethod(method)) { if (DecrypterInfo13.isPossibleDecrypterMethod(method, firstTime)) {
deobfuscateCctor(simpleDeobfuscator, cctor, ref deobfuscatedCctor, hasPublicKeyToken); deobfuscateCctor(simpleDeobfuscator, cctor, ref deobfuscatedCctor, hasPublicKeyToken);
simpleDeobfuscator.deobfuscate(method); simpleDeobfuscator.deobfuscate(method);
info = getInfoV13(cctor, method); info = getInfoV13(cctor, method);
} }
else if (DecrypterInfo40.isPossibleDecrypterMethod(method)) { else if (DecrypterInfo40.isPossibleDecrypterMethod(method, firstTime)) {
deobfuscateCctor(simpleDeobfuscator, cctor, ref deobfuscatedCctor, hasPublicKeyToken); deobfuscateCctor(simpleDeobfuscator, cctor, ref deobfuscatedCctor, hasPublicKeyToken);
simpleDeobfuscator.deobfuscate(method); simpleDeobfuscator.deobfuscate(method);
info = getInfoV40(cctor, method); info = getInfoV40(cctor, method);
} }
else if (DecrypterInfo41.isPossibleDecrypterMethod(method)) { else if (DecrypterInfo41.isPossibleDecrypterMethod(method, firstTime)) {
deobfuscateCctor(simpleDeobfuscator, cctor, ref deobfuscatedCctor, hasPublicKeyToken); deobfuscateCctor(simpleDeobfuscator, cctor, ref deobfuscatedCctor, hasPublicKeyToken);
simpleDeobfuscator.deobfuscate(method); simpleDeobfuscator.deobfuscate(method);
info = getInfoV41(cctor, method); info = getInfoV41(cctor, method);
} }
firstTime = false;
if (info == null) if (info == null)
continue; continue;