public void AddCompilationRoots(IRootingServiceProvider rootProvider)
        {
            TypeDesc owningType = _module.GetGlobalModuleType();
            NativeLibraryStartupMethod nativeLibStartupCode = new NativeLibraryStartupMethod(owningType, _libraryInitializers);

            rootProvider.AddCompilationRoot(nativeLibStartupCode, "Startup Code Main Method", ManagedEntryPointMethodName);
        }
示例#2
0
        public static MibcConfig ParseMibcConfig(TypeSystemContext tsc, PEReader pEReader)
        {
            EcmaModule mibcModule    = EcmaModule.Create(tsc, pEReader, null);
            EcmaMethod mibcConfigMth = (EcmaMethod)mibcModule.GetGlobalModuleType().GetMethod(nameof(MibcConfig), null);

            if (mibcConfigMth == null)
            {
                return(null);
            }

            var ilBody   = EcmaMethodIL.Create(mibcConfigMth);
            var ilReader = new ILReader(ilBody.GetILBytes());

            // Parse:
            //
            //   ldstr "key1"
            //   ldstr "value1"
            //   pop
            //   pop
            //   ldstr "key2"
            //   ldstr "value2"
            //   pop
            //   pop
            //   ...
            //   ret
            string fieldName = null;
            Dictionary <string, string> keyValue = new();

            while (ilReader.HasNext)
            {
                ILOpcode opcode = ilReader.ReadILOpcode();
                switch (opcode)
                {
                case ILOpcode.ldstr:
                    var ldStrValue = (string)ilBody.GetObject(ilReader.ReadILToken());
                    if (fieldName != null)
                    {
                        keyValue[fieldName] = ldStrValue;
                    }
                    else
                    {
                        fieldName = ldStrValue;
                    }
                    break;

                case ILOpcode.ret:
                case ILOpcode.pop:
                    fieldName = null;
                    break;

                default:
                    throw new InvalidOperationException($"Unexpected opcode: {opcode}");
                }
            }

            return(MibcConfig.FromKeyValueMap(keyValue));
        }
示例#3
0
        public void AddCompilationRoots(IRootingServiceProvider rootProvider)
        {
            MethodDesc mainMethod = _module.EntryPoint;

            if (mainMethod == null)
            {
                throw new Exception("No managed entrypoint defined for executable module");
            }

            TypeDesc owningType      = _module.GetGlobalModuleType();
            var      startupCodeMain = new StartupCodeMainMethod(owningType, mainMethod, _libraryInitializers);

            rootProvider.AddCompilationRoot(startupCodeMain, "Startup Code Main Method", ManagedEntryPointMethodName);
        }
示例#4
0
        private void AddMainMethodCompilationRoot(EcmaModule module)
        {
            if (StartupCodeMain != null)
            {
                throw new Exception("Multiple entrypoint modules");
            }

            int        entryPointToken = module.PEReader.PEHeaders.CorHeader.EntryPointTokenOrRelativeVirtualAddress;
            MethodDesc mainMethod      = module.GetMethod(MetadataTokens.EntityHandle(entryPointToken));

            var owningType = module.GetGlobalModuleType();

            StartupCodeMain = new StartupCodeMainMethod(owningType, mainMethod);

            _rootProvider.AddCompilationRoot(StartupCodeMain, "Startup Code Main Method", "__managed__Main");
        }
示例#5
0
        private void AddMainMethodCompilationRoot(EcmaModule module, IRootingServiceProvider rootProvider)
        {
            if (StartupCodeMain != null)
            {
                throw new Exception("Multiple entrypoint modules");
            }

            MethodDesc mainMethod = module.EntryPoint;

            if (mainMethod == null)
            {
                throw new Exception("No managed entrypoint defined for executable module");
            }

            var owningType = module.GetGlobalModuleType();

            StartupCodeMain = new StartupCodeMainMethod(owningType, mainMethod);

            rootProvider.AddCompilationRoot(StartupCodeMain, "Startup Code Main Method", "__managed__Main");
        }