Ejemplo n.º 1
0
 public override void UpdateReferences(BuildingContext context)
 {
     UpdateSectionHeaders();
     base.UpdateReferences(context);
     UpdateNtHeaders();
     UpdateRelocations();
 }
Ejemplo n.º 2
0
 public override void UpdateReferences(BuildingContext context)
 {
     base.UpdateReferences(context);
     _resourceDirectory.VirtualAddress =
         (uint)_offsetConverter.FileOffsetToRva(_directoryTablesBuilder.StartOffset);
     _resourceDirectory.Size = GetPhysicalLength();
 }
Ejemplo n.º 3
0
 public override void UpdateReferences(BuildingContext context)
 {
     base.UpdateReferences(context);
     foreach (var entry in _dataEntries)
     {
         entry.OffsetToData =
             (uint)_offsetConverter.FileOffsetToRva(_dataTableBuilder.GetDataSegment(entry).StartOffset);
     }
 }
Ejemplo n.º 4
0
 public virtual void UpdateReferences(BuildingContext context)
 {
     foreach (var segment in Segments)
     {
         var builder = segment as FileSegmentBuilder;
         if (builder != null)
             builder.UpdateReferences(context);
     }
 }
Ejemplo n.º 5
0
 public override void Build(BuildingContext context)
 {
     foreach (var fieldRva in context.Assembly.NetDirectory.
         MetadataHeader.GetStream<TableStream>().GetTable<FieldRva>())
     {
         GetFieldRvaSegment(fieldRva);
     }
     base.Build(context);
 }
Ejemplo n.º 6
0
 public override void UpdateReferences(BuildingContext context)
 {
     foreach (var fieldRva in context.Assembly.NetDirectory.
         MetadataHeader.GetStream<TableStream>().GetTable<FieldRva>())
     {
         fieldRva.Rva = fieldRva.MetadataRow.Column1 =
             (uint)context.Assembly.FileOffsetToRva(GetFieldRvaSegment(fieldRva).StartOffset);
     }
     base.UpdateReferences(context);
 }
 public override void Build(BuildingContext context)
 {
     foreach (var resource in context.Assembly.NetDirectory.
         MetadataHeader.GetStream<TableStream>().GetTable<ManifestResource>())
     {
         if (resource.IsEmbedded)
             resource.Offset = GetSegmentRelativeOffset(GetResourceSegment(resource));
     }
     base.Build(context);
 }
Ejemplo n.º 8
0
 public override void Build(BuildingContext context)
 {
     foreach (var method in context.Assembly.NetDirectory.
         MetadataHeader.GetStream<TableStream>().GetTable<MethodDefinition>())
     {
         if (method.MethodBody != null)
             Segments.Add(method.MethodBody);
     }
     base.Build(context);
 }
Ejemplo n.º 9
0
 public virtual void UpdateReferences(BuildingContext context)
 {
     foreach (var segment in Segments)
     {
         var builder = segment as FileSegmentBuilder;
         if (builder != null)
         {
             builder.UpdateReferences(context);
         }
     }
 }
        public override void Build(BuildingContext context)
        {
            var is32Bit = context.Assembly.NtHeaders.OptionalHeader.Magic == OptionalHeaderMagic.Pe32;
            _lookupTablesBuilder.Is32Bit = is32Bit;
            AddressTablesBuilder.Is32Bit = is32Bit;

            foreach (var moduleImport in _directory.ModuleImports)
                AppendModuleImport(moduleImport);
            _entryTableBuilder.Segments.Add(new ImageModuleImport());
            base.Build(context);
        }
        private void UpdateDataDirectories(BuildingContext context)
        {
            var optionalHeader  = context.Assembly.NtHeaders.OptionalHeader;
            var importDirectory = optionalHeader.DataDirectories[ImageDataDirectory.ImportDirectoryIndex];

            importDirectory.VirtualAddress = (uint)_offsetConverter.FileOffsetToRva(_entryTableBuilder.StartOffset);
            importDirectory.Size           = this.GetPhysicalLength();

            var iatDirectory = optionalHeader.DataDirectories[ImageDataDirectory.IatDirectoryIndex];

            iatDirectory.VirtualAddress = (uint)_offsetConverter.FileOffsetToRva(AddressTablesBuilder.StartOffset);
            iatDirectory.Size           = AddressTablesBuilder.GetPhysicalLength();
        }
Ejemplo n.º 12
0
 public override void UpdateReferences(BuildingContext context)
 {
     foreach (var method in context.Assembly.NetDirectory.
         MetadataHeader.GetStream<TableStream>().GetTable<MethodDefinition>())
     {
         if (method.MethodBody != null)
         {
             method.Rva = method.MetadataRow.Column1 =
                 (uint)context.Assembly.FileOffsetToRva(method.MethodBody.StartOffset);
         }
     }
     base.UpdateReferences(context);
 }
        public override void Build(BuildingContext context)
        {
            var is32Bit = context.Assembly.NtHeaders.OptionalHeader.Magic == OptionalHeaderMagic.Pe32;

            _lookupTablesBuilder.Is32Bit = is32Bit;
            AddressTablesBuilder.Is32Bit = is32Bit;

            foreach (var moduleImport in _directory.ModuleImports)
            {
                AppendModuleImport(moduleImport);
            }
            _entryTableBuilder.Segments.Add(new ImageModuleImport());
            base.Build(context);
        }
Ejemplo n.º 14
0
        public virtual void UpdateOffsets(BuildingContext context)
        {
            for (int i = 0; i < Segments.Count; i++)
            {
                if (i == 0)
                    Segments[i].StartOffset = StartOffset;
                else
                    Segments[i].StartOffset = Segments[i - 1].StartOffset + Segments[i - 1].GetPhysicalLength();

                var builder = Segments[i] as FileSegmentBuilder;
                if (builder != null)
                    builder.UpdateOffsets(context);
            }
        }
Ejemplo n.º 15
0
        public override void UpdateOffsets(BuildingContext context)
        {
            for (int i = 0; i < Segments.Count; i++)
            {
                if (i == 0)
                    Segments[i].StartOffset = StartOffset;
                else
                    Segments[i].StartOffset = Segments[i - 1].StartOffset + Segments[i - 1].GetPhysicalLength();

                var methodBody = Segments[i] as MethodBody;
                if (methodBody != null && methodBody.IsFat)
                    methodBody.StartOffset = Align((uint)methodBody.StartOffset, 4);
            }
        }
Ejemplo n.º 16
0
        public override void UpdateReferences(BuildingContext context)
        {
            var isDll = context.Assembly.NtHeaders.FileHeader.Characteristics.HasFlag(ImageCharacteristics.Dll);

            var mscoreeModule = context.Assembly.ImportDirectory.ModuleImports.First(x => x.Name == "mscoree.dll");
            var corMainImport = mscoreeModule.SymbolImports.First(
                x => x.HintName != null && x.HintName.Name == (isDll ? "_CorDllMain" : "_CorExeMain"));
            var address = corMainImport.GetTargetAddress(true);

            context.Assembly.NtHeaders.OptionalHeader.AddressOfEntrypoint =
                (uint)context.Assembly.FileOffsetToRva(StartOffset);

            _addressSegment.Data = BitConverter.GetBytes((uint)(address | context.Assembly.NtHeaders.OptionalHeader.ImageBase));
            base.UpdateReferences(context);
        }
Ejemplo n.º 17
0
        public virtual void UpdateOffsets(BuildingContext context)
        {
            for (int i = 0; i < Segments.Count; i++)
            {
                if (i == 0)
                {
                    Segments[i].StartOffset = StartOffset;
                }
                else
                {
                    Segments[i].StartOffset = Segments[i - 1].StartOffset + Segments[i - 1].GetPhysicalLength();
                }

                var builder = Segments[i] as FileSegmentBuilder;
                if (builder != null)
                {
                    builder.UpdateOffsets(context);
                }
            }
        }
Ejemplo n.º 18
0
 public override void Build(BuildingContext context)
 {
     AddDirectory(_rootDirectory, 0);
     base.Build(context);
 }
Ejemplo n.º 19
0
 public override void UpdateReferences(BuildingContext context)
 {
     foreach (var directory in _directories)
         UpdateReferences(directory);
     base.UpdateReferences(context);
 }
Ejemplo n.º 20
0
 public override void UpdateReferences(BuildingContext context)
 {
     base.UpdateReferences(context);
     foreach (var entry in _dataEntries)
     {
         entry.OffsetToData =
             (uint)_offsetConverter.FileOffsetToRva(_dataTableBuilder.GetDataSegment(entry).StartOffset);
     }
 }
Ejemplo n.º 21
0
 public override void Build(BuildingContext context)
 {
     foreach (var segment in Segments.OfType<FileSegmentBuilder>().Reverse())
         segment.Build(context);
 }
