示例#1
0
        private static void InitializeOptionalHeader(ImageOptionalHeader optionalHeader)
        {
            optionalHeader.Magic                       = OptionalHeaderMagic.Pe32;
            optionalHeader.ImageBase                   = 0x400000;
            optionalHeader.SectionAlignment            = 0x2000;
            optionalHeader.FileAlignment               = 0x200;
            optionalHeader.MajorOperatingSystemVersion = 4;
            optionalHeader.MajorSubsystemVersion       = 4;
            optionalHeader.MajorLinkerVersion          = 6;
            optionalHeader.Subsystem                   = ImageSubSystem.WindowsCui;
            optionalHeader.SizeOfStackReserve          = 0x100000;
            optionalHeader.SizeOfStackCommit           = 0x1000;
            optionalHeader.SizeOfHeapReserve           = 0x100000;
            optionalHeader.SizeOfHeapCommit            = 0x1000;
            optionalHeader.NumberOfRvaAndSizes         = 0x10;
            optionalHeader.DllCharacteristics          = ImageDllCharacteristics.DynamicBase |
                                                         ImageDllCharacteristics.NxCompat |
                                                         ImageDllCharacteristics.NoSeh |
                                                         ImageDllCharacteristics.TerminalServerAware;

            for (int i = 0; i < 0x10; i++)
            {
                optionalHeader.DataDirectories.Add(new ImageDataDirectory());
            }
        }
示例#2
0
 private void AssertCommonOptHeaderProperties(ImageOptionalHeader optHeader)
 {
     Assert.Equal(MagicType.Bit32, optHeader.Magic);
     Assert.Equal((ushort)0x11, optHeader.MajorLinkerVersion);
     Assert.Equal((ushort)0x33, optHeader.MinorLinkerVersion);
     Assert.Equal((uint)0x22115544, optHeader.SizeOfCode);
     Assert.Equal(0xaa998877, optHeader.SizeOfInitializedData);
     Assert.Equal((uint)0x22115544, optHeader.SizeOfUninitializedData);
     Assert.Equal(0xaa778822, optHeader.AddressOfEntryPoint);
     Assert.Equal(0xaaff8877, optHeader.BaseOfCode);
     Assert.Equal(0xaa99cc77, optHeader.SectionAlignment);
     Assert.Equal(0xaa99ffdd, optHeader.FileAlignment);
     Assert.Equal((ushort)0x8877, optHeader.MajorOperatingSystemVersion);
     Assert.Equal((ushort)0xaa99, optHeader.MinorOperatingSystemVersion);
     Assert.Equal((ushort)0x44ff, optHeader.MajorImageVersion);
     Assert.Equal((ushort)0xeedd, optHeader.MinorImageVersion);
     Assert.Equal((ushort)0x88bb, optHeader.MajorSubsystemVersion);
     Assert.Equal((ushort)0xaaee, optHeader.MinorSubsystemVersion);
     Assert.Equal(0xaa998877, optHeader.Win32VersionValue);
     Assert.Equal(0xaaff8877, optHeader.SizeOfHeaders);
     Assert.Equal(0xcc998877, optHeader.CheckSum);
     Assert.Equal(SubsystemType.WindowsCui, optHeader.Subsystem);
     Assert.Equal("Windows CUI", optHeader.SubsystemResolved);
     Assert.Equal((ushort)0xaa99, (ushort)optHeader.DllCharacteristics);
     Assert.Equal(0xaa998822, optHeader.LoaderFlags);
     Assert.Equal((uint)0x00000005, optHeader.NumberOfRvaAndSizes);
 }
示例#3
0
        internal static ImageNtHeaders FromReadingContext(ReadingContext context)
        {
            var reader = context.Reader;

            return(new ImageNtHeaders
            {
                StartOffset = reader.Position,
                Signature = reader.ReadUInt32(),
                FileHeader = ImageFileHeader.FromReadingContext(context),
                OptionalHeader = ImageOptionalHeader.FromReadingContext(context),
            });
        }
示例#4
0
        public void OptionalHeaderConstructor64BitWorks_Test()
        {
            var optHeader = new ImageOptionalHeader(new BufferFile(RawStructures.RawImageOptionalHeader64Bit), 2, true);

            AssertCommonOptHeaderProperties(optHeader);
            Assert.Equal((ulong)0x00112233aa99cc44, optHeader.ImageBase);
            Assert.Equal((ulong)0x55443322aa99ddff, optHeader.SizeOfStackReserve);
            Assert.Equal(0xaa998888aa998888, optHeader.SizeOfStackCommit);
            Assert.Equal(0xaa99cceeaa99ccee, optHeader.SizeOfHeapReserve);
            Assert.Equal(0xaa991177aa991177, optHeader.SizeOfHeapCommit);

            // Data directories
            AssertDataDirectories(optHeader.DataDirectory);
        }
示例#5
0
        public void OptionalHeaderConstructor32BitWorks_Test()
        {
            var optHeader = new ImageOptionalHeader(new BufferFile(RawStructures.RawImageOptionalHeader32Bit), 2, false);

            AssertCommonOptHeaderProperties(optHeader);
            Assert.Equal(0xaa998844, optHeader.BaseOfData);
            Assert.Equal(0xaa99cc44, optHeader.ImageBase);
            Assert.Equal(0xaa99ddff, optHeader.SizeOfStackReserve);
            Assert.Equal(0xaa998888, optHeader.SizeOfStackCommit);
            Assert.Equal(0xaa99ccee, optHeader.SizeOfHeapReserve);
            Assert.Equal(0xaa991177, optHeader.SizeOfHeapCommit);

            // Data directories
            AssertDataDirectories(optHeader.DataDirectory);
        }
示例#6
0
        private static void InitializeOptionalHeader(ImageOptionalHeader optionalHeader)
        {
            optionalHeader.Magic = OptionalHeaderMagic.Pe32;
            optionalHeader.ImageBase = 0x400000;
            optionalHeader.SectionAlignment = 0x2000;
            optionalHeader.FileAlignment = 0x200;
            optionalHeader.MajorOperatingSystemVersion = 4;
            optionalHeader.MajorSubsystemVersion = 4;
            optionalHeader.MajorLinkerVersion = 6;
            optionalHeader.Subsystem = ImageSubSystem.WindowsCui;
            optionalHeader.SizeOfStackReserve = 0x100000;
            optionalHeader.SizeOfStackCommit = 0x1000;
            optionalHeader.SizeOfHeapReserve = 0x100000;
            optionalHeader.SizeOfHeapCommit = 0x1000;
            optionalHeader.NumberOfRvaAndSizes = 0x10;
            optionalHeader.DllCharacteristics = ImageDllCharacteristics.DynamicBase |
                ImageDllCharacteristics.NxCompat |
                ImageDllCharacteristics.NoSeh |
                ImageDllCharacteristics.TerminalServerAware;

            for (int i = 0; i < 0x10; i++)
                optionalHeader.DataDirectories.Add(new ImageDataDirectory());
        }