Ploblem with static link library !

c++ / delphi package - dll injection and api hooking

Ploblem with static link library !

Postby Teerayoot » Sat May 22, 2004 6:55 pm

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

Postby madshi » Sun May 23, 2004 7:26 am

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

Yeah i using that one.

Postby Teerayoot » Sun May 23, 2004 12:47 pm

I using madCodeHook.hpp and madCodeHook_.lib
Teerayoot
 
Posts: 10
Joined: Tue May 18, 2004 5:04 pm

Postby madshi » Sun May 23, 2004 12:54 pm

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

New qustion.

Postby Teerayoot » Mon May 24, 2004 3:38 pm

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

Postby madshi » Tue May 25, 2004 7:00 am

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:

http://forum.madshi.net/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.
madshi
Site Admin
 
Posts: 9664
Joined: Sun Mar 21, 2004 5:25 pm


Return to madCodeHook

Who is online

Users browsing this forum: No registered users and 9 guests