Ejemplo n.º 22
0
 public override void Build(BuildingContext context)
 {
     AppendResourceDirectory();
     AppendRelocationDirectory();
     base.Build(context);
 }
Ejemplo n.º 23
0
            public override void UpdateReferences(BuildingContext context)
            {
                var sectionAlignment = _builder.Assembly.NtHeaders.OptionalHeader.SectionAlignment;

                var virtualAddress = sectionAlignment;
                foreach (var section in _sectionBuilders)
                {
                    section.Header.VirtualAddress = virtualAddress;
                    var virtualSize = section.GetVirtualSize();
                    section.Header.VirtualSize = virtualSize;
                    virtualAddress += Align(virtualSize, sectionAlignment);

                    section.Header.PointerToRawData = (uint)section.StartOffset;
                    section.Header.SizeOfRawData = section.GetPhysicalLength();
                }

                base.UpdateReferences(context);
            }
        private void UpdateDataDirectories(BuildingContext context)
        {
            var optionalHeader = context.Assembly.NtHeaders.OptionalHeader;
            var importDirectory = optionalHeader.DataDirectories[ImageDataDirectory.ImportDirectoryIndex];
            importDirectory.VirtualAddress = (uint)_offsetConverter.FileOffsetToRva(_entryTableBuilder.StartOffset);
            importDirectory.Size = this.GetPhysicalLength();

            var iatDirectory = optionalHeader.DataDirectories[ImageDataDirectory.IatDirectoryIndex];
            iatDirectory.VirtualAddress = (uint)_offsetConverter.FileOffsetToRva(AddressTablesBuilder.StartOffset);
            iatDirectory.Size = AddressTablesBuilder.GetPhysicalLength();
        }
 public override void UpdateReferences(BuildingContext context)
 {
     UpdateTableRvas();
     UpdateDataDirectories(context);
     base.UpdateReferences(context);
 }
Ejemplo n.º 26
0
 public override void UpdateOffsets(BuildingContext context)
 {
     if (NetResourceDirectoryBuilder.Segments.Count == 0)
         Segments.Remove(NetResourceDirectoryBuilder);
     base.UpdateOffsets(context);
 }
Ejemplo n.º 27
0
 public override void Build(BuildingContext context)
 {
     AddDirectory(_rootDirectory, 0);
     base.Build(context);
 }
 public override void UpdateReferences(BuildingContext context)
 {
     UpdateTableRvas();
     UpdateDataDirectories(context);
     base.UpdateReferences(context);
 }
Ejemplo n.º 29
0
 public virtual void Build(BuildingContext context)
 {
     foreach (var builder in Segments.OfType<FileSegmentBuilder>())
         builder.Build(context);
 }
Ejemplo n.º 30
0
 public override void UpdateReferences(BuildingContext context)
 {
     UpdateDebugDirectory();
     UpdateMetaDataDirectories();
     base.UpdateReferences(context);
 }
Ejemplo n.º 31
0
        public override void Build(BuildingContext context)
        {
            base.Build(context);

            var stringsBuffer = ((NetBuildingContext)context).GetStreamBuffer<UserStringStreamBuffer>();
            foreach (var instruction in Instructions)
            {
                var value = instruction.Operand as string;
                if (value != null)
                {
                    stringsBuffer.GetStringOffset(value);
                }
            }
        }
Ejemplo n.º 32
0
            public override void UpdateOffsets(BuildingContext context)
            {
                var fileAlignment = _builder.Assembly.NtHeaders.OptionalHeader.FileAlignment;
                var fileAddress = fileAlignment;

                for (int i = 0; i < _sectionBuilders.Count; i++)
                {
                    if (i == 0)
                        _sectionBuilders[i].Header.StartOffset = StartOffset;
                    else
                        _sectionBuilders[i].Header.StartOffset = _sectionBuilders[i - 1].Header.StartOffset + _sectionBuilders[i - 1].Header.GetPhysicalLength();

                    _sectionBuilders[i].StartOffset = fileAddress;
                    _sectionBuilders[i].UpdateOffsets(context);
                    fileAddress += _sectionBuilders[i].GetPhysicalLength();

                }
            }
Ejemplo n.º 33
0
 public override void UpdateReferences(BuildingContext context)
 {
     base.UpdateReferences(context);
     CalculateOffsets();
 }
Ejemplo n.º 34
0
 public WritingContext(WindowsAssembly assembly, IBinaryStreamWriter writer, BuildingContext buildingContext)
 {
     Assembly = assembly;
     Writer = writer;
     BuildingContext = buildingContext;
 }