Works pretty well, except for one minor issue.
On Windows, it will fail if a sufficiently large file name is encountered.
So I decided to fix it. I compiled with MSVC, if that matters.
Add the following code after the includes:
#if defined(WIN32)
#include <io.h>
#include <Windows.h>
#define strcasecmp _stricmp
const wchar_t* MSFILENAMESPACE = {L"\\\\?\\"};
const wchar_t* WIDEREADBINARY = {L"rb"};
FILE* my_fopen(char* filePath, char* ignored)
{
// Windows hack
FILE* fp = NULL;
int fpsize, wchars_num, nameSpaceLen;
wchar_t *fpstr = NULL, *wstr = NULL;
nameSpaceLen = wcslen(MSFILENAMESPACE);
wchars_num = MultiByteToWideChar(CP_UTF8, 0, filePath, -1, NULL, 0 );
wstr = malloc(sizeof(wchar_t) * wchars_num);
if(wstr)
{
MultiByteToWideChar(CP_UTF8, 0, filePath, -1, wstr, wchars_num);
fpsize = GetFullPathNameW(wstr,0,NULL,NULL) + nameSpaceLen;
fpstr = malloc(sizeof(wchar_t) * fpsize);
if(fpstr)
{
wcscpy (fpstr, MSFILENAMESPACE);
GetFullPathNameW(wstr,fpsize-nameSpaceLen,fpstr+nameSpaceLen,NULL);
fp = _wfopen(fpstr, WIDEREADBINARY);
free(fpstr);
}
free(wstr);
}
return fp;
}
#else
FILE* my_fopen(char* filePath, char* mode)
{
return fopen(filePath, mode);
}
#endif /* Def WIN32 */
int beStepOver(BYTE* benstr,int benstrLen,int benstrOffset);
You can also throw in "#define _CRT_SECURE_NO_WARNINGS" at the beginning if the warnings annoy you.
Then just change all the instances of fopen() to my_fopen().