Added basic implementation of writing a macro program to the firmware
This commit is contained in:
parent
10ffdc7aaa
commit
d1b9796c5a
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
|||||||
## Compiler settings
|
## Compiler settings
|
||||||
CC = cc
|
CC = cc
|
||||||
CFLAGS = -Wall
|
CFLAGS = -Wall -Werror -g -std=c99
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
## Project settings
|
## Project settings
|
||||||
|
BIN
firmware.bin
BIN
firmware.bin
Binary file not shown.
@ -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);
|
|
||||||
|
|
@ -1,11 +1,85 @@
|
|||||||
typedef struct fbuffer_t fbuffer_t;
|
#include <stdint.h>
|
||||||
struct fbuffer_t
|
|
||||||
|
/* 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;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* reads in the firmware file into a buffer */
|
/*
|
||||||
fbuffer_t* get_firmware_buffer(char* filename);
|
* A single macro action
|
||||||
void write_firmware_buffer(char* filename, fbuffer_t* p_fb);
|
* 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);
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#include "../include/change_key.h"
|
|
||||||
|
|
||||||
void set_key_value(char* firmware_buffer, int key, int value) {
|
|
||||||
memset(firmware_buffer + key, value, 1);
|
|
||||||
}
|
|
@ -1,15 +1,16 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
/* Just for debugging */
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "../include/firmware_handling.h"
|
#include "../include/firmware_handling.h"
|
||||||
|
|
||||||
fbuffer_t* get_firmware_buffer(char* filename) {
|
f_bffrP get_firmware_buffer(char *filename) {
|
||||||
|
|
||||||
fbuffer_t buffer;
|
f_bffrP p_fb = malloc(sizeof(*p_fb));
|
||||||
fbuffer_t* p_fb = &buffer;
|
|
||||||
|
|
||||||
FILE *firmware = fopen(filename, "rb");
|
FILE *firmware = fopen(filename, "rb");
|
||||||
if(!firmware) {
|
if(!firmware) {
|
||||||
@ -23,6 +24,7 @@ fbuffer_t* get_firmware_buffer(char* filename) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set buffer size and read in firmware file into buffer*/
|
||||||
p_fb->size = sb.st_size;
|
p_fb->size = sb.st_size;
|
||||||
p_fb->buffer = malloc(p_fb->size);
|
p_fb->buffer = malloc(p_fb->size);
|
||||||
fread(p_fb->buffer, p_fb->size, 1, firmware);
|
fread(p_fb->buffer, p_fb->size, 1, firmware);
|
||||||
@ -35,7 +37,7 @@ fbuffer_t* get_firmware_buffer(char* filename) {
|
|||||||
return p_fb;
|
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+");
|
FILE *firmware_file = fopen(filename, "wb+");
|
||||||
if(!firmware_file) {
|
if(!firmware_file) {
|
||||||
@ -47,3 +49,33 @@ void write_firmware_buffer(char* filename, fbuffer_t* p_fb) {
|
|||||||
|
|
||||||
fclose(firmware_file);
|
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; i<MAX_ACTION; i++){
|
||||||
|
|
||||||
|
// Check if an action for that position exists
|
||||||
|
if(kp->prog_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
75
src/main.c
75
src/main.c
@ -1,28 +1,83 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "../include/change_key.h"
|
|
||||||
#include "../include/firmware_handling.h"
|
#include "../include/firmware_handling.h"
|
||||||
#include "../include/keycodes.h"
|
#include "../include/keycodes.h"
|
||||||
|
|
||||||
|
void testing (f_bffrP p_fb);
|
||||||
|
char *updated_file_name(char *orig);
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
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 debugging -> print content of buffer to terminal */
|
||||||
/*
|
/*
|
||||||
for(int i = 0; i<fb->size; i++){
|
for(int i = 0; i<p_fb->size; i++){
|
||||||
putc(isprint(fb->buffer[i]) ? fb->buffer[i] : '.', stdout);
|
putc(isprint(p_fb->buffer[i]) ? p_fb->buffer[i] : '.', stdout);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Temporary solution to renaming the input file */
|
prog_actionP pa = calloc(1, sizeof(*pa));
|
||||||
char str[50];
|
pa->k_modifier = 0x00;
|
||||||
sprintf(str, "new_%s", argv[1]);
|
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;
|
||||||
|
|
||||||
write_firmware_buffer(str, p_fb);
|
|
||||||
return 0;
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user