From: "Joseph Boctor"
Subject: Hook functions, or change function pointers/code
Date: 2000/08/11
Message-ID: #1/1
Organization: Excite@Home - The Leader in Broadband
NNTP-Posting-Date: Fri, 11 Aug 2000 11:42:22 PDT
Newsgroups: comp.os.ms-windows.programming.mfc,fido.win32,fido7.inter.win32,microsoft.public.win32,microsoft.public.win32.programmer
Hi All!
THIS IS VERY URGENT PLEASE HELP
I have two function, I want to hook one function to the other.
ie
func1(); // would actually go to func1()
func2(); // would also go to func2()
// hooking function is called
hook(func1, func2);
func1(); // would go to func1();
func2(); // ***** now would go to func1() as well
unhook();
func1(); // would again go to func1()
func2(); // would go to func2()
now the code that have works in debug mode in vc++ 6, but when I try to
execute it, it gives an access violation error.
I basically make a point to the function code of both functions
( BYTE * lpfunc1 = (BYTE *)func1;
BYTE * lpfunc2 = (BYTE *)func2; )
now I go to change the begining of the function by adding a assembly jmp
instruction to func2.
( *((BYTE *) lpfunc1 + 0) = 0x66;
*((DWORD *) lpfunc1 + 4) = *lpfunc2; )
it works perfect in debug mode and when I try to run the executable, it
doesn't work at all.
Please let me know if I am doing something wrong, or if you have any idea
about another way of doing this.
Thanx a lot
THIS IS VERY URGENT PLEASE HELP
Joe
|