/// <summary> /// Creates a <see cref="SecurityAttribute"/> from an XML string. /// </summary> /// <param name="module">Owner module</param> /// <param name="xml">XML</param> /// <returns>A new <see cref="SecurityAttribute"/> instance</returns> public static SecurityAttribute CreateFromXml(ModuleDef module, string xml) { var attrType = module.CorLibTypes.GetTypeRef("System.Security.Permissions", "PermissionSetAttribute"); var utf8Xml = new UTF8String(xml); var namedArg = new CANamedArgument(false, module.CorLibTypes.String, "XML", new CAArgument(module.CorLibTypes.String, utf8Xml)); var list = ThreadSafeListCreator.Create<CANamedArgument>(namedArg); return new SecurityAttribute(attrType, list); }
void Load(CANamedArgument obj) { if (obj == null) return; Add(obj.Type); Add(obj.Name); Load(obj.Argument); }
/// <summary> /// Creates a <see cref="SecurityAttribute"/> from an XML string. /// </summary> /// <param name="module">Owner module</param> /// <param name="xml">XML</param> /// <returns>A new <see cref="SecurityAttribute"/> instance</returns> public static SecurityAttribute CreateFromXml(ModuleDef module, string xml) { var attrType = module.CorLibTypes.GetTypeRef("System.Security.Permissions", "PermissionSetAttribute"); var utf8Xml = new UTF8String(xml); var namedArg = new CANamedArgument(false, module.CorLibTypes.String, "XML", new CAArgument(module.CorLibTypes.String, utf8Xml)); var list = ThreadSafeListCreator.Create <CANamedArgument>(namedArg); return(new SecurityAttribute(attrType, list)); }
void Add(CANamedArgument arg) { if (arg == null) { return; } Add(arg.Type); Add(arg.Argument); }
void Load(CANamedArgument obj) { if (obj is null) { return; } Add(obj.Type); Add(obj.Name); Load(obj.Argument); }
void InitializeFrom(CANamedArgument namedArg, TypeSigCreatorOptions options) { if (CAArgumentVM != null) CAArgumentVM.PropertyChanged -= caArgumentVM_PropertyChanged; CAArgumentVM = new CAArgumentVM(ownerModule, namedArg.Argument, options, null); OnPropertyChanged(nameof(CAArgumentVM)); CAArgumentVM.PropertyChanged += caArgumentVM_PropertyChanged; Name = namedArg.Name; IsField = namedArg.IsField; ITypeDefOrRef newEnumType; ConstantTypeEnumList.SelectedItem = GetConstantType(namedArg.Type, out newEnumType); EnumType = newEnumType; CAArgumentVM.StorageType = GetType((ConstantType)ConstantTypeEnumList.SelectedItem); }
public CANamedArgumentVM(ModuleDef ownerModule, CANamedArgument namedArg, TypeSigCreatorOptions options) { this.ownerModule = ownerModule; originalNamedArg = namedArg.Clone(); ConstantTypeEnumList = new EnumListVM(ConstantTypeVM.CreateEnumArray(validTypes), (a, b) => OnConstantTypeChanged()); NamedArgTypeEnumList = new EnumListVM(namedArgTypeEnumList, (a, b) => OnNamedArgTypeChanged()); InitializeFrom(namedArg, options); modified = false; }
void Add(CANamedArgument obj) { AddToStack(obj); }
void Add(CANamedArgument arg) { if (arg == null) return; Add(arg.Type); Add(arg.Argument); }
/// <summary> /// Creates a custom ObfuscationAttribute that can be added to a method. /// </summary> /// <param name="module">Module</param> /// <param name="feature">Obfuscation feature name</param> /// <param name="exclude">true if exclude, false if include</param> /// <returns>CustomAttribute</returns> CustomAttribute CreateAttribute(ModuleDef module, String feature, Boolean exclude) { TypeSig stringSig = module.CorLibTypes.String; TypeSig booleanSig = module.CorLibTypes.Boolean; CANamedArgument[] args = new CANamedArgument[] { // Feature new CANamedArgument( false, stringSig, "Feature", new CAArgument(stringSig, feature)), // Exclude new CANamedArgument( false, booleanSig, "Exclude", new CAArgument(booleanSig, exclude)) }; TypeRef obfuscationRef = new TypeRefUser( module, "System.Reflection", "ObfuscationAttribute", module.CorLibTypes.AssemblyRef); MemberRef obfuscationCtor = new MemberRefUser(module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), obfuscationRef); CustomAttribute attr = new CustomAttribute( obfuscationCtor, new CAArgument[0], args ); return attr; }