Page 1 of 1

Ploblem with static link library !

Posted: Sat May 22, 2004 6:55 pm
by Teerayoot
I using madCollection version 2.1.2.0 and working on Borland c++ builder 6.0 and Windows Xp sp1.

The ploblem is when i use madchook in dinamic link library(from madCodeHook\Dll folder )it woking fine not have any ploblem .

But when i use static link library (from folder madCodeHook\BCB6)
bool WINAPI DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)

{
if (fdwReason == DLL_PROCESS_ATTACH)
{
InitializeMadCHook();


CollectHooks ();
HookAPI("WS2_32.DLL", "send", sendCallback, (PVOID*) &sendNext);

FlushHooks ();

} else if (fdwReason == DLL_PROCESS_DETACH)

UnhookAPI( (PVOID*)&sendNext);
FinalizeMadCHook();
// delete working_buffer;



return true;
}

My bcb output show this warnning ...
[C++ Warning] Unit1.cpp(75): W8030 Temporary used for parameter 'nextHook' in call to '__stdcall HookAPI(char *,char *,void *,void * &,unsigned int)'
[C++ Warning] Unit1.cpp(81): W8030 Temporary used for parameter 'nextHook' in call to '__stdcall UnhookAPI(void * &)'

Yes it's warning all compilation successfully .
When i inject my dll into another process ,sometime hook sometime not.
And sendNext() function point to invalid memory address(i trace with debugger)
Memory access violation exception heppen.


What's the ploblem ,and how to solve this thing?

Posted: Sun May 23, 2004 7:26 am
by madshi
The dynamic header and the 2 dynamic lib files are meant for either MSVC or for Borland C++. The static header + lib is meant only for MSVC.

When using BCB, you have a much better choice, namely using the native Delphi precompiled stuff. So use "include "madCodeHook.hpp"" instead of using the "madCHook.h" and "madCHook.lib" files.

Yeah i using that one.

Posted: Sun May 23, 2004 12:47 pm
by Teerayoot
I using madCodeHook.hpp and madCodeHook_.lib

Posted: Sun May 23, 2004 12:54 pm
by madshi
Hmmmm... Did you manually link madCodeHook_.lib in?

Anyway, I'm not sure where the warning comes from. Try to add an additional "0" as the last parameter to HookAPI. Maybe that gets rid of the warning.

New qustion.

Posted: Mon May 24, 2004 3:38 pm
by Teerayoot
Previous ploblem had been solved,it's because i use
#include <mswsock.h> intead of #include <winsock2.h>.
I think your library not work with previous "mswsock.h"


But my new qustion ...
When i use this code
bool WINAPI DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)

{
if (fdwReason == DLL_PROCESS_ATTACH)
{
InitializeMadCHook();
CollectHooks ();
HookAPI("WS2_32.DLL", "send", sendCallback, (PVOID)sendNext ,(unsigned)(0x0));
FlushHooks ();

} else if (fdwReason == DLL_PROCESS_DETACH)
UnhookAPI( (PVOID) sendNext);
FinalizeMadCHook();
return true;
}


My dll not hook in another process.
but when remove InitializeMadCHook(); and FinalizeMadCHook();
in spite of i using static link library

It work ,it hooking.
What 's the reason for this subject.

Posted: Tue May 25, 2004 7:00 am
by madshi
Previous ploblem had been solved,it's because i use
#include <mswsock.h> intead of #include <winsock2.h>.
I think your library not work with previous "mswsock.h"
Please check out this one:

viewtopic.php?p=168#168
My dll not hook in another process.
but when remove InitializeMadCHook(); and FinalizeMadCHook();
in spite of i using static link library
That's strange! InitializeMadCHook() doesn't do anything bad, even if you call it twice! Anyway, you can remove the calls to both InitializeMadCHook() and FinalizeMadCHook() because they're not needed when using BCB + "madCodeHook.hpp". Btw, you don't need to unhook that API in DLL_PROCESS_DETACH. madCodeHook does that automatically for you. You don't need to do anything in DLL_PROCESS_DETACH.