Example #1
0
        internal static IMAGE_OPTIONAL_HEADER FromBinaryReader(BinaryReader reader)
        {
            IMAGE_OPTIONAL_HEADER ret = new IMAGE_OPTIONAL_HEADER();

            try
            {
                ret.Magic = reader.ReadUInt16();
                ret.MajorLinkerVersion      = reader.ReadByte();
                ret.MinorLinkerVersion      = reader.ReadByte();
                ret.SizeOfCode              = reader.ReadUInt32();
                ret.SizeOfInitializedData   = reader.ReadUInt32();
                ret.SizeOfUninitializedData = reader.ReadUInt32();
                ret.AddressOfEntryPoint     = reader.ReadUInt32();
                ret.BaseOfCode              = reader.ReadUInt32();
                ret.BaseOfData              = reader.ReadUInt32();
                ret.ImageBase                   = reader.ReadUInt32();
                ret.SectionAlignment            = reader.ReadUInt32();
                ret.FileAlignment               = reader.ReadUInt32();
                ret.MajorOperatingSystemVersion = reader.ReadUInt16();
                ret.MinorOperatingSystemVersion = reader.ReadUInt16();
                ret.MajorImageVersion           = reader.ReadUInt16();
                ret.MinorImageVersion           = reader.ReadUInt16();
                ret.MajorSubsystemVersion       = reader.ReadUInt16();
                ret.MinorSubsystemVersion       = reader.ReadUInt16();
                ret.Win32VersionValue           = reader.ReadUInt32();
                ret.SizeOfImage                 = reader.ReadUInt32();
                ret.SizeOfHeaders               = reader.ReadUInt32();
                ret.CheckSum            = reader.ReadUInt32();
                ret.Subsystem           = reader.ReadUInt16();
                ret.DllCharacteristics  = reader.ReadUInt16();
                ret.SizeOfStackReserve  = reader.ReadUInt32();
                ret.SizeOfStackCommit   = reader.ReadUInt32();
                ret.SizeOfHeapReserve   = reader.ReadUInt32();
                ret.SizeOfHeapCommit    = reader.ReadUInt32();
                ret.LoaderFlags         = reader.ReadUInt32();
                ret.NumberOfRvaAndSizes = reader.ReadUInt32();

                for (int i = 0; i < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; i++)
                {
                    ret.DataDirectory[i] = new IMAGE_DATA_DIRECTORY();
                    ret.DataDirectory[i].VirtualAddress = reader.ReadUInt32();
                    ret.DataDirectory[i].Size           = reader.ReadUInt32();
                }
            }
            catch
            {
                return(null);
            }
            return(ret);
        }
Example #2
0
        internal static IMAGE_NT_HEADERS FromBinaryReader(BinaryReader reader)
        {
            IMAGE_NT_HEADERS ret = new IMAGE_NT_HEADERS();

            ret.Signature = reader.ReadUInt32();
            if (ret.Signature != IMAGE_NT_SIGNATURE)
            {
                return(null);
            }
            ret.FileHeader = IMAGE_FILE_HEADER.FromBinaryReader(reader);
            if (ret.FileHeader == null)
            {
                return(null);
            }
            ret.OptionalHeader = IMAGE_OPTIONAL_HEADER.FromBinaryReader(reader);
            if (ret.OptionalHeader == null)
            {
                return(null);
            }
            return(ret);
        }