sizeof(ushort); // Characteristics internal CoffHeader(ref PEBinaryReader reader) { Machine = (Machine)reader.ReadUInt16(); NumberOfSections = reader.ReadInt16(); TimeDateStamp = reader.ReadInt32(); PointerToSymbolTable = reader.ReadInt32(); NumberOfSymbols = reader.ReadInt32(); SizeOfOptionalHeader = reader.ReadInt16(); Characteristics = (Characteristics)reader.ReadUInt16(); }
internal CoffHeader(ref PEBinaryReader reader) { Machine = (Machine)reader.ReadUInt16(); NumberOfSections = reader.ReadInt16(); TimeDateStamp = reader.ReadInt32(); PointerToSymbolTable = reader.ReadInt32(); NumberOfSymbols = reader.ReadInt32(); SizeOfOptionalHeader = reader.ReadInt16(); Characteristics = (Characteristics)reader.ReadUInt16(); }
/// <summary> /// Creates and hydrates a memory block representing data in the specified range. /// </summary> /// <param name="start">Starting offset relative to the beginning of the data represented by this provider.</param> /// <param name="size">Size of the resulting block.</param> /// <exception cref="IOException">Error while reading from the memory source.</exception> public AbstractMemoryBlock GetMemoryBlock(int start, int size) { // Add canot overflow as it is the sum of two 32-bit values done in 64 bits. // Negative start or size is handle by overflow to greater than maximum size = int.MaxValue. if ((ulong)(unchecked ((uint)start)) + unchecked ((uint)size) > (ulong)this.Size) { PEBinaryReader.ThrowImageTooSmallOrContainsInvalidOffsetOrCount(); } return(GetMemoryBlockImpl(start, size)); }
public void ReadNullPaddedUTF8WorksWithNoNullPadding() { var headerBytes = Encoding.UTF8.GetBytes(".abcdefg"); var stream = new MemoryStream(headerBytes); stream.Position = 0; var reader = new PEBinaryReader(stream, headerBytes.Length); var text = reader.ReadNullPaddedUTF8(PEFileConstants.SizeofSectionName); Assert.Equal(".abcdefg", text); }
public void ReadNullPaddedUTF8WorksWithNoNullPadding() { var headerBytes = Encoding.UTF8.GetBytes(".abcdefg"); var stream = new MemoryStream(headerBytes); stream.Position = 0; var reader = new PEBinaryReader(stream, headerBytes.Length); var text = reader.ReadNullPaddedUTF8(SectionHeader.NameSize); Assert.Equal(".abcdefg", text); }
public void ReadNullPaddedUTF8WorksWithNoNullPadding() { var headerBytes = Encoding.UTF8.GetBytes(".abcdefg"); var stream = new MemoryStream(headerBytes); stream.Position = 0; var reader = new PEBinaryReader(stream, headerBytes.Length); var text = reader.ReadNullPaddedUTF8(PEFileConstants.SizeofSectionName); AssertEx.AreEqual(".abcdefg", text, "PEBinaryReader.ReadNullPaddedUTF8 erroneously truncated a section name"); }
internal SectionHeader(ref PEBinaryReader reader) { _name = reader.ReadNullPaddedUTF8(PEFileConstants.SizeofSectionName); _virtualSize = reader.ReadInt32(); _virtualAddress = reader.ReadInt32(); _sizeOfRawData = reader.ReadInt32(); _pointerToRawData = reader.ReadInt32(); _pointerToRelocations = reader.ReadInt32(); _pointerToLineNumbers = reader.ReadInt32(); _numberOfRelocations = reader.ReadUInt16(); _numberOfLineNumbers = reader.ReadUInt16(); _sectionCharacteristics = (SectionCharacteristics)reader.ReadUInt32(); }
sizeof(int); // SectionCharacteristics internal SectionHeader(ref PEBinaryReader reader) { Name = reader.ReadNullPaddedUTF8(NameSize); VirtualSize = reader.ReadInt32(); VirtualAddress = reader.ReadInt32(); SizeOfRawData = reader.ReadInt32(); PointerToRawData = reader.ReadInt32(); PointerToRelocations = reader.ReadInt32(); PointerToLineNumbers = reader.ReadInt32(); NumberOfRelocations = reader.ReadUInt16(); NumberOfLineNumbers = reader.ReadUInt16(); SectionCharacteristics = (SectionCharacteristics)reader.ReadUInt32(); }
public void ReadNullPaddedUTF8RemovesNullPadding() { var headerBytes = new byte[PEFileConstants.SizeofSectionName]; headerBytes[0] = 80; headerBytes[1] = 80; headerBytes[2] = 80; var stream = new MemoryStream(headerBytes); stream.Position = 0; var reader = new PEBinaryReader(stream, headerBytes.Length); var text = reader.ReadNullPaddedUTF8(PEFileConstants.SizeofSectionName); Assert.Equal(3, text.Length); Assert.Equal("PPP", text); }
internal CorHeader(ref PEBinaryReader reader) { // byte count reader.ReadInt32(); MajorRuntimeVersion = reader.ReadUInt16(); MinorRuntimeVersion = reader.ReadUInt16(); MetadataDirectory = new DirectoryEntry(ref reader); Flags = (CorFlags)reader.ReadUInt32(); EntryPointTokenOrRelativeVirtualAddress = reader.ReadInt32(); ResourcesDirectory = new DirectoryEntry(ref reader); StrongNameSignatureDirectory = new DirectoryEntry(ref reader); CodeManagerTableDirectory = new DirectoryEntry(ref reader); VtableFixupsDirectory = new DirectoryEntry(ref reader); ExportAddressTableJumpsDirectory = new DirectoryEntry(ref reader); ManagedNativeHeaderDirectory = new DirectoryEntry(ref reader); }
public void ReadNullPaddedUTF8RemovesNullPadding() { var headerBytes = new byte[SectionHeader.NameSize]; headerBytes[0] = 80; headerBytes[1] = 80; headerBytes[2] = 80; var stream = new MemoryStream(headerBytes); stream.Position = 0; var reader = new PEBinaryReader(stream, headerBytes.Length); var text = reader.ReadNullPaddedUTF8(SectionHeader.NameSize); Assert.Equal(3, text.Length); Assert.Equal("PPP", text); }
public void ReadNullPaddedUTF8RemovesNullPadding() { var headerBytes = new byte[PEFileConstants.SizeofSectionName]; headerBytes[0] = 80; headerBytes[1] = 80; headerBytes[2] = 80; var stream = new MemoryStream(headerBytes); stream.Position = 0; var reader = new PEBinaryReader(stream, headerBytes.Length); var text = reader.ReadNullPaddedUTF8(PEFileConstants.SizeofSectionName); AssertEx.AreEqual(3, text.Length, "PEBinaryReader.ReadNullPaddedUTF8 did not truncate null padding"); AssertEx.AreEqual("PPP", text); }
public void Ctor( string name, int virtualSize, int virtualAddress, int sizeOfRawData, int ptrToRawData, int ptrToRelocations, int ptrToLineNumbers, ushort numRelocations, ushort numLineNumbers, SectionCharacteristics characteristics) { var stream = new MemoryStream(); var writer = new BinaryWriter(stream, Encoding.UTF8, leaveOpen: true); writer.Write(PadSectionName(name)); writer.Write(virtualSize); writer.Write(virtualAddress); writer.Write(sizeOfRawData); writer.Write(ptrToRawData); writer.Write(ptrToRelocations); writer.Write(ptrToLineNumbers); writer.Write(numRelocations); writer.Write(numLineNumbers); writer.Write((uint)characteristics); writer.Dispose(); stream.Position = 0; var reader = new PEBinaryReader(stream, (int)stream.Length); var header = new SectionHeader(ref reader); Assert.Equal(name, header.Name); Assert.Equal(virtualSize, header.VirtualSize); Assert.Equal(virtualAddress, header.VirtualAddress); Assert.Equal(sizeOfRawData, header.SizeOfRawData); Assert.Equal(ptrToRawData, header.PointerToRawData); Assert.Equal(ptrToLineNumbers, header.PointerToLineNumbers); Assert.Equal(numRelocations, header.NumberOfRelocations); Assert.Equal(numLineNumbers, header.NumberOfLineNumbers); Assert.Equal(characteristics, header.SectionCharacteristics); }
public void Ctor( string name, int virtualSize, int virtualAddress, int sizeOfRawData, int ptrToRawData, int ptrToRelocations, int ptrToLineNumbers, ushort numRelocations, ushort numLineNumbers, SectionCharacteristics characteristics) { var stream = new MemoryStream(); var writer = new BinaryWriter(stream, Encoding.UTF8, leaveOpen: true); writer.Write(PadSectionName(name)); writer.Write(virtualSize); writer.Write(virtualAddress); writer.Write(sizeOfRawData); writer.Write(ptrToRawData); writer.Write(ptrToRelocations); writer.Write(ptrToLineNumbers); writer.Write(numRelocations); writer.Write(numLineNumbers); writer.Write((uint) characteristics); writer.Dispose(); stream.Position = 0; var reader = new PEBinaryReader(stream, (int) stream.Length); var header = new SectionHeader(ref reader); Assert.Equal(name, header.Name); Assert.Equal(virtualSize, header.VirtualSize); Assert.Equal(virtualAddress, header.VirtualAddress); Assert.Equal(sizeOfRawData, header.SizeOfRawData); Assert.Equal(ptrToRawData, header.PointerToRawData); Assert.Equal(ptrToLineNumbers, header.PointerToLineNumbers); Assert.Equal(numRelocations, header.NumberOfRelocations); Assert.Equal(numLineNumbers, header.NumberOfLineNumbers); Assert.Equal(characteristics, header.SectionCharacteristics); }
internal DirectoryEntry(ref PEBinaryReader reader) { RelativeVirtualAddress = reader.ReadInt32(); Size = reader.ReadInt32(); }