namespace zlib { using System; internal sealed class InfTree { internal const int BMAX = 15; internal static readonly int[] cpdext = new int[] { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }; internal static readonly int[] cpdist = new int[] { 1, 2, 3, 4, 5, 7, 9, 13, 0x11, 0x19, 0x21, 0x31, 0x41, 0x61, 0x81, 0xc1, 0x101, 0x181, 0x201, 0x301, 0x401, 0x601, 0x801, 0xc01, 0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001 }; internal static readonly int[] cplens = new int[] { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 0x11, 0x13, 0x17, 0x1b, 0x1f, 0x23, 0x2b, 0x33, 0x3b, 0x43, 0x53, 0x63, 0x73, 0x83, 0xa3, 0xc3, 0xe3, 0x102, 0, 0 }; internal static readonly int[] cplext = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0x70, 0x70 }; internal const int fixed_bd = 5; internal const int fixed_bl = 9; internal static readonly int[] fixed_td = new int[] { 80, 5, 1, 0x57, 5, 0x101, 0x53, 5, 0x11, 0x5b, 5, 0x1001, 0x51, 5, 5, 0x59, 5, 0x401, 0x55, 5, 0x41, 0x5d, 5, 0x4001, 80, 5, 3, 0x58, 5, 0x201, 0x54, 5, 0x21, 0x5c, 5, 0x2001, 0x52, 5, 9, 90, 5, 0x801, 0x56, 5, 0x81, 0xc0, 5, 0x6001, 80, 5, 2, 0x57, 5, 0x181, 0x53, 5, 0x19, 0x5b, 5, 0x1801, 0x51, 5, 7, 0x59, 5, 0x601, 0x55, 5, 0x61, 0x5d, 5, 0x6001, 80, 5, 4, 0x58, 5, 0x301, 0x54, 5, 0x31, 0x5c, 5, 0x3001, 0x52, 5, 13, 90, 5, 0xc01, 0x56, 5, 0xc1, 0xc0, 5, 0x6001 }; internal static readonly int[] fixed_tl = new int[] { 0x60, 7, 0x100, 0, 8, 80, 0, 8, 0x10, 0x54, 8, 0x73, 0x52, 7, 0x1f, 0, 8, 0x70, 0, 8, 0x30, 0, 9, 0xc0, 80, 7, 10, 0, 8, 0x60, 0, 8, 0x20, 0, 9, 160, 0, 8, 0, 0, 8, 0x80, 0, 8, 0x40, 0, 9, 0xe0, 80, 7, 6, 0, 8, 0x58, 0, 8, 0x18, 0, 9, 0x90, 0x53, 7, 0x3b, 0, 8, 120, 0, 8, 0x38, 0, 9, 0xd0, 0x51, 7, 0x11, 0, 8, 0x68, 0, 8, 40, 0, 9, 0xb0, 0, 8, 8, 0, 8, 0x88, 0, 8, 0x48, 0, 9, 240, 80, 7, 4, 0, 8, 0x54, 0, 8, 20, 0x55, 8, 0xe3, 0x53, 7, 0x2b, 0, 8, 0x74, 0, 8, 0x34, 0, 9, 200, 0x51, 7, 13, 0, 8, 100, 0, 8, 0x24, 0, 9, 0xa8, 0, 8, 4, 0, 8, 0x84, 0, 8, 0x44, 0, 9, 0xe8, 80, 7, 8, 0, 8, 0x5c, 0, 8, 0x1c, 0, 9, 0x98, 0x54, 7, 0x53, 0, 8, 0x7c, 0, 8, 60, 0, 9, 0xd8, 0x52, 7, 0x17, 0, 8, 0x6c, 0, 8, 0x2c, 0, 9, 0xb8, 0, 8, 12, 0, 8, 140, 0, 8, 0x4c, 0, 9, 0xf8, 80, 7, 3, 0, 8, 0x52, 0, 8, 0x12, 0x55, 8, 0xa3, 0x53, 7, 0x23, 0, 8, 0x72, 0, 8, 50, 0, 9, 0xc4, 0x51, 7, 11, 0, 8, 0x62, 0, 8, 0x22, 0, 9, 0xa4, 0, 8, 2, 0, 8, 130, 0, 8, 0x42, 0, 9, 0xe4, 80, 7, 7, 0, 8, 90, 0, 8, 0x1a, 0, 9, 0x94, 0x54, 7, 0x43, 0, 8, 0x7a, 0, 8, 0x3a, 0, 9, 0xd4, 0x52, 7, 0x13, 0, 8, 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0x33, 0, 9, 0xc7, 0x51, 7, 11, 0, 8, 0x63, 0, 8, 0x23, 0, 9, 0xa7, 0, 8, 3, 0, 8, 0x83, 0, 8, 0x43, 0, 9, 0xe7, 80, 7, 7, 0, 8, 0x5b, 0, 8, 0x1b, 0, 9, 0x97, 0x54, 7, 0x43, 0, 8, 0x7b, 0, 8, 0x3b, 0, 9, 0xd7, 0x52, 7, 0x13, 0, 8, 0x6b, 0, 8, 0x2b, 0, 9, 0xb7, 0, 8, 11, 0, 8, 0x8b, 0, 8, 0x4b, 0, 9, 0xf7, 80, 7, 5, 0, 8, 0x57, 0, 8, 0x17, 0xc0, 8, 0, 0x53, 7, 0x33, 0, 8, 0x77, 0, 8, 0x37, 0, 9, 0xcf, 0x51, 7, 15, 0, 8, 0x67, 0, 8, 0x27, 0, 9, 0xaf, 0, 8, 7, 0, 8, 0x87, 0, 8, 0x47, 0, 9, 0xef, 80, 7, 9, 0, 8, 0x5f, 0, 8, 0x1f, 0, 9, 0x9f, 0x54, 7, 0x63, 0, 8, 0x7f, 0, 8, 0x3f, 0, 9, 0xdf, 0x52, 7, 0x1b, 0, 8, 0x6f, 0, 8, 0x2f, 0, 9, 0xbf, 0, 8, 15, 0, 8, 0x8f, 0, 8, 0x4f, 0, 9, 0xff }; private const int MANY = 0x5a0; private const int Z_BUF_ERROR = -5; private const int Z_DATA_ERROR = -3; private const int Z_ERRNO = -1; private const int Z_MEM_ERROR = -4; private const int Z_NEED_DICT = 2; private const int Z_OK = 0; private const int Z_STREAM_END = 1; private const int Z_STREAM_ERROR = -2; private const int Z_VERSION_ERROR = -6; internal static int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, int[] v) { int[] numArray = new int[0x10]; int[] sourceArray = new int[3]; int[] numArray3 = new int[15]; int[] numArray4 = new int[0x10]; int index = 0; int num5 = n; do { numArray[b[bindex + index]]++; index++; num5--; } while (num5 != 0); if (numArray[0] == n) { t[0] = -1; m[0] = 0; return 0; } int num8 = m[0]; int num6 = 1; while (num6 <= 15) { if (numArray[num6] != 0) { break; } num6++; } int num7 = num6; if (num8 < num6) { num8 = num6; } num5 = 15; while (num5 != 0) { if (numArray[num5] != 0) { break; } num5--; } int num3 = num5; if (num8 > num5) { num8 = num5; } m[0] = num8; int num14 = ((int) 1) << num6; while (num6 < num5) { num14 -= numArray[num6]; if (num14 < 0) { return -3; } num6++; num14 = num14 << 1; } num14 -= numArray[num5]; if (num14 < 0) { return -3; } numArray[num5] += num14; numArray4[1] = num6 = 0; index = 1; int num13 = 2; while (--num5 != 0) { numArray4[num13] = num6 += numArray[index]; num13++; index++; } num5 = 0; index = 0; do { num6 = b[bindex + index]; if (num6 != 0) { v[numArray4[num6]++] = num5; } index++; } while (++num5 < n); n = numArray4[num3]; numArray4[0] = num5 = 0; index = 0; int num4 = -1; int bits = -num8; numArray3[0] = 0; int num11 = 0; int num15 = 0; while (num7 <= num3) { int num2; int num = numArray[num7]; goto Label_03BD; Label_01B2: num4++; bits += num8; num15 = num3 - bits; num15 = (num15 > num8) ? num8 : num15; if ((num2 = ((int) 1) << (num6 = num7 - bits)) > (num + 1)) { num2 -= num + 1; num13 = num7; if (num6 < num15) { while (++num6 < num15) { if ((num2 = num2 << 1) <= numArray[++num13]) { break; } num2 -= numArray[num13]; } } } num15 = ((int) 1) << num6; if ((hn[0] + num15) > 0x5a0) { return -3; } numArray3[num4] = num11 = hn[0]; hn[0] += num15; if (num4 != 0) { numArray4[num4] = num5; sourceArray[0] = (byte) num6; sourceArray[1] = (byte) num8; num6 = SupportClass.URShift(num5, (int) (bits - num8)); sourceArray[2] = (num11 - numArray3[num4 - 1]) - num6; Array.Copy(sourceArray, 0, hp, (numArray3[num4 - 1] + num6) * 3, 3); } else { t[0] = num11; } Label_02AE: if (num7 > (bits + num8)) { goto Label_01B2; } sourceArray[1] = (byte) (num7 - bits); if (index >= n) { sourceArray[0] = 0xc0; } else if (v[index] < s) { sourceArray[0] = (v[index] < 0x100) ? ((byte) 0) : ((byte) 0x60); sourceArray[2] = v[index++]; } else { sourceArray[0] = (byte) ((e[v[index] - s] + 0x10) + 0x40); sourceArray[2] = d[v[index++] - s]; } num2 = ((int) 1) << (num7 - bits); num6 = SupportClass.URShift(num5, bits); while (num6 < num15) { Array.Copy(sourceArray, 0, hp, (num11 + num6) * 3, 3); num6 += num2; } num6 = ((int) 1) << (num7 - 1); while ((num5 & num6) != 0) { num5 ^= num6; num6 = SupportClass.URShift(num6, 1); } num5 ^= num6; for (int i = (((int) 1) << bits) - 1; (num5 & i) != numArray4[num4]; i = (((int) 1) << bits) - 1) { num4--; bits -= num8; } Label_03BD: if (num-- != 0) { goto Label_02AE; } num7++; } if ((num14 != 0) && (num3 != 1)) { return -5; } return 0; } internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZStream z) { int[] hn = new int[1]; int[] v = new int[0x13]; int num = huft_build(c, 0, 0x13, 0x13, null, null, tb, bb, hp, hn, v); if (num == -3) { z.msg = "oversubscribed dynamic bit lengths tree"; return num; } if ((num != -5) && (bb[0] != 0)) { return num; } z.msg = "incomplete dynamic bit lengths tree"; return -3; } internal static int inflate_trees_dynamic(int nl, int nd, int[] c, int[] bl, int[] bd, int[] tl, int[] td, int[] hp, ZStream z) { int[] hn = new int[1]; int[] v = new int[0x120]; int num = huft_build(c, 0, nl, 0x101, cplens, cplext, tl, bl, hp, hn, v); if ((num != 0) || (bl[0] == 0)) { if (num == -3) { z.msg = "oversubscribed literal/length tree"; return num; } if (num != -4) { z.msg = "incomplete literal/length tree"; num = -3; } return num; } num = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v); if ((num == 0) && ((bd[0] != 0) || (nl <= 0x101))) { return 0; } if (num == -3) { z.msg = "oversubscribed distance tree"; return num; } if (num == -5) { z.msg = "incomplete distance tree"; return -3; } if (num != -4) { z.msg = "empty distance tree with lengths"; num = -3; } return num; } internal static int inflate_trees_fixed(int[] bl, int[] bd, int[][] tl, int[][] td, ZStream z) { bl[0] = 9; bd[0] = 5; tl[0] = fixed_tl; td[0] = fixed_td; return 0; } } }