hack_malloc
hack_malloc copied to clipboard
Fun with malloc() and free(): PoC implementation, tracing, training deep neural networks
hack_malloc
Fun with malloc()
and free()
. Tested on Linux and macOS.
-
hack_malloc.c
- super inefficient but working implementation. -
override_malloc.c
- demonstration how to interceptmalloc()
andfree()
. -
trace_malloc.c
- advanced heap interceptor which writes the log to disk. -
model.py
- Keras RNN model which predictsmalloc()
andfree()
taking the log fromlibtracemalloc.so
as the input.
How to build
Linux:
make -f Makefile.linux
Mac OS X:
make -f cp Makefile.darwin
How to run
./test
python3 model.py --input log.txt.gz --epochs 1 --type GRU --validation 0.15
How to inject
Linux:
LD_PRELOAD=/path/to/liboverridemalloc.so ./program
Mac OS X:
DYLD_INSERT_LIBRARIES=/path/to/liboverridemalloc.dylib DYLD_FORCE_FLAT_NAMESPACE=1 ./program
Note for Mac OS X: due to SIP, programs at /usr/bin, e.g., ls, are not going to be affected.
License
MIT license.