proj: Add intercept command
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
bin/
|
||||
*.so
|
||||
*.o
|
||||
*.log
|
||||
|
||||
34
proj/intercept/intercept
Executable file
34
proj/intercept/intercept
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-f', '--functions')
|
||||
mode = parser.add_mutually_exclusive_group()
|
||||
mode.add_argument('-l', '--log')
|
||||
mode.add_argument('-i', '--intercept')
|
||||
args, extra = parser.parse_known_args()
|
||||
if len(extra) > 0 and extra[0] == '--':
|
||||
extra.pop(0)
|
||||
|
||||
if args.intercept:
|
||||
intercept = args.intercept
|
||||
elif args.log:
|
||||
intercept = 'file:' + args.log
|
||||
else:
|
||||
intercept = 'stderr'
|
||||
subprocess.run(extra, stdin=sys.stdin, env={
|
||||
'LD_PRELOAD': os.getcwd() + '/intercept.so',
|
||||
'INTERCEPT': intercept,
|
||||
'INTERCEPT_FUNCTIONS': args.functions or '*',
|
||||
})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user