Example #1
0
        public List <ParsedELFSymbol> LoadAllSymbols()
        {
            List <ParsedELFSymbol> symbols = new List <ParsedELFSymbol>();

            byte[] symbolTable = LoadSection(FindSectionByName(".symtab"));
            byte[] stringTable = LoadSection(FindSectionByName(".strtab"));

            if (symbolTable == null || stringTable == null)
            {
                return(symbols);
            }

            bool isARM = ELFHeader.e_machine == 40;

            int structSize  = Marshal.SizeOf(typeof(elf32_sym));
            int symbolCount = symbolTable.Length / structSize;

            for (int i = 0; i < symbolCount; i++)
            {
                elf32_sym rawSym = (elf32_sym)ConvertByteArrayToStruct(symbolTable, typeof(elf32_sym), i * structSize);
                if (rawSym.st_value == 0)
                {
                    continue;
                }

                string symbolName = null;
                if (rawSym.st_name != 0 && rawSym.st_name < stringTable.Length)
                {
                    int eidx = 0;
                    for (eidx = (int)rawSym.st_name; eidx < stringTable.Length; eidx++)
                    {
                        if (stringTable[eidx] == 0)
                        {
                            break;
                        }
                    }

                    symbolName = Encoding.ASCII.GetString(stringTable, (int)rawSym.st_name, eidx - (int)rawSym.st_name);
                }

                if (string.IsNullOrEmpty(symbolName) || symbolName[0] == '$')
                {
                    continue;
                }

                if (isARM)
                {
                    rawSym.st_value &= ~1U; //On ARM the LSB of the address is used to denote arm/thumb mode
                }
                symbols.Add(new ParsedELFSymbol {
                    Address = rawSym.st_value, Name = symbolName, Size = rawSym.st_size
                });
            }

            return(symbols);
        }
Example #2
0
        public elf32_sym[] LoadSymbolTable(int offset, int symbolCount)
        {
            elf32_sym[] data    = new elf32_sym[symbolCount];
            int         symSize = Marshal.SizeOf(typeof(elf32_sym));

            for (int i = 0; i < symbolCount; i++)
            {
                data[i] = ReadStruct <elf32_sym>(offset + i * symSize);
            }
            return(data);
        }