smallwolf
May 21st, 2010, 10:03 PM
hello:
i want to test to call a function in a different way, but failed.....
the program compiled and run, it listed the files...and then the process crashed with errors...
what's wrong with my code:
using wxDevC++, Windows xp sp3
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main(int argc, char *argv[])
{
typedef BOOL (*FINDCLOSE)(HANDLE);
FINDCLOSE fc=(FINDCLOSE)GetProcAddress(GetModuleHandle("Kernel32"),"FindClose");
void* oldProc=fc;
BYTE* vfc=(BYTE*)oldProc;
BYTE* buffer=malloc(170); // allocate enough memory to hold the code
memcpy(buffer,vfc,168);
void* orif=buffer;
PROC findc=(PROC)orif;
WIN32_FIND_DATA find_data;
HANDLE find_handle;
find_handle = FindFirstFile("C:\\*.*", &find_data );
if( find_handle != INVALID_HANDLE_VALUE )
{
/// list files in this directory
do
{
printf(find_data.cFileName);
printf("\n");
}while( FindNextFile( find_handle, &find_data ) );
findc( find_handle ); // i replace the FindClose()
}
system("PAUSE");
return 0;
}
i want to test to call a function in a different way, but failed.....
the program compiled and run, it listed the files...and then the process crashed with errors...
what's wrong with my code:
using wxDevC++, Windows xp sp3
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main(int argc, char *argv[])
{
typedef BOOL (*FINDCLOSE)(HANDLE);
FINDCLOSE fc=(FINDCLOSE)GetProcAddress(GetModuleHandle("Kernel32"),"FindClose");
void* oldProc=fc;
BYTE* vfc=(BYTE*)oldProc;
BYTE* buffer=malloc(170); // allocate enough memory to hold the code
memcpy(buffer,vfc,168);
void* orif=buffer;
PROC findc=(PROC)orif;
WIN32_FIND_DATA find_data;
HANDLE find_handle;
find_handle = FindFirstFile("C:\\*.*", &find_data );
if( find_handle != INVALID_HANDLE_VALUE )
{
/// list files in this directory
do
{
printf(find_data.cFileName);
printf("\n");
}while( FindNextFile( find_handle, &find_data ) );
findc( find_handle ); // i replace the FindClose()
}
system("PAUSE");
return 0;
}