Remove all cecil code/comment refs

This commit is contained in:
de4dot 2012-11-22 09:14:51 +01:00
parent fd129aa3c0
commit 9263a3df3d
68 changed files with 482 additions and 484 deletions

View File

@ -34,7 +34,7 @@ using ROpCodes = System.Reflection.Emit.OpCodes;
namespace AssemblyData.methodsrewriter { namespace AssemblyData.methodsrewriter {
class CodeGenerator { class CodeGenerator {
static Dictionary<OpCode, ROpCode> cecilToReflection = new Dictionary<OpCode, ROpCode>(); static Dictionary<OpCode, ROpCode> dot10ToReflection = new Dictionary<OpCode, ROpCode>();
static CodeGenerator() { static CodeGenerator() {
var refDict = new Dictionary<short, ROpCode>(0x100); var refDict = new Dictionary<short, ROpCode>(0x100);
foreach (var f in typeof(ROpCodes).GetFields(BindingFlags.Static | BindingFlags.Public)) { foreach (var f in typeof(ROpCodes).GetFields(BindingFlags.Static | BindingFlags.Public)) {
@ -51,7 +51,7 @@ namespace AssemblyData.methodsrewriter {
ROpCode ropcode; ROpCode ropcode;
if (!refDict.TryGetValue(opcode.Value, out ropcode)) if (!refDict.TryGetValue(opcode.Value, out ropcode))
continue; continue;
cecilToReflection[opcode] = ropcode; dot10ToReflection[opcode] = ropcode;
} }
} }
@ -332,7 +332,7 @@ namespace AssemblyData.methodsrewriter {
ROpCode convertOpCode(OpCode opcode) { ROpCode convertOpCode(OpCode opcode) {
ROpCode ropcode; ROpCode ropcode;
if (cecilToReflection.TryGetValue(opcode, out ropcode)) if (dot10ToReflection.TryGetValue(opcode, out ropcode))
return ropcode; return ropcode;
return ROpCodes.Nop; return ROpCodes.Nop;
} }

View File

@ -24,9 +24,9 @@ namespace AssemblyData.methodsrewriter {
class MMethod { class MMethod {
public MethodBase methodBase; public MethodBase methodBase;
public MethodDef methodDef; public MethodDef methodDef;
public MMethod(MethodBase methodBase, MethodDef methodDefinition) { public MMethod(MethodBase methodBase, MethodDef methodDef) {
this.methodBase = methodBase; this.methodBase = methodBase;
this.methodDef = methodDefinition; this.methodDef = methodDef;
} }
public bool hasInstructions() { public bool hasInstructions() {

View File

@ -27,15 +27,15 @@ namespace AssemblyData.methodsrewriter {
class MModule { class MModule {
public Module module; public Module module;
public ModuleDefMD moduleDef; public ModuleDefMD moduleDef;
TypeDefinitionDict<MType> typeReferenceToType = new TypeDefinitionDict<MType>(); TypeDefDict<MType> typeRefToType = new TypeDefDict<MType>();
Dictionary<int, MType> tokenToType = new Dictionary<int, MType>(); Dictionary<int, MType> tokenToType = new Dictionary<int, MType>();
Dictionary<int, MMethod> tokenToGlobalMethod; Dictionary<int, MMethod> tokenToGlobalMethod;
Dictionary<int, MField> tokenToGlobalField; Dictionary<int, MField> tokenToGlobalField;
TypeDef moduleType; TypeDef moduleType;
public MModule(Module module, ModuleDefMD moduleDefinition) { public MModule(Module module, ModuleDefMD moduleDef) {
this.module = module; this.module = module;
this.moduleDef = moduleDefinition; this.moduleDef = moduleDef;
initTokenToType(); initTokenToType();
} }
@ -49,17 +49,17 @@ namespace AssemblyData.methodsrewriter {
} }
catch { catch {
tokenToType[token] = null; tokenToType[token] = null;
typeReferenceToType.add(typeDef, null); typeRefToType.add(typeDef, null);
continue; continue;
} }
var mtype = new MType(type, typeDef); var mtype = new MType(type, typeDef);
tokenToType[token] = mtype; tokenToType[token] = mtype;
typeReferenceToType.add(typeDef, mtype); typeRefToType.add(typeDef, mtype);
} }
} }
public MType getType(IType typeRef) { public MType getType(IType typeRef) {
return typeReferenceToType.find(typeRef); return typeRefToType.find(typeRef);
} }
public MMethod getMethod(IMethod methodRef) { public MMethod getMethod(IMethod methodRef) {

View File

@ -28,23 +28,23 @@ namespace AssemblyData.methodsrewriter {
public Type type; public Type type;
public TypeDef typeDef; public TypeDef typeDef;
Dictionary<int, MMethod> tokenToMethod; Dictionary<int, MMethod> tokenToMethod;
MethodDefinitionDict<MMethod> methodReferenceToMethod; MethodDefDict<MMethod> methodRefToMethod;
Dictionary<int, MField> tokenToField; Dictionary<int, MField> tokenToField;
FieldDefinitionDict<MField> fieldReferenceToField; FieldDefDict<MField> fieldRefToField;
public MType(Type type, TypeDef typeDefinition) { public MType(Type type, TypeDef typeDef) {
this.type = type; this.type = type;
this.typeDef = typeDefinition; this.typeDef = typeDef;
} }
public MMethod getMethod(IMethod methodRef) { public MMethod getMethod(IMethod methodRef) {
initMethods(); initMethods();
return methodReferenceToMethod.find(methodRef); return methodRefToMethod.find(methodRef);
} }
public MField getField(IField fieldRef) { public MField getField(IField fieldRef) {
initFields(); initFields();
return fieldReferenceToField.find(fieldRef); return fieldRefToField.find(fieldRef);
} }
public MMethod getMethod(int token) { public MMethod getMethod(int token) {
@ -61,7 +61,7 @@ namespace AssemblyData.methodsrewriter {
if (tokenToMethod != null) if (tokenToMethod != null)
return; return;
tokenToMethod = new Dictionary<int, MMethod>(typeDef.Methods.Count); tokenToMethod = new Dictionary<int, MMethod>(typeDef.Methods.Count);
methodReferenceToMethod = new MethodDefinitionDict<MMethod>(); methodRefToMethod = new MethodDefDict<MMethod>();
var tmpTokenToMethod = new Dictionary<int, MethodBase>(); var tmpTokenToMethod = new Dictionary<int, MethodBase>();
var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; 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 token = (int)m.MDToken.Raw;
var method = new MMethod(tmpTokenToMethod[token], m); var method = new MMethod(tmpTokenToMethod[token], m);
tokenToMethod[token] = method; tokenToMethod[token] = method;
methodReferenceToMethod.add(method.methodDef, method); methodRefToMethod.add(method.methodDef, method);
} }
} }
@ -79,7 +79,7 @@ namespace AssemblyData.methodsrewriter {
if (tokenToField != null) if (tokenToField != null)
return; return;
tokenToField = new Dictionary<int, MField>(typeDef.Fields.Count); tokenToField = new Dictionary<int, MField>(typeDef.Fields.Count);
fieldReferenceToField = new FieldDefinitionDict<MField>(); fieldRefToField = new FieldDefDict<MField>();
var tmpTokenToField = new Dictionary<int, FieldInfo>(); var tmpTokenToField = new Dictionary<int, FieldInfo>();
var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; 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 token = (int)f.MDToken.Raw;
var field = new MField(tmpTokenToField[token], f); var field = new MField(tmpTokenToField[token], f);
tokenToField[token] = field; tokenToField[token] = field;
fieldReferenceToField.add(field.fieldDef, field); fieldRefToField.add(field.fieldDef, field);
} }
} }

View File

@ -73,21 +73,21 @@ namespace AssemblyData.methodsrewriter {
return null; return null;
} }
public static MMethod getMethod(IMethod methodReference) { public static MMethod getMethod(IMethod methodRef) {
if (methodReference == null) if (methodRef == null)
return null; return null;
var module = getModule(methodReference.DeclaringType.Scope); var module = getModule(methodRef.DeclaringType.Scope);
if (module != null) if (module != null)
return module.getMethod(methodReference); return module.getMethod(methodRef);
return null; return null;
} }
public static MField getField(IField fieldReference) { public static MField getField(IField fieldRef) {
if (fieldReference == null) if (fieldRef == null)
return null; return null;
var module = getModule(fieldReference.DeclaringType.Scope); var module = getModule(fieldRef.DeclaringType.Scope);
if (module != null) if (module != null)
return module.getField(fieldReference); return module.getField(fieldRef);
return null; return null;
} }
@ -104,7 +104,7 @@ namespace AssemblyData.methodsrewriter {
if (method != null && method.MethodSig != null) if (method != null && method.MethodSig != null)
return getRtMethod(method); 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) { public static Type getRtType(IType typeRef) {

View File

@ -91,10 +91,10 @@ namespace de4dot.blocks {
return true; return true;
} }
public static FieldDef findFieldType(TypeDef typeDefinition, string typeName, bool isStatic) { public static FieldDef findFieldType(TypeDef typeDef, string typeName, bool isStatic) {
if (typeDefinition == null) if (typeDef == null)
return null; return null;
foreach (var field in typeDefinition.Fields) { foreach (var field in typeDef.Fields) {
if (field.IsStatic == isStatic && field.FieldSig.GetFieldType().GetFullName() == typeName) if (field.IsStatic == isStatic && field.FieldSig.GetFieldType().GetFullName() == typeName)
return field; return field;
} }
@ -274,12 +274,12 @@ namespace de4dot.blocks {
return getField(getType(module, field.DeclaringType), field); return getField(getType(module, field.DeclaringType), field);
} }
public static FieldDef getField(TypeDef type, IField fieldReference) { public static FieldDef getField(TypeDef type, IField fieldRef) {
if (type == null || fieldReference == null) if (type == null || fieldRef == null)
return null; return null;
if (fieldReference is FieldDef) if (fieldRef is FieldDef)
return (FieldDef)fieldReference; return (FieldDef)fieldRef;
return type.FindField(fieldReference.Name, fieldReference.FieldSig); return type.FindField(fieldRef.Name, fieldRef.FieldSig);
} }
public static FieldDef getField(TypeDef type, string typeFullName) { public static FieldDef getField(TypeDef type, string typeFullName) {
@ -596,7 +596,7 @@ namespace de4dot.blocks {
return null; 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)); var typeRef = module.UpdateRowId(new TypeRefUser(module, ns, name, asmRef));
if (isValueType) if (isValueType)
return new ValueTypeSig(typeRef); return new ValueTypeSig(typeRef);

View File

@ -23,7 +23,7 @@ using System.Collections.Generic;
namespace de4dot.blocks { namespace de4dot.blocks {
// This class makes sure that each block that is entered with a non-empty stack has at // 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 // 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 { class ForwardScanOrder {
ScopeBlock scopeBlock; ScopeBlock scopeBlock;
IList<BaseBlock> sorted; IList<BaseBlock> sorted;

View File

@ -22,7 +22,7 @@ using System.Collections.Generic;
using dot10.DotNet; using dot10.DotNet;
namespace de4dot.blocks { namespace de4dot.blocks {
public class TypeDefinitionDict<TValue> { public class TypeDefDict<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>(); Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<ScopeAndTokenKey, TypeDef> tokenToKey = new Dictionary<ScopeAndTokenKey, TypeDef>(); Dictionary<ScopeAndTokenKey, TypeDef> tokenToKey = new Dictionary<ScopeAndTokenKey, TypeDef>();
Dictionary<IType, TValue> refToValue = new Dictionary<IType, TValue>(TypeEqualityComparer.Instance); Dictionary<IType, TValue> refToValue = new Dictionary<IType, TValue>(TypeEqualityComparer.Instance);
@ -101,11 +101,11 @@ namespace de4dot.blocks {
} }
} }
public abstract class FieldDefinitionDictBase<TValue> { public abstract class FieldDefDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>(); Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<ScopeAndTokenKey, FieldDef> tokenToKey = new Dictionary<ScopeAndTokenKey, FieldDef>(); Dictionary<ScopeAndTokenKey, FieldDef> tokenToKey = new Dictionary<ScopeAndTokenKey, FieldDef>();
Dictionary<IFieldReferenceKey, TValue> refToValue = new Dictionary<IFieldReferenceKey, TValue>(); Dictionary<IFieldRefKey, TValue> refToValue = new Dictionary<IFieldRefKey, TValue>();
Dictionary<IFieldReferenceKey, FieldDef> refToKey = new Dictionary<IFieldReferenceKey, FieldDef>(); Dictionary<IFieldRefKey, FieldDef> refToKey = new Dictionary<IFieldRefKey, FieldDef>();
public int Count { public int Count {
get { return tokenToValue.Count; } get { return tokenToValue.Count; }
@ -123,7 +123,7 @@ namespace de4dot.blocks {
return new ScopeAndTokenKey(fieldDef); return new ScopeAndTokenKey(fieldDef);
} }
internal abstract IFieldReferenceKey getReferenceKey(IField fieldRef); internal abstract IFieldRefKey getRefKey(IField fieldRef);
public TValue find(IField fieldRef) { public TValue find(IField fieldRef) {
TValue value; TValue value;
@ -131,7 +131,7 @@ namespace de4dot.blocks {
if (fieldDef != null) if (fieldDef != null)
tokenToValue.TryGetValue(getTokenKey(fieldDef), out value); tokenToValue.TryGetValue(getTokenKey(fieldDef), out value);
else else
refToValue.TryGetValue(getReferenceKey(fieldRef), out value); refToValue.TryGetValue(getRefKey(fieldRef), out value);
return value; return value;
} }
@ -141,7 +141,7 @@ namespace de4dot.blocks {
if (fieldDef != null && tokenToValue.TryGetValue(getTokenKey(fieldDef), out value)) if (fieldDef != null && tokenToValue.TryGetValue(getTokenKey(fieldDef), out value))
return value; return value;
refToValue.TryGetValue(getReferenceKey(fieldRef), out value); refToValue.TryGetValue(getRefKey(fieldRef), out value);
return value; return value;
} }
@ -150,7 +150,7 @@ namespace de4dot.blocks {
tokenToValue[tokenKey] = value; tokenToValue[tokenKey] = value;
tokenToKey[tokenKey] = fieldDef; tokenToKey[tokenKey] = fieldDef;
var refKey = getReferenceKey(fieldDef); var refKey = getRefKey(fieldDef);
if (!refToValue.ContainsKey(refKey) || if (!refToValue.ContainsKey(refKey) ||
getAccessibilityOrder(fieldDef) < getAccessibilityOrder(refToKey[refKey])) { getAccessibilityOrder(fieldDef) < getAccessibilityOrder(refToKey[refKey])) {
refToKey[refKey] = fieldDef; refToKey[refKey] = fieldDef;
@ -169,35 +169,35 @@ namespace de4dot.blocks {
0, // Public 0, // Public
70, // <reserved> 70, // <reserved>
}; };
static int getAccessibilityOrder(FieldDef fieldDefinition) { static int getAccessibilityOrder(FieldDef fieldDef) {
return accessibilityOrder[(int)fieldDefinition.Attributes & 7]; return accessibilityOrder[(int)fieldDef.Attributes & 7];
} }
public void onTypesRenamed() { public void onTypesRenamed() {
var newFieldRefToDef = new Dictionary<IFieldReferenceKey, TValue>(refToValue.Count); var newFieldRefToDef = new Dictionary<IFieldRefKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue) foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((FieldDef)kvp.Key.FieldReference)] = kvp.Value; newFieldRefToDef[getRefKey((FieldDef)kvp.Key.FieldRef)] = kvp.Value;
refToValue = newFieldRefToDef; refToValue = newFieldRefToDef;
} }
} }
public class FieldDefinitionDict<TValue> : FieldDefinitionDictBase<TValue> { public class FieldDefDict<TValue> : FieldDefDictBase<TValue> {
internal override IFieldReferenceKey getReferenceKey(IField fieldRef) { internal override IFieldRefKey getRefKey(IField fieldRef) {
return new FieldReferenceKey(fieldRef); return new FieldRefKey(fieldRef);
} }
} }
public class FieldDefinitionAndDeclaringTypeDict<TValue> : FieldDefinitionDictBase<TValue> { public class FieldDefAndDeclaringTypeDict<TValue> : FieldDefDictBase<TValue> {
internal override IFieldReferenceKey getReferenceKey(IField fieldRef) { internal override IFieldRefKey getRefKey(IField fieldRef) {
return new FieldReferenceAndDeclaringTypeKey(fieldRef); return new FieldRefAndDeclaringTypeKey(fieldRef);
} }
} }
public abstract class MethodDefinitionDictBase<TValue> { public abstract class MethodDefDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>(); Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<ScopeAndTokenKey, MethodDef> tokenToKey = new Dictionary<ScopeAndTokenKey, MethodDef>(); Dictionary<ScopeAndTokenKey, MethodDef> tokenToKey = new Dictionary<ScopeAndTokenKey, MethodDef>();
Dictionary<IMethodReferenceKey, TValue> refToValue = new Dictionary<IMethodReferenceKey, TValue>(); Dictionary<IMethodRefKey, TValue> refToValue = new Dictionary<IMethodRefKey, TValue>();
Dictionary<IMethodReferenceKey, MethodDef> refToKey = new Dictionary<IMethodReferenceKey, MethodDef>(); Dictionary<IMethodRefKey, MethodDef> refToKey = new Dictionary<IMethodRefKey, MethodDef>();
public int Count { public int Count {
get { return tokenToValue.Count; } get { return tokenToValue.Count; }
@ -215,7 +215,7 @@ namespace de4dot.blocks {
return new ScopeAndTokenKey(methodDef); return new ScopeAndTokenKey(methodDef);
} }
internal abstract IMethodReferenceKey getReferenceKey(IMethod methodRef); internal abstract IMethodRefKey getRefKey(IMethod methodRef);
public TValue find(IMethod methodRef) { public TValue find(IMethod methodRef) {
TValue value; TValue value;
@ -223,7 +223,7 @@ namespace de4dot.blocks {
if (methodDef != null) if (methodDef != null)
tokenToValue.TryGetValue(getTokenKey(methodDef), out value); tokenToValue.TryGetValue(getTokenKey(methodDef), out value);
else else
refToValue.TryGetValue(getReferenceKey(methodRef), out value); refToValue.TryGetValue(getRefKey(methodRef), out value);
return value; return value;
} }
@ -233,7 +233,7 @@ namespace de4dot.blocks {
if (methodDef != null && tokenToValue.TryGetValue(getTokenKey(methodDef), out value)) if (methodDef != null && tokenToValue.TryGetValue(getTokenKey(methodDef), out value))
return value; return value;
refToValue.TryGetValue(getReferenceKey(methodRef), out value); refToValue.TryGetValue(getRefKey(methodRef), out value);
return value; return value;
} }
@ -242,7 +242,7 @@ namespace de4dot.blocks {
tokenToValue[tokenKey] = value; tokenToValue[tokenKey] = value;
tokenToKey[tokenKey] = methodDef; tokenToKey[tokenKey] = methodDef;
var refKey = getReferenceKey(methodDef); var refKey = getRefKey(methodDef);
if (!refToValue.ContainsKey(refKey) || if (!refToValue.ContainsKey(refKey) ||
getAccessibilityOrder(methodDef) < getAccessibilityOrder(refToKey[refKey])) { getAccessibilityOrder(methodDef) < getAccessibilityOrder(refToKey[refKey])) {
refToKey[refKey] = methodDef; refToKey[refKey] = methodDef;
@ -261,34 +261,34 @@ namespace de4dot.blocks {
0, // Public 0, // Public
70, // <reserved> 70, // <reserved>
}; };
static int getAccessibilityOrder(MethodDef methodDefinition) { static int getAccessibilityOrder(MethodDef methodDef) {
return accessibilityOrder[(int)methodDefinition.Attributes & 7]; return accessibilityOrder[(int)methodDef.Attributes & 7];
} }
public void onTypesRenamed() { public void onTypesRenamed() {
var newFieldRefToDef = new Dictionary<IMethodReferenceKey, TValue>(refToValue.Count); var newFieldRefToDef = new Dictionary<IMethodRefKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue) foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((MethodDef)kvp.Key.MethodReference)] = kvp.Value; newFieldRefToDef[getRefKey((MethodDef)kvp.Key.MethodRef)] = kvp.Value;
refToValue = newFieldRefToDef; refToValue = newFieldRefToDef;
} }
} }
public class MethodDefinitionDict<TValue> : MethodDefinitionDictBase<TValue> { public class MethodDefDict<TValue> : MethodDefDictBase<TValue> {
internal override IMethodReferenceKey getReferenceKey(IMethod methodRef) { internal override IMethodRefKey getRefKey(IMethod methodRef) {
return new MethodReferenceKey(methodRef); return new MethodRefKey(methodRef);
} }
} }
public class MethodDefinitionAndDeclaringTypeDict<TValue> : MethodDefinitionDictBase<TValue> { public class MethodDefAndDeclaringTypeDict<TValue> : MethodDefDictBase<TValue> {
internal override IMethodReferenceKey getReferenceKey(IMethod methodRef) { internal override IMethodRefKey getRefKey(IMethod methodRef) {
return new MethodReferenceAndDeclaringTypeKey(methodRef); return new MethodRefAndDeclaringTypeKey(methodRef);
} }
} }
public abstract class EventDefinitionDictBase<TValue> { public abstract class EventDefDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>(); Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<ScopeAndTokenKey, EventDef> tokenToKey = new Dictionary<ScopeAndTokenKey, EventDef>(); Dictionary<ScopeAndTokenKey, EventDef> tokenToKey = new Dictionary<ScopeAndTokenKey, EventDef>();
Dictionary<IEventReferenceKey, TValue> refToValue = new Dictionary<IEventReferenceKey, TValue>(); Dictionary<IEventRefKey, TValue> refToValue = new Dictionary<IEventRefKey, TValue>();
public int Count { public int Count {
get { return tokenToValue.Count; } get { return tokenToValue.Count; }
@ -302,11 +302,11 @@ namespace de4dot.blocks {
return tokenToValue.Values; return tokenToValue.Values;
} }
ScopeAndTokenKey getTokenKey(EventDef eventReference) { ScopeAndTokenKey getTokenKey(EventDef eventRef) {
return new ScopeAndTokenKey(eventReference); return new ScopeAndTokenKey(eventRef);
} }
internal abstract IEventReferenceKey getReferenceKey(EventDef eventRef); internal abstract IEventRefKey getRefKey(EventDef eventRef);
public TValue find(EventDef eventRef) { public TValue find(EventDef eventRef) {
TValue value; TValue value;
@ -319,7 +319,7 @@ namespace de4dot.blocks {
if (tokenToValue.TryGetValue(getTokenKey(eventRef), out value)) if (tokenToValue.TryGetValue(getTokenKey(eventRef), out value))
return value; return value;
refToValue.TryGetValue(getReferenceKey(eventRef), out value); refToValue.TryGetValue(getRefKey(eventRef), out value);
return value; return value;
} }
@ -328,33 +328,33 @@ namespace de4dot.blocks {
tokenToValue[tokenKey] = value; tokenToValue[tokenKey] = value;
tokenToKey[tokenKey] = eventDef; tokenToKey[tokenKey] = eventDef;
refToValue[getReferenceKey(eventDef)] = value; refToValue[getRefKey(eventDef)] = value;
} }
public void onTypesRenamed() { public void onTypesRenamed() {
var newFieldRefToDef = new Dictionary<IEventReferenceKey, TValue>(refToValue.Count); var newFieldRefToDef = new Dictionary<IEventRefKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue) foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((EventDef)kvp.Key.EventDef)] = kvp.Value; newFieldRefToDef[getRefKey((EventDef)kvp.Key.EventDef)] = kvp.Value;
refToValue = newFieldRefToDef; refToValue = newFieldRefToDef;
} }
} }
public class EventDefinitionDict<TValue> : EventDefinitionDictBase<TValue> { public class EventDefDict<TValue> : EventDefDictBase<TValue> {
internal override IEventReferenceKey getReferenceKey(EventDef eventRef) { internal override IEventRefKey getRefKey(EventDef eventRef) {
return new EventReferenceKey(eventRef); return new EventRefKey(eventRef);
} }
} }
public class EventDefinitionAndDeclaringTypeDict<TValue> : EventDefinitionDictBase<TValue> { public class EventDefAndDeclaringTypeDict<TValue> : EventDefDictBase<TValue> {
internal override IEventReferenceKey getReferenceKey(EventDef eventRef) { internal override IEventRefKey getRefKey(EventDef eventRef) {
return new EventReferenceAndDeclaringTypeKey(eventRef); return new EventRefAndDeclaringTypeKey(eventRef);
} }
} }
public abstract class PropertyDefinitionDictBase<TValue> { public abstract class PropertyDefDictBase<TValue> {
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>(); Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
Dictionary<ScopeAndTokenKey, PropertyDef> tokenToKey = new Dictionary<ScopeAndTokenKey, PropertyDef>(); Dictionary<ScopeAndTokenKey, PropertyDef> tokenToKey = new Dictionary<ScopeAndTokenKey, PropertyDef>();
Dictionary<IPropertyReferenceKey, TValue> refToValue = new Dictionary<IPropertyReferenceKey, TValue>(); Dictionary<IPropertyRefKey, TValue> refToValue = new Dictionary<IPropertyRefKey, TValue>();
public int Count { public int Count {
get { return tokenToValue.Count; } get { return tokenToValue.Count; }
@ -368,11 +368,11 @@ namespace de4dot.blocks {
return tokenToValue.Values; return tokenToValue.Values;
} }
ScopeAndTokenKey getTokenKey(PropertyDef propertyReference) { ScopeAndTokenKey getTokenKey(PropertyDef propertyRef) {
return new ScopeAndTokenKey(propertyReference); return new ScopeAndTokenKey(propertyRef);
} }
internal abstract IPropertyReferenceKey getReferenceKey(PropertyDef propertyReference); internal abstract IPropertyRefKey getRefKey(PropertyDef propertyRef);
public TValue find(PropertyDef propRef) { public TValue find(PropertyDef propRef) {
TValue value; TValue value;
@ -385,7 +385,7 @@ namespace de4dot.blocks {
if (tokenToValue.TryGetValue(getTokenKey(propRef), out value)) if (tokenToValue.TryGetValue(getTokenKey(propRef), out value))
return value; return value;
refToValue.TryGetValue(getReferenceKey(propRef), out value); refToValue.TryGetValue(getRefKey(propRef), out value);
return value; return value;
} }
@ -394,26 +394,26 @@ namespace de4dot.blocks {
tokenToValue[tokenKey] = value; tokenToValue[tokenKey] = value;
tokenToKey[tokenKey] = propDef; tokenToKey[tokenKey] = propDef;
refToValue[getReferenceKey(propDef)] = value; refToValue[getRefKey(propDef)] = value;
} }
public void onTypesRenamed() { public void onTypesRenamed() {
var newFieldRefToDef = new Dictionary<IPropertyReferenceKey, TValue>(refToValue.Count); var newFieldRefToDef = new Dictionary<IPropertyRefKey, TValue>(refToValue.Count);
foreach (var kvp in refToValue) foreach (var kvp in refToValue)
newFieldRefToDef[getReferenceKey((PropertyDef)kvp.Key.PropertyDef)] = kvp.Value; newFieldRefToDef[getRefKey((PropertyDef)kvp.Key.PropertyDef)] = kvp.Value;
refToValue = newFieldRefToDef; refToValue = newFieldRefToDef;
} }
} }
public class PropertyDefinitionDict<TValue> : PropertyDefinitionDictBase<TValue> { public class PropertyDefDict<TValue> : PropertyDefDictBase<TValue> {
internal override IPropertyReferenceKey getReferenceKey(PropertyDef propRef) { internal override IPropertyRefKey getRefKey(PropertyDef propRef) {
return new PropertyReferenceKey(propRef); return new PropertyRefKey(propRef);
} }
} }
public class PropertyDefinitionAndDeclaringTypeDict<TValue> : PropertyDefinitionDictBase<TValue> { public class PropertyDefAndDeclaringTypeDict<TValue> : PropertyDefDictBase<TValue> {
internal override IPropertyReferenceKey getReferenceKey(PropertyDef propRef) { internal override IPropertyRefKey getRefKey(PropertyDef propRef) {
return new PropertyReferenceAndDeclaringTypeKey(propRef); return new PropertyRefAndDeclaringTypeKey(propRef);
} }
} }
@ -502,30 +502,30 @@ namespace de4dot.blocks {
} }
} }
interface IFieldReferenceKey { interface IFieldRefKey {
IField FieldReference { get; } IField FieldRef { get; }
} }
interface IMethodReferenceKey { interface IMethodRefKey {
IMethod MethodReference { get; } IMethod MethodRef { get; }
} }
interface IEventReferenceKey { interface IEventRefKey {
EventDef EventDef { get; } EventDef EventDef { get; }
} }
interface IPropertyReferenceKey { interface IPropertyRefKey {
PropertyDef PropertyDef { get; } PropertyDef PropertyDef { get; }
} }
sealed class FieldReferenceKey : IFieldReferenceKey { sealed class FieldRefKey : IFieldRefKey {
readonly IField fieldRef; readonly IField fieldRef;
public IField FieldReference { public IField FieldRef {
get { return fieldRef; } get { return fieldRef; }
} }
public FieldReferenceKey(IField fieldRef) { public FieldRefKey(IField fieldRef) {
this.fieldRef = fieldRef; this.fieldRef = fieldRef;
} }
@ -534,7 +534,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as FieldReferenceKey; var other = obj as FieldRefKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer().Equals(fieldRef, other.fieldRef); 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; readonly IMethod methodRef;
public IMethod MethodReference { public IMethod MethodRef {
get { return methodRef; } get { return methodRef; }
} }
public MethodReferenceKey(IMethod methodRef) { public MethodRefKey(IMethod methodRef) {
this.methodRef = methodRef; this.methodRef = methodRef;
} }
@ -561,7 +561,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as MethodReferenceKey; var other = obj as MethodRefKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer().Equals(methodRef, other.methodRef); 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; readonly IField fieldRef;
public IField FieldReference { public IField FieldRef {
get { return fieldRef; } get { return fieldRef; }
} }
public FieldReferenceAndDeclaringTypeKey(IField fieldRef) { public FieldRefAndDeclaringTypeKey(IField fieldRef) {
this.fieldRef = fieldRef; this.fieldRef = fieldRef;
} }
@ -588,7 +588,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as FieldReferenceAndDeclaringTypeKey; var other = obj as FieldRefAndDeclaringTypeKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer(SigComparerOptions.CompareMethodFieldDeclaringType).Equals(fieldRef, other.fieldRef); 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; readonly IMethod methodRef;
public IMethod MethodReference { public IMethod MethodRef {
get { return methodRef; } get { return methodRef; }
} }
public MethodReferenceAndDeclaringTypeKey(IMethod methodRef) { public MethodRefAndDeclaringTypeKey(IMethod methodRef) {
this.methodRef = methodRef; this.methodRef = methodRef;
} }
@ -615,7 +615,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as MethodReferenceAndDeclaringTypeKey; var other = obj as MethodRefAndDeclaringTypeKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer(SigComparerOptions.CompareMethodFieldDeclaringType).Equals(methodRef, other.methodRef); 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; readonly EventDef eventRef;
public EventDef EventDef { public EventDef EventDef {
get { return eventRef; } get { return eventRef; }
} }
public EventReferenceKey(EventDef eventRef) { public EventRefKey(EventDef eventRef) {
this.eventRef = eventRef; this.eventRef = eventRef;
} }
@ -642,7 +642,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as EventReferenceKey; var other = obj as EventRefKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer().Equals(eventRef, other.eventRef); 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; readonly EventDef eventRef;
public EventDef EventDef { public EventDef EventDef {
get { return eventRef; } get { return eventRef; }
} }
public EventReferenceAndDeclaringTypeKey(EventDef eventRef) { public EventRefAndDeclaringTypeKey(EventDef eventRef) {
this.eventRef = eventRef; this.eventRef = eventRef;
} }
@ -669,7 +669,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as EventReferenceAndDeclaringTypeKey; var other = obj as EventRefAndDeclaringTypeKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer(SigComparerOptions.CompareEventDeclaringType).Equals(eventRef, other.eventRef); 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; readonly PropertyDef propRef;
public PropertyDef PropertyDef { public PropertyDef PropertyDef {
get { return propRef; } get { return propRef; }
} }
public PropertyReferenceKey(PropertyDef propRef) { public PropertyRefKey(PropertyDef propRef) {
this.propRef = propRef; this.propRef = propRef;
} }
@ -696,7 +696,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as PropertyReferenceKey; var other = obj as PropertyRefKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer().Equals(propRef, other.propRef); 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; readonly PropertyDef propRef;
public PropertyDef PropertyDef { public PropertyDef PropertyDef {
get { return propRef; } get { return propRef; }
} }
public PropertyReferenceAndDeclaringTypeKey(PropertyDef propRef) { public PropertyRefAndDeclaringTypeKey(PropertyDef propRef) {
this.propRef = propRef; this.propRef = propRef;
} }
@ -723,7 +723,7 @@ namespace de4dot.blocks {
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
var other = obj as PropertyReferenceAndDeclaringTypeKey; var other = obj as PropertyRefAndDeclaringTypeKey;
if (other == null) if (other == null)
return false; return false;
return new SigComparer(SigComparerOptions.ComparePropertyDeclaringType).Equals(propRef, other.propRef); return new SigComparer(SigComparerOptions.ComparePropertyDeclaringType).Equals(propRef, other.propRef);

View File

@ -21,7 +21,7 @@ using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
[assembly: AssemblyTitle("blocks")] [assembly: AssemblyTitle("blocks")]
[assembly: AssemblyDescription("Modifies Mono.Cecil MethodDefinition bodies")] [assembly: AssemblyDescription("Modifies dot10 MethodDef bodies")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("blocks")] [assembly: AssemblyProduct("blocks")]

View File

@ -46,7 +46,7 @@ namespace de4dot.code {
dataDict.Remove(name); dataDict.Remove(name);
} }
static ITypeDefOrRef getNonGenericTypeReference(ITypeDefOrRef typeRef) { static ITypeDefOrRef getNonGenericTypeRef(ITypeDefOrRef typeRef) {
var ts = typeRef as TypeSpec; var ts = typeRef as TypeSpec;
if (ts == null) if (ts == null)
return typeRef; return typeRef;
@ -59,7 +59,7 @@ namespace de4dot.code {
public TypeDef resolveType(ITypeDefOrRef type) { public TypeDef resolveType(ITypeDefOrRef type) {
if (type == null) if (type == null)
return null; return null;
type = getNonGenericTypeReference(type); type = getNonGenericTypeRef(type);
var typeDef = type as TypeDef; var typeDef = type as TypeDef;
if (typeDef != null) if (typeDef != null)

View File

@ -133,11 +133,11 @@ namespace de4dot.code {
printExInfo(exInfo); printExInfo(exInfo);
var instrString = instr.OpCode.Name; var instrString = instr.OpCode.Name;
var operandString = getOperandString(instr); var operandString = getOperandString(instr);
var memberReference = instr.Operand as ITokenOperand; var memberRef = instr.Operand as ITokenOperand;
if (operandString == "") if (operandString == "")
Logger.log(loggerEvent, "{0}", instrString); Logger.log(loggerEvent, "{0}", instrString);
else if (memberReference != null) else if (memberRef != null)
Logger.log(loggerEvent, "{0,-9} {1} // {2:X8}", instrString, Utils.removeNewlines(operandString), memberReference.MDToken.ToUInt32()); Logger.log(loggerEvent, "{0,-9} {1} // {2:X8}", instrString, Utils.removeNewlines(operandString), memberRef.MDToken.ToUInt32());
else else
Logger.log(loggerEvent, "{0,-9} {1}", instrString, Utils.removeNewlines(operandString)); Logger.log(loggerEvent, "{0,-9} {1}", instrString, Utils.removeNewlines(operandString));
} }

View File

@ -165,7 +165,7 @@ namespace de4dot.code {
this.callEndIndex = callEndIndex; this.callEndIndex = callEndIndex;
} }
public IMethod getMethodReference() { public IMethod getMethodRef() {
return (IMethod)block.Instructions[callEndIndex].Operand; return (IMethod)block.Instructions[callEndIndex].Operand;
} }
} }
@ -257,7 +257,7 @@ namespace de4dot.code {
bool findArgs(CallResult callResult) { bool findArgs(CallResult callResult) {
var block = callResult.block; var block = callResult.block;
var method = callResult.getMethodReference(); var method = callResult.getMethodRef();
var methodArgs = DotNetUtils.getArgs(method); var methodArgs = DotNetUtils.getArgs(method);
int numArgs = methodArgs.Count; int numArgs = methodArgs.Count;
var args = new object[numArgs]; var args = new object[numArgs];

View File

@ -552,8 +552,6 @@ namespace de4dot.code {
deob.DeobfuscatedFile = null; deob.DeobfuscatedFile = null;
if (!options.ControlFlowDeobfuscation) { 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()) if (ShouldPreserveTokens())
return; return;
} }

View File

@ -128,7 +128,7 @@ namespace de4dot.code {
} }
class StaticStringInliner : StringInlinerBase { class StaticStringInliner : StringInlinerBase {
MethodDefinitionAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>> stringDecrypters = new MethodDefinitionAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>>(); MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>> stringDecrypters = new MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], string>>();
public override bool HasHandlers { public override bool HasHandlers {
get { return stringDecrypters.Count != 0; } get { return stringDecrypters.Count != 0; }

View File

@ -28,10 +28,10 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm {
IDeobfuscatorContext deobfuscatorContext; IDeobfuscatorContext deobfuscatorContext;
ModuleDefMD module; ModuleDefMD module;
EmbeddedResource resource; EmbeddedResource resource;
AssemblyRef vmAssemblyReference; AssemblyRef vmAssemblyRef;
public bool Detected { public bool Detected {
get { return resource != null && vmAssemblyReference != null; } get { return resource != null && vmAssemblyRef != null; }
} }
public EmbeddedResource Resource { public EmbeddedResource Resource {
@ -48,16 +48,16 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm {
this.module = module; this.module = module;
if (oldOne.resource != null) if (oldOne.resource != null)
this.resource = (EmbeddedResource)module.Resources[oldOne.module.Resources.IndexOf(oldOne.resource)]; this.resource = (EmbeddedResource)module.Resources[oldOne.module.Resources.IndexOf(oldOne.resource)];
if (oldOne.vmAssemblyReference != null) if (oldOne.vmAssemblyRef != null)
this.vmAssemblyReference = module.ResolveAssemblyRef(oldOne.vmAssemblyReference.Rid); this.vmAssemblyRef = module.ResolveAssemblyRef(oldOne.vmAssemblyRef.Rid);
} }
public void find() { public void find() {
resource = findCsvmResource(); resource = findCsvmResource();
vmAssemblyReference = findVmAssemblyReference(); vmAssemblyRef = findVmAssemblyRef();
} }
AssemblyRef findVmAssemblyReference() { AssemblyRef findVmAssemblyRef() {
foreach (var memberRef in module.GetMemberRefs()) { foreach (var memberRef in module.GetMemberRefs()) {
var sig = memberRef.MethodSig; var sig = memberRef.MethodSig;
if (sig == null) if (sig == null)
@ -132,7 +132,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm {
} }
VmOpCodeHandlerDetector getVmOpCodeHandlerDetector() { VmOpCodeHandlerDetector getVmOpCodeHandlerDetector() {
var vmFilename = vmAssemblyReference.Name + ".dll"; var vmFilename = vmAssemblyRef.Name + ".dll";
var vmModulePath = Path.Combine(Path.GetDirectoryName(module.Location), vmFilename); var vmModulePath = Path.Combine(Path.GetDirectoryName(module.Location), vmFilename);
Logger.v("CSVM filename: {0}", vmFilename); Logger.v("CSVM filename: {0}", vmFilename);

View File

@ -234,12 +234,12 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm {
throw new ApplicationException("Invalid number of locals"); throw new ApplicationException("Invalid number of locals");
for (int i = 0; i < numLocals; i++) for (int i = 0; i < numLocals; i++)
locals.Add(new Local(readTypeReference(reader))); locals.Add(new Local(readTypeRef(reader)));
return locals; return locals;
} }
TypeSig readTypeReference(BinaryReader reader) { TypeSig readTypeRef(BinaryReader reader) {
var etype = (ElementType)reader.ReadInt32(); var etype = (ElementType)reader.ReadInt32();
switch (etype) { switch (etype) {
case ElementType.Void: return module.CorLibTypes.Void; case ElementType.Void: return module.CorLibTypes.Void;
@ -345,7 +345,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm {
object fixOperand(IList<Instruction> instrs, Instruction instr, IVmOperand vmOperand) { object fixOperand(IList<Instruction> instrs, Instruction instr, IVmOperand vmOperand) {
if (vmOperand is TokenOperand) if (vmOperand is TokenOperand)
return getMemberReference(((TokenOperand)vmOperand).token); return getMemberRef(((TokenOperand)vmOperand).token);
if (vmOperand is TargetDisplOperand) if (vmOperand is TargetDisplOperand)
return getInstruction(instrs, instr, ((TargetDisplOperand)vmOperand).displacement); return getInstruction(instrs, instr, ((TargetDisplOperand)vmOperand).displacement);
@ -387,7 +387,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm {
return fieldRef; return fieldRef;
} }
ITokenOperand getMemberReference(int token) { ITokenOperand getMemberRef(int token) {
var memberRef = module.ResolveToken(token) as ITokenOperand; var memberRef = module.ResolveToken(token) as ITokenOperand;
if (memberRef == null) if (memberRef == null)
throw new ApplicationException(string.Format("Could not find member ref: {0:X8}", token)); throw new ApplicationException(string.Format("Could not find member ref: {0:X8}", token));

View File

@ -75,7 +75,7 @@ namespace de4dot.code.deobfuscators.Agile_NET.vm {
} }
static internal IEnumerable<FieldDef> getFields(TypeDef type) { static internal IEnumerable<FieldDef> getFields(TypeDef type) {
var typeFields = new FieldDefinitionAndDeclaringTypeDict<FieldDef>(); var typeFields = new FieldDefAndDeclaringTypeDict<FieldDef>();
foreach (var field in type.Fields) foreach (var field in type.Fields)
typeFields.add(field, field); typeFields.add(field, field);
var realFields = new Dictionary<FieldDef, bool>(); var realFields = new Dictionary<FieldDef, bool>();

View File

@ -52,15 +52,15 @@ namespace de4dot.code.deobfuscators.Babel_NET {
string[] strings; string[] strings;
AssemblyRef[] assemblyNames; AssemblyRef[] assemblyNames;
Dictionary<string, int> methodOffsets; Dictionary<string, int> methodOffsets;
List<TypeSig> typeReferences; List<TypeSig> typeRefs;
MemberReferenceConverter memberReferenceConverter; MemberRefConverter memberRefConverter;
IDeobfuscatorContext deobfuscatorContext; IDeobfuscatorContext deobfuscatorContext;
public ImageReader(IDeobfuscatorContext deobfuscatorContext, ModuleDefMD module, byte[] data) { public ImageReader(IDeobfuscatorContext deobfuscatorContext, ModuleDefMD module, byte[] data) {
this.deobfuscatorContext = deobfuscatorContext; this.deobfuscatorContext = deobfuscatorContext;
this.module = module; this.module = module;
this.reader = MemoryImageStream.Create(data); this.reader = MemoryImageStream.Create(data);
this.memberReferenceConverter = new MemberReferenceConverter(module); this.memberRefConverter = new MemberRefConverter(module);
} }
public bool initialize() { public bool initialize() {
@ -86,26 +86,26 @@ namespace de4dot.code.deobfuscators.Babel_NET {
void initializeV10() { void initializeV10() {
reader.ReadInt16(); reader.ReadInt16();
int methodNamesOffset = (int)reader.ReadInt64(); int methodNamesOffset = (int)reader.ReadInt64();
int typeReferencesOffset = (int)reader.ReadInt64(); int typeRefsOffset = (int)reader.ReadInt64();
int assemblyReferencesOffset = (int)reader.ReadInt64(); int assemblyRefsOffset = (int)reader.ReadInt64();
int stringsOffset = (int)reader.ReadInt64(); int stringsOffset = (int)reader.ReadInt64();
initializeStrings(stringsOffset); initializeStrings(stringsOffset);
initializeAssemblyNames(assemblyReferencesOffset); initializeAssemblyNames(assemblyRefsOffset);
initializeMethodNames(methodNamesOffset); initializeMethodNames(methodNamesOffset);
initializeTypeReferences(typeReferencesOffset); initializeTypeRefs(typeRefsOffset);
} }
void initializeV55() { void initializeV55() {
int methodNamesOffset = (int)reader.ReadInt64() ^ METADATA_SIG; int methodNamesOffset = (int)reader.ReadInt64() ^ METADATA_SIG;
int typeReferencesOffset = (int)reader.ReadInt64() ^ (METADATA_SIG << 1); int typeRefsOffset = (int)reader.ReadInt64() ^ (METADATA_SIG << 1);
int assemblyReferencesOffset = (int)reader.ReadInt64() ^ ((METADATA_SIG << 1) + 1); int assemblyRefsOffset = (int)reader.ReadInt64() ^ ((METADATA_SIG << 1) + 1);
int stringsOffset = (int)reader.ReadInt64() ^ (((METADATA_SIG << 1) + 1) << 1); int stringsOffset = (int)reader.ReadInt64() ^ (((METADATA_SIG << 1) + 1) << 1);
initializeStrings(stringsOffset); initializeStrings(stringsOffset);
initializeAssemblyNames(assemblyReferencesOffset); initializeAssemblyNames(assemblyRefsOffset);
initializeMethodNames(methodNamesOffset); initializeMethodNames(methodNamesOffset);
initializeTypeReferences(typeReferencesOffset); initializeTypeRefs(typeRefsOffset);
} }
public void restore(string name, MethodDef method) { public void restore(string name, MethodDef method) {
@ -138,11 +138,11 @@ namespace de4dot.code.deobfuscators.Babel_NET {
body.ExceptionHandlers.Add(eh); body.ExceptionHandlers.Add(eh);
} }
BabelMethodDefinition getMethod(string name) { BabelMethodDef getMethod(string name) {
int offset = methodOffsets[name]; int offset = methodOffsets[name];
methodOffsets.Remove(name); methodOffsets.Remove(name);
reader.Position = offset; reader.Position = offset;
return new MethodDefinitionReader(this, reader).read(); return new MethodDefReader(this, reader).read();
} }
public string readString() { public string readString() {
@ -150,7 +150,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
} }
public TypeSig readTypeSig() { public TypeSig readTypeSig() {
return typeReferences[readVariableLengthInt32()]; return typeRefs[readVariableLengthInt32()];
} }
public TypeSig[] readTypeSigs() { public TypeSig[] readTypeSigs() {
@ -160,7 +160,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
return refs; return refs;
} }
public IField readFieldReference() { public IField readFieldRef() {
var name = readString(); var name = readString();
var declaringType = readTypeSig(); var declaringType = readTypeSig();
@ -171,7 +171,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
Utils.removeNewlines(declaringType))); Utils.removeNewlines(declaringType)));
} }
return memberReferenceConverter.convert(fields[0]); return memberRefConverter.convert(fields[0]);
} }
static List<FieldDef> getFields(TypeDef type, string name) { static List<FieldDef> getFields(TypeDef type, string name) {
@ -180,10 +180,10 @@ namespace de4dot.code.deobfuscators.Babel_NET {
return new List<FieldDef>(type.FindFields(name)); return new List<FieldDef>(type.FindFields(name));
} }
public IMethod readMethodReference() { public IMethod readMethodRef() {
var babelMethodRef = new MethodReferenceReader(this, reader).read(); var babelMethodRef = new MethodRefReader(this, reader).read();
var method = getMethodReference(babelMethodRef); var method = getMethodRef(babelMethodRef);
if (method == null) { if (method == null) {
throw new ApplicationException(string.Format("Could not find method '{0}' in type '{1}'", throw new ApplicationException(string.Format("Could not find method '{0}' in type '{1}'",
Utils.removeNewlines(babelMethodRef.Name), Utils.removeNewlines(babelMethodRef.Name),
@ -198,7 +198,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
return module.UpdateRowId(mr); return module.UpdateRowId(mr);
} }
IMethod getMethodReference(BabelMethodreference babelMethodRef) { IMethod getMethodRef(BabelMethodreference babelMethodRef) {
var declaringType = resolve(babelMethodRef.DeclaringType); var declaringType = resolve(babelMethodRef.DeclaringType);
if (declaringType == null) if (declaringType == null)
return null; return null;
@ -221,10 +221,10 @@ namespace de4dot.code.deobfuscators.Babel_NET {
foreach (var method in declaringType.Methods) { foreach (var method in declaringType.Methods) {
if (compareMethod(GenericArgsSubstitutor.create(method, gis, gim), babelMethodRef)) { if (compareMethod(GenericArgsSubstitutor.create(method, gis, gim), babelMethodRef)) {
if (!babelMethodRef.IsGenericMethod) if (!babelMethodRef.IsGenericMethod)
methods.Add(memberReferenceConverter.convert(method)); methods.Add(memberRefConverter.convert(method));
else { else {
var gim2 = new GenericInstMethodSig(babelMethodRef.GenericArguments); 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); methods.Add(ms);
} }
} }
@ -329,39 +329,39 @@ namespace de4dot.code.deobfuscators.Babel_NET {
} }
} }
void initializeTypeReferences(int headerOffset) { void initializeTypeRefs(int headerOffset) {
reader.Position = headerOffset; reader.Position = headerOffset;
if (reader.ReadInt32() != TYPEREFS_SIG) if (reader.ReadInt32() != TYPEREFS_SIG)
throw new ApplicationException("Invalid typerefs sig"); throw new ApplicationException("Invalid typerefs sig");
int numTypeRefs = reader.ReadInt32(); int numTypeRefs = reader.ReadInt32();
typeReferences = new List<TypeSig>(numTypeRefs + 1); typeRefs = new List<TypeSig>(numTypeRefs + 1);
typeReferences.Add(null); typeRefs.Add(null);
var genericArgFixes = new Dictionary<GenericInstSig, List<int>>(); var genericArgFixes = new Dictionary<GenericInstSig, List<int>>();
for (int i = 0; i < numTypeRefs; i++) { for (int i = 0; i < numTypeRefs; i++) {
TypeId typeId = (TypeId)reader.ReadByte(); TypeId typeId = (TypeId)reader.ReadByte();
switch (typeId) { switch (typeId) {
case TypeId.TypeRef: case TypeId.TypeRef:
typeReferences.Add(readTypeRef()); typeRefs.Add(readTypeRef());
break; break;
case TypeId.GenericInstance: case TypeId.GenericInstance:
List<int> genericArgs; List<int> genericArgs;
var git = readGenericInstanceType(out genericArgs); var git = readGenericInstanceType(out genericArgs);
typeReferences.Add(git); typeRefs.Add(git);
genericArgFixes[git] = genericArgs; genericArgFixes[git] = genericArgs;
break; break;
case TypeId.Pointer: case TypeId.Pointer:
typeReferences.Add(readPointerType()); typeRefs.Add(readPointerType());
break; break;
case TypeId.Array: case TypeId.Array:
typeReferences.Add(readArrayType()); typeRefs.Add(readArrayType());
break; break;
case TypeId.ByRef: case TypeId.ByRef:
typeReferences.Add(readByReferenceType()); typeRefs.Add(readByRefType());
break; break;
default: default:
@ -372,7 +372,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
foreach (var kv in genericArgFixes) { foreach (var kv in genericArgFixes) {
var git = kv.Key; var git = kv.Key;
foreach (var typeNum in kv.Value) 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); parseReflectionTypeName(readString(), out ns, out name);
var asmRef = assemblyNames[readVariableLengthInt32()]; var asmRef = assemblyNames[readVariableLengthInt32()];
var declaringType = readTypeSig(); var declaringType = readTypeSig();
var typeReference = new TypeRefUser(module, ns, name); var typeRef = new TypeRefUser(module, ns, name);
if (declaringType != null) if (declaringType != null)
typeReference.ResolutionScope = getTypeRef(declaringType); typeRef.ResolutionScope = getTypeRef(declaringType);
else else
typeReference.ResolutionScope = asmRef; typeRef.ResolutionScope = asmRef;
return memberReferenceConverter.convert(typeReference); return memberRefConverter.convert(typeRef);
} }
TypeRef getTypeRef(TypeSig type) { TypeRef getTypeRef(TypeSig type) {
@ -469,7 +469,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
return new ArraySig(typeSig, rank); return new ArraySig(typeSig, rank);
} }
ByRefSig readByReferenceType() { ByRefSig readByRefType() {
return new ByRefSig(readTypeSig()); return new ByRefSig(readTypeSig());
} }

View File

@ -23,14 +23,14 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.Babel_NET { namespace de4dot.code.deobfuscators.Babel_NET {
// Converts type references/definitions in one module to this module // Converts type references/definitions in one module to this module
class MemberReferenceConverter { class MemberRefConverter {
ModuleDefMD module; ModuleDefMD module;
public ModuleDefMD Module { public ModuleDefMD Module {
get { return module; } get { return module; }
} }
public MemberReferenceConverter(ModuleDefMD module) { public MemberRefConverter(ModuleDefMD module) {
this.module = module; this.module = module;
} }
@ -60,7 +60,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
public IField convert(IField fieldRef) { public IField convert(IField fieldRef) {
if (isInOurModule(fieldRef)) if (isInOurModule(fieldRef))
return tryGetFieldDefinition(fieldRef); return tryGetFieldDef(fieldRef);
return createImporter().Import(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) if (!(methodRef is MemberRef || methodRef is MethodDef) || methodRef.MethodSig == null)
throw new ApplicationException("Invalid method reference type"); throw new ApplicationException("Invalid method reference type");
if (isInOurModule(methodRef)) if (isInOurModule(methodRef))
return (IMethodDefOrRef)tryGetMethodDefinition(methodRef); return (IMethodDefOrRef)tryGetMethodDef(methodRef);
return (IMethodDefOrRef)createImporter().Import(methodRef); return (IMethodDefOrRef)createImporter().Import(methodRef);
} }
public IField tryGetFieldDefinition(IField fieldRef) { public IField tryGetFieldDef(IField fieldRef) {
var fieldDef = fieldRef as FieldDef; var fieldDef = fieldRef as FieldDef;
if (fieldDef != null) if (fieldDef != null)
return fieldDef; return fieldDef;
@ -83,7 +83,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
return DotNetUtils.getField(declaringType, fieldRef); return DotNetUtils.getField(declaringType, fieldRef);
} }
public IMethod tryGetMethodDefinition(IMethod methodRef) { public IMethod tryGetMethodDef(IMethod methodRef) {
var methodDef = methodRef as MethodDef; var methodDef = methodRef as MethodDef;
if (methodDef != null) if (methodDef != null)
return methodDef; return methodDef;

View File

@ -45,11 +45,11 @@ namespace de4dot.code.deobfuscators.Babel_NET {
} }
protected override IField ReadInlineField(Instruction instr) { protected override IField ReadInlineField(Instruction instr) {
return imageReader.readFieldReference(); return imageReader.readFieldRef();
} }
protected override IMethod ReadInlineMethod(Instruction instr) { protected override IMethod ReadInlineMethod(Instruction instr) {
return imageReader.readMethodReference(); return imageReader.readMethodRef();
} }
protected override MethodSig ReadInlineSig(Instruction instr) { protected override MethodSig ReadInlineSig(Instruction instr) {
@ -63,8 +63,8 @@ namespace de4dot.code.deobfuscators.Babel_NET {
protected override ITokenOperand ReadInlineTok(Instruction instr) { protected override ITokenOperand ReadInlineTok(Instruction instr) {
switch (reader.ReadByte()) { switch (reader.ReadByte()) {
case 0: return imageReader.readTypeSig().ToTypeDefOrRef(); case 0: return imageReader.readTypeSig().ToTypeDefOrRef();
case 1: return imageReader.readFieldReference(); case 1: return imageReader.readFieldRef();
case 2: return imageReader.readMethodReference(); case 2: return imageReader.readMethodRef();
default: throw new ApplicationException("Unknown token type"); default: throw new ApplicationException("Unknown token type");
} }
} }

View File

@ -42,7 +42,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
} }
} }
class BabelMethodDefinition : BabelMethodreference { class BabelMethodDef : BabelMethodreference {
Parameter thisParameter; Parameter thisParameter;
public int Flags2 { get; set; } public int Flags2 { get; set; }
@ -95,16 +95,16 @@ namespace de4dot.code.deobfuscators.Babel_NET {
} }
} }
class MethodReferenceReader { class MethodRefReader {
ImageReader imageReader; ImageReader imageReader;
IBinaryReader reader; IBinaryReader reader;
BabelMethodreference bmr; BabelMethodreference bmr;
public MethodReferenceReader(ImageReader imageReader, IBinaryReader reader) public MethodRefReader(ImageReader imageReader, IBinaryReader reader)
: this(imageReader, reader, new BabelMethodreference()) { : 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.imageReader = imageReader;
this.reader = reader; this.reader = reader;
this.bmr = bmr; this.bmr = bmr;
@ -133,19 +133,19 @@ namespace de4dot.code.deobfuscators.Babel_NET {
} }
} }
class MethodDefinitionReader { class MethodDefReader {
MethodReferenceReader methodReferenceReader; MethodRefReader methodRefReader;
MethodBodyReader methodBodyReader; MethodBodyReader methodBodyReader;
BabelMethodDefinition bmd; BabelMethodDef bmd;
public MethodDefinitionReader(ImageReader imageReader, IBinaryReader reader) { public MethodDefReader(ImageReader imageReader, IBinaryReader reader) {
this.bmd = new BabelMethodDefinition(); this.bmd = new BabelMethodDef();
this.methodReferenceReader = new MethodReferenceReader(imageReader, reader, bmd); this.methodRefReader = new MethodRefReader(imageReader, reader, bmd);
this.methodBodyReader = new MethodBodyReader(imageReader, reader); this.methodBodyReader = new MethodBodyReader(imageReader, reader);
} }
public BabelMethodDefinition read() { public BabelMethodDef read() {
methodReferenceReader.read(); methodRefReader.read();
methodBodyReader.read(bmd.getRealParameters()); methodBodyReader.read(bmd.getRealParameters());
bmd.setBody(methodBodyReader); bmd.setBody(methodBodyReader);
return bmd; return bmd;

View File

@ -25,7 +25,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.Babel_NET { namespace de4dot.code.deobfuscators.Babel_NET {
class ProxyCallFixer : ProxyCallFixer2 { class ProxyCallFixer : ProxyCallFixer2 {
MethodDefinitionAndDeclaringTypeDict<ProxyCreatorType> methodToType = new MethodDefinitionAndDeclaringTypeDict<ProxyCreatorType>(); MethodDefAndDeclaringTypeDict<ProxyCreatorType> methodToType = new MethodDefAndDeclaringTypeDict<ProxyCreatorType>();
public ProxyCallFixer(ModuleDefMD module) public ProxyCallFixer(ModuleDefMD module)
: base(module) { : base(module) {

View File

@ -309,7 +309,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
return null; return null;
} }
class ReflectionToCecilMethodCreator { class ReflectionToDot10MethodCreator {
MethodDef method; MethodDef method;
List<Instruction> instructions = new List<Instruction>(); List<Instruction> instructions = new List<Instruction>();
InstructionEmulator emulator; InstructionEmulator emulator;
@ -331,7 +331,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
get { return instructions; } get { return instructions; }
} }
public ReflectionToCecilMethodCreator(MethodDef method) { public ReflectionToDot10MethodCreator(MethodDef method) {
this.method = method; this.method = method;
this.emulator = new InstructionEmulator(method); this.emulator = new InstructionEmulator(method);
} }
@ -439,7 +439,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
emulator.pop(); // the this ptr emulator.pop(); // the this ptr
addInstruction(new Instruction { addInstruction(new Instruction {
OpCode = opcode, OpCode = opcode,
Operand = createCecilOperand(opcode, operand), Operand = createDot10Operand(opcode, operand),
}); });
return true; 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) if (op is Int32Value)
return ((Int32Value)op).value; return ((Int32Value)op).value;
if (op is StringValue) if (op is StringValue)
@ -470,7 +470,7 @@ namespace de4dot.code.deobfuscators.Babel_NET {
} }
static List<Instruction> getOffsetCalcInstructions(MethodDef method) { static List<Instruction> getOffsetCalcInstructions(MethodDef method) {
var creator = new ReflectionToCecilMethodCreator(method); var creator = new ReflectionToDot10MethodCreator(method);
creator.create(); creator.create();
var instrs = creator.Instructions; var instrs = creator.Instructions;

View File

@ -25,7 +25,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.CodeFort { namespace de4dot.code.deobfuscators.CodeFort {
class ProxyCallFixer : ProxyCallFixer3 { class ProxyCallFixer : ProxyCallFixer3 {
MethodDefinitionAndDeclaringTypeDict<bool> proxyTargetMethods = new MethodDefinitionAndDeclaringTypeDict<bool>(); MethodDefAndDeclaringTypeDict<bool> proxyTargetMethods = new MethodDefAndDeclaringTypeDict<bool>();
TypeDef proxyMethodsType; TypeDef proxyMethodsType;
public TypeDef ProxyMethodsType { public TypeDef ProxyMethodsType {

View File

@ -29,7 +29,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.CodeWall { namespace de4dot.code.deobfuscators.CodeWall {
class StringDecrypter { class StringDecrypter {
ModuleDefMD module; ModuleDefMD module;
MethodDefinitionAndDeclaringTypeDict<StringEncrypterInfo> stringEncrypterInfos = new MethodDefinitionAndDeclaringTypeDict<StringEncrypterInfo>(); MethodDefAndDeclaringTypeDict<StringEncrypterInfo> stringEncrypterInfos = new MethodDefAndDeclaringTypeDict<StringEncrypterInfo>();
Version version; Version version;
public enum Version { public enum Version {

View File

@ -25,7 +25,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.DeepSea { namespace de4dot.code.deobfuscators.DeepSea {
class ArrayBlockState { class ArrayBlockState {
ModuleDefMD module; ModuleDefMD module;
FieldDefinitionAndDeclaringTypeDict<FieldInfo> fieldToInfo = new FieldDefinitionAndDeclaringTypeDict<FieldInfo>(); FieldDefAndDeclaringTypeDict<FieldInfo> fieldToInfo = new FieldDefAndDeclaringTypeDict<FieldInfo>();
public class FieldInfo { public class FieldInfo {
public readonly FieldDef field; public readonly FieldDef field;

View File

@ -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. // DS 4.x can move fields from a class to a struct. This class restores the fields.
class FieldsRestorer { class FieldsRestorer {
ModuleDefMD module; ModuleDefMD module;
TypeDefinitionDict<List<TypeDef>> structToOwners = new TypeDefinitionDict<List<TypeDef>>(); TypeDefDict<List<TypeDef>> structToOwners = new TypeDefDict<List<TypeDef>>();
FieldDefinitionAndDeclaringTypeDict<bool> structFieldsToFix = new FieldDefinitionAndDeclaringTypeDict<bool>(); FieldDefAndDeclaringTypeDict<bool> structFieldsToFix = new FieldDefAndDeclaringTypeDict<bool>();
TypeDefinitionDict<FieldDefinitionAndDeclaringTypeDict<FieldDef>> typeToFieldsDict = new TypeDefinitionDict<FieldDefinitionAndDeclaringTypeDict<FieldDef>>(); TypeDefDict<FieldDefAndDeclaringTypeDict<FieldDef>> typeToFieldsDict = new TypeDefDict<FieldDefAndDeclaringTypeDict<FieldDef>>();
public List<TypeDef> FieldStructs { public List<TypeDef> FieldStructs {
get { get {
@ -76,7 +76,7 @@ namespace de4dot.code.deobfuscators.DeepSea {
break; break;
} }
var fieldsDict = new FieldDefinitionAndDeclaringTypeDict<FieldDef>(); var fieldsDict = new FieldDefAndDeclaringTypeDict<FieldDef>();
typeToFieldsDict.add(ownerType, fieldsDict); typeToFieldsDict.add(ownerType, fieldsDict);
foreach (var structField in structType.Fields) { foreach (var structField in structType.Fields) {
var newField = module.UpdateRowId(new FieldDefUser(structField.Name, structField.FieldSig.Clone(), structField.Attributes)); var newField = module.UpdateRowId(new FieldDefUser(structField.Name, structField.FieldSig.Clone(), structField.Attributes));
@ -144,7 +144,7 @@ namespace de4dot.code.deobfuscators.DeepSea {
} }
IEnumerable<FieldDef> getPossibleFields(TypeDef type) { IEnumerable<FieldDef> getPossibleFields(TypeDef type) {
var typeToFields = new TypeDefinitionDict<List<FieldDef>>(); var typeToFields = new TypeDefDict<List<FieldDef>>();
foreach (var field in type.Fields) { foreach (var field in type.Fields) {
if (field.Attributes != FieldAttributes.Private) if (field.Attributes != FieldAttributes.Private)
continue; continue;

View File

@ -27,7 +27,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.DeepSea { namespace de4dot.code.deobfuscators.DeepSea {
class StringDecrypter { class StringDecrypter {
ModuleDefMD module; ModuleDefMD module;
MethodDefinitionAndDeclaringTypeDict<IDecrypterInfo> methodToInfo = new MethodDefinitionAndDeclaringTypeDict<IDecrypterInfo>(); MethodDefAndDeclaringTypeDict<IDecrypterInfo> methodToInfo = new MethodDefAndDeclaringTypeDict<IDecrypterInfo>();
DecrypterVersion version = DecrypterVersion.Unknown; DecrypterVersion version = DecrypterVersion.Unknown;
public enum DecrypterVersion { public enum DecrypterVersion {
@ -45,12 +45,12 @@ namespace de4dot.code.deobfuscators.DeepSea {
} }
static short[] findKey(MethodDef initMethod, FieldDef keyField) { static short[] findKey(MethodDef initMethod, FieldDef keyField) {
var fields = new FieldDefinitionAndDeclaringTypeDict<bool>(); var fields = new FieldDefAndDeclaringTypeDict<bool>();
fields.add(keyField, true); fields.add(keyField, true);
return findKey(initMethod, fields); return findKey(initMethod, fields);
} }
static short[] findKey(MethodDef initMethod, FieldDefinitionAndDeclaringTypeDict<bool> fields) { static short[] findKey(MethodDef initMethod, FieldDefAndDeclaringTypeDict<bool> fields) {
var instrs = initMethod.Body.Instructions; var instrs = initMethod.Body.Instructions;
for (int i = 0; i < instrs.Count - 2; i++) { for (int i = 0; i < instrs.Count - 2; i++) {
var ldci4 = instrs[i]; var ldci4 = instrs[i];
@ -153,7 +153,7 @@ namespace de4dot.code.deobfuscators.DeepSea {
MethodDef cctor; MethodDef cctor;
int magic; int magic;
int arg1, arg2; int arg1, arg2;
FieldDefinitionAndDeclaringTypeDict<bool> fields; FieldDefAndDeclaringTypeDict<bool> fields;
ArrayInfo arrayInfo; ArrayInfo arrayInfo;
ushort[] encryptedData; ushort[] encryptedData;
short[] key; short[] key;
@ -206,8 +206,8 @@ namespace de4dot.code.deobfuscators.DeepSea {
return count >= 2; return count >= 2;
} }
static FieldDefinitionAndDeclaringTypeDict<bool> getFields(MethodDef method) { static FieldDefAndDeclaringTypeDict<bool> getFields(MethodDef method) {
var fields = new FieldDefinitionAndDeclaringTypeDict<bool>(); var fields = new FieldDefAndDeclaringTypeDict<bool>();
foreach (var instr in method.Body.Instructions) { foreach (var instr in method.Body.Instructions) {
if (instr.OpCode.Code != Code.Ldsfld && instr.OpCode.Code != Code.Stsfld) if (instr.OpCode.Code != Code.Ldsfld && instr.OpCode.Code != Code.Stsfld)
continue; continue;

View File

@ -229,8 +229,8 @@ namespace de4dot.code.deobfuscators {
public abstract IEnumerable<int> getStringDecrypterMethods(); public abstract IEnumerable<int> getStringDecrypterMethods();
class MethodCallRemover { class MethodCallRemover {
Dictionary<string, MethodDefinitionAndDeclaringTypeDict<bool>> methodNameInfos = new Dictionary<string, MethodDefinitionAndDeclaringTypeDict<bool>>(); Dictionary<string, MethodDefAndDeclaringTypeDict<bool>> methodNameInfos = new Dictionary<string, MethodDefAndDeclaringTypeDict<bool>>();
MethodDefinitionAndDeclaringTypeDict<MethodDefinitionAndDeclaringTypeDict<bool>> methodRefInfos = new MethodDefinitionAndDeclaringTypeDict<MethodDefinitionAndDeclaringTypeDict<bool>>(); MethodDefAndDeclaringTypeDict<MethodDefAndDeclaringTypeDict<bool>> methodRefInfos = new MethodDefAndDeclaringTypeDict<MethodDefAndDeclaringTypeDict<bool>>();
void checkMethod(IMethod methodToBeRemoved) { void checkMethod(IMethod methodToBeRemoved) {
var sig = methodToBeRemoved.MethodSig; var sig = methodToBeRemoved.MethodSig;
@ -245,9 +245,9 @@ namespace de4dot.code.deobfuscators {
return; return;
checkMethod(methodToBeRemoved); checkMethod(methodToBeRemoved);
MethodDefinitionAndDeclaringTypeDict<bool> dict; MethodDefAndDeclaringTypeDict<bool> dict;
if (!methodNameInfos.TryGetValue(method, out dict)) if (!methodNameInfos.TryGetValue(method, out dict))
methodNameInfos[method] = dict = new MethodDefinitionAndDeclaringTypeDict<bool>(); methodNameInfos[method] = dict = new MethodDefAndDeclaringTypeDict<bool>();
dict.add(methodToBeRemoved, true); dict.add(methodToBeRemoved, true);
} }
@ -258,7 +258,7 @@ namespace de4dot.code.deobfuscators {
var dict = methodRefInfos.find(method); var dict = methodRefInfos.find(method);
if (dict == null) if (dict == null)
methodRefInfos.add(method, dict = new MethodDefinitionAndDeclaringTypeDict<bool>()); methodRefInfos.add(method, dict = new MethodDefAndDeclaringTypeDict<bool>());
dict.add(methodToBeRemoved, true); dict.add(methodToBeRemoved, true);
} }
@ -270,7 +270,7 @@ namespace de4dot.code.deobfuscators {
} }
void removeAll(IList<Block> allBlocks, Blocks blocks, string method) { void removeAll(IList<Block> allBlocks, Blocks blocks, string method) {
MethodDefinitionAndDeclaringTypeDict<bool> info; MethodDefAndDeclaringTypeDict<bool> info;
if (!methodNameInfos.TryGetValue(method, out info)) if (!methodNameInfos.TryGetValue(method, out info))
return; return;
@ -285,7 +285,7 @@ namespace de4dot.code.deobfuscators {
removeCalls(allBlocks, blocks, info); removeCalls(allBlocks, blocks, info);
} }
void removeCalls(IList<Block> allBlocks, Blocks blocks, MethodDefinitionAndDeclaringTypeDict<bool> info) { void removeCalls(IList<Block> allBlocks, Blocks blocks, MethodDefAndDeclaringTypeDict<bool> info) {
var instrsToDelete = new List<int>(); var instrsToDelete = new List<int>();
foreach (var block in allBlocks) { foreach (var block in allBlocks) {
instrsToDelete.Clear(); instrsToDelete.Clear();

View File

@ -25,7 +25,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.Dotfuscator { namespace de4dot.code.deobfuscators.Dotfuscator {
class StringDecrypter { class StringDecrypter {
ModuleDefMD module; ModuleDefMD module;
MethodDefinitionAndDeclaringTypeDict<StringDecrypterInfo> stringDecrypterMethods = new MethodDefinitionAndDeclaringTypeDict<StringDecrypterInfo>(); MethodDefAndDeclaringTypeDict<StringDecrypterInfo> stringDecrypterMethods = new MethodDefAndDeclaringTypeDict<StringDecrypterInfo>();
public class StringDecrypterInfo { public class StringDecrypterInfo {
public MethodDef method; public MethodDef method;

View File

@ -24,7 +24,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators { namespace de4dot.code.deobfuscators {
class ExceptionLoggerRemover { class ExceptionLoggerRemover {
MethodDefinitionAndDeclaringTypeDict<bool> exceptionLoggerMethods = new MethodDefinitionAndDeclaringTypeDict<bool>(); MethodDefAndDeclaringTypeDict<bool> exceptionLoggerMethods = new MethodDefAndDeclaringTypeDict<bool>();
public int NumRemovedExceptionLoggers { get; set; } public int NumRemovedExceptionLoggers { get; set; }

View File

@ -32,7 +32,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
TypeDef delegateType; TypeDef delegateType;
TypeDef delegateInitType; TypeDef delegateInitType;
protected BinaryReader decryptedReader; protected BinaryReader decryptedReader;
MethodDefinitionAndDeclaringTypeDict<Info> decrypterMethods = new MethodDefinitionAndDeclaringTypeDict<Info>(); MethodDefAndDeclaringTypeDict<Info> decrypterMethods = new MethodDefAndDeclaringTypeDict<Info>();
protected class Info { protected class Info {
public MethodDef method; public MethodDef method;
@ -66,7 +66,7 @@ namespace de4dot.code.deobfuscators.Goliath_NET {
public IEnumerable<TypeDef> DecrypterTypes { public IEnumerable<TypeDef> DecrypterTypes {
get { get {
var types = new TypeDefinitionDict<TypeDef>(); var types = new TypeDefDict<TypeDef>();
foreach (var info in decrypterMethods.getValues()) { foreach (var info in decrypterMethods.getValues()) {
if (info.referenced) if (info.referenced)
types.add(info.method.DeclaringType, info.method.DeclaringType); types.add(info.method.DeclaringType, info.method.DeclaringType);

View File

@ -25,7 +25,7 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators.Goliath_NET { namespace de4dot.code.deobfuscators.Goliath_NET {
class LocalsRestorer { class LocalsRestorer {
ModuleDefMD module; ModuleDefMD module;
TypeDefinitionDict<Info> typeToInfo = new TypeDefinitionDict<Info>(); TypeDefDict<Info> typeToInfo = new TypeDefDict<Info>();
class Info { class Info {
public TypeDef type; public TypeDef type;

View File

@ -243,7 +243,7 @@ namespace de4dot.code.deobfuscators.ILProtector {
} }
static void restoreMethod(MethodDef method, MethodReader methodReader) { static void restoreMethod(MethodDef method, MethodReader methodReader) {
// body.MaxStackSize = <let Mono.Cecil calculate this> // body.MaxStackSize = <let dot10 calculate this>
method.Body.InitLocals = methodReader.InitLocals; method.Body.InitLocals = methodReader.InitLocals;
methodReader.RestoreMethod(method); methodReader.RestoreMethod(method);
} }

View File

@ -44,9 +44,9 @@ namespace de4dot.code.deobfuscators {
MemberRef createInitializeArrayMethod() { MemberRef createInitializeArrayMethod() {
if (initializeArrayMethod == null) { if (initializeArrayMethod == null) {
var runtimeHelpersType = DotNetUtils.findOrCreateTypeReference(module, module.CorLibTypes.AssemblyRef, "System.Runtime.CompilerServices", "RuntimeHelpers", false); var runtimeHelpersType = DotNetUtils.findOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System.Runtime.CompilerServices", "RuntimeHelpers", false);
var systemArrayType = DotNetUtils.findOrCreateTypeReference(module, module.CorLibTypes.AssemblyRef, "System", "Array", false); var systemArrayType = DotNetUtils.findOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System", "Array", false);
var runtimeFieldHandleType = DotNetUtils.findOrCreateTypeReference(module, module.CorLibTypes.AssemblyRef, "System", "RuntimeFieldHandle", true); var runtimeFieldHandleType = DotNetUtils.findOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System", "RuntimeFieldHandle", true);
var methodSig = MethodSig.CreateStatic(module.CorLibTypes.Void, systemArrayType, runtimeFieldHandleType); var methodSig = MethodSig.CreateStatic(module.CorLibTypes.Void, systemArrayType, runtimeFieldHandleType);
initializeArrayMethod = module.UpdateRowId(new MemberRefUser(module, "InitializeArray", methodSig, runtimeHelpersType.TypeDefOrRef)); initializeArrayMethod = module.UpdateRowId(new MemberRefUser(module, "InitializeArray", methodSig, runtimeHelpersType.TypeDefOrRef));
} }
@ -96,7 +96,7 @@ namespace de4dot.code.deobfuscators {
return arrayType; return arrayType;
if (valueType == null) 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); arrayType = new TypeDefUser("", string.Format("__StaticArrayInitTypeSize={0}", size), valueType.TypeDefOrRef);
module.UpdateRowId(arrayType); module.UpdateRowId(arrayType);
arrayType.Attributes = TypeAttributes.NestedPrivate | TypeAttributes.ExplicitLayout | arrayType.Attributes = TypeAttributes.NestedPrivate | TypeAttributes.ExplicitLayout |

View File

@ -23,11 +23,11 @@ using dot10.DotNet;
using de4dot.blocks; using de4dot.blocks;
namespace de4dot.code.deobfuscators { namespace de4dot.code.deobfuscators {
class MemberReferenceBuilder { class MemberRefBuilder {
ModuleDefMD module; ModuleDefMD module;
Dictionary<TypeSig, TypeSig> createdTypes = new Dictionary<TypeSig, TypeSig>(TypeEqualityComparer.Instance); Dictionary<TypeSig, TypeSig> createdTypes = new Dictionary<TypeSig, TypeSig>(TypeEqualityComparer.Instance);
public MemberReferenceBuilder(ModuleDefMD module) { public MemberRefBuilder(ModuleDefMD module) {
this.module = module; this.module = module;
} }
@ -108,7 +108,7 @@ namespace de4dot.code.deobfuscators {
} }
public ClassSig type(string ns, string name, string asmSimpleName) { 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) { public ClassSig type(string ns, string name) {
@ -120,7 +120,7 @@ namespace de4dot.code.deobfuscators {
} }
public ValueTypeSig valueType(string ns, string name, string asmSimpleName) { 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) { public ValueTypeSig valueType(string ns, string name) {
@ -173,7 +173,7 @@ namespace de4dot.code.deobfuscators {
return module.UpdateRowId(new MemberRefUser(module, name, sig, declaringType)); return module.UpdateRowId(new MemberRefUser(module, name, sig, declaringType));
} }
AssemblyRef findAssemblyReference(string asmSimpleName) { AssemblyRef findAssemblyRef(string asmSimpleName) {
var asmRef = module.GetAssemblyRef(asmSimpleName); var asmRef = module.GetAssemblyRef(asmSimpleName);
if (asmRef == null) if (asmRef == null)
throw new ApplicationException(string.Format("Could not find assembly {0} in assembly references", asmSimpleName)); throw new ApplicationException(string.Format("Could not find assembly {0} in assembly references", asmSimpleName));

View File

@ -24,9 +24,9 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators { namespace de4dot.code.deobfuscators {
class MethodCallRestorerBase { class MethodCallRestorerBase {
protected MemberReferenceBuilder builder; protected MemberRefBuilder builder;
protected ModuleDefMD module; protected ModuleDefMD module;
MethodDefinitionAndDeclaringTypeDict<NewMethodInfo> oldToNewMethod = new MethodDefinitionAndDeclaringTypeDict<NewMethodInfo>(); MethodDefAndDeclaringTypeDict<NewMethodInfo> oldToNewMethod = new MethodDefAndDeclaringTypeDict<NewMethodInfo>();
class NewMethodInfo { class NewMethodInfo {
public OpCode opCode; public OpCode opCode;
@ -40,7 +40,7 @@ namespace de4dot.code.deobfuscators {
public MethodCallRestorerBase(ModuleDefMD module) { public MethodCallRestorerBase(ModuleDefMD module) {
this.module = module; this.module = module;
this.builder = new MemberReferenceBuilder(module); this.builder = new MemberRefBuilder(module);
} }
public void createGetManifestResourceStream1(MethodDef oldMethod) { public void createGetManifestResourceStream1(MethodDef oldMethod) {

View File

@ -23,8 +23,8 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators { namespace de4dot.code.deobfuscators {
class MethodCollection { class MethodCollection {
TypeDefinitionDict<bool> types = new TypeDefinitionDict<bool>(); TypeDefDict<bool> types = new TypeDefDict<bool>();
MethodDefinitionAndDeclaringTypeDict<bool> methods = new MethodDefinitionAndDeclaringTypeDict<bool>(); MethodDefAndDeclaringTypeDict<bool> methods = new MethodDefAndDeclaringTypeDict<bool>();
public bool exists(IMethod method) { public bool exists(IMethod method) {
if (method == null) if (method == null)

View File

@ -257,12 +257,12 @@ namespace de4dot.code.deobfuscators {
local = pushInstr.Operand as Local; local = pushInstr.Operand as Local;
if (local == null) if (local == null)
return null; return null;
type = createByReferenceType(local.Type.RemovePinned()); type = createByRefType(local.Type.RemovePinned());
break; break;
case Code.Ldarga: case Code.Ldarga:
case Code.Ldarga_S: case Code.Ldarga_S:
type = createByReferenceType(pushInstr.GetArgumentType(method.MethodSig, method.DeclaringType)); type = createByRefType(pushInstr.GetArgumentType(method.MethodSig, method.DeclaringType));
break; break;
case Code.Ldfld: case Code.Ldfld:
@ -278,12 +278,12 @@ namespace de4dot.code.deobfuscators {
var field2 = pushInstr.Operand as IField; var field2 = pushInstr.Operand as IField;
if (field2 == null || field2.FieldSig == null) if (field2 == null || field2.FieldSig == null)
return null; return null;
type = createByReferenceType(field2.FieldSig.GetFieldType()); type = createByRefType(field2.FieldSig.GetFieldType());
break; break;
case Code.Ldelema: case Code.Ldelema:
case Code.Unbox: case Code.Unbox:
type = createByReferenceType(pushInstr.Operand as ITypeDefOrRef); type = createByRefType(pushInstr.Operand as ITypeDefOrRef);
break; break;
default: default:
@ -293,13 +293,13 @@ namespace de4dot.code.deobfuscators {
return type; return type;
} }
static ByRefSig createByReferenceType(ITypeDefOrRef elementType) { static ByRefSig createByRefType(ITypeDefOrRef elementType) {
if (elementType == null) if (elementType == null)
return null; return null;
return new ByRefSig(elementType.ToTypeSig()); return new ByRefSig(elementType.ToTypeSig());
} }
static ByRefSig createByReferenceType(TypeSig elementType) { static ByRefSig createByRefType(TypeSig elementType) {
if (elementType == null) if (elementType == null)
return null; return null;
return new ByRefSig(elementType); return new ByRefSig(elementType);

View File

@ -181,7 +181,7 @@ namespace de4dot.code.deobfuscators {
// ...push args... // ...push args...
// call Invoke // call Invoke
abstract class ProxyCallFixer1 : ProxyCallFixerBase { abstract class ProxyCallFixer1 : ProxyCallFixerBase {
FieldDefinitionAndDeclaringTypeDict<DelegateInfo> fieldToDelegateInfo = new FieldDefinitionAndDeclaringTypeDict<DelegateInfo>(); FieldDefAndDeclaringTypeDict<DelegateInfo> fieldToDelegateInfo = new FieldDefAndDeclaringTypeDict<DelegateInfo>();
protected ProxyCallFixer1(ModuleDefMD module) protected ProxyCallFixer1(ModuleDefMD module)
: base(module) { : base(module) {
@ -369,7 +369,7 @@ namespace de4dot.code.deobfuscators {
// ...push args... // ...push args...
// call static method // call static method
abstract class ProxyCallFixer2 : ProxyCallFixerBase { abstract class ProxyCallFixer2 : ProxyCallFixerBase {
MethodDefinitionAndDeclaringTypeDict<DelegateInfo> proxyMethodToDelegateInfo = new MethodDefinitionAndDeclaringTypeDict<DelegateInfo>(); MethodDefAndDeclaringTypeDict<DelegateInfo> proxyMethodToDelegateInfo = new MethodDefAndDeclaringTypeDict<DelegateInfo>();
protected ProxyCallFixer2(ModuleDefMD module) protected ProxyCallFixer2(ModuleDefMD module)
: base(module) { : base(module) {

View File

@ -29,7 +29,7 @@ namespace de4dot.code.deobfuscators.Rummage {
class StringDecrypter { class StringDecrypter {
ModuleDefMD module; ModuleDefMD module;
MethodDef stringDecrypterMethod; MethodDef stringDecrypterMethod;
FieldDefinitionAndDeclaringTypeDict<StringInfo> stringInfos = new FieldDefinitionAndDeclaringTypeDict<StringInfo>(); FieldDefAndDeclaringTypeDict<StringInfo> stringInfos = new FieldDefAndDeclaringTypeDict<StringInfo>();
int fileDispl; int fileDispl;
uint[] key; uint[] key;
BinaryReader reader; BinaryReader reader;

View File

@ -85,11 +85,11 @@ namespace de4dot.code.deobfuscators.Skater_NET {
protected override void scanForObfuscator() { protected override void scanForObfuscator() {
stringDecrypter = new StringDecrypter(module); stringDecrypter = new StringDecrypter(module);
if (hasAssemblyReference("Microsoft.VisualBasic")) if (hasAssemblyRef("Microsoft.VisualBasic"))
stringDecrypter.find(); stringDecrypter.find();
} }
bool hasAssemblyReference(string name) { bool hasAssemblyRef(string name) {
foreach (var asmRef in module.GetAssemblyRefs()) { foreach (var asmRef in module.GetAssemblyRefs()) {
if (asmRef.Name == name) if (asmRef.Name == name)
return true; return true;

View File

@ -32,7 +32,7 @@ namespace de4dot.code.deobfuscators.Skater_NET {
ModuleDefMD module; ModuleDefMD module;
TypeDef decrypterType; TypeDef decrypterType;
MethodDef decrypterCctor; MethodDef decrypterCctor;
FieldDefinitionAndDeclaringTypeDict<string> fieldToDecryptedString = new FieldDefinitionAndDeclaringTypeDict<string>(); FieldDefAndDeclaringTypeDict<string> fieldToDecryptedString = new FieldDefAndDeclaringTypeDict<string>();
bool canRemoveType; bool canRemoveType;
IDecrypter decrypter; IDecrypter decrypter;

View File

@ -416,8 +416,8 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
if (decrypter.CanDecrypt) { if (decrypter.CanDecrypt) {
var invokeMethod = info.GetStringDelegate == null ? null : info.GetStringDelegate.FindMethod("Invoke"); var invokeMethod = info.GetStringDelegate == null ? null : info.GetStringDelegate.FindMethod("Invoke");
staticStringInliner.add(invokeMethod, (method, gim, args) => { staticStringInliner.add(invokeMethod, (method, gim, args) => {
var fieldDefinition = DotNetUtils.getField(module, (IField)args[0]); var fieldDef = DotNetUtils.getField(module, (IField)args[0]);
return decrypter.decrypt(fieldDefinition.MDToken.ToInt32(), (int)args[1]); return decrypter.decrypt(fieldDef.MDToken.ToInt32(), (int)args[1]);
}); });
staticStringInliner.add(info.StringDecrypterMethod, (method, gim, args) => { staticStringInliner.add(info.StringDecrypterMethod, (method, gim, args) => {
return decrypter.decrypt(0, (int)args[0]); return decrypter.decrypt(0, (int)args[0]);

View File

@ -217,7 +217,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
// Find the string decrypter string offset value or null if none found // Find the string decrypter string offset value or null if none found
int? findOffsetValue(MethodDef method) { int? findOffsetValue(MethodDef method) {
var fieldDict = new FieldDefinitionAndDeclaringTypeDict<IField>(); var fieldDict = new FieldDefAndDeclaringTypeDict<IField>();
foreach (var field in method.DeclaringType.Fields) foreach (var field in method.DeclaringType.Fields)
fieldDict.add(field, field); fieldDict.add(field, field);
@ -253,7 +253,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
return null; return null;
} }
int? findOffsetValue(MethodDef method, FieldDef offsetField, FieldDefinitionAndDeclaringTypeDict<IField> fields) { int? findOffsetValue(MethodDef method, FieldDef offsetField, FieldDefAndDeclaringTypeDict<IField> fields) {
var instructions = method.Body.Instructions; var instructions = method.Body.Instructions;
for (int i = 0; i <= instructions.Count - 2; i++) { for (int i = 0; i <= instructions.Count - 2; i++) {
var ldstr = instructions[i]; var ldstr = instructions[i];

View File

@ -48,8 +48,8 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
this.simpleDeobfuscator = simpleDeobfuscator; this.simpleDeobfuscator = simpleDeobfuscator;
} }
TypeDef getType(ITypeDefOrRef typeReference) { TypeDef getType(ITypeDefOrRef typeRef) {
return DotNetUtils.getType(module, typeReference); return DotNetUtils.getType(module, typeRef);
} }
public void find() { public void find() {

View File

@ -27,8 +27,8 @@ namespace de4dot.code.deobfuscators.Spices_Net {
ModuleDefMD module; ModuleDefMD module;
TypeDef resourceManagerType; TypeDef resourceManagerType;
TypeDef componentResourceManagerType; TypeDef componentResourceManagerType;
MethodDefinitionAndDeclaringTypeDict<IMethod> resourceManagerCtors = new MethodDefinitionAndDeclaringTypeDict<IMethod>(); MethodDefAndDeclaringTypeDict<IMethod> resourceManagerCtors = new MethodDefAndDeclaringTypeDict<IMethod>();
MethodDefinitionAndDeclaringTypeDict<IMethod> componentManagerCtors = new MethodDefinitionAndDeclaringTypeDict<IMethod>(); MethodDefAndDeclaringTypeDict<IMethod> componentManagerCtors = new MethodDefAndDeclaringTypeDict<IMethod>();
public TypeDef ResourceManagerType { public TypeDef ResourceManagerType {
get { return resourceManagerType; } get { return resourceManagerType; }
@ -54,7 +54,7 @@ namespace de4dot.code.deobfuscators.Spices_Net {
initializeCtors(componentResourceManagerType, componentManagerCtors); initializeCtors(componentResourceManagerType, componentManagerCtors);
} }
void initializeCtors(TypeDef manager, MethodDefinitionAndDeclaringTypeDict<IMethod> ctors) { void initializeCtors(TypeDef manager, MethodDefAndDeclaringTypeDict<IMethod> ctors) {
if (manager == null) if (manager == null)
return; return;

View File

@ -26,8 +26,8 @@ using de4dot.blocks.cflow;
namespace de4dot.code.deobfuscators.Spices_Net { namespace de4dot.code.deobfuscators.Spices_Net {
class SpicesMethodCallInliner : MethodCallInliner { class SpicesMethodCallInliner : MethodCallInliner {
ModuleDefMD module; ModuleDefMD module;
TypeDefinitionDict<bool> methodsTypes = new TypeDefinitionDict<bool>(); TypeDefDict<bool> methodsTypes = new TypeDefDict<bool>();
MethodDefinitionAndDeclaringTypeDict<MethodDef> classMethods = new MethodDefinitionAndDeclaringTypeDict<MethodDef>(); MethodDefAndDeclaringTypeDict<MethodDef> classMethods = new MethodDefAndDeclaringTypeDict<MethodDef>();
public SpicesMethodCallInliner(ModuleDefMD module) public SpicesMethodCallInliner(ModuleDefMD module)
: base(false) { : base(false) {
@ -58,7 +58,7 @@ namespace de4dot.code.deobfuscators.Spices_Net {
} }
void restoreMethodBodies() { void restoreMethodBodies() {
var methodToOrigMethods = new MethodDefinitionAndDeclaringTypeDict<List<MethodDef>>(); var methodToOrigMethods = new MethodDefAndDeclaringTypeDict<List<MethodDef>>();
foreach (var t in module.Types) { foreach (var t in module.Types) {
var types = new List<TypeDef>(AllTypesHelper.Types(new List<TypeDef> { t })); var types = new List<TypeDef>(AllTypesHelper.Types(new List<TypeDef> { t }));
foreach (var type in types) { foreach (var type in types) {
@ -207,12 +207,12 @@ namespace de4dot.code.deobfuscators.Spices_Net {
return list; return list;
} }
public TypeDefinitionDict<bool> getInlinedTypes(IEnumerable<MethodDef> unusedMethods) { public TypeDefDict<bool> getInlinedTypes(IEnumerable<MethodDef> unusedMethods) {
var unused = new MethodDefinitionAndDeclaringTypeDict<bool>(); var unused = new MethodDefAndDeclaringTypeDict<bool>();
foreach (var method in unusedMethods) foreach (var method in unusedMethods)
unused.add(method, true); unused.add(method, true);
var types = new TypeDefinitionDict<bool>(); var types = new TypeDefDict<bool>();
foreach (var type in methodsTypes.getKeys()) { foreach (var type in methodsTypes.getKeys()) {
if (checkAllMethodsUnused(unused, type)) if (checkAllMethodsUnused(unused, type))
types.add(type, true); types.add(type, true);
@ -220,7 +220,7 @@ namespace de4dot.code.deobfuscators.Spices_Net {
return types; return types;
} }
static bool checkAllMethodsUnused(MethodDefinitionAndDeclaringTypeDict<bool> unused, TypeDef type) { static bool checkAllMethodsUnused(MethodDefAndDeclaringTypeDict<bool> unused, TypeDef type) {
foreach (var method in type.Methods) { foreach (var method in type.Methods) {
if (!unused.find(method)) if (!unused.find(method))
return false; return false;

View File

@ -30,7 +30,7 @@ namespace de4dot.code.deobfuscators.Spices_Net {
TypeDef decrypterType; TypeDef decrypterType;
FieldDef encryptedDataField; FieldDef encryptedDataField;
StringDataFlags stringDataFlags; StringDataFlags stringDataFlags;
MethodDefinitionAndDeclaringTypeDict<DecrypterInfo> methodToInfo = new MethodDefinitionAndDeclaringTypeDict<DecrypterInfo>(); MethodDefAndDeclaringTypeDict<DecrypterInfo> methodToInfo = new MethodDefAndDeclaringTypeDict<DecrypterInfo>();
byte[] decryptedData; byte[] decryptedData;
byte[] key; byte[] key;
byte[] iv; byte[] iv;

View File

@ -25,15 +25,15 @@ using de4dot.blocks;
namespace de4dot.code.deobfuscators { namespace de4dot.code.deobfuscators {
abstract class ValueInlinerBase<TValue> : MethodReturnValueInliner { abstract class ValueInlinerBase<TValue> : MethodReturnValueInliner {
MethodDefinitionAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>> decrypterMethods = new MethodDefinitionAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>>(); MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>> decrypterMethods = new MethodDefAndDeclaringTypeDict<Func<MethodDef, MethodSpec, object[], object>>();
bool removeUnbox = false; bool removeUnbox = false;
class MyCallResult : CallResult { class MyCallResult : CallResult {
public IMethod methodReference; public IMethod methodRef;
public MethodSpec gim; public MethodSpec gim;
public MyCallResult(Block block, int callEndIndex, IMethod method, MethodSpec gim) public MyCallResult(Block block, int callEndIndex, IMethod method, MethodSpec gim)
: base(block, callEndIndex) { : base(block, callEndIndex) {
this.methodReference = method; this.methodRef = method;
this.gim = gim; this.gim = gim;
} }
} }
@ -63,8 +63,8 @@ namespace de4dot.code.deobfuscators {
protected override void inlineAllCalls() { protected override void inlineAllCalls() {
foreach (var tmp in callResults) { foreach (var tmp in callResults) {
var callResult = (MyCallResult)tmp; var callResult = (MyCallResult)tmp;
var handler = decrypterMethods.find(callResult.methodReference); var handler = decrypterMethods.find(callResult.methodRef);
callResult.returnValue = handler((MethodDef)callResult.methodReference, callResult.gim, callResult.args); callResult.returnValue = handler((MethodDef)callResult.methodRef, callResult.gim, callResult.args);
} }
} }

View File

@ -31,7 +31,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v3 {
MethodDef stringDecrypter1; MethodDef stringDecrypter1;
MethodDef stringDecrypter2; MethodDef stringDecrypter2;
List<MethodDef> initMethods = new List<MethodDef>(); List<MethodDef> initMethods = new List<MethodDef>();
List<ModuleRef> moduleReferences = new List<ModuleRef>(); List<ModuleRef> moduleRefs = new List<ModuleRef>();
Resource linkedResource; Resource linkedResource;
public bool Detected { public bool Detected {
@ -78,7 +78,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v3 {
this.stringDecrypter2 = lookup(oldOne.stringDecrypter2, "Could not find stringDecrypter2"); this.stringDecrypter2 = lookup(oldOne.stringDecrypter2, "Could not find stringDecrypter2");
foreach (var method in oldOne.initMethods) foreach (var method in oldOne.initMethods)
initMethods.Add(lookup(method, "Could not find initMethod")); initMethods.Add(lookup(method, "Could not find initMethod"));
updateModuleReferences(); updateModuleRefs();
} }
T lookup<T>(T def, string errorMessage) where T : class, ICodedToken { T lookup<T>(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", "()")) if (DotNetUtils.isMethod(method, "System.Void", "()"))
initMethods.Add(method); initMethods.Add(method);
} }
updateModuleReferences(); updateModuleRefs();
return; return;
} }
} }
void updateModuleReferences() { void updateModuleRefs() {
foreach (var method in decrypterType.Methods) { foreach (var method in decrypterType.Methods) {
if (method.ImplMap != null) { if (method.ImplMap != null) {
switch (method.ImplMap.Name.String) { switch (method.ImplMap.Name.String) {
case "nr_nli": case "nr_nli":
case "nr_startup": case "nr_startup":
moduleReferences.Add(method.ImplMap.Module); moduleRefs.Add(method.ImplMap.Module);
break; break;
} }
} }
@ -117,7 +117,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v3 {
} }
void updateLinkedResource() { void updateLinkedResource() {
foreach (var modref in moduleReferences) { foreach (var modref in moduleRefs) {
var resource = DotNetUtils.getResource(module, modref.Name.String) as LinkedResource; var resource = DotNetUtils.getResource(module, modref.Name.String) as LinkedResource;
if (resource == null) if (resource == null)
continue; continue;

View File

@ -31,9 +31,9 @@ namespace de4dot.code.renamer {
public MemberInfo(Ref memberRef) { public MemberInfo(Ref memberRef) {
this.memberRef = memberRef; this.memberRef = memberRef;
oldFullName = memberRef.memberReference.FullName; oldFullName = memberRef.memberRef.FullName;
oldName = memberRef.memberReference.Name.String; oldName = memberRef.memberRef.Name.String;
newName = memberRef.memberReference.Name.String; newName = memberRef.memberRef.Name.String;
} }
public void rename(string newTypeName) { public void rename(string newTypeName) {
@ -91,8 +91,8 @@ namespace de4dot.code.renamer {
public ParamInfo(MParamDef paramDef) { public ParamInfo(MParamDef paramDef) {
this.paramDef = paramDef; this.paramDef = paramDef;
this.oldName = paramDef.ParameterDefinition.Name; this.oldName = paramDef.ParameterDef.Name;
this.newName = paramDef.ParameterDefinition.Name; this.newName = paramDef.ParameterDef.Name;
} }
public bool gotNewName() { public bool gotNewName() {

View File

@ -107,7 +107,7 @@ namespace de4dot.code.renamer {
} }
interface ITypeNameCreator { interface ITypeNameCreator {
string create(TypeDef typeDefinition, string newBaseTypeName); string create(TypeDef typeDef, string newBaseTypeName);
} }
class NameInfos { class NameInfos {
@ -172,26 +172,26 @@ namespace de4dot.code.renamer {
return new NameCreator(prefix); return new NameCreator(prefix);
} }
public string create(TypeDef typeDefinition, string newBaseTypeName) { public string create(TypeDef typeDef, string newBaseTypeName) {
var nameCreator = getNameCreator(typeDefinition, newBaseTypeName); var nameCreator = getNameCreator(typeDef, newBaseTypeName);
return existingNames.getName(typeDefinition.Name.String, nameCreator); return existingNames.getName(typeDef.Name.String, nameCreator);
} }
NameCreator getNameCreator(TypeDef typeDefinition, string newBaseTypeName) { NameCreator getNameCreator(TypeDef typeDef, string newBaseTypeName) {
var nameCreator = createUnknownTypeName; var nameCreator = createUnknownTypeName;
if (typeDefinition.IsEnum) if (typeDef.IsEnum)
nameCreator = createEnumName; nameCreator = createEnumName;
else if (typeDefinition.IsValueType) else if (typeDef.IsValueType)
nameCreator = createStructName; nameCreator = createStructName;
else if (typeDefinition.IsClass) { else if (typeDef.IsClass) {
if (typeDefinition.BaseType != null) { if (typeDef.BaseType != null) {
var fn = typeDefinition.BaseType.FullName; var fn = typeDef.BaseType.FullName;
if (fn == "System.Delegate") if (fn == "System.Delegate")
nameCreator = createDelegateName; nameCreator = createDelegateName;
else if (fn == "System.MulticastDelegate") else if (fn == "System.MulticastDelegate")
nameCreator = createDelegateName; nameCreator = createDelegateName;
else { else {
nameCreator = nameInfos.find(newBaseTypeName ?? typeDefinition.BaseType.Name.String); nameCreator = nameInfos.find(newBaseTypeName ?? typeDef.BaseType.Name.String);
if (nameCreator == null) if (nameCreator == null)
nameCreator = createClassName; nameCreator = createClassName;
} }
@ -199,7 +199,7 @@ namespace de4dot.code.renamer {
else else
nameCreator = createClassName; nameCreator = createClassName;
} }
else if (typeDefinition.IsInterface) else if (typeDef.IsInterface)
nameCreator = createInterfaceName; nameCreator = createInterfaceName;
return nameCreator; return nameCreator;
} }

View File

@ -83,13 +83,13 @@ namespace de4dot.code.renamer {
renameResourceKeys(); renameResourceKeys();
var groups = modules.initializeVirtualMembers(); var groups = modules.initializeVirtualMembers();
memberInfos.initialize(modules); memberInfos.initialize(modules);
renameTypeDefinitions(); renameTypeDefs();
renameTypeReferences(); renameTypeRefs();
modules.onTypesRenamed(); modules.onTypesRenamed();
restorePropertiesAndEvents(groups); restorePropertiesAndEvents(groups);
prepareRenameMemberDefinitions(groups); prepareRenameMemberDefs(groups);
renameMemberDefinitions(); renameMemberDefs();
renameMemberReferences(); renameMemberRefs();
removeUselessOverrides(groups); removeUselessOverrides(groups);
renameResources(); renameResources();
modules.cleanUp(); modules.cleanUp();
@ -127,7 +127,7 @@ namespace de4dot.code.renamer {
} }
} }
void renameTypeDefinitions() { void renameTypeDefs() {
if (isVerbose) if (isVerbose)
Logger.v("Renaming obfuscated type definitions"); Logger.v("Renaming obfuscated type definitions");
@ -141,7 +141,7 @@ namespace de4dot.code.renamer {
state.addTypeName(memberInfos.type(type).oldName); state.addTypeName(memberInfos.type(type).oldName);
prepareRenameTypes(modules.BaseTypes, state); prepareRenameTypes(modules.BaseTypes, state);
fixClsTypeNames(); fixClsTypeNames();
renameTypeDefinitions(modules.NonNestedTypes); renameTypeDefs(modules.NonNestedTypes);
} }
void removeOneClassNamespaces(Module module) { void removeOneClassNamespaces(Module module) {
@ -174,37 +174,37 @@ namespace de4dot.code.renamer {
} }
} }
void renameTypeDefinitions(IEnumerable<MTypeDef> typeDefs) { void renameTypeDefs(IEnumerable<MTypeDef> typeDefs) {
Logger.Instance.indent(); Logger.Instance.indent();
foreach (var typeDef in typeDefs) { foreach (var typeDef in typeDefs) {
rename(typeDef); rename(typeDef);
renameTypeDefinitions(typeDef.NestedTypes); renameTypeDefs(typeDef.NestedTypes);
} }
Logger.Instance.deIndent(); Logger.Instance.deIndent();
} }
void rename(MTypeDef type) { void rename(MTypeDef type) {
var typeDefinition = type.TypeDef; var typeDef = type.TypeDef;
var info = memberInfos.type(type); var info = memberInfos.type(type);
if (isVerbose) 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(); Logger.Instance.indent();
renameGenericParams(type.GenericParams); renameGenericParams(type.GenericParams);
if (RenameTypes && info.gotNewName()) { if (RenameTypes && info.gotNewName()) {
var old = typeDefinition.Name; var old = typeDef.Name;
typeDefinition.Name = new UTF8String(info.newName); typeDef.Name = new UTF8String(info.newName);
if (isVerbose) 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) { if (RenameNamespaces && info.newNamespace != null) {
var old = typeDefinition.Namespace; var old = typeDef.Namespace;
typeDefinition.Namespace = new UTF8String(info.newNamespace); typeDef.Namespace = new UTF8String(info.newNamespace);
if (isVerbose) 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(); Logger.Instance.deIndent();
@ -223,7 +223,7 @@ namespace de4dot.code.renamer {
} }
} }
void renameMemberDefinitions() { void renameMemberDefs() {
if (isVerbose) if (isVerbose)
Logger.v("Renaming member definitions #2"); Logger.v("Renaming member definitions #2");
@ -321,13 +321,13 @@ namespace de4dot.code.renamer {
var paramInfo = memberInfos.param(param); var paramInfo = memberInfos.param(param);
if (!paramInfo.gotNewName()) if (!paramInfo.gotNewName())
continue; continue;
param.ParameterDefinition.CreateParamDef(); param.ParameterDef.CreateParamDef();
param.ParameterDefinition.Name = paramInfo.newName; param.ParameterDef.Name = paramInfo.newName;
if (isVerbose) { if (isVerbose) {
if (param.IsReturnParameter) if (param.IsReturnParameter)
Logger.v("RetParam: {0} => {1}", Utils.removeNewlines(paramInfo.oldName), Utils.removeNewlines(paramInfo.newName)); Logger.v("RetParam: {0} => {1}", Utils.removeNewlines(paramInfo.oldName), Utils.removeNewlines(paramInfo.newName));
else 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) if (isVerbose)
Logger.v("Renaming references to other definitions"); Logger.v("Renaming references to other definitions");
foreach (var module in modules.TheModules) { foreach (var module in modules.TheModules) {
@ -347,9 +347,9 @@ namespace de4dot.code.renamer {
refToDef.reference.Name = refToDef.definition.Name; refToDef.reference.Name = refToDef.definition.Name;
foreach (var refToDef in module.FieldRefsToRename) foreach (var refToDef in module.FieldRefsToRename)
refToDef.reference.Name = refToDef.definition.Name; 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; 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; info.cattr.NamedArguments[info.index].Name = info.reference.Name;
Logger.Instance.deIndent(); Logger.Instance.deIndent();
} }
@ -405,7 +405,7 @@ namespace de4dot.code.renamer {
} }
} }
void renameTypeReferences() { void renameTypeRefs() {
if (isVerbose) if (isVerbose)
Logger.v("Renaming references to type definitions"); Logger.v("Renaming references to type definitions");
var theModules = modules.TheModules; var theModules = modules.TheModules;
@ -891,7 +891,7 @@ namespace de4dot.code.renamer {
return eventDef; return eventDef;
} }
void prepareRenameMemberDefinitions(MethodNameGroups groups) { void prepareRenameMemberDefs(MethodNameGroups groups) {
if (isVerbose) if (isVerbose)
Logger.v("Renaming member definitions #1"); Logger.v("Renaming member definitions #1");
@ -987,7 +987,7 @@ namespace de4dot.code.renamer {
foreach (var method in methods) { foreach (var method in methods) {
var nameChecker = !method.Owner.HasModule ? null : method.Owner.Module.ObfuscatedFile.NameChecker; var nameChecker = !method.Owner.HasModule ? null : method.Owner.Module.ObfuscatedFile.NameChecker;
for (int i = 0; i < argNames.Length; i++) { 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)) if (nameChecker == null || nameChecker.isValidMethodArgName(argName))
argNames[i] = argName; argNames[i] = argName;
} }
@ -1416,7 +1416,7 @@ namespace de4dot.code.renamer {
foreach (var propMethod in group.Methods) { foreach (var propMethod in group.Methods) {
TypeSig propType; TypeSig propType;
if (methodType == PropertyMethodType.Setter) if (methodType == PropertyMethodType.Setter)
propType = propMethod.ParamDefs[propMethod.ParamDefs.Count - 1].ParameterDefinition.Type; propType = propMethod.ParamDefs[propMethod.ParamDefs.Count - 1].ParameterDef.Type;
else else
propType = propMethod.MethodDef.MethodSig.GetRetType(); propType = propMethod.MethodDef.MethodSig.GetRetType();
if (type == null) if (type == null)
@ -1613,7 +1613,7 @@ namespace de4dot.code.renamer {
memberInfos.method(methodDef).suggestedName = "Main"; memberInfos.method(methodDef).suggestedName = "Main";
if (methodDef.ParamDefs.Count == 1) { if (methodDef.ParamDefs.Count == 1) {
var paramDef = methodDef.ParamDefs[0]; var paramDef = methodDef.ParamDefs[0];
var type = paramDef.ParameterDefinition.Type; var type = paramDef.ParameterDef.Type;
if (type.FullName == "System.String[]") if (type.FullName == "System.String[]")
memberInfos.param(paramDef).newName = "args"; memberInfos.param(paramDef).newName = "args";
} }

View File

@ -315,7 +315,7 @@ namespace de4dot.code.renamer {
if (info.gotNewName()) if (info.gotNewName())
continue; continue;
if (!checker.isValidMethodArgName(info.oldName)) 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 (!NameChecker.isValidMethodReturnArgName(info.oldName)) {
if (newVariableNameState == null) if (newVariableNameState == null)
newVariableNameState = variableNameState.cloneParamsOnly(); 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() { void initializeWindowsFormsFieldsAndProps() {
var checker = NameChecker; var checker = NameChecker;
var ourFields = new FieldDefinitionAndDeclaringTypeDict<MFieldDef>(); var ourFields = new FieldDefAndDeclaringTypeDict<MFieldDef>();
foreach (var fieldDef in type.AllFields) foreach (var fieldDef in type.AllFields)
ourFields.add(fieldDef.FieldDef, fieldDef); ourFields.add(fieldDef.FieldDef, fieldDef);
var ourMethods = new MethodDefinitionAndDeclaringTypeDict<MMethodDef>(); var ourMethods = new MethodDefAndDeclaringTypeDict<MMethodDef>();
foreach (var methodDef in type.AllMethods) foreach (var methodDef in type.AllMethods)
ourMethods.add(methodDef.MethodDef, methodDef); ourMethods.add(methodDef.MethodDef, methodDef);
@ -487,7 +487,7 @@ namespace de4dot.code.renamer {
var calledMethodDef = ourMethods.find(calledMethod); var calledMethodDef = ourMethods.find(calledMethod);
if (calledMethodDef == null) if (calledMethodDef == null)
continue; continue;
fieldRef = getFieldReference(calledMethodDef.MethodDef); fieldRef = getFieldRef(calledMethodDef.MethodDef);
var propDef = calledMethodDef.Property; var propDef = calledMethodDef.Property;
if (propDef == null) 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) if (method == null || method.Body == null)
return null; return null;
var instructions = method.Body.Instructions; var instructions = method.Body.Instructions;
@ -544,10 +544,10 @@ namespace de4dot.code.renamer {
} }
public void initializeEventHandlerNames() { public void initializeEventHandlerNames() {
var ourFields = new FieldDefinitionAndDeclaringTypeDict<MFieldDef>(); var ourFields = new FieldDefAndDeclaringTypeDict<MFieldDef>();
foreach (var fieldDef in type.AllFields) foreach (var fieldDef in type.AllFields)
ourFields.add(fieldDef.FieldDef, fieldDef); ourFields.add(fieldDef.FieldDef, fieldDef);
var ourMethods = new MethodDefinitionAndDeclaringTypeDict<MMethodDef>(); var ourMethods = new MethodDefAndDeclaringTypeDict<MMethodDef>();
foreach (var methodDef in type.AllMethods) foreach (var methodDef in type.AllMethods)
ourMethods.add(methodDef.MethodDef, methodDef); 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 // 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. // from the previous control, and then adds the handler to the new control.
void initVbEventHandlers(FieldDefinitionAndDeclaringTypeDict<MFieldDef> ourFields, MethodDefinitionAndDeclaringTypeDict<MMethodDef> ourMethods) { void initVbEventHandlers(FieldDefAndDeclaringTypeDict<MFieldDef> ourFields, MethodDefAndDeclaringTypeDict<MMethodDef> ourMethods) {
var checker = NameChecker; var checker = NameChecker;
foreach (var propDef in type.AllProperties) { foreach (var propDef in type.AllProperties) {
@ -675,7 +675,7 @@ namespace de4dot.code.renamer {
return -1; return -1;
} }
void initFieldEventHandlers(FieldDefinitionAndDeclaringTypeDict<MFieldDef> ourFields, MethodDefinitionAndDeclaringTypeDict<MMethodDef> ourMethods) { void initFieldEventHandlers(FieldDefAndDeclaringTypeDict<MFieldDef> ourFields, MethodDefAndDeclaringTypeDict<MMethodDef> ourMethods) {
var checker = NameChecker; var checker = NameChecker;
foreach (var methodDef in type.AllMethods) { foreach (var methodDef in type.AllMethods) {
@ -754,7 +754,7 @@ namespace de4dot.code.renamer {
} }
} }
void initTypeEventHandlers(FieldDefinitionAndDeclaringTypeDict<MFieldDef> ourFields, MethodDefinitionAndDeclaringTypeDict<MMethodDef> ourMethods) { void initTypeEventHandlers(FieldDefAndDeclaringTypeDict<MFieldDef> ourFields, MethodDefAndDeclaringTypeDict<MMethodDef> ourMethods) {
var checker = NameChecker; var checker = NameChecker;
foreach (var methodDef in type.AllMethods) { foreach (var methodDef in type.AllMethods) {

View File

@ -86,13 +86,13 @@ namespace de4dot.code.renamer {
existingEventNames.merge(other.existingEventNames); existingEventNames.merge(other.existingEventNames);
} }
public string getNewPropertyName(PropertyDef propertyDefinition) { public string getNewPropertyName(PropertyDef propertyDef) {
var propType = propertyDefinition.PropertySig.GetRetType(); var propType = propertyDef.PropertySig.GetRetType();
string newName; string newName;
if (isGeneric(propType)) if (isGeneric(propType))
newName = existingPropertyNames.getName(propertyDefinition.Name, genericPropertyNameCreator); newName = existingPropertyNames.getName(propertyDef.Name, genericPropertyNameCreator);
else else
newName = existingPropertyNames.getName(propertyDefinition.Name, () => propertyNameCreator.create(propType)); newName = existingPropertyNames.getName(propertyDef.Name, () => propertyNameCreator.create(propType));
addPropertyName(newName); addPropertyName(newName);
return newName; return newName;
} }
@ -106,7 +106,7 @@ namespace de4dot.code.renamer {
return false; return false;
} }
public string getNewEventName(EventDef eventDefinition) { public string getNewEventName(EventDef eventDef) {
string newName = eventNameCreator.create(); string newName = eventNameCreator.create();
addEventName(newName); addEventName(newName);
return newName; return newName;

View File

@ -27,14 +27,14 @@ namespace de4dot.code.renamer.asmmodules {
public MMethodDef RaiseMethod { get; set; } public MMethodDef RaiseMethod { get; set; }
public EventDef EventDef { public EventDef EventDef {
get { return (EventDef)memberReference; } get { return (EventDef)memberRef; }
} }
public MEventDef(EventDef eventDefinition, MTypeDef owner, int index) public MEventDef(EventDef eventDef, MTypeDef owner, int index)
: base(eventDefinition, owner, index) { : base(eventDef, owner, index) {
} }
public IEnumerable<MethodDef> methodDefinitions() { public IEnumerable<MethodDef> methodDefs() {
if (EventDef.AddMethod != null) if (EventDef.AddMethod != null)
yield return EventDef.AddMethod; yield return EventDef.AddMethod;
if (EventDef.RemoveMethod != null) if (EventDef.RemoveMethod != null)
@ -48,7 +48,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
public bool isVirtual() { public bool isVirtual() {
foreach (var method in methodDefinitions()) { foreach (var method in methodDefs()) {
if (method.IsVirtual) if (method.IsVirtual)
return true; return true;
} }

View File

@ -22,11 +22,11 @@ using dot10.DotNet;
namespace de4dot.code.renamer.asmmodules { namespace de4dot.code.renamer.asmmodules {
class MFieldDef : Ref { class MFieldDef : Ref {
public FieldDef FieldDef { public FieldDef FieldDef {
get { return (FieldDef)memberReference; } get { return (FieldDef)memberRef; }
} }
public MFieldDef(FieldDef fieldDefinition, MTypeDef owner, int index) public MFieldDef(FieldDef fieldDef, MTypeDef owner, int index)
: base(fieldDefinition, owner, index) { : base(fieldDef, owner, index) {
} }
} }
} }

View File

@ -23,7 +23,7 @@ using dot10.DotNet;
namespace de4dot.code.renamer.asmmodules { namespace de4dot.code.renamer.asmmodules {
class MGenericParamDef : Ref { class MGenericParamDef : Ref {
public GenericParam GenericParam { public GenericParam GenericParam {
get { return (GenericParam)memberReference; } get { return (GenericParam)memberRef; }
} }
public MGenericParamDef(GenericParam genericParameter, int index) public MGenericParamDef(GenericParam genericParameter, int index)

View File

@ -21,8 +21,8 @@ using dot10.DotNet;
namespace de4dot.code.renamer.asmmodules { namespace de4dot.code.renamer.asmmodules {
interface IResolver { interface IResolver {
MTypeDef resolveType(ITypeDefOrRef typeReference); MTypeDef resolveType(ITypeDefOrRef typeRef);
MMethodDef resolveMethod(IMethodDefOrRef methodReference); MMethodDef resolveMethod(IMethodDefOrRef methodRef);
MFieldDef resolveField(MemberRef fieldReference); MFieldDef resolveField(MemberRef fieldRef);
} }
} }

View File

@ -60,20 +60,20 @@ namespace de4dot.code.renamer.asmmodules {
} }
public MethodDef MethodDef { public MethodDef MethodDef {
get { return (MethodDef)memberReference; } get { return (MethodDef)memberRef; }
} }
public MMethodDef(MethodDef methodDefinition, MTypeDef owner, int index) public MMethodDef(MethodDef methodDef, MTypeDef owner, int index)
: base(methodDefinition, owner, index) { : base(methodDef, owner, index) {
genericParams = MGenericParamDef.createGenericParamDefList(MethodDef.GenericParameters); genericParams = MGenericParamDef.createGenericParamDefList(MethodDef.GenericParameters);
visibleBaseIndex = methodDefinition.MethodSig != null && methodDefinition.MethodSig.HasThis ? 1 : 0; visibleBaseIndex = methodDef.MethodSig != null && methodDef.MethodSig.HasThis ? 1 : 0;
for (int i = 0; i < methodDefinition.Parameters.Count; i++) { for (int i = 0; i < methodDef.Parameters.Count; i++) {
var param = methodDefinition.Parameters[i]; var param = methodDef.Parameters[i];
if (param.IsNormalMethodParameter) if (param.IsNormalMethodParameter)
visibleParamCount++; visibleParamCount++;
paramDefs.Add(new MParamDef(param, i)); paramDefs.Add(new MParamDef(param, i));
} }
returnParamDef = new MParamDef(methodDefinition.Parameters.ReturnParameter, -1); returnParamDef = new MParamDef(methodDef.Parameters.ReturnParameter, -1);
} }
public bool isPublic() { public bool isPublic() {

View File

@ -30,15 +30,15 @@ namespace de4dot.code.renamer.asmmodules {
IList<RefToDef<TypeRef, TypeDef>> typeRefsToRename = new List<RefToDef<TypeRef, TypeDef>>(); IList<RefToDef<TypeRef, TypeDef>> typeRefsToRename = new List<RefToDef<TypeRef, TypeDef>>();
IList<RefToDef<MemberRef, MethodDef>> methodRefsToRename = new List<RefToDef<MemberRef, MethodDef>>(); IList<RefToDef<MemberRef, MethodDef>> methodRefsToRename = new List<RefToDef<MemberRef, MethodDef>>();
IList<RefToDef<MemberRef, FieldDef>> fieldRefsToRename = new List<RefToDef<MemberRef, FieldDef>>(); IList<RefToDef<MemberRef, FieldDef>> fieldRefsToRename = new List<RefToDef<MemberRef, FieldDef>>();
List<CustomAttributeReference> customAttributeFieldReferences = new List<CustomAttributeReference>(); List<CustomAttributeRef> customAttributeFieldRefs = new List<CustomAttributeRef>();
List<CustomAttributeReference> customAttributePropertyReferences = new List<CustomAttributeReference>(); List<CustomAttributeRef> customAttributePropertyRefs = new List<CustomAttributeRef>();
List<MethodDef> allMethods; List<MethodDef> allMethods;
public class CustomAttributeReference { public class CustomAttributeRef {
public CustomAttribute cattr; public CustomAttribute cattr;
public int index; public int index;
public IMemberRef reference; public IMemberRef reference;
public CustomAttributeReference(CustomAttribute cattr, int index, IMemberRef reference) { public CustomAttributeRef(CustomAttribute cattr, int index, IMemberRef reference) {
this.cattr = cattr; this.cattr = cattr;
this.index = index; this.index = index;
this.reference = reference; this.reference = reference;
@ -66,12 +66,12 @@ namespace de4dot.code.renamer.asmmodules {
get { return fieldRefsToRename; } get { return fieldRefsToRename; }
} }
public IEnumerable<CustomAttributeReference> CustomAttributeFieldReferences { public IEnumerable<CustomAttributeRef> CustomAttributeFieldRefs {
get { return customAttributeFieldReferences; } get { return customAttributeFieldRefs; }
} }
public IEnumerable<CustomAttributeReference> CustomAttributePropertyReferences { public IEnumerable<CustomAttributeRef> CustomAttributePropertyRefs {
get { return customAttributePropertyReferences; } get { return customAttributePropertyRefs; }
} }
public IObfuscatedFile ObfuscatedFile { public IObfuscatedFile ObfuscatedFile {
@ -98,7 +98,7 @@ namespace de4dot.code.renamer.asmmodules {
return allMethods; return allMethods;
} }
public void findAllMemberReferences(ref int typeIndex) { public void findAllMemberRefs(ref int typeIndex) {
memberRefFinder = new MemberRefFinder(); memberRefFinder = new MemberRefFinder();
memberRefFinder.findAll(ModuleDefMD); memberRefFinder.findAll(ModuleDefMD);
allMethods = new List<MethodDef>(memberRefFinder.methodDefs.Keys); allMethods = new List<MethodDef>(memberRefFinder.methodDefs.Keys);
@ -118,8 +118,8 @@ namespace de4dot.code.renamer.asmmodules {
foreach (var typeDef in allTypesList) { foreach (var typeDef in allTypesList) {
if (typeDef.TypeDef.NestedTypes == null) if (typeDef.TypeDef.NestedTypes == null)
continue; continue;
foreach (var nestedTypeDefinition in typeDef.TypeDef.NestedTypes) { foreach (var nestedTypeDef2 in typeDef.TypeDef.NestedTypes) {
int index = typeToIndex[nestedTypeDefinition]; int index = typeToIndex[nestedTypeDef2];
var nestedTypeDef = allTypesCopy[index]; var nestedTypeDef = allTypesCopy[index];
allTypesCopy[index] = null; allTypesCopy[index] = null;
if (nestedTypeDef == null) // Impossible if (nestedTypeDef == null) // Impossible
@ -169,7 +169,7 @@ namespace de4dot.code.renamer.asmmodules {
continue; continue;
} }
customAttributeFieldReferences.Add(new CustomAttributeReference(cattr, i, fieldDef.FieldDef)); customAttributeFieldRefs.Add(new CustomAttributeRef(cattr, i, fieldDef.FieldDef));
} }
else { else {
var propDef = findProperty(typeDef, namedArg.Name, namedArg.Type); var propDef = findProperty(typeDef, namedArg.Name, namedArg.Type);
@ -181,7 +181,7 @@ namespace de4dot.code.renamer.asmmodules {
continue; 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; ModuleDefMD.EnableTypeDefFindCache = old;
} }
static ITypeDefOrRef getNonGenericTypeReference(ITypeDefOrRef typeRef) { static ITypeDefOrRef getNonGenericTypeRef(ITypeDefOrRef typeRef) {
var ts = typeRef as TypeSpec; var ts = typeRef as TypeSpec;
if (ts == null) if (ts == null)
return typeRef; return typeRef;
@ -242,19 +242,19 @@ namespace de4dot.code.renamer.asmmodules {
return gis.GenericType.TypeDefOrRef; return gis.GenericType.TypeDefOrRef;
} }
public MTypeDef resolveType(ITypeDefOrRef typeReference) { public MTypeDef resolveType(ITypeDefOrRef typeRef) {
return this.types.find(getNonGenericTypeReference(typeReference)); return this.types.find(getNonGenericTypeRef(typeRef));
} }
public MMethodDef resolveMethod(IMethodDefOrRef methodRef) { public MMethodDef resolveMethod(IMethodDefOrRef methodRef) {
var typeDef = this.types.find(getNonGenericTypeReference(methodRef.DeclaringType)); var typeDef = this.types.find(getNonGenericTypeRef(methodRef.DeclaringType));
if (typeDef == null) if (typeDef == null)
return null; return null;
return typeDef.findMethod(methodRef); return typeDef.findMethod(methodRef);
} }
public MFieldDef resolveField(MemberRef fieldRef) { public MFieldDef resolveField(MemberRef fieldRef) {
var typeDef = this.types.find(getNonGenericTypeReference(fieldRef.DeclaringType)); var typeDef = this.types.find(getNonGenericTypeRef(fieldRef.DeclaringType));
if (typeDef == null) if (typeDef == null)
return null; return null;
return typeDef.findField(fieldRef); return typeDef.findField(fieldRef);

View File

@ -149,19 +149,19 @@ namespace de4dot.code.renamer.asmmodules {
public void initialize() { public void initialize() {
initializeCalled = true; initializeCalled = true;
findAllMemberReferences(); findAllMemberRefs();
initAllTypes(); initAllTypes();
resolveAllRefs(); resolveAllRefs();
} }
void findAllMemberReferences() { void findAllMemberRefs() {
Logger.v("Finding all MemberReferences"); Logger.v("Finding all MemberRefs");
int index = 0; int index = 0;
foreach (var module in modules) { foreach (var module in modules) {
if (modules.Count > 1) if (modules.Count > 1)
Logger.v("Finding all MemberReferences ({0})", module.Filename); Logger.v("Finding all MemberRefs ({0})", module.Filename);
Logger.Instance.indent(); Logger.Instance.indent();
module.findAllMemberReferences(ref index); module.findAllMemberRefs(ref index);
Logger.Instance.deIndent(); Logger.Instance.deIndent();
} }
} }
@ -319,22 +319,22 @@ namespace de4dot.code.renamer.asmmodules {
if (typeToTypeDefDict.tryGetValue(type, out typeDef)) if (typeToTypeDefDict.tryGetValue(type, out typeDef))
return typeDef; return typeDef;
var typeDefinition = deobfuscatorContext.resolveType(type); var typeDef2 = deobfuscatorContext.resolveType(type);
if (typeDefinition == null) { if (typeDef2 == null) {
typeToTypeDefDict.tryGetSimilarValue(type, out typeDef); typeToTypeDefDict.tryGetSimilarValue(type, out typeDef);
typeToTypeDefDict[type] = typeDef; typeToTypeDefDict[type] = typeDef;
return typeDef; return typeDef;
} }
if (typeToTypeDefDict.tryGetValue(typeDefinition, out typeDef)) { if (typeToTypeDefDict.tryGetValue(typeDef2, out typeDef)) {
typeToTypeDefDict[type] = typeDef; typeToTypeDefDict[type] = typeDef;
return typeDef; return typeDef;
} }
typeToTypeDefDict[type] = null; // In case of a circular reference 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(); typeDef.addMembers();
foreach (var iface in typeDef.TypeDef.Interfaces) { foreach (var iface in typeDef.TypeDef.Interfaces) {
var ifaceDef = resolveOther(iface.Interface); var ifaceDef = resolveOther(iface.Interface);
@ -347,8 +347,8 @@ namespace de4dot.code.renamer.asmmodules {
typeDef.addBaseType(baseDef, typeDef.TypeDef.BaseType); typeDef.addBaseType(baseDef, typeDef.TypeDef.BaseType);
typeToTypeDefDict[type] = typeDef; typeToTypeDefDict[type] = typeDef;
if (type != typeDefinition) if (type != typeDef2)
typeToTypeDefDict[typeDefinition] = typeDef; typeToTypeDefDict[typeDef2] = typeDef;
return typeDef; return typeDef;
} }
@ -449,7 +449,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
if (isAutoCreatedType(typeRef)) if (isAutoCreatedType(typeRef))
return null; 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), Utils.removeNewlines(typeRef),
typeRef.MDToken.ToInt32(), typeRef.MDToken.ToInt32(),
typeRef.Module, typeRef.Module,
@ -470,7 +470,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
if (isAutoCreatedType(methodRef.DeclaringType)) if (isAutoCreatedType(methodRef.DeclaringType))
return null; 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), Utils.removeNewlines(methodRef),
methodRef.MDToken.ToInt32(), methodRef.MDToken.ToInt32(),
methodRef.DeclaringType.Module, methodRef.DeclaringType.Module,
@ -478,24 +478,24 @@ namespace de4dot.code.renamer.asmmodules {
return null; return null;
} }
public MFieldDef resolveField(MemberRef fieldReference) { public MFieldDef resolveField(MemberRef fieldRef) {
if (fieldReference.DeclaringType == null) if (fieldRef.DeclaringType == null)
return null; return null;
var modules = findModules(fieldReference.DeclaringType); var modules = findModules(fieldRef.DeclaringType);
if (modules == null) if (modules == null)
return null; return null;
foreach (var module in modules) { foreach (var module in modules) {
var rv = module.resolveField(fieldReference); var rv = module.resolveField(fieldRef);
if (rv != null) if (rv != null)
return rv; return rv;
} }
if (isAutoCreatedType(fieldReference.DeclaringType)) if (isAutoCreatedType(fieldRef.DeclaringType))
return null; return null;
Logger.e("Could not resolve FieldReference {0} ({1:X8}) (from {2} -> {3})", Logger.e("Could not resolve FieldRef {0} ({1:X8}) (from {2} -> {3})",
Utils.removeNewlines(fieldReference), Utils.removeNewlines(fieldRef),
fieldReference.MDToken.ToInt32(), fieldRef.MDToken.ToInt32(),
fieldReference.DeclaringType.Module, fieldRef.DeclaringType.Module,
fieldReference.DeclaringType.Scope); fieldRef.DeclaringType.Scope);
return null; return null;
} }
} }

View File

@ -21,17 +21,17 @@ using dot10.DotNet;
namespace de4dot.code.renamer.asmmodules { namespace de4dot.code.renamer.asmmodules {
class MParamDef { class MParamDef {
public Parameter ParameterDefinition { get; set; } public Parameter ParameterDef { get; set; }
public int Index { get; private set; } public int Index { get; private set; }
public bool IsReturnParameter { public bool IsReturnParameter {
get { return ParameterDefinition.IsReturnTypeParameter; } get { return ParameterDef.IsReturnTypeParameter; }
} }
public bool IsHiddenThisParameter { public bool IsHiddenThisParameter {
get { return ParameterDefinition.IsHiddenThisParameter; } get { return ParameterDef.IsHiddenThisParameter; }
} }
public MParamDef(Parameter parameterDefinition, int index) { public MParamDef(Parameter parameterDef, int index) {
this.ParameterDefinition = parameterDefinition; this.ParameterDef = parameterDef;
Index = index; Index = index;
} }
} }

View File

@ -26,14 +26,14 @@ namespace de4dot.code.renamer.asmmodules {
public MMethodDef SetMethod { get; set; } public MMethodDef SetMethod { get; set; }
public PropertyDef PropertyDef { public PropertyDef PropertyDef {
get { return (PropertyDef)memberReference; } get { return (PropertyDef)memberRef; }
} }
public MPropertyDef(PropertyDef propertyDefinition, MTypeDef owner, int index) public MPropertyDef(PropertyDef propertyDef, MTypeDef owner, int index)
: base(propertyDefinition, owner, index) { : base(propertyDef, owner, index) {
} }
public IEnumerable<MethodDef> methodDefinitions() { public IEnumerable<MethodDef> methodDefs() {
if (PropertyDef.GetMethod != null) if (PropertyDef.GetMethod != null)
yield return PropertyDef.GetMethod; yield return PropertyDef.GetMethod;
if (PropertyDef.SetMethod != null) if (PropertyDef.SetMethod != null)
@ -45,7 +45,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
public bool isVirtual() { public bool isVirtual() {
foreach (var method in methodDefinitions()) { foreach (var method in methodDefs()) {
if (method.IsVirtual) if (method.IsVirtual)
return true; return true;
} }

View File

@ -21,18 +21,18 @@ using dot10.DotNet;
namespace de4dot.code.renamer.asmmodules { namespace de4dot.code.renamer.asmmodules {
abstract class Ref { abstract class Ref {
public readonly IMemberRef memberReference; public readonly IMemberRef memberRef;
public int Index { get; set; } public int Index { get; set; }
public MTypeDef Owner { get; set; } public MTypeDef Owner { get; set; }
protected Ref(IMemberRef memberReference, MTypeDef owner, int index) { protected Ref(IMemberRef memberRef, MTypeDef owner, int index) {
this.memberReference = memberReference; this.memberRef = memberRef;
Owner = owner; Owner = owner;
Index = index; Index = index;
} }
public override string ToString() { public override string ToString() {
return memberReference != null ? memberReference.ToString() : null; return memberRef != null ? memberRef.ToString() : null;
} }
} }
} }

View File

@ -29,7 +29,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
} }
class TypeDefDict : TypeDefinitionDict<MTypeDef> { class TypeDefDict : TypeDefDict<MTypeDef> {
public IEnumerable<MTypeDef> getSorted() { public IEnumerable<MTypeDef> getSorted() {
return DictHelper.getSorted(getValues()); return DictHelper.getSorted(getValues());
} }
@ -39,7 +39,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
} }
class FieldDefDict : FieldDefinitionDict<MFieldDef> { class FieldDefDict : FieldDefDict<MFieldDef> {
public IEnumerable<MFieldDef> getSorted() { public IEnumerable<MFieldDef> getSorted() {
return DictHelper.getSorted(getValues()); return DictHelper.getSorted(getValues());
} }
@ -49,7 +49,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
} }
class MethodDefDict : MethodDefinitionDict<MMethodDef> { class MethodDefDict : MethodDefDict<MMethodDef> {
public IEnumerable<MMethodDef> getSorted() { public IEnumerable<MMethodDef> getSorted() {
return DictHelper.getSorted(getValues()); return DictHelper.getSorted(getValues());
} }
@ -59,7 +59,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
} }
class PropertyDefDict : PropertyDefinitionDict<MPropertyDef> { class PropertyDefDict : PropertyDefDict<MPropertyDef> {
public IEnumerable<MPropertyDef> getSorted() { public IEnumerable<MPropertyDef> getSorted() {
return DictHelper.getSorted(getValues()); return DictHelper.getSorted(getValues());
} }
@ -69,7 +69,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
} }
class EventDefDict : EventDefinitionDict<MEventDef> { class EventDefDict : EventDefDict<MEventDef> {
public IEnumerable<MEventDef> getSorted() { public IEnumerable<MEventDef> getSorted() {
return DictHelper.getSorted(getValues()); return DictHelper.getSorted(getValues());
} }

View File

@ -24,21 +24,21 @@ using de4dot.blocks;
namespace de4dot.code.renamer.asmmodules { namespace de4dot.code.renamer.asmmodules {
class TypeInfo { class TypeInfo {
public ITypeDefOrRef typeReference; public ITypeDefOrRef typeRef;
public MTypeDef typeDef; public MTypeDef typeDef;
public TypeInfo(ITypeDefOrRef typeReference, MTypeDef typeDef) { public TypeInfo(ITypeDefOrRef typeRef, MTypeDef typeDef) {
this.typeReference = typeReference; this.typeRef = typeRef;
this.typeDef = typeDef; this.typeDef = typeDef;
} }
public TypeInfo(TypeInfo other, GenericInstSig git) { public TypeInfo(TypeInfo other, GenericInstSig git) {
this.typeReference = GenericArgsSubstitutor.create(other.typeReference, git); this.typeRef = GenericArgsSubstitutor.create(other.typeRef, git);
this.typeDef = other.typeDef; this.typeDef = other.typeDef;
} }
public override int GetHashCode() { public override int GetHashCode() {
return typeDef.GetHashCode() + return typeDef.GetHashCode() +
new SigComparer().GetHashCode(typeReference); new SigComparer().GetHashCode(typeRef);
} }
public override bool Equals(object obj) { public override bool Equals(object obj) {
@ -46,11 +46,11 @@ namespace de4dot.code.renamer.asmmodules {
if (other == null) if (other == null)
return false; return false;
return typeDef == other.typeDef && return typeDef == other.typeDef &&
new SigComparer().Equals(typeReference, other.typeReference); new SigComparer().Equals(typeRef, other.typeRef);
} }
public override string ToString() { public override string ToString() {
return typeReference.ToString(); return typeRef.ToString();
} }
} }
@ -75,15 +75,15 @@ namespace de4dot.code.renamer.asmmodules {
class MethodInst { class MethodInst {
public MMethodDef origMethodDef; 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.origMethodDef = origMethodDef;
this.methodReference = methodReference; this.methodRef = methodRef;
} }
public override string ToString() { 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) { public void initializeFrom(MethodInstances other, GenericInstSig git) {
foreach (var list in other.methodInstances.Values) { foreach (var list in other.methodInstances.Values) {
foreach (var methodInst in list) { 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)); add(new MethodInst(methodInst.origMethodDef, newMethod));
} }
} }
@ -101,15 +101,15 @@ namespace de4dot.code.renamer.asmmodules {
public void add(MethodInst methodInst) { public void add(MethodInst methodInst) {
List<MethodInst> list; List<MethodInst> list;
var key = methodInst.methodReference; var key = methodInst.methodRef;
if (methodInst.origMethodDef.isNewSlot() || !methodInstances.TryGetValue(key, out list)) if (methodInst.origMethodDef.isNewSlot() || !methodInstances.TryGetValue(key, out list))
methodInstances[key] = list = new List<MethodInst>(); methodInstances[key] = list = new List<MethodInst>();
list.Add(methodInst); list.Add(methodInst);
} }
public List<MethodInst> lookup(IMethodDefOrRef methodReference) { public List<MethodInst> lookup(IMethodDefOrRef methodRef) {
List<MethodInst> list; List<MethodInst> list;
methodInstances.TryGetValue(methodReference, out list); methodInstances.TryGetValue(methodRef, out list);
return list; return list;
} }
@ -186,8 +186,8 @@ namespace de4dot.code.renamer.asmmodules {
foreach (var pair in other.interfaceMethods) { foreach (var pair in other.interfaceMethods) {
var oldTypeInfo = pair.Value.IFace; var oldTypeInfo = pair.Value.IFace;
var newTypeInfo = new TypeInfo(oldTypeInfo, git); var newTypeInfo = new TypeInfo(oldTypeInfo, git);
var oldKey = oldTypeInfo.typeReference; var oldKey = oldTypeInfo.typeRef;
var newKey = newTypeInfo.typeReference; var newKey = newTypeInfo.typeRef;
InterfaceMethodInfo newMethodsInfo = new InterfaceMethodInfo(newTypeInfo, other.interfaceMethods[oldKey]); InterfaceMethodInfo newMethodsInfo = new InterfaceMethodInfo(newTypeInfo, other.interfaceMethods[oldKey]);
if (interfaceMethods.ContainsKey(newKey)) if (interfaceMethods.ContainsKey(newKey))
@ -197,14 +197,14 @@ namespace de4dot.code.renamer.asmmodules {
} }
public void addInterface(TypeInfo iface) { public void addInterface(TypeInfo iface) {
var key = iface.typeReference; var key = iface.typeRef;
if (!interfaceMethods.ContainsKey(key)) if (!interfaceMethods.ContainsKey(key))
interfaceMethods[key] = new InterfaceMethodInfo(iface); interfaceMethods[key] = new InterfaceMethodInfo(iface);
} }
// Returns the previous classMethod, or null if none // Returns the previous classMethod, or null if none
public MMethodDef addMethod(TypeInfo iface, MMethodDef ifaceMethod, MMethodDef classMethod) { 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 // 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) { public void addMethodIfEmpty(TypeInfo iface, MMethodDef ifaceMethod, MMethodDef classMethod) {
InterfaceMethodInfo info; InterfaceMethodInfo info;
if (!interfaceMethods.TryGetValue(iface.typeReference, out info)) if (!interfaceMethods.TryGetValue(iface.typeRef, out info))
throw new ApplicationException("Could not find interface"); throw new ApplicationException("Could not find interface");
info.addMethodIfEmpty(ifaceMethod, classMethod); info.addMethodIfEmpty(ifaceMethod, classMethod);
} }
@ -260,7 +260,7 @@ namespace de4dot.code.renamer.asmmodules {
public MTypeDef NestingType { get; set; } public MTypeDef NestingType { get; set; }
public TypeDef TypeDef { public TypeDef TypeDef {
get { return (TypeDef)memberReference; } get { return (TypeDef)memberRef; }
} }
public IEnumerable<MEventDef> AllEvents { public IEnumerable<MEventDef> AllEvents {
@ -295,8 +295,8 @@ namespace de4dot.code.renamer.asmmodules {
get { return properties.getSorted(); } get { return properties.getSorted(); }
} }
public MTypeDef(TypeDef typeDefinition, Module module, int index) public MTypeDef(TypeDef typeDef, Module module, int index)
: base(typeDefinition, null, index) { : base(typeDef, null, index) {
this.module = module; this.module = module;
genericParams = MGenericParamDef.createGenericParamDefList(TypeDef.GenericParameters); genericParams = MGenericParamDef.createGenericParamDefList(TypeDef.GenericParameters);
} }
@ -406,7 +406,7 @@ namespace de4dot.code.renamer.asmmodules {
add(new MPropertyDef(type.Properties[i], this, i)); add(new MPropertyDef(type.Properties[i], this, i));
foreach (var propDef in properties.getValues()) { foreach (var propDef in properties.getValues()) {
foreach (var method in propDef.methodDefinitions()) { foreach (var method in propDef.methodDefs()) {
var methodDef = findMethod(method); var methodDef = findMethod(method);
if (methodDef == null) if (methodDef == null)
throw new ApplicationException("Could not find property method"); 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 eventDef in events.getValues()) {
foreach (var method in eventDef.methodDefinitions()) { foreach (var method in eventDef.methodDefs()) {
var methodDef = findMethod(method); var methodDef = findMethod(method);
if (methodDef == null) if (methodDef == null)
throw new ApplicationException("Could not find event method"); throw new ApplicationException("Could not find event method");
@ -494,7 +494,7 @@ namespace de4dot.code.renamer.asmmodules {
} }
void initializeInterfaces(TypeInfo typeInfo) { void initializeInterfaces(TypeInfo typeInfo) {
var git = typeInfo.typeReference.ToGenericInstSig(); var git = typeInfo.typeRef.ToGenericInstSig();
interfaceMethodInfos.initializeFrom(typeInfo.typeDef.interfaceMethodInfos, git); interfaceMethodInfos.initializeFrom(typeInfo.typeDef.interfaceMethodInfos, git);
foreach (var info in typeInfo.typeDef.allImplementedInterfaces.Keys) { foreach (var info in typeInfo.typeDef.allImplementedInterfaces.Keys) {
var newTypeInfo = new TypeInfo(info, git); var newTypeInfo = new TypeInfo(info, git);
@ -540,9 +540,9 @@ namespace de4dot.code.renamer.asmmodules {
var ifaceMethod = methodInst.origMethodDef; var ifaceMethod = methodInst.origMethodDef;
if (!ifaceMethod.isVirtual()) if (!ifaceMethod.isVirtual())
continue; continue;
var ifaceMethodReference = GenericArgsSubstitutor.create(methodInst.methodReference, ifaceInfo.typeReference.ToGenericInstSig()); var ifaceMethodRef = GenericArgsSubstitutor.create(methodInst.methodRef, ifaceInfo.typeRef.ToGenericInstSig());
MMethodDef classMethod; MMethodDef classMethod;
if (!methodsDict.TryGetValue(ifaceMethodReference, out classMethod)) if (!methodsDict.TryGetValue(ifaceMethodRef, out classMethod))
continue; continue;
interfaceMethodInfos.addMethod(ifaceInfo, ifaceMethod, classMethod); 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. // We should allow newslot methods, despite what the official doc says.
if (!classMethod.origMethodDef.isPublic()) if (!classMethod.origMethodDef.isPublic())
continue; continue;
methodsDict[classMethod.methodReference] = classMethod.origMethodDef; methodsDict[classMethod.methodRef] = classMethod.origMethodDef;
break; break;
} }
} }
@ -574,7 +574,7 @@ namespace de4dot.code.renamer.asmmodules {
var ifaceMethod = methodsList[0].origMethodDef; var ifaceMethod = methodsList[0].origMethodDef;
if (!ifaceMethod.isVirtual()) if (!ifaceMethod.isVirtual())
continue; continue;
var ifaceMethodRef = GenericArgsSubstitutor.create(ifaceMethod.MethodDef, ifaceInfo.typeReference.ToGenericInstSig()); var ifaceMethodRef = GenericArgsSubstitutor.create(ifaceMethod.MethodDef, ifaceInfo.typeRef.ToGenericInstSig());
MMethodDef classMethod; MMethodDef classMethod;
if (!methodsDict.TryGetValue(ifaceMethodRef, out classMethod)) if (!methodsDict.TryGetValue(ifaceMethodRef, out classMethod))
continue; continue;
@ -588,12 +588,12 @@ namespace de4dot.code.renamer.asmmodules {
methodsDict.Clear(); methodsDict.Clear();
var ifaceMethodsDict = new Dictionary<IMethodDefOrRef, MMethodDef>(MethodEqualityComparer.CompareDeclaringTypes); var ifaceMethodsDict = new Dictionary<IMethodDefOrRef, MMethodDef>(MethodEqualityComparer.CompareDeclaringTypes);
foreach (var ifaceInfo in allImplementedInterfaces.Keys) { foreach (var ifaceInfo in allImplementedInterfaces.Keys) {
var git = ifaceInfo.typeReference.ToGenericInstSig(); var git = ifaceInfo.typeRef.ToGenericInstSig();
foreach (var ifaceMethod in ifaceInfo.typeDef.methods.getValues()) { foreach (var ifaceMethod in ifaceInfo.typeDef.methods.getValues()) {
IMethodDefOrRef ifaceMethodReference = ifaceMethod.MethodDef; IMethodDefOrRef ifaceMethodRef = ifaceMethod.MethodDef;
if (git != null) if (git != null)
ifaceMethodReference = simpleClone(ifaceMethod.MethodDef, ifaceInfo.typeReference); ifaceMethodRef = simpleClone(ifaceMethod.MethodDef, ifaceInfo.typeRef);
ifaceMethodsDict[ifaceMethodReference] = ifaceMethod; ifaceMethodsDict[ifaceMethodRef] = ifaceMethod;
} }
} }
foreach (var classMethod in methods.getValues()) { foreach (var classMethod in methods.getValues()) {
@ -699,7 +699,7 @@ namespace de4dot.code.renamer.asmmodules {
void instantiateVirtualMembers(MethodNameGroups groups) { void instantiateVirtualMembers(MethodNameGroups groups) {
if (!TypeDef.IsInterface) { if (!TypeDef.IsInterface) {
if (baseType != null) 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 // Figure out which methods we override in the base class
foreach (var methodDef in methods.getValues()) { foreach (var methodDef in methods.getValues()) {