]>
Commit | Line | Data |
---|---|---|
14c7c974 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
f083c6c3 A |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14c7c974 A |
14 | * |
15 | * The Original Code and all software distributed under the License are | |
f083c6c3 | 16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
14c7c974 A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
f083c6c3 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
14c7c974 A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | Library: compressor for executable files. | |
27 | ||
28 | R. E. Crandall, July 1995 | |
29 | ||
30 | Copyright 1995 NeXT Computer, Inc. | |
31 | All rights reserved. | |
32 | ||
33 | */ | |
34 | ||
35 | #import "rcz_common.h" | |
36 | ||
37 | static unsigned short que[QLEN]; | |
38 | ||
39 | unsigned int | |
40 | rcz_decompress_memory(unsigned char *in, unsigned char *out) | |
41 | /* Returns actual number of bytes emitted as decompressed stream 'out.' | |
42 | Note that the 'in' stream contains this byte count already. | |
43 | ||
44 | Returns -1 if the input stream was not in compressed format. | |
45 | */ | |
46 | { | |
47 | unsigned int c, j, k, jmatch, jabove; | |
f083c6c3 | 48 | int length, even_length, word, token, version; |
14c7c974 | 49 | unsigned char *outorigin = out; |
14c7c974 A |
50 | |
51 | version = *in++; | |
52 | version = (version<<8) | (*in++); | |
53 | version = (version<<8) | (*in++); | |
54 | version = (version<<8) | (*in++); | |
55 | ||
56 | if(version != METHOD_17_JUL_95) { | |
57 | return (-1); | |
58 | // fprintf(stderr, "Incompatible version.\n"); | |
59 | // return(0); | |
60 | } | |
61 | ||
62 | length = *in++; | |
63 | length = (length<<8) | (*in++); | |
64 | length = (length<<8) | (*in++); | |
65 | length = (length<<8) | (*in++); | |
66 | ||
67 | for(c=0; c < QLEN; c++) que[c] = c; | |
68 | even_length = 2*(length/2); | |
69 | while((int)(out-outorigin) < even_length) { | |
70 | token = *in++; | |
71 | token = (token<<8) | (*in++); | |
72 | token = (token<<8) | (*in++); | |
73 | token = (token<<8) | (*in++); | |
74 | c = 1<<31; | |
75 | for(k = 0; k<32; k++) { | |
76 | if(c & token) { | |
77 | jmatch = *in++; | |
78 | word = que[jmatch]; | |
79 | /* Next, dynamically process the queue for match. */ | |
80 | jabove = (F1*jmatch) >> 4; | |
81 | for(j = jmatch; j > jabove; j--) { | |
82 | que[j] = que[j-1]; | |
83 | } | |
84 | que[jabove] = word; | |
85 | } else { | |
86 | /* Next, dynamically process the queue for unmatch. */ | |
87 | word = *in++; | |
88 | word = (word << 8) | (*in++); | |
89 | for(j=QLEN-1; j > ABOVE; j--) { | |
90 | que[j] = que[j-1]; | |
91 | } | |
92 | que[ABOVE] = word; | |
93 | } | |
94 | *out++ = (word >> 8) & 0xff; | |
95 | *out++ = (word) & 0xff; | |
96 | if((int)(out-outorigin) >= even_length) break; | |
97 | c >>= 1; | |
98 | } | |
99 | } | |
100 | if(even_length != length) *out++ = *in++; | |
101 | return(length); | |
102 | } |