Link to home
Start Free TrialLog in
Avatar of xmichen
xmichen

asked on

Madshi's madCodeHook Hook WS2_32.dll in windows98/me

When I try to hook WS2_32.dll in windows98/me
it will return an error like the follow:

Failed to load Winsock library!


But the same code works fine in windows xp/2k

HookAPI('WS2_32.dll', 'send', @sendCallback, @sendNext);
HookAPI('WS2_32.dll', 'recv', @recvCallback, @recvNext);

I tried the same hook code and the follow code
all can't work:(

        HookAPI('WS2_32.dll', 'recv', @recvCallback, @recvNext, MIXTURE_MODE);
        HookAPI('WS2_32.dll', 'send', @sendCallback, @sendNext, MIXTURE_MODE);
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xmichen
xmichen

ASKER

It worked with the lastest beta build of madCodeHook

But when I close the hooked application
will got an error window like this:

Runtime error 216 at 598036D6
Are you using Delphi or C++? In the latter case are you using the static or dynamic lib? Are you sure your code is correct? Try to use empty hook callback functions (that is only call the next function without doing anything else).
Avatar of xmichen

ASKER

I use Delphi
I try to use empty hook callback function,It still got error like that
but in windows xp/2k it works fine
How does your (empty) code look like?
Avatar of xmichen

ASKER

var
  sendNext : function( s       : Integer;
               buffer  : PByteArray;
               len     : Integer;
               flags   : Integer ):Integer; stdcall;
function sendCallback( s       : Integer;
               buffer  : PByteArray;
               len     : Integer;
               flags   : Integer ):Integer; stdcall;
begin
  Result := sendNext(s, buffer, len, flags);
end;
I'd like to see the whole code of the dll.

Also, which application shows that runtime error 216? Is it your own application or another one?
Avatar of xmichen

ASKER

unit Hookfunc;

interface
 
uses
  Windows, Messages, SysUtils, madCodeHook, Dialogs,
  graphics;

type
  TByteArray = array[0..32767] of byte;
  PByteArray = ^TByteArray;

implementation

var
  sendNext : function( s       : Integer;
               buffer  : PByteArray;
               len     : Integer;
               flags   : Integer ):Integer; stdcall;
function sendCallback( s       : Integer;
               buffer  : PByteArray;
               len     : Integer;
               flags   : Integer ):Integer; stdcall;
begin
  Result := sendNext(s, buffer, len, flags);
end;

procedure MyDLLHandler(Reason: Integer);
var
  FHandle   : LongWORD;
begin
  case Reason of
    DLL_PROCESS_ATTACH:
    begin
      HookAPI('WS2_32.dll', 'send', @sendCallback, @sendNext);
    end;
  end;
end;

begin
  DLLProc := @MyDLLHandler;
  MyDLLhandler(DLL_PROCESS_ATTACH);
end.
Avatar of xmichen

ASKER

Also, which application shows that runtime error 216? Is it your own application or another one?

looks is my dll shows that runtime error
But your dll is loaded in all processes. Inside of which process does it show that box?

P.S: Please remove Dialogs from the uses clause. It blows up the size of your dll quite much, cause it links in lots of VCL stuff.
P.P.S: Also remove graphics from the uses clause. You should try to avoid any VCL imports in a hook dll.
Avatar of xmichen

ASKER

I removed the graphics and Dialogs in uses clause
still got that error:(

that dll use CreateProcessEx load into one processes...not loaded in all processes
What if you remove the HookAPI call? Does the error then still occur? If it does, can you please compile the hook dll with madExcept? Thanks.
Avatar of xmichen

ASKER

Oh I am sorry,
It's my mistake
I add madExcept in the dll file
I remove it is ok
looks madExcept can't work with dll?
madExcept generally should work with dlls just fine. Using it for hook dlls which are used for system wide injection is not a good idea. But using it for a hook dll, which only gets injected into one process (as you do) should normally work.

So the problem exists only when you compile the dll with madExcept? That's strange...