public static async Task <LoadConfigurationDirectory> GetAsync(PortableExecutableImage image) { if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.LoadConfigTable)) { return(null); } var dataDirectory = image.NTHeaders.DataDirectories[DataDirectoryType.LoadConfigTable]; if (DataDirectory.IsNullOrEmpty(dataDirectory)) { return(null); } var calc = image.GetCalculator(); var section = calc.RVAToSection(dataDirectory.VirtualAddress); var fileOffset = calc.RVAToOffset(section, dataDirectory.VirtualAddress); var imageBase = image.NTHeaders.OptionalHeader.ImageBase; var location = new Location(image, fileOffset, dataDirectory.VirtualAddress, imageBase + dataDirectory.VirtualAddress, dataDirectory.Size, dataDirectory.Size, section); var stream = image.GetStream(); stream.Seek(fileOffset.ToInt64(), SeekOrigin.Begin); LoadConfigurationDirectory directory = null; if (image.Is32Bit) { IMAGE_LOAD_CONFIG_DIRECTORY32 config; try { config = await stream.ReadStructAsync <IMAGE_LOAD_CONFIG_DIRECTORY32>().ConfigureAwait(false); } catch (Exception ex) { throw new PortableExecutableImageException(image, "Could not load Load Configration Directory from stream.", ex); } directory = new LoadConfigurationDirectory(image, dataDirectory, location, config); } else { IMAGE_LOAD_CONFIG_DIRECTORY64 config; try { config = await stream.ReadStructAsync <IMAGE_LOAD_CONFIG_DIRECTORY64>().ConfigureAwait(false); } catch (Exception ex) { throw new PortableExecutableImageException(image, "Could not load Load Configration Directory from stream.", ex); } directory = new LoadConfigurationDirectory(image, dataDirectory, location, config); } return(directory); }
internal LoadConfigurationCodeIntegrity(LoadConfigurationDirectory directory, IMAGE_LOAD_CONFIG_CODE_INTEGRITY codeIntegrity) { _directory = directory; _codeIntegrity = codeIntegrity; }