private void Load(BuildType type) { _existingStrings.TryAdd(type.Name); LoadNamespace(type.Namespace); if (type.NameChanged) { _existingStrings.TryAdd(type.NewName); } if (type.NamespaceChanged) { LoadNamespace(type.NewNamespace); } foreach (BuildMethod method in type.Methods) { _existingStrings.TryAdd(method.Name); if (method.NameChanged) { _existingStrings.TryAdd(method.NewName); } } foreach (BuildField field in type.Fields) { _existingStrings.TryAdd(field.Name); if (field.NameChanged) { _existingStrings.TryAdd(field.NewName); } } foreach (BuildProperty property in type.Properties) { _existingStrings.TryAdd(property.Name); if (property.NameChanged) { _existingStrings.TryAdd(property.NewName); } } foreach (BuildEvent e in type.Events) { _existingStrings.TryAdd(e.Name); if (e.NameChanged) { _existingStrings.TryAdd(e.NewName); } } foreach (BuildType nestedType in type.NestedTypes) { Load(nestedType); } }
private static void AnalyzeType(BuildType type) { if (type.IsInterface) { return; } if (type.SealTypeProcessed && !type.SealType) { return; } var baseType = ((IType)type).BaseType; while (baseType != null) { baseType = baseType.DeclaringType; type = baseType as BuildType; if (type != null) { if (type.SealTypeProcessed && !type.SealType) { break; } type.SealType = false; type.SealTypeProcessed = true; } baseType = baseType.BaseType; } }
private void Enqueue(BuildType type) { if (!type.StripProcessed) { type.StripProcessed = true; _queue.Enqueue(type); } }
private void UnstripAndEnqueue(BuildType type) { if (type.Strip) { type.Strip = false; Enqueue(type); } }
public static void Analyze(BuildType type) { AnalyzeType(type); foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
private bool CanStrip(BuildType type) { if (type.IsGlobal()) { return(false); } return(true); }
private void MapCustomAttributeArguments( CustomAttributeNamedArgumentCollection arguments, BuildType type) { // Collect fields var fields = new Dictionary<string, BuildField>(); foreach (BuildField field in type.Fields) { if (!fields.ContainsKey(field.Name)) fields.Add(field.Name, field); } // Collect properties var properties = new Dictionary<string, BuildProperty>(); foreach (BuildProperty property in type.Properties) { if (!properties.ContainsKey(property.Name)) properties.Add(property.Name, property); } // Map for (int i = 0; i < arguments.Count; i++) { var argument = arguments[i]; switch (argument.Type) { case CustomAttributeNamedArgumentType.Field: { BuildField field; if (fields.TryGetValue(argument.Name, out field)) { if (MapCustomAttributeFieldArgument(ref argument, field)) { arguments[i] = argument; } } } break; case CustomAttributeNamedArgumentType.Property: { BuildProperty property; if (properties.TryGetValue(argument.Name, out property)) { if (MapCustomAttributePropertyArgument(ref argument, property)) { arguments[i] = argument; } } } break; default: throw new InvalidOperationException(); } } }
public static void Analyze(BuildType type) { if (!IsBaseTypeValid(type)) { UnmarkMethods(type); } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
private void Analyze(BuildType type) { if (IsConfigurationSettings(type)) { ProcessConfigurationSettings(type); } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
private void Map(BuildType type) { foreach (BuildMethod method in type.Methods) { Map(method); } foreach (BuildType nestedType in type.NestedTypes) { Map(nestedType); } }
private void Analyze(BuildType type) { foreach (BuildField field in type.Fields) { Analyze(field); } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
private bool Build(ref TypeReference typeRef, BuildType type) { bool changed = false; // Name string name; if (type.NameChanged) { name = type.NewName; changed = true; } else { name = type.Name; } // Namespace string ns; if (type.NamespaceChanged) { ns = type.NewNamespace; changed = true; } else { ns = type.Namespace; } // Owner var owner = typeRef.Owner; if (type.IsNested) { var enclosingTypeRef = (TypeReference)owner; var enclosingType = (BuildType)type.GetEnclosingType(); if (Build(ref enclosingTypeRef, enclosingType)) { owner = enclosingTypeRef; changed = true; } } else if (owner != null) { changed |= Build(ref owner); } if (!changed) return false; bool isValueType = typeRef.IsValueType.HasValue ? typeRef.IsValueType.Value : type.IsValueType(); typeRef = new TypeReference(name, ns, owner, isValueType); return true; }
private void ObfuscateControlFlow(BuildType type) { foreach (BuildMethod method in type.Methods) { ObfuscateControlFlow(method); } foreach (BuildType nestedType in type.NestedTypes) { ObfuscateControlFlow(nestedType); } }
private void Analyze(BuildType type) { foreach (BuildMethod method in type.Methods) { Analyze(method); } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
private bool IsConfigurationSettings(BuildType type) { if (type.Name != "SettingsBase") { return(false); } if (type.Namespace != "System.Configuration") { return(false); } return(true); }
private void Analyze(BuildType type) { if (type.Strip) { type.Strip = CanStrip(type); } if (!type.Strip) { Enqueue(type); } foreach (BuildMethod method in type.Methods) { if (!method.Strip) { Enqueue(method); } } foreach (BuildField field in type.Fields) { if (!field.Strip) { Enqueue(field); } } foreach (BuildProperty property in type.Properties) { if (!property.Strip) { Enqueue(property); } } foreach (BuildEvent e in type.Events) { if (!e.Strip) { Enqueue(e); } } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
public static void Strip(BuildType type) { if (type.IsMainType) { return; } if (type.StripObfuscationAttribute) { CA.ObfuscationAttribute.RemoveMarkedAsStrip(type.CustomAttributes); } foreach (BuildMethod method in type.Methods) { if (method.StripObfuscationAttribute) { CA.ObfuscationAttribute.RemoveMarkedAsStrip(method.CustomAttributes); } } foreach (BuildField field in type.Fields) { if (field.StripObfuscationAttribute) { CA.ObfuscationAttribute.RemoveMarkedAsStrip(field.CustomAttributes); } } foreach (BuildProperty property in type.Properties) { if (property.StripObfuscationAttribute) { CA.ObfuscationAttribute.RemoveMarkedAsStrip(property.CustomAttributes); } } foreach (BuildEvent e in type.Events) { if (e.StripObfuscationAttribute) { CA.ObfuscationAttribute.RemoveMarkedAsStrip(e.CustomAttributes); } } foreach (BuildType nestedType in type.NestedTypes) { Strip(nestedType); } }
private void Build(BuildType type) { foreach (BuildMethod method in type.Methods) { if (method.EncryptIL) { Build(method); } } foreach (BuildType nestedType in type.NestedTypes) { Build(nestedType); } }
private bool GetMemberChangedName(BuildType type, string name, out string newName) { newName = null; // Property var property = type.Properties.Find(name) as BuildProperty; if (property != null) { if (property.NameChanged) { newName = property.Name; return(true); } return(false); } // Event var e = type.Events.Find(name) as BuildEvent; if (e != null) { if (e.NameChanged) { newName = e.Name; return(true); } return(false); } // Field var field = type.Fields.Find(name) as BuildField; if (field != null) { if (field.NameChanged) { newName = field.Name; return(true); } return(false); } return(false); }
private void GenerateMembers(BuildType type) { Reset(); GenerateMethods(type.Methods); GenerateFields(type.Fields); GenerateProperties(type.Properties); GenerateEvents(type.Events); Reset(); GenerateNestedTypes(type.NestedTypes); foreach (BuildType nestedType in type.NestedTypes) { GenerateMembers(nestedType); } }
private static void Obfuscate(BuildType type, bool ignoreEncryptIL) { if (type.IsMainType) { return; } foreach (BuildMethod method in type.Methods) { Obfuscate(method, ignoreEncryptIL); } foreach (BuildType nestedType in type.NestedTypes) { Obfuscate(nestedType, ignoreEncryptIL); } }
public static void Build(BuildType type) { if (type.IsMainType) { return; } foreach (BuildMethod method in type.Methods) { Build(method); } foreach (BuildType nestedType in type.NestedTypes) { Build(nestedType); } }
private bool GetChangedFieldName(BuildType type, ref string name) { foreach (BuildField field in type.Fields) { if (field.Name == name) { if (!field.NameChanged) { return(false); } name = field.NewName; return(true); } } return(false); }
private bool GetChangedPropertyName(BuildType type, ref string name) { foreach (BuildProperty property in type.Properties) { if (property.Name == name) { if (!property.NameChanged) { return(false); } name = property.NewName; return(true); } } return(false); }
public static void Analyze(BuildType type) { if (type.IsInterface) { return; } var slots = new MethodSlotList(type); foreach (var slot in slots) { Analyze(slot); } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
public static void Change(BuildType type) { if (type.NameChanged) { type.Name = type.NewName; foreach (var genericParameter in type.GenericParameters) { genericParameter.Name = null; } } if (type.NamespaceChanged) { type.Namespace = type.NewNamespace; } foreach (BuildMethod method in type.Methods) { Change(method); } foreach (BuildField field in type.Fields) { Change(field); } foreach (BuildProperty property in type.Properties) { Change(property); } foreach (BuildEvent e in type.Events) { Change(e); } foreach (BuildType nestedType in type.NestedTypes) { Change(nestedType); } }
private bool MapTypeNameToken(ref string typeToken, out BuildType type) { type = null; var typeName = XamlTypeName.Parse(typeToken); if (typeName == null) { return(false); } if (string.IsNullOrEmpty(typeName.Prefix)) { return(false); } bool changed = MapTypeName(typeName, out type); if (typeName.HasTypeArgs) { var typeArguments = typeName.TypeArguments; for (int i = 0; i < typeArguments.Count; i++) { var typeArg = typeArguments[i]; BuildType notUsedType; if (MapTypeName(typeArg, out notUsedType)) { typeArguments[i] = typeArg; changed = true; } } } if (changed) { typeToken = typeName.ToString(); } return(changed); }
private void Analyze(BuildType type) { var attr = CA.BindableAttribute.FindFirst(type.CustomAttributes); if (attr != null && attr.Bindable) { if (!_renameBindableMembers) { type.Rename = false; } type.Strip = false; } foreach (BuildMethod method in type.Methods) { Analyze(method); } foreach (BuildField field in type.Fields) { Analyze(field); } foreach (BuildProperty property in type.Properties) { Analyze(property); } foreach (BuildEvent e in type.Events) { Analyze(e); } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType); } }
public static void Seal(BuildType type) { if (type.IsMainType) { return; } if (type.IsInterface) { return; } if (type.SealType && !type.IsSealed) { type.IsSealed = true; } foreach (BuildType nestedType in type.NestedTypes) { Seal(nestedType); } }
private void Analyze(BuildType type, bool serializable) { LoadSerializableAttributes(ref serializable, type.CustomAttributes); if (serializable) { if (!_renameSerializableMembers) { type.Rename = false; } type.Strip = false; } foreach (BuildMethod method in type.Methods) { Analyze(method, serializable); } foreach (BuildField field in type.Fields) { Analyze(field, serializable); } foreach (BuildProperty property in type.Properties) { Analyze(property, serializable); } foreach (BuildEvent e in type.Events) { Analyze(e, serializable); } foreach (BuildType nestedType in type.NestedTypes) { Analyze(nestedType, serializable); } }