c - how to catch calls with LD_PRELOAD when unknown programs may be calling execve without passing environment -


i know how intercept system calls ld_preload, occur in compiled programs may not have source for. example, if want know calls int fsync(int) of unknown program foobar, compile wrapper

int fsync(int) 

for

(int (*) (int))dlsym(rtld_next,"fsync"); 

into shared library , can set environment variable ld_preload , run foobar. assuming foobar dynamically linked, programs are, know calls fsync.

but suppose there unknown program foobar1 , in source of program statement this:

execve("foobar", null, null) 

that is, environment not passed. whole ld_preload scheme breaks down?

i checked compiling statemet above foobar1, when run, calls foobar not reported.

while 1 can safely assume modern programs dynamically linked, 1 cannot @ assume how may or may not using execve?

so then, whole ld_preload scheme, says such great thing, not working unless have source programs concerned, in case can check calls execve , edit them if necessary. in case, there no need ld_preload, if have sources everything. ld_preload specifically, supposed be, useful when don't have sources programs inspecting.

where wrong here - how can people say, ld_preload useful inspecting unknown programs doing??

i guess write wrapper execve. in wrapper, add original envp argument, 1 more string: "ld_preload=my library" . "seems" work, checked on simple examples.

i not sure if should posting "answer" may exceed level of c experience.

can more experienced me comment if going work in long run?


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -