diff --git a/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.LZX.cs b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.LZX.cs new file mode 100644 index 00000000..4757bef4 --- /dev/null +++ b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.LZX.cs @@ -0,0 +1,431 @@ +// using static BurnOutSharp.Wrappers.CabinetConstants; +// using static BurnOutSharp.Wrappers.FDIcConstants; +// using static BurnOutSharp.Wrappers.FDIConstants; +// using cab_LONG = System.Int32; +// using cab_off_t = System.UInt32; +// using cab_UBYTE = System.Byte; +// using cab_ULONG = System.UInt32; +// using cab_UWORD = System.UInt16; + +// namespace BurnOutSharp.Wrappers +// { +// internal unsafe class LZXfdi +// { +// /************************************************************ +// * fdi_lzx_read_lens (internal) +// */ +// static int fdi_lzx_read_lens(cab_UBYTE* lens, cab_ULONG first, cab_ULONG last, struct lzx_bits *lb, +// fdi_decomp_state* decomp_state) { +// cab_ULONG i, j, x, y; +// int z; + +// register cab_ULONG bitbuf = lb->bb; +// register int bitsleft = lb->bl; +// cab_UBYTE* inpos = lb->ip; +// cab_UWORD* hufftbl; + +// for (x = 0; x< 20; x++) { +// READ_BITS(y, 4); +// LENTABLE(PRETREE)[x] = y; +// } +// BUILD_TABLE(PRETREE); + +// for (x = first; xbb = bitbuf; +// lb->bl = bitsleft; +// lb->ip = inpos; +// return 0; +// } + +// /******************************************************* +// * LZXfdi_decomp(internal) +// */ +// static int LZXfdi_decomp(int inlen, int outlen, fdi_decomp_state* decomp_state) +// { +// cab_UBYTE* inpos = CAB(inbuf); +// const cab_UBYTE* endinp = inpos + inlen; +// cab_UBYTE* window = LZX(window); +// cab_UBYTE* runsrc, *rundest; +// cab_UWORD* hufftbl; /* used in READ_HUFFSYM macro as chosen decoding table */ + +// cab_ULONG window_posn = LZX(window_posn); +// cab_ULONG window_size = LZX(window_size); +// cab_ULONG R0 = LZX(R0); +// cab_ULONG R1 = LZX(R1); +// cab_ULONG R2 = LZX(R2); + +// register cab_ULONG bitbuf; +// register int bitsleft; +// cab_ULONG match_offset, i, j, k; /* ijk used in READ_HUFFSYM macro */ +// struct lzx_bits lb; /* used in READ_LENGTHS macro */ + +// int togo = outlen, this_run, main_element, aligned_bits; +// int match_length, copy_length, length_footer, extra, verbatim_bits; + +// TRACE("(inlen == %d, outlen == %d)\n", inlen, outlen); + +// INIT_BITSTREAM; + +// /* read header if necessary */ +// if (!LZX(header_read)) +// { +// i = j = 0; +// READ_BITS(k, 1); if (k) { READ_BITS(i, 16); READ_BITS(j, 16); } +// LZX(intel_filesize) = (i << 16) | j; /* or 0 if not encoded */ +// LZX(header_read) = 1; +// } + +// /* main decoding loop */ +// while (togo > 0) +// { +// /* last block finished, new block expected */ +// if (LZX(block_remaining) == 0) +// { +// if (LZX(block_type) == LZX_BLOCKTYPE_UNCOMPRESSED) +// { +// if (LZX(block_length) & 1) inpos++; /* realign bitstream to word */ +// INIT_BITSTREAM; +// } + +// READ_BITS(LZX(block_type), 3); +// READ_BITS(i, 16); +// READ_BITS(j, 8); +// LZX(block_remaining) = LZX(block_length) = (i << 8) | j; + +// switch (LZX(block_type)) +// { +// case LZX_BLOCKTYPE_ALIGNED: +// for (i = 0; i < 8; i++) { READ_BITS(j, 3); LENTABLE(ALIGNED)[i] = j; } +// BUILD_TABLE(ALIGNED); +// /* rest of aligned header is same as verbatim */ + +// case LZX_BLOCKTYPE_VERBATIM: +// READ_LENGTHS(MAINTREE, 0, 256, fdi_lzx_read_lens); +// READ_LENGTHS(MAINTREE, 256, LZX(main_elements), fdi_lzx_read_lens); +// BUILD_TABLE(MAINTREE); +// if (LENTABLE(MAINTREE)[0xE8] != 0) LZX(intel_started) = 1; + +// READ_LENGTHS(LENGTH, 0, LZX_NUM_SECONDARY_LENGTHS, fdi_lzx_read_lens); +// BUILD_TABLE(LENGTH); +// break; + +// case LZX_BLOCKTYPE_UNCOMPRESSED: +// LZX(intel_started) = 1; /* because we can't assume otherwise */ +// ENSURE_BITS(16); /* get up to 16 pad bits into the buffer */ +// if (bitsleft > 16) inpos -= 2; /* and align the bitstream! */ +// R0 = inpos[0] | (inpos[1] << 8) | (inpos[2] << 16) | (inpos[3] << 24); inpos += 4; +// R1 = inpos[0] | (inpos[1] << 8) | (inpos[2] << 16) | (inpos[3] << 24); inpos += 4; +// R2 = inpos[0] | (inpos[1] << 8) | (inpos[2] << 16) | (inpos[3] << 24); inpos += 4; +// break; + +// default: +// return DECR_ILLEGALDATA; +// } +// } + +// /* buffer exhaustion check */ +// if (inpos > endinp) +// { +// /* it's possible to have a file where the next run is less than +// * 16 bits in size. In this case, the READ_HUFFSYM() macro used +// * in building the tables will exhaust the buffer, so we should +// * allow for this, but not allow those accidentally read bits to +// * be used (so we check that there are at least 16 bits +// * remaining - in this boundary case they aren't really part of +// * the compressed data) +// */ +// if (inpos > (endinp + 2) || bitsleft < 16) return DECR_ILLEGALDATA; +// } + +// while ((this_run = LZX(block_remaining)) > 0 && togo > 0) +// { +// if (this_run > togo) this_run = togo; +// togo -= this_run; +// LZX(block_remaining) -= this_run; + +// /* apply 2^x-1 mask */ +// window_posn &= window_size - 1; +// /* runs can't straddle the window wraparound */ +// if ((window_posn + this_run) > window_size) +// return DECR_DATAFORMAT; + +// switch (LZX(block_type)) +// { + +// case LZX_BLOCKTYPE_VERBATIM: +// while (this_run > 0) +// { +// READ_HUFFSYM(MAINTREE, main_element); + +// if (main_element < LZX_NUM_CHARS) +// { +// /* literal: 0 to LZX_NUM_CHARS-1 */ +// window[window_posn++] = main_element; +// this_run--; +// } +// else +// { +// /* match: LZX_NUM_CHARS + ((slot<<3) | length_header (3 bits)) */ +// main_element -= LZX_NUM_CHARS; + +// match_length = main_element & LZX_NUM_PRIMARY_LENGTHS; +// if (match_length == LZX_NUM_PRIMARY_LENGTHS) +// { +// READ_HUFFSYM(LENGTH, length_footer); +// match_length += length_footer; +// } +// match_length += LZX_MIN_MATCH; + +// match_offset = main_element >> 3; + +// if (match_offset > 2) +// { +// /* not repeated offset */ +// if (match_offset != 3) +// { +// extra = CAB(extra_bits)[match_offset]; +// READ_BITS(verbatim_bits, extra); +// match_offset = CAB(lzx_position_base)[match_offset] +// - 2 + verbatim_bits; +// } +// else +// { +// match_offset = 1; +// } + +// /* update repeated offset LRU queue */ +// R2 = R1; R1 = R0; R0 = match_offset; +// } +// else if (match_offset == 0) +// { +// match_offset = R0; +// } +// else if (match_offset == 1) +// { +// match_offset = R1; +// R1 = R0; R0 = match_offset; +// } +// else /* match_offset == 2 */ +// { +// match_offset = R2; +// R2 = R0; R0 = match_offset; +// } + +// rundest = window + window_posn; +// this_run -= match_length; + +// /* copy any wrapped around source data */ +// if (window_posn >= match_offset) +// { +// /* no wrap */ +// runsrc = rundest - match_offset; +// } +// else +// { +// runsrc = rundest + (window_size - match_offset); +// copy_length = match_offset - window_posn; +// if (copy_length < match_length) +// { +// match_length -= copy_length; +// window_posn += copy_length; +// while (copy_length-- > 0) *rundest++ = *runsrc++; +// runsrc = window; +// } +// } +// window_posn += match_length; + +// /* copy match data - no worries about destination wraps */ +// while (match_length-- > 0) *rundest++ = *runsrc++; +// } +// } +// break; + +// case LZX_BLOCKTYPE_ALIGNED: +// while (this_run > 0) +// { +// READ_HUFFSYM(MAINTREE, main_element); + +// if (main_element < LZX_NUM_CHARS) +// { +// /* literal: 0 to LZX_NUM_CHARS-1 */ +// window[window_posn++] = main_element; +// this_run--; +// } +// else +// { +// /* match: LZX_NUM_CHARS + ((slot<<3) | length_header (3 bits)) */ +// main_element -= LZX_NUM_CHARS; + +// match_length = main_element & LZX_NUM_PRIMARY_LENGTHS; +// if (match_length == LZX_NUM_PRIMARY_LENGTHS) +// { +// READ_HUFFSYM(LENGTH, length_footer); +// match_length += length_footer; +// } +// match_length += LZX_MIN_MATCH; + +// match_offset = main_element >> 3; + +// if (match_offset > 2) +// { +// /* not repeated offset */ +// extra = CAB(extra_bits)[match_offset]; +// match_offset = CAB(lzx_position_base)[match_offset] - 2; +// if (extra > 3) +// { +// /* verbatim and aligned bits */ +// extra -= 3; +// READ_BITS(verbatim_bits, extra); +// match_offset += (verbatim_bits << 3); +// READ_HUFFSYM(ALIGNED, aligned_bits); +// match_offset += aligned_bits; +// } +// else if (extra == 3) +// { +// /* aligned bits only */ +// READ_HUFFSYM(ALIGNED, aligned_bits); +// match_offset += aligned_bits; +// } +// else if (extra > 0) +// { /* extra==1, extra==2 */ +// /* verbatim bits only */ +// READ_BITS(verbatim_bits, extra); +// match_offset += verbatim_bits; +// } +// else /* extra == 0 */ +// { +// /* ??? */ +// match_offset = 1; +// } + +// /* update repeated offset LRU queue */ +// R2 = R1; R1 = R0; R0 = match_offset; +// } +// else if (match_offset == 0) +// { +// match_offset = R0; +// } +// else if (match_offset == 1) +// { +// match_offset = R1; +// R1 = R0; R0 = match_offset; +// } +// else /* match_offset == 2 */ +// { +// match_offset = R2; +// R2 = R0; R0 = match_offset; +// } + +// rundest = window + window_posn; +// this_run -= match_length; + +// /* copy any wrapped around source data */ +// if (window_posn >= match_offset) +// { +// /* no wrap */ +// runsrc = rundest - match_offset; +// } +// else +// { +// runsrc = rundest + (window_size - match_offset); +// copy_length = match_offset - window_posn; +// if (copy_length < match_length) +// { +// match_length -= copy_length; +// window_posn += copy_length; +// while (copy_length-- > 0) *rundest++ = *runsrc++; +// runsrc = window; +// } +// } +// window_posn += match_length; + +// /* copy match data - no worries about destination wraps */ +// while (match_length-- > 0) *rundest++ = *runsrc++; +// } +// } +// break; + +// case LZX_BLOCKTYPE_UNCOMPRESSED: +// if ((inpos + this_run) > endinp) return DECR_ILLEGALDATA; +// memcpy(window + window_posn, inpos, (size_t)this_run); +// inpos += this_run; window_posn += this_run; +// break; + +// default: +// return DECR_ILLEGALDATA; /* might as well */ +// } + +// } +// } + +// if (togo != 0) return DECR_ILLEGALDATA; +// memcpy(CAB(outbuf), window + ((!window_posn) ? window_size : window_posn) - +// outlen, (size_t)outlen); + +// LZX(window_posn) = window_posn; +// LZX(R0) = R0; +// LZX(R1) = R1; +// LZX(R2) = R2; + +// /* intel E8 decoding */ +// if ((LZX(frames_read)++ < 32768) && LZX(intel_filesize) != 0) +// { +// if (outlen <= 6 || !LZX(intel_started)) +// { +// LZX(intel_curpos) += outlen; +// } +// else +// { +// cab_UBYTE* data = CAB(outbuf); +// cab_UBYTE* dataend = data + outlen - 10; +// cab_LONG curpos = LZX(intel_curpos); +// cab_LONG filesize = LZX(intel_filesize); +// cab_LONG abs_off, rel_off; + +// LZX(intel_curpos) = curpos + outlen; + +// while (data < dataend) +// { +// if (*data++ != 0xE8) { curpos++; continue; } +// abs_off = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); +// if ((abs_off >= -curpos) && (abs_off < filesize)) +// { +// rel_off = (abs_off >= 0) ? abs_off - curpos : abs_off + filesize; +// data[0] = (cab_UBYTE)rel_off; +// data[1] = (cab_UBYTE)(rel_off >> 8); +// data[2] = (cab_UBYTE)(rel_off >> 16); +// data[3] = (cab_UBYTE)(rel_off >> 24); +// } +// data += 4; +// curpos += 5; +// } +// } +// } +// return DECR_OK; +// } +// } +// } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.MSZIP.cs b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.MSZIP.cs new file mode 100644 index 00000000..1bfb8769 --- /dev/null +++ b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.MSZIP.cs @@ -0,0 +1,611 @@ +// using static BurnOutSharp.Wrappers.CabinetConstants; +// using static BurnOutSharp.Wrappers.FDIcConstants; +// using static BurnOutSharp.Wrappers.FDIConstants; +// using cab_LONG = System.Int32; +// using cab_off_t = System.UInt32; +// using cab_UBYTE = System.Byte; +// using cab_ULONG = System.UInt32; +// using cab_UWORD = System.UInt16; + +// namespace BurnOutSharp.Wrappers +// { +// internal unsafe class MSZIPfdi +// { +// /// +// /// Ziphuft_free (internal) +// /// +// static void fdi_Ziphuft_free(FDI_Int fdi, Ziphuft t) +// { +// // No-op because of garbage collection +// } + +// /// +// /// fdi_Ziphuft_build (internal) +// /// +// static cab_LONG fdi_Ziphuft_build(cab_ULONG* b, cab_ULONG n, cab_ULONG s, cab_UWORD* d, cab_UWORD* e, ref Ziphuft[] t, cab_LONG* m, fdi_decomp_state decomp_state) +// { +// cab_ULONG a; /* counter for codes of length k */ +// cab_ULONG el; /* length of EOB code (value 256) */ +// cab_ULONG f; /* i repeats in table every f entries */ +// cab_LONG g; /* maximum code length */ +// cab_LONG h; /* table level */ +// cab_ULONG i; /* counter, current code */ +// cab_ULONG j; /* counter */ +// cab_LONG k; /* number of bits in current code */ +// cab_LONG* l; /* stack of bits per table */ +// cab_ULONG* p; /* pointer into decomp_state.zip.c[],decomp_state.zip.b[],decomp_state.zip.v[] */ +// Ziphuft* q; /* points to current table */ +// Ziphuft r; /* table entry for structure assignment */ +// cab_LONG w; /* bits before this table == (l * h) */ +// cab_ULONG* xp; /* pointer into x */ +// cab_LONG y; /* number of dummy codes added */ +// cab_ULONG z; /* number of entries in current table */ + +// l = decomp_state.zip.lx + 1; + +// // Generate counts for each bit length +// // set length of EOB code, if any +// el = n > 256 ? b[256] : ZIPBMAX; + +// for (i = 0; i < ZIPBMAX + 1; ++i) +// { +// decomp_state.zip.c[i] = 0; +// } + +// p = b; i = n; + +// // assume all entries <= ZIPBMAX +// do +// { +// decomp_state.zip.c[*p]++; p++; +// } while (--i != 0); + +// // null input--all zero length codes +// if (decomp_state.zip.c[0] == n) +// { +// t = null; +// *m = 0; +// return 0; +// } + +// // Find minimum and maximum length, bound *m by those +// for (j = 1; j <= ZIPBMAX; j++) +// { +// if (decomp_state.zip.c[j] != 0) +// break; +// } + +// // minimum code length +// k = (int)j; +// if (*m < j) +// *m = (int)j; + +// for (i = ZIPBMAX; i != 0; i--) +// { +// if (decomp_state.zip.c[i] != 0) +// break; +// } + +// // maximum code length +// g = (int)i; +// if (*m > i) +// *m = (int)i; + +// // Adjust last length count to fill out codes, if needed */ +// for (y = 1 << (int)j; j < i; j++, y <<= 1) +// { +// // bad input: more codes than bits +// if ((y -= (int)decomp_state.zip.c[j]) < 0) +// return 2; +// } + +// if ((y -= (int)decomp_state.zip.c[i]) < 0) +// return 2; + +// decomp_state.zip.c[i] += (uint)y; + +// // Generate starting offsets LONGo the value table for each length +// decomp_state.zip.x[1] = j = 0; +// p = decomp_state.zip.c + 1; xp = decomp_state.zip.x + 2; +// while (--i != 0) +// { +// // note that i == g from above +// *xp++ = (j += *p++); +// } + +// /* Make a table of values in order of bit lengths */ +// p = b; i = 0; +// do +// { +// if ((j = *p++) != 0) +// decomp_state.zip.v[decomp_state.zip.x[j]++] = i; +// } while (++i < n); + +// // Generate the Huffman codes and for each, make the table entries +// decomp_state.zip.x[0] = i = 0; /* first Huffman code is zero */ +// p = decomp_state.zip.v; /* grab values in bit order */ +// h = -1; /* no tables yet--level -1 */ +// w = l[-1] = 0; /* no bits decoded yet */ +// decomp_state.zip.u[0] = null; /* just to keep compilers happy */ +// q = null; /* ditto */ +// z = 0; /* ditto */ + +// /* go through the bit lengths (k already is bits in shortest code) */ +// for (; k <= g; k++) +// { +// a = decomp_state.zip.c[k]; +// while (a-- != 0) +// { +// // here i is the Huffman code of length k bits for value *p +// // make tables up to required level +// while (k > w + l[h]) +// { +// // add bits already decoded +// w += l[h++]; + +// // compute minimum size table less than or equal to *m bits +// if ((z = (uint)(g - w)) > *m) /* upper limit */ +// z = (uint)*m; + +// // try a k-w bit table +// if ((f = (uint)(1 << (int)(j = (uint)(k - w)))) > a + 1) +// { /* too few codes for k-w bit table */ +// f -= a + 1; /* deduct codes from patterns left */ +// xp = decomp_state.zip.c + k; +// while (++j < z) /* try smaller tables up to z bits */ +// { +// if ((f <<= 1) <= *++xp) +// break; /* enough codes to use up j bits */ +// f -= *xp; /* else deduct codes from patterns */ +// } +// } + +// if ((cab_ULONG)w + j > el && (cab_ULONG)w < el) +// j = el - w; /* make EOB code end at table */ + +// z = 1 << j; /* table entries for j-bit table */ +// l[h] = j; /* set table size in stack */ + +// /* allocate and link in new table */ +// if (!(q = decomp_state.fdi.alloc((z + 1) * sizeof(Ziphuft)))) +// { +// if (h) +// fdi_Ziphuft_free(decomp_state.fdi, decomp_state.zip.u[0]); +// return 3; /* not enough memory */ +// } + +// *t = q + 1; /* link to list for Ziphuft_free() */ +// *(t = &(q.v.t)) = null; +// decomp_state.zip.u[h] = ++q; /* table starts after link */ + +// // connect to last table, if there is one +// if (h != 0) +// { +// decomp_state.zip.x[h] = i; /* save pattern for backing up */ +// r.b = (cab_UBYTE)l[h - 1]; /* bits to dump before this table */ +// r.e = (cab_UBYTE)(16 + j); /* bits in this table */ +// r.t = q; /* pointer to this table */ +// j = (i & ((1 << w) - 1)) >> (w - l[h - 1]); +// decomp_state.zip.u[h - 1][j] = r; /* connect to last table */ +// } +// } + +// /* set up table entry in r */ +// r.b = (cab_UBYTE)(k - w); +// if (p >= decomp_state.zip.v + n) +// { +// r.e = 99; /* out of values--invalid code */ +// } +// else if (*p < s) +// { +// r.e = (cab_UBYTE)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */ +// r.n = *p++; /* simple code is just the value */ +// } +// else +// { +// r.e = (cab_UBYTE)e[*p - s]; /* non-simple--look up in lists */ +// r.n = d[*p++ - s]; +// } + +// /* fill code-like entries with r */ +// f = 1 << (k - w); +// for (j = i >> w; j < z; j += f) +// q[j] = r; + +// /* backwards increment the k-bit code i */ +// for (j = 1 << (k - 1); i & j; j >>= 1) +// i ^= j; +// i ^= j; + +// /* backup over finished tables */ +// while ((i & ((1 << w) - 1)) != decomp_state.zip.x[h]) +// w -= l[--h]; /* don't need to update q */ +// } +// } + +// /* return actual size of base table */ +// *m = l[0]; + +// /* Return true (1) if we were given an incomplete table */ +// return y != 0 && g != 1; +// } + +// /// +// /// fdi_Zipinflate_codes (internal) +// /// +// static cab_LONG fdi_Zipinflate_codes(in Ziphuft tl, in Ziphuft td, cab_LONG bl, cab_LONG bd, fdi_decomp_state decomp_state) +// { +// cab_ULONG e; /* table entry flag/number of extra bits */ +// cab_ULONG n, d; /* length and index for copy */ +// cab_ULONG w; /* current window position */ +// Ziphuft t; /* pointer to table entry */ +// cab_ULONG ml, md; /* masks for bl and bd bits */ +// cab_ULONG b; /* bit buffer */ +// cab_ULONG k; /* number of bits in bit buffer */ + +// /* make local copies of globals */ +// b = decomp_state.zip.bb; /* initialize bit buffer */ +// k = decomp_state.zip.bk; +// w = decomp_state.zip.window_posn; /* initialize window position */ + +// /* inflate the coded data */ +// ml = Zipmask[bl]; /* precompute masks for speed */ +// md = Zipmask[bd]; + +// for (; ; ) +// { +// ZIPNEEDBITS((cab_ULONG)bl) +// if ((e = (t = tl + (b & ml)).e) > 16) +// do +// { +// if (e == 99) +// return 1; +// ZIPDUMPBITS(t.b) +// e -= 16; +// ZIPNEEDBITS(e) +// } while ((e = (t = t.v.t + (b & Zipmask[e])).e) > 16); +// ZIPDUMPBITS(t.b) +// if (e == 16) /* then it's a literal */ +// decomp_state.outbuf[w++] = (cab_UBYTE)t.v.n; +// else /* it's an EOB or a length */ +// { +// /* exit if end of block */ +// if (e == 15) +// break; + +// /* get length of block to copy */ +// ZIPNEEDBITS(e) +// n = t.v.n + (b & Zipmask[e]); +// ZIPDUMPBITS(e); + +// /* decode distance of block to copy */ +// ZIPNEEDBITS((cab_ULONG)bd) +// if ((e = (t = td + (b & md)).e) > 16) +// do +// { +// if (e == 99) +// return 1; +// ZIPDUMPBITS(t.b) +// e -= 16; +// ZIPNEEDBITS(e) +// } while ((e = (t = t.v.t + (b & Zipmask[e])).e) > 16); +// ZIPDUMPBITS(t.b) +// ZIPNEEDBITS(e) +// d = w - t.v.n - (b & Zipmask[e]); +// ZIPDUMPBITS(e) +// do +// { +// d &= ZIPWSIZE - 1; +// e = ZIPWSIZE - max(d, w); +// e = min(e, n); +// n -= e; +// do +// { +// decomp_state.outbuf[w++] = decomp_state.outbuf[d++]; +// } while (--e); +// } while (n); +// } +// } + +// /* restore the globals from the locals */ +// decomp_state.zip.window_posn = w; /* restore global window pointer */ +// decomp_state.zip.bb = b; /* restore global bit buffer */ +// decomp_state.zip.bk = k; + +// /* done */ +// return 0; +// } + +// /// +// /// Zipinflate_stored (internal) +// /// +// /// "decompress" an inflated type 0 (stored) block. +// /// +// static cab_LONG fdi_Zipinflate_stored(fdi_decomp_state decomp_state) +// { +// cab_ULONG n; /* number of bytes in block */ +// cab_ULONG w; /* current window position */ +// cab_ULONG b; /* bit buffer */ +// cab_ULONG k; /* number of bits in bit buffer */ + +// /* make local copies of globals */ +// b = decomp_state.zip.bb; /* initialize bit buffer */ +// k = decomp_state.zip.bk; +// w = decomp_state.zip.window_posn; /* initialize window position */ + +// /* go to byte boundary */ +// n = k & 7; +// ZIPDUMPBITS(n); + +// /* get the length and its complement */ +// ZIPNEEDBITS(16) +// n = (b & 0xffff); +// ZIPDUMPBITS(16) +// ZIPNEEDBITS(16) +// if (n != ((~b) & 0xffff)) +// return 1; /* error in compressed data */ +// ZIPDUMPBITS(16) + +// /* read and output the compressed data */ +// while (n--) +// { +// ZIPNEEDBITS(8) +// decomp_state.outbuf[w++] = (cab_UBYTE)b; +// ZIPDUMPBITS(8) +// } + +// /* restore the globals from the locals */ +// decomp_state.zip.window_posn = w; /* restore global window pointer */ +// decomp_state.zip.bb = b; /* restore global bit buffer */ +// decomp_state.zip.bk = k; +// return 0; +// } + +// /// +// /// fdi_Zipinflate_fixed (internal) +// /// +// static cab_LONG fdi_Zipinflate_fixed(fdi_decomp_state decomp_state) +// { +// Ziphuft fixed_tl; +// Ziphuft fixed_td; +// cab_LONG fixed_bl, fixed_bd; +// cab_LONG i; /* temporary variable */ +// cab_ULONG* l; + +// l = decomp_state.zip.ll; + +// /* literal table */ +// for (i = 0; i < 144; i++) +// l[i] = 8; +// for (; i < 256; i++) +// l[i] = 9; +// for (; i < 280; i++) +// l[i] = 7; +// for (; i < 288; i++) /* make a complete, but wrong code set */ +// l[i] = 8; +// fixed_bl = 7; +// if ((i = fdi_Ziphuft_build(l, 288, 257, Zipcplens, Zipcplext, &fixed_tl, &fixed_bl, decomp_state))) +// return i; + +// /* distance table */ +// for (i = 0; i < 30; i++) /* make an incomplete code set */ +// l[i] = 5; +// fixed_bd = 5; +// if ((i = fdi_Ziphuft_build(l, 30, 0, Zipcpdist, Zipcpdext, &fixed_td, &fixed_bd, decomp_state)) > 1) +// { +// fdi_Ziphuft_free(decomp_state.fdi, fixed_tl); +// return i; +// } + +// /* decompress until an end-of-block code */ +// i = fdi_Zipinflate_codes(fixed_tl, fixed_td, fixed_bl, fixed_bd, decomp_state); + +// fdi_Ziphuft_free(decomp_state.fdi, fixed_td); +// fdi_Ziphuft_free(decomp_state.fdi, fixed_tl); +// return i; +// } + +// /// +// /// fdi_Zipinflate_dynamic (internal) +// /// +// /// decompress an inflated type 2 (dynamic Huffman codes) block. +// /// +// static cab_LONG fdi_Zipinflate_dynamic(fdi_decomp_state decomp_state) +// { +// cab_LONG i; /* temporary variables */ +// cab_ULONG j; +// cab_ULONG* ll; +// cab_ULONG l; /* last length */ +// cab_ULONG m; /* mask for bit lengths table */ +// cab_ULONG n; /* number of lengths to get */ +// Ziphuft tl; /* literal/length code table */ +// Ziphuft td; /* distance code table */ +// cab_LONG bl; /* lookup bits for tl */ +// cab_LONG bd; /* lookup bits for td */ +// cab_ULONG nb; /* number of bit length codes */ +// cab_ULONG nl; /* number of literal/length codes */ +// cab_ULONG nd; /* number of distance codes */ +// cab_ULONG b; /* bit buffer */ +// cab_ULONG k; /* number of bits in bit buffer */ + +// /* make local bit buffer */ +// b = decomp_state.zip.bb; +// k = decomp_state.zip.bk; +// ll = decomp_state.zip.ll; + +// /* read in table lengths */ +// ZIPNEEDBITS(5) +// nl = 257 + (b & 0x1f); /* number of literal/length codes */ +// ZIPDUMPBITS(5) +// ZIPNEEDBITS(5) +// nd = 1 + (b & 0x1f); /* number of distance codes */ +// ZIPDUMPBITS(5) +// ZIPNEEDBITS(4) +// nb = 4 + (b & 0xf); /* number of bit length codes */ +// ZIPDUMPBITS(4) +// if (nl > 288 || nd > 32) +// return 1; /* bad lengths */ + +// /* read in bit-length-code lengths */ +// for (j = 0; j < nb; j++) +// { +// ZIPNEEDBITS(3) +// ll[Zipborder[j]] = b & 7; +// ZIPDUMPBITS(3) +// } +// for (; j < 19; j++) +// ll[Zipborder[j]] = 0; + +// /* build decoding table for trees--single level, 7 bit lookup */ +// bl = 7; +// if ((i = fdi_Ziphuft_build(ll, 19, 19, null, null, &tl, &bl, decomp_state)) != 0) +// { +// if (i == 1) +// fdi_Ziphuft_free(decomp_state.fdi, tl); +// return i; /* incomplete code set */ +// } + +// /* read in literal and distance code lengths */ +// n = nl + nd; +// m = Zipmask[bl]; +// i = l = 0; +// while ((cab_ULONG)i < n) +// { +// ZIPNEEDBITS((cab_ULONG)bl) +// j = (td = tl + (b & m)).b; +// ZIPDUMPBITS(j) +// j = td.v.n; +// if (j < 16) /* length of code in bits (0..15) */ +// ll[i++] = l = j; /* save last length in l */ +// else if (j == 16) /* repeat last length 3 to 6 times */ +// { +// ZIPNEEDBITS(2) +// j = 3 + (b & 3); +// ZIPDUMPBITS(2) +// if ((cab_ULONG)i + j > n) +// return 1; +// while (j--) +// ll[i++] = l; +// } +// else if (j == 17) /* 3 to 10 zero length codes */ +// { +// ZIPNEEDBITS(3) +// j = 3 + (b & 7); +// ZIPDUMPBITS(3) +// if ((cab_ULONG)i + j > n) +// return 1; +// while (j--) +// ll[i++] = 0; +// l = 0; +// } +// else /* j == 18: 11 to 138 zero length codes */ +// { +// ZIPNEEDBITS(7) +// j = 11 + (b & 0x7f); +// ZIPDUMPBITS(7) +// if ((cab_ULONG)i + j > n) +// return 1; +// while (j--) +// ll[i++] = 0; +// l = 0; +// } +// } + +// /* free decoding table for trees */ +// fdi_Ziphuft_free(decomp_state.fdi, tl); + +// /* restore the global bit buffer */ +// decomp_state.zip.bb = b; +// decomp_state.zip.bk = k; + +// /* build the decoding tables for literal/length and distance codes */ +// bl = ZIPLBITS; +// if ((i = fdi_Ziphuft_build(ll, nl, 257, Zipcplens, Zipcplext, &tl, &bl, decomp_state)) != 0) +// { +// if (i == 1) +// fdi_Ziphuft_free(decomp_state.fdi, tl); +// return i; /* incomplete code set */ +// } +// bd = ZIPDBITS; +// fdi_Ziphuft_build(ll + nl, nd, 0, Zipcpdist, Zipcpdext, &td, &bd, decomp_state); + +// /* decompress until an end-of-block code */ +// if (fdi_Zipinflate_codes(tl, td, bl, bd, decomp_state)) +// return 1; + +// /* free the decoding tables, return */ +// fdi_Ziphuft_free(decomp_state.fdi, tl); +// fdi_Ziphuft_free(decomp_state.fdi, td); +// return 0; +// } + +// /// +// /// fdi_Zipinflate_block (internal) +// /// +// /// decompress an inflated block +// /// +// static cab_LONG fdi_Zipinflate_block(cab_LONG* e, fdi_decomp_state decomp_state) /* e == last block flag */ +// { +// cab_ULONG t; /* block type */ +// cab_ULONG b; /* bit buffer */ +// cab_ULONG k; /* number of bits in bit buffer */ + +// /* make local bit buffer */ +// b = decomp_state.zip.bb; +// k = decomp_state.zip.bk; + +// /* read in last block bit */ +// ZIPNEEDBITS(1) +// * e = (cab_LONG)b & 1; +// ZIPDUMPBITS(1) + +// /* read in block type */ +// ZIPNEEDBITS(2) +// t = b & 3; +// ZIPDUMPBITS(2) + +// /* restore the global bit buffer */ +// decomp_state.zip.bb = b; +// decomp_state.zip.bk = k; + +// /* inflate that block type */ +// if (t == 2) +// return fdi_Zipinflate_dynamic(decomp_state); +// if (t == 0) +// return fdi_Zipinflate_stored(decomp_state); +// if (t == 1) +// return fdi_Zipinflate_fixed(decomp_state); +// /* bad block type */ +// return 2; +// } + +// /// +// /// ZIPfdi_decomp(internal) +// /// +// static int ZIPfdi_decomp(int inlen, int outlen, fdi_decomp_state decomp_state) +// { +// cab_LONG e; /* last block flag */ + +// TRACE("(inlen == %d, outlen == %d)\n", inlen, outlen); + +// decomp_state.zip.inpos = decomp_state.inbuf; +// decomp_state.zip.bb = decomp_state.zip.bk = decomp_state.zip.window_posn = 0; +// if (outlen > ZIPWSIZE) +// return DECR_DATAFORMAT; + +// /* CK = Chris Kirmse, official Microsoft purloiner */ +// if (decomp_state.zip.inpos[0] != 0x43 || decomp_state.zip.inpos[1] != 0x4B) +// return DECR_ILLEGALDATA; +// decomp_state.zip.inpos += 2; + +// do +// { +// if (fdi_Zipinflate_block(&e, decomp_state)) +// return DECR_ILLEGALDATA; +// } while (!e); + +// /* return success */ +// return DECR_OK; +// } +// } +// } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.Quantum.cs b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.Quantum.cs new file mode 100644 index 00000000..7fa1d293 --- /dev/null +++ b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.Quantum.cs @@ -0,0 +1,290 @@ +// using static BurnOutSharp.Wrappers.CabinetConstants; +// using static BurnOutSharp.Wrappers.FDIcConstants; +// using static BurnOutSharp.Wrappers.FDIConstants; +// using cab_LONG = System.Int32; +// using cab_off_t = System.UInt32; +// using cab_UBYTE = System.Byte; +// using cab_ULONG = System.UInt32; +// using cab_UWORD = System.UInt16; + +// namespace BurnOutSharp.Wrappers +// { +// internal unsafe class Quantumfdi +// { +// /// +// /// QTMupdatemodel (internal) +// /// +// internal static void QTMupdatemodel(QTMmodel model, int sym) +// { +// for (int i = 0; i < sym; i++) +// { +// model.syms[i].cumfreq += 8; +// } + +// if (model.syms[0].cumfreq > 3800) +// { +// if (--model.shiftsleft != 0) +// { +// for (int i = model.entries - 1; i >= 0; i--) +// { +// // -1, not -2; the 0 entry saves this +// model.syms[i].cumfreq >>= 1; +// if (model.syms[i].cumfreq <= model.syms[i + 1].cumfreq) +// model.syms[i].cumfreq = (ushort)(model.syms[i + 1].cumfreq + 1); +// } +// } +// else +// { +// model.shiftsleft = 50; +// for (int i = 0; i < model.entries; i++) +// { +// // no -1, want to include the 0 entry +// // this converts cumfreqs into frequencies, then shifts right +// model.syms[i].cumfreq -= model.syms[i + 1].cumfreq; +// model.syms[i].cumfreq++; /* avoid losing things entirely */ +// model.syms[i].cumfreq >>= 1; +// } + +// // Now sort by frequencies, decreasing order -- this must be an +// // inplace selection sort, or a sort with the same (in)stability +// // characteristics +// for (int i = 0; i < model.entries - 1; i++) +// { +// for (int j = i + 1; j < model.entries; j++) +// { +// if (model.syms[i].cumfreq < model.syms[j].cumfreq) +// { +// QTMmodelsym temp = model.syms[i]; +// model.syms[i] = model.syms[j]; +// model.syms[j] = temp; +// } +// } +// } + +// // Then convert frequencies back to cumfreq +// for (int i = model.entries - 1; i >= 0; i--) +// { +// model.syms[i].cumfreq += model.syms[i + 1].cumfreq; +// } + +// // Then update the other part of the table +// for (int i = 0; i < model.entries; i++) +// { +// model.tabloc[model.syms[i].sym] = (ushort)i; +// } +// } +// } +// } + +// /// +// /// QTMfdi_initmodel (internal) +// /// +// /// Initialize a model which decodes symbols from [s] to [s]+[n]-1 +// /// +// internal static void QTMfdi_initmodel(QTMmodel m, QTMmodelsym[] sym, int n, int s) +// { +// int i; +// m.shiftsleft = 4; +// m.entries = n; +// m.syms = sym; +// memset(m.tabloc, 0xFF, sizeof(m.tabloc)); /* clear out look-up table */ +// for (i = 0; i < n; i++) +// { +// m.tabloc[i + s] = (ushort)i; /* set up a look-up entry for symbol */ +// m.syms[i].sym = (ushort)(i + s); /* actual symbol */ +// m.syms[i].cumfreq = (ushort)(n - i); /* current frequency of that symbol */ +// } +// m.syms[n].cumfreq = 0; +// } + +// /// +// /// QTMfdi_init (internal) +// /// +// internal static int QTMfdi_init(int window, int level, fdi_decomp_state decomp_state) +// { +// uint wndsize = (uint)(1 << window); +// int msz = window * 2, i; +// uint j; + +// /* QTM supports window sizes of 2^10 (1Kb) through 2^21 (2Mb) */ +// /* if a previously allocated window is big enough, keep it */ +// if (window < 10 || window > 21) return DECR_DATAFORMAT; +// if (decomp_state.qtm.actual_size < wndsize) +// { +// if (decomp_state.qtm.window != null) decomp_state.fdi.free(decomp_state.qtm.window); +// decomp_state.qtm.window = null; +// } +// if (decomp_state.qtm.window == null) +// { +// if ((decomp_state.qtm.window = decomp_state.fdi.alloc((int)wndsize)) == null) return DECR_NOMEMORY; +// decomp_state.qtm.actual_size = wndsize; +// } +// decomp_state.qtm.window_size = wndsize; +// decomp_state.qtm.window_posn = 0; + +// /* initialize static slot/extrabits tables */ +// for (i = 0, j = 0; i < 27; i++) +// { +// decomp_state.q_length_extra[i] = (byte)((i == 26) ? 0 : (i < 2 ? 0 : i - 2) >> 2); +// decomp_state.q_length_base[i] = (byte)j; j += (uint)(1 << ((i == 26) ? 5 : decomp_state.q_length_extra[i])); +// } +// for (i = 0, j = 0; i < 42; i++) +// { +// decomp_state.q_extra_bits[i] = (byte)((i < 2 ? 0 : i - 2) >> 1); +// decomp_state.q_position_base[i] = j; j += (uint)(1 << decomp_state.q_extra_bits[i]); +// } + +// /* initialize arithmetic coding models */ + +// QTMfdi_initmodel(decomp_state.qtm.model7, decomp_state.qtm.m7sym, 7, 0); + +// QTMfdi_initmodel(decomp_state.qtm.model00, decomp_state.qtm.m00sym, 0x40, 0x00); +// QTMfdi_initmodel(decomp_state.qtm.model40, decomp_state.qtm.m40sym, 0x40, 0x40); +// QTMfdi_initmodel(decomp_state.qtm.model80, decomp_state.qtm.m80sym, 0x40, 0x80); +// QTMfdi_initmodel(decomp_state.qtm.modelC0, decomp_state.qtm.mC0sym, 0x40, 0xC0); + +// /* model 4 depends on table size, ranges from 20 to 24 */ +// QTMfdi_initmodel(decomp_state.qtm.model4, decomp_state.qtm.m4sym, (msz < 24) ? msz : 24, 0); +// /* model 5 depends on table size, ranges from 20 to 36 */ +// QTMfdi_initmodel(decomp_state.qtm.model5, decomp_state.qtm.m5sym, (msz < 36) ? msz : 36, 0); +// /* model 6pos depends on table size, ranges from 20 to 42 */ +// QTMfdi_initmodel(decomp_state.qtm.model6pos, decomp_state.qtm.m6psym, msz, 0); +// QTMfdi_initmodel(decomp_state.qtm.model6len, decomp_state.qtm.m6lsym, 27, 0); + +// return DECR_OK; +// } + +// /// +// /// QTMfdi_decomp(internal) +// /// +// internal static int QTMfdi_decomp(int inlen, int outlen, fdi_decomp_state decomp_state) +// { +// cab_UBYTE* inpos = decomp_state.inbuf; +// cab_UBYTE* window = decomp_state.qtm.window; +// cab_UBYTE* runsrc, rundest; +// cab_ULONG window_posn = decomp_state.qtm.window_posn; +// cab_ULONG window_size = decomp_state.qtm.window_size; + +// /* used by bitstream macros */ +// int bitsleft, bitrun, bitsneed; +// cab_ULONG bitbuf; + +// /* used by GET_SYMBOL */ +// cab_ULONG range; +// cab_UWORD symf; +// int i; + +// int extra, togo = outlen, match_length = 0, copy_length; +// cab_UBYTE selector, sym; +// cab_ULONG match_offset = 0; + +// cab_UWORD H = 0xFFFF, L = 0, C; + +// System.Diagnostics.Debug.WriteLine("(inlen == %d, outlen == %d)\n", inlen, outlen); + +// /* read initial value of C */ +// Q_INIT_BITSTREAM; +// Q_READ_BITS(C, 16); + +// /* apply 2^x-1 mask */ +// window_posn &= window_size - 1; +// /* runs can't straddle the window wraparound */ +// if ((window_posn + togo) > window_size) +// { +// System.Diagnostics.Debug.WriteLine("straddled run\n"); +// return DECR_DATAFORMAT; +// } + +// while (togo > 0) +// { +// GET_SYMBOL(model7, selector); +// switch (selector) +// { +// case 0: +// GET_SYMBOL(model00, sym); window[window_posn++] = sym; togo--; +// break; +// case 1: +// GET_SYMBOL(model40, sym); window[window_posn++] = sym; togo--; +// break; +// case 2: +// GET_SYMBOL(model80, sym); window[window_posn++] = sym; togo--; +// break; +// case 3: +// GET_SYMBOL(modelC0, sym); window[window_posn++] = sym; togo--; +// break; + +// case 4: +// /* selector 4 = fixed length of 3 */ +// GET_SYMBOL(model4, sym); +// Q_READ_BITS(extra, decomp_state.q_extra_bits[sym]); +// match_offset = decomp_state.q_position_base[sym] + extra + 1; +// match_length = 3; +// break; + +// case 5: +// /* selector 5 = fixed length of 4 */ +// GET_SYMBOL(model5, sym); +// Q_READ_BITS(extra, decomp_state.q_extra_bits[sym]); +// match_offset = decomp_state.q_position_base[sym] + extra + 1; +// match_length = 4; +// break; + +// case 6: +// /* selector 6 = variable length */ +// GET_SYMBOL(model6len, sym); +// Q_READ_BITS(extra, decomp_state.q_length_extra[sym]); +// match_length = decomp_state.q_length_base[sym] + extra + 5; +// GET_SYMBOL(model6pos, sym); +// Q_READ_BITS(extra, decomp_state.q_extra_bits[sym]); +// match_offset = decomp_state.q_position_base[sym] + extra + 1; +// break; + +// default: +// System.Diagnostics.Debug.WriteLine("Selector is bogus\n"); +// return DECR_ILLEGALDATA; +// } + +// /* if this is a match */ +// if (selector >= 4) +// { +// rundest = window + window_posn; +// togo -= match_length; + +// /* copy any wrapped around source data */ +// if (window_posn >= match_offset) +// { +// /* no wrap */ +// runsrc = rundest - match_offset; +// } +// else +// { +// runsrc = rundest + (window_size - match_offset); +// copy_length = match_offset - window_posn; +// if (copy_length < match_length) +// { +// match_length -= copy_length; +// window_posn += copy_length; +// while (copy_length-- > 0) *rundest++ = *runsrc++; +// runsrc = window; +// } +// } +// window_posn += match_length; + +// /* copy match data - no worries about destination wraps */ +// while (match_length-- > 0) *rundest++ = *runsrc++; +// } +// } /* while (togo > 0) */ + +// if (togo != 0) +// { +// System.Diagnostics.Debug.WriteLine("Frame overflow, this_run = %d\n", togo); +// return DECR_ILLEGALDATA; +// } + +// memcpy(decomp_state.outbuf, window + ((!window_posn) ? window_size : window_posn) - outlen, outlen); + +// decomp_state.qtm.window_posn = window_posn; +// return DECR_OK; +// } +// } +// } \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.cs b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.cs index 9bdbb6ba..dee12406 100644 --- a/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.cs +++ b/BurnOutSharp.Wrappers/MicrosoftCabinet.fdi.cs @@ -18,7 +18,6 @@ // private const int FDIERROR_NONE = 0; // private const int ERROR_BAD_ARGUMENTS = 0; // private const int FDIERROR_ALLOC_FAIL = 0; -// private static void TRACE(object o) { } // private static void ERR(object o) { } // // END TEMP AREA @@ -43,73 +42,6 @@ // return fdi; // } -// /**************************************************************** -// * QTMupdatemodel (internal) -// */ -// static void QTMupdatemodel(QTMmodel model, int sym) -// { -// QTMmodelsym temp; -// int i, j; - -// for (i = 0; i < sym; i++) model.syms[i].cumfreq += 8; - -// if (model.syms[0].cumfreq > 3800) -// { -// if (--model.shiftsleft != 0) -// { -// for (i = model.entries - 1; i >= 0; i--) -// { -// /* -1, not -2; the 0 entry saves this */ -// model.syms[i].cumfreq >>= 1; -// if (model.syms[i].cumfreq <= model.syms[i + 1].cumfreq) -// { -// model.syms[i].cumfreq = (ushort)(model.syms[i + 1].cumfreq + 1); -// } -// } -// } -// else -// { -// model.shiftsleft = 50; -// for (i = 0; i < model.entries; i++) -// { -// /* no -1, want to include the 0 entry */ -// /* this converts cumfreqs into frequencies, then shifts right */ -// model.syms[i].cumfreq -= model.syms[i + 1].cumfreq; -// model.syms[i].cumfreq++; /* avoid losing things entirely */ -// model.syms[i].cumfreq >>= 1; -// } - -// /* now sort by frequencies, decreasing order -- this must be an -// * inplace selection sort, or a sort with the same (in)stability -// * characteristics -// */ -// for (i = 0; i < model.entries - 1; i++) -// { -// for (j = i + 1; j < model.entries; j++) -// { -// if (model.syms[i].cumfreq < model.syms[j].cumfreq) -// { -// temp = model.syms[i]; -// model.syms[i] = model.syms[j]; -// model.syms[j] = temp; -// } -// } -// } - -// /* then convert frequencies back to cumfreq */ -// for (i = model.entries - 1; i >= 0; i--) -// { -// model.syms[i].cumfreq += model.syms[i + 1].cumfreq; -// } -// /* then update the other part of the table */ -// for (i = 0; i < model.entries; i++) -// { -// model.tabloc[model.syms[i].sym] = (ushort)i; -// } -// } -// } -// } - // /************************************************************************* // * make_decode_table (internal) // * @@ -287,7 +219,7 @@ // { // FDI_Int fdi; -// // TRACE("(pfnalloc == ^%p, pfnfree == ^%p, pfnopen == ^%p, pfnread == ^%p, pfnwrite == ^%p, " +// // System.Diagnostics.Debug.WriteLine("(pfnalloc == ^%p, pfnfree == ^%p, pfnopen == ^%p, pfnread == ^%p, pfnwrite == ^%p, " // // "pfnclose == ^%p, pfnseek == ^%p, cpuType == %d, perf == ^%p)\n", // // pfnalloc, pfnfree, pfnopen, pfnread, pfnwrite, pfnclose, pfnseek, // // cpuType, perf); @@ -349,7 +281,7 @@ // uint i; // byte[] buf = null; -// //TRACE("(fdi == %p, hf == %Id, cabsize == %ld)\n", fdi, hf, cabsize); +// //System.Diagnostics.Debug.WriteLine("(fdi == %p, hf == %Id, cabsize == %ld)\n", fdi, hf, cabsize); // do // { @@ -413,7 +345,7 @@ // byte[] buf = new byte[64]; byte block_resv; // string prevname = null, previnfo = null, nextname = null, nextinfo = null; -// //TRACE("(fdi == ^%p, hf == %Id, pfdici == ^%p)\n", fdi, hf, pfdici); +// //System.Diagnostics.Debug.WriteLine("(fdi == ^%p, hf == %Id, pfdici == ^%p)\n", fdi, hf, pfdici); // /* read in the CFHEADER */ // if (fdi.read(hf, buf, cfhead_SIZEOF) != cfhead_SIZEOF) @@ -585,7 +517,7 @@ // bool rv; // FDI_Int fdi = get_fdi_ptr(hfdi); -// //TRACE("(hfdi == ^%p, hf == ^%Id, pfdici == ^%p)\n", hfdi, hf, pfdici); +// //System.Diagnostics.Debug.WriteLine("(hfdi == ^%p, hf == ^%Id, pfdici == ^%p)\n", hfdi, hf, pfdici); // if (fdi == null) return false; @@ -602,84 +534,6 @@ // return rv; // } -// /****************************************************************** -// * QTMfdi_initmodel (internal) -// * -// * Initialize a model which decodes symbols from [s] to [s]+[n]-1 -// */ -// static void QTMfdi_initmodel(QTMmodel m, QTMmodelsym[] sym, int n, int s) -// { -// int i; -// m.shiftsleft = 4; -// m.entries = n; -// m.syms = sym; -// memset(m.tabloc, 0xFF, sizeof(m.tabloc)); /* clear out look-up table */ -// for (i = 0; i < n; i++) -// { -// m.tabloc[i + s] = (ushort)i; /* set up a look-up entry for symbol */ -// m.syms[i].sym = (ushort)(i + s); /* actual symbol */ -// m.syms[i].cumfreq = (ushort)(n - i); /* current frequency of that symbol */ -// } -// m.syms[n].cumfreq = 0; -// } - -// /****************************************************************** -// * QTMfdi_init (internal) -// */ -// static int QTMfdi_init(int window, int level, fdi_decomp_state decomp_state) -// { -// uint wndsize = (uint)(1 << window); -// int msz = window * 2, i; -// uint j; - -// /* QTM supports window sizes of 2^10 (1Kb) through 2^21 (2Mb) */ -// /* if a previously allocated window is big enough, keep it */ -// if (window < 10 || window > 21) return DECR_DATAFORMAT; -// if (decomp_state.qtm.actual_size < wndsize) -// { -// if (decomp_state.qtm.window != null) decomp_state.fdi.free(decomp_state.qtm.window); -// decomp_state.qtm.window = null; -// } -// if (decomp_state.qtm.window == null) -// { -// if ((decomp_state.qtm.window = decomp_state.fdi.alloc((int)wndsize)) == null) return DECR_NOMEMORY; -// decomp_state.qtm.actual_size = wndsize; -// } -// decomp_state.qtm.window_size = wndsize; -// decomp_state.qtm.window_posn = 0; - -// /* initialize static slot/extrabits tables */ -// for (i = 0, j = 0; i < 27; i++) -// { -// decomp_state.q_length_extra[i] = (byte)((i == 26) ? 0 : (i < 2 ? 0 : i - 2) >> 2); -// decomp_state.q_length_base[i] = (byte)j; j += (uint)(1 << ((i == 26) ? 5 : decomp_state.q_length_extra[i])); -// } -// for (i = 0, j = 0; i < 42; i++) -// { -// decomp_state.q_extra_bits[i] = (byte)((i < 2 ? 0 : i - 2) >> 1); -// decomp_state.q_position_base[i] = j; j += (uint)(1 << decomp_state.q_extra_bits[i]); -// } - -// /* initialize arithmetic coding models */ - -// QTMfdi_initmodel(decomp_state.qtm.model7, decomp_state.qtm.m7sym, 7, 0); - -// QTMfdi_initmodel(decomp_state.qtm.model00, decomp_state.qtm.m00sym, 0x40, 0x00); -// QTMfdi_initmodel(decomp_state.qtm.model40, decomp_state.qtm.m40sym, 0x40, 0x40); -// QTMfdi_initmodel(decomp_state.qtm.model80, decomp_state.qtm.m80sym, 0x40, 0x80); -// QTMfdi_initmodel(decomp_state.qtm.modelC0, decomp_state.qtm.mC0sym, 0x40, 0xC0); - -// /* model 4 depends on table size, ranges from 20 to 24 */ -// QTMfdi_initmodel(decomp_state.qtm.model4, decomp_state.qtm.m4sym, (msz < 24) ? msz : 24, 0); -// /* model 5 depends on table size, ranges from 20 to 36 */ -// QTMfdi_initmodel(decomp_state.qtm.model5, decomp_state.qtm.m5sym, (msz < 36) ? msz : 36, 0); -// /* model 6pos depends on table size, ranges from 20 to 42 */ -// QTMfdi_initmodel(decomp_state.qtm.model6pos, decomp_state.qtm.m6psym, msz, 0); -// QTMfdi_initmodel(decomp_state.qtm.model6len, decomp_state.qtm.m6lsym, 27, 0); - -// return DECR_OK; -// } - // /************************************************************ // * LZXfdi_init (internal) // */ @@ -755,25 +609,6 @@ // Array.Copy(decomp_state.inbuf, decomp_state.outbuf, inlen); // return DECR_OK; // } - -// /******************************************************** -// * Ziphuft_free (internal) -// */ -// static void fdi_Ziphuft_free(FDI_Int fdi, Ziphuft t) -// { -// Ziphuft p, q; - -// /* Go through linked list, freeing from the allocated (t[-1]) address. */ -// p = t; -// while (p != null) -// { -// q = (--p).v.t; -// fdi.free(p); -// p = q; -// } -// } - -// // Left off at fdi_Ziphuft_build (internal) // } // /// @@ -1498,7 +1333,7 @@ // /// // public uint[] x = new uint[ZIPBMAX + 1]; -// public int inpos; // byte* +// public byte* inpos; // } // /* Quantum stuff */ @@ -1656,7 +1491,7 @@ // public int bl; -// public byte[] ip; // byte* +// public byte* ip; // } // /****************************************************************************/ @@ -1829,7 +1664,7 @@ // /// // /// (high level) start of data to use up // /// -// public byte outpos; // byte* +// public byte* outpos; // /// // /// (high level) amount of data to use up @@ -2258,7 +2093,7 @@ // /// // /// (high level) start of data to use up // /// -// public byte outpos; // byte* +// public byte* outpos; // /// // /// (high level) amount of data to use up