Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello, I'm hoping someone might be able to help out. I've been looking for a few days now for a way to intercept all calls to CreateFile for a specific process name, and force that call to be in shared read only mode. I am aware that most programs lock a file for a reason. I am also aware that the program only reads from the file, and does not need to be locked. I plan on opening the file with read only and locking the file to read only.

I have found many different methods, most if not all being outdated, or I just could not get them to properly override the call.

While it would be very appreciated, I don't need complete source code, and I'm not asking for any hand holding. I just need a nudge in the proper direction!

Thank you for any help you can offer!

NOTE: While the name of the function I want to override is CreateFile, it will actually open an existing file instead of creating a new one.
Posted
Updated 5-Nov-11 11:07am
v3

Hello,

Have you looked at WinApi Hooks?

This article uses CreateFile to demonstrate api hooking :D

EasyHook - The reinvention of Windows API hooking[^]

Valery.
 
Share this answer
 
Comments
KairuByte 5-Nov-11 21:12pm    
That one may work.... It seems to be a slightly different version of something I looked at earlier today. I'll test it out and get back to you! ^_^
KairuByte 7-Nov-11 8:49am    
Checking it out now, first chance I have had. It does seem to actually compile, which the previous version I had seen did not. Looks promising!
KairuByte 7-Nov-11 10:08am    
That works quite well! Now I just need to figure out a way to inject into a process before it starts, without needing to start the process from my project... Maybe hooking explorers process start? Anyway, thanks!
That makes no sense at all. If a process is creating the file, it CAN'T be opened in read-only mode. What I think you mean is that you want to set the file to exclusive-write mode so no other apps can write to it.
 
Share this answer
 
Comments
KairuByte 5-Nov-11 13:18pm    
While that is what the function name suggests, that is not the case. CreateFile either creates the file (or I/O device) if it does not exist, or opens the file (or I/O device) if it is already present.

In this case the file is most definitely always present, though I suppose I could throw in a check beforehand just to make sure.

Here is Microsoft's documentation on CreateFile: msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900