Link to home
Start Free TrialLog in
Avatar of Sandra-24
Sandra-24

asked on

Replace fopen/fwrite

I would like to insert my own code each time a third party application writes to the disk. I have the source code and I thought the easiest way to do this is simply to replace fopen/fwrite with a function of my own that internally calls the real fopen/fwrite. How can I do this?

Thanks,
-Sandra
Avatar of Farzad Akbarnejad
Farzad Akbarnejad
Flag of Iran, Islamic Republic of image

Hello,
I think thaty you must write a resident in memory program that listen to int 13h for writing and reading disk.

-FA
Do you have the source code of the third party's fopen/fwrite? If you do, have you tried to call the ::fopen and ::fwrite functions?  If you just rename their fopen/fwrite functions so that their names are slightly different, then the next time you build the third party library it should pull in the standard c-runtime library version of fopen/fwrite.
Avatar of jasonclarke
jasonclarke

An alternative might be to use something like the .NET FileSystemWatcher class - this raises events when specified I/O events take place (like changes to a particular directory or file).   There is a Win32 equivalent - ReadDirectoryChanges - but this is probably harder to use than the .NET class.
ASKER CERTIFIED SOLUTION
Avatar of grg99
grg99

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sandra-24

ASKER

Thanks grg99, that's exactly what I wanted.

Cheers,
-Sandra
Note that this trick will work but only for sources you compile with this stuff included.

It won't change any fwrite's being done in linked in libraries.

Ands it won't trap any other kinds of writes, like with write()  and the other variations.