First test to read and edit the firmware, added defines for the required offsets etc
This commit is contained in:
parent
c39a70ff88
commit
cc81d31ab6
BIN
firmware.bin
Normal file
BIN
firmware.bin
Normal file
Binary file not shown.
32
include/change_key.h
Normal file
32
include/change_key.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* changeKey.h */
|
||||||
|
|
||||||
|
/* Define for key offsets */
|
||||||
|
#define KEY1 0x00005149
|
||||||
|
#define KEY2 0x00005179
|
||||||
|
#define KEY3 0x00005181
|
||||||
|
#define KEY4 0x00005189
|
||||||
|
#define KEY5 0x00005190
|
||||||
|
#define KEY6 0x00005182
|
||||||
|
#define KEY7 0x0000517a
|
||||||
|
#define 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);
|
||||||
|
|
11
include/firmware_handling.h
Normal file
11
include/firmware_handling.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
typedef struct fbuffer_t fbuffer_t;
|
||||||
|
struct fbuffer_t
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
10
src/change_key.c
Normal file
10
src/change_key.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#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);
|
||||||
|
}
|
49
src/firmware_handling.c
Normal file
49
src/firmware_handling.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "../include/firmware_handling.h"
|
||||||
|
|
||||||
|
fbuffer_t* get_firmware_buffer(char* filename) {
|
||||||
|
|
||||||
|
fbuffer_t buffer;
|
||||||
|
fbuffer_t* p_fb = &buffer;
|
||||||
|
|
||||||
|
FILE *firmware = fopen(filename, "rb");
|
||||||
|
if(!firmware) {
|
||||||
|
perror("Error while reading in Firmware File.\r\nExiting.");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct stat sb;
|
||||||
|
if(stat(filename, &sb) == -1) {
|
||||||
|
perror("Error while reading Firmware metadata.\r\nExiting.");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_fb->size = sb.st_size;
|
||||||
|
p_fb->buffer = malloc(p_fb->size);
|
||||||
|
fread(p_fb->buffer, p_fb->size, 1, firmware);
|
||||||
|
|
||||||
|
/* for testing if the buffer could be read correclty */
|
||||||
|
// printf("buffer size: %d", p_fb->size);
|
||||||
|
|
||||||
|
fclose(firmware);
|
||||||
|
|
||||||
|
return p_fb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_firmware_buffer(char* filename, fbuffer_t* p_fb) {
|
||||||
|
|
||||||
|
FILE *firmware_file = fopen(filename, "wb+");
|
||||||
|
if(!firmware_file) {
|
||||||
|
perror("Error while opening in Firmware File.\r\nExiting.");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite(p_fb->buffer, p_fb->size, 1, firmware_file);
|
||||||
|
|
||||||
|
fclose(firmware_file);
|
||||||
|
}
|
27
src/main.c
Normal file
27
src/main.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "../include/change_key.h"
|
||||||
|
#include "../include/firmware_handling.h"
|
||||||
|
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
fbuffer_t* p_fb = get_firmware_buffer(argv[1]);
|
||||||
|
|
||||||
|
set_key_value(p_fb->buffer, KEY8, 0x1E);
|
||||||
|
|
||||||
|
/* for debugging -> print content of buffer to terminal */
|
||||||
|
/*
|
||||||
|
for(int i = 0; i<fb->size; i++){
|
||||||
|
putc(isprint(fb->buffer[i]) ? fb->buffer[i] : '.', stdout);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
char str[50];
|
||||||
|
|
||||||
|
sprintf(str, "new_%s", argv[1]);
|
||||||
|
|
||||||
|
write_firmware_buffer(str, p_fb);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user