X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/blobdiff_plain/6fc57dcd5431aa5e19febfadb242de1e80f16c8f..395daefd4eb7af2962adee12f30249cca6991514:/rsb-crc.c diff --git a/rsb-crc.c b/rsb-crc.c index 3fe5cbc..8c8fbbe 100644 --- a/rsb-crc.c +++ b/rsb-crc.c @@ -115,79 +115,24 @@ unsigned int rsb_crc(unsigned int r11_crc, unsigned char *r10_buf, unsigned int * 55ae0: DATA: 0x04c11db7 */ -unsigned int rsb_crc2(unsigned char *r0_buf, unsigned int r1_buflen, unsigned int r2_magic, unsigned int *crc) { - int r8_ret = 1; - unsigned int r3 = 0xc0000000; +unsigned int rsb_crc2(unsigned char *r0_buf, unsigned int r1_buflen, unsigned int r2_magic, unsigned int *crc_out) { unsigned int r4_len; - unsigned int r5; - unsigned int r6; - unsigned int r7_poly; - unsigned int r9; - unsigned int carry; + unsigned int file_crc; -#if 0 - if (r0_buf <= r3) - return r8_ret; -#endif + r4_len = *(unsigned int*)(r0_buf + 0x20); - r3 = ((unsigned int)r0_buf) + 0x20; - r4_len = *((unsigned int*)r3); - printf("CRC: length: %d\n", r4_len); - - r8_ret = 2; - - r3 += 4; - r5 = *((unsigned int*)r3); - - if (r5 != r2_magic) - return r8_ret; - - r8_ret = 3; - - if (r1_buflen >= r4_len) { - r5 = 0; - } else { - r5 = 1; - } - - if (r5 != 0) - return r8_ret; + if (*((unsigned int*)(r0_buf + 0x24)) != r2_magic) + return 2; /* MAGIC does not match */ - r8_ret = 4; - - r3 = (unsigned int)r0_buf; - r4_len += r3; + if (r1_buflen < r4_len) + return 3; /* image to small */ - r5 = ~0x0; - - r7_poly = POLY; - - while (r3 < r4_len) { - r9 = r3 & (~0x3); - r6 = *((unsigned int*)r9); - r9 = r3 & 0x3; - r9 = r9 << 0x3; - r6 = r6 >> r9; - r5 = r5 ^ (r6 << 24); - r6 = 0x8; - - do { - carry = r5 & 0x80000000; - r5 = r5 << 1; - if (carry) - r5 = r5 ^ r7_poly; - r6--; - } while(r6); - r3++; - } - - r5 = ~r5; - *crc = r5; + *crc_out = ~rsb_crc(~0x0, r0_buf, r4_len); - r3 = *((unsigned int*)r4_len); + file_crc = *((unsigned int*)(r0_buf + r4_len)); - if (r3 == r5) - r8_ret = 0; + if (file_crc != *crc_out) + return 4; - return r8_ret; + return 0; }