ELF Parsing : Accessing a DIE Directly using pyelftools

1.6k views Asked by At

I need a method for accessing DIE's directly using their offset. So far, I have found that there is a method for the Computation Unit (CU) object in which you can access a DIE from its offset.

I.e. :

cu._get_DIE(die.attributes['DW_AT_type'].value)

However if you try to access a DIE that is outside of the current CU, you are out of bounds because that DIE isn't indexed under that CU.

The best way I can think of to accomplish this is to loop through the CU's and create a comprehensive list of DIE's using the offset as an index.

It seems like there should be a method for the DWARFInfo class that you can access any DIE as long as you have it's offset.

The reason that I need to do this is because I am looping through all of the CU's to generate a list of my globals, and I need to reference DIE's in different CU's to retrieve the type information as I go.

1

There are 1 answers

0
Wade Guthrie On

pyelftools seems to express references as value relative to the compilation unit so you'll probably need to include the CU information in your list of globals.

Check out https://github.com/eliben/pyelftools/issues/27. It indicates that the references can be relative to the compilation unit. In fact, the DWARF specification says that, too: http://dwarfstd.org/doc/dwarf-2.0.0.pdf#page=71