Ir para conteúdo
Fórum Script Brasil
  • 0

Hook winsock, ta dando erro =\


caion90

Pergunta

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 para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,7k
×
×
  • Criar Novo...