|
-
May 21st, 2010, 10:03 PM
#1
why this clone function doesn't work?
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
Code:
#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;
}
-
May 22nd, 2010, 12:22 AM
#2
Re: why this clone function doesn't work?
Why do you think 168 bytes is enough to hold a copy of the FindClose() function?
How do you know that FindClose() does not call other code that it expects to be within its memory space, but outside of the 168 bytes that you copy?
-
May 23rd, 2010, 04:52 AM
#3
Re: why this clone function doesn't work?
You also must check the return value of GetProcAddress (and of GetModuleHandle too!)
Victor Nijegorodov
-
May 23rd, 2010, 11:01 AM
#4
Re: why this clone function doesn't work?
thanks for your reply!
maybe it doesn't work in that way! i just want to try some ideas, it's a good learning experience.....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|