private void DumpMethod(int tabs, MethodKey key, ObfuscatedThing method, bool isLast) { var oldSig = $"{GetRawTypeName(key.Method.ReturnType.FullName)} {method.Name}"; if (key.Method.GenericParameters.Count > 0) { oldSig += "<"; for (var i = 0; i < key.Method.GenericParameters.Count; ++i) { oldSig += i > 0 ? ", " : ""; oldSig += GetRawTypeName(key.Method.GenericParameters[i].FullName); } oldSig += ">"; } oldSig += "("; for (var i = 0; i < key.Count; ++i) { oldSig += i > 0 ? ", " : ""; oldSig += GetRawTypeName(key.ParamTypes[i]); } oldSig += ")"; var newSig = method.StatusText; WriteLine(tabs, $"\"{oldSig}\": \"{newSig}\"{(isLast ? "" : ",")}"); }
internal static bool PropertyMatch(PropertyDefinition candidate, PropertyDefinition property) { return((MethodKey.MethodMatch(candidate.GetMethod, property.GetMethod) && MethodKey.MethodMatch(candidate.SetMethod, property.SetMethod)) || (MethodKey.MethodMatch(property.GetMethod, candidate.GetMethod) && MethodKey.MethodMatch(property.SetMethod, candidate.SetMethod))); }
public bool ShouldSkipStringHiding(MethodKey method, InheritMap map, bool projectHideStrings) { if (method.DeclaringType.IsResourcesType() && method.Method.ReturnType.FullName == "System.Resources.ResourceManager") { return(true); // IMPORTANT: avoid hiding resource type name, as it might be renamed later. } if (ShouldForce(method.TypeKey, TypeAffectFlags.AffectString, map)) { return(false); } if (forceStringHiding.IsMatch(method, map)) { return(false); } if (ShouldSkip(method.TypeKey, TypeAffectFlags.AffectString, map)) { return(true); } if (skipStringHiding.IsMatch(method, map)) { return(true); } return(!projectHideStrings); }
public bool ShouldSkip(MethodKey method, InheritMap map, bool keepPublicApi, bool hidePrivateApi, bool markedOnly, out string message) { if (method.Method.IsRuntime) { message = "runtime method"; return(true); } if (method.Method.IsSpecialName) { switch (method.Method.SemanticsAttributes) { case MethodSemanticsAttributes.Getter: case MethodSemanticsAttributes.Setter: message = "skipping properties"; return(!project.Settings.RenameProperties); case MethodSemanticsAttributes.AddOn: case MethodSemanticsAttributes.RemoveOn: message = "skipping events"; return(!project.Settings.RenameEvents); default: message = "special name"; return(true); } } return(ShouldSkipParams(method, map, keepPublicApi, hidePrivateApi, markedOnly, out message)); }
private void DumpMethod(MethodKey key, ObfuscatedThing info) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}(", info.Name); for (int i = 0; i < key.Count; i++) { if (i > 0) { sb.Append(","); } sb.Append(key.ParamTypes[i]); } sb.Append(")"); if (info.Status == ObfuscationStatus.Renamed) { writer.WriteStartElement("renamedMethod"); writer.WriteAttributeString("oldName", sb.ToString()); writer.WriteAttributeString("newName", info.StatusText); writer.WriteEndElement(); writer.WriteString("\r\n"); } else { writer.WriteStartElement("skippedMethod"); writer.WriteAttributeString("name", sb.ToString()); writer.WriteAttributeString("reason", info.StatusText); writer.WriteEndElement(); writer.WriteString("\r\n"); } }
private void DumpMethod(MethodKey key, ObfuscatedThing info) { writer.Write("\t{0}(", info.Name); for (int i = 0; i < key.Count; i++) { if (i > 0) { writer.Write(", "); } else { writer.Write(" "); } writer.Write(key.ParamTypes[i]); } if (info.Status == ObfuscationStatus.Renamed) { writer.WriteLine(" ) -> {0}", info.StatusText); } else { Debug.Assert(info.Status == ObfuscationStatus.Skipped, "Status is expected to be either Renamed or Skipped."); writer.WriteLine(" ) skipped: {0}", info.StatusText); } }
public bool ShouldSkipParams(MethodKey method, InheritMap map, bool keepPublicApi, bool hidePrivateApi, bool markedOnly, out string message) { var attribute = method.Method.MarkedToRename(); // skip runtime methods if (attribute != null) { message = "attribute"; return(!attribute.Value); } var parent = method.DeclaringType.MarkedToRename(); if (parent != null) { message = "type attribute"; return(!parent.Value); } if (markedOnly) { message = "MarkedOnly option in configuration"; return(true); } if (ShouldForce(method.TypeKey, TypeAffectFlags.AffectMethod, map)) { message = "type rule in configuration"; return(false); } if (forceMethods.IsMatch(method, map)) { message = "method rule in configuration"; return(false); } if (ShouldSkip(method.TypeKey, TypeAffectFlags.AffectMethod, map)) { message = "type rule in configuration"; return(true); } if (skipMethods.IsMatch(method, map)) { message = "method rule in configuration"; return(true); } if (method.DeclaringType.IsTypePublic() && method.Method.IsPublic()) { message = "KeepPublicApi option in configuration"; return(keepPublicApi); } message = "HidePrivateApi option in configuration"; return(!hidePrivateApi); }
public bool ShouldSkipStringHiding(MethodKey method, InheritMap map) { if (ShouldSkip(method.TypeKey, TypeSkipFlags.SkipStringHiding, map)) { return(true); } return(skipStringHiding.IsMatch(method, map)); }
public bool ShouldSkipStringHiding(MethodKey method, InheritMap map, bool hidePrivateApi) { if (ShouldSkip(method.TypeKey, TypeAffectFlags.SkipStringHiding, map)) { return(true); } return(skipStringHiding.IsMatch(method, map)); }
internal bool ShouldSkip(MethodKey method) { if (ShouldSkip(method.TypeKey, TypeSkipFlags.SkipMethod)) { return(true); } return(skipMethods.IsMatch(method)); }
internal bool ShouldSkipStringHiding(MethodKey method) { if (ShouldSkip(method.TypeKey, TypeSkipFlags.SkipStringHiding)) { return(true); } return(skipStringHiding.IsMatch(method)); }
private void MatchMethodGroup(MethodDefinition method, MethodGroup newGroup, Project project) { foreach (var baseMethod in type.TypeDefinition.Methods) { if (MethodKey.MethodMatch(baseMethod, method) || MethodKey.MethodMatch(method, baseMethod)) { newGroup.Methods.Add(new MethodKey(baseMethod)); newGroup.External |= !project.Contains(type); } } }
public MethodGroup GetMethodGroup(MethodKey methodKey) { MethodGroup group; if (methodGroups.TryGetValue(methodKey, out group)) { return(group); } else { return(null); } }
public ObfuscatedThing GetMethod(MethodKey key) { ObfuscatedClass c = GetClass(key.TypeKey); ObfuscatedThing t; if (!c.Methods.TryGetValue(key, out t)) { t = new ObfuscatedThing(key.ToString()); c.Methods[key] = t; } return(t); }
public bool ShouldSkip(MethodKey method, InheritMap map, bool keepPublicApi, bool hidePrivateApi) { if (ShouldSkip(method.TypeKey, TypeSkipFlags.SkipMethod, map, hidePrivateApi)) { return(true); } if (skipMethods.IsMatch(method, map)) { return(true); } return(method.ShouldSkip(keepPublicApi, hidePrivateApi)); }
public virtual bool Matches(MemberReference member) { FieldReference fieldRef = member as FieldReference; if (fieldRef != null) { if (Name == fieldRef.Name && TypeKey.Matches(fieldRef.DeclaringType)) { return(MethodKey.TypeMatch(Type, fieldRef.FieldType)); } } return(false); }
public bool ShouldSkip(MethodKey method, InheritMap map, bool keepPublicApi, bool hidePrivateApi, bool markedOnly, out string message) { if (method.Method.IsRuntime) { message = "runtime method"; return(true); } if (method.Method.IsSpecialName) { switch (method.Method.SemanticsAttributes) { case MethodSemanticsAttributes.None: // Do nothing, most likely this is a dangling accessor method without // associated event or property break; case MethodSemanticsAttributes.Getter: case MethodSemanticsAttributes.Setter: message = "skipping properties"; if (!project.Settings.RenameProperties) { return(true); } break; case MethodSemanticsAttributes.AddOn: case MethodSemanticsAttributes.RemoveOn: message = "skipping events"; if (!project.Settings.RenameEvents) { return(true); } break; default: message = "special name"; return(true); } } return(ShouldSkipParams(method, map, keepPublicApi, hidePrivateApi, markedOnly, out message)); }
MethodGroup AddToGroup(MethodGroup group, MethodKey methodKey) { // add the method to the group group.Methods.Add(methodKey); // point the method at the group MethodGroup group2; if (methodGroups.TryGetValue(methodKey, out group2) && group2 != group) { // we have a problem; two unrelated groups come together; merge them if (group.Methods.Count > group2.Methods.Count) { group.Name = group.Name ?? group2.Name; group.External = group.External | group2.External; foreach (MethodKey mk in group2.Methods) { methodGroups[mk] = group; group.Methods.Add(mk); } return(group); } else { group2.Name = group2.Name ?? group.Name; group2.External = group2.External | group.External; foreach (MethodKey mk in group.Methods) { methodGroups[mk] = group2; group2.Methods.Add(mk); } return(group2); } } methodGroups[methodKey] = group; return(group); }
public bool ShouldSkipStringHiding(MethodKey method, InheritMap map, bool projectHideStrings) { if (method.DeclaringType.IsResourcesType() && method.Method.ReturnType.FullName == "System.Resources.ResourceManager") { return(true); // IMPORTANT: avoid hiding resource type name, as it might be renamed later. } if (ShouldForce(method.TypeKey, TypeAffectFlags.AffectString, map)) { return(false); } if (forceStringHiding.IsMatch(method, map)) { return(false); } if (ShouldSkip(method.TypeKey, TypeAffectFlags.AffectString, map)) { return(true); } if (skipStringHiding.IsMatch(method, map)) { return(true); } // // Check if Exclude = true and ApplyToMembers is set on the owning method. // if (!(method.Method.MarkedToRename(true) ?? true)) { return(true); } return(!projectHideStrings); }
public bool ShouldSkipStringHiding(MethodKey method, InheritMap map, bool projectHideStrings) { if (ShouldForce(method.TypeKey, TypeAffectFlags.AffectString, map)) { return(false); } if (forceStringHiding.IsMatch(method, map)) { return(false); } if (ShouldSkip(method.TypeKey, TypeAffectFlags.AffectString, map)) { return(true); } if (skipStringHiding.IsMatch(method, map)) { return(true); } return(!projectHideStrings); }
public void UpdateMethod(MethodKey key, ObfuscationStatus status, string text) { ObfuscatedThing m = GetMethod(key); m.Update(status, text); }
public void ForceSkip(MethodKey method) { skipMethods.Add(new MethodTester(method)); }
static bool MethodsMatch(MethodKey left, MethodKey right) { return(MethodKey.MethodMatch(left.Method, right.Method) || MethodKey.MethodMatch(right.Method, left.Method)); }
public MethodGroup GetMethodGroup(MethodKey methodKey) { return(methodGroups.ContainsKey(methodKey) ? methodGroups[methodKey] : null); }
static bool MethodsMatch(MethodKey[] methods, int i, int j) { return(MethodKey.MethodMatch(methods [i].Method, methods [j].Method)); }