#!/usr/bin/python import sys,os if len(sys.argv) <> 2: print "Usage: %s symbol_log\n" % (sys.argv[0]) binary_cache = {} def get_symbols(binary): global binary_cache try: return binary_cache[binary] except: print("%s not in cache" % binary) ls = os.popen("nm --numeric-sort '%s'" % binary).read().split("\n") table = {} table["log"] = [] binary_cache[binary] = table for line in ls: cols = line.split(" ") if len(cols) <> 3 or cols[1].lower() != "t" : continue table[int(cols[0],16)] = cols[2] return table def parse_log(log): log = open(log).read().rstrip().split("\n"); for line in log: col = line.split(" ") if len(col) <> 3 or col[0] <> "func_enter": continue binary_path = col[1] addy = int(col[2],16) get_symbols(binary_path)["log"].append(addy) parse_log(sys.argv[1]) for binary, info in binary_cache.iteritems(): if len(info.keys()) == 1: print "Got nothing for %s" % binary continue f = open(binary + ".script", "w") f.write("SECTIONS\n{\n"); for entry in info["log"]: try: name = info[entry] s = " .text.%s : {*(.text.%s) }\n" % (name, name) f.write(s) except: print "No %x in %s" % (entry, binary) f.write("}\nINSERT AFTER .gnu.version_r\n"); f.close();