Implementing a virtual file by overriding Win32 File API

1.3k views Asked by At

Is there any way to override Win32 File API such as CreateFile()? I want my app to see a virtual file solely for my app, however, the virtual file does not exist actually.

2

There are 2 answers

0
Eugene Mayevski 'Callback On BEST ANSWER

There exist two approaches - with a kernel-mode driver (documented one) and without such driver (a hacky way).

With a kernel-mode driver you have two ways - (1) create a virtual filesystem driver (or take existing one) and (2) create a filesystem filter driver (or take existing one). Driver development = a year or so of work to do right and completely. Driver development is fully documented in MSDN.

Without a kernel-mode driver you need to employ API hooking. Libraries such as Detours, MadCodeHook and Boxedapp SDK do this (and let you do this as well).

Hooking an API topic is quite large to describe it here fully, but there's a good CodeProject article on this topic.

1
Kyle Alons On

System-wide? Bad idea. If it's just your app, don't use the standard APIs and implement it yourself. But if the data must persist between sessions, you'll have to store the data somewhere (file, registry, etc.).