[Okteta] [PATCH] Support for pointers in data structures viewer

Alessandro Di Federico ale at clearmind.me
Sat Aug 11 12:20:13 UTC 2012


Hi, I've just discovered Okteta and I liked it very much, in particular
for its data structures viewer, however I thought it could be better, so
I decided to implement a feature I find very useful: pointers. My effort
is currently focused on being able to completely parse a whole ELF file
in a single tree. For instance the Elf32_Ehdr struct (`man elf` to see
its documentation) contains a sh_off field which is a "pointer" to an
offset in the file, where an array (with length e_shnum) of Elf32_Shdr
structs begins.

Attached you can see an example OSD for ELF with the pointer element and
a screenshot of the result.

So here's a resume of what I've done:
      * Implemented the PointerDataInformation class, which allows to
        define a pointer to an offset in the file. The contents of the
        pointed that is parsed after the parsing of the whole structure
        is finished, so I can use as array size (for instance) a field
        which comes after the pointer field itself.
      * Added the totallength attribute to the array element, which
        allows to set a maximum size in bytes for the array instead that
        in number of elements. This is useful when there's a list of
        string and you know their size altogether but not the individual
        sizes.
      * Slightly changed the way findChildForDynamicArrayLength works,
        now it starts from the element which should be added and goes up
        to the parents searching in all its elements, except the element
        we came from.

I also had to remove some QSharedPointer (otherwise okteta crashed
badly) and I left some TODOs for that because I'm not sure that simply
remove them is a solution.

In future I'd like to add also these features:
      * Pointers to other parts of the tree (for instance
        Elf32_Sym.st_name is the index of a string in the symbol table)
      * Union selector, which means an expression to choose the correct
        field of the union to use/display/highlight
      * Virtual memory, which means to associate a virtual memory
        address to a certain offset in the file, this way we could parse
        pointers on core dumps (or memory dumps in general) too

It's still a draft but I hope you like the patch. I'd like to hear your
opinion on all the points I've mentioned, and I'm available to modify
the patch to follow your suggestions.

Attached you find the screenshot, an example OSD for ELF using pointers,
a very simple ELF to test and the patch itself.

Bye,
Ale
-------------- next part --------------
A non-text attachment was scrubbed...
Name: elf-tree-example.png
Type: image/png
Size: 131688 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-utils-devel/attachments/20120811/8b601cd0/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pointer1.patch
Type: text/x-patch
Size: 45043 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-utils-devel/attachments/20120811/8b601cd0/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: elf.h.osd
Type: application/x-vnd.kde.okteta.structure
Size: 12550 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-utils-devel/attachments/20120811/8b601cd0/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minimal.gz
Type: application/x-gzip
Size: 299 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-utils-devel/attachments/20120811/8b601cd0/attachment-0001.gz>


More information about the Kde-utils-devel mailing list