diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-27 15:11:34 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-27 15:11:34 -0800 |
commit | 1a66a74e8a35c1fd85060060ba61bb1b67d6eb44 (patch) | |
tree | bd34c8c763a8b9148fa896c1326d2b12883667f7 /cochran.c | |
parent | 5bc3ba5e95e753c86d483d8adc0326e8a80c5797 (diff) | |
download | subsurface-1a66a74e8a35c1fd85060060ba61bb1b67d6eb44.tar.gz |
cochran: do a partial header de-scramble
This descrambles at least parts of the header data. Some of it has the
same pattern of data 4kB apart, it may be that there is a dive hiding in
there too (ie what I currently call a "header" may in fact be a header
_plus_ a dive).
But the 4kB thing may well be an artifact of the crazy scrambling code
itself. Who knows what kind of chunking the Cochran Analyst
"encryption" uses.
As with the dive data, there seems to be some offset differences between
different CAN files.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'cochran.c')
-rw-r--r-- | cochran.c | 56 |
1 files changed, 46 insertions, 10 deletions
@@ -79,7 +79,7 @@ static int figure_out_modulus(const unsigned char *decode, const unsigned char * #define hexchar(n) ("0123456789abcdef"[(n)&15]) -static void show_line(unsigned offset, const unsigned char *data, unsigned size) +static int show_line(unsigned offset, const unsigned char *data, unsigned size, int show_empty) { unsigned char bits; int i, off; @@ -105,18 +105,51 @@ static void show_line(unsigned offset, const unsigned char *data, unsigned size) asc[1] = 0; } - if (bits) + if (bits) { puts(buffer); + return 1; + } + if (show_empty) + puts("..."); + return 0; } -static void cochran_debug_write(const char *filename, int dive, const unsigned char *data, unsigned size) +static void cochran_debug_write(const char *filename, const unsigned char *data, unsigned size) { - int i; - printf("\n%s, dive %d\n\n", filename, dive); + int i, show = 1; - for (i = 0; i < size; i += 16) { - show_line(i, data + i, size - i); - } + for (i = 0; i < size; i += 16) + show = show_line(i, data + i, size - i, show); +} + +static void parse_cochran_header(const char *filename, + const unsigned char *decode, unsigned mod, + const unsigned char *in, unsigned size) +{ + char *buf = malloc(size); + + /* Do the "null decode" using a one-byte decode array of '\0' */ + partial_decode(0 , 0x0b14, "", 0, 1, in, size, buf); + + /* + * The header scrambling is different form the dive + * scrambling. Oh yay! + */ +#if 0 // Alex + partial_decode(0x058c, 0x0b14, decode, 0, mod, in, size, buf); +#else // Don + partial_decode(0x05a0, 0x0b14, decode, 0, mod, in, size, buf); +#endif + partial_decode(0x0b14, 0x1b14, decode, 0, mod, in, size, buf); + partial_decode(0x1b14, 0x2b14, decode, 0, mod, in, size, buf); + partial_decode(0x2b14, 0x3b14, decode, 0, mod, in, size, buf); + partial_decode(0x3b14, 0x5414, decode, 0, mod, in, size, buf); + partial_decode(0x5414, size, decode, 0, mod, in, size, buf); + + printf("\n%s, header\n\n", filename); + cochran_debug_write(filename, buf, size); + + free(buf); } static void parse_cochran_dive(const char *filename, int dive, @@ -150,7 +183,8 @@ static void parse_cochran_dive(const char *filename, int dive, partial_decode(0x4a14, 0xc9bd, decode, 0, mod, in, size, buf); partial_decode(0xc9bd, size, decode, 0, mod, in, size, buf); - cochran_debug_write(filename, dive, buf, size); + printf("\n%s, dive %d\n\n", filename, dive); + cochran_debug_write(filename, buf, size); free(buf); } @@ -172,6 +206,8 @@ int try_to_open_cochran(const char *filename, struct memblock *mem, GError **err mod = figure_out_modulus(decode, mem->buffer + dive1, dive2 - dive1); + parse_cochran_header(filename, decode, mod, mem->buffer + 0x40000, dive1 - 0x40000); + for (i = 0; i < 65534; i++) { dive1 = offsets[i]; dive2 = offsets[i+1]; @@ -179,7 +215,7 @@ int try_to_open_cochran(const char *filename, struct memblock *mem, GError **err break; if (dive2 > mem->size) break; - parse_cochran_dive(filename, i, decode, mod, mem->buffer + dive1, dive2 - dive1); + parse_cochran_dive(filename, i+1, decode, mod, mem->buffer + dive1, dive2 - dive1); } exit(0); |