static void WriteDosHeader(DosHeader dosHeader, BinaryStreamWriter writer) { writer.WriteUInt16((ushort)MZSignature.MZ); writer.WriteUInt16(dosHeader.cblp); writer.WriteUInt16(dosHeader.cp); writer.WriteUInt16(dosHeader.crlc); writer.WriteUInt16(dosHeader.cparhdr); writer.WriteUInt16(dosHeader.minalloc); writer.WriteUInt16(dosHeader.maxalloc); writer.WriteUInt16(dosHeader.ss); writer.WriteUInt16(dosHeader.sp); writer.WriteUInt16(dosHeader.csum); writer.WriteUInt16(dosHeader.ip); writer.WriteUInt16(dosHeader.cs); writer.WriteUInt16(dosHeader.lfarlc); writer.WriteUInt16(dosHeader.ovno); writer.WriteUInt64(dosHeader.res1); writer.WriteUInt16(dosHeader.oemid); writer.WriteUInt16(dosHeader.oeminfo); writer.WriteUInt32(dosHeader.ReservedNumber0); writer.WriteUInt32(dosHeader.ReservedNumber1); writer.WriteUInt32(dosHeader.ReservedNumber2); writer.WriteUInt32(dosHeader.ReservedNumber3); writer.WriteUInt32(dosHeader.ReservedNumber4); writer.WriteUInt32(dosHeader.lfanew); }
public void DosHeader() { var dh = new DosHeader(); dh.lfanew = 0x102; Assert.AreEqual("[MZ].lfanew=102h", dh.ToString()); }
public DosHeaderModel(DosHeader dosHeader) : base("DOS header") { this.dosHeader = dosHeader; this.Address = 0; this.Length = DosHeader.Size; }
public static DosHeader Read(Stream stream) { stream.CheckedExpect((ushort)PESignature.MZ, "reading MZ signature"); var result = new DosHeader(); result.cblp = stream.CheckedReadUInt16("reading cblp field of DOS header"); result.cp = stream.CheckedReadUInt16("reading cp field of DOS header"); result.crlc = stream.CheckedReadUInt16("reading crlc field of DOS header"); result.cparhdr = stream.CheckedReadUInt16("reading cparhdr field of DOS header"); result.minalloc = stream.CheckedReadUInt16("reading minalloc field of DOS header"); result.maxalloc = stream.CheckedReadUInt16("reading maxalloc field of DOS header"); result.ss = stream.CheckedReadUInt16("reading ss field of DOS header"); result.sp = stream.CheckedReadUInt16("reading sp field of DOS header"); result.csum = stream.CheckedReadUInt16("reading csum field of DOS header"); result.ip = stream.CheckedReadUInt16("reading ip field of DOS header"); result.cs = stream.CheckedReadUInt16("reading cs field of DOS header"); result.lfarlc = stream.CheckedReadUInt16("reading lfarlc field of DOS header"); result.ovno = stream.CheckedReadUInt16("reading ovno field of DOS header"); result.res1 = stream.CheckedReadUInt64("reading res1 field of DOS header"); result.oemid = stream.CheckedReadUInt16("reading oemid field of DOS header"); result.oeminfo = stream.CheckedReadUInt16("reading oeminfo field of DOS header"); var res2 = new DosHeader.Reserved10Bytes(); res2.Byte0 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte1 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte2 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte3 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte4 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte5 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte6 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte7 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte8 = stream.CheckedReadByte("reading res2 field of DOS header"); res2.Byte9 = stream.CheckedReadByte("reading res2 field of DOS header"); result.res2 = res2; result.lfanew = stream.CheckedReadUInt32("reading res2 field of DOS header"); return result; }
static void AssertDosHeader(DosHeader dosHeader) { Assert.AreEqual(144, dosHeader.cblp); Assert.AreEqual(3, dosHeader.cp); Assert.AreEqual(0, dosHeader.crlc); Assert.AreEqual(4, dosHeader.cparhdr); Assert.AreEqual(0, dosHeader.minalloc); Assert.AreEqual(65535, dosHeader.maxalloc); Assert.AreEqual(0, dosHeader.ss); Assert.AreEqual(184, dosHeader.sp); Assert.AreEqual(0, dosHeader.csum); Assert.AreEqual(0, dosHeader.ip); Assert.AreEqual(0, dosHeader.cs); Assert.AreEqual(64, dosHeader.lfarlc); Assert.AreEqual(0, dosHeader.ovno); Assert.AreEqual((ulong)0, dosHeader.res1); Assert.AreEqual(0, dosHeader.oemid); Assert.AreEqual(0, dosHeader.oeminfo); Assert.AreEqual((uint)0, dosHeader.ReservedNumber0); Assert.AreEqual((uint)0, dosHeader.ReservedNumber1); Assert.AreEqual((uint)0, dosHeader.ReservedNumber2); Assert.AreEqual((uint)0, dosHeader.ReservedNumber3); Assert.AreEqual((uint)0, dosHeader.ReservedNumber4); Assert.AreEqual((uint)128, dosHeader.lfanew); }