示例#1
0
 public Relocation(BinaryReaderX reader)
 {
     Offset  = reader.ReadUInt16();
     Type    = (RelocationType)reader.ReadByte();
     Section = reader.ReadByte();
     Addend  = reader.ReadUInt32();
 }
示例#2
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);
        }
示例#3
0
        public RelocationTable(DAT dat, string name, RelocationType type)
        {
            EndianBinaryReader reader = dat.reader;
            int levelIndex            = 0;

            string[] levelList = DAT.levelList;
            for (int i = 0; i < levelList.Length; i++)
            {
                if (levelList[i].ToLower().Equals(name.ToLower()))
                {
                    levelIndex = i;
                    break;
                }
            }
            RelocationTableReference rtref = new RelocationTableReference((byte)levelIndex, (byte)type);
            //R3Loader.Loader.print("RtRef Pre  (" + rtref.levelId + "," + rtref.relocationType + ")");
            uint mask   = dat.GetMask(rtref);
            uint offset = dat.GetOffset(rtref);

            //R3Loader.Loader.print("RtRef Post (" + rtref.levelId + "," + rtref.relocationType + ")");

            /*dat.reader.BaseStream.Seek(offset, SeekOrigin.Begin);
             * reader.SetMask(mask);
             * byte[] dataNew = reader.ReadBytes(1000000);
             * Util.ByteArrayToFile(name + "_" + type + ".data", dataNew);*/
            dat.reader.BaseStream.Seek(offset, SeekOrigin.Begin);
            reader.SetMask(mask);
            reader.ReadUInt32();
            Read(reader);
        }
        // Use this to automatically decide whether to load it from RT* file or from DAT
        public RelocationTable(string path, DAT dat, string name, RelocationType type)
        {
            this.name = name;
            this.type = type;
            this.dat  = dat;

            /*string newPath = path;
             * switch (type) {
             * case RelocationType.RTB:
             * newPath = Path.ChangeExtension(path, "rtb"); break;
             * case RelocationType.RTP:
             * newPath = Path.ChangeExtension(path, "rtp"); break;
             * case RelocationType.RTS:
             * newPath = Path.ChangeExtension(path, "rts"); break;
             * case RelocationType.RTT:
             * newPath = Path.ChangeExtension(path, "rtt"); break;
             * case RelocationType.RTL:
             * newPath = Path.ChangeExtension(path, "rtl"); break;
             * case RelocationType.RTD:
             * newPath = Path.ChangeExtension(path, "rtd"); break;
             * case RelocationType.RTG:
             * newPath = Path.ChangeExtension(path, "rtg"); break;
             * case RelocationType.RTV:
             * newPath = Path.ChangeExtension(path, "rtv"); break;
             * }
             * this.path = newPath;*/
            this.path = path;
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Relocation"/> class.
 /// </summary>
 /// <param name="symbol">The target symbol.</param>
 /// <param name="offset">The offset relative to the start of at which the storage
 /// unit to be relocated resides.</param>
 /// <param name="addend">The constant used to compute the value of the relocatable field.</param>
 /// <param name="type">The type of relocation compution to perform.</param>
 public Relocation(Symbol symbol, long offset, long addend, RelocationType type)
 {
     TargetSymbol = symbol;
     Offset       = offset;
     Addend       = addend;
     Type         = type;
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Relocation"/> class.
 /// </summary>
 /// <param name="symbol">The target symbol.</param>
 /// <param name="offset">The offset relative to the start of at which the storage
 /// unit to be relocated resides.</param>
 /// <param name="addend">The constant used to compute the value of the relocatable field.</param>
 /// <param name="type">The type of relocation compution to perform.</param>
 public Relocation(Symbol symbol, long offset, long addend, RelocationType type)
 {
     TargetSymbol = symbol;
     Offset = offset;
     Addend = addend;
     Type = type;
 }
示例#7
0
        public Elf32Rel(Elf32_Rel *st)
        {
            Offset = st->r_offset;
            Info   = st->r_info;

            Symbol = Info >> 8;
            Type   = (RelocationType)(byte)Info;
        }
        public Relocation_Entry(ushort offset, byte type, byte section, uint addend)
        {
            Offset     = offset;
            Type_Value = type;
            Section    = section;
            Addend     = addend;

            Type = (RelocationType)type;
        }
示例#9
0
        public Relocation(EndianBinaryReader reader)
        {
            Offset = reader.ReadInt32();

            var info = reader.ReadUInt32();

            SymbolTargetIndex = info >> 8;
            Type = (RelocationType)(info & 0x000000FF);
        }
示例#10
0
        public Relocation(byte[] data, int start, SymbolTable <uint> symbols)
        {
            Offset = CONVERTER.ToUInt32(data, start);

            var info = CONVERTER.ToUInt32(data, start + 4);

            var symbolTargetIndex = info >> 8;

            Symbol = symbols.Entries.ElementAt((int)symbolTargetIndex);
            Type   = (RelocationType)(info & 0x000000FF);
        }
示例#11
0
        /// <summary>
        /// Creates a new relocation entry.
        /// </summary>
        /// <param name="type">The type of relocation to apply.</param>
        /// <param name="offset">The offset within the page to apply the relocation on.</param>
        /// <exception cref="ArgumentOutOfRangeException">Occurs when the offset does not indicate a valid offset within
        /// the page.</exception>
        public RelocationEntry(RelocationType type, int offset)
        {
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), "Offset cannot be negative.");
            }
            if (offset > 0xFFF)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), "Offset cannot be larger than 0xFFF.");
            }

            _value = (ushort)(((byte)type << 12) | (offset & 0xFFF));
        }
