예제 #1
0
        public void Read(ParsedDocument doc, ElfSectionHeader section, byte[] data)
        {
            var header = doc.document.header;

            symbols.Clear();
            using (var ms = new System.IO.MemoryStream(data))
            {
                int sylsize = header.Head_Is64Bit ? 24 : 16;
                for (var i = 0; i < data.Length; i += sylsize)
                {
                    Symbol symbol = new Symbol();
                    if (header.Head_Is64Bit)//64位和32位格式,顺序不太一样
                    {
                        symbol.st_name  = ms.ReadUInt32(header);
                        symbol.st_info  = ms.ReadByte1();
                        symbol.st_other = ms.ReadByte1();
                        symbol.st_shndx = ms.ReadUInt16(header);
                        symbol.st_value = ms.ReadUIntPtr(header);
                        symbol.st_size  = ms.ReadUIntPtr(header);
                    }
                    else
                    {
                        symbol.st_name  = ms.ReadUInt32(header);
                        symbol.st_value = ms.ReadUIntPtr(header);
                        symbol.st_size  = ms.ReadUIntPtr(header);
                        symbol.st_info  = ms.ReadByte1();
                        symbol.st_other = ms.ReadByte1();
                        symbol.st_shndx = ms.ReadUInt16(header);
                    }
                    if (doc.Parsed_StringTables.ContainsKey((int)section.Link))
                    {
                        var stable = doc.Parsed_StringTables[(int)section.Link];
                        stable.TryGetValue((int)symbol.st_name, out symbol.Name);
                    }
                    symbol.SymbolBinding = (SymbolBinding)(symbol.st_info >> 4);
                    symbol.SymbolType    = (SymbolType)(symbol.st_info & 0x0F);
                    if (Enum.IsDefined(typeof(SpecialSectionIndex), symbol.st_shndx))
                    {
                        symbol.SpecialSectionIndex = (SpecialSectionIndex)symbol.st_shndx;
                    }
                    else
                    {
                        symbol.SpecialSectionIndex = null;
                    }


                    symbols.Add(symbol);
                }
            }
        }