コード例 #1
0
ファイル: Linker.cs プロジェクト: Treeki/Kamek
        private bool KamekUseReloc(Elf.Reloc type, Word source, Word dest)
        {
            if (source < _kamekStart || source >= _kamekEnd)
            {
                return(false);
            }
            if (type != Elf.Reloc.R_PPC_ADDR32)
            {
                throw new InvalidOperationException("Unsupported relocation type in the Kamek hook data section");
            }

            _kamekRelocations[source] = dest;
            return(true);
        }
コード例 #2
0
ファイル: Linker.cs プロジェクト: Treeki/Kamek
        private void ProcessRelaSection(Elf elf, Elf.ElfSection relocs, Elf.ElfSection section, Elf.ElfSection symtab)
        {
            if (relocs.sh_entsize != 12)
            {
                throw new InvalidDataException("Invalid relocs format (sh_entsize != 12)");
            }
            if (symtab.sh_type != Elf.ElfSection.Type.SHT_SYMTAB)
            {
                throw new InvalidDataException("Symbol table does not have type SHT_SYMTAB");
            }

            var reader = new BinaryReader(new MemoryStream(relocs.data));
            int count  = relocs.data.Length / 12;

            for (int i = 0; i < count; i++)
            {
                uint r_offset = reader.ReadBigUInt32();
                uint r_info   = reader.ReadBigUInt32();
                int  r_addend = reader.ReadBigInt32();

                Elf.Reloc reloc    = (Elf.Reloc)(r_info & 0xFF);
                int       symIndex = (int)(r_info >> 8);

                if (symIndex == 0)
                {
                    throw new InvalidDataException("linking to undefined symbol");
                }
                if (!_sectionBases.ContainsKey(section))
                {
                    continue; // we don't care about this
                }
                string symName = _symbolTableContents[symtab][symIndex];
                //Console.WriteLine("{0,-30} {1}", symName, reloc);

                Word source = _sectionBases[section] + r_offset;
                Word dest   = ResolveSymbol(elf, symName).address + r_addend;

                //Console.WriteLine("Linking from {0} to {1}", source, dest);

                if (!KamekUseReloc(reloc, source, dest))
                {
                    _fixups.Add(new Fixup {
                        type = reloc, source = source, dest = dest
                    });
                }
            }
        }
コード例 #3
0
 public RelocCommand(Word source, Word target, Elf.Reloc reloc)
     : base((Ids)reloc, source)
 {
     Target = target;
 }