Autor Beitrag
Big_Boss
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

XP home
Turbo Delphi, Delphi 2005 PE
BeitragVerfasst: Mi 03.01.07 17:15 
Hallo,


Ich mache ein Programm, welches die Buchstaben zählt, die man eingibt.
Ich habe einen hook gemacht und sogar einen der klappt(in einer DLL):
ausblenden volle Höhe Delphi-Quelltext
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:
  Function keyboard(nCode:integer; wparam:wparam; lparam:lparam): lresult; stdcall;
  begin
  Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
  case ncode<0 of   //Was wird gemacht, wenn ncode kleiner als 0 ist
  true: exit;       //Wenn es wahr ist, dann wird beendet
  false:            //wenn ncode größer als 0 ist, dann ...
  begin
  case wparam of
  $41:Str:=Str+'a';
  $42:Str:=Str+'b';
  $43:Str:=Str+'c';
  $44:Str:=Str+'d';
  $45:Str:=Str+'e';
  $46:Str:=Str+'f';
  $47:Str:=Str+'g';
  $48:Str:=Str+'h';
  $49:Str:=Str+'i';
  $4A:Str:=Str+'j';
  $4B:Str:=Str+'k';
  $4C:Str:=Str+'l';
  $4D:Str:=Str+'m';
  $4E:Str:=Str+'n';
  $4F:Str:=Str+'o';
  $50:Str:=Str+'p';
  $51:Str:=Str+'q';
  $52:Str:=Str+'r';
  $53:Str:=Str+'s';
  $54:Str:=Str+'t';
  $55:Str:=Str+'u';
  $56:Str:=Str+'v';
  $57:Str:=Str+'w';
  $58:Str:=Str+'x';
  $59:Str:=Str+'y';
  $5A:Str:=Str+'z';
  $30:Str:=Str+'0';
  $31:Str:=Str+'1';
  $32:Str:=Str+'2';
  $33:Str:=Str+'3';
  $34:Str:=Str+'4';
  $35:Str:=Str+'5';
  $36:Str:=Str+'6';
  $37:Str:=Str+'7';
  $38:Str:=Str+'8';
  $39:Str:=Str+'9';
  end;


Wenn ich z.b. $41:=beep(200,200); durch $41:Str:=Str+'a'; ersetze, dann ist der Hook systemweit(hört man ja an dem ton), das mit dem string geht aber nicht. (ich speichere die anzahl der buchstaben in einer ini und dort wird die Anzahl erst verändert, wenn die Anwendung fokusiert ist).

Was muss ich machen, damit der String (str) auch systemweit geändert wird?


MfG Big_Boss
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mi 03.01.07 17:50 
Hast du den gesamten Hook in einer DLL? Welches OS verwendest du? Kannst du bitte den Code zeigen, mit dem du den Hook startest?

Gruß alias5000

PS.: Oh, noch einer aus Heilbronn :cool: Wo wohnst du genau? :mrgreen:

EDIT: Hab ich ganz vergessen: du willst mir damit aber nich nen Keylogger schreiben?

_________________
Programmers never die, they just GOSUB without RETURN
Big_Boss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

XP home
Turbo Delphi, Delphi 2005 PE
BeitragVerfasst: Mi 03.01.07 21:33 
ausblenden volle Höhe Delphi-Quelltext
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:
...
var
  HookHandle: Cardinal = 0;
  WindowHandle: Cardinal = 0;
  Str: String;


  Function keyboard(nCode:integer; wparam:wparam; lparam:lparam): lresult; stdcall;
  begin
  Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
  case ncode<0 of   //Was wird gemacht, wenn ncode kleiner als 0 ist
  true: exit;       //Wenn es wahr ist, dann wird beendet
  false:            //wenn ncode größer als 0 ist, dann ...
  begin
  case wparam of
  $41:Str:=Str+'a';
  $42:Str:=Str+'b';
  $43:Str:=Str+'c';
  $44:Str:=Str+'d';
  $45:Str:=Str+'e';
  $46:Str:=Str+'f';
  $47:Str:=Str+'g';
  $48:Str:=Str+'h';
  $49:Str:=Str+'i';
  $4A:Str:=Str+'j';
  $4B:Str:=Str+'k';
  $4C:Str:=Str+'l';
  $4D:Str:=Str+'m';
  $4E:Str:=Str+'n';
  $4F:Str:=Str+'o';
  $50:Str:=Str+'p';
  $51:Str:=Str+'q';
  $52:Str:=Str+'r';
  $53:Str:=Str+'s';
  $54:Str:=Str+'t';
  $55:Str:=Str+'u';
  $56:Str:=Str+'v';
  $57:Str:=Str+'w';
  $58:Str:=Str+'x';
  $59:Str:=Str+'y';
  $5A:Str:=Str+'z';
  $30:Str:=Str+'0';
  $31:Str:=Str+'1';
  $32:Str:=Str+'2';
  $33:Str:=Str+'3';
  $34:Str:=Str+'4';
  $35:Str:=Str+'5';
  $36:Str:=Str+'6';
  $37:Str:=Str+'7';
  $38:Str:=Str+'8';
  $39:Str:=Str+'9';
  $20:Str:=Str+' ';
  end;


  end;

  end;
  end;

  Function installhook(HW:cardinal):Boolean; stdcall;
  begin
  result:=false;
  if Hookhandle=0 then begin
    HookHandle := SetWindowsHookEx(WH_KEYBOARD, @Keyboard, HInstance, 0);
    WindowHandle := Hw;
    Result := TRUE;
  end;
