Skip to content

Instantly share code, notes, and snippets.

@paucoma
Created November 18, 2018 22:55
Show Gist options
  • Save paucoma/059525c15f45817a9124129a0d340021 to your computer and use it in GitHub Desktop.
Save paucoma/059525c15f45817a9124129a0d340021 to your computer and use it in GitHub Desktop.
Tiny Task Configuration File Modifier
/*
Deciphering TinyTask Recording Format after a bit of trial and error I found and used the following
*/
#include<stdio.h>
/* Our structure
- 0002 0000 7906 0000 4501 0000 dd0a 9400 7607 0b00
- 20 bytes in length
- interpreted as shorts, when we read it with fread, bytes get reordered
- 0200 0000 0679 0000 0145 0000 0add 0094 0776 000b
*/
/*
resources:
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendinput
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-taginput
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagkeybdinput
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmouseinput
https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
*/
struct record{
unsigned short act; //Action type
unsigned short rsv0;
unsigned short a; //in Mouse = screen x-coordinates
// In KeyPress 0xmmnn , where nn follows Microsoft Virtual Key codes
// https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
// In KeyPress 0xmmnn, where mm follows hardware scancode set 1
// http://www.ee.bgu.ac.il/~microlab/MicroLab/Labs/ScanCodes.htm
// http://www.quadibloc.com/comp/scan.htm
// https://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html
unsigned short rsv1;
unsigned short b; //in Mouse = screen y-coordinates
// In KeyPress, hardware scancode set 1 expressed as 2 bytes , mainly 0x00mm
unsigned short rsv2;
unsigned int timestampms; //windows uptime timestamp in ms
unsigned int identifier;
};
typedef enum {
act_MouseMoveTo = 0x0200,
act_MouseLeftPress = 0x0201,
act_MouseLeftRelease = 0x0202,
act_MouseRightPress = 0x0204,
act_MouseRightRelease = 0x0205,
act_KeyPress = 0x0100,
act_KeyRelease = 0x0101
} RecAact;
#include <stdlib.h>
#include <string.h>
int getfsize(FILE *fp){
int prev=ftell(fp);
fseek(fp, 0L, SEEK_END);
int sz=ftell(fp);
fseek(fp,prev,SEEK_SET); //go back to where we were
return sz;
}
char* concat(const char *s1, const char *s2){
char *result = malloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator
// in real code you would check for errors in malloc here
strcpy(result, s1);
strcat(result, s2);
return result;
}
int main(int argc, char* argv[]){
FILE *in_ptr,*out_ptr;
int retval = 0; //Return value success by default
struct record *inRec,*outRec;
unsigned int tsms0;
tsms0 = 0;
if (argc < 2) return 1;
in_ptr=fopen(argv[1],"rb");
if (!in_ptr){
printf("Unable to open file for reading");
retval = 1;
}else{
//Lets get the filesize of our input file
int num_recs = (int) ( getfsize(in_ptr) / sizeof(struct record) );
inRec = malloc(sizeof(struct record)*num_recs);
outRec = malloc(sizeof(struct record)*num_recs);
out_ptr=fopen(concat("_",argv[1]),"wb");
if (!out_ptr){
printf("Unable to open file for writing");
retval = 1;
}else{
fread(inRec,sizeof(struct record),num_recs,in_ptr);
//fread returns a size_t representing the number of elements read successfully
// remove consecutive MouseMoves and refactor timebase
// the last mousemoveto position is also removed.
// Shortens mouse movements to mousemovems ms
int mousemovems = 200;
int mmstart,mmstop;
mmstart = mmstop = 0;
int j=1;
outRec[0]=inRec[0];
tsms0=inRec[0].timestampms;
outRec[0].timestampms -= tsms0;
for(int i=1;i<num_recs;i++){
if(inRec[i].act == act_MouseMoveTo){
if(mmstart==0){
mmstart=i;
outRec[j]=inRec[i];
outRec[j++].timestampms -= tsms0;
}
mmstop = i;
}else{
if(mmstart != mmstop) {
outRec[j]=inRec[mmstop];
//outRec[j++].timestampms -= tsms0;
//we set our next move at a time only mousemovems later
outRec[j].timestampms = outRec[j-1].timestampms + mousemovems;
//we shift our 0 timestamp
tsms0 = inRec[mmstop].timestampms-outRec[j++].timestampms;
}
outRec[j]=inRec[i];
outRec[j++].timestampms -= tsms0;
mmstart = mmstop = 0;
}
}
fwrite(outRec,sizeof(struct record),j,out_ptr);
}
fclose(out_ptr);
}
fclose(in_ptr);
return retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment