views:

74

answers:

1

Hey,

I do have a program (call it "a.exe" for example) which reads its config from several files. can I write another program to redirect all file accesses of "a.exe" to another stream (console for example)?

I don't have the code of "a.exe" but if I get the source code of a.exe, obviously I can change all the file accesses. but is there any possible way to override all file access by very "minimum" changes? for example overriding file.open function or something like that?

A: 

One simple idea is to have another program or script provide named pipes instead of the actual files. Once a.exe tries to read from them, it will block until something else sends data through the pipe.

Like in Linux you could do:

mkfifo config.txt # if a.exe uses config.txt
./a.exe # a.exe will now block until you write to config.txt and close it

They should work in Windows too it seems: Wikipedia on Named Pipes

Barring this, or if you want to do something more advanced, you'd have to look into tools that hooks or overrides external library calls for a given binary.

integer
Pipe naming restrictions on Windows prevent transparent replacement of a file with a named pipe. It's a good approach on Linux though, I've used it myself.
Ben Voigt
thank you so much for you quick answer.I updated the Question by the way.
Sangihi