コード例 #1
0
ファイル: Program.cs プロジェクト: BGCX261/zoompe-git
        private static BaseRelocationBlock[] GetBaseRelocationsFor(string file, PEFile pe)
        {
            var stream = new MemoryStream(File.ReadAllBytes(file));
            var reader = new BinaryStreamReader(stream, new byte[1024]);

            pe.ReadFrom(reader);

            var baseRelocationDirectory = pe.OptionalHeader.DataDirectories[(int)DataDirectoryKind.BaseRelocation];

            var rvaStream = new RvaStream(
                stream,
                pe.SectionHeaders.Select(
                    s => new RvaStream.Range
            {
                PhysicalAddress = s.PointerToRawData,
                Size            = s.VirtualSize,
                VirtualAddress  = s.VirtualAddress
            })
                .ToArray());

            rvaStream.Position = baseRelocationDirectory.VirtualAddress;

            var sectionReader = new BinaryStreamReader(rvaStream, new byte[32]);

            var result = BaseRelocationBlock.ReadBlocks(sectionReader, baseRelocationDirectory.Size);

            return(result);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: BGCX261/zoompe-git
 private static void PrintBaseRelocations(BaseRelocationBlock[] relocBlocks)
 {
     foreach (var b in relocBlocks)
     {
         Console.WriteLine(b.PageRVA.ToString("X")+"h ("+b.Size+")");
         foreach (var e in b.Entries)
         {
             Console.WriteLine("    " + e.Offset.ToString("X").PadLeft(4, '0') + "h " + e.Type);
         }
     }
 }
コード例 #3
0
 private void AppendRelocationDirectory()
 {
     if (Assembly.RelocationDirectory != null)
     {
         Assembly.RelocationDirectory.Blocks.Clear();
         var block = new BaseRelocationBlock(0);
         block.Entries.Add(new BaseRelocationEntry(BaseRelocationType.HighLow, 0));
         block.Entries.Add(new BaseRelocationEntry(BaseRelocationType.Absolute, 0));
         Assembly.RelocationDirectory.Blocks.Add(block);
         _relocSectionBuilder.Segments.Add(Assembly.RelocationDirectory);
     }
 }
コード例 #4
0
 private void AppendRelocationDirectory()
 {
     if (Assembly.RelocationDirectory != null)
     {
         Assembly.RelocationDirectory.Blocks.Clear();
         var block = new BaseRelocationBlock(0);
         block.Entries.Add(new BaseRelocationEntry(BaseRelocationType.HighLow, 0));
         block.Entries.Add(new BaseRelocationEntry(BaseRelocationType.Absolute, 0));
         Assembly.RelocationDirectory.Blocks.Add(block);
         _relocSectionBuilder.Segments.Add(Assembly.RelocationDirectory);
     }
 }
コード例 #5
0
        private void CreateRelocationSection()
        {
            Assembly.RelocationDirectory.Blocks.Clear();
            var block = new BaseRelocationBlock(0);

            block.Entries.Add(new BaseRelocationEntry(BaseRelocationType.HighLow, 0));
            block.Entries.Add(new BaseRelocationEntry(BaseRelocationType.Absolute, 0));
            Assembly.RelocationDirectory.Blocks.Add(block);

            _relocSectionHeader = new ImageSectionHeader
            {
                Name       = ".reloc",
                Attributes = ImageSectionAttributes.MemoryRead |
                             ImageSectionAttributes.ContentInitializedData,
                Section = { Segments = { Assembly.RelocationDirectory } }
            };
        }