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