From 2bcaf5188ad9d3414cb4a8304f24ef4b2695bb88 Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Thu, 4 Dec 2014 07:54:54 -0800 Subject: [PATCH] grouping the hunk blocks with their relocation information --- hunktools/hunk.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/hunktools/hunk.py b/hunktools/hunk.py index 1aff4f8..51dd374 100755 --- a/hunktools/hunk.py +++ b/hunktools/hunk.py @@ -144,31 +144,51 @@ def parse_hunkfile(hunkfile): print("hunk sizes: ", hunk_sizes) elif id == HUNK_BLOCK_UNIT: strlen = read_int32(infile) * 4 - print("# name: %d" % strlen) + #print("# name: %d" % strlen) unit_name = str(infile.read(strlen)) print("UNIT '%s'" % unit_name) + print("---------------------------------------------") else: is_loadfile = False raise Exception('Unsupported header type') blocks = read_blocks(infile, is_loadfile) - print("%d blocks read: " % len(blocks)) + #print("%d blocks read: " % len(blocks)) + + # group the blocks into relocation groups + groups = [] + for block in blocks: + if block[0] in {'NAME', 'UNIT'}: + continue + elif block[0] in {'BSS', 'CODE', 'DATA'}: + current_group = [] + + if block[0] == 'END': + groups.append(current_group) + current_group = [] + else: + current_group.append(block) + + for i, group in enumerate(groups): + names = ','.join([block[0] for block in group]) + print("Group %d -> %s" % (i, names)) + + """ for i, block in enumerate(blocks): if block[0] == 'NAME': - print("Block %d: '%s' -> '%s'" % (i, block[0], block[1])) + print("%d: '%s' -> '%s'" % (i, block[0], block[1])) elif block[0] == 'BSS': - print("Block %d: '%s' -> %d" % (i, block[0], block[1])) + print("%d: '%s' -> %d" % (i, block[0], block[1])) elif block[0] == 'CODE': print("%d: '%s', size = %d" % (i, block[0], len(block[1]))) - print("----------------------------\n") - code = block[1] - disassemble(code) - - print("\n---------------------------\n") + #print("----------------------------\n") + #code = block[1] + #disassemble(code) + #print("\n---------------------------\n") elif block[0] == 'RELOC32': print("%d: '%s': %s" % (i, block[0], block[1])) else: - print("Block %d: '%s'" % (i, block[0])) + print("%d: '%s'" % (i, block[0]))""" if __name__ == '__main__':