private void _disassemble()
        {
            Records = new List <InstructionRecord>();
            var sectionsToLoad = _elf.GetSections <ProgBitsSection <uint> >()
                                 .Where(x => x.Type == SectionType.ProgBits && x.Flags.HasFlag(SectionFlags.Executable));

            foreach (var s in sectionsToLoad)
            {
                var  stream   = new MemoryStream(s.GetContents());
                var  reader   = new SimpleEndianessAwareReader(stream, _elf.Endianess);
                uint position = 0;

                while (position < s.Size)
                {
                    var address = s.LoadAddress + position;
                    var chunk   = BitArrayFactory.FromUnsignedInt(
                        reader.ReadUInt32(), InstructionSize * 8
                        );
                    var instruction = _instructionSet.Resolve(chunk) ?? new Instruction("UNKNOWN");
                    instruction.Position = address;
                    instruction.Data     = chunk;

                    Records.Add(
                        new InstructionRecord(s.Name, address, instruction)
                        );
                    position += InstructionSize;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Gets all of the symbol entries from an ELF binary and returns it
        /// as an IEnumerable.
        /// </summary>
        /// <param name="elf">ELF to get the symbols from</param>
        /// <returns>List of all entries in every symbol table in the ELF binary</returns>
        public static IEnumerable <ISymbolEntry> GetAllSymbols(IELF elf)
        {
            IEnumerable <ISymbolTable> symbolTables = elf.GetSections <ISymbolTable>();

            return(symbolTables.Aggregate(
                       new List <ISymbolEntry>(),
                       (agg, next) => {
                agg.AddRange(next.Entries);
                return agg;
            }
                       ));
        }
Пример #3
0
        public override void InitFromElf(IELF elf)
        {
            base.InitFromElf(elf);

            var bamSection = elf.GetSections <Section <uint> >().FirstOrDefault(x => x.Name == ".__bam_bootarea");

            if (bamSection != null)
            {
                var bamSectionContents         = bamSection.GetContents();
                var isValidResetConfigHalfWord = bamSectionContents[1] == 0x5a;
                if (!isValidResetConfigHalfWord)
                {
                    this.Log(LogLevel.Warning, "Invalid BAM section, ignoring.");
                }
                else
                {
                    StartInVle = (bamSectionContents[0] & 0x1) == 1;
                    this.Log(LogLevel.Info, "Will {0}start in VLE mode.", StartInVle ? "" : "not ");
                }
            }
        }
Пример #4
0
 public IEnumerable <T> GetSections <T>() where T : ISection
 {
     return(_inner.GetSections <T>());
 }