public ExportedType(string @namespace, string name, ModuleDefinition module, IMetadataScope scope)
 {
     this.@namespace = @namespace;
     this.name = name;
     this.scope = scope;
     this.module = module;
 }
 public static Collection<CustomAttribute> GetCustomAttributes(
     this ICustomAttributeProvider self,
     ref Collection<CustomAttribute> variable,
     ModuleDefinition module)
 {
     return module.HasImage()
         ? module.Read(ref variable, self, (provider, reader) => reader.ReadCustomAttributes(provider))
         : variable = new Collection<CustomAttribute>();
 }
        void CopyTo(CustomAttribute target, ModuleDefinition context)
        {
            foreach (var arg in ConstructorArguments)
                target.ConstructorArguments.Add(new CustomAttributeArgument(context.Import(arg.Type), arg.Value));

            foreach (var field in Fields)
                target.Fields.Add(new CustomAttributeNamedArgument(field.Name, new CustomAttributeArgument(context.Import(field.Argument.Type), field.Argument.Value)));

            foreach (var prop in Properties)
                target.Properties.Add(new CustomAttributeNamedArgument(prop.Name, new CustomAttributeArgument(context.Import(prop.Argument.Type), prop.Argument.Value)));
        }
 public TypeReference(string @namespace, string name, ModuleDefinition module, IMetadataScope scope, bool valueType)
     : this(@namespace, name, module, scope)
 {
     value_type = valueType;
 }
 public static Collection<SecurityDeclaration> GetSecurityDeclarations(
     this ISecurityDeclarationProvider self,
     ref Collection<SecurityDeclaration> variable,
     ModuleDefinition module)
 {
     return module.HasImage()
         ? module.Read(ref variable, self, (provider, reader) => reader.ReadSecurityDeclarations(provider))
         : variable = new Collection<SecurityDeclaration>();
 }
 public static bool GetHasSecurityDeclarations(
     this ISecurityDeclarationProvider self,
     ModuleDefinition module)
 {
     return module.HasImage() && module.Read(self, (provider, reader) => reader.HasSecurityDeclarations(provider));
 }
 internal SecurityDeclaration(SecurityAction action, uint signature, ModuleDefinition module)
 {
     this.action = action;
     this.signature = signature;
     this.module = module;
 }
        static TypeDefinition GetTypeDefinition(ModuleDefinition module, TypeReference type)
        {
            if (!type.IsNested)
                return module.GetType(type.Namespace, type.Name);

            var declaring_type = type.DeclaringType.Resolve();
            if (declaring_type == null)
                return null;

            return declaring_type.GetNestedType(type.TypeFullName());
        }
 public static bool GetHasGenericParameters(
     this IGenericParameterProvider self,
     ModuleDefinition module)
 {
     return module.HasImage() && module.Read(self, (provider, reader) => reader.HasGenericParameters(provider));
 }
 public static void PatchAssemblyNames(ModuleDefinition module, string searchToken, Version searchVersion, string replaceToken, Version replaceVersion)
 {
     var references = SearchReferences(module, searchToken, searchVersion).ToList();
     PatchAssemblyNames(references, replaceToken, replaceVersion);
 }
 public static bool GetHasCustomAttributes(
     this ICustomAttributeProvider self,
     ModuleDefinition module)
 {
     return module.HasImage() && module.Read(self, (provider, reader) => reader.HasCustomAttributes(provider));
 }
 public CoreTypeSystem(ModuleDefinition module)
     : base(module)
 {
 }
        internal static TypeSystem CreateTypeSystem(ModuleDefinition module)
        {
            if (module.IsCorlib())
                return new CoreTypeSystem(module);

            return new CommonTypeSystem(module);
        }
        private static TypeReference FixTypeImport(ModuleDefinition context, MethodDefinition source, MethodDefinition target,
            TypeReference type)
        {
            if (type.FullName == source.DeclaringType.FullName)
                return target.DeclaringType;

            return context.Import(type);
        }
        private static MethodReference FixMethodImport(ModuleDefinition context, MethodDefinition source,
            MethodDefinition target, MethodReference method)
        {
            if (method.DeclaringType.FullName == source.DeclaringType.FullName)
                return FindMatchingMethod(target.DeclaringType, method);

            return context.Import(method);
        }
        private static FieldReference FixFieldImport(ModuleDefinition context, MethodDefinition source,
            MethodDefinition target, FieldReference field)
        {
            if (field.DeclaringType.FullName == source.DeclaringType.FullName)
                return FindMatchingField(target.DeclaringType, field);

            return context.Import(field);
        }
 public static IEnumerable<AssemblyNameReference> SearchReferences(ModuleDefinition module, string searchToken,
     Version searchVersion)
 {
     return module.AssemblyReferences.Where(aname => ByteHelper.ByteToString(aname.PublicKeyToken) == searchToken && aname.Version == searchVersion);
 }
 public TypeReference(string @namespace, string name, ModuleDefinition module, IMetadataScope scope)
     : this(@namespace, name)
 {
     this.module = module;
     this.scope = scope;
 }
 // HACK - Reflexil - Ends
 TypeSystem(ModuleDefinition module)
 {
     this.module = module;
 }
 public static TypeDefinition FindMatchingType(ModuleDefinition mdef, string fulltypename)
 {
     return FindMatchingType(mdef.Types, fulltypename);
 }
 internal static CustomAttribute Clone(CustomAttribute custattr, ModuleDefinition context)
 {
     var ca = new CustomAttribute(context.Import(custattr.Constructor));
     custattr.CopyTo(ca, context);
     return ca;
 }
        static TypeDefinition GetType(ModuleDefinition module, TypeReference reference)
        {
            var type = GetTypeDefinition(module, reference);
            if (type != null)
                return type;

            if (!module.HasExportedTypes)
                return null;

            var exported_types = module.ExportedTypes;

            for (int i = 0; i < exported_types.Count; i++)
            {
                var exported_type = exported_types[i];
                if (exported_type.Name != reference.Name)
                    continue;

                if (exported_type.Namespace != reference.Namespace)
                    continue;

                return exported_type.Resolve();
            }

            return null;
        }
Example #23
0
 public MetadataImporter(ModuleDefinition module)
 {
     this.module = module;
 }
 public static Collection<GenericParameter> GetGenericParameters(
     this IGenericParameterProvider self,
     ref Collection<GenericParameter> collection,
     ModuleDefinition module)
 {
     return module.HasImage()
         ? module.Read(ref collection, self, (provider, reader) => reader.ReadGenericParameters(provider))
         : collection = new GenericParameterCollection(self);
 }