Exemplo n.º 1
0
        public ModuleDefUser CreateHookModule()
        {
            _processedTypes.Clear();
            _processedMethods.Clear();
            _processedFields.Clear();


            _hookModule = new ModuleDefUser($"{_assemblyName}.dll", Guid.NewGuid(), new AssemblyRefUser(new AssemblyNameInfo(typeof(void).Assembly.GetName().FullName)))
            {
                Kind           = ModuleKind.Dll,
                RuntimeVersion = MDHeaderRuntimeVersion.MS_CLR_40
            };

            var ass = new AssemblyDefUser(_assemblyName, _originalModule.Assembly.Version);

            ass.Modules.Add(_hookModule);             // ??????? wtf but this is needed lmao

            // -- Add custom attribute for identifying
            var attr     = new TypeDefUser(IDENTIFICATION_ATTRIBUTE_NAME, _hookModule.Import(typeof(Attribute)));
            var attrCtor = new MethodDefUser(".ctor", MethodSig.CreateInstance(_hookModule.CorLibTypes.Void), MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);

            attrCtor.Body = new CilBody();
            attrCtor.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
            attr.Methods.Add(attrCtor);

            _hookModule.Types.Add(attr);
            ass.CustomAttributes.Add(new CustomAttribute(attrCtor));

            // --
            foreach (var typeDef in _originalModule.Types)
            {
                CreateRawTree(typeDef);
            }

            PopulateEverythingWithData();

            return(_hookModule);
        }
Exemplo n.º 2
0
 GenericParamConstraint Clone(GenericParamConstraint gpc) =>
 new GenericParamConstraintUser((ITypeDefOrRef)generatedModule.Import(gpc.Constraint));