summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-03-22 15:53:37 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-03-22 15:53:37 +0000
commit149a7bab5bcd835a7370c3ae19a6d193a0d92e84 (patch)
tree5bc5d485ab5af86ce0a876f962ee8c9bc4874dc2
parente5b77b1a47fb99c616f3ba9045d79120fd491fab (diff)
downloadrockbox-149a7bab5bcd835a7370c3ae19a6d193a0d92e84.tar.gz
rockbox-149a7bab5bcd835a7370c3ae19a6d193a0d92e84.zip
Make Gigabeat's scramble endian-safe.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12892 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--tools/descramble.c15
-rw-r--r--tools/gigabeat.c11
-rw-r--r--tools/scramble.c7
3 files changed, 31 insertions, 2 deletions
diff --git a/tools/descramble.c b/tools/descramble.c
index c993c9f25e..9d45b8c0dc 100644
--- a/tools/descramble.c
+++ b/tools/descramble.c
@@ -26,6 +26,21 @@
26 26
27int iaudio_decode(char *iname, char *oname); 27int iaudio_decode(char *iname, char *oname);
28 28
29unsigned int le2int(unsigned char* buf)
30{
31 int32_t res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
32
33 return res;
34}
35
36void int2le(unsigned int val, unsigned char* addr)
37{
38 addr[0] = val & 0xFF;
39 addr[1] = (val >> 8) & 0xff;
40 addr[2] = (val >> 16) & 0xff;
41 addr[3] = (val >> 24) & 0xff;
42}
43
29void usage(void) 44void usage(void)
30{ 45{
31 printf("usage: descramble [options] <input file> <output file>\n"); 46 printf("usage: descramble [options] <input file> <output file>\n");
diff --git a/tools/gigabeat.c b/tools/gigabeat.c
index 863d0741f2..f4d64ea511 100644
--- a/tools/gigabeat.c
+++ b/tools/gigabeat.c
@@ -49,6 +49,7 @@ int gigabeat_code(char *infile, char *outfile)
49 FILE *in, *out; 49 FILE *in, *out;
50 unsigned long size = 0; 50 unsigned long size = 0;
51 unsigned long bytes_read; 51 unsigned long bytes_read;
52 unsigned char buf[4];
52 unsigned long data; 53 unsigned long data;
53 unsigned long key = 0x19751217; 54 unsigned long key = 0x19751217;
54 55
@@ -56,8 +57,11 @@ int gigabeat_code(char *infile, char *outfile)
56 out = openoutfile(outfile); 57 out = openoutfile(outfile);
57 58
58 while (!feof(in)) { 59 while (!feof(in)) {
59 bytes_read = fread(&data, 1, 4, in); 60 bytes_read = fread(buf, 1, 4, in);
60 61
62 /* Read in little-endian */
63 data = le2int(buf);
64
61 data = data ^ key; 65 data = data ^ key;
62 66
63 key = key + (key << 1); 67 key = key + (key << 1);
@@ -65,7 +69,10 @@ int gigabeat_code(char *infile, char *outfile)
65 69
66 size += bytes_read; 70 size += bytes_read;
67 71
68 fwrite(&data, 1, bytes_read, out); 72 /* Write out little-endian */
73 int2le(data, buf);
74
75 fwrite(buf, 1, bytes_read, out);
69 } 76 }
70 77
71 fprintf(stderr, "File processed successfully\n" ); 78 fprintf(stderr, "File processed successfully\n" );
diff --git a/tools/scramble.c b/tools/scramble.c
index 7e6ca1f51c..555bf84291 100644
--- a/tools/scramble.c
+++ b/tools/scramble.c
@@ -52,6 +52,13 @@ void short2le(unsigned short val, unsigned char* addr)
52 addr[1] = (val >> 8) & 0xff; 52 addr[1] = (val >> 8) & 0xff;
53} 53}
54 54
55unsigned int le2int(unsigned char* buf)
56{
57 int32_t res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
58
59 return res;
60}
61
55void int2le(unsigned int val, unsigned char* addr) 62void int2le(unsigned int val, unsigned char* addr)
56{ 63{
57 addr[0] = val & 0xFF; 64 addr[0] = val & 0xFF;