Beispiel #1
0
 internal void Read(BinaryReader br)
 {
     Magic = br.ReadUInt16();
     if (Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC && Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)
     {
         throw new BadImageFormatException();
     }
     MajorLinkerVersion      = br.ReadByte();
     MinorLinkerVersion      = br.ReadByte();
     SizeOfCode              = br.ReadUInt32();
     SizeOfInitializedData   = br.ReadUInt32();
     SizeOfUninitializedData = br.ReadUInt32();
     AddressOfEntryPoint     = br.ReadUInt32();
     BaseOfCode              = br.ReadUInt32();
     if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
     {
         BaseOfData = br.ReadUInt32();
         ImageBase  = br.ReadUInt32();
     }
     else
     {
         ImageBase = br.ReadUInt64();
     }
     SectionAlignment            = br.ReadUInt32();
     FileAlignment               = br.ReadUInt32();
     MajorOperatingSystemVersion = br.ReadUInt16();
     MinorOperatingSystemVersion = br.ReadUInt16();
     MajorImageVersion           = br.ReadUInt16();
     MinorImageVersion           = br.ReadUInt16();
     MajorSubsystemVersion       = br.ReadUInt16();
     MinorSubsystemVersion       = br.ReadUInt16();
     Win32VersionValue           = br.ReadUInt32();
     SizeOfImage        = br.ReadUInt32();
     SizeOfHeaders      = br.ReadUInt32();
     CheckSum           = br.ReadUInt32();
     Subsystem          = br.ReadUInt16();
     DllCharacteristics = br.ReadUInt16();
     if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
     {
         SizeOfStackReserve = br.ReadUInt32();
         SizeOfStackCommit  = br.ReadUInt32();
         SizeOfHeapReserve  = br.ReadUInt32();
         SizeOfHeapCommit   = br.ReadUInt32();
     }
     else
     {
         SizeOfStackReserve = br.ReadUInt64();
         SizeOfStackCommit  = br.ReadUInt64();
         SizeOfHeapReserve  = br.ReadUInt64();
         SizeOfHeapCommit   = br.ReadUInt64();
     }
     LoaderFlags         = br.ReadUInt32();
     NumberOfRvaAndSizes = br.ReadUInt32();
     DataDirectory       = new IMAGE_DATA_DIRECTORY[NumberOfRvaAndSizes];
     for (uint i = 0; i < NumberOfRvaAndSizes; i++)
     {
         DataDirectory[i] = new IMAGE_DATA_DIRECTORY();
         DataDirectory[i].Read(br);
     }
 }
Beispiel #2
0
		internal void Read(BinaryReader br)
		{
			Magic = br.ReadUInt16();
			if (Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC && Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)
			{
				throw new BadImageFormatException();
			}
			MajorLinkerVersion = br.ReadByte();
			MinorLinkerVersion = br.ReadByte();
			SizeOfCode = br.ReadUInt32();
			SizeOfInitializedData = br.ReadUInt32();
			SizeOfUninitializedData = br.ReadUInt32();
			AddressOfEntryPoint = br.ReadUInt32();
			BaseOfCode = br.ReadUInt32();
			if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
			{
				BaseOfData = br.ReadUInt32();
				ImageBase = br.ReadUInt32();
			}
			else
			{
				ImageBase = br.ReadUInt64();
			}
			SectionAlignment = br.ReadUInt32();
			FileAlignment = br.ReadUInt32();
			MajorOperatingSystemVersion = br.ReadUInt16();
			MinorOperatingSystemVersion = br.ReadUInt16();
			MajorImageVersion = br.ReadUInt16();
			MinorImageVersion = br.ReadUInt16();
			MajorSubsystemVersion = br.ReadUInt16();
			MinorSubsystemVersion = br.ReadUInt16();
			Win32VersionValue = br.ReadUInt32();
			SizeOfImage = br.ReadUInt32();
			SizeOfHeaders = br.ReadUInt32();
			CheckSum = br.ReadUInt32();
			Subsystem = br.ReadUInt16();
			DllCharacteristics = br.ReadUInt16();
			if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
			{
				SizeOfStackReserve = br.ReadUInt32();
				SizeOfStackCommit = br.ReadUInt32();
				SizeOfHeapReserve = br.ReadUInt32();
				SizeOfHeapCommit = br.ReadUInt32();
			}
			else
			{
				SizeOfStackReserve = br.ReadUInt64();
				SizeOfStackCommit = br.ReadUInt64();
				SizeOfHeapReserve = br.ReadUInt64();
				SizeOfHeapCommit = br.ReadUInt64();
			}
			LoaderFlags = br.ReadUInt32();
			NumberOfRvaAndSizes = br.ReadUInt32();
			DataDirectory = new IMAGE_DATA_DIRECTORY[NumberOfRvaAndSizes];
			for (uint i = 0; i < NumberOfRvaAndSizes; i++)
			{
				DataDirectory[i] = new IMAGE_DATA_DIRECTORY();
				DataDirectory[i].Read(br);
			}
		}