private void WriteRelocSection(Stream peStream, SectionHeader relocSection, int entryPointAddress) { peStream.Position = relocSection.PointerToRawData; var writer = new BlobBuilder(relocSection.SizeOfRawData); writer.WriteUInt32((((uint)entryPointAddress + 2) / 0x1000) * 0x1000); writer.WriteUInt32(_properties.Requires64bits && !_properties.RequiresAmdInstructionSet ? 14u : 12u); uint offsetWithinPage = ((uint)entryPointAddress + 2) % 0x1000; uint relocType = _properties.Requires64bits ? 10u : 3u; ushort s = (ushort)((relocType << 12) | offsetWithinPage); writer.WriteUInt16(s); if (_properties.Requires64bits && !_properties.RequiresAmdInstructionSet) { writer.WriteUInt32(relocType << 12); } writer.WriteUInt16(0); // next chunk's RVA writer.PadTo(relocSection.SizeOfRawData); writer.WriteTo(peStream); }
public void WriteAlignPad() { var writer = new BlobBuilder(4); writer.WriteByte(0x01); writer.PadTo(2); writer.WriteByte(0x02); writer.Align(4); writer.Align(4); writer.WriteByte(0x03); writer.Align(4); writer.WriteByte(0x04); writer.WriteByte(0x05); writer.Align(8); writer.WriteByte(0x06); writer.Align(2); writer.Align(1); AssertEx.Equal(new byte[] { 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00 }, writer.ToArray()); }