|
The program works fine, but I have another
problem: I need to store strings as part
of my hook procedure of one of my hooked
api's. However, this does not seem to work.
Is there a limitation of variables in the
global shared area that does not permit
strings, i.e. something like
char buf[100];
?
|
|
|
|
|
I don't recommend using the shared memory area for that. Instead, try creating a memory mapped file or another method of named interprocess communication.
|
|
|
|
|
|
Are you compiling it into a C++ project
|
|
|
|
|
The dll is getting loaded into protected memory I think... For when I try to replace the method calls, it is crashing out for certain dll's. Specifically DirectInput. DirectDraw works just fine. Any suggestions?
Wy
|
|
|
|
|
I have used it for DirectInput w/no problems. Check your hook function to make sure it's correct
|
|
|
|
|
Hi there, great code. I thought you would like
to know that there is a book called 'Programming
Applications for Microsoft Windows' from MS Press
by J.Richter, which has a nother way of doing api
hooking; It is in Chapter 22; Jeffrey calls it
'Dll Injection'. You may want to rewrite this
example in your style, and post it here as 'Lesson 2
|
|
|
|
|
I got a Chinese copy of that, but not all the MessageBox function can be hooked, when I call hWnd->MessageBoxA(...),the hook dosen't work, I don't know why, any help is appreciated....
|
|
|
|
|
It would be very useful if there was a list
of changes that are needed to monitor a different
api with a different argument list in a different
dll. This will make it possible to use this code
without actually understanding it
|
|
|
|
|
It would be very useful if there was a list
of changes that are needed to monitor a different
api with a different argument list in a different
dll. This will make it possible to use this code
without actually understanding it
|
|
|
|
|
Just create a new SDLLHook structure and pass it to HookAPICalls(), it's that simple. Specify the name of the DLL and the function(s) you want to hook in the appropriate members of the structure.
You will of course need the header file/function prototypes for the DLL you are trying to hook so that you can make your own functions with equivalent stack/register usage.
-Wad
|
|
|
|
|
i tried ur method to hook some functions in a test.dll with some function like testfunction, i load this dll at runtime using loadlibrary, but ur method doesnt hook my testfunction function. but same methodworks for standard win32 dlls. plz help me here..
|
|
|
|
|
I think this example does not compile on
win200
|
|
|
|
|
Actually, I developed this under Win2000.
What compiler error are you getting? Perhaps you don't have the DirectX SDK installed.
-Wad
|
|
|
|
|
I have solved the problem. There where about
5 errors due to typing; I have to change your
(DWORD) casts into (unsigned long) and a few
from unsigned long pointer to unsigned long.
I am not sure what is supposed to happen when
the hook in installed, there in no visible
difference with bend.exe. However, I tested on
a different api and a different dll, and it
worked.
p.s. bend.exe doesn't seem to run on win9
|
|
|
|
|
If you look at the hooked DirectDrawCreate, it calls MessageBeep. This causes a sound to play, which tells you that the hook was installed and is working properly.
It's up to you to do something interesting with it.
Is anyone else experiencing the same compiler errors? DWORD is a standard Windows type, it should be available whenever <windows.h> is included. Perhaps I forgot to include a stdafx.h or something.
-Wad
|
|
|
|
|
I am getting the same 5 errors I believe.
In apihijack.cpp,
Error 1 error C2440: '=' : cannot convert from 'DWORD' to 'void *' Line 158
Error 2 error C2440: '=' : cannot convert from 'PDWORD' to 'DWORD' Line 196
Error 3 error C2446: '>' : no conversion from 'PDWORD' to 'DWORD' Line 203
Error 4 error C2040: '>' : 'DWORD' differs in levels of indirection from 'PDWORD' Line 203
Error 5 error C2440: '=' : cannot convert from 'PDWORD' to 'DWORD' Line 204
I am using MS VC++ 2005 to compile.
Edit: Forgot to add that you have to change the casting operators to get the sample to compile.
-- modified at 21:18 Saturday 22nd April, 2006
|
|
|
|
|
Love the forgotten line about '... make sure this is the Everquest process...' DOH.. =) At least we are working on the
same thing. How were you able to intercept the object's method calls? Ie, llpd->Flip(), lpDD->SetCooperativemode(), etc?
Wy
|
|
|
|
|
Argh, thought I had gotten rid of that =) Where did you see the reference?
Try this (reconstructed from memory):
#define CINTERFACE
#include <ddraw.h>
// This type conveniently comes from ddraw.h with CINTERFACE defined.
IDirectDrawVtbl OldIDirectDrawVtbl;
HRESULT IDirectDrawHooked_QueryInterface( ... )
{
OldIDirectDrawVtbl.QueryInterface( ... );
}
HRESULT MyDirectDrawCreate( ... )
{
// Create the DirectDraw object normally.
HRESULT ret = (oldFunc)( ... );
static bool IDirectDrawHooked = false;
if ( !IDirectDrawHooked )
{
// Save the IDirectDraw virtual method table.
memcpy( &OldIDirectDrawVtbl, ( *ppvObj )->Vtbl, sizeof(IDirectDrawVtbl) );
// Replace functions in the real Vtbl with ours.
( *ppvObj )->QueryInterface = IDirectDrawHooked_QueryInterface;
}
}
I think that's about it. COM is just so easy to hack...
-Wad
|
|
|
|
|
You used *ppvObj in your the above code. The only way I could get this wo work was to declare
*ppvObj = (LPDIRECTDRAW7)lplpDD;
or similar. Do I HAVE to cast this to directdraw7? So, the code will have to be redefined when dx7 is released?
Also, for the 2nd line...
(*ppvObj)->QueryInterface = IDirectDrawHooked_QueryInterface;
}
I am always getting an error that QueryInterface is not a member??
Wyv
|
|
|
|
|
got it i think...
//Save the IDirectDraw virtual method table.
memcpy(&OldIDirectDrawVtbl,(*ppvObj)->lpVtbl,sizeof(IDirectDraw7Vtbl));
//Replace member functions in the real lpVtbl with ours
(*ppvObj)->lpVtbl->QueryInterface = IDirectDrawHooked_QueryInterface;
|
|
|
|
|
Looks like you found the solution to get it to compile, however DirectDrawCreate only creates IDirectDraw interfaces, not IDirectDraw7.
However since QueryInterface is in the same position in both Vtbls, it should still work, I would reccommend casting to LPDIRECTDRAW though, just to maintain consistency.
As far as the new DirectX versions thing, usually what applications do is start with an IDirectDraw object, and then call QueryInterface on that to get the IDirectDraw7 object. Other apps use DirectDrawCreateEx or CoCreateInstance, which can be used to request any version of the interface I believe. This makes it hard to do an all around generic hooking system with DirectX, however I'm sure it's possible.
-Wad
|
|
|
|