Beispiel #1
0
        private HResult ProvideWindowsLibrary(
            IntPtr self,
            string fileName,
            string runtimeModulePath,
            LIBRARY_PROVIDER_INDEX_TYPE indexType,
            uint timeStamp,
            uint sizeOfImage,
            out IntPtr modulePathOut)
        {
            Trace.TraceInformation($"LibraryProviderWrapper.ProvideWindowsLibrary {fileName} {runtimeModulePath} {timeStamp:X8} {sizeOfImage:X8}");
            try
            {
                // Should only be called for Windows targets
                Assert.Equal(OSPlatform.Windows, _targetOS);

                // Should always get the identity on Windows
                Assert.Equal(LIBRARY_PROVIDER_INDEX_TYPE.Identity, indexType);

                string modulePath = null;
                if (fileName.Contains(DbiName))
                {
                    if (_dbiModulePath != null)
                    {
                        modulePath = _dbiModulePath;
                    }
                    else
                    {
                        modulePath = DownloadModule(DbiName, timeStamp, sizeOfImage);
                    }
                }
                // This needs to work for long named DAC's so remove the extension
                else if (fileName.Contains(Path.GetFileNameWithoutExtension(DacName)))
                {
                    if (_dacModulePath != null)
                    {
                        modulePath = _dacModulePath;
                    }
                    else
                    {
                        modulePath = DownloadModule(DacName, timeStamp, sizeOfImage);
                    }
                }
                TestGetPEInfo(modulePath, timeStamp, sizeOfImage);
                modulePathOut = Marshal.StringToCoTaskMemUni(modulePath);
                Trace.TraceInformation($"LibraryProviderWrapper.ProvideWindowsLibrary SUCCEEDED {modulePath}");
                return(HResult.S_OK);
            }
            catch (Exception ex)
            {
                Trace.TraceError($"LibraryProviderWrapper.ProvideWindowsLibrary {ex}");
            }
            Trace.TraceError("LibraryProviderWrapper.ProvideWindowsLibrary FAILED");
            modulePathOut = IntPtr.Zero;
            return(HResult.E_INVALIDARG);
        }
Beispiel #2
0
        private HResult ProvideUnixLibrary(
            IntPtr self,
            string fileName,
            string runtimeModulePath,
            LIBRARY_PROVIDER_INDEX_TYPE indexType,
            byte *buildIdBytes,
            int buildIdSize,
            out IntPtr modulePathOut)
        {
            try
            {
                // Should only be called for Unix targets
                Assert.NotEqual(OSPlatform.Windows, _targetOS);

                byte[] buildId    = Array.Empty <byte>();
                string modulePath = null;
                if (buildIdBytes != null && buildIdSize > 0)
                {
                    Span <byte> span = new Span <byte>(buildIdBytes, buildIdSize);
                    buildId = span.ToArray();
                }
                Trace.TraceInformation($"LibraryProviderWrapper.ProvideUnixLibrary {fileName} {runtimeModulePath} {indexType} {string.Concat(buildId.Select((b) => b.ToString("x2")))}");
                if (fileName.Contains(DbiName))
                {
                    if (_dbiModulePath != null)
                    {
                        modulePath = _dbiModulePath;
                    }
                    else
                    {
                        modulePath = DownloadModule(DbiName, buildId);
                    }
                }
                else if (fileName.Contains(DacName))
                {
                    if (_dacModulePath != null)
                    {
                        modulePath = _dacModulePath;
                    }
                    else
                    {
                        modulePath = DownloadModule(DacName, buildId);
                    }
                }
                if (modulePath != null)
                {
                    switch (indexType)
                    {
                    case LIBRARY_PROVIDER_INDEX_TYPE.Identity:
                        TestBuildId(GetBuildId(modulePath), buildId);
                        break;

                    case LIBRARY_PROVIDER_INDEX_TYPE.Runtime:
                        TestBuildId(_runtimeModuleBuildId, buildId);
                        break;
                    }
                    modulePathOut = Marshal.StringToCoTaskMemUni(modulePath);
                    Trace.TraceInformation($"LibraryProviderWrapper.ProvideUnixLibrary SUCCEEDED {modulePath}");
                    return(HResult.S_OK);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError($"LibraryProviderWrapper.ProvideUnixLibrary {ex}");
            }
            Trace.TraceError("LibraryProviderWrapper.ProvideUnixLibrary FAILED");
            modulePathOut = IntPtr.Zero;
            return(HResult.E_INVALIDARG);
        }