示例#12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Relocation"/> class.
        /// </summary>
        /// <param name="symbol">The target symbol.</param>
        /// <param name="section">The section in which the storage unit to be relocated resides.</param>
        /// <param name="offset">The offset relative to the start of <paramref name="section"/> at which the storage
        /// unit to be relocated resides.</param>
        /// <param name="addend">The constant used to compute the value of the relocatable field.</param>
        /// <param name="type">The type of relocation compution to perform.</param>
        public Relocation(Symbol symbol, Section section, Int128 offset, Int128 addend, RelocationType type)
        {
            #region Contract
            Contract.Requires<ArgumentNullException>(symbol != null);
            Contract.Requires<ArgumentNullException>(section != null);
            #endregion

            this.targetSymbol = symbol;
            this.section = section;
            this.offset = offset;
            this.addend = addend;
            this.type = type;
        }
示例#13
0
            private void ApplyRelocationBlock(Image image, long delta, IMAGE_BASE_RELOCATION *relocation)
            {
                byte *  dest           = image.BasePtr + relocation->VirtualAddress;
                ushort *relocationInfo = (ushort *)((byte *)relocation + sizeof(IMAGE_BASE_RELOCATION));

                for (int i = 0; i < (relocation->BlockSizeInclusive - sizeof(IMAGE_BASE_RELOCATION)) / 2; i++, relocationInfo++)
                {
                    RelocationType type   = (RelocationType)(*relocationInfo >> 12);
                    int            offset = *relocationInfo & 0xFFF;

                    switch (type)
                    {
                    case RelocationType.Absolute:
                        // Skip relocation;
                        break;

                    case RelocationType.HighLow:
                        // Change complete 32-bit address.
                        int *patchAddressHighLow = (int *)(dest + offset);
                        if ((byte *)patchAddressHighLow < image.BasePtr || (byte *)patchAddressHighLow > image.BasePtr + image.Size)
                        {
                            throw new LoadFailedException("This DLL is damaged; relocation table references an illegal 32-bit offset.");
                        }
                        *patchAddressHighLow += (int)delta;
                        break;

                    case RelocationType.Dir64:
                        // Change complete 64-bit address.
                        long *patchAddress64 = (long *)(dest + offset);
                        if ((byte *)patchAddress64 < image.BasePtr || (byte *)patchAddress64 > image.BasePtr + image.Size)
                        {
                            throw new LoadFailedException("This DLL is damaged; relocation table references an illegal 64-bit offset.");
                        }
                        *patchAddress64 += delta;
                        break;

                    default:
                        throw new LoadFailedException(string.Format("This DLL requires unsupported address-relocation type {0} ({1})", type, (int)type));
                    }
                }
            }
示例#14
0
        internal Relocation(int offset, RelocationType type)
        {
            Offset = offset;

            Type = type;
        }
示例#15
0
 /// <summary>
 /// Creates a new base relocation.
 /// </summary>
 /// <param name="type">The type of base relocation to apply.</param>
 /// <param name="location">The location within the executable to apply the base relocation.</param>
 public BaseRelocation(RelocationType type, ISegmentReference location)
 {
     Type     = type;
     Location = location ?? throw new ArgumentNullException(nameof(location));
 }
示例#16
0
 private static string PadRelocName(RelocationType type) =>
 type.ToString().PadRight(nameof(RelocationType.R_MIPS_HI16).Length);
示例#17
0
 /// <summary>
 /// Init constructor of RelocationItem.
 /// </summary>
 public RelocationItem(RelocationType type, uint offset)
 {
     Type   = type;
     Offset = offset;
 }
示例#18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Relocation"/> class.
        /// </summary>
        /// <param name="symbol">The target symbol.</param>
        /// <param name="section">The section in which the storage unit to be relocated resides.</param>
        /// <param name="offset">The offset relative to the start of <paramref name="section"/> at which the storage
        /// unit to be relocated resides.</param>
        /// <param name="addend">The constant used to compute the value of the relocatable field.</param>
        /// <param name="type">The type of relocation compution to perform.</param>
        public Relocation(Symbol symbol, Section section, Int128 offset, Int128 addend, RelocationType type)
        {
            #region Contract
            Contract.Requires <ArgumentNullException>(symbol != null);
            Contract.Requires <ArgumentNullException>(section != null);
            #endregion

            this.targetSymbol = symbol;
            this.section      = section;
            this.offset       = offset;
            this.addend       = addend;
            this.type         = type;
        }