Merge branch 'master' into skater
This commit is contained in:
commit
07768cefd1
|
@ -46,6 +46,7 @@ namespace de4dot.blocks {
|
|||
|
||||
public class TypeDefinitionDict<TValue> {
|
||||
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
|
||||
Dictionary<ScopeAndTokenKey, TypeDefinition> tokenToKey = new Dictionary<ScopeAndTokenKey, TypeDefinition>();
|
||||
Dictionary<TypeReferenceKey, TValue> refToValue = new Dictionary<TypeReferenceKey, TValue>();
|
||||
Dictionary<TypeReferenceKey, TypeDefinition> refToKey = new Dictionary<TypeReferenceKey, TypeDefinition>();
|
||||
|
||||
|
@ -54,10 +55,10 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public IEnumerable<TypeDefinition> getKeys() {
|
||||
return refToKey.Values;
|
||||
return tokenToKey.Values;
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> getAll() {
|
||||
public IEnumerable<TValue> getValues() {
|
||||
return tokenToValue.Values;
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,9 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public void add(TypeDefinition typeDefinition, TValue value) {
|
||||
tokenToValue[getTokenKey(typeDefinition)] = value;
|
||||
var tokenKey = getTokenKey(typeDefinition);
|
||||
tokenToValue[tokenKey] = value;
|
||||
tokenToKey[tokenKey] = typeDefinition;
|
||||
|
||||
var refKey = getReferenceKey(typeDefinition);
|
||||
if (!refToValue.ContainsKey(refKey) ||
|
||||
|
@ -123,6 +126,7 @@ namespace de4dot.blocks {
|
|||
|
||||
public abstract class FieldDefinitionDictBase<TValue> {
|
||||
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
|
||||
Dictionary<ScopeAndTokenKey, FieldDefinition> tokenToKey = new Dictionary<ScopeAndTokenKey, FieldDefinition>();
|
||||
Dictionary<IFieldReferenceKey, TValue> refToValue = new Dictionary<IFieldReferenceKey, TValue>();
|
||||
Dictionary<IFieldReferenceKey, FieldDefinition> refToKey = new Dictionary<IFieldReferenceKey, FieldDefinition>();
|
||||
|
||||
|
@ -131,10 +135,10 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public IEnumerable<FieldDefinition> getKeys() {
|
||||
return refToKey.Values;
|
||||
return tokenToKey.Values;
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> getAll() {
|
||||
public IEnumerable<TValue> getValues() {
|
||||
return tokenToValue.Values;
|
||||
}
|
||||
|
||||
|
@ -163,7 +167,9 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public void add(FieldDefinition fieldDefinition, TValue value) {
|
||||
tokenToValue[getTokenKey(fieldDefinition)] = value;
|
||||
var tokenKey = getTokenKey(fieldDefinition);
|
||||
tokenToValue[tokenKey] = value;
|
||||
tokenToKey[tokenKey] = fieldDefinition;
|
||||
|
||||
var refKey = getReferenceKey(fieldDefinition);
|
||||
if (!refToValue.ContainsKey(refKey) ||
|
||||
|
@ -210,6 +216,7 @@ namespace de4dot.blocks {
|
|||
|
||||
public abstract class MethodDefinitionDictBase<TValue> {
|
||||
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
|
||||
Dictionary<ScopeAndTokenKey, MethodDefinition> tokenToKey = new Dictionary<ScopeAndTokenKey, MethodDefinition>();
|
||||
Dictionary<IMethodReferenceKey, TValue> refToValue = new Dictionary<IMethodReferenceKey, TValue>();
|
||||
Dictionary<IMethodReferenceKey, MethodDefinition> refToKey = new Dictionary<IMethodReferenceKey, MethodDefinition>();
|
||||
|
||||
|
@ -218,10 +225,10 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public IEnumerable<MethodDefinition> getKeys() {
|
||||
return refToKey.Values;
|
||||
return tokenToKey.Values;
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> getAll() {
|
||||
public IEnumerable<TValue> getValues() {
|
||||
return tokenToValue.Values;
|
||||
}
|
||||
|
||||
|
@ -250,7 +257,9 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public void add(MethodDefinition methodDefinition, TValue value) {
|
||||
tokenToValue[getTokenKey(methodDefinition)] = value;
|
||||
var tokenKey = getTokenKey(methodDefinition);
|
||||
tokenToValue[tokenKey] = value;
|
||||
tokenToKey[tokenKey] = methodDefinition;
|
||||
|
||||
var refKey = getReferenceKey(methodDefinition);
|
||||
if (!refToValue.ContainsKey(refKey) ||
|
||||
|
@ -297,13 +306,18 @@ namespace de4dot.blocks {
|
|||
|
||||
public abstract class PropertyDefinitionDictBase<TValue> {
|
||||
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
|
||||
Dictionary<ScopeAndTokenKey, PropertyDefinition> tokenToKey = new Dictionary<ScopeAndTokenKey, PropertyDefinition>();
|
||||
Dictionary<IPropertyReferenceKey, TValue> refToValue = new Dictionary<IPropertyReferenceKey, TValue>();
|
||||
|
||||
public int Count {
|
||||
get { return tokenToValue.Count; }
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> getAll() {
|
||||
public IEnumerable<PropertyDefinition> getKeys() {
|
||||
return tokenToKey.Values;
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> getValues() {
|
||||
return tokenToValue.Values;
|
||||
}
|
||||
|
||||
|
@ -332,7 +346,10 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public void add(PropertyDefinition propertyDefinition, TValue value) {
|
||||
tokenToValue[getTokenKey(propertyDefinition)] = value;
|
||||
var tokenKey = getTokenKey(propertyDefinition);
|
||||
tokenToValue[tokenKey] = value;
|
||||
tokenToKey[tokenKey] = propertyDefinition;
|
||||
|
||||
refToValue[getReferenceKey(propertyDefinition)] = value;
|
||||
}
|
||||
|
||||
|
@ -358,13 +375,18 @@ namespace de4dot.blocks {
|
|||
|
||||
public abstract class EventDefinitionDictBase<TValue> {
|
||||
Dictionary<ScopeAndTokenKey, TValue> tokenToValue = new Dictionary<ScopeAndTokenKey, TValue>();
|
||||
Dictionary<ScopeAndTokenKey, EventDefinition> tokenToKey = new Dictionary<ScopeAndTokenKey, EventDefinition>();
|
||||
Dictionary<IEventReferenceKey, TValue> refToValue = new Dictionary<IEventReferenceKey, TValue>();
|
||||
|
||||
public int Count {
|
||||
get { return tokenToValue.Count; }
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> getAll() {
|
||||
public IEnumerable<EventDefinition> getKeys() {
|
||||
return tokenToKey.Values;
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> getValues() {
|
||||
return tokenToValue.Values;
|
||||
}
|
||||
|
||||
|
@ -393,7 +415,10 @@ namespace de4dot.blocks {
|
|||
}
|
||||
|
||||
public void add(EventDefinition eventDefinition, TValue value) {
|
||||
tokenToValue[getTokenKey(eventDefinition)] = value;
|
||||
var tokenKey = getTokenKey(eventDefinition);
|
||||
tokenToValue[tokenKey] = value;
|
||||
tokenToKey[tokenKey] = eventDefinition;
|
||||
|
||||
refToValue[getReferenceKey(eventDefinition)] = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,12 +122,7 @@ namespace de4dot.code {
|
|||
}
|
||||
|
||||
public IEnumerable<MethodDefinition> Methods {
|
||||
get {
|
||||
var list = new List<MethodDefinition>(stringDecrypters.Count);
|
||||
foreach (var method in stringDecrypters.getKeys())
|
||||
list.Add(method);
|
||||
return list;
|
||||
}
|
||||
get { return stringDecrypters.getKeys(); }
|
||||
}
|
||||
|
||||
class MyCallResult : CallResult {
|
||||
|
|
|
@ -899,10 +899,68 @@ namespace de4dot.code.renamer {
|
|||
ifaceMethods.visitAll((scope) => prepareRenameVirtualMethods(scope, "imethod_", true));
|
||||
virtualMethods.visitAll((scope) => prepareRenameVirtualMethods(scope, "vmethod_", true));
|
||||
|
||||
restoreMethodArgs(scopes);
|
||||
|
||||
foreach (var typeDef in modules.AllTypes)
|
||||
memberInfos.type(typeDef).prepareRenameMethods2();
|
||||
}
|
||||
|
||||
void restoreMethodArgs(MethodNameScopes scopes) {
|
||||
foreach (var scope in scopes.getAllScopes()) {
|
||||
if (scope.Methods[0].ParamDefs.Count == 0)
|
||||
continue;
|
||||
|
||||
var argNames = getValidArgNames(scope);
|
||||
|
||||
foreach (var method in scope.Methods) {
|
||||
if (!method.Owner.HasModule)
|
||||
continue;
|
||||
var nameChecker = method.Owner.Module.ObfuscatedFile.NameChecker;
|
||||
|
||||
for (int i = 0; i < argNames.Length; i++) {
|
||||
var argName = argNames[i];
|
||||
if (argName == null || !nameChecker.isValidMethodArgName(argName))
|
||||
continue;
|
||||
var info = memberInfos.param(method.ParamDefs[i]);
|
||||
if (nameChecker.isValidMethodArgName(info.oldName))
|
||||
continue;
|
||||
info.newName = argName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string[] getValidArgNames(MethodNameScope scope) {
|
||||
var methods = new List<MethodDef>(scope.Methods);
|
||||
foreach (var method in scope.Methods) {
|
||||
foreach (var overrideRef in method.MethodDefinition.Overrides) {
|
||||
var overrideDef = modules.resolve(overrideRef);
|
||||
if (overrideDef == null) {
|
||||
var typeDef = modules.resolve(overrideRef.DeclaringType) ?? modules.resolveOther(overrideRef.DeclaringType);
|
||||
if (typeDef == null)
|
||||
continue;
|
||||
overrideDef = typeDef.find(overrideRef);
|
||||
if (overrideDef == null)
|
||||
continue;
|
||||
}
|
||||
if (overrideDef.ParamDefs.Count != method.ParamDefs.Count)
|
||||
continue;
|
||||
methods.Add(overrideDef);
|
||||
}
|
||||
}
|
||||
|
||||
var argNames = new string[scope.Methods[0].ParamDefs.Count];
|
||||
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;
|
||||
if (nameChecker == null || nameChecker.isValidMethodArgName(argName))
|
||||
argNames[i] = argName;
|
||||
}
|
||||
}
|
||||
return argNames;
|
||||
}
|
||||
|
||||
class PrepareHelper {
|
||||
Dictionary<TypeDef, bool> prepareMethodCalled = new Dictionary<TypeDef, bool>();
|
||||
MemberInfos memberInfos;
|
||||
|
|
|
@ -286,8 +286,15 @@ namespace de4dot.code.renamer {
|
|||
void prepareRenameMethodArgs(MethodDef methodDef) {
|
||||
if (methodDef.ParamDefs.Count > 0) {
|
||||
if (isEventHandler(methodDef)) {
|
||||
param(methodDef.ParamDefs[0]).newName = "sender";
|
||||
param(methodDef.ParamDefs[1]).newName = "e";
|
||||
ParamInfo info;
|
||||
|
||||
info = param(methodDef.ParamDefs[0]);
|
||||
if (!info.gotNewName())
|
||||
info.newName = "sender";
|
||||
|
||||
info = param(methodDef.ParamDefs[1]);
|
||||
if (!info.gotNewName())
|
||||
info.newName = "e";
|
||||
}
|
||||
else {
|
||||
var newVariableNameState = variableNameState.clone();
|
||||
|
@ -793,12 +800,6 @@ namespace de4dot.code.renamer {
|
|||
return type.FullName.EndsWith("EventHandler", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
static MethodReference getOverrideMethod(MethodDefinition meth) {
|
||||
if (meth == null || !meth.HasOverrides)
|
||||
return null;
|
||||
return meth.Overrides[0];
|
||||
}
|
||||
|
||||
string findWindowsFormsClassName(TypeDef type) {
|
||||
foreach (var methodDef in type.AllMethods) {
|
||||
if (methodDef.MethodDefinition.Body == null)
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
}
|
||||
|
||||
public IEnumerable<TypeDef> getAllTypes() {
|
||||
return types.getAll();
|
||||
return types.getValues();
|
||||
}
|
||||
|
||||
public IEnumerable<MethodDefinition> getAllMethods() {
|
||||
|
@ -131,7 +131,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
|
||||
public void onTypesRenamed() {
|
||||
var newTypes = new TypeDefDict();
|
||||
foreach (var typeDef in types.getAll()) {
|
||||
foreach (var typeDef in types.getValues()) {
|
||||
typeDef.onTypesRenamed();
|
||||
newTypes.add(typeDef);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ using de4dot.blocks;
|
|||
namespace de4dot.code.renamer.asmmodules {
|
||||
interface RefDict<TRef, TMRef> where TRef : Ref where TMRef : MemberReference {
|
||||
int Count { get; }
|
||||
IEnumerable<TRef> getAll();
|
||||
IEnumerable<TRef> getValues();
|
||||
IEnumerable<TRef> getSorted();
|
||||
TRef find(TMRef tmref);
|
||||
TRef findAny(TMRef tmref);
|
||||
|
@ -39,12 +39,12 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
get { return typeToDef.Count; }
|
||||
}
|
||||
|
||||
public IEnumerable<TypeDef> getAll() {
|
||||
return typeToDef.getAll();
|
||||
public IEnumerable<TypeDef> getValues() {
|
||||
return typeToDef.getValues();
|
||||
}
|
||||
|
||||
public IEnumerable<TypeDef> getSorted() {
|
||||
var list = new List<TypeDef>(getAll());
|
||||
var list = new List<TypeDef>(getValues());
|
||||
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
||||
return list;
|
||||
}
|
||||
|
@ -73,12 +73,12 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
get { return fieldToDef.Count; }
|
||||
}
|
||||
|
||||
public IEnumerable<FieldDef> getAll() {
|
||||
return fieldToDef.getAll();
|
||||
public IEnumerable<FieldDef> getValues() {
|
||||
return fieldToDef.getValues();
|
||||
}
|
||||
|
||||
public IEnumerable<FieldDef> getSorted() {
|
||||
var list = new List<FieldDef>(getAll());
|
||||
var list = new List<FieldDef>(getValues());
|
||||
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
||||
return list;
|
||||
}
|
||||
|
@ -107,12 +107,12 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
get { return methodToDef.Count; }
|
||||
}
|
||||
|
||||
public IEnumerable<MethodDef> getAll() {
|
||||
return methodToDef.getAll();
|
||||
public IEnumerable<MethodDef> getValues() {
|
||||
return methodToDef.getValues();
|
||||
}
|
||||
|
||||
public IEnumerable<MethodDef> getSorted() {
|
||||
var list = new List<MethodDef>(getAll());
|
||||
var list = new List<MethodDef>(getValues());
|
||||
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
||||
return list;
|
||||
}
|
||||
|
@ -141,12 +141,12 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
get { return propToDef.Count; }
|
||||
}
|
||||
|
||||
public IEnumerable<PropertyDef> getAll() {
|
||||
return propToDef.getAll();
|
||||
public IEnumerable<PropertyDef> getValues() {
|
||||
return propToDef.getValues();
|
||||
}
|
||||
|
||||
public IEnumerable<PropertyDef> getSorted() {
|
||||
var list = new List<PropertyDef>(getAll());
|
||||
var list = new List<PropertyDef>(getValues());
|
||||
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
||||
return list;
|
||||
}
|
||||
|
@ -175,12 +175,12 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
get { return eventToDef.Count; }
|
||||
}
|
||||
|
||||
public IEnumerable<EventDef> getAll() {
|
||||
return eventToDef.getAll();
|
||||
public IEnumerable<EventDef> getValues() {
|
||||
return eventToDef.getValues();
|
||||
}
|
||||
|
||||
public IEnumerable<EventDef> getSorted() {
|
||||
var list = new List<EventDef>(getAll());
|
||||
var list = new List<EventDef>(getValues());
|
||||
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -246,19 +246,19 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
}
|
||||
|
||||
public IEnumerable<EventDef> AllEvents {
|
||||
get { return events.getAll(); }
|
||||
get { return events.getValues(); }
|
||||
}
|
||||
|
||||
public IEnumerable<FieldDef> AllFields {
|
||||
get { return fields.getAll(); }
|
||||
get { return fields.getValues(); }
|
||||
}
|
||||
|
||||
public IEnumerable<MethodDef> AllMethods {
|
||||
get { return methods.getAll(); }
|
||||
get { return methods.getValues(); }
|
||||
}
|
||||
|
||||
public IEnumerable<PropertyDef> AllProperties {
|
||||
get { return properties.getAll(); }
|
||||
get { return properties.getValues(); }
|
||||
}
|
||||
|
||||
public IEnumerable<EventDef> AllEventsSorted {
|
||||
|
@ -379,7 +379,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
for (int i = 0; i < type.Properties.Count; i++)
|
||||
add(new PropertyDef(type.Properties[i], this, i));
|
||||
|
||||
foreach (var propDef in properties.getAll()) {
|
||||
foreach (var propDef in properties.getValues()) {
|
||||
foreach (var method in propDef.methodDefinitions()) {
|
||||
var methodDef = find(method);
|
||||
if (methodDef == null)
|
||||
|
@ -392,7 +392,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
}
|
||||
}
|
||||
|
||||
foreach (var eventDef in events.getAll()) {
|
||||
foreach (var eventDef in events.getValues()) {
|
||||
foreach (var method in eventDef.methodDefinitions()) {
|
||||
var methodDef = find(method);
|
||||
if (methodDef == null)
|
||||
|
@ -448,7 +448,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
if (baseType != null)
|
||||
baseType.typeDef.initializeVirtualMembers(scopes, resolver);
|
||||
|
||||
foreach (var methodDef in methods.getAll()) {
|
||||
foreach (var methodDef in methods.getValues()) {
|
||||
if (methodDef.isVirtual())
|
||||
scopes.add(methodDef);
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
//--- methods to implement the corresponding interface method.
|
||||
if (interfaces.Count > 0) {
|
||||
methodsDict.Clear();
|
||||
foreach (var method in methods.getAll()) {
|
||||
foreach (var method in methods.getValues()) {
|
||||
if (!method.isPublic() || !method.isVirtual() || !method.isNewSlot())
|
||||
continue;
|
||||
methodsDict[new MethodReferenceKey(method.MethodDefinition)] = method;
|
||||
|
@ -572,14 +572,14 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
var ifaceMethodsDict = new Dictionary<MethodReferenceAndDeclaringTypeKey, MethodDef>();
|
||||
foreach (var ifaceInfo in allImplementedInterfaces.Keys) {
|
||||
var git = ifaceInfo.typeReference as GenericInstanceType;
|
||||
foreach (var ifaceMethod in ifaceInfo.typeDef.methods.getAll()) {
|
||||
foreach (var ifaceMethod in ifaceInfo.typeDef.methods.getValues()) {
|
||||
MethodReference ifaceMethodReference = ifaceMethod.MethodDefinition;
|
||||
if (git != null)
|
||||
ifaceMethodReference = simpleClone(ifaceMethod.MethodDefinition, git);
|
||||
ifaceMethodsDict[new MethodReferenceAndDeclaringTypeKey(ifaceMethodReference)] = ifaceMethod;
|
||||
}
|
||||
}
|
||||
foreach (var classMethod in methods.getAll()) {
|
||||
foreach (var classMethod in methods.getValues()) {
|
||||
if (!classMethod.isVirtual())
|
||||
continue;
|
||||
foreach (var overrideMethod in classMethod.MethodDefinition.Overrides) {
|
||||
|
@ -694,7 +694,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
virtualMethodInstances.initializeFrom(baseType.typeDef.virtualMethodInstances, baseType.typeReference as GenericInstanceType);
|
||||
|
||||
// Figure out which methods we override in the base class
|
||||
foreach (var methodDef in methods.getAll()) {
|
||||
foreach (var methodDef in methods.getValues()) {
|
||||
if (!methodDef.isVirtual() || methodDef.isNewSlot())
|
||||
continue;
|
||||
var methodInstList = virtualMethodInstances.lookup(methodDef.MethodDefinition);
|
||||
|
@ -705,7 +705,7 @@ namespace de4dot.code.renamer.asmmodules {
|
|||
}
|
||||
}
|
||||
|
||||
foreach (var methodDef in methods.getAll()) {
|
||||
foreach (var methodDef in methods.getValues()) {
|
||||
if (!methodDef.isVirtual())
|
||||
continue;
|
||||
virtualMethodInstances.add(new MethodInst(methodDef, methodDef.MethodDefinition));
|
||||
|
|
Loading…
Reference in New Issue
Block a user