Mouse logger

A place to submit all custom code, scripts, and programs.
Forum rules
Do NOT post malicious code or programs. Please review all code posted in this forum before downloading or running any of the code or programs here.

Mouse logger

Post by pretentious on Thu Feb 05, 2015 7:51 am
([msg=86616]see Mouse logger[/msg])

This is a program i wrote, inspired by http://iographica.com/
the c executable reads from the mouse device on my computer and prints a timestamp and the relative movement into another file. The python script reads the file in as an argument and redraws the mouses movement on a canvas. I set up a cronjob for this and set the image as my background. It was cool for a little while, and I wanted to add some more features the iographica has, like circles and shit (and I have knowledge of different mouse actions too) but I probably have undiagnosed ADD and moved onto other things
mouse_log.c
Code: Select all
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main(){
    int x = 683, y = 384;
FILE *input = fopen("/dev/input/mouse0","r");
FILE *log = fopen("/var/log/mouse_log", "a");
signed char char_num;
signed char protocol[3];
    while(input){// tests to see if file exists
        for(char_num = 0; char_num <3; char_num++){
            protocol[char_num] = fgetc(input);
        }
        x+=protocol[1];
        if(x >1366)x = 1366;
        if(x < 0)x = 0;
        y-=protocol[2];
        if(y > 768)y = 768;
        if(y < 0)y = 0;
        // I'm still not entirely sure how to decode the mouse buttons but in the future it will likely be easier to user numbers than words anyway
        // assuming protocol -1 when device is unplugged
        while(protocol[0] == -1){
            sleep(1);
            input = fopen("/dev/input/mouse0","r");
            if(input)
                break;
        }
    if(protocol[0] != -1)
        fprintf(log, "%d %d %d %d\n", (int)time(NULL), protocol[0], x, y);       
    }
    fclose(input);
    fclose(log);
}


line.py
Code: Select all
from PIL import Image, ImageDraw
import sys
#import time
filecount = open(sys.argv[1],'r')
f = open(sys.argv[1],'r')
img = Image.new("RGB",(1367*2, 768*2) ,"black")
pixdata = img.load()
formatted = f.readline().split()
x1 = int(formatted[2])
y1 = int(formatted[3])
draw = ImageDraw.Draw(img)
for line in f:
    formatted = line.split()
    if len(formatted) != 4:
        continue
    #print formatted
    x2 = int(formatted[2])
    y2 = int(formatted[3])
    colour = pixdata[x1,y1]
    shade = colour[0]
    if shade < 200:
        shade = shade + 25
    draw.line((x1*2,y1*2,x2*2,y2*2),(shade,shade,shade))
    x1 = x2
    y1 = y2
new = img.resize((1367,769), Image.ANTIALIAS)
#new.show()
new.save("wall.png","PNG")
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: Mouse logger

Post by ghost107 on Thu Feb 05, 2015 5:36 pm
([msg=86622]see Re: Mouse logger[/msg])

It's kinda heavy on the CPU(Try to add a sleep):

Checking the mousse Polling rate on Ubuntu:
Code: Select all

cat /sys/module/usbhid/parameters/mousepoll
Result(should be one of this values):
1 ms = 1000Hz
2 ms = 500Hz
4 ms = 250Hz
8 ms = 125Hz
10 ms = 100Hz


You should look into Xlib(Xlib is like Win32 of Linux system):
http://tronche.com/gui/x/xlib/input/
Code: Select all
#include "X11/Xlib.h"

Display *display;
Window window;
XEvent event;
unsigned long event_mask = PointerMotion;

display = XOpenDisplay(NULL);                    //Connect  to the display server
window = XRootWindow(display, 0);                //0 = primary display, 1 = seconday display
XSelectInput(display, window,  event_mask);  // select a input type

while(true) {
   XNextEvent( display, &event );
   switch( event.type ) {
      case MotionNotify:
         printf("x=%d, y=%d\n", event.xmotion.x, event.xmotion.y );
         break;
   }
}
Last edited by ghost107 on Thu Feb 05, 2015 5:53 pm, edited 2 times in total.
User avatar
ghost107
Poster
Poster
 
Posts: 321
Joined: Wed Jul 02, 2008 7:57 am
Blog: View Blog (0)


Re: Mouse logger

Post by cyberdrain on Thu Feb 05, 2015 5:46 pm
([msg=86627]see Re: Mouse logger[/msg])

Bookmarked! :3 I have to read these back another time.
Free your mind / Think clearly
User avatar
cyberdrain
Expert
Expert
 
Posts: 2160
Joined: Sun Nov 27, 2011 1:58 pm
Blog: View Blog (0)


Re: Mouse logger

Post by pretentious on Sat Feb 07, 2015 1:45 am
([msg=86637]see Re: Mouse logger[/msg])

ghost107 wrote:It's kinda heavy on the CPU(Try to add a sleep):

It's interesting that you mention this because I made a point to avoid system bloat and even though the code looks dodgy, I saw negligible resource use. It gave me the impression that fgetc pauses execution while waiting to read something. But I'm probably wrong.

I also tried using the x11 library previously to this but couldn't get it working as a background process. Oh well lol
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)



Return to Custom Code

Who is online

Users browsing this forum: No registered users and 0 guests