示例#1
0
        internal Relocation(RelocationBlock relocBlock, long relocOffset, ushort relocValue)
        {
            block = relocBlock;

            int reloc_type = relocValue >> 12;
            int reloc_offset = relocValue & 0xFFF;

            type = (RelocationType)reloc_type;
            offset = Convert.ToUInt16(reloc_offset);
            value = relocValue;
            computed_rva = block.PageRVA;

            switch (type)
            {
                case RelocationType.Absolute:
                    break;
                case RelocationType.HighLow:
                    computed_rva += offset;
                    break;
                case RelocationType.Dir64:
                    computed_rva += offset;
                    break;      
                case RelocationType.High:
                case RelocationType.Low:
                default:
                    computed_rva = 0;
                    break;
            }

            location = new StreamLocation(relocOffset,size);
        }
 protected override void LoadInternal(VirtualReader rdr)
 {
     for (; rdr.BaseStream.Position < Location.Size + Location.Address;)
     {
         RelocationBlock b = new RelocationBlock();
         b.Load(rdr);
         bs.Add(b);
     }
 }
示例#3
0
        public IReadable Read()
        {
            var peHeaderReader = (PeHeaderReader) new PeHeaderReader(_filePath).Read();

            BaseRelocationTable = peHeaderReader.Is32BitPeHeader
                ? peHeaderReader.PeHeader32.OptionalHeader.BaseRelocationTable
                : peHeaderReader.PeHeader64.OptionalHeader.BaseRelocationTable;

            var address = RvaToRawFormatConverter.RvaToOffset32(BaseRelocationTable.VirtualAddress,
                                                                peHeaderReader.SectionHeaders,
                                                                peHeaderReader.Is32BitPeHeader
                    ? peHeaderReader.PeHeader32.OptionalHeader.SectionAlignment
                    : peHeaderReader.PeHeader64.OptionalHeader.SectionAlignment);

            using var fs = new FileStream(_filePath, FileMode.Open, FileAccess.Read);
            var br = new BinaryReader(fs);

            fs.Seek(address, SeekOrigin.Begin);

            Int32 currentSize;

            for (var i = 0; i < BaseRelocationTable.Size; i += currentSize)
            {
                currentSize = 0;
                var relocationBlock = new RelocationBlock
                {
                    PageRva   = br.ReadUInt32(),
                    BlockSize = br.ReadUInt32()
                };

                currentSize += Marshal.SizeOf(relocationBlock.PageRva);
                currentSize += Marshal.SizeOf(relocationBlock.BlockSize);

                for (var j = 0; j < (relocationBlock.BlockSize - 8) / 2; j++)
                {
                    var relocationSectionInfo = br.ReadUInt16();
                    var relocationSection     = new RelocationSection
                    {
                        Type   = (RelocationType)((relocationSectionInfo & 0xf000) >> 12),
                        Offset = (UInt16)(relocationSectionInfo & 0x0fff)
                    };
                    relocationBlock.RelocationSections.Add(relocationSection);
                    currentSize += Marshal.SizeOf(relocationSection.Offset);
                }

                RelocationBlocks.Add(relocationBlock);
            }

            br.Dispose();
            br.Close();

            return(this);
        }
 public bool Remove(RelocationBlock item)
 {
     return(bs.Remove(item));
 }
 public bool Contains(RelocationBlock item)
 {
     return(bs.Contains(item));
 }
 public void Add(RelocationBlock item)
 {
     bs.Add(item);
 }
 public void Insert(int index, RelocationBlock item)
 {
     bs.Insert(index, item);
 }
 public int IndexOf(RelocationBlock item)
 {
     return(bs.IndexOf(item));
 }