public void ImageDataDirectoryConstructorWorks_Test() { var dataDirectory = new IMAGE_DATA_DIRECTORY(RawStructures.RawDataDirectory, 2); Assert.AreEqual((uint) 0x44332211, dataDirectory.VirtualAddress); Assert.AreEqual(0x88776655, dataDirectory.Size); }
/// <summary> /// Create a new IMAGE_OPTIONAL_HEADER object. /// </summary> /// <param name="buff">A PE file as a byte array.</param> /// <param name="offset">Raw offset to the optional header.</param> public IMAGE_OPTIONAL_HEADER_x64(byte[] buff, uint offset) : base(buff, offset) { _is64Bit = is64Bit; DataDirectory = new IMAGE_DATA_DIRECTORY[16]; for (uint i = 0; i < 16; i++) { if (!_is64Bit) DataDirectory[i] = new IMAGE_DATA_DIRECTORY(buff, offset + 0x60 + i*0x8); else DataDirectory[i] = new IMAGE_DATA_DIRECTORY(buff, offset + 0x70 + i*0x8); } }
/// <summary> /// Create a new IMAGE_OPTIONAL_HEADER object. /// </summary> /// <param name="buff">A PE file as a byte array.</param> /// <param name="offset">Raw offset to the optional header.</param> /// <param name="is64Bit">Set to true, if header is for a x64 application.</param> public IMAGE_OPTIONAL_HEADER(byte[] buff, uint offset, bool is64Bit) : base(buff, offset) { _is64Bit = is64Bit; DataDirectory = new IMAGE_DATA_DIRECTORY[16]; for (uint i = 0; i < 16; i++) { if (!_is64Bit) { DataDirectory[i] = new IMAGE_DATA_DIRECTORY(buff, offset + 0x60 + i * 0x8); } else { DataDirectory[i] = new IMAGE_DATA_DIRECTORY(buff, offset + 0x70 + i * 0x8); } } }
private void AssertDataDirectories(IMAGE_DATA_DIRECTORY[] dataDirectories) { Assert.AreEqual(16, dataDirectories.Length); Assert.AreEqual((uint) 0x44332211, dataDirectories[(int) Constants.DataDirectoryIndex.Export].VirtualAddress); Assert.AreEqual((uint) 0x44332233, dataDirectories[(int) Constants.DataDirectoryIndex.Export].Size); Assert.AreEqual((uint) 0x44332244, dataDirectories[(int) Constants.DataDirectoryIndex.Import].VirtualAddress); Assert.AreEqual((uint) 0x44332255, dataDirectories[(int) Constants.DataDirectoryIndex.Import].Size); Assert.AreEqual((uint) 0x44887766, dataDirectories[(int) Constants.DataDirectoryIndex.Resource].VirtualAddress); Assert.AreEqual((uint) 0x4433aa99, dataDirectories[(int) Constants.DataDirectoryIndex.Resource].Size); Assert.AreEqual((uint) 0x44882211, dataDirectories[(int) Constants.DataDirectoryIndex.Exception].VirtualAddress); Assert.AreEqual((uint) 0x44334433, dataDirectories[(int) Constants.DataDirectoryIndex.Exception].Size); Assert.AreEqual((uint) 0x443322bb, dataDirectories[(int) Constants.DataDirectoryIndex.Security].VirtualAddress); Assert.AreEqual((uint) 0x443322cc, dataDirectories[(int) Constants.DataDirectoryIndex.Security].Size); Assert.AreEqual((uint) 0x443322dd, dataDirectories[(int) Constants.DataDirectoryIndex.BaseReloc].VirtualAddress); Assert.AreEqual((uint) 0x443322ee, dataDirectories[(int) Constants.DataDirectoryIndex.BaseReloc].Size); Assert.AreEqual((uint) 0x443322ff, dataDirectories[(int) Constants.DataDirectoryIndex.Debug].VirtualAddress); Assert.AreEqual((uint) 0x44333311, dataDirectories[(int) Constants.DataDirectoryIndex.Debug].Size); Assert.AreEqual((uint) 0x44334411, dataDirectories[(int) Constants.DataDirectoryIndex.Copyright].VirtualAddress); Assert.AreEqual((uint) 0x44335511, dataDirectories[(int) Constants.DataDirectoryIndex.Copyright].Size); Assert.AreEqual((uint) 0x44336611, dataDirectories[(int) Constants.DataDirectoryIndex.Globalptr].VirtualAddress); Assert.AreEqual((uint) 0x44337711, dataDirectories[(int) Constants.DataDirectoryIndex.Globalptr].Size); Assert.AreEqual((uint) 0x44338811, dataDirectories[(int) Constants.DataDirectoryIndex.TLS].VirtualAddress); Assert.AreEqual((uint) 0x44339911, dataDirectories[(int) Constants.DataDirectoryIndex.TLS].Size); Assert.AreEqual((uint) 0x4433aa11, dataDirectories[(int) Constants.DataDirectoryIndex.LoadConfig].VirtualAddress); Assert.AreEqual((uint) 0x4433bb11, dataDirectories[(int) Constants.DataDirectoryIndex.LoadConfig].Size); Assert.AreEqual((uint) 0x443399ee, dataDirectories[(int) Constants.DataDirectoryIndex.BoundImport].VirtualAddress); Assert.AreEqual((uint) 0x44330099, dataDirectories[(int) Constants.DataDirectoryIndex.BoundImport].Size); Assert.AreEqual((uint) 0x4433cc11, dataDirectories[(int) Constants.DataDirectoryIndex.IAT].VirtualAddress); Assert.AreEqual((uint) 0x4433dd11, dataDirectories[(int) Constants.DataDirectoryIndex.IAT].Size); Assert.AreEqual((uint) 0x4433ee11, dataDirectories[(int) Constants.DataDirectoryIndex.DelayImport].VirtualAddress); Assert.AreEqual((uint) 0x4433ff11, dataDirectories[(int) Constants.DataDirectoryIndex.DelayImport].Size); Assert.AreEqual((uint) 0x44442211, dataDirectories[(int) Constants.DataDirectoryIndex.COM_Descriptor].VirtualAddress); Assert.AreEqual((uint) 0x44552211, dataDirectories[(int) Constants.DataDirectoryIndex.COM_Descriptor].Size); Assert.AreEqual(0xffcc2211, dataDirectories[(int) Constants.DataDirectoryIndex.Reserved].VirtualAddress); Assert.AreEqual((uint) 0x44cc2211, dataDirectories[(int) Constants.DataDirectoryIndex.Reserved].Size); }