elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  [Duda] CallBack
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: [Duda] CallBack  (Leído 4,765 veces)
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: [Duda] CallBack
« Respuesta #10 en: 17 Enero 2011, 20:08 pm »

.
Te dejo esto el proceso WndProc aun no lo pongo como miembro de la clase aun que sera facil tal cual a dicho Eternal Idol haciendo dicha funcion como Static ( yo mientras trabajare de esta manera para depurar mi codigo ).

Código
  1.  
  2. LRESULT CALLBACK    WndProc     (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  3.  
  4. cls_socket::cls_socket()
  5. {   /*  Constructor */
  6.    this->Event_RequestConection    = NULL;
  7.    this->Event_GetData             = NULL;
  8.    this->Event_Closed              = NULL;
  9.    this->Event_Connent             = NULL;
  10.    this->Event_Error               = NULL;
  11.    this->v_socket                  = INVALID_SOCKET;
  12.    this->State                     = sckError;
  13.  
  14.    this->RemoteHost                = NULL;
  15.    this->RemotePort                = 0;
  16.    this->LocalPort                 = 0;
  17.  
  18.    if ( WSAStartup( MAKEWORD(2,2) , &this->v_wsadata  ) != NO_ERROR )
  19.        return;
  20.    this->v_hWinSock = CreateWindowExA( 0 , "STATIC" , "SOCKET_WINDOW",0, 0, 0, 0, 0, 0, 0, 0,NULL);
  21.    if (this->v_hWinSock != NULL)
  22.        if ( SetWindowLongA( this->v_hWinSock , GWL_USERDATA , (LONG)this ) == 0 )
  23.            if ( (this->v_PrevProc = SetWindowLongA( this->v_hWinSock , GWL_WNDPROC, (DWORD)WndProc)) != 0 ) {
  24.                this->v_ItsOk = true;
  25.                this->State = sckClosed;
  26.            }
  27. }
  28. cls_socket::~cls_socket() {   /*  Destructor */
  29.    WSACleanup();
  30.    if ( this->v_PrevProc != 0 )
  31.        SetWindowLongA (this->v_hWinSock , GWL_WNDPROC, this->v_PrevProc);
  32.    if ( this->v_hWinSock != NULL )
  33.        DestroyWindow (this->v_hWinSock);
  34. }
  35.  
  36. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  37.    char            *v_abuffer      = NULL;
  38.    char            v_buffer[1024]  = {};
  39.    int             v_res           = 0;
  40.    unsigned int    v_lenstr        = 0;
  41.    cls_socket      *thisClass      = NULL;
  42.    SOCKET          AceptSocket     = INVALID_SOCKET;
  43.  
  44.    if ( uMsg != 1025 )
  45.        return DefWindowProc(hWnd, uMsg, wParam, lParam);
  46.  
  47.    /* Recuperamos la Clase */
  48.    thisClass = (cls_socket*)GetWindowLongA ( hWnd , GWL_USERDATA );
  49.    if ( thisClass == NULL )
  50.        return DefWindowProc(hWnd, uMsg, wParam, lParam);
  51.    switch ( lParam ) {
  52.        case FD_CONNECT:
  53.            thisClass->State = sckConnected;
  54.            /* Evento */
  55.            if ( thisClass->Event_Connent != NULL )
  56.                thisClass->Event_Connent ( thisClass );
  57.            break;
  58.        case FD_READ:
  59.            v_res   = 0;
  60.            v_lenstr  = 0;
  61.            do {
  62.                v_res = recv(  thisClass->v_socket , &v_buffer[0] , 1024 , 0 );
  63.                if ( v_res > 0 ) {
  64.                    v_lenstr += v_res;
  65.                    v_abuffer = (char*)realloc(v_abuffer, sizeof(char) * (v_lenstr+1));
  66.                    memcpy( &v_abuffer[v_lenstr-v_res], &v_buffer[0] , v_res);
  67.                }
  68.            } while ( v_res > 0 );
  69.            if ( v_lenstr > 0 ) {
  70.                v_abuffer[v_lenstr] = '\0';
  71.                /* Evento */
  72.                if ( thisClass->Event_GetData != NULL )
  73.                    thisClass->Event_GetData ( v_abuffer , v_lenstr , thisClass );
  74.                free ( v_abuffer );
  75.            }   //  if
  76.            break;
  77.        case FD_WRITE:
  78.            break;
  79.        case FD_CLOSE:
  80.            thisClass->State = sckClosed;
  81.            closesocket( thisClass->v_socket );
  82.            thisClass->v_socket = INVALID_SOCKET;
  83.            /* Evento */
  84.            if ( thisClass->Event_Closed != NULL )
  85.                thisClass->Event_Closed ( thisClass );
  86.            break;
  87.        case FD_ACCEPT:
  88.            //sockaddr        SockAcept;
  89.            if ( ( AceptSocket = accept( thisClass->v_socket , NULL , NULL ) ) != INVALID_SOCKET )
  90.                /* Evento */
  91.                if ( thisClass->Event_RequestConection != NULL )
  92.                    thisClass->Event_RequestConection ( &AceptSocket , thisClass );
  93.            break;
  94.        default: break;
  95.    }   //  switch
  96.    return 0;
  97. }
  98.  
  99.  

Temibles Lunas!¡.
.


En línea

The Dark Shadow is my passion.
ThunderCls


Desconectado Desconectado

Mensajes: 455


Coder | Reverser | Gamer


Ver Perfil WWW
Re: [Duda] CallBack
« Respuesta #11 en: 17 Enero 2011, 21:05 pm »

Gracias Black, vere que hago con esta info  ;-)
Saludos


En línea

-[ "…I can only show you the door. You're the one that has to walk through it." – Morpheus (The Matrix) ]-
http://reversec0de.wordpress.com
https://github.com/ThunderCls/
Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Process32next Callback
Programación Visual Basic
ntaryl 4 2,239 Último mensaje 24 Septiembre 2008, 05:58 am
por ssccaann43 ©
TLS Callback
Programación C/C++
ThunderCls 0 1,931 Último mensaje 9 Mayo 2011, 22:18 pm
por ThunderCls
Funciones callback?
Programación C/C++
roilivethelife 1 2,977 Último mensaje 20 Agosto 2012, 17:41 pm
por rir3760
Rutina de desencriptación con TLS Callback
Análisis y Diseño de Malware
Binary_Death 5 3,252 Último mensaje 1 Septiembre 2013, 06:13 am
por Binary_Death
Refresco tkinter de texto recibido en un callback
Scripting
minak 1 1,757 Último mensaje 11 Mayo 2018, 13:48 pm
por minak
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines