34static unsigned char sixpack_magic[8] = {137,
'6',
'P',
'K', 13, 10, 26, 10};
36#define CUDBG_BLOCK_SIZE (63*1024)
37#define CUDBG_CHUNK_BUF_LEN 16
38#define CUDBG_MIN_COMPR_LEN 32
42#define ADLER32_BASE 65521
45 const void *buf,
int len)
47 const unsigned char *ptr = (
const unsigned char *)buf;
48 unsigned long s1 = checksum & 0xffff;
49 unsigned long s2 = (checksum >> 16) & 0xffff;
52 unsigned k = len < 5552 ? len : 5552;
56 s1 += *ptr++; s2 += s1;
57 s1 += *ptr++; s2 += s1;
58 s1 += *ptr++; s2 += s1;
59 s1 += *ptr++; s2 += s1;
60 s1 += *ptr++; s2 += s1;
61 s1 += *ptr++; s2 += s1;
62 s1 += *ptr++; s2 += s1;
63 s1 += *ptr++; s2 += s1;
68 s1 += *ptr++; s2 += s1;
73 return (s2 << 16) + s1;
91 if (*offset >= out_buf_size) {
96 memcpy((
char *)out_buf + *offset, in_buf, in_buf_size);
97 *offset = *offset + in_buf_size;
106 if (in_buf_size - *offset < out_buf_size)
109 memcpy((
char *)out_buf, (
char *)in_buf + *offset, out_buf_size);
110 *offset = *offset + out_buf_size;
115 unsigned long size,
unsigned long checksum,
121 buffer[0] =
id & 255;
122 buffer[1] = (
unsigned char)(
id >> 8);
123 buffer[2] = options & 255;
124 buffer[3] = (
unsigned char)(options >> 8);
125 buffer[4] = size & 255;
126 buffer[5] = (size >> 8) & 255;
127 buffer[6] = (size >> 16) & 255;
128 buffer[7] = (size >> 24) & 255;
129 buffer[8] = checksum & 255;
130 buffer[9] = (checksum >> 8) & 255;
131 buffer[10] = (checksum >> 16) & 255;
132 buffer[11] = (checksum >> 24) & 255;
133 buffer[12] = extra & 255;
134 buffer[13] = (extra >> 8) & 255;
135 buffer[14] = (extra >> 16) & 255;
136 buffer[15] = (extra >> 24) & 255;
148 unsigned long fsize = pin_buff->
size;
149 unsigned char *buffer;
150 unsigned long checksum;
152 char *shown_name =
"abc";
160 buffer = (
unsigned char *)tmp_buffer.
data;
168 buffer[0] = fsize & 255;
169 buffer[1] = (fsize >> 8) & 255;
170 buffer[2] = (fsize >> 16) & 255;
171 buffer[3] = (fsize >> 24) & 255;
176 buffer[8] = (strlen(shown_name)+1) & 255;
177 buffer[9] = (
unsigned char)((strlen(shown_name)+1) >> 8);
181 (
int)strlen(shown_name)+1);
184 10+(
unsigned long)strlen(shown_name)+1,
191 &(pout_buff->
offset), buffer, 10);
197 &(pout_buff->
offset), shown_name,
198 (
u32)strlen(shown_name)+1);
213 unsigned long checksum;
214 unsigned char *result;
215 unsigned int bytes_read;
216 int chunk_size, level = 2, rc = 0;
217 int compress_method = 1;
219 bytes_read = pin_buff->
size;
225 result = (
unsigned char *)tmp_buffer.
data;
232 switch (compress_method) {
250 &pout_buff->
offset, result, chunk_size);
287 unsigned char buffer[8];
292 &_c_buff->
offset, buffer, 8);
297 for (c = 0; c < 8; c++)
304static inline unsigned long readU16(
const unsigned char *ptr)
306 return ptr[0]+(ptr[1]<<8);
309static inline unsigned long readU32(
const unsigned char *ptr)
311 return ptr[0]+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
315 unsigned long *psize,
unsigned long *pchecksum,
316 unsigned long *pextra)
320 &pc_buff->
offset, buffer, 16);
324 *pid =
readU16(buffer) & 0xffff;
325 *poptions =
readU16(buffer+2) & 0xffff;
326 *psize =
readU32(buffer+4) & 0xffffffff;
327 *pchecksum =
readU32(buffer+8) & 0xffffffff;
328 *pextra =
readU32(buffer+12) & 0xffffffff;
345 unsigned char *compressed_buffer;
346 unsigned char *decompressed_buffer;
348 unsigned long chunk_size;
349 unsigned long chunk_checksum;
350 unsigned long chunk_extra;
351 unsigned long checksum;
353 unsigned long remaining;
354 unsigned long bytes_read;
355 u32 decompressed_size = 0;
356 int chunk_id, chunk_options, rc;
362 &tmp_compressed_buffer);
368 &tmp_decompressed_buffer);
372 compressed_buffer = (
unsigned char *)tmp_compressed_buffer.
data;
373 decompressed_buffer = (
unsigned char *)tmp_decompressed_buffer.
data;
382 &chunk_size, &chunk_checksum,
388 if ((chunk_id == 1) && (chunk_size > 10) &&
399 if (checksum != chunk_checksum)
404 if (pd_buff->
size < decompressed_size) {
408 pc_buff->
offset -= chunk_size + 16;
420 &tmp_compressed_buffer);
425 &tmp_decompressed_buffer);
429 compressed_buffer = (
unsigned char *)tmp_compressed_buffer.
data;
430 decompressed_buffer = (
unsigned char *)tmp_decompressed_buffer.
data;
433 if ((chunk_id == 17) && decompressed_size) {
435 switch (chunk_options) {
438 remaining = chunk_size;
460 remaining -= bytes_read;
464 if (checksum != chunk_checksum)
486 if (checksum != chunk_checksum) {
496 if (remaining != chunk_extra) {
#define CUDBG_STATUS_CHKSUM_MISSMATCH
#define CUDBG_STATUS_DECOMPRESS_FAIL
#define CUDBG_STATUS_INVALID_BUFF
#define CUDBG_STATUS_SMALL_BUFF
#define CUDBG_STATUS_OUTBUFF_OVERFLOW
int get_scratch_buff(struct cudbg_buffer *pdbg_buff, u32 size, struct cudbg_buffer *pscratch_buff)
void release_scratch_buff(struct cudbg_buffer *pscratch_buff, struct cudbg_buffer *pdbg_buff)
int fastlz_decompress(const void *input, int length, void *output, int maxout)
int fastlz_compress_level(int level, const void *input, int length, void *output)
int compress_buff(struct cudbg_buffer *pin_buff, struct cudbg_buffer *pout_buff)
int write_magic(struct cudbg_buffer *_out_buff)
#define CUDBG_MIN_COMPR_LEN
static unsigned long readU16(const unsigned char *ptr)
#define CUDBG_CHUNK_BUF_LEN
int validate_buffer(struct cudbg_buffer *compressed_buffer)
static unsigned long update_adler32(unsigned long checksum, const void *buf, int len)
static unsigned long readU32(const unsigned char *ptr)
int read_chunk_header(struct cudbg_buffer *pc_buff, int *pid, int *poptions, unsigned long *psize, unsigned long *pchecksum, unsigned long *pextra)
int write_chunk_header(struct cudbg_buffer *_outbuf, int id, int options, unsigned long size, unsigned long checksum, unsigned long extra)
static unsigned char sixpack_magic[8]
int read_from_buf(void *in_buf, u32 in_buf_size, u32 *offset, void *out_buf, u32 out_buf_size)
int detect_magic(struct cudbg_buffer *_c_buff)
int decompress_buffer(struct cudbg_buffer *pc_buff, struct cudbg_buffer *pd_buff)
int write_compression_hdr(struct cudbg_buffer *pin_buff, struct cudbg_buffer *pout_buff)
int write_to_buf(void *out_buf, u32 out_buf_size, u32 *offset, void *in_buf, u32 in_buf_size)