ImageWriter(ModuleDefinition module, MetadataBuilder metadata, Stream stream) : base(stream) { this.module = module; this.metadata = metadata; this.GetDebugHeader (); this.GetWin32Resources (); this.text_map = BuildTextMap (); this.sections = 2; // text + reloc this.pe64 = module.Architecture != TargetArchitecture.I386; this.time_stamp = (uint) DateTime.UtcNow.Subtract (new DateTime (1970, 1, 1)).TotalSeconds; }
ImageWriter(ModuleDefinition module, MetadataBuilder metadata, Stream stream) : base(stream) { this.module = module; this.pe64 = module.Architecture != TargetArchitecture.I386; this.metadata = metadata; this.GetDebugHeader(); this.GetWin32Resources(); this.text_map = BuildTextMap(); this.sections = new Collection <Section>(2); // text + reloc this.time_stamp = (uint)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; }
private ImageWriter(ModuleDefinition module, MetadataBuilder metadata, Stream stream) : base(stream) { this.module = module; this.metadata = metadata; this.pe64 = (module.Architecture == TargetArchitecture.AMD64) || (module.Architecture == TargetArchitecture.IA64); this.has_reloc = module.Architecture == TargetArchitecture.I386; this.GetDebugHeader(); this.GetWin32Resources(); this.text_map = this.BuildTextMap(); this.sections = this.has_reloc ? ((ushort)2) : ((ushort)1); this.time_stamp = (uint)DateTime.UtcNow.Subtract(new DateTime(0x7b2, 1, 1)).TotalSeconds; }
public void BuildMetadataTextMap() { TextMap textMap = text_map; textMap.AddMap(TextSegment.MetadataHeader, GetMetadataHeaderLength(module.RuntimeVersion)); textMap.AddMap(TextSegment.TableHeap, metadata.table_heap.length, 4); textMap.AddMap(TextSegment.StringHeap, metadata.string_heap.length, 4); textMap.AddMap(TextSegment.UserStringHeap, (!metadata.user_string_heap.IsEmpty) ? metadata.user_string_heap.length : 0, 4); textMap.AddMap(TextSegment.GuidHeap, metadata.guid_heap.length, 4); textMap.AddMap(TextSegment.BlobHeap, (!metadata.blob_heap.IsEmpty) ? metadata.blob_heap.length : 0, 4); textMap.AddMap(TextSegment.PdbHeap, (metadata.pdb_heap != null) ? metadata.pdb_heap.length : 0, 4); }
private void BuildTextMap() { TextMap textMap = text_map; textMap.AddMap(TextSegment.Code, metadata.code.length, (!pe64) ? 4 : 16); textMap.AddMap(TextSegment.Resources, metadata.resources.length, 8); textMap.AddMap(TextSegment.Data, metadata.data.length, 4); if (metadata.data.length > 0) { metadata.table_heap.FixupData(textMap.GetRVA(TextSegment.Data)); } textMap.AddMap(TextSegment.StrongNameSignature, GetStrongNameLength(), 4); BuildMetadataTextMap(); int length = 0; if (debug_header != null && debug_header.HasEntries) { int num = debug_header.Entries.Length * 28; int num2 = (int)textMap.GetNextRVA(TextSegment.BlobHeap) + num; int num3 = 0; for (int i = 0; i < debug_header.Entries.Length; i++) { ImageDebugHeaderEntry imageDebugHeaderEntry = debug_header.Entries[i]; ImageDebugDirectory directory = imageDebugHeaderEntry.Directory; directory.AddressOfRawData = ((imageDebugHeaderEntry.Data.Length != 0) ? num2 : 0); imageDebugHeaderEntry.Directory = directory; num3 += imageDebugHeaderEntry.Data.Length; num2 += num3; } length = num + num3; } textMap.AddMap(TextSegment.DebugDirectory, length, 4); if (!has_reloc) { uint nextRVA = textMap.GetNextRVA(TextSegment.DebugDirectory); textMap.AddMap(TextSegment.ImportDirectory, new Range(nextRVA, 0u)); textMap.AddMap(TextSegment.ImportHintNameTable, new Range(nextRVA, 0u)); textMap.AddMap(TextSegment.StartupStub, new Range(nextRVA, 0u)); } else { uint nextRVA2 = textMap.GetNextRVA(TextSegment.DebugDirectory); uint num4 = nextRVA2 + 48; num4 = (uint)((int)(num4 + 15) & -16); uint num5 = num4 - nextRVA2 + 27; uint num6 = nextRVA2 + num5; num6 = (uint)((module.Architecture == TargetArchitecture.IA64) ? ((int)(num6 + 15) & -16) : (2 + ((int)(num6 + 3) & -4))); textMap.AddMap(TextSegment.ImportDirectory, new Range(nextRVA2, num5)); textMap.AddMap(TextSegment.ImportHintNameTable, new Range(num4, 0u)); textMap.AddMap(TextSegment.StartupStub, new Range(num6, GetStartupStubLength())); } }
private ImageWriter(ModuleDefinition module, MetadataBuilder metadata, Stream stream) : base(stream) { this.module = module; this.metadata = metadata; this.pe64 = (module.Architecture == TargetArchitecture.AMD64 ? true : module.Architecture == TargetArchitecture.IA64); this.has_reloc = module.Architecture == TargetArchitecture.I386; this.GetDebugHeader(); this.GetWin32Resources(); this.text_map = this.BuildTextMap(); this.sections = (ushort)((this.has_reloc ? 2 : 1)); DateTime utcNow = DateTime.UtcNow; TimeSpan timeSpan = utcNow.Subtract(new DateTime(1970, 1, 1)); this.time_stamp = (uint)timeSpan.TotalSeconds; }
private TextMap BuildTextMap() { TextMap textMap = this.metadata.text_map; textMap.AddMap(TextSegment.Code, this.metadata.code.length, (!this.pe64 ? 4 : 16)); textMap.AddMap(TextSegment.Resources, this.metadata.resources.length, 8); textMap.AddMap(TextSegment.Data, this.metadata.data.length, 4); if (this.metadata.data.length > 0) { this.metadata.table_heap.FixupData(textMap.GetRVA(TextSegment.Data)); } textMap.AddMap(TextSegment.StrongNameSignature, this.GetStrongNameLength(), 4); textMap.AddMap(TextSegment.MetadataHeader, this.GetMetadataHeaderLength()); textMap.AddMap(TextSegment.TableHeap, this.metadata.table_heap.length, 4); textMap.AddMap(TextSegment.StringHeap, this.metadata.string_heap.length, 4); textMap.AddMap(TextSegment.UserStringHeap, (this.metadata.user_string_heap.IsEmpty ? 0 : this.metadata.user_string_heap.length), 4); textMap.AddMap(TextSegment.GuidHeap, 16); textMap.AddMap(TextSegment.BlobHeap, (this.metadata.blob_heap.IsEmpty ? 0 : this.metadata.blob_heap.length), 4); int length = 0; if (!this.debug_data.IsNullOrEmpty <byte>()) { this.debug_directory.AddressOfRawData = (int)(textMap.GetNextRVA(TextSegment.BlobHeap) + 28); length = (int)this.debug_data.Length + 28; } textMap.AddMap(TextSegment.DebugDirectory, length, 4); if (!this.has_reloc) { uint nextRVA = textMap.GetNextRVA(TextSegment.DebugDirectory); textMap.AddMap(TextSegment.ImportDirectory, new Range(nextRVA, 0)); textMap.AddMap(TextSegment.ImportHintNameTable, new Range(nextRVA, 0)); textMap.AddMap(TextSegment.StartupStub, new Range(nextRVA, 0)); return(textMap); } uint num = textMap.GetNextRVA(TextSegment.DebugDirectory); uint num1 = num + 48; num1 = num1 + 15 & -16; uint num2 = num1 - num + 27; uint num3 = num + num2; num3 = (this.module.Architecture == TargetArchitecture.IA64 ? num3 + 15 & -16 : 2 + (num3 + 3 & -4)); textMap.AddMap(TextSegment.ImportDirectory, new Range(num, num2)); textMap.AddMap(TextSegment.ImportHintNameTable, new Range(num1, 0)); textMap.AddMap(TextSegment.StartupStub, new Range(num3, this.GetStartupStubLength())); return(textMap); }
ImageWriter(ModuleDefinition module, string runtime_version, MetadataBuilder metadata, Disposable<Stream> stream, bool metadataOnly = false) : base(stream.value) { this.module = module; this.runtime_version = runtime_version; this.text_map = metadata.text_map; this.stream = stream; this.metadata = metadata; if (metadataOnly) return; this.pe64 = module.Architecture == TargetArchitecture.AMD64 || module.Architecture == TargetArchitecture.IA64; this.has_reloc = module.Architecture == TargetArchitecture.I386; this.GetDebugHeader (); this.GetWin32Resources (); this.BuildTextMap (); this.sections = (ushort) (has_reloc ? 2 : 1); // text + reloc? }
private ImageWriter(ModuleDefinition module, string runtime_version, MetadataBuilder metadata, Disposable <Stream> stream, bool metadataOnly = false) : base(stream.value) { this.module = module; this.runtime_version = runtime_version; text_map = metadata.text_map; this.stream = stream; this.metadata = metadata; if (!metadataOnly) { pe64 = (module.Architecture == TargetArchitecture.AMD64 || module.Architecture == TargetArchitecture.IA64 || module.Architecture == TargetArchitecture.ARM64); has_reloc = (module.Architecture == TargetArchitecture.I386); GetDebugHeader(); GetWin32Resources(); BuildTextMap(); sections = (ushort)((!has_reloc) ? 1 : 2); } }
private TextMap BuildTextMap() { TextMap map = this.metadata.text_map; map.AddMap(TextSegment.Code, this.metadata.code.length, !this.pe64 ? 4 : 0x10); map.AddMap(TextSegment.Resources, this.metadata.resources.length, 8); map.AddMap(TextSegment.Data, this.metadata.data.length, 4); if (this.metadata.data.length > 0) { this.metadata.table_heap.FixupData(map.GetRVA(TextSegment.Data)); } map.AddMap(TextSegment.StrongNameSignature, this.GetStrongNameLength(), 4); map.AddMap(TextSegment.MetadataHeader, this.GetMetadataHeaderLength()); map.AddMap(TextSegment.TableHeap, this.metadata.table_heap.length, 4); map.AddMap(TextSegment.StringHeap, this.metadata.string_heap.length, 4); map.AddMap(TextSegment.UserStringHeap, this.metadata.user_string_heap.IsEmpty ? 0 : this.metadata.user_string_heap.length, 4); map.AddMap(TextSegment.GuidHeap, 0x10); map.AddMap(TextSegment.BlobHeap, this.metadata.blob_heap.IsEmpty ? 0 : this.metadata.blob_heap.length, 4); int length = 0; if (!this.debug_data.IsNullOrEmpty <byte>()) { this.debug_directory.AddressOfRawData = (int)(map.GetNextRVA(TextSegment.BlobHeap) + 0x1c); length = this.debug_data.Length + 0x1c; } map.AddMap(TextSegment.DebugDirectory, length, 4); if (!this.has_reloc) { uint num2 = map.GetNextRVA(TextSegment.DebugDirectory); map.AddMap(TextSegment.ImportDirectory, new Range(num2, 0)); map.AddMap(TextSegment.ImportHintNameTable, new Range(num2, 0)); map.AddMap(TextSegment.StartupStub, new Range(num2, 0)); return(map); } uint nextRVA = map.GetNextRVA(TextSegment.DebugDirectory); uint index = (uint)(((nextRVA + 0x30) + 15) & -16); uint num5 = (index - nextRVA) + ((uint)0x1b); uint num6 = nextRVA + num5; map.AddMap(TextSegment.ImportDirectory, new Range(nextRVA, num5)); map.AddMap(TextSegment.ImportHintNameTable, new Range(index, 0)); map.AddMap(TextSegment.StartupStub, new Range((this.module.Architecture == TargetArchitecture.IA64) ? ((uint)((num6 + 15) & -16)) : ((uint)(2 + ((num6 + 3) & -4))), this.GetStartupStubLength())); return(map); }
ImageWriter(ModuleDefinition module, string runtime_version, MetadataBuilder metadata, Disposable <Stream> stream, bool metadataOnly = false) : base(stream.value) { this.module = module; this.runtime_version = runtime_version; this.text_map = metadata.text_map; this.stream = stream; this.metadata = metadata; if (metadataOnly) { return; } this.pe64 = module.Architecture == TargetArchitecture.AMD64 || module.Architecture == TargetArchitecture.IA64 || module.Architecture == TargetArchitecture.ARM64; this.has_reloc = module.Architecture == TargetArchitecture.I386; this.GetDebugHeader(); this.GetWin32Resources(); this.BuildTextMap(); this.sections = (ushort)(has_reloc ? 2 : 1); // text + reloc? }