Ploblem with static link library !

c++ / delphi package - dll injection and api hooking
Post Reply
Teerayoot
Posts: 10
Joined: Tue May 18, 2004 5:04 pm

Ploblem with static link library !

Post 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?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post 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.
Teerayoot
Posts: 10
Joined: Tue May 18, 2004 5:04 pm

Yeah i using that one.

Post by Teerayoot »

I using madCodeHook.hpp and madCodeHook_.lib
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post 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.
Teerayoot
Posts: 10
Joined: Tue May 18, 2004 5:04 pm

New qustion.

Post 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.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post 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.
Post Reply