Jump to content
  • Advertisement
Sign in to follow this  
roby65

Create a "virtual file" only for one application

This topic is 3477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make an application read from memory and not from a file for only one file....... i made a class to simulate a file read, but there is a problem. i hooked CreateFileA and ReadFile: static HANDLE __stdcall Hacked_CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { debug<<"CreateFileA(\""<<lpFileName<<"\",...,...);\n"; if(!stricmp(lpFileName,"game.dbs")) { debug<<"Returned fake handle\n"; return (HANDLE)0xFFFFFF; } return Original_CreateFileA(lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } BOOL __stdcall Hacked_ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped) { if(hFile==(HANDLE)0xFFFFFF) { debug<<"Read of fake file\n"; return game_database_static.ReadFakeFile((char*)lpBuffer,nNumberOfBytesToRead,(int*)lpNumberOfBytesRead); } return Original_ReadFile(hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,lpOverlapped); but the applicatin still reads from the original file and not from emory!!!!!!! :( why?

Share this post


Link to post
Share on other sites
Advertisement
Prime example of polymorphism
struct Reader {
virtual DWORD read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) = 0;
};

struct FileReader {
FileReader(LPCSTR lpFileName) {
h = CreateFile(lpFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
}

virtual DWORD read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
DWORD nRead = 0;
ReadFile(h,lpBuffer,nNumberOfBytesToRead,&nRead,0);
return nRead;
}
private:
HANDLE h;
}

struct MemReader {
virtual DWORD read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
DWORD nRead;
game_database_static.ReadFakeFile((char*)lpBuffer,nNumberOfBytesToRead,(int*)&nRead);
return nRead;
}
}



Quote:
CreateFileA


Don't reference these functions directly. Depending on how you compile the project, different version of the function might get used.

Also - don't mess with WinAPI namespace. It's a disaster as it is.

Or, if you can't use classes, use function pointers:

typedef BOOL (__stdcall *readFileFP)(HANDLE, LPVOID, DWORD, LPDWORD, LPOVERLAPPED)
Then pass the readFileFP to the functions that do IO.

Share this post


Link to post
Share on other sites
the problem is that i hook two functions to check if the program is loading a file, if the file is "game.dbs" i want to make it read my file.....
i hook CreateFileA and ReadFile, but the program can load the file anyway...how?!?!?!

Share this post


Link to post
Share on other sites
Quote:
Original post by roby65
the problem is that i hook two functions to check if the program is loading a file, if the file is "game.dbs" i want to make it read my file.....
i hook CreateFileA and ReadFile, but the program can load the file anyway...how?!?!?!
Why not just modify the code to use some proxy function? What exactly are you trying to do?

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by roby65
the problem is that i hook two functions to check if the program is loading a file, if the file is "game.dbs" i want to make it read my file.....
i hook CreateFileA and ReadFile, but the program can load the file anyway...how?!?!?!
Why not just modify the code to use some proxy function? What exactly are you trying to do?


i'm trying to make a "basic anticheat" for crashday, a game that doesn't check for modified files when you play online...so when game tryes to read from the file i want to read from memory...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!