1
0

proj: Add intercept command

This commit is contained in:
2025-04-17 13:47:13 +02:00
parent 74c5fa7c2c
commit bf2165fe76
2 changed files with 35 additions and 0 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
bin/ bin/
*.so *.so
*.o *.o
*.log

34
proj/intercept/intercept Executable file
View 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()