riboseinc / retrace

retrace is a versatile security vulnerability / bug discovery tool through monitoring and modifying the behavior of compiled binaries on Linux, OpenBSD/FreeBSD/NetBSD (shared object) and macOS (dynamic library).
Other
60 stars 19 forks source link

Add support for NetBSD #102

Open erikbor opened 7 years ago

pablo-mendoza commented 7 years ago

I just looked at the latest code with NetBSD and it's a royal PITA

A lot of functions are just wrappers, for example gettimeofday is just wrapper for gettimeofday50. Which gets us into a loop with our current code. Our gettimeofday implementation gets properly renamed to gettimeofday50 but our real_gettimeofday doesn't and it finds the wrapper which calls into our code which calls into the wrapper which call into our code, etc.

I fixed a few functions by making our wrapper actually implement and call real__gettimeofday50 but that quickly grew into a huge #if NetBSD__ mess everywhere.

I don't see any way to get the renaming automatically for our get_real functions however :(

erikbor commented 7 years ago

@riataman If it's too much of a hassle then let's forget NetBSD right now. I'd love to have support for it but I suppose that the user base of NetBSD is quite low anyway and getting retrace to work might take too much effort and it might get broken later leaving it in a broken state. What do you think?

drystone commented 7 years ago

@riataman would real_gettimeofday = _dl_sym(RTLD_NEXT, "__gettimeofday50") solve this? If so we could fairly easily change everything to use the equivalent of _dl_sym(RTLD_NEXT, gettimeofday_sym)

pablo-mendoza commented 7 years ago

real_gettimeofday = _dl_sym(RTLD_NEXT, "__gettimeofday50") would indeed solve it. Also need to be done for quite a bunch of others ... not all of them, and the number changes from one to another.