- Joined
- Sep 10, 2007
- Messages
- 970
- Reaction score
- 815
Wizkid is an idiot. This does not include my signature scanner library. This unpacks every file, not just XMLs like Peter's shenanigans.
Code:
#include <windows.h>
#include <stdio.h>
#include "Detour/CDetour.h"
void create_subdirs (const char *path) {
char *work = strdup(path), *ptr;
for (ptr = work; *ptr; ++ ptr)
if (*ptr == '\\') {
*ptr = 0;
printf("subdir: [%s]\n", work);
CreateDirectory (work,NULL);
*ptr = '\\';
}
free(work);
}
CDetour MZFile__ReadDet;
void __stdcall MZFile__ReadHook (int i, void *lpBuffer, int nSize)
{
printf ("Hook?\n");
char *lpFile;
_asm mov lpFile, esi
printf ("[I=%i] MZFile::Read [%s][\n", i, lpFile);
char szPath[256];
sprintf(szPath,"MRS\\%s", lpFile);
for(int i =0; i <strlen(szPath); i++)
if(szPath[i] == '/')
szPath[i] = '\\';
create_subdirs (szPath);
MZFile__ReadDet.Org (i, lpBuffer, nSize);
DWORD dwWrote;
HANDLE hFile = CreateFile (szPath, GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
WriteFile (hFile, lpBuffer, nSize, &dwWrote, NULL);
printf("%u]\n", dwWrote);
}
CDetour MZip__ReadFileDet;
void __stdcall MZip__ReadFileHook (const char *szFile, void *lpBuffer, int nSize)
{
char szPath[256];
sprintf(szPath,"MRS\\%s",szFile);
for(int i =0; i <strlen(szPath); i++)
if(szPath[i] == '/')
szPath[i] = '\\';
create_subdirs (szPath);
MZip__ReadFileDet.Org (szFile, lpBuffer, nSize);
printf ("%s (",szFile);
DWORD dwWrote;
HANDLE hFile = CreateFile (szPath, GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
WriteFile (hFile, lpBuffer, nSize, &dwWrote, NULL);
printf("%u)\n", dwWrote);
CloseHandle (hFile);
}
void Initialize ()
{
AllocConsole ( );
freopen ( "CONOUT$", "wb", stdout );
printf ("Testing..\n");
MZip__ReadFileDet.Detour ((PBYTE)0x00538B40, (PBYTE)MZip__ReadFileHook, true);
MZip__ReadFileDet.Apply ();
MZFile__ReadDet2.Detour ((PBYTE)0x00538960, (PBYTE)MZFile__ReadHook2, true);
MZFile__ReadDet2.Apply ();
AllocConsole ( );
freopen ( "CONOUT$", "wb", stdout );
printf ("Detours applied.\n");
}
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
DisableThreadLibraryCalls ( hModule );
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
Initialize( );
break;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}