Search code examples
pythonparsingobjdump

parsing objdump output


I was wondering if someone here had written/uses a script which parses the output of objdump and extracts opcodes from it? I have a very very trivial implementation but I'm looking for something better.

The problem I am facing with this script is simply that it does simple string parsing; this is more of a utility script, and thats why I haven't written tests for these. I was wondering if the same could be done by writing a custom made parser or a simple yet efficient regular expression.

This query is for the purpose of learning, so that I can approach such a problem in a (hopefully)better manner next time.

I don't mind the specifics of the implementation(shell,ruby,python,perl; anything would do). The code does not even matter that much, really, I'd like a few hints on how you would do it.


Solution

  • I'm sorry if this isn't what you wanted, but your paste is no longer available.

    Here is a quick tip. Different parts of the output are separated by tabs.

    '  402000:\t14 43                \tadc    $0x43,%al\n'
    

    This should get you started:

    >>> r
    '  402000:\t14 43                \tadc    $0x43,%al\n'
    >>> r = r.strip()
    >>> r
    '402000:\t14 43                \tadc    $0x43,%al'
    >>> r = r.split('\t')
    >>> r
    ['402000:', '14 43                ', 'adc    $0x43,%al']
    >>> r[1] = r[1].strip()
    >>> r
    ['402000:', '14 43', 'adc    $0x43,%al']