Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CompressFile
- {
- // Fields
- private static bool bool_0 = false;
- private static CoderPropID[] coderPropID_0 = new CoderPropID[] { CoderPropID.DictionarySize, CoderPropID.PosStateBits, CoderPropID.LitContextBits, CoderPropID.LitPosBits, CoderPropID.Algorithm, CoderPropID.NumFastBytes, CoderPropID.MatchFinder, CoderPropID.EndMarker };
- private static int int_0 = 0x10000;
- private static object[] object_0 = new object[] { int_0, 2, 3, 0, 1, 0x20, "bt4", bool_0 };
- private uint uint_0;
- // Methods
- public static byte[] Compress(byte[] inputBytes)
- {
- Encoder encoder = new Encoder();
- Stream inStream = new MemoryStream(inputBytes);
- Stream outStream = new MemoryStream();
- encoder.SetCoderProperties(coderPropID_0, object_0);
- encoder.WriteCoderProperties(outStream);
- for (int i = 0; i < 8; i++)
- {
- outStream.WriteByte((byte) (inStream.Length >> (8 * i)));
- }
- encoder.Code(inStream, outStream, inStream.Length, 0L, null);
- outStream.Position = 13L;
- byte[] buffer = new byte[outStream.Length - 13L];
- outStream.Read(buffer, 0, buffer.Length);
- byte[] destinationArray = new byte[10];
- destinationArray[0] = 0x10;
- destinationArray[1] = 0x11;
- byte[] bytes = BitConverter.GetBytes(buffer.Length);
- Array.Copy(bytes, 0, destinationArray, 2, bytes.Length);
- byte[] sourceArray = BitConverter.GetBytes(inputBytes.Length);
- Array.Copy(sourceArray, 0, destinationArray, 6, sourceArray.Length);
- List<byte> list = new List<byte>();
- list.AddRange(destinationArray);
- list.AddRange(buffer);
- byte[] collection = BitConverter.GetBytes((int) CheckSumCRC32.GetCRC32CheckSum(list.ToArray()));
- list.AddRange(collection);
- return list.ToArray();
- }
- public static List<CompressFrangment> ConvertToCompressFileArray(byte[] inputBytes)
- {
- CompressFrangment frangment;
- List<CompressFrangment> list = new List<CompressFrangment>();
- for (long i = 0L; i < (inputBytes.Length - 4); i = (i + 10L) + frangment.compressSize)
- {
- frangment = new CompressFrangment {
- headVersion = inputBytes[(int) ((IntPtr) i)],
- algorithmAndLevel = inputBytes[(int) ((IntPtr) (i + 1L))],
- compressSize = BitConverter.ToInt32(new byte[] { inputBytes[(int) ((IntPtr) (i + 2L))], inputBytes[(int) ((IntPtr) (i + 3L))], inputBytes[(int) ((IntPtr) (i + 4L))], inputBytes[(int) ((IntPtr) (i + 5L))] }, 0),
- uncompressSize = BitConverter.ToInt32(new byte[] { inputBytes[(int) ((IntPtr) (i + 6L))], inputBytes[(int) ((IntPtr) (i + 7L))], inputBytes[(int) ((IntPtr) (i + 8L))], inputBytes[(int) ((IntPtr) (i + 9L))] }, 0),
- compressData = new byte[frangment.compressSize]
- };
- Array.Copy(inputBytes, i + 10L, frangment.compressData, 0L, (long) frangment.compressSize);
- list.Add(frangment);
- }
- return list;
- }
- public static byte[] Decompress(List<CompressFrangment> cmpList)
- {
- List<byte> list = new List<byte>();
- foreach (CompressFrangment frangment in cmpList)
- {
- byte[] compressData = frangment.compressData;
- byte num = (byte) (frangment.algorithmAndLevel / 0x10);
- byte num2 = (byte) (frangment.algorithmAndLevel & 15);
- byte[] buffer = new byte[frangment.uncompressSize];
- if (num == 2)
- {
- uint num3 = 0;
- FastLZWrapper.DataDecompress(frangment.compressData, buffer, ref num3);
- if (num3 != frangment.uncompressSize)
- {
- throw new CommonException(CommonErrorCode.Communication_Compression_FASTLZ_Decompress_Failed);
- }
- }
- else if (num == 1)
- {
- Decoder decoder = new Decoder();
- byte[] buffer3 = new byte[5];
- buffer3[0] = 0x5d;
- buffer3[3] = 1;
- byte[] properties = buffer3;
- switch (num2)
- {
- case 0:
- {
- byte[] buffer7 = new byte[5];
- buffer7[0] = 0x5d;
- buffer7[2] = 0x40;
- properties = buffer7;
- break;
- }
- case 2:
- {
- byte[] buffer6 = new byte[5];
- buffer6[0] = 0x5d;
- buffer6[3] = 4;
- properties = buffer6;
- break;
- }
- }
- decoder.SetDecoderProperties(properties);
- List<byte> list2 = new List<byte>();
- list2.AddRange(properties);
- list2.AddRange(BitConverter.GetBytes(frangment.uncompressSize));
- list2.AddRange(new byte[4]);
- list2.AddRange(frangment.compressData);
- MemoryStream stream = new MemoryStream(list2.ToArray());
- MemoryStream outStream = new MemoryStream(frangment.uncompressSize);
- decoder.Train(stream);
- stream.Position = 13L;
- decoder.Code(stream, outStream, (long) frangment.compressData.Length, (long) frangment.uncompressSize, null);
- buffer = outStream.ToArray();
- }
- compressData = buffer;
- list.AddRange(compressData);
- }
- return list.ToArray();
- }
- // Properties
- public uint UInt32_0
- {
- get
- {
- return this.uint_0;
- }
- set
- {
- this.uint_0 = value;
- }
- }
- // Nested Types
- internal static class Class3
- {
- // Fields
- public const byte byte_0 = 0x10;
- public const int int_0 = 10;
- public const int int_1 = 2;
- public const int int_2 = 6;
- }
- public enum CompressAlogorithem : byte
- {
- FastLZ = 2,
- LZMA = 1,
- NoCompression = 0
- }
- public enum CompressLevel : byte
- {
- Level0 = 0,
- Level1 = 1,
- Level2 = 2
- }
- }
- Collapse Methods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement