Merge branch 'master' into confuser

This commit is contained in:
de4dot 2012-09-01 23:52:42 +02:00
commit 88d3dcc062
10 changed files with 23 additions and 17 deletions

View File

@ -146,7 +146,7 @@ namespace AssemblyData.methodsrewriter {
var asmRef = DotNetUtils.getAssemblyNameReference(b); var asmRef = DotNetUtils.getAssemblyNameReference(b);
var asmName = a.Assembly.GetName(); var asmName = a.Assembly.GetName();
if (asmRef.Name != asmName.Name) if (asmRef == null || asmRef.Name != asmName.Name)
return false; return false;
return compareTypes(a.DeclaringType, b.DeclaringType); return compareTypes(a.DeclaringType, b.DeclaringType);

View File

@ -926,6 +926,9 @@ namespace de4dot.blocks {
public static AssemblyNameReference getAssemblyNameReference(TypeReference type) { public static AssemblyNameReference getAssemblyNameReference(TypeReference type) {
var scope = type.Scope; var scope = type.Scope;
if (scope == null)
return null;
if (scope is ModuleDefinition) { if (scope is ModuleDefinition) {
var moduleDefinition = (ModuleDefinition)scope; var moduleDefinition = (ModuleDefinition)scope;
return moduleDefinition.Assembly.Name; return moduleDefinition.Assembly.Name;
@ -946,7 +949,7 @@ namespace de4dot.blocks {
public static string getFullAssemblyName(TypeReference type) { public static string getFullAssemblyName(TypeReference type) {
var asmRef = getAssemblyNameReference(type); var asmRef = getAssemblyNameReference(type);
return asmRef.FullName; return asmRef == null ? null : asmRef.FullName;
} }
public static bool isAssembly(IMetadataScope scope, string assemblySimpleName) { public static bool isAssembly(IMetadataScope scope, string assemblySimpleName) {

2
cecil

@ -1 +1 @@
Subproject commit 86e21d470a0232f6b746ee2b8b7a9483c1842fea Subproject commit 119a3d404ab12a8a19a249e97c1e5f6ca0850b6a

View File

@ -56,6 +56,8 @@ namespace de4dot.code {
ExternalAssembly load(TypeReference type) { ExternalAssembly load(TypeReference type) {
var asmFullName = DotNetUtils.getFullAssemblyName(type); var asmFullName = DotNetUtils.getFullAssemblyName(type);
if (asmFullName == null)
return null;
ExternalAssembly asm; ExternalAssembly asm;
if (assemblies.TryGetValue(asmFullName, out asm)) if (assemblies.TryGetValue(asmFullName, out asm))
return asm; return asm;

View File

@ -67,7 +67,8 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
!containsString(method, "run under a debugger") && !containsString(method, "run under a debugger") &&
!containsString(method, "run under debugger") && !containsString(method, "run under debugger") &&
!containsString(method, "Debugger detected") && !containsString(method, "Debugger detected") &&
!containsString(method, "Debugger was detected")) !containsString(method, "Debugger was detected") &&
!containsString(method, "{0} was detected"))
continue; continue;
antiDebuggerType = type; antiDebuggerType = type;

View File

@ -110,7 +110,7 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
MethodDefinition getProxyCreateMethod(TypeDefinition type) { MethodDefinition getProxyCreateMethod(TypeDefinition type) {
if (DotNetUtils.findFieldType(type, "System.ModuleHandle", true) == null) if (DotNetUtils.findFieldType(type, "System.ModuleHandle", true) == null)
return null; return null;
if (type.Fields.Count < 1 || type.Fields.Count > 10) if (type.Fields.Count < 1 || type.Fields.Count > 12)
return null; return null;
MethodDefinition createMethod = null; MethodDefinition createMethod = null;

View File

@ -272,12 +272,13 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
var ldci4 = instrs[i]; var ldci4 = instrs[i];
if (!DotNetUtils.isLdcI4(ldci4)) if (!DotNetUtils.isLdcI4(ldci4))
continue; continue;
if (DotNetUtils.getLdcI4Value(ldci4) != 2) int loopCount = DotNetUtils.getLdcI4Value(ldci4);
if (loopCount < 2 || loopCount > 3)
continue; continue;
var blt = instrs[i + 1]; var blt = instrs[i + 1];
if (blt.OpCode.Code != Code.Blt && blt.OpCode.Code != Code.Blt_S) if (blt.OpCode.Code != Code.Blt && blt.OpCode.Code != Code.Blt_S)
continue; continue;
return 1; return loopCount - 1;
} }
return 0; return 0;
} }

View File

@ -84,7 +84,7 @@ namespace de4dot.code.deobfuscators.CryptoObfuscator {
if (!method.IsStatic || !DotNetUtils.isMethod(method, "System.Void", "()")) if (!method.IsStatic || !DotNetUtils.isMethod(method, "System.Void", "()"))
return false; return false;
if (type.Methods.Count < 3 || type.Methods.Count > 12) if (type.Methods.Count < 3 || type.Methods.Count > 14)
return false; return false;
if (DotNetUtils.getPInvokeMethod(type, "mscoree", "StrongNameSignatureVerificationEx") != null) { if (DotNetUtils.getPInvokeMethod(type, "mscoree", "StrongNameSignatureVerificationEx") != null) {
} }

View File

@ -71,16 +71,15 @@ namespace de4dot.code.deobfuscators {
var mbHeader = new MethodBodyHeader(); var mbHeader = new MethodBodyHeader();
uint codeOffset; uint codeOffset;
switch (peek(reader) & 3) { byte b = peek(reader);
case 2: if ((b & 3) == 2) {
mbHeader.flags = 2; mbHeader.flags = 2;
mbHeader.maxStack = 8; mbHeader.maxStack = 8;
mbHeader.codeSize = (uint)(reader.ReadByte() >> 2); mbHeader.codeSize = (uint)(reader.ReadByte() >> 2);
mbHeader.localVarSigTok = 0; mbHeader.localVarSigTok = 0;
codeOffset = 1; codeOffset = 1;
break; }
else if ((b & 7) == 3) {
case 3:
mbHeader.flags = reader.ReadUInt16(); mbHeader.flags = reader.ReadUInt16();
codeOffset = (uint)(4 * (mbHeader.flags >> 12)); codeOffset = (uint)(4 * (mbHeader.flags >> 12));
if (codeOffset != 12) if (codeOffset != 12)
@ -92,11 +91,9 @@ namespace de4dot.code.deobfuscators {
mbHeader.localVarSigTok = reader.ReadUInt32(); mbHeader.localVarSigTok = reader.ReadUInt32();
if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11) if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11)
throw new InvalidMethodBody(); throw new InvalidMethodBody();
break;
default:
throw new InvalidMethodBody();
} }
else
throw new InvalidMethodBody();
if (mbHeader.codeSize + codeOffset > reader.BaseStream.Length) if (mbHeader.codeSize + codeOffset > reader.BaseStream.Length)
throw new InvalidMethodBody(); throw new InvalidMethodBody();

View File

@ -390,6 +390,8 @@ namespace de4dot.code.renamer.asmmodules {
// Returns null if it's a non-loaded module/assembly // Returns null if it's a non-loaded module/assembly
IEnumerable<Module> findModules(TypeReference type) { IEnumerable<Module> findModules(TypeReference type) {
var scope = type.Scope; var scope = type.Scope;
if (scope == null)
return null;
if (scope is AssemblyNameReference) if (scope is AssemblyNameReference)
return findModules((AssemblyNameReference)scope); return findModules((AssemblyNameReference)scope);