diff --git a/linker_interceptor.py b/linker_interceptor.py new file mode 100755 index 0000000000..e49902cf07 --- /dev/null +++ b/linker_interceptor.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import subprocess, json, sys, os + +FILTER = ['-shared'] + +CXX = os.getenv('__LIBAFL_QEMU_BUILD_CXX') or 'c++' +OUT = os.getenv('__LIBAFL_QEMU_BUILD_OUT') or 'linkinfo.json' + +args = sys.argv[1:] + +out_args = [] +shareds = [] +prev_o = False +for i in range(len(args)): + if prev_o: + prev_o = False + continue + elif args[i] in FILTER: + continue + elif args[i].endswith('.so') and not args[i].startswith('-'): + shareds.append(args[i]) + continue + elif args[i] == '-o': + prev_o = True + continue + elif args[i].startswith('-L') or args[i].startswith('-l'): + shareds.append(args[i]) + out_args.append(args[i]) + +with open(OUT, 'w') as f: + json.dump({'cmd': out_args, 'so': shareds}, f, indent=2) + +subprocess.run([CXX] + args)