35 lines
951 B
Python
Executable File
35 lines
951 B
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import argparse
|
|
import threading
|
|
import subprocess
|
|
|
|
import intercept
|
|
import intercept.standard
|
|
|
|
|
|
def socket_thread(socket: str) -> None:
|
|
intercept.intercept(socket, intercept.standard.MemoryAllocationTester)
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser()
|
|
args, extra = parser.parse_known_args()
|
|
socket_name = f'/tmp/intercept.memory.{os.getpid()}.sock'
|
|
t1 = threading.Thread(target=socket_thread, args=(socket_name,))
|
|
t1.daemon = True
|
|
t1.start()
|
|
subprocess.run(extra, env={
|
|
'LD_PRELOAD': os.getcwd() + '/../../intercept/intercept.so',
|
|
'INTERCEPT': 'unix:' + socket_name,
|
|
'INTERCEPT_VERBOSE': '1',
|
|
'INTERCEPT_FUNCTIONS': ','.join(['malloc', 'calloc', 'realloc', 'reallocarray', 'free', 'getaddrinfo', 'freeaddrinfo']),
|
|
'INTERCEPT_LIBRARIES': '*,-/lib*,-/usr/lib*',
|
|
})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|