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

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

            writer.WriteUInt32(NameId);
            writer.WriteUInt32(OffsetToData);
        }
Ejemplo n.º 4
0
 public override void Write(WritingContext context)
 {
     foreach (var moduleImport in ModuleImports)
     {
         moduleImport.Write(context);
     }
     new ImageModuleImport().Write(context);
 }
Ejemplo n.º 5
0
 public override void Write(WritingContext context)
 {
     var writer = context.Writer;
     writer.WriteUInt32(PageRva);
     writer.WriteUInt32(BlockSize);
     foreach (var entry in Entries)
         entry.Write(context);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
        public override void Write(WritingContext context)
        {
            var writer = context.Writer;

            writer.WriteUInt32(PageRva);
            writer.WriteUInt32(BlockSize);
            foreach (var entry in Entries)
            {
                entry.Write(context);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 18
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteUInt32(Signature);
     FileHeader.Write(context);
     OptionalHeader.Write(context);
 }
Ejemplo n.º 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);
Ejemplo n.º 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]);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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]);
        }
Ejemplo n.º 23
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(_defaultDosHeader);
 }
Ejemplo n.º 24
0
 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 27
0
 public override void Write(WritingContext context)
 {
     var stream = context.Writer;
     stream.WriteUInt32(VirtualAddress);
     stream.WriteUInt32(Size);
 }
Ejemplo n.º 28
0
 public override void Write(WritingContext context)
 {
     foreach (var moduleImport in ModuleImports)
         moduleImport.Write(context);
     new ImageModuleImport().Write(context);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 31
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);
 }
Ejemplo n.º 32
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);
        }
Ejemplo n.º 33
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(Data);
 }
Ejemplo n.º 34
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteUInt32(Signature);
     FileHeader.Write(context);
     OptionalHeader.Write(context);
 }
Ejemplo n.º 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);
Ejemplo n.º 36
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(Data);
 }
Ejemplo n.º 37
0
 public override void Write(WritingContext context)
 {
     context.Writer.WriteBytes(_defaultDosHeader);
 }