开发者

parsing objdump output

开发者 https://www.devze.com 2023-02-01 06:18 出处:网络
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 fo开发者_C百科r so

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 fo开发者_C百科r 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.


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']


The BEST solution would be to build objdump from source and make a python or other language swig wrapper that gets the output directly. You CAN do it with string parsing, but that's often buggy(read as implemented poorly). It is definitely possible to do the string parsing properly...I have a utility that relies on this.

0

精彩评论

暂无评论...
验证码 换一张
取 消