]> git.zerfleddert.de Git - rsbs2/blob - firmware.c
decode settings in firmware
[rsbs2] / firmware.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "rsb-crc.h"
11
12 #define FINDSTR(addr, str) (!strncmp((char*)addr, str, strlen(str)))
13
14 void handle_defaults(unsigned char *fw, int len, int patch)
15 {
16 int i;
17
18 for (i = 0; i < (len-100 /* XXX */); i++) {
19 if (FINDSTR(fw+i, "/default/fw_prop/") ||
20 FINDSTR(fw+i, "/default/fw_setup/") ||
21 FINDSTR(fw+i, "/default/oem_prop/")) {
22 unsigned char *pos = fw + i;
23 unsigned char type1, type2;
24 unsigned char right_rw, rw_mask;
25 unsigned char *val;
26
27 printf("0x%08x: found setting: %s: ", i, pos);
28
29 pos += strlen((char*)pos) + 1;
30
31 if ((pos[0] != 0x11) ||
32 (pos[1] != 0x11) ||
33 (pos[2] != 0x01) ||
34 (pos[3] != 0x83)) {
35 printf("ignoring...\n");
36 continue;
37 }
38
39
40 pos += 4;
41
42 right_rw = pos[2];
43 rw_mask = pos[3];
44
45 type1 = pos[4];
46 type2 = pos[8];
47 val = pos + 9;
48
49 if (type1 == 0x00 && type2 == 0x04) {
50 printf("STRING: %s ", val);
51 } else if (type1 == 0x01 && type2 == 0x01) {
52 printf("BOOL: %s ",(*val ? "TRUE" : "FALSE"));
53 } else if (type1 == 0x04 && type2 == 0x02) {
54 printf("VAL: 0x%x ", *((unsigned int*)val));
55 } else {
56 printf("0x%02x 0x%2x...ignoring\n", type1, type2);
57 continue;
58 }
59
60 if (right_rw == 0x00 && rw_mask == 0x00) {
61 printf("(R-) ");
62 } else if (right_rw == 0x01) {
63 printf("(RW mask: 0x%02x) ", rw_mask);
64 } else {
65 printf("(UNK 0x%02x 0x%02x) ", right_rw, rw_mask);
66 }
67 printf("\n");
68 }
69 }
70 }
71
72 void handle_boarddescription(unsigned char *fw, int len, int patch)
73 {
74 /* 0x01 0x01 0x50 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x88 0x02 0xac 0x01 0xd0 0x05 0x00 0x00 0x6a 0x3a 0x00 0x00 0x06 0x00 0x01 0x00 0x00 0x00 0x00 0x00 */
75 }
76
77 int main(int argc, char **argv)
78 {
79 struct stat statbuf;
80 unsigned char *fw;
81 int fd;
82 int remaining;
83 int ret;
84 unsigned int crc, oldcrc;
85
86 if (argc != 2) {
87 fprintf(stderr,"Syntax: %s firmware.bin\n", argv[0]);
88 exit(1);
89 }
90
91 if (stat(argv[1], &statbuf) == -1) {
92 perror("stat");
93 exit(1);
94 }
95
96 if ((fd = open(argv[1], O_RDONLY)) == -1) {
97 perror("open");
98 exit(1);
99 }
100
101 if ((fw = malloc(statbuf.st_size)) == NULL) {
102 perror("malloc");
103 exit(1);
104 }
105
106 bzero(fw, statbuf.st_size);
107
108 remaining = statbuf.st_size;
109
110 while(remaining) {
111 if ((ret = read(fd, fw + (statbuf.st_size - remaining), remaining)) == -1) {
112 perror("read");
113 exit(1);
114 }
115 remaining -= ret;
116 }
117
118 ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
119 oldcrc = (unsigned int)*((unsigned int*)(fw + statbuf.st_size - 4));
120
121 printf("Checksum: 0x%08x (%s), should be: 0x%08x\n",
122 crc,
123 (ret ? "NOT OK" : "OK"),
124 oldcrc);
125
126 if (1) {
127 handle_defaults(fw, statbuf.st_size - 4, 0);
128 handle_boarddescription(fw, statbuf.st_size - 4, 0);
129 if (0) {
130 ret = rsb_crc2(fw, statbuf.st_size, 0x55335053, &crc);
131 printf("Checksum: 0x%08x\n", crc);
132 }
133 }
134
135 exit(0);
136 }
Impressum, Datenschutz