Example #1
0
 public override void Write(WritingContext context)
 {
     foreach (var block in Blocks)
     {
         block.Write(context);
     }
 }
Example #2
0
        public override void Write(WritingContext context)
        {
            var stream = context.Writer;

            stream.WriteUInt32(VirtualAddress);
            stream.WriteUInt32(Size);
        }
Example #3
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt32(NameId);
            writer.WriteUInt32(OffsetToData);
        }
Example #4
0
 public override void Write(WritingContext context)
 {
     foreach (var moduleImport in ModuleImports)
     {
         moduleImport.Write(context);
     }
     new ImageModuleImport().Write(context);
 }
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt32(PageRva);
     writer.WriteUInt32(BlockSize);
     foreach (var entry in Entries)
         entry.Write(context);
 }
Example #6
0
 public override void Write(WritingContext context)
 {
     var rva = OffsetConverter.FileOffsetToRva(Reference.StartOffset);
     if (Is32Bit)
         context.Writer.WriteUInt32((uint)rva);
     else
         context.Writer.WriteUInt64((ulong)rva);
 }
Example #7
0
        public override void Write(WritingContext context)
        {
            // TODO: more elegant way of creating buffer.
            uint physicalLength = GetPhysicalLength();

            context.Writer.Position += physicalLength;
            context.Writer.Position -= physicalLength;
            base.Write(context);
        }
Example #8
0
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt16(Hint);
     writer.WriteBytes(Encoding.ASCII.GetBytes(Name));
     writer.WriteByte(0);
     if (writer.Position % 2 != 0)
         writer.WriteByte(0);
 }
Example #9
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt32(ImportLookupTableRva);
            writer.WriteUInt32(TimeDateStamp);
            writer.WriteUInt32(ForwarderChain);
            writer.WriteUInt32(NameRva);
            writer.WriteUInt32(ImportAddressTableRva);
        }
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt32(PageRva);
            writer.WriteUInt32(BlockSize);
            foreach (var entry in Entries)
            {
                entry.Write(context);
            }
        }
Example #11
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt16(Hint);
            writer.WriteBytes(Encoding.ASCII.GetBytes(Name));
            writer.WriteByte(0);
            if (writer.Position % 2 != 0)
            {
                writer.WriteByte(0);
            }
        }
Example #12
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt16((ushort)Machine);
            writer.WriteUInt16(NumberOfSections);
            writer.WriteUInt32(TimeDateStamp);
            writer.WriteUInt32(PointerToSymbolTable);
            writer.WriteUInt32(NumberOfSymbols);
            writer.WriteUInt16(SizeOfOptionalHeader);
            writer.WriteUInt16((ushort)Characteristics);
        }
Example #13
0
        public override void Write(WritingContext context)
        {
            var rva = OffsetConverter.FileOffsetToRva(Reference.StartOffset);

            if (Is32Bit)
            {
                context.Writer.WriteUInt32((uint)rva);
            }
            else
            {
                context.Writer.WriteUInt64((ulong)rva);
            }
        }
Example #14
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt32(Characteristics);
            writer.WriteUInt32(TimeDateStamp);
            writer.WriteUInt16(MajorVersion);
            writer.WriteUInt16(MinorVersion);
            writer.WriteUInt32((uint)Type);
            writer.WriteUInt32(SizeOfData);
            writer.WriteUInt32(AddressOfRawData);
            writer.WriteUInt32(PointerToRawData);
        }
Example #15
0
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt32(Characteristics);
     writer.WriteUInt32(TimeDateStamp);
     writer.WriteUInt16(MajorVersion);
     writer.WriteUInt16(MinorVersion);
     writer.WriteUInt32(NameRva);
     writer.WriteUInt32(OrdinalBase);
     writer.WriteUInt32(NumberOfFunctions);
     writer.WriteUInt32(NumberOfNames);
     writer.WriteUInt32(AddressOfFunctions);
     writer.WriteUInt32(AddressOfNames);
     writer.WriteUInt32(AddressOfNameOrdinals);
 }
Example #16
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt32(Characteristics);
            writer.WriteUInt32(TimeDateStamp);
            writer.WriteUInt16(MajorVersion);
            writer.WriteUInt16(MinorVersion);
            writer.WriteUInt16(NamedEntriesCount);
            writer.WriteUInt16(IdEntriesCount);

            foreach (var entry in Entries)
            {
                entry.Write(context);
            }
        }
Example #17
0
        public override void Write(WritingContext context)
        {
            var writer    = context.Writer;
            var nameBytes = Encoding.ASCII.GetBytes(Name ?? string.Empty);

            writer.WriteBytes(nameBytes);
            writer.WriteBytes(new byte[8 - nameBytes.Length]);

            writer.WriteUInt32(VirtualSize);
            writer.WriteUInt32(VirtualAddress);
            writer.WriteUInt32(SizeOfRawData);
            writer.WriteUInt32(PointerToRawData);
            writer.WriteUInt32(PointerToRelocations);
            writer.WriteUInt32(PointerToLinenumbers);
            writer.WriteUInt16(NumberOfRelocations);
            writer.WriteUInt16(NumberOfLinenumbers);
            writer.WriteUInt32((uint)Attributes);
        }
