eliben / pyelftools

Parsing ELF and DWARF in Python
Other
2.03k stars 511 forks source link

Exception when trying to parse .oat (ARM-32) File format: #117

Open AndyXan opened 8 years ago

AndyXan commented 8 years ago

Hello, while i've been using angr which depends on cle and cle on pyelftools i stumbled upon some weird errors regarding pyelftools.

I've tried to parse a simple .oat file which basically is normal ARM-32 elffile. Readelf parses it correctly. The following stacktrace is given:

`... /home/andy/angr/angr-dev/cle/cle/backends/elf.pyc in __register_dyn(self, seg_readelf) 341 Parse the dynamic section for dynamically linked objects. 342 """ --> 343 for tag in seg_readelf.iter_tags(): 344 # Create a dictionary, self.dynamic, mapping DT* strings to their values 345 tagstr = self.arch.translate_dynamic_tag(tag.entry.d_tag)

/home/andy/.environments/angr/lib/python2.7/site-packages/elftools/elf/dynamic.py in iter_tags(self, type) 136 for tag in self._iter_tags(type=type): 137 print tag --> 138 yield DynamicTag(tag, self._get_stringtable()) 139 140 def _get_tag(self, n):

/home/andy/.environments/angr/lib/python2.7/site-packages/elftools/elf/dynamic.py in init(self, entry, stringtable) 50 if entry.d_tag in self._HANDLED_TAGS: 51 setattr(self, entry.d_tag[3:].lower(), ---> 52 stringtable.get_string(self.entry.d_val)) 53 54 def getitem(self, name):

AttributeError: 'SymbolTableSection' object has no attribute 'get_string'`

Hope you can fix this issue, Greetings

oat_test.zip

armijnhemel commented 6 years ago

I wouldn't call oat a "normal" ELF file. It is an ELF wrapper around Android bytecode :-)

Also, readelf just seems to parse it correctly, but it throws a warning:

$ readelf --dyn-syms b.oat

Symbol table '.dynsym' contains 4 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND readelf: b.oat: Warning: local symbol 0 found at index >= .dynsym's sh_info value of 0 1: 00001000 0x1f000 OBJECT GLOBAL DEFAULT 4 oatdata 2: 00020000 92884 OBJECT GLOBAL DEFAULT 5 oatexec 3: 00036ad0 4 OBJECT GLOBAL DEFAULT 5 oatlastword

I guess that is where it could have gone wrong.