static private Align ( uint value, uint align ) : uint | ||
value | uint | |
align | uint | |
리턴 | uint |
private Section CreateSection(string name, uint size, Section previous) { uint virtualAddress; Section section = new Section() { Name = name }; if (previous != null) { virtualAddress = previous.VirtualAddress + ImageWriter.Align(previous.VirtualSize, 8192); } else { virtualAddress = 8192; } section.VirtualAddress = virtualAddress; section.VirtualSize = size; section.PointerToRawData = (previous != null ? previous.PointerToRawData + previous.SizeOfRawData : ImageWriter.Align(this.GetHeaderSize(), 512)); section.SizeOfRawData = ImageWriter.Align(size, 512); return(section); }
private void WriteOptionalHeaders() { Object sizeOfRawData; Object obj; uint start; uint virtualAddress; uint virtualSize; base.WriteUInt16((ushort)((!this.pe64 ? 267 : 523))); base.WriteByte(8); base.WriteByte(0); base.WriteUInt32(this.text.SizeOfRawData); if (this.reloc != null) { sizeOfRawData = this.reloc.SizeOfRawData; } else { sizeOfRawData = null; } if (this.rsrc != null) { obj = this.rsrc.SizeOfRawData; } else { obj = null; } base.WriteUInt32(sizeOfRawData + obj); base.WriteUInt32(0); Range range = this.text_map.GetRange(TextSegment.StartupStub); if (range.Length > 0) { start = range.Start; } else { start = 0; } base.WriteUInt32(start); base.WriteUInt32(8192); if (this.pe64) { base.WriteUInt64((ulong)4194304); } else { base.WriteUInt32(0); base.WriteUInt32(4194304); } base.WriteUInt32(8192); base.WriteUInt32(512); base.WriteUInt16(4); base.WriteUInt16(0); base.WriteUInt16(0); base.WriteUInt16(0); base.WriteUInt16(4); base.WriteUInt16(0); base.WriteUInt32(0); Section section = this.LastSection(); base.WriteUInt32(section.VirtualAddress + ImageWriter.Align(section.VirtualSize, 8192)); base.WriteUInt32(this.text.PointerToRawData); base.WriteUInt32(0); base.WriteUInt16(this.GetSubSystem()); base.WriteUInt16((ushort)this.module.Characteristics); if (this.pe64) { base.WriteUInt64((ulong)1048576); base.WriteUInt64((ulong)4096); base.WriteUInt64((ulong)1048576); base.WriteUInt64((ulong)4096); } else { base.WriteUInt32(1048576); base.WriteUInt32(4096); base.WriteUInt32(1048576); base.WriteUInt32(4096); } base.WriteUInt32(0); base.WriteUInt32(16); this.WriteZeroDataDirectory(); base.WriteDataDirectory(this.text_map.GetDataDirectory(TextSegment.ImportDirectory)); if (this.rsrc == null) { this.WriteZeroDataDirectory(); } else { base.WriteUInt32(this.rsrc.VirtualAddress); base.WriteUInt32(this.rsrc.VirtualSize); } this.WriteZeroDataDirectory(); this.WriteZeroDataDirectory(); if (this.reloc != null) { virtualAddress = this.reloc.VirtualAddress; } else { virtualAddress = 0; } base.WriteUInt32(virtualAddress); if (this.reloc != null) { virtualSize = this.reloc.VirtualSize; } else { virtualSize = 0; } base.WriteUInt32(virtualSize); if (this.text_map.GetLength(TextSegment.DebugDirectory) <= 0) { this.WriteZeroDataDirectory(); } else { base.WriteUInt32(this.text_map.GetRVA(TextSegment.DebugDirectory)); base.WriteUInt32(28); } this.WriteZeroDataDirectory(); this.WriteZeroDataDirectory(); this.WriteZeroDataDirectory(); this.WriteZeroDataDirectory(); this.WriteZeroDataDirectory(); base.WriteDataDirectory(this.text_map.GetDataDirectory(TextSegment.ImportAddressTable)); this.WriteZeroDataDirectory(); base.WriteDataDirectory(this.text_map.GetDataDirectory(TextSegment.CLIHeader)); this.WriteZeroDataDirectory(); }