Example #18
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteUInt32(Signature);
     FileHeader.Write(context);
     OptionalHeader.Write(context);
 }
Example #19
0
 /// <summary>
 /// Writes the segment to a specific writing context.
 /// </summary>
 /// <param name="context">The context to use.</param>
 public abstract void Write(WritingContext context);
Example #20
0
        public override void Write(WritingContext context)
        {
            var  writer = context.Writer;
            long start  = writer.Position;

            writer.WriteUInt16((ushort)Magic);
            writer.WriteByte(MajorLinkerVersion);
            writer.WriteByte(MinorLinkerVersion);
            writer.WriteUInt32(SizeOfCode);
            writer.WriteUInt32(SizeOfInitializedData);
            writer.WriteUInt32(SizeOfUninitializedData);
            writer.WriteUInt32(AddressOfEntrypoint);
            writer.WriteUInt32(BaseOfCode);

            switch (Magic)
            {
            case OptionalHeaderMagic.Pe32:
                writer.WriteUInt32(BaseOfData);
                writer.WriteUInt32((uint)ImageBase);
                break;

            case OptionalHeaderMagic.Pe32Plus:
                writer.WriteUInt64(ImageBase);
                break;

            default:
                throw new NotSupportedException(string.Format("Unrecognized or unsupported executable format."));
            }

            writer.WriteUInt32(SectionAlignment);
            writer.WriteUInt32(FileAlignment);
            writer.WriteUInt16(MajorOperatingSystemVersion);
            writer.WriteUInt16(MinorOperatingSystemVersion);
            writer.WriteUInt16(MajorImageVersion);
            writer.WriteUInt16(MinorImageVersion);
            writer.WriteUInt16(MajorSubsystemVersion);
            writer.WriteUInt16(MinorSubsystemVersion);
            writer.WriteUInt32(Win32VersionValue);
            writer.WriteUInt32(SizeOfImage);
            writer.WriteUInt32(SizeOfHeaders);
            writer.WriteUInt32(CheckSum);
            writer.WriteUInt16((ushort)Subsystem);
            writer.WriteUInt16((ushort)DllCharacteristics);

            if (Magic == OptionalHeaderMagic.Pe32)
            {
                writer.WriteUInt32((uint)SizeOfStackReserve);
                writer.WriteUInt32((uint)SizeOfStackCommit);
                writer.WriteUInt32((uint)SizeOfHeapReserve);
                writer.WriteUInt32((uint)SizeOfHeapCommit);
            }
            else
            {
                writer.WriteUInt64(SizeOfStackReserve);
                writer.WriteUInt64(SizeOfStackCommit);
                writer.WriteUInt64(SizeOfHeapReserve);
                writer.WriteUInt64(SizeOfHeapCommit);
            }

            writer.WriteUInt32(LoaderFlags);
            writer.WriteUInt32(NumberOfRvaAndSizes);

            foreach (var directory in DataDirectories)
            {
                directory.Write(context);
            }

            writer.WriteBytes(new byte[start + context.Assembly.NtHeaders.FileHeader.SizeOfOptionalHeader - writer.Position]);
        }
Example #21
0
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt16((ushort)Machine);
     writer.WriteUInt16(NumberOfSections);
     writer.WriteUInt32(TimeDateStamp);
     writer.WriteUInt32(PointerToSymbolTable);
     writer.WriteUInt32(NumberOfSymbols);
     writer.WriteUInt16(SizeOfOptionalHeader);
     writer.WriteUInt16((ushort)Characteristics);
 }
