brintos

brintos / llvm-project-archived public Read only

0
0
Text · 864 B · 69da526 Raw
37 lines · python
1#!/usr/bin/env python2 3import argparse4import re5import sys6 7 8def main():9    argp = argparse.ArgumentParser()10    argp.add_argument("infile", type=argparse.FileType("rb"), help="Input vmcore file")11    argp.add_argument(12        "outfile", type=argparse.FileType("wb"), help="Output vmcore file"13    )14    args = argp.parse_args()15 16    inf = args.infile17    outf = args.outfile18    line_re = re.compile(r"^% RD: (\d+) (\d+)")19 20    # copy the first chunk that usually includes ELF headers21    # (not output by patched libfbsdvmcore since libelf reads this)22    outf.write(inf.read(1024))23 24    for l in sys.stdin:25        m = line_re.match(l)26        if m is None:27            continue28        offset, size = [int(x) for x in m.groups()]29 30        inf.seek(offset)31        outf.seek(offset)32        outf.write(inf.read(size))33 34 35if __name__ == "__main__":36    main()37