From 9263a3df3d4a6e905379b6a471862fd551d0d4e2 Mon Sep 17 00:00:00 2001 From: de4dot Date: Thu, 22 Nov 2012 09:14:51 +0100 Subject: [PATCH] Remove all cecil code/comment refs --- AssemblyData/methodsrewriter/CodeGenerator.cs | 6 +- AssemblyData/methodsrewriter/MMethod.cs | 4 +- AssemblyData/methodsrewriter/MModule.cs | 12 +- AssemblyData/methodsrewriter/MType.cs | 20 +- AssemblyData/methodsrewriter/Resolver.cs | 18 +- blocks/DotNetUtils.cs | 18 +- blocks/ForwardScanOrder.cs | 2 +- blocks/MemberDefDict.cs | 198 +++++++++--------- blocks/Properties/AssemblyInfo.cs | 2 +- de4dot.code/DeobfuscatorContext.cs | 4 +- de4dot.code/MethodPrinter.cs | 6 +- de4dot.code/MethodReturnValueInliner.cs | 4 +- de4dot.code/ObfuscatedFile.cs | 2 - de4dot.code/StringInliner.cs | 2 +- .../deobfuscators/Agile_NET/vm/Csvm.cs | 14 +- .../Agile_NET/vm/CsvmToCilMethodConverter.cs | 8 +- .../Agile_NET/vm/UnknownHandlerInfo.cs | 2 +- .../deobfuscators/Babel_NET/ImageReader.cs | 72 +++---- .../Babel_NET/MemberReferenceConverter.cs | 12 +- .../Babel_NET/MethodBodyReader.cs | 8 +- .../Babel_NET/MethodReferenceReader.cs | 24 +-- .../deobfuscators/Babel_NET/ProxyCallFixer.cs | 2 +- .../Babel_NET/StringDecrypter.cs | 10 +- .../deobfuscators/CodeFort/ProxyCallFixer.cs | 2 +- .../deobfuscators/CodeWall/StringDecrypter.cs | 2 +- .../deobfuscators/DeepSea/ArrayBlockState.cs | 2 +- .../deobfuscators/DeepSea/FieldsRestorer.cs | 10 +- .../deobfuscators/DeepSea/StringDecrypter.cs | 12 +- de4dot.code/deobfuscators/DeobfuscatorBase.cs | 14 +- .../Dotfuscator/StringDecrypter.cs | 2 +- .../deobfuscators/ExceptionLoggerRemover.cs | 2 +- .../Goliath_NET/DecrypterBase.cs | 4 +- .../Goliath_NET/LocalsRestorer.cs | 2 +- .../ILProtector/MethodsDecrypter.cs | 2 +- .../deobfuscators/InitializedDataCreator.cs | 8 +- .../deobfuscators/MemberReferenceBuilder.cs | 10 +- .../deobfuscators/MethodCallRestorerBase.cs | 6 +- de4dot.code/deobfuscators/MethodCollection.cs | 4 +- de4dot.code/deobfuscators/MethodStack.cs | 12 +- .../deobfuscators/ProxyCallFixerBase.cs | 4 +- .../deobfuscators/Rummage/StringDecrypter.cs | 2 +- .../deobfuscators/Skater_NET/Deobfuscator.cs | 4 +- .../Skater_NET/StringDecrypter.cs | 2 +- .../SmartAssembly/Deobfuscator.cs | 4 +- .../SmartAssembly/StringDecrypterInfo.cs | 4 +- .../SmartAssembly/StringEncoderClassFinder.cs | 4 +- .../Spices_Net/ResourceNamesRestorer.cs | 6 +- .../Spices_Net/SpicesMethodCallInliner.cs | 14 +- .../Spices_Net/StringDecrypter.cs | 2 +- de4dot.code/deobfuscators/ValueInlinerBase.cs | 10 +- .../dotNET_Reactor/v3/DecrypterType.cs | 12 +- de4dot.code/renamer/MemberInfos.cs | 10 +- de4dot.code/renamer/NameCreators.cs | 24 +-- de4dot.code/renamer/Renamer.cs | 58 ++--- de4dot.code/renamer/TypeInfo.cs | 22 +- de4dot.code/renamer/VariableNameState.cs | 10 +- de4dot.code/renamer/asmmodules/EventDef.cs | 10 +- de4dot.code/renamer/asmmodules/FieldDef.cs | 6 +- .../renamer/asmmodules/GenericParamDef.cs | 2 +- de4dot.code/renamer/asmmodules/IResolver.cs | 6 +- de4dot.code/renamer/asmmodules/MethodDef.cs | 14 +- de4dot.code/renamer/asmmodules/Module.cs | 36 ++-- de4dot.code/renamer/asmmodules/Modules.cs | 48 ++--- de4dot.code/renamer/asmmodules/ParamDef.cs | 10 +- de4dot.code/renamer/asmmodules/PropertyDef.cs | 10 +- de4dot.code/renamer/asmmodules/Ref.cs | 8 +- de4dot.code/renamer/asmmodules/RefDict.cs | 10 +- de4dot.code/renamer/asmmodules/TypeDef.cs | 70 +++---- 68 files changed, 482 insertions(+), 484 deletions(-) diff --git a/AssemblyData/methodsrewriter/CodeGenerator.cs b/AssemblyData/methodsrewriter/CodeGenerator.cs index 80a74e39..c5677b7e 100644 --- a/AssemblyData/methodsrewriter/CodeGenerator.cs +++ b/AssemblyData/methodsrewriter/CodeGenerator.cs @@ -34,7 +34,7 @@ using ROpCodes = System.Reflection.Emit.OpCodes; namespace AssemblyData.methodsrewriter { class CodeGenerator { - static Dictionary cecilToReflection = new Dictionary(); + static Dictionary dot10ToReflection = new Dictionary(); static CodeGenerator() { var refDict = new Dictionary(0x100); foreach (var f in typeof(ROpCodes).GetFields(BindingFlags.Static | BindingFlags.Public)) { @@ -51,7 +51,7 @@ namespace AssemblyData.methodsrewriter { ROpCode ropcode; if (!refDict.TryGetValue(opcode.Value, out ropcode)) continue; - cecilToReflection[opcode] = ropcode; + dot10ToReflection[opcode] = ropcode; } } @@ -332,7 +332,7 @@ namespace AssemblyData.methodsrewriter { ROpCode convertOpCode(OpCode opcode) { ROpCode ropcode; - if (cecilToReflection.TryGetValue(opcode, out ropcode)) + if (dot10ToReflection.TryGetValue(opcode, out ropcode)) return ropcode; return ROpCodes.Nop; } diff --git a/AssemblyData/methodsrewriter/MMethod.cs b/AssemblyData/methodsrewriter/MMethod.cs index dfd3be0e..99cee089 100644 --- a/AssemblyData/methodsrewriter/MMethod.cs +++ b/AssemblyData/methodsrewriter/MMethod.cs @@ -24,9 +24,9 @@ namespace AssemblyData.methodsrewriter { class MMethod { public MethodBase methodBase; public MethodDef methodDef; - public MMethod(MethodBase methodBase, MethodDef methodDefinition) { + public MMethod(MethodBase methodBase, MethodDef methodDef) { this.methodBase = methodBase; - this.methodDef = methodDefinition; + this.methodDef = methodDef; } public bool hasInstructions() { diff --git a/AssemblyData/methodsrewriter/MModule.cs b/AssemblyData/methodsrewriter/MModule.cs index e003bfcf..b85046b0 100644 --- a/AssemblyData/methodsrewriter/MModule.cs +++ b/AssemblyData/methodsrewriter/MModule.cs @@ -27,15 +27,15 @@ namespace AssemblyData.methodsrewriter { class MModule { public Module module; public ModuleDefMD moduleDef; - TypeDefinitionDict typeReferenceToType = new TypeDefinitionDict(); + TypeDefDict typeRefToType = new TypeDefDict(); Dictionary tokenToType = new Dictionary(); Dictionary tokenToGlobalMethod; Dictionary tokenToGlobalField; TypeDef moduleType; - public MModule(Module module, ModuleDefMD moduleDefinition) { + public MModule(Module module, ModuleDefMD moduleDef) { this.module = module; - this.moduleDef = moduleDefinition; + this.moduleDef = moduleDef; initTokenToType(); } @@ -49,17 +49,17 @@ namespace AssemblyData.methodsrewriter { } catch { tokenToType[token] = null; - typeReferenceToType.add(typeDef, null); + typeRefToType.add(typeDef, null); continue; } var mtype = new MType(type, typeDef); tokenToType[token] = mtype; - typeReferenceToType.add(typeDef, mtype); + typeRefToType.add(typeDef, mtype); } } public MType getType(IType typeRef) { - return typeReferenceToType.find(typeRef); + return typeRefToType.find(typeRef); } public MMethod getMethod(IMethod methodRef) { diff --git a/AssemblyData/methodsrewriter/MType.cs b/AssemblyData/methodsrewriter/MType.cs index 00d42751..22a32b37 100644 --- a/AssemblyData/methodsrewriter/MType.cs +++ b/AssemblyData/methodsrewriter/MType.cs @@ -28,23 +28,23 @@ namespace AssemblyData.methodsrewriter { public Type type; public TypeDef typeDef; Dictionary tokenToMethod; - MethodDefinitionDict methodReferenceToMethod; + MethodDefDict methodRefToMethod; Dictionary tokenToField; - FieldDefinitionDict fieldReferenceToField; + FieldDefDict fieldRefToField; - public MType(Type type, TypeDef typeDefinition) { + public MType(Type type, TypeDef typeDef) { this.type = type; - this.typeDef = typeDefinition; + this.typeDef = typeDef; } public MMethod getMethod(IMethod methodRef) { initMethods(); - return methodReferenceToMethod.find(methodRef); + return methodRefToMethod.find(methodRef); } public MField getField(IField fieldRef) { initFields(); - return fieldReferenceToField.find(fieldRef); + return fieldRefToField.find(fieldRef); } public MMethod getMethod(int token) { @@ -61,7 +61,7 @@ namespace AssemblyData.methodsrewriter { if (tokenToMethod != null) return; tokenToMethod = new Dictionary(typeDef.Methods.Count); - methodReferenceToMethod = new MethodDefinitionDict(); + methodRefToMethod = new MethodDefDict(); var tmpTokenToMethod = new Dictionary(); var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; @@ -71,7 +71,7 @@ namespace AssemblyData.methodsrewriter { var token = (int)m.MDToken.Raw; var method = new MMethod(tmpTokenToMethod[token], m); tokenToMethod[token] = method; - methodReferenceToMethod.add(method.methodDef, method); + methodRefToMethod.add(method.methodDef, method); } } @@ -79,7 +79,7 @@ namespace AssemblyData.methodsrewriter { if (tokenToField != null) return; tokenToField = new Dictionary(typeDef.Fields.Count); - fieldReferenceToField = new FieldDefinitionDict(); + fieldRefToField = new FieldDefDict(); var tmpTokenToField = new Dictionary(); var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; @@ -89,7 +89,7 @@ namespace AssemblyData.methodsrewriter { var token = (int)f.MDToken.Raw; var field = new MField(tmpTokenToField[token], f); tokenToField[token] = field; - fieldReferenceToField.add(field.fieldDef, field); + fieldRefToField.add(field.fieldDef, field); } } diff --git a/AssemblyData/methodsrewriter/Resolver.cs b/AssemblyData/methodsrewriter/Resolver.cs index 9d593089..6c6133f0 100644 --- a/AssemblyData/methodsrewriter/Resolver.cs +++ b/AssemblyData/methodsrewriter/Resolver.cs @@ -73,21 +73,21 @@ namespace AssemblyData.methodsrewriter { return null; } - public static MMethod getMethod(IMethod methodReference) { - if (methodReference == null) + public static MMethod getMethod(IMethod methodRef) { + if (methodRef == null) return null; - var module = getModule(methodReference.DeclaringType.Scope); + var module = getModule(methodRef.DeclaringType.Scope); if (module != null) - return module.getMethod(methodReference); + return module.getMethod(methodRef); return null; } - public static MField getField(IField fieldReference) { - if (fieldReference == null) + public static MField getField(IField fieldRef) { + if (fieldRef == null) return null; - var module = getModule(fieldReference.DeclaringType.Scope); + var module = getModule(fieldRef.DeclaringType.Scope); if (module != null) - return module.getField(fieldReference); + return module.getField(fieldRef); return null; } @@ -104,7 +104,7 @@ namespace AssemblyData.methodsrewriter { if (method != null && method.MethodSig != null) return getRtMethod(method); - throw new ApplicationException(string.Format("Unknown MemberReference: {0}", memberRef)); + throw new ApplicationException(string.Format("Unknown MemberRef: {0}", memberRef)); } public static Type getRtType(IType typeRef) { diff --git a/blocks/DotNetUtils.cs b/blocks/DotNetUtils.cs index 2375a6f7..bb262811 100644 --- a/blocks/DotNetUtils.cs +++ b/blocks/DotNetUtils.cs @@ -91,10 +91,10 @@ namespace de4dot.blocks { return true; } - public static FieldDef findFieldType(TypeDef typeDefinition, string typeName, bool isStatic) { - if (typeDefinition == null) + public static FieldDef findFieldType(TypeDef typeDef, string typeName, bool isStatic) { + if (typeDef == null) return null; - foreach (var field in typeDefinition.Fields) { + foreach (var field in typeDef.Fields) { if (field.IsStatic == isStatic && field.FieldSig.GetFieldType().GetFullName() == typeName) return field; } @@ -274,12 +274,12 @@ namespace de4dot.blocks { return getField(getType(module, field.DeclaringType), field); } - public static FieldDef getField(TypeDef type, IField fieldReference) { - if (type == null || fieldReference == null) + public static FieldDef getField(TypeDef type, IField fieldRef) { + if (type == null || fieldRef == null) return null; - if (fieldReference is FieldDef) - return (FieldDef)fieldReference; - return type.FindField(fieldReference.Name, fieldReference.FieldSig); + if (fieldRef is FieldDef) + return (FieldDef)fieldRef; + return type.FindField(fieldRef.Name, fieldRef.FieldSig); } public static FieldDef getField(TypeDef type, string typeFullName) { @@ -596,7 +596,7 @@ namespace de4dot.blocks { return null; } - public static TypeDefOrRefSig findOrCreateTypeReference(ModuleDef module, AssemblyRef asmRef, string ns, string name, bool isValueType) { + public static TypeDefOrRefSig findOrCreateTypeRef(ModuleDef module, AssemblyRef asmRef, string ns, string name, bool isValueType) { var typeRef = module.UpdateRowId(new TypeRefUser(module, ns, name, asmRef)); if (isValueType) return new ValueTypeSig(typeRef); diff --git a/blocks/ForwardScanOrder.cs b/blocks/ForwardScanOrder.cs index 751608ca..5f3150f1 100644 --- a/blocks/ForwardScanOrder.cs +++ b/blocks/ForwardScanOrder.cs @@ -23,7 +23,7 @@ using System.Collections.Generic; namespace de4dot.blocks { // This class makes sure that each block that is entered with a non-empty stack has at // least one of its source blocks sorted before itself. This is to make sure peverify - // doesn't complain AND also to make sure Mono.Cecil sets the correct maxstack. + // doesn't complain AND also to make sure dot10 sets the correct maxstack. class ForwardScanOrder { ScopeBlock scopeBlock; IList sorted; diff --git a/blocks/MemberDefDict.cs b/blocks/MemberDefDict.cs index 28a4b465..156b3beb 100644 --- a/blocks/MemberDefDict.cs +++ b/blocks/MemberDefDict.cs @@ -22,7 +22,7 @@ using System.Collections.Generic; using dot10.DotNet; namespace de4dot.blocks { - public class TypeDefinitionDict { + public class TypeDefDict { Dictionary tokenToValue = new Dictionary(); Dictionary tokenToKey = new Dictionary(); Dictionary refToValue = new Dictionary(TypeEqualityComparer.Instance); @@ -101,11 +101,11 @@ namespace de4dot.blocks { } } - public abstract class FieldDefinitionDictBase { + public abstract class FieldDefDictBase { Dictionary tokenToValue = new Dictionary(); Dictionary tokenToKey = new Dictionary(); - Dictionary refToValue = new Dictionary(); - Dictionary refToKey = new Dictionary(); + Dictionary refToValue = new Dictionary(); + Dictionary refToKey = new Dictionary(); public int Count { get { return tokenToValue.Count; } @@ -123,7 +123,7 @@ namespace de4dot.blocks { return new ScopeAndTokenKey(fieldDef); } - internal abstract IFieldReferenceKey getReferenceKey(IField fieldRef); + internal abstract IFieldRefKey getRefKey(IField fieldRef); public TValue find(IField fieldRef) { TValue value; @@ -131,7 +131,7 @@ namespace de4dot.blocks { if (fieldDef != null) tokenToValue.TryGetValue(getTokenKey(fieldDef), out value); else - refToValue.TryGetValue(getReferenceKey(fieldRef), out value); + refToValue.TryGetValue(getRefKey(fieldRef), out value); return value; } @@ -141,7 +141,7 @@ namespace de4dot.blocks { if (fieldDef != null && tokenToValue.TryGetValue(getTokenKey(fieldDef), out value)) return value; - refToValue.TryGetValue(getReferenceKey(fieldRef), out value); + refToValue.TryGetValue(getRefKey(fieldRef), out value); return value; } @@ -150,7 +150,7 @@ namespace de4dot.blocks { tokenToValue[tokenKey] = value; tokenToKey[tokenKey] = fieldDef; - var refKey = getReferenceKey(fieldDef); + var refKey = getRefKey(fieldDef); if (!refToValue.ContainsKey(refKey) || getAccessibilityOrder(fieldDef) < getAccessibilityOrder(refToKey[refKey])) { refToKey[refKey] = fieldDef; @@ -169,35 +169,35 @@ namespace de4dot.blocks { 0, // Public 70, // }; - static int getAccessibilityOrder(FieldDef fieldDefinition) { - return accessibilityOrder[(int)fieldDefinition.Attributes & 7]; + static int getAccessibilityOrder(FieldDef fieldDef) { + return accessibilityOrder[(int)fieldDef.Attributes & 7]; } public void onTypesRenamed() { - var newFieldRefToDef = new Dictionary(refToValue.Count); + var newFieldRefToDef = new Dictionary(refToValue.Count); foreach (var kvp in refToValue) - newFieldRefToDef[getReferenceKey((FieldDef)kvp.Key.FieldReference)] = kvp.Value; + newFieldRefToDef[getRefKey((FieldDef)kvp.Key.FieldRef)] = kvp.Value; refToValue = newFieldRefToDef; } } - public class FieldDefinitionDict : FieldDefinitionDictBase { - internal override IFieldReferenceKey getReferenceKey(IField fieldRef) { - return new FieldReferenceKey(fieldRef); + public class FieldDefDict : FieldDefDictBase { + internal override IFieldRefKey getRefKey(IField fieldRef) { + return new FieldRefKey(fieldRef); } } - public class FieldDefinitionAndDeclaringTypeDict : FieldDefinitionDictBase { - internal override IFieldReferenceKey getReferenceKey(IField fieldRef) { - return new FieldReferenceAndDeclaringTypeKey(fieldRef); + public class FieldDefAndDeclaringTypeDict : FieldDefDictBase { + internal override IFieldRefKey getRefKey(IField fieldRef) { + return new FieldRefAndDeclaringTypeKey(fieldRef); } } - public abstract class MethodDefinitionDictBase { + public abstract class MethodDefDictBase { Dictionary tokenToValue = new Dictionary(); Dictionary tokenToKey = new Dictionary(); - Dictionary refToValue = new Dictionary(); - Dictionary refToKey = new Dictionary(); + Dictionary refToValue = new Dictionary(); + Dictionary refToKey = new Dictionary(); public int Count { get { return tokenToValue.Count; } @@ -215,7 +215,7 @@ namespace de4dot.blocks { return new ScopeAndTokenKey(methodDef); } - internal abstract IMethodReferenceKey getReferenceKey(IMethod methodRef); + internal abstract IMethodRefKey getRefKey(IMethod methodRef); public TValue find(IMethod methodRef) { TValue value; @@ -223,7 +223,7 @@ namespace de4dot.blocks { if (methodDef != null) tokenToValue.TryGetValue(getTokenKey(methodDef), out value); else - refToValue.TryGetValue(getReferenceKey(methodRef), out value); + refToValue.TryGetValue(getRefKey(methodRef), out value); return value; } @@ -233,7 +233,7 @@ namespace de4dot.blocks { if (methodDef != null && tokenToValue.TryGetValue(getTokenKey(methodDef), out value)) return value; - refToValue.TryGetValue(getReferenceKey(methodRef), out value); + refToValue.TryGetValue(getRefKey(methodRef), out value); return value; } @@ -242,7 +242,7 @@ namespace de4dot.blocks { tokenToValue[tokenKey] = value; tokenToKey[tokenKey] = methodDef; - var refKey = getReferenceKey(methodDef); + var refKey = getRefKey(methodDef); if (!refToValue.ContainsKey(refKey) || getAccessibilityOrder(methodDef) < getAccessibilityOrder(refToKey[refKey])) { refToKey[refKey] = methodDef; @@ -261,34 +261,34 @@ namespace de4dot.blocks { 0, // Public 70, // }; - static int getAccessibilityOrder(MethodDef methodDefinition) { - return accessibilityOrder[(int)methodDefinition.Attributes & 7]; + static int getAccessibilityOrder(MethodDef methodDef) { + return accessibilityOrder[(int)methodDef.Attributes & 7]; } public void onTypesRenamed() { - var newFieldRefToDef = new Dictionary(refToValue.Count); + var newFieldRefToDef = new Dictionary(refToValue.Count); foreach (var kvp in refToValue) - newFieldRefToDef[getReferenceKey((MethodDef)kvp.Key.MethodReference)] = kvp.Value; + newFieldRefToDef[getRefKey((MethodDef)kvp.Key.MethodRef)] = kvp.Value; refToValue = newFieldRefToDef; } } - public class MethodDefinitionDict : MethodDefinitionDictBase { - internal override IMethodReferenceKey getReferenceKey(IMethod methodRef) { - return new MethodReferenceKey(methodRef); + public class MethodDefDict : MethodDefDictBase { + internal override IMethodRefKey getRefKey(IMethod methodRef) { + return new MethodRefKey(methodRef); } } - public class MethodDefinitionAndDeclaringTypeDict : MethodDefinitionDictBase { - internal override IMethodReferenceKey getReferenceKey(IMethod methodRef) { - return new MethodReferenceAndDeclaringTypeKey(methodRef); + public class MethodDefAndDeclaringTypeDict : MethodDefDictBase { + internal override IMethodRefKey getRefKey(IMethod methodRef) { + return new MethodRefAndDeclaringTypeKey(methodRef); } } - public abstract class EventDefinitionDictBase { + public abstract class EventDefDictBase { Dictionary tokenToValue = new Dictionary(); Dictionary tokenToKey = new Dictionary(); - Dictionary refToValue = new Dictionary(); + Dictionary refToValue = new Dictionary(); public int Count { get { return tokenToValue.Count; } @@ -302,11 +302,11 @@ namespace de4dot.blocks { return tokenToValue.Values; } - ScopeAndTokenKey getTokenKey(EventDef eventReference) { - return new ScopeAndTokenKey(eventReference); + ScopeAndTokenKey getTokenKey(EventDef eventRef) { + return new ScopeAndTokenKey(eventRef); } - internal abstract IEventReferenceKey getReferenceKey(EventDef eventRef); + internal abstract IEventRefKey getRefKey(EventDef eventRef); public TValue find(EventDef eventRef) { TValue value; @@ -319,7 +319,7 @@ namespace de4dot.blocks { if (tokenToValue.TryGetValue(getTokenKey(eventRef), out value)) return value; - refToValue.TryGetValue(getReferenceKey(eventRef), out value); + refToValue.TryGetValue(getRefKey(eventRef), out value); return value; } @@ -328,33 +328,33 @@ namespace de4dot.blocks { tokenToValue[tokenKey] = value; tokenToKey[tokenKey] = eventDef; - refToValue[getReferenceKey(eventDef)] = value; + refToValue[getRefKey(eventDef)] = value; } public void onTypesRenamed() { - var newFieldRefToDef = new Dictionary(refToValue.Count); + var newFieldRefToDef = new Dictionary(refToValue.Count); foreach (var kvp in refToValue) - newFieldRefToDef[getReferenceKey((EventDef)kvp.Key.EventDef)] = kvp.Value; + newFieldRefToDef[getRefKey((EventDef)kvp.Key.EventDef)] = kvp.Value; refToValue = newFieldRefToDef; } } - public class EventDefinitionDict : EventDefinitionDictBase { - internal override IEventReferenceKey getReferenceKey(EventDef eventRef) { - return new EventReferenceKey(eventRef); + public class EventDefDict : EventDefDictBase { + internal override IEventRefKey getRefKey(EventDef eventRef) { + return new EventRefKey(eventRef); } } - public class EventDefinitionAndDeclaringTypeDict : EventDefinitionDictBase { - internal override IEventReferenceKey getReferenceKey(EventDef eventRef) { - return new EventReferenceAndDeclaringTypeKey(eventRef); + public class EventDefAndDeclaringTypeDict : EventDefDictBase { + internal override IEventRefKey getRefKey(EventDef eventRef) { + return new EventRefAndDeclaringTypeKey(eventRef); } } - public abstract class PropertyDefinitionDictBase { + public abstract class PropertyDefDictBase { Dictionary tokenToValue = new Dictionary(); Dictionary tokenToKey = new Dictionary(); - Dictionary refToValue = new Dictionary(); + Dictionary refToValue = new Dictionary(); public int Count { get { return tokenToValue.Count; } @@ -368,11 +368,11 @@ namespace de4dot.blocks { return tokenToValue.Values; } - ScopeAndTokenKey getTokenKey(PropertyDef propertyReference) { - return new ScopeAndTokenKey(propertyReference); + ScopeAndTokenKey getTokenKey(PropertyDef propertyRef) { + return new ScopeAndTokenKey(propertyRef); } - internal abstract IPropertyReferenceKey getReferenceKey(PropertyDef propertyReference); + internal abstract IPropertyRefKey getRefKey(PropertyDef propertyRef); public TValue find(PropertyDef propRef) { TValue value; @@ -385,7 +385,7 @@ namespace de4dot.blocks { if (tokenToValue.TryGetValue(getTokenKey(propRef), out value)) return value; - refToValue.TryGetValue(getReferenceKey(propRef), out value); + refToValue.TryGetValue(getRefKey(propRef), out value); return value; } @@ -394,26 +394,26 @@ namespace de4dot.blocks { tokenToValue[tokenKey] = value; tokenToKey[tokenKey] = propDef; - refToValue[getReferenceKey(propDef)] = value; + refToValue[getRefKey(propDef)] = value; } public void onTypesRenamed() { - var newFieldRefToDef = new Dictionary(refToValue.Count); + var newFieldRefToDef = new Dictionary(refToValue.Count); foreach (var kvp in refToValue) - newFieldRefToDef[getReferenceKey((PropertyDef)kvp.Key.PropertyDef)] = kvp.Value; + newFieldRefToDef[getRefKey((PropertyDef)kvp.Key.PropertyDef)] = kvp.Value; refToValue = newFieldRefToDef; } } - public class PropertyDefinitionDict : PropertyDefinitionDictBase { - internal override IPropertyReferenceKey getReferenceKey(PropertyDef propRef) { - return new PropertyReferenceKey(propRef); + public class PropertyDefDict : PropertyDefDictBase { + internal override IPropertyRefKey getRefKey(PropertyDef propRef) { + return new PropertyRefKey(propRef); } } - public class PropertyDefinitionAndDeclaringTypeDict : PropertyDefinitionDictBase { - internal override IPropertyReferenceKey getReferenceKey(PropertyDef propRef) { - return new PropertyReferenceAndDeclaringTypeKey(propRef); + public class PropertyDefAndDeclaringTypeDict : PropertyDefDictBase { + internal override IPropertyRefKey getRefKey(PropertyDef propRef) { + return new PropertyRefAndDeclaringTypeKey(propRef); } } @@ -502,30 +502,30 @@ namespace de4dot.blocks { } } - interface IFieldReferenceKey { - IField FieldReference { get; } + interface IFieldRefKey { + IField FieldRef { get; } } - interface IMethodReferenceKey { - IMethod MethodReference { get; } + interface IMethodRefKey { + IMethod MethodRef { get; } } - interface IEventReferenceKey { + interface IEventRefKey { EventDef EventDef { get; } } - interface IPropertyReferenceKey { + interface IPropertyRefKey { PropertyDef PropertyDef { get; } } - sealed class FieldReferenceKey : IFieldReferenceKey { + sealed class FieldRefKey : IFieldRefKey { readonly IField fieldRef; - public IField FieldReference { + public IField FieldRef { get { return fieldRef; } } - public FieldReferenceKey(IField fieldRef) { + public FieldRefKey(IField fieldRef) { this.fieldRef = fieldRef; } @@ -534,7 +534,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as FieldReferenceKey; + var other = obj as FieldRefKey; if (other == null) return false; return new SigComparer().Equals(fieldRef, other.fieldRef); @@ -545,14 +545,14 @@ namespace de4dot.blocks { } } - sealed class MethodReferenceKey : IMethodReferenceKey { + sealed class MethodRefKey : IMethodRefKey { readonly IMethod methodRef; - public IMethod MethodReference { + public IMethod MethodRef { get { return methodRef; } } - public MethodReferenceKey(IMethod methodRef) { + public MethodRefKey(IMethod methodRef) { this.methodRef = methodRef; } @@ -561,7 +561,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as MethodReferenceKey; + var other = obj as MethodRefKey; if (other == null) return false; return new SigComparer().Equals(methodRef, other.methodRef); @@ -572,14 +572,14 @@ namespace de4dot.blocks { } } - sealed class FieldReferenceAndDeclaringTypeKey : IFieldReferenceKey { + sealed class FieldRefAndDeclaringTypeKey : IFieldRefKey { readonly IField fieldRef; - public IField FieldReference { + public IField FieldRef { get { return fieldRef; } } - public FieldReferenceAndDeclaringTypeKey(IField fieldRef) { + public FieldRefAndDeclaringTypeKey(IField fieldRef) { this.fieldRef = fieldRef; } @@ -588,7 +588,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as FieldReferenceAndDeclaringTypeKey; + var other = obj as FieldRefAndDeclaringTypeKey; if (other == null) return false; return new SigComparer(SigComparerOptions.CompareMethodFieldDeclaringType).Equals(fieldRef, other.fieldRef); @@ -599,14 +599,14 @@ namespace de4dot.blocks { } } - sealed class MethodReferenceAndDeclaringTypeKey : IMethodReferenceKey { + sealed class MethodRefAndDeclaringTypeKey : IMethodRefKey { readonly IMethod methodRef; - public IMethod MethodReference { + public IMethod MethodRef { get { return methodRef; } } - public MethodReferenceAndDeclaringTypeKey(IMethod methodRef) { + public MethodRefAndDeclaringTypeKey(IMethod methodRef) { this.methodRef = methodRef; } @@ -615,7 +615,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as MethodReferenceAndDeclaringTypeKey; + var other = obj as MethodRefAndDeclaringTypeKey; if (other == null) return false; return new SigComparer(SigComparerOptions.CompareMethodFieldDeclaringType).Equals(methodRef, other.methodRef); @@ -626,14 +626,14 @@ namespace de4dot.blocks { } } - sealed class EventReferenceKey : IEventReferenceKey { + sealed class EventRefKey : IEventRefKey { readonly EventDef eventRef; public EventDef EventDef { get { return eventRef; } } - public EventReferenceKey(EventDef eventRef) { + public EventRefKey(EventDef eventRef) { this.eventRef = eventRef; } @@ -642,7 +642,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as EventReferenceKey; + var other = obj as EventRefKey; if (other == null) return false; return new SigComparer().Equals(eventRef, other.eventRef); @@ -653,14 +653,14 @@ namespace de4dot.blocks { } } - sealed class EventReferenceAndDeclaringTypeKey : IEventReferenceKey { + sealed class EventRefAndDeclaringTypeKey : IEventRefKey { readonly EventDef eventRef; public EventDef EventDef { get { return eventRef; } } - public EventReferenceAndDeclaringTypeKey(EventDef eventRef) { + public EventRefAndDeclaringTypeKey(EventDef eventRef) { this.eventRef = eventRef; } @@ -669,7 +669,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as EventReferenceAndDeclaringTypeKey; + var other = obj as EventRefAndDeclaringTypeKey; if (other == null) return false; return new SigComparer(SigComparerOptions.CompareEventDeclaringType).Equals(eventRef, other.eventRef); @@ -680,14 +680,14 @@ namespace de4dot.blocks { } } - sealed class PropertyReferenceKey : IPropertyReferenceKey { + sealed class PropertyRefKey : IPropertyRefKey { readonly PropertyDef propRef; public PropertyDef PropertyDef { get { return propRef; } } - public PropertyReferenceKey(PropertyDef propRef) { + public PropertyRefKey(PropertyDef propRef) { this.propRef = propRef; } @@ -696,7 +696,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as PropertyReferenceKey; + var other = obj as PropertyRefKey; if (other == null) return false; return new SigComparer().Equals(propRef, other.propRef); @@ -707,14 +707,14 @@ namespace de4dot.blocks { } } - sealed class PropertyReferenceAndDeclaringTypeKey : IPropertyReferenceKey { + sealed class PropertyRefAndDeclaringTypeKey : IPropertyRefKey { readonly PropertyDef propRef; public PropertyDef PropertyDef { get { return propRef; } } - public PropertyReferenceAndDeclaringTypeKey(PropertyDef propRef) { + public PropertyRefAndDeclaringTypeKey(PropertyDef propRef) { this.propRef = propRef; } @@ -723,7 +723,7 @@ namespace de4dot.blocks { } public override bool Equals(object obj) { - var other = obj as PropertyReferenceAndDeclaringTypeKey; + var other = obj as PropertyRefAndDeclaringTypeKey; if (other == null) return false; return new SigComparer(SigComparerOptions.ComparePropertyDeclaringType).Equals(propRef, other.propRef); diff --git a/blocks/Properties/AssemblyInfo.cs b/blocks/Properties/AssemblyInfo.cs index 81934537..168d5fe8 100644 --- a/blocks/Properties/AssemblyInfo.cs +++ b/blocks/Properties/AssemblyInfo.cs @@ -21,7 +21,7 @@ using System.Reflection; using System.Runtime.InteropServices; [assembly: AssemblyTitle("blocks")] -[assembly: AssemblyDescription("Modifies Mono.Cecil MethodDefinition bodies")] +[assembly: AssemblyDescription("Modifies dot10 MethodDef bodies")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("blocks")] diff --git a/de4dot.code/DeobfuscatorContext.cs b/de4dot.code/DeobfuscatorContext.cs index 400f41d7..fc8a1948 100644 --- a/de4dot.code/DeobfuscatorContext.cs +++ b/de4dot.code/DeobfuscatorContext.cs @@ -46,7 +46,7 @@ namespace de4dot.code { dataDict.Remove(name); } - static ITypeDefOrRef getNonGenericTypeReference(ITypeDefOrRef typeRef) { + static ITypeDefOrRef getNonGenericTypeRef(ITypeDefOrRef typeRef) { var ts = typeRef as TypeSpec; if (ts == null) return typeRef; @@ -59,7 +59,7 @@ namespace de4dot.code { public TypeDef resolveType(ITypeDefOrRef type) { if (type == null) return null; - type = getNonGenericTypeReference(type); + type = getNonGenericTypeRef(type); var typeDef = type as TypeDef; if (typeDef != null) diff --git a/de4dot.code/MethodPrinter.cs b/de4dot.code/MethodPrinter.cs index 0ce91c79..79c46969 100644 --- a/de4dot.code/MethodPrinter.cs +++ b/de4dot.code/MethodPrinter.cs @@ -133,11 +133,11 @@ namespace de4dot.code { printExInfo(exInfo); var instrString = instr.OpCode.Name; var operandString = getOperandString(instr); - var memberReference = instr.Operand as ITokenOperand; + var memberRef = instr.Operand as ITokenOperand; if (operandString == "") Logger.log(loggerEvent, "{0}", instrString); - else if (memberReference != null) - Logger.log(loggerEvent, "{0,-9} {1} // {2:X8}", instrString, Utils.removeNewlines(operandString), memberReference.MDToken.ToUInt32()); + else if (memberRef != null) + Logger.log(loggerEvent, "{0,-9} {1} // {2:X8}", instrString, Utils.removeNewlines(operandString), memberRef.MDToken.ToUInt32()); else Logger.log(loggerEvent, "{0,-9} {1}", instrString, Utils.removeNewlines(operandString)); } diff --git a/de4dot.code/MethodReturnValueInliner.cs b/de4dot.code/MethodReturnValueInliner.cs index 1951c4b3..856e83ca 100644 --- a/de4dot.code/MethodReturnValueInliner.cs +++ b/de4dot.code/MethodReturnValueInliner.cs @@ -165,7 +165,7 @@ namespace de4dot.code { this.callEndIndex = callEndIndex; } - public IMethod getMethodReference() { + public IMethod getMethodRef() { return (IMethod)block.Instructions[callEndIndex].Operand; } } @@ -257,7 +257,7 @@ namespace de4dot.code { bool findArgs(CallResult callResult) { var block = callResult.block; - var method = callResult.getMethodReference(); + var method = callResult.getMethodRef(); var methodArgs = DotNetUtils.getArgs(method); int numArgs = methodArgs.Count; var args = new object[numArgs]; diff --git a/de4dot.code/ObfuscatedFile.cs b/de4dot.code/ObfuscatedFile.cs index d04bb6cd..15ac0462 100644 --- a/de4dot.code/ObfuscatedFile.cs +++ b/de4dot.code/ObfuscatedFile.cs @@ -552,8 +552,6 @@ namespace de4dot.code { deob.DeobfuscatedFile = null; if (!options.ControlFlowDeobfuscation) { - // If it's the unknown type, we don't remove any types that could cause Mono.Cecil - // to throw an exception. if (ShouldPreserveTokens()) return; } diff --git a/de4dot.code/StringInliner.cs b/de4dot.code/StringInliner.cs index cf586ddd..b60e5e32 100644 --- a/de4dot.code/StringInliner.cs +++ b/de4dot.code/StringInliner.cs @@ -128,7 +128,7 @@ namespace de4dot.code { } class StaticStringInliner : StringInlinerBase { - MethodDefinitionAndDeclaringTypeDict> stringDecrypters = new MethodDefinitionAndDeclaringTypeDict>(); + MethodDefAndDeclaringTypeDict> stringDecrypters = new MethodDefAndDeclaringTypeDict>(); public override bool HasHandlers { get { return stringDecrypters.Count != 0; } diff --git a/de4dot.code/deobfuscators/Agile_NET/vm/Csvm.cs b/de4dot.code/deobfuscators/Agile_NET/vm/Csvm.cs index 43230ea1..8699f08f 100644 --- a/de4dot.code/deobfuscators/Agile_NET/vm/Csvm.cs +++ b/de4dot.code/deobfuscators/Agile_NET/vm/Csvm.cs @@ -28,10 +28,10 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm { IDeobfuscatorContext deobfuscatorContext; ModuleDefMD module; EmbeddedResource resource; - AssemblyRef vmAssemblyReference; + AssemblyRef vmAssemblyRef; public bool Detected { - get { return resource != null && vmAssemblyReference != null; } + get { return resource != null && vmAssemblyRef != null; } } public EmbeddedResource Resource { @@ -48,16 +48,16 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm { this.module = module; if (oldOne.resource != null) this.resource = (EmbeddedResource)module.Resources[oldOne.module.Resources.IndexOf(oldOne.resource)]; - if (oldOne.vmAssemblyReference != null) - this.vmAssemblyReference = module.ResolveAssemblyRef(oldOne.vmAssemblyReference.Rid); + if (oldOne.vmAssemblyRef != null) + this.vmAssemblyRef = module.ResolveAssemblyRef(oldOne.vmAssemblyRef.Rid); } public void find() { resource = findCsvmResource(); - vmAssemblyReference = findVmAssemblyReference(); + vmAssemblyRef = findVmAssemblyRef(); } - AssemblyRef findVmAssemblyReference() { + AssemblyRef findVmAssemblyRef() { foreach (var memberRef in module.GetMemberRefs()) { var sig = memberRef.MethodSig; if (sig == null) @@ -132,7 +132,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm { } VmOpCodeHandlerDetector getVmOpCodeHandlerDetector() { - var vmFilename = vmAssemblyReference.Name + ".dll"; + var vmFilename = vmAssemblyRef.Name + ".dll"; var vmModulePath = Path.Combine(Path.GetDirectoryName(module.Location), vmFilename); Logger.v("CSVM filename: {0}", vmFilename); diff --git a/de4dot.code/deobfuscators/Agile_NET/vm/CsvmToCilMethodConverter.cs b/de4dot.code/deobfuscators/Agile_NET/vm/CsvmToCilMethodConverter.cs index 342288f4..5f13d521 100644 --- a/de4dot.code/deobfuscators/Agile_NET/vm/CsvmToCilMethodConverter.cs +++ b/de4dot.code/deobfuscators/Agile_NET/vm/CsvmToCilMethodConverter.cs @@ -234,12 +234,12 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm { throw new ApplicationException("Invalid number of locals"); for (int i = 0; i < numLocals; i++) - locals.Add(new Local(readTypeReference(reader))); + locals.Add(new Local(readTypeRef(reader))); return locals; } - TypeSig readTypeReference(BinaryReader reader) { + TypeSig readTypeRef(BinaryReader reader) { var etype = (ElementType)reader.ReadInt32(); switch (etype) { case ElementType.Void: return module.CorLibTypes.Void; @@ -345,7 +345,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm { object fixOperand(IList instrs, Instruction instr, IVmOperand vmOperand) { if (vmOperand is TokenOperand) - return getMemberReference(((TokenOperand)vmOperand).token); + return getMemberRef(((TokenOperand)vmOperand).token); if (vmOperand is TargetDisplOperand) return getInstruction(instrs, instr, ((TargetDisplOperand)vmOperand).displacement); @@ -387,7 +387,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm { return fieldRef; } - ITokenOperand getMemberReference(int token) { + ITokenOperand getMemberRef(int token) { var memberRef = module.ResolveToken(token) as ITokenOperand; if (memberRef == null) throw new ApplicationException(string.Format("Could not find member ref: {0:X8}", token)); diff --git a/de4dot.code/deobfuscators/Agile_NET/vm/UnknownHandlerInfo.cs b/de4dot.code/deobfuscators/Agile_NET/vm/UnknownHandlerInfo.cs index f2d923e1..10c77360 100644 --- a/de4dot.code/deobfuscators/Agile_NET/vm/UnknownHandlerInfo.cs +++ b/de4dot.code/deobfuscators/Agile_NET/vm/UnknownHandlerInfo.cs @@ -75,7 +75,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm { } static internal IEnumerable getFields(TypeDef type) { - var typeFields = new FieldDefinitionAndDeclaringTypeDict(); + var typeFields = new FieldDefAndDeclaringTypeDict(); foreach (var field in type.Fields) typeFields.add(field, field); var realFields = new Dictionary(); diff --git a/de4dot.code/deobfuscators/Babel_NET/ImageReader.cs b/de4dot.code/deobfuscators/Babel_NET/ImageReader.cs index f6440d66..f5ed7ead 100644 --- a/de4dot.code/deobfuscators/Babel_NET/ImageReader.cs +++ b/de4dot.code/deobfuscators/Babel_NET/ImageReader.cs @@ -52,15 +52,15 @@ namespace de4dot.code.deobfuscators.Babel_NET { string[] strings; AssemblyRef[] assemblyNames; Dictionary methodOffsets; - List typeReferences; - MemberReferenceConverter memberReferenceConverter; + List typeRefs; + MemberRefConverter memberRefConverter; IDeobfuscatorContext deobfuscatorContext; public ImageReader(IDeobfuscatorContext deobfuscatorContext, ModuleDefMD module, byte[] data) { this.deobfuscatorContext = deobfuscatorContext; this.module = module; this.reader = MemoryImageStream.Create(data); - this.memberReferenceConverter = new MemberReferenceConverter(module); + this.memberRefConverter = new MemberRefConverter(module); } public bool initialize() { @@ -86,26 +86,26 @@ namespace de4dot.code.deobfuscators.Babel_NET { void initializeV10() { reader.ReadInt16(); int methodNamesOffset = (int)reader.ReadInt64(); - int typeReferencesOffset = (int)reader.ReadInt64(); - int assemblyReferencesOffset = (int)reader.ReadInt64(); + int typeRefsOffset = (int)reader.ReadInt64(); + int assemblyRefsOffset = (int)reader.ReadInt64(); int stringsOffset = (int)reader.ReadInt64(); initializeStrings(stringsOffset); - initializeAssemblyNames(assemblyReferencesOffset); + initializeAssemblyNames(assemblyRefsOffset); initializeMethodNames(methodNamesOffset); - initializeTypeReferences(typeReferencesOffset); + initializeTypeRefs(typeRefsOffset); } void initializeV55() { int methodNamesOffset = (int)reader.ReadInt64() ^ METADATA_SIG; - int typeReferencesOffset = (int)reader.ReadInt64() ^ (METADATA_SIG << 1); - int assemblyReferencesOffset = (int)reader.ReadInt64() ^ ((METADATA_SIG << 1) + 1); + int typeRefsOffset = (int)reader.ReadInt64() ^ (METADATA_SIG << 1); + int assemblyRefsOffset = (int)reader.ReadInt64() ^ ((METADATA_SIG << 1) + 1); int stringsOffset = (int)reader.ReadInt64() ^ (((METADATA_SIG << 1) + 1) << 1); initializeStrings(stringsOffset); - initializeAssemblyNames(assemblyReferencesOffset); + initializeAssemblyNames(assemblyRefsOffset); initializeMethodNames(methodNamesOffset); - initializeTypeReferences(typeReferencesOffset); + initializeTypeRefs(typeRefsOffset); } public void restore(string name, MethodDef method) { @@ -138,11 +138,11 @@ namespace de4dot.code.deobfuscators.Babel_NET { body.ExceptionHandlers.Add(eh); } - BabelMethodDefinition getMethod(string name) { + BabelMethodDef getMethod(string name) { int offset = methodOffsets[name]; methodOffsets.Remove(name); reader.Position = offset; - return new MethodDefinitionReader(this, reader).read(); + return new MethodDefReader(this, reader).read(); } public string readString() { @@ -150,7 +150,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { } public TypeSig readTypeSig() { - return typeReferences[readVariableLengthInt32()]; + return typeRefs[readVariableLengthInt32()]; } public TypeSig[] readTypeSigs() { @@ -160,7 +160,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { return refs; } - public IField readFieldReference() { + public IField readFieldRef() { var name = readString(); var declaringType = readTypeSig(); @@ -171,7 +171,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { Utils.removeNewlines(declaringType))); } - return memberReferenceConverter.convert(fields[0]); + return memberRefConverter.convert(fields[0]); } static List getFields(TypeDef type, string name) { @@ -180,10 +180,10 @@ namespace de4dot.code.deobfuscators.Babel_NET { return new List(type.FindFields(name)); } - public IMethod readMethodReference() { - var babelMethodRef = new MethodReferenceReader(this, reader).read(); + public IMethod readMethodRef() { + var babelMethodRef = new MethodRefReader(this, reader).read(); - var method = getMethodReference(babelMethodRef); + var method = getMethodRef(babelMethodRef); if (method == null) { throw new ApplicationException(string.Format("Could not find method '{0}' in type '{1}'", Utils.removeNewlines(babelMethodRef.Name), @@ -198,7 +198,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { return module.UpdateRowId(mr); } - IMethod getMethodReference(BabelMethodreference babelMethodRef) { + IMethod getMethodRef(BabelMethodreference babelMethodRef) { var declaringType = resolve(babelMethodRef.DeclaringType); if (declaringType == null) return null; @@ -221,10 +221,10 @@ namespace de4dot.code.deobfuscators.Babel_NET { foreach (var method in declaringType.Methods) { if (compareMethod(GenericArgsSubstitutor.create(method, gis, gim), babelMethodRef)) { if (!babelMethodRef.IsGenericMethod) - methods.Add(memberReferenceConverter.convert(method)); + methods.Add(memberRefConverter.convert(method)); else { var gim2 = new GenericInstMethodSig(babelMethodRef.GenericArguments); - var ms = module.UpdateRowId(new MethodSpecUser(memberReferenceConverter.convert(method), gim2)); + var ms = module.UpdateRowId(new MethodSpecUser(memberRefConverter.convert(method), gim2)); methods.Add(ms); } } @@ -329,39 +329,39 @@ namespace de4dot.code.deobfuscators.Babel_NET { } } - void initializeTypeReferences(int headerOffset) { + void initializeTypeRefs(int headerOffset) { reader.Position = headerOffset; if (reader.ReadInt32() != TYPEREFS_SIG) throw new ApplicationException("Invalid typerefs sig"); int numTypeRefs = reader.ReadInt32(); - typeReferences = new List(numTypeRefs + 1); - typeReferences.Add(null); + typeRefs = new List(numTypeRefs + 1); + typeRefs.Add(null); var genericArgFixes = new Dictionary>(); for (int i = 0; i < numTypeRefs; i++) { TypeId typeId = (TypeId)reader.ReadByte(); switch (typeId) { case TypeId.TypeRef: - typeReferences.Add(readTypeRef()); + typeRefs.Add(readTypeRef()); break; case TypeId.GenericInstance: List genericArgs; var git = readGenericInstanceType(out genericArgs); - typeReferences.Add(git); + typeRefs.Add(git); genericArgFixes[git] = genericArgs; break; case TypeId.Pointer: - typeReferences.Add(readPointerType()); + typeRefs.Add(readPointerType()); break; case TypeId.Array: - typeReferences.Add(readArrayType()); + typeRefs.Add(readArrayType()); break; case TypeId.ByRef: - typeReferences.Add(readByReferenceType()); + typeRefs.Add(readByRefType()); break; default: @@ -372,7 +372,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { foreach (var kv in genericArgFixes) { var git = kv.Key; foreach (var typeNum in kv.Value) - git.GenericArguments.Add(typeReferences[typeNum]); + git.GenericArguments.Add(typeRefs[typeNum]); } } @@ -381,13 +381,13 @@ namespace de4dot.code.deobfuscators.Babel_NET { parseReflectionTypeName(readString(), out ns, out name); var asmRef = assemblyNames[readVariableLengthInt32()]; var declaringType = readTypeSig(); - var typeReference = new TypeRefUser(module, ns, name); + var typeRef = new TypeRefUser(module, ns, name); if (declaringType != null) - typeReference.ResolutionScope = getTypeRef(declaringType); + typeRef.ResolutionScope = getTypeRef(declaringType); else - typeReference.ResolutionScope = asmRef; + typeRef.ResolutionScope = asmRef; - return memberReferenceConverter.convert(typeReference); + return memberRefConverter.convert(typeRef); } TypeRef getTypeRef(TypeSig type) { @@ -469,7 +469,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { return new ArraySig(typeSig, rank); } - ByRefSig readByReferenceType() { + ByRefSig readByRefType() { return new ByRefSig(readTypeSig()); } diff --git a/de4dot.code/deobfuscators/Babel_NET/MemberReferenceConverter.cs b/de4dot.code/deobfuscators/Babel_NET/MemberReferenceConverter.cs index 4c7ff56c..d636a12a 100644 --- a/de4dot.code/deobfuscators/Babel_NET/MemberReferenceConverter.cs +++ b/de4dot.code/deobfuscators/Babel_NET/MemberReferenceConverter.cs @@ -23,14 +23,14 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.Babel_NET { // Converts type references/definitions in one module to this module - class MemberReferenceConverter { + class MemberRefConverter { ModuleDefMD module; public ModuleDefMD Module { get { return module; } } - public MemberReferenceConverter(ModuleDefMD module) { + public MemberRefConverter(ModuleDefMD module) { this.module = module; } @@ -60,7 +60,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { public IField convert(IField fieldRef) { if (isInOurModule(fieldRef)) - return tryGetFieldDefinition(fieldRef); + return tryGetFieldDef(fieldRef); return createImporter().Import(fieldRef); } @@ -68,11 +68,11 @@ namespace de4dot.code.deobfuscators.Babel_NET { if (!(methodRef is MemberRef || methodRef is MethodDef) || methodRef.MethodSig == null) throw new ApplicationException("Invalid method reference type"); if (isInOurModule(methodRef)) - return (IMethodDefOrRef)tryGetMethodDefinition(methodRef); + return (IMethodDefOrRef)tryGetMethodDef(methodRef); return (IMethodDefOrRef)createImporter().Import(methodRef); } - public IField tryGetFieldDefinition(IField fieldRef) { + public IField tryGetFieldDef(IField fieldRef) { var fieldDef = fieldRef as FieldDef; if (fieldDef != null) return fieldDef; @@ -83,7 +83,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { return DotNetUtils.getField(declaringType, fieldRef); } - public IMethod tryGetMethodDefinition(IMethod methodRef) { + public IMethod tryGetMethodDef(IMethod methodRef) { var methodDef = methodRef as MethodDef; if (methodDef != null) return methodDef; diff --git a/de4dot.code/deobfuscators/Babel_NET/MethodBodyReader.cs b/de4dot.code/deobfuscators/Babel_NET/MethodBodyReader.cs index 38c17a55..34436bd0 100644 --- a/de4dot.code/deobfuscators/Babel_NET/MethodBodyReader.cs +++ b/de4dot.code/deobfuscators/Babel_NET/MethodBodyReader.cs @@ -45,11 +45,11 @@ namespace de4dot.code.deobfuscators.Babel_NET { } protected override IField ReadInlineField(Instruction instr) { - return imageReader.readFieldReference(); + return imageReader.readFieldRef(); } protected override IMethod ReadInlineMethod(Instruction instr) { - return imageReader.readMethodReference(); + return imageReader.readMethodRef(); } protected override MethodSig ReadInlineSig(Instruction instr) { @@ -63,8 +63,8 @@ namespace de4dot.code.deobfuscators.Babel_NET { protected override ITokenOperand ReadInlineTok(Instruction instr) { switch (reader.ReadByte()) { case 0: return imageReader.readTypeSig().ToTypeDefOrRef(); - case 1: return imageReader.readFieldReference(); - case 2: return imageReader.readMethodReference(); + case 1: return imageReader.readFieldRef(); + case 2: return imageReader.readMethodRef(); default: throw new ApplicationException("Unknown token type"); } } diff --git a/de4dot.code/deobfuscators/Babel_NET/MethodReferenceReader.cs b/de4dot.code/deobfuscators/Babel_NET/MethodReferenceReader.cs index 92d2f45e..ee545cd5 100644 --- a/de4dot.code/deobfuscators/Babel_NET/MethodReferenceReader.cs +++ b/de4dot.code/deobfuscators/Babel_NET/MethodReferenceReader.cs @@ -42,7 +42,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { } } - class BabelMethodDefinition : BabelMethodreference { + class BabelMethodDef : BabelMethodreference { Parameter thisParameter; public int Flags2 { get; set; } @@ -95,16 +95,16 @@ namespace de4dot.code.deobfuscators.Babel_NET { } } - class MethodReferenceReader { + class MethodRefReader { ImageReader imageReader; IBinaryReader reader; BabelMethodreference bmr; - public MethodReferenceReader(ImageReader imageReader, IBinaryReader reader) + public MethodRefReader(ImageReader imageReader, IBinaryReader reader) : this(imageReader, reader, new BabelMethodreference()) { } - public MethodReferenceReader(ImageReader imageReader, IBinaryReader reader, BabelMethodreference bmr) { + public MethodRefReader(ImageReader imageReader, IBinaryReader reader, BabelMethodreference bmr) { this.imageReader = imageReader; this.reader = reader; this.bmr = bmr; @@ -133,19 +133,19 @@ namespace de4dot.code.deobfuscators.Babel_NET { } } - class MethodDefinitionReader { - MethodReferenceReader methodReferenceReader; + class MethodDefReader { + MethodRefReader methodRefReader; MethodBodyReader methodBodyReader; - BabelMethodDefinition bmd; + BabelMethodDef bmd; - public MethodDefinitionReader(ImageReader imageReader, IBinaryReader reader) { - this.bmd = new BabelMethodDefinition(); - this.methodReferenceReader = new MethodReferenceReader(imageReader, reader, bmd); + public MethodDefReader(ImageReader imageReader, IBinaryReader reader) { + this.bmd = new BabelMethodDef(); + this.methodRefReader = new MethodRefReader(imageReader, reader, bmd); this.methodBodyReader = new MethodBodyReader(imageReader, reader); } - public BabelMethodDefinition read() { - methodReferenceReader.read(); + public BabelMethodDef read() { + methodRefReader.read(); methodBodyReader.read(bmd.getRealParameters()); bmd.setBody(methodBodyReader); return bmd; diff --git a/de4dot.code/deobfuscators/Babel_NET/ProxyCallFixer.cs b/de4dot.code/deobfuscators/Babel_NET/ProxyCallFixer.cs index b7d98a34..c522e8c9 100644 --- a/de4dot.code/deobfuscators/Babel_NET/ProxyCallFixer.cs +++ b/de4dot.code/deobfuscators/Babel_NET/ProxyCallFixer.cs @@ -25,7 +25,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.Babel_NET { class ProxyCallFixer : ProxyCallFixer2 { - MethodDefinitionAndDeclaringTypeDict methodToType = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict methodToType = new MethodDefAndDeclaringTypeDict(); public ProxyCallFixer(ModuleDefMD module) : base(module) { diff --git a/de4dot.code/deobfuscators/Babel_NET/StringDecrypter.cs b/de4dot.code/deobfuscators/Babel_NET/StringDecrypter.cs index bb6791b1..d0f61cce 100644 --- a/de4dot.code/deobfuscators/Babel_NET/StringDecrypter.cs +++ b/de4dot.code/deobfuscators/Babel_NET/StringDecrypter.cs @@ -309,7 +309,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { return null; } - class ReflectionToCecilMethodCreator { + class ReflectionToDot10MethodCreator { MethodDef method; List instructions = new List(); InstructionEmulator emulator; @@ -331,7 +331,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { get { return instructions; } } - public ReflectionToCecilMethodCreator(MethodDef method) { + public ReflectionToDot10MethodCreator(MethodDef method) { this.method = method; this.emulator = new InstructionEmulator(method); } @@ -439,7 +439,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { emulator.pop(); // the this ptr addInstruction(new Instruction { OpCode = opcode, - Operand = createCecilOperand(opcode, operand), + Operand = createDot10Operand(opcode, operand), }); return true; } @@ -449,7 +449,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { } } - object createCecilOperand(OpCode opcode, Value op) { + object createDot10Operand(OpCode opcode, Value op) { if (op is Int32Value) return ((Int32Value)op).value; if (op is StringValue) @@ -470,7 +470,7 @@ namespace de4dot.code.deobfuscators.Babel_NET { } static List getOffsetCalcInstructions(MethodDef method) { - var creator = new ReflectionToCecilMethodCreator(method); + var creator = new ReflectionToDot10MethodCreator(method); creator.create(); var instrs = creator.Instructions; diff --git a/de4dot.code/deobfuscators/CodeFort/ProxyCallFixer.cs b/de4dot.code/deobfuscators/CodeFort/ProxyCallFixer.cs index 605c36f8..60c55c4d 100644 --- a/de4dot.code/deobfuscators/CodeFort/ProxyCallFixer.cs +++ b/de4dot.code/deobfuscators/CodeFort/ProxyCallFixer.cs @@ -25,7 +25,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.CodeFort { class ProxyCallFixer : ProxyCallFixer3 { - MethodDefinitionAndDeclaringTypeDict proxyTargetMethods = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict proxyTargetMethods = new MethodDefAndDeclaringTypeDict(); TypeDef proxyMethodsType; public TypeDef ProxyMethodsType { diff --git a/de4dot.code/deobfuscators/CodeWall/StringDecrypter.cs b/de4dot.code/deobfuscators/CodeWall/StringDecrypter.cs index 755c057a..a40af6b9 100644 --- a/de4dot.code/deobfuscators/CodeWall/StringDecrypter.cs +++ b/de4dot.code/deobfuscators/CodeWall/StringDecrypter.cs @@ -29,7 +29,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.CodeWall { class StringDecrypter { ModuleDefMD module; - MethodDefinitionAndDeclaringTypeDict stringEncrypterInfos = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict stringEncrypterInfos = new MethodDefAndDeclaringTypeDict(); Version version; public enum Version { diff --git a/de4dot.code/deobfuscators/DeepSea/ArrayBlockState.cs b/de4dot.code/deobfuscators/DeepSea/ArrayBlockState.cs index b0156011..fb665c2a 100644 --- a/de4dot.code/deobfuscators/DeepSea/ArrayBlockState.cs +++ b/de4dot.code/deobfuscators/DeepSea/ArrayBlockState.cs @@ -25,7 +25,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.DeepSea { class ArrayBlockState { ModuleDefMD module; - FieldDefinitionAndDeclaringTypeDict fieldToInfo = new FieldDefinitionAndDeclaringTypeDict(); + FieldDefAndDeclaringTypeDict fieldToInfo = new FieldDefAndDeclaringTypeDict(); public class FieldInfo { public readonly FieldDef field; diff --git a/de4dot.code/deobfuscators/DeepSea/FieldsRestorer.cs b/de4dot.code/deobfuscators/DeepSea/FieldsRestorer.cs index f83d43df..5da3f1f3 100644 --- a/de4dot.code/deobfuscators/DeepSea/FieldsRestorer.cs +++ b/de4dot.code/deobfuscators/DeepSea/FieldsRestorer.cs @@ -27,9 +27,9 @@ namespace de4dot.code.deobfuscators.DeepSea { // DS 4.x can move fields from a class to a struct. This class restores the fields. class FieldsRestorer { ModuleDefMD module; - TypeDefinitionDict> structToOwners = new TypeDefinitionDict>(); - FieldDefinitionAndDeclaringTypeDict structFieldsToFix = new FieldDefinitionAndDeclaringTypeDict(); - TypeDefinitionDict> typeToFieldsDict = new TypeDefinitionDict>(); + TypeDefDict> structToOwners = new TypeDefDict>(); + FieldDefAndDeclaringTypeDict structFieldsToFix = new FieldDefAndDeclaringTypeDict(); + TypeDefDict> typeToFieldsDict = new TypeDefDict>(); public List FieldStructs { get { @@ -76,7 +76,7 @@ namespace de4dot.code.deobfuscators.DeepSea { break; } - var fieldsDict = new FieldDefinitionAndDeclaringTypeDict(); + var fieldsDict = new FieldDefAndDeclaringTypeDict(); typeToFieldsDict.add(ownerType, fieldsDict); foreach (var structField in structType.Fields) { var newField = module.UpdateRowId(new FieldDefUser(structField.Name, structField.FieldSig.Clone(), structField.Attributes)); @@ -144,7 +144,7 @@ namespace de4dot.code.deobfuscators.DeepSea { } IEnumerable getPossibleFields(TypeDef type) { - var typeToFields = new TypeDefinitionDict>(); + var typeToFields = new TypeDefDict>(); foreach (var field in type.Fields) { if (field.Attributes != FieldAttributes.Private) continue; diff --git a/de4dot.code/deobfuscators/DeepSea/StringDecrypter.cs b/de4dot.code/deobfuscators/DeepSea/StringDecrypter.cs index 2c221274..f27d0990 100644 --- a/de4dot.code/deobfuscators/DeepSea/StringDecrypter.cs +++ b/de4dot.code/deobfuscators/DeepSea/StringDecrypter.cs @@ -27,7 +27,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.DeepSea { class StringDecrypter { ModuleDefMD module; - MethodDefinitionAndDeclaringTypeDict methodToInfo = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict methodToInfo = new MethodDefAndDeclaringTypeDict(); DecrypterVersion version = DecrypterVersion.Unknown; public enum DecrypterVersion { @@ -45,12 +45,12 @@ namespace de4dot.code.deobfuscators.DeepSea { } static short[] findKey(MethodDef initMethod, FieldDef keyField) { - var fields = new FieldDefinitionAndDeclaringTypeDict(); + var fields = new FieldDefAndDeclaringTypeDict(); fields.add(keyField, true); return findKey(initMethod, fields); } - static short[] findKey(MethodDef initMethod, FieldDefinitionAndDeclaringTypeDict fields) { + static short[] findKey(MethodDef initMethod, FieldDefAndDeclaringTypeDict fields) { var instrs = initMethod.Body.Instructions; for (int i = 0; i < instrs.Count - 2; i++) { var ldci4 = instrs[i]; @@ -153,7 +153,7 @@ namespace de4dot.code.deobfuscators.DeepSea { MethodDef cctor; int magic; int arg1, arg2; - FieldDefinitionAndDeclaringTypeDict fields; + FieldDefAndDeclaringTypeDict fields; ArrayInfo arrayInfo; ushort[] encryptedData; short[] key; @@ -206,8 +206,8 @@ namespace de4dot.code.deobfuscators.DeepSea { return count >= 2; } - static FieldDefinitionAndDeclaringTypeDict getFields(MethodDef method) { - var fields = new FieldDefinitionAndDeclaringTypeDict(); + static FieldDefAndDeclaringTypeDict getFields(MethodDef method) { + var fields = new FieldDefAndDeclaringTypeDict(); foreach (var instr in method.Body.Instructions) { if (instr.OpCode.Code != Code.Ldsfld && instr.OpCode.Code != Code.Stsfld) continue; diff --git a/de4dot.code/deobfuscators/DeobfuscatorBase.cs b/de4dot.code/deobfuscators/DeobfuscatorBase.cs index 66bbcca0..66b59fff 100644 --- a/de4dot.code/deobfuscators/DeobfuscatorBase.cs +++ b/de4dot.code/deobfuscators/DeobfuscatorBase.cs @@ -229,8 +229,8 @@ namespace de4dot.code.deobfuscators { public abstract IEnumerable getStringDecrypterMethods(); class MethodCallRemover { - Dictionary> methodNameInfos = new Dictionary>(); - MethodDefinitionAndDeclaringTypeDict> methodRefInfos = new MethodDefinitionAndDeclaringTypeDict>(); + Dictionary> methodNameInfos = new Dictionary>(); + MethodDefAndDeclaringTypeDict> methodRefInfos = new MethodDefAndDeclaringTypeDict>(); void checkMethod(IMethod methodToBeRemoved) { var sig = methodToBeRemoved.MethodSig; @@ -245,9 +245,9 @@ namespace de4dot.code.deobfuscators { return; checkMethod(methodToBeRemoved); - MethodDefinitionAndDeclaringTypeDict dict; + MethodDefAndDeclaringTypeDict dict; if (!methodNameInfos.TryGetValue(method, out dict)) - methodNameInfos[method] = dict = new MethodDefinitionAndDeclaringTypeDict(); + methodNameInfos[method] = dict = new MethodDefAndDeclaringTypeDict(); dict.add(methodToBeRemoved, true); } @@ -258,7 +258,7 @@ namespace de4dot.code.deobfuscators { var dict = methodRefInfos.find(method); if (dict == null) - methodRefInfos.add(method, dict = new MethodDefinitionAndDeclaringTypeDict()); + methodRefInfos.add(method, dict = new MethodDefAndDeclaringTypeDict()); dict.add(methodToBeRemoved, true); } @@ -270,7 +270,7 @@ namespace de4dot.code.deobfuscators { } void removeAll(IList allBlocks, Blocks blocks, string method) { - MethodDefinitionAndDeclaringTypeDict info; + MethodDefAndDeclaringTypeDict info; if (!methodNameInfos.TryGetValue(method, out info)) return; @@ -285,7 +285,7 @@ namespace de4dot.code.deobfuscators { removeCalls(allBlocks, blocks, info); } - void removeCalls(IList allBlocks, Blocks blocks, MethodDefinitionAndDeclaringTypeDict info) { + void removeCalls(IList allBlocks, Blocks blocks, MethodDefAndDeclaringTypeDict info) { var instrsToDelete = new List(); foreach (var block in allBlocks) { instrsToDelete.Clear(); diff --git a/de4dot.code/deobfuscators/Dotfuscator/StringDecrypter.cs b/de4dot.code/deobfuscators/Dotfuscator/StringDecrypter.cs index 92f5c1a9..ae83b746 100644 --- a/de4dot.code/deobfuscators/Dotfuscator/StringDecrypter.cs +++ b/de4dot.code/deobfuscators/Dotfuscator/StringDecrypter.cs @@ -25,7 +25,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.Dotfuscator { class StringDecrypter { ModuleDefMD module; - MethodDefinitionAndDeclaringTypeDict stringDecrypterMethods = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict stringDecrypterMethods = new MethodDefAndDeclaringTypeDict(); public class StringDecrypterInfo { public MethodDef method; diff --git a/de4dot.code/deobfuscators/ExceptionLoggerRemover.cs b/de4dot.code/deobfuscators/ExceptionLoggerRemover.cs index 5a8d13f9..7c8d5f21 100644 --- a/de4dot.code/deobfuscators/ExceptionLoggerRemover.cs +++ b/de4dot.code/deobfuscators/ExceptionLoggerRemover.cs @@ -24,7 +24,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators { class ExceptionLoggerRemover { - MethodDefinitionAndDeclaringTypeDict exceptionLoggerMethods = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict exceptionLoggerMethods = new MethodDefAndDeclaringTypeDict(); public int NumRemovedExceptionLoggers { get; set; } diff --git a/de4dot.code/deobfuscators/Goliath_NET/DecrypterBase.cs b/de4dot.code/deobfuscators/Goliath_NET/DecrypterBase.cs index 29111394..dcb1e4ce 100644 --- a/de4dot.code/deobfuscators/Goliath_NET/DecrypterBase.cs +++ b/de4dot.code/deobfuscators/Goliath_NET/DecrypterBase.cs @@ -32,7 +32,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET { TypeDef delegateType; TypeDef delegateInitType; protected BinaryReader decryptedReader; - MethodDefinitionAndDeclaringTypeDict decrypterMethods = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict decrypterMethods = new MethodDefAndDeclaringTypeDict(); protected class Info { public MethodDef method; @@ -66,7 +66,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET { public IEnumerable DecrypterTypes { get { - var types = new TypeDefinitionDict(); + var types = new TypeDefDict(); foreach (var info in decrypterMethods.getValues()) { if (info.referenced) types.add(info.method.DeclaringType, info.method.DeclaringType); diff --git a/de4dot.code/deobfuscators/Goliath_NET/LocalsRestorer.cs b/de4dot.code/deobfuscators/Goliath_NET/LocalsRestorer.cs index 7ec50b74..986266ea 100644 --- a/de4dot.code/deobfuscators/Goliath_NET/LocalsRestorer.cs +++ b/de4dot.code/deobfuscators/Goliath_NET/LocalsRestorer.cs @@ -25,7 +25,7 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators.Goliath_NET { class LocalsRestorer { ModuleDefMD module; - TypeDefinitionDict typeToInfo = new TypeDefinitionDict(); + TypeDefDict typeToInfo = new TypeDefDict(); class Info { public TypeDef type; diff --git a/de4dot.code/deobfuscators/ILProtector/MethodsDecrypter.cs b/de4dot.code/deobfuscators/ILProtector/MethodsDecrypter.cs index 055b200c..7fc944c9 100644 --- a/de4dot.code/deobfuscators/ILProtector/MethodsDecrypter.cs +++ b/de4dot.code/deobfuscators/ILProtector/MethodsDecrypter.cs @@ -243,7 +243,7 @@ namespace de4dot.code.deobfuscators.ILProtector { } static void restoreMethod(MethodDef method, MethodReader methodReader) { - // body.MaxStackSize = + // body.MaxStackSize = method.Body.InitLocals = methodReader.InitLocals; methodReader.RestoreMethod(method); } diff --git a/de4dot.code/deobfuscators/InitializedDataCreator.cs b/de4dot.code/deobfuscators/InitializedDataCreator.cs index 72598d1f..66227cfd 100644 --- a/de4dot.code/deobfuscators/InitializedDataCreator.cs +++ b/de4dot.code/deobfuscators/InitializedDataCreator.cs @@ -44,9 +44,9 @@ namespace de4dot.code.deobfuscators { MemberRef createInitializeArrayMethod() { if (initializeArrayMethod == null) { - var runtimeHelpersType = DotNetUtils.findOrCreateTypeReference(module, module.CorLibTypes.AssemblyRef, "System.Runtime.CompilerServices", "RuntimeHelpers", false); - var systemArrayType = DotNetUtils.findOrCreateTypeReference(module, module.CorLibTypes.AssemblyRef, "System", "Array", false); - var runtimeFieldHandleType = DotNetUtils.findOrCreateTypeReference(module, module.CorLibTypes.AssemblyRef, "System", "RuntimeFieldHandle", true); + var runtimeHelpersType = DotNetUtils.findOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System.Runtime.CompilerServices", "RuntimeHelpers", false); + var systemArrayType = DotNetUtils.findOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System", "Array", false); + var runtimeFieldHandleType = DotNetUtils.findOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System", "RuntimeFieldHandle", true); var methodSig = MethodSig.CreateStatic(module.CorLibTypes.Void, systemArrayType, runtimeFieldHandleType); initializeArrayMethod = module.UpdateRowId(new MemberRefUser(module, "InitializeArray", methodSig, runtimeHelpersType.TypeDefOrRef)); } @@ -96,7 +96,7 @@ namespace de4dot.code.deobfuscators { return arrayType; if (valueType == null) - valueType = DotNetUtils.findOrCreateTypeReference(module, module.CorLibTypes.AssemblyRef, "System", "ValueType", false); + valueType = DotNetUtils.findOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System", "ValueType", false); arrayType = new TypeDefUser("", string.Format("__StaticArrayInitTypeSize={0}", size), valueType.TypeDefOrRef); module.UpdateRowId(arrayType); arrayType.Attributes = TypeAttributes.NestedPrivate | TypeAttributes.ExplicitLayout | diff --git a/de4dot.code/deobfuscators/MemberReferenceBuilder.cs b/de4dot.code/deobfuscators/MemberReferenceBuilder.cs index e6b55c18..1822f41a 100644 --- a/de4dot.code/deobfuscators/MemberReferenceBuilder.cs +++ b/de4dot.code/deobfuscators/MemberReferenceBuilder.cs @@ -23,11 +23,11 @@ using dot10.DotNet; using de4dot.blocks; namespace de4dot.code.deobfuscators { - class MemberReferenceBuilder { + class MemberRefBuilder { ModuleDefMD module; Dictionary createdTypes = new Dictionary(TypeEqualityComparer.Instance); - public MemberReferenceBuilder(ModuleDefMD module) { + public MemberRefBuilder(ModuleDefMD module) { this.module = module; } @@ -108,7 +108,7 @@ namespace de4dot.code.deobfuscators { } public ClassSig type(string ns, string name, string asmSimpleName) { - return type(ns, name, findAssemblyReference(asmSimpleName)); + return type(ns, name, findAssemblyRef(asmSimpleName)); } public ClassSig type(string ns, string name) { @@ -120,7 +120,7 @@ namespace de4dot.code.deobfuscators { } public ValueTypeSig valueType(string ns, string name, string asmSimpleName) { - return valueType(ns, name, findAssemblyReference(asmSimpleName)); + return valueType(ns, name, findAssemblyRef(asmSimpleName)); } public ValueTypeSig valueType(string ns, string name) { @@ -173,7 +173,7 @@ namespace de4dot.code.deobfuscators { return module.UpdateRowId(new MemberRefUser(module, name, sig, declaringType)); } - AssemblyRef findAssemblyReference(string asmSimpleName) { + AssemblyRef findAssemblyRef(string asmSimpleName) { var asmRef = module.GetAssemblyRef(asmSimpleName); if (asmRef == null) throw new ApplicationException(string.Format("Could not find assembly {0} in assembly references", asmSimpleName)); diff --git a/de4dot.code/deobfuscators/MethodCallRestorerBase.cs b/de4dot.code/deobfuscators/MethodCallRestorerBase.cs index 011f80e4..c841f897 100644 --- a/de4dot.code/deobfuscators/MethodCallRestorerBase.cs +++ b/de4dot.code/deobfuscators/MethodCallRestorerBase.cs @@ -24,9 +24,9 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators { class MethodCallRestorerBase { - protected MemberReferenceBuilder builder; + protected MemberRefBuilder builder; protected ModuleDefMD module; - MethodDefinitionAndDeclaringTypeDict oldToNewMethod = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict oldToNewMethod = new MethodDefAndDeclaringTypeDict(); class NewMethodInfo { public OpCode opCode; @@ -40,7 +40,7 @@ namespace de4dot.code.deobfuscators { public MethodCallRestorerBase(ModuleDefMD module) { this.module = module; - this.builder = new MemberReferenceBuilder(module); + this.builder = new MemberRefBuilder(module); } public void createGetManifestResourceStream1(MethodDef oldMethod) { diff --git a/de4dot.code/deobfuscators/MethodCollection.cs b/de4dot.code/deobfuscators/MethodCollection.cs index 2b2e2b26..0ac65312 100644 --- a/de4dot.code/deobfuscators/MethodCollection.cs +++ b/de4dot.code/deobfuscators/MethodCollection.cs @@ -23,8 +23,8 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators { class MethodCollection { - TypeDefinitionDict types = new TypeDefinitionDict(); - MethodDefinitionAndDeclaringTypeDict methods = new MethodDefinitionAndDeclaringTypeDict(); + TypeDefDict types = new TypeDefDict(); + MethodDefAndDeclaringTypeDict methods = new MethodDefAndDeclaringTypeDict(); public bool exists(IMethod method) { if (method == null) diff --git a/de4dot.code/deobfuscators/MethodStack.cs b/de4dot.code/deobfuscators/MethodStack.cs index a5b67843..da128955 100644 --- a/de4dot.code/deobfuscators/MethodStack.cs +++ b/de4dot.code/deobfuscators/MethodStack.cs @@ -257,12 +257,12 @@ namespace de4dot.code.deobfuscators { local = pushInstr.Operand as Local; if (local == null) return null; - type = createByReferenceType(local.Type.RemovePinned()); + type = createByRefType(local.Type.RemovePinned()); break; case Code.Ldarga: case Code.Ldarga_S: - type = createByReferenceType(pushInstr.GetArgumentType(method.MethodSig, method.DeclaringType)); + type = createByRefType(pushInstr.GetArgumentType(method.MethodSig, method.DeclaringType)); break; case Code.Ldfld: @@ -278,12 +278,12 @@ namespace de4dot.code.deobfuscators { var field2 = pushInstr.Operand as IField; if (field2 == null || field2.FieldSig == null) return null; - type = createByReferenceType(field2.FieldSig.GetFieldType()); + type = createByRefType(field2.FieldSig.GetFieldType()); break; case Code.Ldelema: case Code.Unbox: - type = createByReferenceType(pushInstr.Operand as ITypeDefOrRef); + type = createByRefType(pushInstr.Operand as ITypeDefOrRef); break; default: @@ -293,13 +293,13 @@ namespace de4dot.code.deobfuscators { return type; } - static ByRefSig createByReferenceType(ITypeDefOrRef elementType) { + static ByRefSig createByRefType(ITypeDefOrRef elementType) { if (elementType == null) return null; return new ByRefSig(elementType.ToTypeSig()); } - static ByRefSig createByReferenceType(TypeSig elementType) { + static ByRefSig createByRefType(TypeSig elementType) { if (elementType == null) return null; return new ByRefSig(elementType); diff --git a/de4dot.code/deobfuscators/ProxyCallFixerBase.cs b/de4dot.code/deobfuscators/ProxyCallFixerBase.cs index e960b490..047d0b47 100644 --- a/de4dot.code/deobfuscators/ProxyCallFixerBase.cs +++ b/de4dot.code/deobfuscators/ProxyCallFixerBase.cs @@ -181,7 +181,7 @@ namespace de4dot.code.deobfuscators { // ...push args... // call Invoke abstract class ProxyCallFixer1 : ProxyCallFixerBase { - FieldDefinitionAndDeclaringTypeDict fieldToDelegateInfo = new FieldDefinitionAndDeclaringTypeDict(); + FieldDefAndDeclaringTypeDict fieldToDelegateInfo = new FieldDefAndDeclaringTypeDict(); protected ProxyCallFixer1(ModuleDefMD module) : base(module) { @@ -369,7 +369,7 @@ namespace de4dot.code.deobfuscators { // ...push args... // call static method abstract class ProxyCallFixer2 : ProxyCallFixerBase { - MethodDefinitionAndDeclaringTypeDict proxyMethodToDelegateInfo = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict proxyMethodToDelegateInfo = new MethodDefAndDeclaringTypeDict(); protected ProxyCallFixer2(ModuleDefMD module) : base(module) { diff --git a/de4dot.code/deobfuscators/Rummage/StringDecrypter.cs b/de4dot.code/deobfuscators/Rummage/StringDecrypter.cs index c390b03e..03f8c6ae 100644 --- a/de4dot.code/deobfuscators/Rummage/StringDecrypter.cs +++ b/de4dot.code/deobfuscators/Rummage/StringDecrypter.cs @@ -29,7 +29,7 @@ namespace de4dot.code.deobfuscators.Rummage { class StringDecrypter { ModuleDefMD module; MethodDef stringDecrypterMethod; - FieldDefinitionAndDeclaringTypeDict stringInfos = new FieldDefinitionAndDeclaringTypeDict(); + FieldDefAndDeclaringTypeDict stringInfos = new FieldDefAndDeclaringTypeDict(); int fileDispl; uint[] key; BinaryReader reader; diff --git a/de4dot.code/deobfuscators/Skater_NET/Deobfuscator.cs b/de4dot.code/deobfuscators/Skater_NET/Deobfuscator.cs index 16aa8d30..1f317545 100644 --- a/de4dot.code/deobfuscators/Skater_NET/Deobfuscator.cs +++ b/de4dot.code/deobfuscators/Skater_NET/Deobfuscator.cs @@ -85,11 +85,11 @@ namespace de4dot.code.deobfuscators.Skater_NET { protected override void scanForObfuscator() { stringDecrypter = new StringDecrypter(module); - if (hasAssemblyReference("Microsoft.VisualBasic")) + if (hasAssemblyRef("Microsoft.VisualBasic")) stringDecrypter.find(); } - bool hasAssemblyReference(string name) { + bool hasAssemblyRef(string name) { foreach (var asmRef in module.GetAssemblyRefs()) { if (asmRef.Name == name) return true; diff --git a/de4dot.code/deobfuscators/Skater_NET/StringDecrypter.cs b/de4dot.code/deobfuscators/Skater_NET/StringDecrypter.cs index 46dd681d..9f950ed3 100644 --- a/de4dot.code/deobfuscators/Skater_NET/StringDecrypter.cs +++ b/de4dot.code/deobfuscators/Skater_NET/StringDecrypter.cs @@ -32,7 +32,7 @@ namespace de4dot.code.deobfuscators.Skater_NET { ModuleDefMD module; TypeDef decrypterType; MethodDef decrypterCctor; - FieldDefinitionAndDeclaringTypeDict fieldToDecryptedString = new FieldDefinitionAndDeclaringTypeDict(); + FieldDefAndDeclaringTypeDict fieldToDecryptedString = new FieldDefAndDeclaringTypeDict(); bool canRemoveType; IDecrypter decrypter; diff --git a/de4dot.code/deobfuscators/SmartAssembly/Deobfuscator.cs b/de4dot.code/deobfuscators/SmartAssembly/Deobfuscator.cs index 8090fe83..154bee59 100644 --- a/de4dot.code/deobfuscators/SmartAssembly/Deobfuscator.cs +++ b/de4dot.code/deobfuscators/SmartAssembly/Deobfuscator.cs @@ -416,8 +416,8 @@ namespace de4dot.code.deobfuscators.SmartAssembly { if (decrypter.CanDecrypt) { var invokeMethod = info.GetStringDelegate == null ? null : info.GetStringDelegate.FindMethod("Invoke"); staticStringInliner.add(invokeMethod, (method, gim, args) => { - var fieldDefinition = DotNetUtils.getField(module, (IField)args[0]); - return decrypter.decrypt(fieldDefinition.MDToken.ToInt32(), (int)args[1]); + var fieldDef = DotNetUtils.getField(module, (IField)args[0]); + return decrypter.decrypt(fieldDef.MDToken.ToInt32(), (int)args[1]); }); staticStringInliner.add(info.StringDecrypterMethod, (method, gim, args) => { return decrypter.decrypt(0, (int)args[0]); diff --git a/de4dot.code/deobfuscators/SmartAssembly/StringDecrypterInfo.cs b/de4dot.code/deobfuscators/SmartAssembly/StringDecrypterInfo.cs index 6ce71988..3cfbf588 100644 --- a/de4dot.code/deobfuscators/SmartAssembly/StringDecrypterInfo.cs +++ b/de4dot.code/deobfuscators/SmartAssembly/StringDecrypterInfo.cs @@ -217,7 +217,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly { // Find the string decrypter string offset value or null if none found int? findOffsetValue(MethodDef method) { - var fieldDict = new FieldDefinitionAndDeclaringTypeDict(); + var fieldDict = new FieldDefAndDeclaringTypeDict(); foreach (var field in method.DeclaringType.Fields) fieldDict.add(field, field); @@ -253,7 +253,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly { return null; } - int? findOffsetValue(MethodDef method, FieldDef offsetField, FieldDefinitionAndDeclaringTypeDict fields) { + int? findOffsetValue(MethodDef method, FieldDef offsetField, FieldDefAndDeclaringTypeDict fields) { var instructions = method.Body.Instructions; for (int i = 0; i <= instructions.Count - 2; i++) { var ldstr = instructions[i]; diff --git a/de4dot.code/deobfuscators/SmartAssembly/StringEncoderClassFinder.cs b/de4dot.code/deobfuscators/SmartAssembly/StringEncoderClassFinder.cs index 6df6a376..4eb767ae 100644 --- a/de4dot.code/deobfuscators/SmartAssembly/StringEncoderClassFinder.cs +++ b/de4dot.code/deobfuscators/SmartAssembly/StringEncoderClassFinder.cs @@ -48,8 +48,8 @@ namespace de4dot.code.deobfuscators.SmartAssembly { this.simpleDeobfuscator = simpleDeobfuscator; } - TypeDef getType(ITypeDefOrRef typeReference) { - return DotNetUtils.getType(module, typeReference); + TypeDef getType(ITypeDefOrRef typeRef) { + return DotNetUtils.getType(module, typeRef); } public void find() { diff --git a/de4dot.code/deobfuscators/Spices_Net/ResourceNamesRestorer.cs b/de4dot.code/deobfuscators/Spices_Net/ResourceNamesRestorer.cs index bc53fdaa..03d847a1 100644 --- a/de4dot.code/deobfuscators/Spices_Net/ResourceNamesRestorer.cs +++ b/de4dot.code/deobfuscators/Spices_Net/ResourceNamesRestorer.cs @@ -27,8 +27,8 @@ namespace de4dot.code.deobfuscators.Spices_Net { ModuleDefMD module; TypeDef resourceManagerType; TypeDef componentResourceManagerType; - MethodDefinitionAndDeclaringTypeDict resourceManagerCtors = new MethodDefinitionAndDeclaringTypeDict(); - MethodDefinitionAndDeclaringTypeDict componentManagerCtors = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict resourceManagerCtors = new MethodDefAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict componentManagerCtors = new MethodDefAndDeclaringTypeDict(); public TypeDef ResourceManagerType { get { return resourceManagerType; } @@ -54,7 +54,7 @@ namespace de4dot.code.deobfuscators.Spices_Net { initializeCtors(componentResourceManagerType, componentManagerCtors); } - void initializeCtors(TypeDef manager, MethodDefinitionAndDeclaringTypeDict ctors) { + void initializeCtors(TypeDef manager, MethodDefAndDeclaringTypeDict ctors) { if (manager == null) return; diff --git a/de4dot.code/deobfuscators/Spices_Net/SpicesMethodCallInliner.cs b/de4dot.code/deobfuscators/Spices_Net/SpicesMethodCallInliner.cs index d9f45c4e..264fd07a 100644 --- a/de4dot.code/deobfuscators/Spices_Net/SpicesMethodCallInliner.cs +++ b/de4dot.code/deobfuscators/Spices_Net/SpicesMethodCallInliner.cs @@ -26,8 +26,8 @@ using de4dot.blocks.cflow; namespace de4dot.code.deobfuscators.Spices_Net { class SpicesMethodCallInliner : MethodCallInliner { ModuleDefMD module; - TypeDefinitionDict methodsTypes = new TypeDefinitionDict(); - MethodDefinitionAndDeclaringTypeDict classMethods = new MethodDefinitionAndDeclaringTypeDict(); + TypeDefDict methodsTypes = new TypeDefDict(); + MethodDefAndDeclaringTypeDict classMethods = new MethodDefAndDeclaringTypeDict(); public SpicesMethodCallInliner(ModuleDefMD module) : base(false) { @@ -58,7 +58,7 @@ namespace de4dot.code.deobfuscators.Spices_Net { } void restoreMethodBodies() { - var methodToOrigMethods = new MethodDefinitionAndDeclaringTypeDict>(); + var methodToOrigMethods = new MethodDefAndDeclaringTypeDict>(); foreach (var t in module.Types) { var types = new List(AllTypesHelper.Types(new List { t })); foreach (var type in types) { @@ -207,12 +207,12 @@ namespace de4dot.code.deobfuscators.Spices_Net { return list; } - public TypeDefinitionDict getInlinedTypes(IEnumerable unusedMethods) { - var unused = new MethodDefinitionAndDeclaringTypeDict(); + public TypeDefDict getInlinedTypes(IEnumerable unusedMethods) { + var unused = new MethodDefAndDeclaringTypeDict(); foreach (var method in unusedMethods) unused.add(method, true); - var types = new TypeDefinitionDict(); + var types = new TypeDefDict(); foreach (var type in methodsTypes.getKeys()) { if (checkAllMethodsUnused(unused, type)) types.add(type, true); @@ -220,7 +220,7 @@ namespace de4dot.code.deobfuscators.Spices_Net { return types; } - static bool checkAllMethodsUnused(MethodDefinitionAndDeclaringTypeDict unused, TypeDef type) { + static bool checkAllMethodsUnused(MethodDefAndDeclaringTypeDict unused, TypeDef type) { foreach (var method in type.Methods) { if (!unused.find(method)) return false; diff --git a/de4dot.code/deobfuscators/Spices_Net/StringDecrypter.cs b/de4dot.code/deobfuscators/Spices_Net/StringDecrypter.cs index 60256419..23eff5d5 100644 --- a/de4dot.code/deobfuscators/Spices_Net/StringDecrypter.cs +++ b/de4dot.code/deobfuscators/Spices_Net/StringDecrypter.cs @@ -30,7 +30,7 @@ namespace de4dot.code.deobfuscators.Spices_Net { TypeDef decrypterType; FieldDef encryptedDataField; StringDataFlags stringDataFlags; - MethodDefinitionAndDeclaringTypeDict methodToInfo = new MethodDefinitionAndDeclaringTypeDict(); + MethodDefAndDeclaringTypeDict methodToInfo = new MethodDefAndDeclaringTypeDict(); byte[] decryptedData; byte[] key; byte[] iv; diff --git a/de4dot.code/deobfuscators/ValueInlinerBase.cs b/de4dot.code/deobfuscators/ValueInlinerBase.cs index 824019df..2d9a18b6 100644 --- a/de4dot.code/deobfuscators/ValueInlinerBase.cs +++ b/de4dot.code/deobfuscators/ValueInlinerBase.cs @@ -25,15 +25,15 @@ using de4dot.blocks; namespace de4dot.code.deobfuscators { abstract class ValueInlinerBase : MethodReturnValueInliner { - MethodDefinitionAndDeclaringTypeDict> decrypterMethods = new MethodDefinitionAndDeclaringTypeDict>(); + MethodDefAndDeclaringTypeDict> decrypterMethods = new MethodDefAndDeclaringTypeDict>(); bool removeUnbox = false; class MyCallResult : CallResult { - public IMethod methodReference; + public IMethod methodRef; public MethodSpec gim; public MyCallResult(Block block, int callEndIndex, IMethod method, MethodSpec gim) : base(block, callEndIndex) { - this.methodReference = method; + this.methodRef = method; this.gim = gim; } } @@ -63,8 +63,8 @@ namespace de4dot.code.deobfuscators { protected override void inlineAllCalls() { foreach (var tmp in callResults) { var callResult = (MyCallResult)tmp; - var handler = decrypterMethods.find(callResult.methodReference); - callResult.returnValue = handler((MethodDef)callResult.methodReference, callResult.gim, callResult.args); + var handler = decrypterMethods.find(callResult.methodRef); + callResult.returnValue = handler((MethodDef)callResult.methodRef, callResult.gim, callResult.args); } } diff --git a/de4dot.code/deobfuscators/dotNET_Reactor/v3/DecrypterType.cs b/de4dot.code/deobfuscators/dotNET_Reactor/v3/DecrypterType.cs index b6cb7765..4743d3b9 100644 --- a/de4dot.code/deobfuscators/dotNET_Reactor/v3/DecrypterType.cs +++ b/de4dot.code/deobfuscators/dotNET_Reactor/v3/DecrypterType.cs @@ -31,7 +31,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v3 { MethodDef stringDecrypter1; MethodDef stringDecrypter2; List initMethods = new List(); - List moduleReferences = new List(); + List moduleRefs = new List(); Resource linkedResource; public bool Detected { @@ -78,7 +78,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v3 { this.stringDecrypter2 = lookup(oldOne.stringDecrypter2, "Could not find stringDecrypter2"); foreach (var method in oldOne.initMethods) initMethods.Add(lookup(method, "Could not find initMethod")); - updateModuleReferences(); + updateModuleRefs(); } T lookup(T def, string errorMessage) where T : class, ICodedToken { @@ -97,18 +97,18 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v3 { if (DotNetUtils.isMethod(method, "System.Void", "()")) initMethods.Add(method); } - updateModuleReferences(); + updateModuleRefs(); return; } } - void updateModuleReferences() { + void updateModuleRefs() { foreach (var method in decrypterType.Methods) { if (method.ImplMap != null) { switch (method.ImplMap.Name.String) { case "nr_nli": case "nr_startup": - moduleReferences.Add(method.ImplMap.Module); + moduleRefs.Add(method.ImplMap.Module); break; } } @@ -117,7 +117,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v3 { } void updateLinkedResource() { - foreach (var modref in moduleReferences) { + foreach (var modref in moduleRefs) { var resource = DotNetUtils.getResource(module, modref.Name.String) as LinkedResource; if (resource == null) continue; diff --git a/de4dot.code/renamer/MemberInfos.cs b/de4dot.code/renamer/MemberInfos.cs index 22918903..60a6765a 100644 --- a/de4dot.code/renamer/MemberInfos.cs +++ b/de4dot.code/renamer/MemberInfos.cs @@ -31,9 +31,9 @@ namespace de4dot.code.renamer { public MemberInfo(Ref memberRef) { this.memberRef = memberRef; - oldFullName = memberRef.memberReference.FullName; - oldName = memberRef.memberReference.Name.String; - newName = memberRef.memberReference.Name.String; + oldFullName = memberRef.memberRef.FullName; + oldName = memberRef.memberRef.Name.String; + newName = memberRef.memberRef.Name.String; } public void rename(string newTypeName) { @@ -91,8 +91,8 @@ namespace de4dot.code.renamer { public ParamInfo(MParamDef paramDef) { this.paramDef = paramDef; - this.oldName = paramDef.ParameterDefinition.Name; - this.newName = paramDef.ParameterDefinition.Name; + this.oldName = paramDef.ParameterDef.Name; + this.newName = paramDef.ParameterDef.Name; } public bool gotNewName() { diff --git a/de4dot.code/renamer/NameCreators.cs b/de4dot.code/renamer/NameCreators.cs index 71be2abf..fc684775 100644 --- a/de4dot.code/renamer/NameCreators.cs +++ b/de4dot.code/renamer/NameCreators.cs @@ -107,7 +107,7 @@ namespace de4dot.code.renamer { } interface ITypeNameCreator { - string create(TypeDef typeDefinition, string newBaseTypeName); + string create(TypeDef typeDef, string newBaseTypeName); } class NameInfos { @@ -172,26 +172,26 @@ namespace de4dot.code.renamer { return new NameCreator(prefix); } - public string create(TypeDef typeDefinition, string newBaseTypeName) { - var nameCreator = getNameCreator(typeDefinition, newBaseTypeName); - return existingNames.getName(typeDefinition.Name.String, nameCreator); + public string create(TypeDef typeDef, string newBaseTypeName) { + var nameCreator = getNameCreator(typeDef, newBaseTypeName); + return existingNames.getName(typeDef.Name.String, nameCreator); } - NameCreator getNameCreator(TypeDef typeDefinition, string newBaseTypeName) { + NameCreator getNameCreator(TypeDef typeDef, string newBaseTypeName) { var nameCreator = createUnknownTypeName; - if (typeDefinition.IsEnum) + if (typeDef.IsEnum) nameCreator = createEnumName; - else if (typeDefinition.IsValueType) + else if (typeDef.IsValueType) nameCreator = createStructName; - else if (typeDefinition.IsClass) { - if (typeDefinition.BaseType != null) { - var fn = typeDefinition.BaseType.FullName; + else if (typeDef.IsClass) { + if (typeDef.BaseType != null) { + var fn = typeDef.BaseType.FullName; if (fn == "System.Delegate") nameCreator = createDelegateName; else if (fn == "System.MulticastDelegate") nameCreator = createDelegateName; else { - nameCreator = nameInfos.find(newBaseTypeName ?? typeDefinition.BaseType.Name.String); + nameCreator = nameInfos.find(newBaseTypeName ?? typeDef.BaseType.Name.String); if (nameCreator == null) nameCreator = createClassName; } @@ -199,7 +199,7 @@ namespace de4dot.code.renamer { else nameCreator = createClassName; } - else if (typeDefinition.IsInterface) + else if (typeDef.IsInterface) nameCreator = createInterfaceName; return nameCreator; } diff --git a/de4dot.code/renamer/Renamer.cs b/de4dot.code/renamer/Renamer.cs index 3e2a5bbe..a26c1945 100644 --- a/de4dot.code/renamer/Renamer.cs +++ b/de4dot.code/renamer/Renamer.cs @@ -83,13 +83,13 @@ namespace de4dot.code.renamer { renameResourceKeys(); var groups = modules.initializeVirtualMembers(); memberInfos.initialize(modules); - renameTypeDefinitions(); - renameTypeReferences(); + renameTypeDefs(); + renameTypeRefs(); modules.onTypesRenamed(); restorePropertiesAndEvents(groups); - prepareRenameMemberDefinitions(groups); - renameMemberDefinitions(); - renameMemberReferences(); + prepareRenameMemberDefs(groups); + renameMemberDefs(); + renameMemberRefs(); removeUselessOverrides(groups); renameResources(); modules.cleanUp(); @@ -127,7 +127,7 @@ namespace de4dot.code.renamer { } } - void renameTypeDefinitions() { + void renameTypeDefs() { if (isVerbose) Logger.v("Renaming obfuscated type definitions"); @@ -141,7 +141,7 @@ namespace de4dot.code.renamer { state.addTypeName(memberInfos.type(type).oldName); prepareRenameTypes(modules.BaseTypes, state); fixClsTypeNames(); - renameTypeDefinitions(modules.NonNestedTypes); + renameTypeDefs(modules.NonNestedTypes); } void removeOneClassNamespaces(Module module) { @@ -174,37 +174,37 @@ namespace de4dot.code.renamer { } } - void renameTypeDefinitions(IEnumerable typeDefs) { + void renameTypeDefs(IEnumerable typeDefs) { Logger.Instance.indent(); foreach (var typeDef in typeDefs) { rename(typeDef); - renameTypeDefinitions(typeDef.NestedTypes); + renameTypeDefs(typeDef.NestedTypes); } Logger.Instance.deIndent(); } void rename(MTypeDef type) { - var typeDefinition = type.TypeDef; + var typeDef = type.TypeDef; var info = memberInfos.type(type); if (isVerbose) - Logger.v("Type: {0} ({1:X8})", Utils.removeNewlines(typeDefinition.FullName), typeDefinition.MDToken.ToUInt32()); + Logger.v("Type: {0} ({1:X8})", Utils.removeNewlines(typeDef.FullName), typeDef.MDToken.ToUInt32()); Logger.Instance.indent(); renameGenericParams(type.GenericParams); if (RenameTypes && info.gotNewName()) { - var old = typeDefinition.Name; - typeDefinition.Name = new UTF8String(info.newName); + var old = typeDef.Name; + typeDef.Name = new UTF8String(info.newName); if (isVerbose) - Logger.v("Name: {0} => {1}", Utils.removeNewlines(old), Utils.removeNewlines(typeDefinition.Name)); + Logger.v("Name: {0} => {1}", Utils.removeNewlines(old), Utils.removeNewlines(typeDef.Name)); } if (RenameNamespaces && info.newNamespace != null) { - var old = typeDefinition.Namespace; - typeDefinition.Namespace = new UTF8String(info.newNamespace); + var old = typeDef.Namespace; + typeDef.Namespace = new UTF8String(info.newNamespace); if (isVerbose) - Logger.v("Namespace: {0} => {1}", Utils.removeNewlines(old), Utils.removeNewlines(typeDefinition.Namespace)); + Logger.v("Namespace: {0} => {1}", Utils.removeNewlines(old), Utils.removeNewlines(typeDef.Namespace)); } Logger.Instance.deIndent(); @@ -223,7 +223,7 @@ namespace de4dot.code.renamer { } } - void renameMemberDefinitions() { + void renameMemberDefs() { if (isVerbose) Logger.v("Renaming member definitions #2"); @@ -321,13 +321,13 @@ namespace de4dot.code.renamer { var paramInfo = memberInfos.param(param); if (!paramInfo.gotNewName()) continue; - param.ParameterDefinition.CreateParamDef(); - param.ParameterDefinition.Name = paramInfo.newName; + param.ParameterDef.CreateParamDef(); + param.ParameterDef.Name = paramInfo.newName; if (isVerbose) { if (param.IsReturnParameter) Logger.v("RetParam: {0} => {1}", Utils.removeNewlines(paramInfo.oldName), Utils.removeNewlines(paramInfo.newName)); else - Logger.v("Param ({0}/{1}): {2} => {3}", param.ParameterDefinition.MethodSigIndex + 1, methodDef.MethodDef.MethodSig.GetParamCount(), Utils.removeNewlines(paramInfo.oldName), Utils.removeNewlines(paramInfo.newName)); + Logger.v("Param ({0}/{1}): {2} => {3}", param.ParameterDef.MethodSigIndex + 1, methodDef.MethodDef.MethodSig.GetParamCount(), Utils.removeNewlines(paramInfo.oldName), Utils.removeNewlines(paramInfo.newName)); } } } @@ -336,7 +336,7 @@ namespace de4dot.code.renamer { } } - void renameMemberReferences() { + void renameMemberRefs() { if (isVerbose) Logger.v("Renaming references to other definitions"); foreach (var module in modules.TheModules) { @@ -347,9 +347,9 @@ namespace de4dot.code.renamer { refToDef.reference.Name = refToDef.definition.Name; foreach (var refToDef in module.FieldRefsToRename) refToDef.reference.Name = refToDef.definition.Name; - foreach (var info in module.CustomAttributeFieldReferences) + foreach (var info in module.CustomAttributeFieldRefs) info.cattr.NamedArguments[info.index].Name = info.reference.Name; - foreach (var info in module.CustomAttributePropertyReferences) + foreach (var info in module.CustomAttributePropertyRefs) info.cattr.NamedArguments[info.index].Name = info.reference.Name; Logger.Instance.deIndent(); } @@ -405,7 +405,7 @@ namespace de4dot.code.renamer { } } - void renameTypeReferences() { + void renameTypeRefs() { if (isVerbose) Logger.v("Renaming references to type definitions"); var theModules = modules.TheModules; @@ -891,7 +891,7 @@ namespace de4dot.code.renamer { return eventDef; } - void prepareRenameMemberDefinitions(MethodNameGroups groups) { + void prepareRenameMemberDefs(MethodNameGroups groups) { if (isVerbose) Logger.v("Renaming member definitions #1"); @@ -987,7 +987,7 @@ namespace de4dot.code.renamer { foreach (var method in methods) { var nameChecker = !method.Owner.HasModule ? null : method.Owner.Module.ObfuscatedFile.NameChecker; for (int i = 0; i < argNames.Length; i++) { - var argName = method.ParamDefs[i].ParameterDefinition.Name; + var argName = method.ParamDefs[i].ParameterDef.Name; if (nameChecker == null || nameChecker.isValidMethodArgName(argName)) argNames[i] = argName; } @@ -1416,7 +1416,7 @@ namespace de4dot.code.renamer { foreach (var propMethod in group.Methods) { TypeSig propType; if (methodType == PropertyMethodType.Setter) - propType = propMethod.ParamDefs[propMethod.ParamDefs.Count - 1].ParameterDefinition.Type; + propType = propMethod.ParamDefs[propMethod.ParamDefs.Count - 1].ParameterDef.Type; else propType = propMethod.MethodDef.MethodSig.GetRetType(); if (type == null) @@ -1613,7 +1613,7 @@ namespace de4dot.code.renamer { memberInfos.method(methodDef).suggestedName = "Main"; if (methodDef.ParamDefs.Count == 1) { var paramDef = methodDef.ParamDefs[0]; - var type = paramDef.ParameterDefinition.Type; + var type = paramDef.ParameterDef.Type; if (type.FullName == "System.String[]") memberInfos.param(paramDef).newName = "args"; } diff --git a/de4dot.code/renamer/TypeInfo.cs b/de4dot.code/renamer/TypeInfo.cs index b11f5d5f..0261e1d6 100644 --- a/de4dot.code/renamer/TypeInfo.cs +++ b/de4dot.code/renamer/TypeInfo.cs @@ -315,7 +315,7 @@ namespace de4dot.code.renamer { if (info.gotNewName()) continue; if (!checker.isValidMethodArgName(info.oldName)) - info.newName = newVariableNameState.getNewParamName(info.oldName, paramDef.ParameterDefinition); + info.newName = newVariableNameState.getNewParamName(info.oldName, paramDef.ParameterDef); } } } @@ -325,7 +325,7 @@ namespace de4dot.code.renamer { if (!NameChecker.isValidMethodReturnArgName(info.oldName)) { if (newVariableNameState == null) newVariableNameState = variableNameState.cloneParamsOnly(); - info.newName = newVariableNameState.getNewParamName(info.oldName, methodDef.ReturnParamDef.ParameterDefinition); + info.newName = newVariableNameState.getNewParamName(info.oldName, methodDef.ReturnParamDef.ParameterDef); } } @@ -451,10 +451,10 @@ namespace de4dot.code.renamer { void initializeWindowsFormsFieldsAndProps() { var checker = NameChecker; - var ourFields = new FieldDefinitionAndDeclaringTypeDict(); + var ourFields = new FieldDefAndDeclaringTypeDict(); foreach (var fieldDef in type.AllFields) ourFields.add(fieldDef.FieldDef, fieldDef); - var ourMethods = new MethodDefinitionAndDeclaringTypeDict(); + var ourMethods = new MethodDefAndDeclaringTypeDict(); foreach (var methodDef in type.AllMethods) ourMethods.add(methodDef.MethodDef, methodDef); @@ -487,7 +487,7 @@ namespace de4dot.code.renamer { var calledMethodDef = ourMethods.find(calledMethod); if (calledMethodDef == null) continue; - fieldRef = getFieldReference(calledMethodDef.MethodDef); + fieldRef = getFieldRef(calledMethodDef.MethodDef); var propDef = calledMethodDef.Property; if (propDef == null) @@ -515,7 +515,7 @@ namespace de4dot.code.renamer { } } - static IField getFieldReference(MethodDef method) { + static IField getFieldRef(MethodDef method) { if (method == null || method.Body == null) return null; var instructions = method.Body.Instructions; @@ -544,10 +544,10 @@ namespace de4dot.code.renamer { } public void initializeEventHandlerNames() { - var ourFields = new FieldDefinitionAndDeclaringTypeDict(); + var ourFields = new FieldDefAndDeclaringTypeDict(); foreach (var fieldDef in type.AllFields) ourFields.add(fieldDef.FieldDef, fieldDef); - var ourMethods = new MethodDefinitionAndDeclaringTypeDict(); + var ourMethods = new MethodDefAndDeclaringTypeDict(); foreach (var methodDef in type.AllMethods) ourMethods.add(methodDef.MethodDef, methodDef); @@ -558,7 +558,7 @@ namespace de4dot.code.renamer { // VB initializes the handlers in the property setter, where it first removes the handler // from the previous control, and then adds the handler to the new control. - void initVbEventHandlers(FieldDefinitionAndDeclaringTypeDict ourFields, MethodDefinitionAndDeclaringTypeDict ourMethods) { + void initVbEventHandlers(FieldDefAndDeclaringTypeDict ourFields, MethodDefAndDeclaringTypeDict ourMethods) { var checker = NameChecker; foreach (var propDef in type.AllProperties) { @@ -675,7 +675,7 @@ namespace de4dot.code.renamer { return -1; } - void initFieldEventHandlers(FieldDefinitionAndDeclaringTypeDict ourFields, MethodDefinitionAndDeclaringTypeDict ourMethods) { + void initFieldEventHandlers(FieldDefAndDeclaringTypeDict ourFields, MethodDefAndDeclaringTypeDict ourMethods) { var checker = NameChecker; foreach (var methodDef in type.AllMethods) { @@ -754,7 +754,7 @@ namespace de4dot.code.renamer { } } - void initTypeEventHandlers(FieldDefinitionAndDeclaringTypeDict ourFields, MethodDefinitionAndDeclaringTypeDict ourMethods) { + void initTypeEventHandlers(FieldDefAndDeclaringTypeDict ourFields, MethodDefAndDeclaringTypeDict ourMethods) { var checker = NameChecker; foreach (var methodDef in type.AllMethods) { diff --git a/de4dot.code/renamer/VariableNameState.cs b/de4dot.code/renamer/VariableNameState.cs index c8bd88f1..09e788ac 100644 --- a/de4dot.code/renamer/VariableNameState.cs +++ b/de4dot.code/renamer/VariableNameState.cs @@ -86,13 +86,13 @@ namespace de4dot.code.renamer { existingEventNames.merge(other.existingEventNames); } - public string getNewPropertyName(PropertyDef propertyDefinition) { - var propType = propertyDefinition.PropertySig.GetRetType(); + public string getNewPropertyName(PropertyDef propertyDef) { + var propType = propertyDef.PropertySig.GetRetType(); string newName; if (isGeneric(propType)) - newName = existingPropertyNames.getName(propertyDefinition.Name, genericPropertyNameCreator); + newName = existingPropertyNames.getName(propertyDef.Name, genericPropertyNameCreator); else - newName = existingPropertyNames.getName(propertyDefinition.Name, () => propertyNameCreator.create(propType)); + newName = existingPropertyNames.getName(propertyDef.Name, () => propertyNameCreator.create(propType)); addPropertyName(newName); return newName; } @@ -106,7 +106,7 @@ namespace de4dot.code.renamer { return false; } - public string getNewEventName(EventDef eventDefinition) { + public string getNewEventName(EventDef eventDef) { string newName = eventNameCreator.create(); addEventName(newName); return newName; diff --git a/de4dot.code/renamer/asmmodules/EventDef.cs b/de4dot.code/renamer/asmmodules/EventDef.cs index 14ea1742..1f6e1b61 100644 --- a/de4dot.code/renamer/asmmodules/EventDef.cs +++ b/de4dot.code/renamer/asmmodules/EventDef.cs @@ -27,14 +27,14 @@ namespace de4dot.code.renamer.asmmodules { public MMethodDef RaiseMethod { get; set; } public EventDef EventDef { - get { return (EventDef)memberReference; } + get { return (EventDef)memberRef; } } - public MEventDef(EventDef eventDefinition, MTypeDef owner, int index) - : base(eventDefinition, owner, index) { + public MEventDef(EventDef eventDef, MTypeDef owner, int index) + : base(eventDef, owner, index) { } - public IEnumerable methodDefinitions() { + public IEnumerable methodDefs() { if (EventDef.AddMethod != null) yield return EventDef.AddMethod; if (EventDef.RemoveMethod != null) @@ -48,7 +48,7 @@ namespace de4dot.code.renamer.asmmodules { } public bool isVirtual() { - foreach (var method in methodDefinitions()) { + foreach (var method in methodDefs()) { if (method.IsVirtual) return true; } diff --git a/de4dot.code/renamer/asmmodules/FieldDef.cs b/de4dot.code/renamer/asmmodules/FieldDef.cs index 13049071..854f1e52 100644 --- a/de4dot.code/renamer/asmmodules/FieldDef.cs +++ b/de4dot.code/renamer/asmmodules/FieldDef.cs @@ -22,11 +22,11 @@ using dot10.DotNet; namespace de4dot.code.renamer.asmmodules { class MFieldDef : Ref { public FieldDef FieldDef { - get { return (FieldDef)memberReference; } + get { return (FieldDef)memberRef; } } - public MFieldDef(FieldDef fieldDefinition, MTypeDef owner, int index) - : base(fieldDefinition, owner, index) { + public MFieldDef(FieldDef fieldDef, MTypeDef owner, int index) + : base(fieldDef, owner, index) { } } } diff --git a/de4dot.code/renamer/asmmodules/GenericParamDef.cs b/de4dot.code/renamer/asmmodules/GenericParamDef.cs index c7a7c992..645d5cd9 100644 --- a/de4dot.code/renamer/asmmodules/GenericParamDef.cs +++ b/de4dot.code/renamer/asmmodules/GenericParamDef.cs @@ -23,7 +23,7 @@ using dot10.DotNet; namespace de4dot.code.renamer.asmmodules { class MGenericParamDef : Ref { public GenericParam GenericParam { - get { return (GenericParam)memberReference; } + get { return (GenericParam)memberRef; } } public MGenericParamDef(GenericParam genericParameter, int index) diff --git a/de4dot.code/renamer/asmmodules/IResolver.cs b/de4dot.code/renamer/asmmodules/IResolver.cs index e7f4bd09..03f3003b 100644 --- a/de4dot.code/renamer/asmmodules/IResolver.cs +++ b/de4dot.code/renamer/asmmodules/IResolver.cs @@ -21,8 +21,8 @@ using dot10.DotNet; namespace de4dot.code.renamer.asmmodules { interface IResolver { - MTypeDef resolveType(ITypeDefOrRef typeReference); - MMethodDef resolveMethod(IMethodDefOrRef methodReference); - MFieldDef resolveField(MemberRef fieldReference); + MTypeDef resolveType(ITypeDefOrRef typeRef); + MMethodDef resolveMethod(IMethodDefOrRef methodRef); + MFieldDef resolveField(MemberRef fieldRef); } } diff --git a/de4dot.code/renamer/asmmodules/MethodDef.cs b/de4dot.code/renamer/asmmodules/MethodDef.cs index b365f20b..17e5035e 100644 --- a/de4dot.code/renamer/asmmodules/MethodDef.cs +++ b/de4dot.code/renamer/asmmodules/MethodDef.cs @@ -60,20 +60,20 @@ namespace de4dot.code.renamer.asmmodules { } public MethodDef MethodDef { - get { return (MethodDef)memberReference; } + get { return (MethodDef)memberRef; } } - public MMethodDef(MethodDef methodDefinition, MTypeDef owner, int index) - : base(methodDefinition, owner, index) { + public MMethodDef(MethodDef methodDef, MTypeDef owner, int index) + : base(methodDef, owner, index) { genericParams = MGenericParamDef.createGenericParamDefList(MethodDef.GenericParameters); - visibleBaseIndex = methodDefinition.MethodSig != null && methodDefinition.MethodSig.HasThis ? 1 : 0; - for (int i = 0; i < methodDefinition.Parameters.Count; i++) { - var param = methodDefinition.Parameters[i]; + visibleBaseIndex = methodDef.MethodSig != null && methodDef.MethodSig.HasThis ? 1 : 0; + for (int i = 0; i < methodDef.Parameters.Count; i++) { + var param = methodDef.Parameters[i]; if (param.IsNormalMethodParameter) visibleParamCount++; paramDefs.Add(new MParamDef(param, i)); } - returnParamDef = new MParamDef(methodDefinition.Parameters.ReturnParameter, -1); + returnParamDef = new MParamDef(methodDef.Parameters.ReturnParameter, -1); } public bool isPublic() { diff --git a/de4dot.code/renamer/asmmodules/Module.cs b/de4dot.code/renamer/asmmodules/Module.cs index 69ad8a91..7d750db3 100644 --- a/de4dot.code/renamer/asmmodules/Module.cs +++ b/de4dot.code/renamer/asmmodules/Module.cs @@ -30,15 +30,15 @@ namespace de4dot.code.renamer.asmmodules { IList> typeRefsToRename = new List>(); IList> methodRefsToRename = new List>(); IList> fieldRefsToRename = new List>(); - List customAttributeFieldReferences = new List(); - List customAttributePropertyReferences = new List(); + List customAttributeFieldRefs = new List(); + List customAttributePropertyRefs = new List(); List allMethods; - public class CustomAttributeReference { + public class CustomAttributeRef { public CustomAttribute cattr; public int index; public IMemberRef reference; - public CustomAttributeReference(CustomAttribute cattr, int index, IMemberRef reference) { + public CustomAttributeRef(CustomAttribute cattr, int index, IMemberRef reference) { this.cattr = cattr; this.index = index; this.reference = reference; @@ -66,12 +66,12 @@ namespace de4dot.code.renamer.asmmodules { get { return fieldRefsToRename; } } - public IEnumerable CustomAttributeFieldReferences { - get { return customAttributeFieldReferences; } + public IEnumerable CustomAttributeFieldRefs { + get { return customAttributeFieldRefs; } } - public IEnumerable CustomAttributePropertyReferences { - get { return customAttributePropertyReferences; } + public IEnumerable CustomAttributePropertyRefs { + get { return customAttributePropertyRefs; } } public IObfuscatedFile ObfuscatedFile { @@ -98,7 +98,7 @@ namespace de4dot.code.renamer.asmmodules { return allMethods; } - public void findAllMemberReferences(ref int typeIndex) { + public void findAllMemberRefs(ref int typeIndex) { memberRefFinder = new MemberRefFinder(); memberRefFinder.findAll(ModuleDefMD); allMethods = new List(memberRefFinder.methodDefs.Keys); @@ -118,8 +118,8 @@ namespace de4dot.code.renamer.asmmodules { foreach (var typeDef in allTypesList) { if (typeDef.TypeDef.NestedTypes == null) continue; - foreach (var nestedTypeDefinition in typeDef.TypeDef.NestedTypes) { - int index = typeToIndex[nestedTypeDefinition]; + foreach (var nestedTypeDef2 in typeDef.TypeDef.NestedTypes) { + int index = typeToIndex[nestedTypeDef2]; var nestedTypeDef = allTypesCopy[index]; allTypesCopy[index] = null; if (nestedTypeDef == null) // Impossible @@ -169,7 +169,7 @@ namespace de4dot.code.renamer.asmmodules { continue; } - customAttributeFieldReferences.Add(new CustomAttributeReference(cattr, i, fieldDef.FieldDef)); + customAttributeFieldRefs.Add(new CustomAttributeRef(cattr, i, fieldDef.FieldDef)); } else { var propDef = findProperty(typeDef, namedArg.Name, namedArg.Type); @@ -181,7 +181,7 @@ namespace de4dot.code.renamer.asmmodules { continue; } - customAttributePropertyReferences.Add(new CustomAttributeReference(cattr, i, propDef.PropertyDef)); + customAttributePropertyRefs.Add(new CustomAttributeRef(cattr, i, propDef.PropertyDef)); } } } @@ -232,7 +232,7 @@ namespace de4dot.code.renamer.asmmodules { ModuleDefMD.EnableTypeDefFindCache = old; } - static ITypeDefOrRef getNonGenericTypeReference(ITypeDefOrRef typeRef) { + static ITypeDefOrRef getNonGenericTypeRef(ITypeDefOrRef typeRef) { var ts = typeRef as TypeSpec; if (ts == null) return typeRef; @@ -242,19 +242,19 @@ namespace de4dot.code.renamer.asmmodules { return gis.GenericType.TypeDefOrRef; } - public MTypeDef resolveType(ITypeDefOrRef typeReference) { - return this.types.find(getNonGenericTypeReference(typeReference)); + public MTypeDef resolveType(ITypeDefOrRef typeRef) { + return this.types.find(getNonGenericTypeRef(typeRef)); } public MMethodDef resolveMethod(IMethodDefOrRef methodRef) { - var typeDef = this.types.find(getNonGenericTypeReference(methodRef.DeclaringType)); + var typeDef = this.types.find(getNonGenericTypeRef(methodRef.DeclaringType)); if (typeDef == null) return null; return typeDef.findMethod(methodRef); } public MFieldDef resolveField(MemberRef fieldRef) { - var typeDef = this.types.find(getNonGenericTypeReference(fieldRef.DeclaringType)); + var typeDef = this.types.find(getNonGenericTypeRef(fieldRef.DeclaringType)); if (typeDef == null) return null; return typeDef.findField(fieldRef); diff --git a/de4dot.code/renamer/asmmodules/Modules.cs b/de4dot.code/renamer/asmmodules/Modules.cs index 1fecf5a6..1ce6472a 100644 --- a/de4dot.code/renamer/asmmodules/Modules.cs +++ b/de4dot.code/renamer/asmmodules/Modules.cs @@ -149,19 +149,19 @@ namespace de4dot.code.renamer.asmmodules { public void initialize() { initializeCalled = true; - findAllMemberReferences(); + findAllMemberRefs(); initAllTypes(); resolveAllRefs(); } - void findAllMemberReferences() { - Logger.v("Finding all MemberReferences"); + void findAllMemberRefs() { + Logger.v("Finding all MemberRefs"); int index = 0; foreach (var module in modules) { if (modules.Count > 1) - Logger.v("Finding all MemberReferences ({0})", module.Filename); + Logger.v("Finding all MemberRefs ({0})", module.Filename); Logger.Instance.indent(); - module.findAllMemberReferences(ref index); + module.findAllMemberRefs(ref index); Logger.Instance.deIndent(); } } @@ -319,22 +319,22 @@ namespace de4dot.code.renamer.asmmodules { if (typeToTypeDefDict.tryGetValue(type, out typeDef)) return typeDef; - var typeDefinition = deobfuscatorContext.resolveType(type); - if (typeDefinition == null) { + var typeDef2 = deobfuscatorContext.resolveType(type); + if (typeDef2 == null) { typeToTypeDefDict.tryGetSimilarValue(type, out typeDef); typeToTypeDefDict[type] = typeDef; return typeDef; } - if (typeToTypeDefDict.tryGetValue(typeDefinition, out typeDef)) { + if (typeToTypeDefDict.tryGetValue(typeDef2, out typeDef)) { typeToTypeDefDict[type] = typeDef; return typeDef; } typeToTypeDefDict[type] = null; // In case of a circular reference - typeToTypeDefDict[typeDefinition] = null; + typeToTypeDefDict[typeDef2] = null; - typeDef = new MTypeDef(typeDefinition, null, 0); + typeDef = new MTypeDef(typeDef2, null, 0); typeDef.addMembers(); foreach (var iface in typeDef.TypeDef.Interfaces) { var ifaceDef = resolveOther(iface.Interface); @@ -347,8 +347,8 @@ namespace de4dot.code.renamer.asmmodules { typeDef.addBaseType(baseDef, typeDef.TypeDef.BaseType); typeToTypeDefDict[type] = typeDef; - if (type != typeDefinition) - typeToTypeDefDict[typeDefinition] = typeDef; + if (type != typeDef2) + typeToTypeDefDict[typeDef2] = typeDef; return typeDef; } @@ -449,7 +449,7 @@ namespace de4dot.code.renamer.asmmodules { } if (isAutoCreatedType(typeRef)) return null; - Logger.e("Could not resolve TypeReference {0} ({1:X8}) (from {2} -> {3})", + Logger.e("Could not resolve TypeRef {0} ({1:X8}) (from {2} -> {3})", Utils.removeNewlines(typeRef), typeRef.MDToken.ToInt32(), typeRef.Module, @@ -470,7 +470,7 @@ namespace de4dot.code.renamer.asmmodules { } if (isAutoCreatedType(methodRef.DeclaringType)) return null; - Logger.e("Could not resolve MethodReference {0} ({1:X8}) (from {2} -> {3})", + Logger.e("Could not resolve MethodRef {0} ({1:X8}) (from {2} -> {3})", Utils.removeNewlines(methodRef), methodRef.MDToken.ToInt32(), methodRef.DeclaringType.Module, @@ -478,24 +478,24 @@ namespace de4dot.code.renamer.asmmodules { return null; } - public MFieldDef resolveField(MemberRef fieldReference) { - if (fieldReference.DeclaringType == null) + public MFieldDef resolveField(MemberRef fieldRef) { + if (fieldRef.DeclaringType == null) return null; - var modules = findModules(fieldReference.DeclaringType); + var modules = findModules(fieldRef.DeclaringType); if (modules == null) return null; foreach (var module in modules) { - var rv = module.resolveField(fieldReference); + var rv = module.resolveField(fieldRef); if (rv != null) return rv; } - if (isAutoCreatedType(fieldReference.DeclaringType)) + if (isAutoCreatedType(fieldRef.DeclaringType)) return null; - Logger.e("Could not resolve FieldReference {0} ({1:X8}) (from {2} -> {3})", - Utils.removeNewlines(fieldReference), - fieldReference.MDToken.ToInt32(), - fieldReference.DeclaringType.Module, - fieldReference.DeclaringType.Scope); + Logger.e("Could not resolve FieldRef {0} ({1:X8}) (from {2} -> {3})", + Utils.removeNewlines(fieldRef), + fieldRef.MDToken.ToInt32(), + fieldRef.DeclaringType.Module, + fieldRef.DeclaringType.Scope); return null; } } diff --git a/de4dot.code/renamer/asmmodules/ParamDef.cs b/de4dot.code/renamer/asmmodules/ParamDef.cs index 376bde46..6a3bcee9 100644 --- a/de4dot.code/renamer/asmmodules/ParamDef.cs +++ b/de4dot.code/renamer/asmmodules/ParamDef.cs @@ -21,17 +21,17 @@ using dot10.DotNet; namespace de4dot.code.renamer.asmmodules { class MParamDef { - public Parameter ParameterDefinition { get; set; } + public Parameter ParameterDef { get; set; } public int Index { get; private set; } public bool IsReturnParameter { - get { return ParameterDefinition.IsReturnTypeParameter; } + get { return ParameterDef.IsReturnTypeParameter; } } public bool IsHiddenThisParameter { - get { return ParameterDefinition.IsHiddenThisParameter; } + get { return ParameterDef.IsHiddenThisParameter; } } - public MParamDef(Parameter parameterDefinition, int index) { - this.ParameterDefinition = parameterDefinition; + public MParamDef(Parameter parameterDef, int index) { + this.ParameterDef = parameterDef; Index = index; } } diff --git a/de4dot.code/renamer/asmmodules/PropertyDef.cs b/de4dot.code/renamer/asmmodules/PropertyDef.cs index 52d303f7..eb9a64f4 100644 --- a/de4dot.code/renamer/asmmodules/PropertyDef.cs +++ b/de4dot.code/renamer/asmmodules/PropertyDef.cs @@ -26,14 +26,14 @@ namespace de4dot.code.renamer.asmmodules { public MMethodDef SetMethod { get; set; } public PropertyDef PropertyDef { - get { return (PropertyDef)memberReference; } + get { return (PropertyDef)memberRef; } } - public MPropertyDef(PropertyDef propertyDefinition, MTypeDef owner, int index) - : base(propertyDefinition, owner, index) { + public MPropertyDef(PropertyDef propertyDef, MTypeDef owner, int index) + : base(propertyDef, owner, index) { } - public IEnumerable methodDefinitions() { + public IEnumerable methodDefs() { if (PropertyDef.GetMethod != null) yield return PropertyDef.GetMethod; if (PropertyDef.SetMethod != null) @@ -45,7 +45,7 @@ namespace de4dot.code.renamer.asmmodules { } public bool isVirtual() { - foreach (var method in methodDefinitions()) { + foreach (var method in methodDefs()) { if (method.IsVirtual) return true; } diff --git a/de4dot.code/renamer/asmmodules/Ref.cs b/de4dot.code/renamer/asmmodules/Ref.cs index ba7528bc..469a299f 100644 --- a/de4dot.code/renamer/asmmodules/Ref.cs +++ b/de4dot.code/renamer/asmmodules/Ref.cs @@ -21,18 +21,18 @@ using dot10.DotNet; namespace de4dot.code.renamer.asmmodules { abstract class Ref { - public readonly IMemberRef memberReference; + public readonly IMemberRef memberRef; public int Index { get; set; } public MTypeDef Owner { get; set; } - protected Ref(IMemberRef memberReference, MTypeDef owner, int index) { - this.memberReference = memberReference; + protected Ref(IMemberRef memberRef, MTypeDef owner, int index) { + this.memberRef = memberRef; Owner = owner; Index = index; } public override string ToString() { - return memberReference != null ? memberReference.ToString() : null; + return memberRef != null ? memberRef.ToString() : null; } } } diff --git a/de4dot.code/renamer/asmmodules/RefDict.cs b/de4dot.code/renamer/asmmodules/RefDict.cs index 3d378713..2a7054cf 100644 --- a/de4dot.code/renamer/asmmodules/RefDict.cs +++ b/de4dot.code/renamer/asmmodules/RefDict.cs @@ -29,7 +29,7 @@ namespace de4dot.code.renamer.asmmodules { } } - class TypeDefDict : TypeDefinitionDict { + class TypeDefDict : TypeDefDict { public IEnumerable getSorted() { return DictHelper.getSorted(getValues()); } @@ -39,7 +39,7 @@ namespace de4dot.code.renamer.asmmodules { } } - class FieldDefDict : FieldDefinitionDict { + class FieldDefDict : FieldDefDict { public IEnumerable getSorted() { return DictHelper.getSorted(getValues()); } @@ -49,7 +49,7 @@ namespace de4dot.code.renamer.asmmodules { } } - class MethodDefDict : MethodDefinitionDict { + class MethodDefDict : MethodDefDict { public IEnumerable getSorted() { return DictHelper.getSorted(getValues()); } @@ -59,7 +59,7 @@ namespace de4dot.code.renamer.asmmodules { } } - class PropertyDefDict : PropertyDefinitionDict { + class PropertyDefDict : PropertyDefDict { public IEnumerable getSorted() { return DictHelper.getSorted(getValues()); } @@ -69,7 +69,7 @@ namespace de4dot.code.renamer.asmmodules { } } - class EventDefDict : EventDefinitionDict { + class EventDefDict : EventDefDict { public IEnumerable getSorted() { return DictHelper.getSorted(getValues()); } diff --git a/de4dot.code/renamer/asmmodules/TypeDef.cs b/de4dot.code/renamer/asmmodules/TypeDef.cs index 61ef2e26..79e9fbe3 100644 --- a/de4dot.code/renamer/asmmodules/TypeDef.cs +++ b/de4dot.code/renamer/asmmodules/TypeDef.cs @@ -24,21 +24,21 @@ using de4dot.blocks; namespace de4dot.code.renamer.asmmodules { class TypeInfo { - public ITypeDefOrRef typeReference; + public ITypeDefOrRef typeRef; public MTypeDef typeDef; - public TypeInfo(ITypeDefOrRef typeReference, MTypeDef typeDef) { - this.typeReference = typeReference; + public TypeInfo(ITypeDefOrRef typeRef, MTypeDef typeDef) { + this.typeRef = typeRef; this.typeDef = typeDef; } public TypeInfo(TypeInfo other, GenericInstSig git) { - this.typeReference = GenericArgsSubstitutor.create(other.typeReference, git); + this.typeRef = GenericArgsSubstitutor.create(other.typeRef, git); this.typeDef = other.typeDef; } public override int GetHashCode() { return typeDef.GetHashCode() + - new SigComparer().GetHashCode(typeReference); + new SigComparer().GetHashCode(typeRef); } public override bool Equals(object obj) { @@ -46,11 +46,11 @@ namespace de4dot.code.renamer.asmmodules { if (other == null) return false; return typeDef == other.typeDef && - new SigComparer().Equals(typeReference, other.typeReference); + new SigComparer().Equals(typeRef, other.typeRef); } public override string ToString() { - return typeReference.ToString(); + return typeRef.ToString(); } } @@ -75,15 +75,15 @@ namespace de4dot.code.renamer.asmmodules { class MethodInst { public MMethodDef origMethodDef; - public IMethodDefOrRef methodReference; + public IMethodDefOrRef methodRef; - public MethodInst(MMethodDef origMethodDef, IMethodDefOrRef methodReference) { + public MethodInst(MMethodDef origMethodDef, IMethodDefOrRef methodRef) { this.origMethodDef = origMethodDef; - this.methodReference = methodReference; + this.methodRef = methodRef; } public override string ToString() { - return methodReference.ToString(); + return methodRef.ToString(); } } @@ -93,7 +93,7 @@ namespace de4dot.code.renamer.asmmodules { public void initializeFrom(MethodInstances other, GenericInstSig git) { foreach (var list in other.methodInstances.Values) { foreach (var methodInst in list) { - var newMethod = GenericArgsSubstitutor.create(methodInst.methodReference, git); + var newMethod = GenericArgsSubstitutor.create(methodInst.methodRef, git); add(new MethodInst(methodInst.origMethodDef, newMethod)); } } @@ -101,15 +101,15 @@ namespace de4dot.code.renamer.asmmodules { public void add(MethodInst methodInst) { List list; - var key = methodInst.methodReference; + var key = methodInst.methodRef; if (methodInst.origMethodDef.isNewSlot() || !methodInstances.TryGetValue(key, out list)) methodInstances[key] = list = new List(); list.Add(methodInst); } - public List lookup(IMethodDefOrRef methodReference) { + public List lookup(IMethodDefOrRef methodRef) { List list; - methodInstances.TryGetValue(methodReference, out list); + methodInstances.TryGetValue(methodRef, out list); return list; } @@ -186,8 +186,8 @@ namespace de4dot.code.renamer.asmmodules { foreach (var pair in other.interfaceMethods) { var oldTypeInfo = pair.Value.IFace; var newTypeInfo = new TypeInfo(oldTypeInfo, git); - var oldKey = oldTypeInfo.typeReference; - var newKey = newTypeInfo.typeReference; + var oldKey = oldTypeInfo.typeRef; + var newKey = newTypeInfo.typeRef; InterfaceMethodInfo newMethodsInfo = new InterfaceMethodInfo(newTypeInfo, other.interfaceMethods[oldKey]); if (interfaceMethods.ContainsKey(newKey)) @@ -197,14 +197,14 @@ namespace de4dot.code.renamer.asmmodules { } public void addInterface(TypeInfo iface) { - var key = iface.typeReference; + var key = iface.typeRef; if (!interfaceMethods.ContainsKey(key)) interfaceMethods[key] = new InterfaceMethodInfo(iface); } // Returns the previous classMethod, or null if none public MMethodDef addMethod(TypeInfo iface, MMethodDef ifaceMethod, MMethodDef classMethod) { - return addMethod(iface.typeReference, ifaceMethod, classMethod); + return addMethod(iface.typeRef, ifaceMethod, classMethod); } // Returns the previous classMethod, or null if none @@ -217,7 +217,7 @@ namespace de4dot.code.renamer.asmmodules { public void addMethodIfEmpty(TypeInfo iface, MMethodDef ifaceMethod, MMethodDef classMethod) { InterfaceMethodInfo info; - if (!interfaceMethods.TryGetValue(iface.typeReference, out info)) + if (!interfaceMethods.TryGetValue(iface.typeRef, out info)) throw new ApplicationException("Could not find interface"); info.addMethodIfEmpty(ifaceMethod, classMethod); } @@ -260,7 +260,7 @@ namespace de4dot.code.renamer.asmmodules { public MTypeDef NestingType { get; set; } public TypeDef TypeDef { - get { return (TypeDef)memberReference; } + get { return (TypeDef)memberRef; } } public IEnumerable AllEvents { @@ -295,8 +295,8 @@ namespace de4dot.code.renamer.asmmodules { get { return properties.getSorted(); } } - public MTypeDef(TypeDef typeDefinition, Module module, int index) - : base(typeDefinition, null, index) { + public MTypeDef(TypeDef typeDef, Module module, int index) + : base(typeDef, null, index) { this.module = module; genericParams = MGenericParamDef.createGenericParamDefList(TypeDef.GenericParameters); } @@ -406,7 +406,7 @@ namespace de4dot.code.renamer.asmmodules { add(new MPropertyDef(type.Properties[i], this, i)); foreach (var propDef in properties.getValues()) { - foreach (var method in propDef.methodDefinitions()) { + foreach (var method in propDef.methodDefs()) { var methodDef = findMethod(method); if (methodDef == null) throw new ApplicationException("Could not find property method"); @@ -419,7 +419,7 @@ namespace de4dot.code.renamer.asmmodules { } foreach (var eventDef in events.getValues()) { - foreach (var method in eventDef.methodDefinitions()) { + foreach (var method in eventDef.methodDefs()) { var methodDef = findMethod(method); if (methodDef == null) throw new ApplicationException("Could not find event method"); @@ -494,7 +494,7 @@ namespace de4dot.code.renamer.asmmodules { } void initializeInterfaces(TypeInfo typeInfo) { - var git = typeInfo.typeReference.ToGenericInstSig(); + var git = typeInfo.typeRef.ToGenericInstSig(); interfaceMethodInfos.initializeFrom(typeInfo.typeDef.interfaceMethodInfos, git); foreach (var info in typeInfo.typeDef.allImplementedInterfaces.Keys) { var newTypeInfo = new TypeInfo(info, git); @@ -540,9 +540,9 @@ namespace de4dot.code.renamer.asmmodules { var ifaceMethod = methodInst.origMethodDef; if (!ifaceMethod.isVirtual()) continue; - var ifaceMethodReference = GenericArgsSubstitutor.create(methodInst.methodReference, ifaceInfo.typeReference.ToGenericInstSig()); + var ifaceMethodRef = GenericArgsSubstitutor.create(methodInst.methodRef, ifaceInfo.typeRef.ToGenericInstSig()); MMethodDef classMethod; - if (!methodsDict.TryGetValue(ifaceMethodReference, out classMethod)) + if (!methodsDict.TryGetValue(ifaceMethodRef, out classMethod)) continue; interfaceMethodInfos.addMethod(ifaceInfo, ifaceMethod, classMethod); } @@ -563,7 +563,7 @@ namespace de4dot.code.renamer.asmmodules { // We should allow newslot methods, despite what the official doc says. if (!classMethod.origMethodDef.isPublic()) continue; - methodsDict[classMethod.methodReference] = classMethod.origMethodDef; + methodsDict[classMethod.methodRef] = classMethod.origMethodDef; break; } } @@ -574,7 +574,7 @@ namespace de4dot.code.renamer.asmmodules { var ifaceMethod = methodsList[0].origMethodDef; if (!ifaceMethod.isVirtual()) continue; - var ifaceMethodRef = GenericArgsSubstitutor.create(ifaceMethod.MethodDef, ifaceInfo.typeReference.ToGenericInstSig()); + var ifaceMethodRef = GenericArgsSubstitutor.create(ifaceMethod.MethodDef, ifaceInfo.typeRef.ToGenericInstSig()); MMethodDef classMethod; if (!methodsDict.TryGetValue(ifaceMethodRef, out classMethod)) continue; @@ -588,12 +588,12 @@ namespace de4dot.code.renamer.asmmodules { methodsDict.Clear(); var ifaceMethodsDict = new Dictionary(MethodEqualityComparer.CompareDeclaringTypes); foreach (var ifaceInfo in allImplementedInterfaces.Keys) { - var git = ifaceInfo.typeReference.ToGenericInstSig(); + var git = ifaceInfo.typeRef.ToGenericInstSig(); foreach (var ifaceMethod in ifaceInfo.typeDef.methods.getValues()) { - IMethodDefOrRef ifaceMethodReference = ifaceMethod.MethodDef; + IMethodDefOrRef ifaceMethodRef = ifaceMethod.MethodDef; if (git != null) - ifaceMethodReference = simpleClone(ifaceMethod.MethodDef, ifaceInfo.typeReference); - ifaceMethodsDict[ifaceMethodReference] = ifaceMethod; + ifaceMethodRef = simpleClone(ifaceMethod.MethodDef, ifaceInfo.typeRef); + ifaceMethodsDict[ifaceMethodRef] = ifaceMethod; } } foreach (var classMethod in methods.getValues()) { @@ -699,7 +699,7 @@ namespace de4dot.code.renamer.asmmodules { void instantiateVirtualMembers(MethodNameGroups groups) { if (!TypeDef.IsInterface) { if (baseType != null) - virtualMethodInstances.initializeFrom(baseType.typeDef.virtualMethodInstances, baseType.typeReference.ToGenericInstSig()); + virtualMethodInstances.initializeFrom(baseType.typeDef.virtualMethodInstances, baseType.typeRef.ToGenericInstSig()); // Figure out which methods we override in the base class foreach (var methodDef in methods.getValues()) {