Update renamer code so a compiler can compile the decompiled output
- property Byte[]_0 => Byte_0 - property ICollection.Boolean_0 => ICollection.IsSynchronized - property pByte_0 => PByte_0 - property T_0 => Prop_0 - property indexer => Item
This commit is contained in:
parent
0d18298b49
commit
c9d4dc2268
|
@ -222,6 +222,14 @@ namespace de4dot.renamer {
|
||||||
return allTypeInfos.TryGetValue(t, out info);
|
return allTypeInfos.TryGetValue(t, out info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool tryGetEvent(EventDef e, out EventInfo info) {
|
||||||
|
return allEventInfos.TryGetValue(e, out info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool tryGetProperty(PropertyDef p, out PropertyInfo info) {
|
||||||
|
return allPropertyInfos.TryGetValue(p, out info);
|
||||||
|
}
|
||||||
|
|
||||||
public PropertyInfo prop(PropertyDef prop) {
|
public PropertyInfo prop(PropertyDef prop) {
|
||||||
return allPropertyInfos[prop];
|
return allPropertyInfos[prop];
|
||||||
}
|
}
|
||||||
|
|
|
@ -983,19 +983,26 @@ namespace de4dot.renamer {
|
||||||
string newEventName, oldEventName;
|
string newEventName, oldEventName;
|
||||||
var eventInfo = memberInfos.evt(eventDef);
|
var eventInfo = memberInfos.evt(eventDef);
|
||||||
|
|
||||||
|
bool mustUseOldEventName = false;
|
||||||
if (overridePrefix == "")
|
if (overridePrefix == "")
|
||||||
oldEventName = eventInfo.oldName;
|
oldEventName = eventInfo.oldName;
|
||||||
else {
|
else {
|
||||||
var overriddenEventDef = getOverriddenEvent(eventMethod);
|
var overriddenEventDef = getOverriddenEvent(eventMethod);
|
||||||
if (overriddenEventDef == null)
|
if (overriddenEventDef == null)
|
||||||
oldEventName = getRealName(eventInfo.oldName);
|
oldEventName = getRealName(eventInfo.oldName);
|
||||||
|
else {
|
||||||
|
mustUseOldEventName = true;
|
||||||
|
EventInfo info;
|
||||||
|
if (memberInfos.tryGetEvent(overriddenEventDef, out info))
|
||||||
|
oldEventName = getRealName(info.newName);
|
||||||
else
|
else
|
||||||
oldEventName = getRealName(memberInfos.evt(overriddenEventDef).newName);
|
oldEventName = getRealName(overriddenEventDef.EventDefinition.Name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventInfo.renamed)
|
if (eventInfo.renamed)
|
||||||
newEventName = getRealName(eventInfo.newName);
|
newEventName = getRealName(eventInfo.newName);
|
||||||
else if (eventDef.Owner.Module.ObfuscatedFile.NameChecker.isValidEventName(oldEventName))
|
else if (mustUseOldEventName || eventDef.Owner.Module.ObfuscatedFile.NameChecker.isValidEventName(oldEventName))
|
||||||
newEventName = oldEventName;
|
newEventName = oldEventName;
|
||||||
else {
|
else {
|
||||||
mergeStateHelper.merge(MergeStateFlags.Events, scope);
|
mergeStateHelper.merge(MergeStateFlags.Events, scope);
|
||||||
|
@ -1016,10 +1023,20 @@ namespace de4dot.renamer {
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDef getOverriddenEvent(MethodDef overrideMethod) {
|
EventDef getOverriddenEvent(MethodDef overrideMethod) {
|
||||||
var overriddenMethod = modules.resolve(overrideMethod.MethodDefinition.Overrides[0]);
|
var theMethod = overrideMethod.MethodDefinition.Overrides[0];
|
||||||
if (overriddenMethod == null)
|
var overriddenMethod = modules.resolve(theMethod);
|
||||||
return null;
|
if (overriddenMethod != null)
|
||||||
return overriddenMethod.Event;
|
return overriddenMethod.Event;
|
||||||
|
|
||||||
|
var extType = theMethod.DeclaringType;
|
||||||
|
if (extType == null)
|
||||||
|
return null;
|
||||||
|
var extTypeDef = modules.resolveOther(extType);
|
||||||
|
var theMethodDef = extTypeDef.find(theMethod);
|
||||||
|
if (theMethodDef != null)
|
||||||
|
return theMethodDef.Event;
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDef getEventMethod(MethodNameScope scope) {
|
MethodDef getEventMethod(MethodNameScope scope) {
|
||||||
|
@ -1069,20 +1086,29 @@ namespace de4dot.renamer {
|
||||||
var propDef = propMethod.Property;
|
var propDef = propMethod.Property;
|
||||||
var propInfo = memberInfos.prop(propDef);
|
var propInfo = memberInfos.prop(propDef);
|
||||||
|
|
||||||
|
bool mustUseOldPropName = false;
|
||||||
if (overridePrefix == "")
|
if (overridePrefix == "")
|
||||||
oldPropName = propInfo.oldName;
|
oldPropName = propInfo.oldName;
|
||||||
else {
|
else {
|
||||||
var overriddenPropDef = getOverriddenProperty(propMethod);
|
var overriddenPropDef = getOverriddenProperty(propMethod);
|
||||||
if (overriddenPropDef == null)
|
if (overriddenPropDef == null)
|
||||||
oldPropName = getRealName(propInfo.oldName);
|
oldPropName = getRealName(propInfo.oldName);
|
||||||
|
else {
|
||||||
|
mustUseOldPropName = true;
|
||||||
|
PropertyInfo info;
|
||||||
|
if (memberInfos.tryGetProperty(overriddenPropDef, out info))
|
||||||
|
oldPropName = getRealName(info.newName);
|
||||||
else
|
else
|
||||||
oldPropName = getRealName(memberInfos.prop(overriddenPropDef).newName);
|
oldPropName = getRealName(overriddenPropDef.PropertyDefinition.Name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propInfo.renamed)
|
if (propInfo.renamed)
|
||||||
newPropName = getRealName(propInfo.newName);
|
newPropName = getRealName(propInfo.newName);
|
||||||
else if (propDef.Owner.Module.ObfuscatedFile.NameChecker.isValidPropertyName(oldPropName))
|
else if (mustUseOldPropName || propDef.Owner.Module.ObfuscatedFile.NameChecker.isValidPropertyName(oldPropName))
|
||||||
newPropName = oldPropName;
|
newPropName = oldPropName;
|
||||||
|
else if (isItemProperty(scope))
|
||||||
|
newPropName = "Item";
|
||||||
else {
|
else {
|
||||||
var propPrefix = getSuggestedPropertyName(scope) ?? getNewPropertyNamePrefix(scope);
|
var propPrefix = getSuggestedPropertyName(scope) ?? getNewPropertyNamePrefix(scope);
|
||||||
mergeStateHelper.merge(MergeStateFlags.Properties, scope);
|
mergeStateHelper.merge(MergeStateFlags.Properties, scope);
|
||||||
|
@ -1102,11 +1128,29 @@ namespace de4dot.renamer {
|
||||||
return newPropName;
|
return newPropName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isItemProperty(MethodNameScope scope) {
|
||||||
|
foreach (var method in scope.Methods) {
|
||||||
|
if (method.Property != null && method.Property.isItemProperty())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
PropertyDef getOverriddenProperty(MethodDef overrideMethod) {
|
PropertyDef getOverriddenProperty(MethodDef overrideMethod) {
|
||||||
var overriddenMethod = modules.resolve(overrideMethod.MethodDefinition.Overrides[0]);
|
var theMethod = overrideMethod.MethodDefinition.Overrides[0];
|
||||||
if (overriddenMethod == null)
|
var overriddenMethod = modules.resolve(theMethod);
|
||||||
return null;
|
if (overriddenMethod != null)
|
||||||
return overriddenMethod.Property;
|
return overriddenMethod.Property;
|
||||||
|
|
||||||
|
var extType = theMethod.DeclaringType;
|
||||||
|
if (extType == null)
|
||||||
|
return null;
|
||||||
|
var extTypeDef = modules.resolveOther(extType);
|
||||||
|
var theMethodDef = extTypeDef.find(theMethod);
|
||||||
|
if (theMethodDef != null)
|
||||||
|
return theMethodDef.Property;
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDef getPropertyMethod(MethodNameScope scope) {
|
MethodDef getPropertyMethod(MethodNameScope scope) {
|
||||||
|
@ -1132,10 +1176,12 @@ namespace de4dot.renamer {
|
||||||
const string defaultVal = "Prop_";
|
const string defaultVal = "Prop_";
|
||||||
|
|
||||||
var propType = getPropertyType(scope);
|
var propType = getPropertyType(scope);
|
||||||
if (propType == null || propType is GenericInstanceType)
|
if (propType == null || propType is GenericInstanceType || propType is GenericParameter)
|
||||||
return defaultVal;
|
return defaultVal;
|
||||||
|
|
||||||
string name = propType.Name;
|
var prefix = getPrefix(propType);
|
||||||
|
|
||||||
|
string name = propType.GetElementType().Name;
|
||||||
int i;
|
int i;
|
||||||
if ((i = name.IndexOf('`')) >= 0)
|
if ((i = name.IndexOf('`')) >= 0)
|
||||||
name = name.Substring(0, i);
|
name = name.Substring(0, i);
|
||||||
|
@ -1143,7 +1189,21 @@ namespace de4dot.renamer {
|
||||||
name = name.Substring(i + 1);
|
name = name.Substring(i + 1);
|
||||||
if (name == "")
|
if (name == "")
|
||||||
return defaultVal;
|
return defaultVal;
|
||||||
return name + "_";
|
|
||||||
|
return prefix.ToUpperInvariant() + upperFirst(name) + "_";
|
||||||
|
}
|
||||||
|
|
||||||
|
static string upperFirst(string s) {
|
||||||
|
return s.Substring(0, 1).ToUpperInvariant() + s.Substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static string getPrefix(TypeReference typeRef) {
|
||||||
|
string prefix = "";
|
||||||
|
while (typeRef is PointerType) {
|
||||||
|
typeRef = ((PointerType)typeRef).ElementType;
|
||||||
|
prefix += "p";
|
||||||
|
}
|
||||||
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PropertyMethodType {
|
enum PropertyMethodType {
|
||||||
|
|
|
@ -216,8 +216,12 @@ namespace de4dot.renamer {
|
||||||
string propName = propInfo.oldName;
|
string propName = propInfo.oldName;
|
||||||
if (!NameChecker.isValidPropertyName(propName))
|
if (!NameChecker.isValidPropertyName(propName))
|
||||||
propName = propInfo.suggestedName;
|
propName = propInfo.suggestedName;
|
||||||
if (!NameChecker.isValidPropertyName(propName))
|
if (!NameChecker.isValidPropertyName(propName)) {
|
||||||
|
if (propDef.isItemProperty())
|
||||||
|
propName = "Item";
|
||||||
|
else
|
||||||
propName = variableNameState.getNewPropertyName(propDef.PropertyDefinition);
|
propName = variableNameState.getNewPropertyName(propDef.PropertyDefinition);
|
||||||
|
}
|
||||||
variableNameState.addPropertyName(propName);
|
variableNameState.addPropertyName(propName);
|
||||||
propInfo.rename(propName);
|
propInfo.rename(propName);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace de4dot.renamer {
|
||||||
return addTypeName(typeFullName, newName, prefix).create();
|
return addTypeName(typeFullName, newName, prefix).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
string getPrefix(TypeReference typeRef) {
|
static string getPrefix(TypeReference typeRef) {
|
||||||
string prefix = "";
|
string prefix = "";
|
||||||
while (typeRef is PointerType) {
|
while (typeRef is PointerType) {
|
||||||
typeRef = ((PointerType)typeRef).ElementType;
|
typeRef = ((PointerType)typeRef).ElementType;
|
||||||
|
@ -153,7 +153,7 @@ namespace de4dot.renamer {
|
||||||
|
|
||||||
class PropertyNameCreator : TypeNames {
|
class PropertyNameCreator : TypeNames {
|
||||||
protected override string fixName(string prefix, string name) {
|
protected override string fixName(string prefix, string name) {
|
||||||
return prefix + upperFirst(name);
|
return prefix.ToUpperInvariant() + upperFirst(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -324,7 +324,7 @@ namespace de4dot.renamer.asmmodules {
|
||||||
|
|
||||||
AssemblyKeyDictionary<TypeDef> typeToTypeDefDict = new AssemblyKeyDictionary<TypeDef>();
|
AssemblyKeyDictionary<TypeDef> typeToTypeDefDict = new AssemblyKeyDictionary<TypeDef>();
|
||||||
ExternalAssemblies externalAssemblies = new ExternalAssemblies();
|
ExternalAssemblies externalAssemblies = new ExternalAssemblies();
|
||||||
TypeDef resolveOther(TypeReference type) {
|
public TypeDef resolveOther(TypeReference type) {
|
||||||
if (type == null)
|
if (type == null)
|
||||||
return null;
|
return null;
|
||||||
type = type.GetElementType();
|
type = type.GetElementType();
|
||||||
|
|
|
@ -51,5 +51,13 @@ namespace de4dot.renamer.asmmodules {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool isItemProperty() {
|
||||||
|
if (GetMethod != null && GetMethod.ParamDefs.Count >= 1)
|
||||||
|
return true;
|
||||||
|
if (SetMethod != null && SetMethod.ParamDefs.Count >= 2)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user