]> git.zerfleddert.de Git - rsbs2/blame - src/rsb-crc.c
add howto exception list
[rsbs2] / src / rsb-crc.c
CommitLineData
6fc57dcd
MG
1#include <stdio.h>
2
972ac24b
MG
3#define POLY 0x04c11db7
4
c8b1eccb
MG
5unsigned int rsb_crc(unsigned int r11_crc, unsigned char *r10_buf, unsigned int r14_len) {
6 unsigned int r6_pos = 0;
7 unsigned int r3_data;
8 int r5_bit;
972ac24b 9
c8b1eccb
MG
10 while (r6_pos < r14_len) {
11 r3_data = (*(r6_pos+r10_buf)) << 24;
12 r11_crc = r11_crc ^ r3_data;
972ac24b 13
c8b1eccb 14 r5_bit = 8;
972ac24b
MG
15
16 do {
c8b1eccb 17 r3_data = r11_crc & 0x80000000;
972ac24b 18
c8b1eccb
MG
19 if (r3_data != 0) {
20 r3_data = r11_crc << 1;
21 r11_crc = r3_data ^ POLY;
972ac24b 22 } else {
c8b1eccb 23 r11_crc = r11_crc << 1;
972ac24b 24 }
c8b1eccb
MG
25 r5_bit--;
26 } while (r5_bit);
972ac24b 27
c8b1eccb 28 r6_pos++;
972ac24b
MG
29 }
30
c8b1eccb 31 return r11_crc;
972ac24b 32}
6fc57dcd 33
85feabf9 34unsigned int rsb_crc2(unsigned char *r0_buf, unsigned int r1_buflen, unsigned int r2_magic, unsigned int *crc_out) {
6fc57dcd 35 unsigned int r4_len;
b4de9923 36 unsigned int file_crc;
6fc57dcd 37
85feabf9 38 r4_len = *(unsigned int*)(r0_buf + 0x20);
6fc57dcd 39
85feabf9
MG
40 if (*((unsigned int*)(r0_buf + 0x24)) != r2_magic)
41 return 2; /* MAGIC does not match */
6fc57dcd 42
85feabf9
MG
43 if (r1_buflen < r4_len)
44 return 3; /* image to small */
6fc57dcd 45
a4019508 46 *crc_out = ~rsb_crc(~0x0, r0_buf, r4_len);
6fc57dcd 47
b4de9923 48 file_crc = *((unsigned int*)(r0_buf + r4_len));
6fc57dcd 49
a4019508 50 if (file_crc != *crc_out)
01004d01 51 return 4;
6fc57dcd 52
01004d01 53 return 0;
6fc57dcd 54}
Impressum, Datenschutz