Created
May 21, 2014 12:18
-
-
Save math314/7eb60fbafb240696c2f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #coding=utf-8 | |
| import sys,os | |
| import re | |
| from collections import namedtuple | |
| Code = namedtuple('Code',['address','binary','opecode','operand']) | |
| def load_assembler(file_name): | |
| part = re.compile(r"\s(?P<address>\w+):\s+(?P<binary>(\w\w\s)+)\s+((?P<opecode>\w+)(\s+(?P<operand>.*))?)?$") | |
| data = [i.strip('\n') for i in open(file_name)] | |
| ret = [] | |
| i = 0 | |
| text_section = False | |
| while i < len(data): | |
| line = data[i] | |
| if line == "Disassembly of section .text:": | |
| print line | |
| text_section = True | |
| i += 3 | |
| continue | |
| if text_section: | |
| if line == "": | |
| break | |
| m = part.match(line) | |
| code = Code._make([m.group(field) for field in Code._fields]) | |
| if code.opecode is None: | |
| ret[-1].binary += code.binary | |
| else: | |
| ret.append(code) | |
| i += 1 | |
| for i in ret: | |
| print i | |
| def main(): | |
| load_assembler(sys.argv[1]) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment