Example #1
0
        static FieldDef FindAssemblyField(ModuleDef module)
        {
            foreach (var field in module.GlobalType.Fields)
            {
                const FieldAttributes attributes = FieldAttributes.Assembly | FieldAttributes.Static;
                if (field.Attributes != attributes)
                {
                    continue;
                }
                if (!field.DeclaringType.IsGlobalModuleType)
                {
                    continue;
                }
                if (field.FieldType.ElementType != ElementType.Class)
                {
                    continue;
                }
                if (field.FieldType.FullName != "System.Reflection.Assembly")
                {
                    continue;
                }

                return(field);
            }
            return(null);
        }
Example #2
0
        public static FieldAttributes ConvertToHookAttributes(this FieldAttributes originalAttrs)
        {
            var newAttrs = originalAttrs;

            newAttrs &= ~(FieldAttributes.Assembly | FieldAttributes.Private);
            newAttrs |= FieldAttributes.Public;
            return(newAttrs);
        }