示例#1
0
 public override void UpdateReferences(BuildingContext context)
 {
     UpdateSectionHeaders();
     base.UpdateReferences(context);
     UpdateNtHeaders();
     UpdateRelocations();
 }
 public override void UpdateReferences(BuildingContext context)
 {
     base.UpdateReferences(context);
     _resourceDirectory.VirtualAddress =
         (uint)_offsetConverter.FileOffsetToRva(_directoryTablesBuilder.StartOffset);
     _resourceDirectory.Size = GetPhysicalLength();
 }
示例#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);
     }
 }
示例#4
0
 public virtual void UpdateReferences(BuildingContext context)
 {
     foreach (var segment in Segments)
     {
         var builder = segment as FileSegmentBuilder;
         if (builder != null)
             builder.UpdateReferences(context);
     }
 }
示例#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);
 }
示例#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);
 }
 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);
 }
示例#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();
        }
 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);
        }
示例#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);
            }
        }
        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);
            }
        }
        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);
        }
示例#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);
                }
            }
        }
 public override void Build(BuildingContext context)
 {
     AddDirectory(_rootDirectory, 0);
     base.Build(context);
 }
 public override void UpdateReferences(BuildingContext context)
 {
     foreach (var directory in _directories)
         UpdateReferences(directory);
     base.UpdateReferences(context);
 }
 public override void UpdateReferences(BuildingContext context)
 {
     base.UpdateReferences(context);
     foreach (var entry in _dataEntries)
     {
         entry.OffsetToData =
             (uint)_offsetConverter.FileOffsetToRva(_dataTableBuilder.GetDataSegment(entry).StartOffset);
     }
 }
示例#21
0
 public override void Build(BuildingContext context)
 {
     foreach (var segment in Segments.OfType<FileSegmentBuilder>().Reverse())
         segment.Build(context);
 }
示例#22
0
 public override void Build(BuildingContext context)
 {
     AppendResourceDirectory();
     AppendRelocationDirectory();
     base.Build(context);
 }
示例#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);
 }
示例#26
0
 public override void UpdateOffsets(BuildingContext context)
 {
     if (NetResourceDirectoryBuilder.Segments.Count == 0)
         Segments.Remove(NetResourceDirectoryBuilder);
     base.UpdateOffsets(context);
 }
示例#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);
 }
示例#29
0
 public virtual void Build(BuildingContext context)
 {
     foreach (var builder in Segments.OfType<FileSegmentBuilder>())
         builder.Build(context);
 }
示例#30
0
 public override void UpdateReferences(BuildingContext context)
 {
     UpdateDebugDirectory();
     UpdateMetaDataDirectories();
     base.UpdateReferences(context);
 }
示例#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);
                }
            }
        }
示例#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();

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