diff options
author | Frank Busse <bb0xfb@gmail.com> | 2019-02-15 21:38:40 +0000 |
---|---|---|
committer | MartinNowack <martin.nowack@gmail.com> | 2019-03-05 12:47:00 +0000 |
commit | d5de3df2c7e481426c39220072b42dfd307a3526 (patch) | |
tree | 3131581dd85b6d82b930b4f7dcc5b32a169179f6 /tools | |
parent | 77600162b089374eb99179dbb9638ce4b1b45c70 (diff) | |
download | klee-d5de3df2c7e481426c39220072b42dfd307a3526.tar.gz |
ktest-tool: add --extract option
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/ktest-tool/ktest-tool | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/ktest-tool/ktest-tool b/tools/ktest-tool/ktest-tool index 371a2dd6..8356d36b 100755 --- a/tools/ktest-tool/ktest-tool +++ b/tools/ktest-tool/ktest-tool @@ -114,6 +114,17 @@ class KTest: return sio.getvalue() + def extract(self, object_names, trim_zeros): + for name, data in self.objects: + if name not in object_names: + continue + + f = open(self.path + '.' + name, 'wb') + blob = data.rstrip(b'\x00') if trim_zeros else data + f.write(blob) + f.close() + + def main(): epilog = """ @@ -155,13 +166,17 @@ def main(): ap = ArgumentParser(prog='ktest-tool', formatter_class=RawDescriptionHelpFormatter, epilog=dedent(epilog)) ap.add_argument('--trim-zeros', help='trim trailing zeros', action='store_true') + ap.add_argument('--extract', help='write binary value of object into file', metavar='name', nargs=1, action='append') ap.add_argument('files', help='a .ktest file', metavar='file', nargs='+') args = ap.parse_args() for file in args.files: ktest = KTest.fromfile(file) - fmt = '{:trimzeros}' if args.trim_zeros else '{}' - print(fmt.format(ktest), end='') + if args.extract: + ktest.extract({x for xs in args.extract for x in xs}, args.trim_zeros) + else: + fmt = '{:trimzeros}' if args.trim_zeros else '{}' + print(fmt.format(ktest), end='') if __name__ == '__main__': |