Esempio n. 1
0
        public Elf(Stream input)
        {
            var reader = new BinaryReader(input);

            _header = ElfHeader.Read(reader);

            if (_header.e_type != 1)
            {
                throw new InvalidDataException("Only relocatable objects are supported");
            }
            if (_header.e_machine != 0x14)
            {
                throw new InvalidDataException("Only PowerPC is supported");
            }


            input.Seek(_header.e_shoff, SeekOrigin.Begin);
            for (int i = 0; i < _header.e_shnum; i++)
            {
                _sections.Add(ElfSection.Read(reader));
            }

            if (_header.e_shstrndx > 0 && _header.e_shstrndx < _sections.Count)
            {
                var table = _sections[_header.e_shstrndx].data;

                for (int i = 0; i < _sections.Count; i++)
                {
                    _sections[i].name = Util.ExtractNullTerminatedString(table, (int)_sections[i].sh_name);
                }
            }
        }