end;
Function UninstallHook:boolean; stdcall;
begin
  Result:=UNhookwindowsHookex(Hookhandle);
  Hookhandle:=0;
end;


Ja, ich habe alles in einer Dll und Nein, ich möchte keinen Keylogger machen(Der String wird nachher nach Buchstaben durchsucht dachte ich mir). Ich möchte nur so eine Art Buchstaben-Zähl-Programm machen, einfach so um Hooks kennen zu lernen.

PS.: Ich wohn in Massenbachhausen ;)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 03.01.07 21:57 
user profile iconBig_Boss hat folgendes geschrieben:
ausblenden volle Höhe Delphi-Quelltext
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:
  case wparam of
  $41:Str:=Str+'a';
  $42:Str:=Str+'b';
  $43:Str:=Str+'c';
  $44:Str:=Str+'d';
  $45:Str:=Str+'e';
  $46:Str:=Str+'f';
  $47:Str:=Str+'g';
  $48:Str:=Str+'h';
  $49:Str:=Str+'i';
  $4A:Str:=Str+'j';
  $4B:Str:=Str+'k';
  $4C:Str:=Str+'l';
  $4D:Str:=Str+'m';
  $4E:Str:=Str+'n';
  $4F:Str:=Str+'o';
  $50:Str:=Str+'p';
  $51:Str:=Str+'q';
  $52:Str:=Str+'r';
  $53:Str:=Str+'s';
  $54:Str:=Str+'t';
  $55:Str:=Str+'u';
  $56:Str:=Str+'v';
  $57:Str:=Str+'w';
  $58:Str:=Str+'x';
  $59:Str:=Str+'y';
  $5A:Str:=Str+'z';
  $30:Str:=Str+'0';
  $31:Str:=Str+'1';
  $32:Str:=Str+'2';
  $33:Str:=Str+'3';
  $34:Str:=Str+'4';
  $35:Str:=Str+'5';
  $36:Str:=Str+'6';
  $37:Str:=Str+'7';
  $38:Str:=Str+'8';
  $39:Str:=Str+'9';
  $20:Str:=Str+' ';
  end;

Wie wärs mit Str := Str + Chr(wParam); stattdessen?
Ggf. noch mit einer if-Abfrage, ob es sich überhaupt um einen Buchstaben handelt, denn sonst werden alle Zeichen benutzt? (if wParam in [65..90, 48..57, 32] then)

Das hat allerdings nichts mit dem Problem zu tun.
Big_Boss Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20

XP home
Turbo Delphi, Delphi 2005 PE
BeitragVerfasst: Do 04.01.07 13:44 
OK, jetzt funktioniert es(Dank euren Hilfen, Danke). Hier mein Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Function keyboard(nCode:integer; wparam:wparam; lparam:lparam): lresult; 
stdcall;
var ini: TIniFile;
begin
  Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
  if nCode >= 0 then begin
    if wParam in [65..90, 48..57, 32] then begin 
      Str := Str + Chr(wParam); 
      ini := TIniFile.Create('C:\Test.ini');      
    try
        ini.WriteString('String','TASTEN',str);
              finally
        ini.Free;
      end;
    end;
  end;
end;


MfG Big_Boss
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Do 04.01.07 15:31 
Ich würde den Code trotzdem optimieren, damit du nicht bei jedem Tastendruck einen Dateizugriff hast. Ich würde mir trotzdem nochmal Methoden anschauen, mit denen du den String erstmal an deine Anwendung schicken kannst (WM_COPYDATA,... ich glaub Asserbad macht da auch einen Verweis drauf, müsste ich nachschauen). Und dann kannst du ihn ja sonstwie und sonstwann in eine Datei schreiben, ich würde es aber nicht jedes mal machen.

Für die anderen:
Ich hab ihm ein bisschen über ICQ geholfen. Der Kernpunkt dabei war, dass er in der Variable str den String gespeichert hat und dann von der Hauptanwendung aus eine DLL- Procedure ausgeführt hat, die den String in die ini- Datei speichern soll. Da das ein globaler Hook ist, wurde natürlich nur die anwendungseigene DLL- Instanz angesprochen.

Gruß alias5*10³

_________________
Programmers never die, they just GOSUB without RETURN
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Di 09.01.07 19:24 
ne frage: was machste dann mit der dll?
wollt mich auch mal damit beschäftigen...durch den Code steig ich soweit durch aber dann...