Jump to content
Fórum Script Brasil
  • 0

Hook winsock, ta dando erro =\


caion90

Question

library Hook;

uses
  SysUtils,
  Windows,
  afxcodehook,
  winsock2,
  Classes;


var
    o_recv: function( const s: TSocket; var Buf; len, flags: Integer ): Integer; stdcall;
    o_send: function( const s: TSocket; var Buf; len, flags: Integer ): Integer; stdcall;
    dwThreadID: Cardinal = 0;



function fwrite(fname: string; var buf; len: integer):bool;
var fhandle: hwnd;
    w,fsize: cardinal;
begin
result := false;
fhandle := createfile(pchar(fname), GENERIC_WRITE, 0, nil, OPEN_ALWAYS, 0, 0);
if fhandle = INVALID_HANDLE_VALUE then exit;
fsize := GetFileSize(fhandle, nil);
SetFilePointer(fhandle, fsize, nil, FILE_BEGIN);
result := WriteFile(fhandle, buf, len, w, nil);
end;





function n_send( const s: TSocket; var Buf; len, flags: Integer ): Integer; stdcall;
begin
result := -1;
//fwrite('c:\teste\send.txt', buf, len);
//result := o_send(s, buf, len, flags);
//               <---  o_send (erro)
end;

function n_recv( const s: TSocket; var Buf; len, flags: Integer ): Integer; stdcall;
begin
result := -1;
//result := o_recv(s, buf, len, flags);
//fwrite('c:\teste\recv.txt', buf, len);
//              <---- o_recv (erro) 
end;


procedure HookThread;
begin
  while GetModuleHandle('Ws2_32.dll') = 0 do
    Sleep(10);

    HookCode(GetProcAddress(GetModuleHandle('Ws2_32.dll'), 'recv'), @n_recv, @o_recv);
    HookCode(GetProcAddress(GetModuleHandle('Ws2_32.dll'), 'send'), @n_send, @o_send);
end;




procedure DllMain(fdwReason: Cardinal);
begin
  case fdwReason of
    DLL_PROCESS_ATTACH:
    begin
      CreateThread(nil, 0, @HookThread, nil, 0, dwThreadID);
    end;
    DLL_PROCESS_DETACH:
    begin
      //Code
    end;
  end;
end;

begin
  DllProc := @DllMain;
  DllMain(DLL_PROCESS_ATTACH);
end.

então, o erro é justo quando vou pegar e fazer a chamada pra api normal do windows... alguém se habilita a me ajudar? ;)

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652.1k
×
×
  • Create New...