From 45a99e6328280877a3bc9417a4c4219ffca84600 Mon Sep 17 00:00:00 2001 From: _N0x Date: Fri, 11 Feb 2022 00:19:20 +0100 Subject: [PATCH] Added basic implementation of writing a macro program to the firmware --- Makefile | 2 +- firmware.bin | Bin 32768 -> 0 bytes include/change_key.h | 32 -------------- include/firmware_handling.h | 86 +++++++++++++++++++++++++++++++++--- src/change_key.c | 10 ----- src/firmware_handling.c | 42 +++++++++++++++--- src/main.c | 77 +++++++++++++++++++++++++++----- 7 files changed, 184 insertions(+), 65 deletions(-) delete mode 100644 firmware.bin delete mode 100644 include/change_key.h delete mode 100644 src/change_key.c diff --git a/Makefile b/Makefile index a64b886..4b76162 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ## Compiler settings CC = cc -CFLAGS = -Wall +CFLAGS = -Wall -Werror -g -std=c99 LDFLAGS = ## Project settings diff --git a/firmware.bin b/firmware.bin deleted file mode 100644 index 3e478deb202031cb1feb665f245103022cdfc54b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeHwd3Y36*7vRMPEuJQov;N6p%MaiARwTOC@4h|nyNq`ASx(mv#3E?!YEGIq*>HP z83~FGD$a{K<1phI6g6s002jbfyTuI4TaV$2wv-bNtr@EWy%sb!nJ&%8U?|f;V zbMM*ixoe%eTZQeiaDF8T@g1NZa2#*~@IBzviSQ4i-R}qRP6Ft68u3{`@c(g`?G~c< zMM8|f_@B#K+vT5mRG*ti3o!=J1yDZQ6cFZ^ z&~v8}JHL7?Rdg|>)QsBZUWKM)&lq2Hvk>zDNkz_(G@+}R8YkBRyCyf0;|UA1;{2dT zEzFV-HU{Qp+5Phfzot2`x!~J_<>QfWKanf?ivi9{T(uRun?IYH;Hn+ETdPg>l#lPb zt8a~Sm$SxU?rctThl9beFo(AY^R|%v#c=Rc*#5dOSA>L+H8H-e{-6KZHHU61c1)mr z`lHU<2Q4trB z*`OQ6w+P`}FA3)$#E$~D0m{eIKZpCd)55Eu{_DeN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Jhdln09NI ze%+=H=)Qj3N`Ws_ldG=?-gI+n3jIjZ4QAy8HmPG zh4-Hr$9IW_m&A#e#oyl(-+wLsaa{b+Ak1~r$-AXf_erO>NN2KbXZzWH%(Vsk+d>0u zjpx~#2HO7UC>2jSCW}8g62uNip7^ulQt=nZAn}ys5Kl{S;u$GkJS(M$=cF|8yp%4g zq%LBoG(o%|O%g9k-NY`byLd_JAzqd;#4C6=19r@t7PZ zh&ovoyX8c&M@|xZ z@?`OWJXQGRDIy>zNFU0VN(bdq=_7fv^s!uO`$V2hBN~Gl!x=xj13y`oI_~9O#_3MZ` z+JRc&fB85Nf*vdfUJ}2|?|*xHbd=wEtUKDF5C49dr{bKIj&|)BU)%!!%ikN(aeQuM z|1wzAZb#hloct#|C%?>7an4G|bJ6i!{3kpY(Q$lkWdAZ))NV)I@tpi8JSV@*Q*q8p z$8*u~T>K|I7twKiZe;&5Sk!Ju-0__JCp;&wFW~2b?nwv_zz>@4Ok^equ?@6iD*i_w z{PzsD5%wp-hi(4wFY_4ve`SUK53G(~M+H-nWD&j0`b diff --git a/include/change_key.h b/include/change_key.h deleted file mode 100644 index cdc2083..0000000 --- a/include/change_key.h +++ /dev/null @@ -1,32 +0,0 @@ -/* changeKey.h */ - -/* Define for key offsets */ -#define F8_KEY1 0x00005149 -#define F8_KEY2 0x00005179 -#define F8_KEY3 0x00005181 -#define F8_KEY4 0x00005189 -#define F8_KEY5 0x00005190 -#define F8_KEY6 0x00005182 -#define F8_KEY7 0x0000517a -#define F8_KEY8 0x0000514a - -/* Define for prog1-8 offset */ -#define PROG1_OFFSET 0x0000539C -#define PROG2_OFFSET 0x000056BC -#define PROG3_OFFSET 0x000059DC -#define PROG4_OFFSET 0x00005CFC -#define PROG5_OFFSET 0x0000601C -#define PROG6_OFFSET 0x0000633C -#define PROG7_OFFSET 0x0000665C -#define PROG8_OFFSET 0x0006977C - -typedef struct key_prog key_prog; -struct key_prog -{ - int offset; - int key_settings[100][8]; -}; - - -void set_key_value(char* firmware_buffer, int key, int value); - diff --git a/include/firmware_handling.h b/include/firmware_handling.h index 07eeb91..a41c617 100644 --- a/include/firmware_handling.h +++ b/include/firmware_handling.h @@ -1,11 +1,85 @@ -typedef struct fbuffer_t fbuffer_t; -struct fbuffer_t +#include + +/* Max prog_actions per key_prog */ +#define MAX_ACTION 100 + +/* Defines for key offsets */ +#define F8_KEY1 0x00005189 +#define F8_KEY2 0x00005181 +#define F8_KEY3 0x00005179 +#define F8_KEY4 0x00005149 +#define F8_KEY5 0x0000518A +#define F8_KEY6 0x00005182 +#define F8_KEY7 0x0000517A +#define F8_KEY8 0x0000514A + +/* Defines for key program code */ +#define F8_PROG1 0xD7 +#define F8_PROG2 0xD8 +#define F8_PROG3 0xD9 +#define F8_PROG4 0xDA +#define F8_PROG5 0xDB +#define F8_PROG6 0xDC +#define F8_PROG7 0xDD +#define F8_PROG8 0xDE + +/* Define for prog1-8 offset */ +#define PROG1_OFFSET 0x0000539C +#define PROG2_OFFSET 0x000056BC +#define PROG3_OFFSET 0x000059DC +#define PROG4_OFFSET 0x00005CFC +#define PROG5_OFFSET 0x0000601C +#define PROG6_OFFSET 0x0000633C +#define PROG7_OFFSET 0x0000665C +#define PROG8_OFFSET 0x0000697C + +typedef struct f_bffr_t* f_bffrP; +struct f_bffr_t { - char* buffer; + char *buffer; int size; }; -/* reads in the firmware file into a buffer */ -fbuffer_t* get_firmware_buffer(char* filename); -void write_firmware_buffer(char* filename, fbuffer_t* p_fb); +/* + * A single macro action + * First value is the modifiers to be hold while executing the other actions (see keycodes.h) + * Second value is the delay between the keypresse ranging from 0.0 seconds to 3.0 seconds + * The remaining values are the keycodes to be pressed + */ +typedef struct prog_action* prog_actionP; +struct prog_action +{ + uint8_t k_modifier; + uint8_t k_delay; + uint8_t k_action1; + uint8_t k_action2; + uint8_t k_action3; + uint8_t k_action4; + uint8_t k_action5; + uint8_t k_action6; +}; + +/* + * A single macro program consisting of the offset and up to MAX_ACTION (100) actions + */ +typedef struct key_prog* key_progP; +struct key_prog +{ + int prog_offset; + prog_actionP prog_actions[MAX_ACTION]; +}; + +/* + * set the value "value" to the specified key "key" inside the buffer "firmware_buffer" + * Key has to be the offset of the key to be altered. + * Value has to be a keycode + */ +void set_key_value(char *firmware_buffer, int key, int value); + +void set_program(f_bffrP p_fb, key_progP kp); + +/* reads in the firmware file into a buffer */ +f_bffrP get_firmware_buffer(char *filename); + +void write_firmware_buffer(char *filename, f_bffrP p_fb); diff --git a/src/change_key.c b/src/change_key.c deleted file mode 100644 index 9166d04..0000000 --- a/src/change_key.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include -#include - -#include "../include/change_key.h" - -void set_key_value(char* firmware_buffer, int key, int value) { - memset(firmware_buffer + key, value, 1); -} diff --git a/src/firmware_handling.c b/src/firmware_handling.c index 2447fa1..e19c9ed 100644 --- a/src/firmware_handling.c +++ b/src/firmware_handling.c @@ -1,15 +1,16 @@ #include #include -#include #include +#include + +/* Just for debugging */ #include #include "../include/firmware_handling.h" -fbuffer_t* get_firmware_buffer(char* filename) { +f_bffrP get_firmware_buffer(char *filename) { - fbuffer_t buffer; - fbuffer_t* p_fb = &buffer; + f_bffrP p_fb = malloc(sizeof(*p_fb)); FILE *firmware = fopen(filename, "rb"); if(!firmware) { @@ -23,6 +24,7 @@ fbuffer_t* get_firmware_buffer(char* filename) { exit(EXIT_FAILURE); } + /* set buffer size and read in firmware file into buffer*/ p_fb->size = sb.st_size; p_fb->buffer = malloc(p_fb->size); fread(p_fb->buffer, p_fb->size, 1, firmware); @@ -35,7 +37,7 @@ fbuffer_t* get_firmware_buffer(char* filename) { return p_fb; } -void write_firmware_buffer(char* filename, fbuffer_t* p_fb) { +void write_firmware_buffer(char *filename, f_bffrP p_fb) { FILE *firmware_file = fopen(filename, "wb+"); if(!firmware_file) { @@ -47,3 +49,33 @@ void write_firmware_buffer(char* filename, fbuffer_t* p_fb) { fclose(firmware_file); } + + +void set_key_value(char *firmware_buffer, int key, int value) { + memset(firmware_buffer + key, value, 1); +} + +void set_program(f_bffrP p_fb, key_progP kp) { + for(int i=0; iprog_actions[i]){ + /* calculate the offset for the action + * -> general prog_offset + current prog_action i times bytes per action + */ + int actionpointer = kp->prog_offset + (i * sizeof(*kp->prog_actions[0])); + + /* set the modifiers */ + memset(p_fb->buffer + actionpointer + 0, kp->prog_actions[i]->k_modifier, 1); + /* set timing delay */ + memset(p_fb->buffer + actionpointer + 1, kp->prog_actions[i]->k_delay, 1); + /* set action 1-6 */ + memset(p_fb->buffer + actionpointer + 2, kp->prog_actions[i]->k_action1, 1); + memset(p_fb->buffer + actionpointer + 3, kp->prog_actions[i]->k_action2, 1); + memset(p_fb->buffer + actionpointer + 4, kp->prog_actions[i]->k_action3, 1); + memset(p_fb->buffer + actionpointer + 5, kp->prog_actions[i]->k_action4, 1); + memset(p_fb->buffer + actionpointer + 6, kp->prog_actions[i]->k_action5, 1); + memset(p_fb->buffer + actionpointer + 7, kp->prog_actions[i]->k_action6, 1); + } + } +} diff --git a/src/main.c b/src/main.c index a8ed322..6d8523a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,28 +1,83 @@ #include +#include #include #include -#include "../include/change_key.h" #include "../include/firmware_handling.h" #include "../include/keycodes.h" +void testing (f_bffrP p_fb); +char *updated_file_name(char *orig); + int main (int argc, char *argv[]) { - fbuffer_t* p_fb = get_firmware_buffer(argv[1]); + /* Read in the firmware file into a f_bffr_t struct */ + f_bffrP p_fb = get_firmware_buffer(argv[1]); - set_key_value(p_fb->buffer, F8_KEY8, KEY_a_A); + /* Call testing method */ + testing(p_fb); + + write_firmware_buffer(updated_file_name(argv[1]), p_fb); + + free(p_fb->buffer); + free(p_fb); + + return 0; +} + +char *updated_file_name (char *orig){ + char *ne = "_new.bin"; + int len = strlen(orig); + + char *new_name = malloc(len + 4); + + strncpy(new_name, orig, len - 4); + strcat(new_name, ne); + + printf("New File Name: %s", new_name); + + return new_name; +} + +void testing (f_bffrP p_fb) { + set_key_value(p_fb->buffer, F8_KEY1, KEY_9_LeftParenthesis); + set_key_value(p_fb->buffer, F8_KEY2, KEY_8_Asterisk); + set_key_value(p_fb->buffer, F8_KEY3, KEY_7_Ampersand); + set_key_value(p_fb->buffer, F8_KEY4, KEY_6_Caret); + set_key_value(p_fb->buffer, F8_KEY5, KEY_5_Percent); + set_key_value(p_fb->buffer, F8_KEY6, KEY_4_Dollar); + set_key_value(p_fb->buffer, F8_KEY7, KEY_3_Pound); + set_key_value(p_fb->buffer, F8_KEY8, KEY_2_At); /* for debugging -> print content of buffer to terminal */ /* - for(int i = 0; isize; i++){ - putc(isprint(fb->buffer[i]) ? fb->buffer[i] : '.', stdout); + for(int i = 0; isize; i++){ + putc(isprint(p_fb->buffer[i]) ? p_fb->buffer[i] : '.', stdout); } */ - - /* Temporary solution to renaming the input file */ - char str[50]; - sprintf(str, "new_%s", argv[1]); - write_firmware_buffer(str, p_fb); - return 0; + prog_actionP pa = calloc(1, sizeof(*pa)); + pa->k_modifier = 0x00; + pa->k_delay = 0x00; + pa->k_action1 = 0x0B; + pa->k_action2 = 0x04; + pa->k_action3 = 0x0F; + pa->k_action4 = 0x0F; + pa->k_action5 = 0x12; + pa->k_action6 = 0x00; + + + key_progP kp = calloc(1, sizeof(*kp)); + kp->prog_offset = PROG1_OFFSET; + kp->prog_actions[0] = pa; + kp->prog_actions[1] = pa; + kp->prog_actions[2] = pa; + kp->prog_actions[3] = pa; + kp->prog_actions[99] = pa; + //*/ + + set_program(p_fb, kp); + + free(kp); + free(pa); }