# Replaces one function's block in all.c with a separately decompiled one. Usage: splice.py all.c new.c import sys src, new = sys.argv[1:3] s, n = open(src).read(), open(new).read() if 'failed:' in n: sys.exit('still failed: ' + n[:200]) i = s.index(n.split('\n')[0].rsplit(' ', 1)[0] + ' ') # "//@@ " j = s.find('\n//@@ ', i + 5) + 1 or len(s) open(src, 'w').write(s[:i] + n.rstrip('\n') + '\n\n' + s[j:])