summaryrefslogtreecommitdiffstats
path: root/meta/recipes-bsp/zaurus-updater/encdec-updater/encdec-updater.c
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-bsp/zaurus-updater/encdec-updater/encdec-updater.c')
-rw-r--r--meta/recipes-bsp/zaurus-updater/encdec-updater/encdec-updater.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/meta/recipes-bsp/zaurus-updater/encdec-updater/encdec-updater.c b/meta/recipes-bsp/zaurus-updater/encdec-updater/encdec-updater.c
new file mode 100644
index 0000000000..b894623c65
--- /dev/null
+++ b/meta/recipes-bsp/zaurus-updater/encdec-updater/encdec-updater.c
@@ -0,0 +1,80 @@
1//
2//
3// Sharp Zaurus SL-C7x0 updater.sh script encoder/decoder
4//
5// mailto:sash@cacko.biz
6//
7//
8
9#include <stdio.h>
10
11unsigned char enctab[] = {
12 0x4a,0xf7,0x77,0x62,0xb0,0xe3,0xd8,0xf6,0xd1,0x98,0x09,0x2e,0x19,0x0c,0x0d,0x7c,
13 0x04,0xe0,0x6b,0x22,0x10,0x08,0x15,0x16,0xb9,0x28,0x83,0x1f,0x91,0x06,0xfa,0xe8,
14 0xbd,0xc6,0x21,0x32,0x23,0x6f,0x01,0x26,0x5f,0x03,0x33,0xb6,0x35,0xac,0x2d,0x0a,
15 0x6e,0x6c,0xfc,0xc4,0x29,0x34,0x2b,0x42,0x25,0x66,0xc9,0x3e,0x87,0xb4,0x74,0xf2,
16 0x11,0x20,0x41,0xb3,0x27,0x14,0xc1,0xcd,0x3d,0x80,0xd5,0x7f,0xcf,0x4c,0x4d,0xca,
17 0x75,0x51,0xc8,0xa6,0x17,0xf0,0x55,0x82,0x79,0xdc,0x59,0x5a,0x5b,0xb8,0x5d,0x40,
18 0x64,0x58,0xff,0xc5,0xab,0xc0,0xae,0xeb,0xa3,0xad,0xea,0x6a,0x37,0x3b,0x73,0x9a,
19 0x88,0x3a,0xe1,0x68,0x0b,0xec,0xc7,0x76,0xf9,0x38,0x57,0xdd,0x49,0x96,0x95,0x7a,
20 0x50,0x2a,0x4e,0xdb,0x00,0x48,0xd7,0x86,0x47,0x94,0xa0,0x1c,0x8b,0x8c,0x8d,0x92,
21 0x45,0x90,0x7e,0x56,0x93,0xef,0x1a,0x52,0x97,0xbc,0x99,0xb5,0x7d,0x72,0x9d,0x9c,
22 0xfb,0x24,0xa1,0xa2,0x07,0x46,0xa5,0x02,0x69,0xe6,0xa9,0xd3,0x30,0xba,0xd6,0x84,
23 0x63,0x13,0x1b,0xb2,0x1d,0xaf,0x36,0x8e,0xb7,0x53,0x05,0xbb,0x12,0x78,0x8f,0xbe,
24 0x71,0xbf,0xe4,0x1e,0x9e,0xa4,0xe5,0x2f,0x9b,0x31,0x67,0x4b,0xcb,0x43,0xc3,0xce,
25 0x44,0x3c,0x0f,0xd2,0xaa,0xd4,0xed,0xa7,0x7b,0x18,0xd0,0xda,0x0e,0x54,0xf1,0xde,
26 0xdf,0xa8,0x3f,0xe2,0x6d,0xcc,0xf8,0x70,0xe7,0x61,0xe9,0x85,0x65,0x2c,0x39,0xee,
27 0x60,0x81,0x89,0xc2,0xf3,0xf4,0xf5,0x8a,0x5c,0x5e,0xd9,0x4f,0x9f,0xb1,0xfd,0xfe,
28};
29
30unsigned char decode_c(unsigned char c)
31{
32 int i;
33 for (i = 0; i < 256; i++) {
34 if (c == enctab[i]) return i;
35 }
36 printf("Internal bug: encode_c()\n");
37 exit(1);
38 return 0;
39}
40
41unsigned char encode_c(unsigned char c)
42{
43 int i;
44 return enctab[c];
45}
46
47int main(int argc, char *argv[])
48{
49 int i, decode;
50 int c;
51 FILE *inf, *outf;
52 char name[256];
53
54 if (argc < 3) {
55 printf("Decode file:\n\tencsh -d file.sh\nEncode file:\n\tencsh -c file.sh\n");
56 exit(1);
57 }
58
59 if (strcmp(argv[1], "-d")) decode = 1;
60 else decode = 0;
61
62 strcpy(name, argv[2]);
63 strcat(name, ".$$$$");
64
65 inf = fopen(argv[2], "rb");
66 outf = fopen(name, "wb");
67
68 while ((c = fgetc(inf)) >= 0) {
69 if (decode) c = decode_c(c);
70 else c = encode_c(c);
71 fputc(c, outf);
72 }
73
74 fclose(inf);
75 fclose(outf);
76
77 rename(name, argv[2]);
78
79 return 0;
80}