internal NTHeaders(ExecutableImage exeImage, ulong headerOffset, ulong imageBase, FileHeader fileHeader, OptionalHeader optHeader, DataDirectoryCollection dataDirs) { uint size = (4U + fileHeader.Location.FileSize + optHeader.Location.FileSize + dataDirs.Location.FileSize).ToUInt32(); image = exeImage; location = new Location(headerOffset,Convert.ToUInt32(headerOffset),imageBase + headerOffset,size,size); file_header = fileHeader; opt_header = optHeader; data_dirs = dataDirs; }
private void Load() { string error_message = String.Empty; PreloadedInformation preload_info = TryPreload(_stream,out error_message); if (preload_info == null) throw new ExecutableImageException(error_message); ulong image_base = 0; if (preload_info.OptHeader32 != null) image_base = preload_info.OptHeader32.Value.ImageBase; if (preload_info.OptHeader64 != null) image_base = preload_info.OptHeader64.Value.ImageBase; _dos_header = new DOSHeader(this,preload_info.DOSHeader,image_base); _dos_stub = new DOSStub(this,preload_info.StubOffset,preload_info.StubSize,image_base); FileHeader file_header = new FileHeader(this,preload_info.FileHeader,_dos_stub.Location.FileOffset + _dos_stub.Location.FileSize + 4,image_base); OptionalHeader opt_header; if (preload_info.Is32Bit) { opt_header = new OptionalHeader32(this,preload_info.OptHeader32.Value,file_header.Location.FileOffset + file_header.Location.FileSize,image_base); } else { opt_header = new OptionalHeader64(this,preload_info.OptHeader64.Value,file_header.Location.FileOffset + file_header.Location.FileSize,image_base); } DataDirectoryCollection data_dirs = new DataDirectoryCollection(this,opt_header,preload_info.DataDirectories); _nt_headers = new NTHeaders(this,file_header.Location.FileOffset - 4,image_base,file_header,opt_header,data_dirs); _section_table = new SectionTable(this,preload_info.SectionHeaders,_nt_headers.Location.FileOffset + _nt_headers.Location.FileSize,image_base); _sections = new Sections(_section_table); _is_32bit = preload_info.Is32Bit; _is_64bit = preload_info.Is64Bit; _is_clr = preload_info.IsCLR; _is_signed = preload_info.IsSigned; }