1 | diff -Naur allegro_old\include\allegro\file.h allegro\include\allegro\file.h |
2 | --- allegro_old\include\allegro\file.h Sat Jan 22 14:41:58 2005 |
3 | +++ allegro\include\allegro\file.h Tue Apr 12 15:37:55 2005 |
4 | @@ -79,6 +79,7 @@ |
5 | #define PACKFILE_FLAG_CHUNK 4 /* file is a sub-chunk */ |
6 | #define PACKFILE_FLAG_EOF 8 /* reached the end-of-file */ |
7 | #define PACKFILE_FLAG_ERROR 16 /* an error has occurred */ |
8 | +#define PACKFILE_FLAG_OLD_CRYPT 32 /* backward compatibility mode */ |
9 | #define PACKFILE_FLAG_EXEDAT 64 /* reading from our executable */ |
10 | |
11 | |
12 | diff -Naur allegro_old\src\file.c allegro\src\file.c |
13 | --- allegro_old\src\file.c Sat Jan 22 14:42:06 2005 |
14 | +++ allegro\src\file.c Tue Apr 12 15:48:13 2005 |
15 | @@ -1638,7 +1638,50 @@ |
16 | |
17 | header = pack_mgetl(f->normal.parent); |
18 | |
19 | - if (header == encrypt_id(F_PACK_MAGIC, TRUE)) { |
20 | + if ((f->normal.parent->normal.passpos) && |
21 | + ((header == encrypt_id(F_PACK_MAGIC, FALSE)) || |
22 | + (header == encrypt_id(F_NOPACK_MAGIC, FALSE)))) { |
23 | + |
24 | + /* duplicate the file descriptor */ |
25 | + int fd2 = dup(fd); |
26 | + |
27 | + if (fd2<0) { |
28 | + pack_fclose(f->normal.parent); |
29 | + free_packfile(f); |
30 | + *allegro_errno = errno; |
31 | + return NULL; |
32 | + } |
33 | + |
34 | + /* close the parent file (logically, not physically) */ |
35 | + pack_fclose(f->normal.parent); |
36 | + |
37 | + /* backward compatibility mode */ |
38 | + if (!clone_password(f)) { |
39 | + free_packfile(f); |
40 | + return NULL; |
41 | + } |
42 | + |
43 | + f->normal.flags |= PACKFILE_FLAG_OLD_CRYPT; |
44 | + |
45 | + /* re-open the parent file */ |
46 | + lseek(fd2, 0, SEEK_SET); |
47 | + |
48 | + if ((f->normal.parent = _pack_fdopen(fd2, F_READ)) == NULL) { |
49 | + free_packfile(f); |
50 | + return NULL; |
51 | + } |
52 | + |
53 | + f->normal.parent->normal.flags |= PACKFILE_FLAG_OLD_CRYPT; |
54 | + |
55 | + pack_mgetl(f->normal.parent); |
56 | + |
57 | + if (header == encrypt_id(F_PACK_MAGIC, FALSE)) |
58 | + header = encrypt_id(F_PACK_MAGIC, TRUE); |
59 | + else |
60 | + header = encrypt_id(F_NOPACK_MAGIC, TRUE); |
61 | + } |
62 | + |
63 | + if (header == encrypt_id(F_PACK_MAGIC, TRUE)) { |
64 | f->normal.todo = LONG_MAX; |
65 | } |
66 | else if (header == encrypt_id(F_NOPACK_MAGIC, TRUE)) { |
67 | @@ -1898,6 +1941,21 @@ |
68 | chunk->normal.flags = PACKFILE_FLAG_CHUNK; |
69 | chunk->normal.parent = f; |
70 | |
71 | + if (f->normal.flags & PACKFILE_FLAG_OLD_CRYPT) { |
72 | + /* backward compatibility mode */ |
73 | + if (f->normal.passdata) { |
74 | + if ((chunk->normal.passdata = malloc(strlen(f->normal.passdata)+1)) == NULL) { |
75 | + *allegro_errno = ENOMEM; |
76 | + free(chunk); |
77 | + return NULL; |
78 | + } |
79 | + _al_sane_strncpy(chunk->normal.passdata, f->normal.passdata, strlen(f->normal.passdata)+1); |
80 | + chunk->normal.passpos = chunk->normal.passdata + (long)f->normal.passpos - (long)f->normal.passdata; |
81 | + f->normal.passpos = f->normal.passdata; |
82 | + } |
83 | + chunk->normal.flags |= PACKFILE_FLAG_OLD_CRYPT; |
84 | + } |
85 | + |
86 | if (_packfile_datasize < 0) { |
87 | /* read a packed chunk */ |
88 | chunk->normal.unpack_data = create_lzss_unpack_data(); |
89 | @@ -2009,6 +2067,9 @@ |
90 | while (f->normal.todo > 0) |
91 | pack_getc(f); |
92 | |
93 | + if ((f->normal.passpos) && (f->normal.flags & PACKFILE_FLAG_OLD_CRYPT)) |
94 | + parent->normal.passpos = parent->normal.passdata + (long)f->normal.passpos - (long)f->normal.passdata; |
95 | + |
96 | free_packfile(f); |
97 | } |
98 | |
99 | @@ -2656,7 +2717,7 @@ |
100 | sz = read(f->normal.hndl, f->normal.buf+done, f->normal.buf_size-done); |
101 | } |
102 | |
103 | - if (f->normal.passpos) { |
104 | + if ((f->normal.passpos) && (!(f->normal.flags & PACKFILE_FLAG_OLD_CRYPT))) { |
105 | for (i=0; i<f->normal.buf_size; i++) { |
106 | f->normal.buf<i> ^= *(f->normal.passpos++); |
107 | if (!*f->normal.passpos) |
108 | @@ -2698,7 +2759,7 @@ |
109 | goto Error; |
110 | } |
111 | else { |
112 | - if (f->normal.passpos) { |
113 | + if ((f->normal.passpos) && (!(f->normal.flags & PACKFILE_FLAG_OLD_CRYPT))) { |
114 | for (i=0; i<f->normal.buf_size; i++) { |
115 | f->normal.buf<i> ^= *(f->normal.passpos++); |
116 | if (!*f->normal.passpos) |
117 | @@ -3048,7 +3109,14 @@ |
118 | } |
119 | |
120 | if ((mask <<= 1) == 0) { /* shift mask left one bit */ |
121 | - for (i=0; i<code_buf_ptr; i++) /* send at most 8 units of */ |
122 | + if ((file->normal.passpos) && (file->normal.flags & PACKFILE_FLAG_OLD_CRYPT)) { |
123 | + dat->code_buf[0] ^= *file->normal.passpos; |
124 | + file->normal.passpos++; |
125 | + if (!*file->normal.passpos) |
126 | + file->normal.passpos = file->normal.passdata; |
127 | + }; |
128 | + |
129 | + for (i=0; i<code_buf_ptr; i++) /* send at most 8 units of */ |
130 | pack_putc(dat->code_buf<i>, file); /* code together */ |
131 | |
132 | if (pack_ferror(file)) { |
133 | @@ -3095,7 +3163,13 @@ |
134 | } while (len > 0); /* until length of string to be processed is zero */ |
135 | |
136 | if (code_buf_ptr > 1) { /* send remaining code */ |
137 | - for (i=0; i<code_buf_ptr; i++) { |
138 | + if ((file->normal.passpos) && (file->normal.flags & PACKFILE_FLAG_OLD_CRYPT)) { |
139 | + dat->code_buf[0] ^= *file->normal.passpos; |
140 | + file->normal.passpos++; |
141 | + if (!*file->normal.passpos) |
142 | + file->normal.passpos = file->normal.passdata; |
143 | + }; |
144 | + for (i=0; i<code_buf_ptr; i++) { |
145 | pack_putc(dat->code_buf<i>, file); |
146 | if (pack_ferror(file)) { |
147 | ret = EOF; |
148 | @@ -3186,6 +3260,13 @@ |
149 | if (((flags >>= 1) & 256) == 0) { |
150 | if ((c = pack_getc(file)) == EOF) |
151 | break; |
152 | + |
153 | + if ((file->normal.passpos) && (file->normal.flags & PACKFILE_FLAG_OLD_CRYPT)) { |
154 | + c ^= *file->normal.passpos; |
155 | + file->normal.passpos++; |
156 | + if (!*file->normal.passpos) |
157 | + file->normal.passpos = file->normal.passdata; |
158 | + }; |
159 | |
160 | flags = c | 0xFF00; /* uses higher byte to count eight */ |
161 | } |