-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCompressUtils.xs
executable file
·330 lines (244 loc) · 8.17 KB
/
CompressUtils.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
# (C) 2003-2007 Willem Jan Hengeveld <[email protected]>
# Web: http://www.xs4all.nl/~itsme/
# http://wiki.xda-developers.com/
#
# $Id$
#
# CompressUtils - utility functions for rom compression
#
# Version: 0.10
# Date: 4 Jul 2005
# Author: Willem Hengeveld <[email protected]>
*/
#include "compress_msgs.h"
#ifdef __LP64__
#include "win32compress_client.h"
#else
#include "win32compress_loader.h"
#endif
// perl headers should be last since they define many global macro's
// confusing c++ headers
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#define CROAK croak
#pragma optimize("", off)
/*
* some Perl macros for backward compatibility
*/
#ifdef NT_BUILD_NUMBER
#define boolSV(b) ((b) ? &sv_yes : &sv_no)
#endif
#ifndef PL_na
# define PL_na na
#endif
#ifndef SvPV_nolen
# define SvPV_nolen(sv) SvPV(sv, PL_na)
#endif
#ifndef call_pv
# define call_pv(name, flags) perl_call_pv(name, flags)
#endif
#ifndef call_method
# define call_method(name, flags) perl_call_method(name, flags)
#endif
// .......................................................................
// global module context, containing functions from dynamically loaded libraries.
#define MY_CXT_KEY "XdaDevelopers::CompressUtils::_guts" XS_VERSION
typedef struct {
#ifdef __LP64__
win32compress_client client;
#else
win32compress_loader client;
#endif
} my_cxt_t;
START_MY_CXT
// .........................................................
// interface to cecompressv3.dll
//
SV* rom3compress(const unsigned char *data, int length)
{
dMY_CXT;
SV *result=NULL;
if (length==0) return &PL_sv_undef;
result= newSV(length); SvPOK_on(result); SvCUR_set(result, length);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_ROM3_ENCODE, (unsigned char*)SvPV_nolen(result), length-1, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* rom3uncompress(const unsigned char *data, int length, int outlength)
{
dMY_CXT;
SV *result=NULL;
if (length==0) return &PL_sv_undef;
result= newSV(outlength); SvPOK_on(result); SvCUR_set(result, outlength);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_ROM3_DECODE, (unsigned char*)SvPV_nolen(result), outlength, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* rom4compress(const unsigned char *data, int length)
{
dMY_CXT;
SV *result=NULL;
if (length==0) return &PL_sv_undef;
result= newSV(length); SvPOK_on(result); SvCUR_set(result, length);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_ROM4_ENCODE, (unsigned char*)SvPV_nolen(result), length-1, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* rom4uncompress(const unsigned char *data, int length, int outlength)
{
dMY_CXT;
SV *result=NULL;
if (length==0) return &PL_sv_undef;
result= newSV(outlength); SvPOK_on(result); SvCUR_set(result, outlength);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_ROM4_DECODE, (unsigned char*)SvPV_nolen(result), outlength, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* XPR_DecompressDecode(const unsigned char *data, int length, U32 outlength)
{
dMY_CXT;
SV *result= NULL;
U32 dwMaxBlockSize= 0x2000;
if (length==0) return &PL_sv_undef;
result= newSV(dwMaxBlockSize); SvPOK_on(result); SvCUR_set(result, dwMaxBlockSize);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_XPR_DECODE, (unsigned char*)SvPV_nolen(result), outlength, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* XPR_CompressEncode(const unsigned char *data, int length)
{
dMY_CXT;
SV *result= NULL;
U32 dwMaxBlockSize= 0x2000;
if (length==0) return &PL_sv_undef;
result= newSV(dwMaxBlockSize); SvPOK_on(result); SvCUR_set(result, dwMaxBlockSize);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_XPR_ENCODE, (unsigned char*)SvPV_nolen(result), length-1, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* XPH_DecompressDecode(const unsigned char *data, int length, U32 outlength)
{
dMY_CXT;
SV *result= NULL;
U32 dwMaxBlockSize= 0x2000;
if (length==0) return &PL_sv_undef;
result= newSV(dwMaxBlockSize); SvPOK_on(result); SvCUR_set(result, dwMaxBlockSize);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_XPH_DECODE, (unsigned char*)SvPV_nolen(result), outlength, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* XPH_CompressEncode(const unsigned char *data, int length)
{
dMY_CXT;
SV *result= NULL;
U32 dwMaxBlockSize= 0x2000;
if (length==0) return &PL_sv_undef;
result= newSV(dwMaxBlockSize); SvPOK_on(result); SvCUR_set(result, dwMaxBlockSize);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_XPH_ENCODE, (unsigned char*)SvPV_nolen(result), length-1, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* LZX_DecompressDecode(const unsigned char *data, int length, U32 outlength)
{
dMY_CXT;
SV *result= NULL;
U32 dwMaxBlockSize= 0x2000;
if (length==0) return &PL_sv_undef;
result= newSV(dwMaxBlockSize); SvPOK_on(result); SvCUR_set(result, dwMaxBlockSize);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_LZX_DECODE, (unsigned char*)SvPV_nolen(result), outlength, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
SV* LZX_CompressEncode(const unsigned char *data, int length)
{
dMY_CXT;
SV *result= NULL;
U32 dwMaxBlockSize= 0x2000;
if (length==0) return &PL_sv_undef;
result= newSV(dwMaxBlockSize); SvPOK_on(result); SvCUR_set(result, dwMaxBlockSize);
U32 res= MY_CXT.client.DoCompressConvert(ITSCOMP_LZX_ENCODE, (unsigned char*)SvPV_nolen(result), length-1, data, length);
if (res==0xFFFFFFFF) {
sv_setsv(result, &PL_sv_undef);
}
else {
SvCUR_set(result, res);
}
return result;
}
MODULE = XdaDevelopers::CompressUtils PACKAGE = XdaDevelopers::CompressUtils
PROTOTYPES: DISABLE
#if _WITH_LIBS
SV* romcompress_v3(unsigned char *data, int length(data))
SV* romuncompress_v3(unsigned char *data, int length(data), U32 outlength)
SV* romuncompress_v4(unsigned char *data, int length(data), U32 outlength)
SV* romuncompress_v5(unsigned char *data, int length(data), U32 outlength)
#endif
SV* rom3uncompress(unsigned char *data, int length(data), U32 outlength)
SV* rom3compress(unsigned char *data, int length(data))
SV* rom4uncompress(unsigned char *data, int length(data), U32 outlength)
SV* rom4compress(unsigned char *data, int length(data))
#if _WITH_LIBS
SV* DoCeCompressDecode(unsigned char *data, int length(data), U32 outlength)
SV* DoCeCompressEncode(unsigned char *data, int length(data))
SV* DoXpressDecode(unsigned char *data, int length(data), U32 outlength)
SV* DoXpressEncode(unsigned char *data, int length(data))
#endif
SV* XPR_DecompressDecode(unsigned char *data, int length(data), U32 outlength)
SV* XPR_CompressEncode(unsigned char *data, int length(data))
SV* XPH_DecompressDecode(unsigned char *data, int length(data), U32 outlength)
SV* XPH_CompressEncode(unsigned char *data, int length(data))
SV* LZX_DecompressDecode(unsigned char *data, int length(data), U32 outlength)
SV* LZX_CompressEncode(unsigned char *data, int length(data))
BOOT:
{
MY_CXT_INIT;
# apparently the constructor of members of 'client' is not called.
MY_CXT.client.loaddlls();
}