Example #22
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;
            long start = writer.Position;

            writer.WriteUInt16((ushort)Magic);
            writer.WriteByte(MajorLinkerVersion);
            writer.WriteByte(MinorLinkerVersion);
            writer.WriteUInt32(SizeOfCode);
            writer.WriteUInt32(SizeOfInitializedData);
            writer.WriteUInt32(SizeOfUninitializedData);
            writer.WriteUInt32(AddressOfEntrypoint);
            writer.WriteUInt32(BaseOfCode);

            switch (Magic)
            {
                case OptionalHeaderMagic.Pe32:
                    writer.WriteUInt32(BaseOfData);
                    writer.WriteUInt32((uint)ImageBase);
                    break;
                case OptionalHeaderMagic.Pe32Plus:
                    writer.WriteUInt64(ImageBase);
                    break;
                default:
                    throw new NotSupportedException(string.Format("Unrecognized or unsupported executable format."));
            }

            writer.WriteUInt32(SectionAlignment);
            writer.WriteUInt32(FileAlignment);
            writer.WriteUInt16(MajorOperatingSystemVersion);
            writer.WriteUInt16(MinorOperatingSystemVersion);
            writer.WriteUInt16(MajorImageVersion);
            writer.WriteUInt16(MinorImageVersion);
            writer.WriteUInt16(MajorSubsystemVersion);
            writer.WriteUInt16(MinorSubsystemVersion);
            writer.WriteUInt32(Win32VersionValue);
            writer.WriteUInt32(SizeOfImage);
            writer.WriteUInt32(SizeOfHeaders);
            writer.WriteUInt32(CheckSum);
            writer.WriteUInt16((ushort)Subsystem);
            writer.WriteUInt16((ushort)DllCharacteristics);

            if (Magic == OptionalHeaderMagic.Pe32)
            {
                writer.WriteUInt32((uint)SizeOfStackReserve);
                writer.WriteUInt32((uint)SizeOfStackCommit);
                writer.WriteUInt32((uint)SizeOfHeapReserve);
                writer.WriteUInt32((uint)SizeOfHeapCommit);
            }
            else
            {
                writer.WriteUInt64(SizeOfStackReserve);
                writer.WriteUInt64(SizeOfStackCommit);
                writer.WriteUInt64(SizeOfHeapReserve);
                writer.WriteUInt64(SizeOfHeapCommit);
            }

            writer.WriteUInt32(LoaderFlags);
            writer.WriteUInt32(NumberOfRvaAndSizes);

            foreach (var directory in DataDirectories)
                directory.Write(context);

            writer.WriteBytes(new byte[start + context.Assembly.NtHeaders.FileHeader.SizeOfOptionalHeader - writer.Position]);
        }
Example #23
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(_defaultDosHeader);
 }
 public override void Write(WritingContext context)
 {
     foreach (var block in Blocks)
         block.Write(context);
 }
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt32(NameId);
     writer.WriteUInt32(OffsetToData);
 }
Example #26
0
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt32(Characteristics);
     writer.WriteUInt32(TimeDateStamp);
     writer.WriteUInt16(MajorVersion);
     writer.WriteUInt16(MinorVersion);
     writer.WriteUInt32((uint)Type);
     writer.WriteUInt32(SizeOfData);
     writer.WriteUInt32(AddressOfRawData);
     writer.WriteUInt32(PointerToRawData);
 }
Example #27
0
 public override void Write(WritingContext context)
 {
     var stream = context.Writer;
     stream.WriteUInt32(VirtualAddress);
     stream.WriteUInt32(Size);
 }
 public override void Write(WritingContext context)
 {
     foreach (var moduleImport in ModuleImports)
         moduleImport.Write(context);
     new ImageModuleImport().Write(context);
 }
Example #29
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;
            var nameBytes = Encoding.ASCII.GetBytes(Name ?? string.Empty);
            writer.WriteBytes(nameBytes);
            writer.WriteBytes(new byte[8 - nameBytes.Length]);

            writer.WriteUInt32(VirtualSize);
            writer.WriteUInt32(VirtualAddress);
            writer.WriteUInt32(SizeOfRawData);
            writer.WriteUInt32(PointerToRawData);
            writer.WriteUInt32(PointerToRelocations);
            writer.WriteUInt32(PointerToLinenumbers);
            writer.WriteUInt16(NumberOfRelocations);
            writer.WriteUInt16(NumberOfLinenumbers);
            writer.WriteUInt32((uint)Attributes);
        }
Example #30
0
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt32(ImportLookupTableRva);
     writer.WriteUInt32(TimeDateStamp);
     writer.WriteUInt32(ForwarderChain);
     writer.WriteUInt32(NameRva);
     writer.WriteUInt32(ImportAddressTableRva);
 }
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt32(Characteristics);
     writer.WriteUInt32(TimeDateStamp);
     writer.WriteUInt16(MajorVersion);
     writer.WriteUInt16(MinorVersion);
     writer.WriteUInt32(NameRva);
     writer.WriteUInt32(OrdinalBase);
     writer.WriteUInt32(NumberOfFunctions);
     writer.WriteUInt32(NumberOfNames);
     writer.WriteUInt32(AddressOfFunctions);
     writer.WriteUInt32(AddressOfNames);
     writer.WriteUInt32(AddressOfNameOrdinals);
 }
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;
            writer.WriteUInt32(Characteristics);
            writer.WriteUInt32(TimeDateStamp);
            writer.WriteUInt16(MajorVersion);
            writer.WriteUInt16(MinorVersion);
            writer.WriteUInt16(NamedEntriesCount);
            writer.WriteUInt16(IdEntriesCount);

            foreach (var entry in Entries)
                entry.Write(context);
        }
Example #33
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(Data);
 }
Example #34
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteUInt32(Signature);
     FileHeader.Write(context);
     OptionalHeader.Write(context);
 }
Example #35
0
 /// <summary>
 /// Writes the segment to a specific writing context.
 /// </summary>
 /// <param name="context">The context to use.</param>
 public abstract void Write(WritingContext context);
Example #36
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(Data);
 }
Example #37
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(_defaultDosHeader);
 }