/// <summary> /// CompressPropertyData - compresses property data using the compression defined by 'compressor' /// </summary> /// <param name="input">The int[] of packet data to compress</param> /// <param name="algorithm">In: the desired algorithm to use. Out: the algorithm used</param> /// <returns>the compressed data in a byte[]</returns> #endif internal static byte[] CompressPacketData( #if OLD_ISF Compressor compressor, #endif int[] input, ref byte algorithm) { #if OLD_ISF // // lock to prevent multi-threaded vulnerabilities // lock (_compressSync) { #endif if (input == null) { //we don't raise any information that could be used to attack our ISF code //a simple 'ISF Operation Failed' is sufficient since the user can't do //anything to fix bogus ISF throw new InvalidOperationException(SR.Get(SRID.IsfOperationFailed)); } byte[] data = AlgoModule.CompressPacketData(input, algorithm); #if OLD_ISF uint cbOutSize = 0; MS.Win32.Penimc.CompressorSafeHandle safeCompressorHandle = (compressor == null) ? MS.Win32.Penimc.CompressorSafeHandle.Null : compressor._compressorHandle; int hr = MS.Win32.Penimc.UnsafeNativeMethods.IsfCompressPacketData(safeCompressorHandle, input, (uint)input.Length, ref algorithm, ref cbOutSize, null); if (0 == hr) { byte[] data2 = new byte[cbOutSize]; hr = MS.Win32.Penimc.UnsafeNativeMethods.IsfCompressPacketData(safeCompressorHandle, input, (uint)input.Length, ref algorithm, ref cbOutSize, data2); if (0 == hr) { //see if data matches if (data2.Length != data.Length) { throw new InvalidOperationException("MAGIC EXCEPTION: Packet data length didn't match with new compression"); } for (int i = 0; i < data2.Length; i++) { if (data2[i] != data[i]) { throw new InvalidOperationException("MAGIC EXCEPTION: Packet data didn't match with new compression at index " + i.ToString()); } } return data; } } throw new InvalidOperationException(StrokeCollectionSerializer.ISFDebugMessage("IsfCompressPacketData returned:" + hr.ToString(CultureInfo.InvariantCulture))); } #else return data; #endif }
/// <summary> /// DecompressPropertyData - decompresses a byte[] representing property data (such as DrawingAttributes.Color) /// </summary> /// <param name="input">The byte[] to decompress</param> #endif internal static byte[] DecompressPropertyData(byte[] input) { #if OLD_ISF // // lock to prevent multi-threaded vulnerabilities // lock (_compressSync) { #endif if (input == null) { //we don't raise any information that could be used to attack our ISF code //a simple 'ISF Operation Failed' is sufficient since the user can't do //anything to fix bogus ISF throw new InvalidOperationException(StrokeCollectionSerializer.ISFDebugMessage(SR.Get(SRID.DecompressPropertyFailed))); } byte[] data = AlgoModule.DecompressPropertyData(input); #if OLD_ISF uint size = 0; byte algo = 0; int hr = MS.Win32.Penimc.UnsafeNativeMethods.IsfDecompressPropertyData(input, (uint)input.Length, ref size, null, ref algo); if (0 == hr) { byte[] data2 = new byte[size]; hr = MS.Win32.Penimc.UnsafeNativeMethods.IsfDecompressPropertyData(input, (uint)input.Length, ref size, data2, ref algo); if (0 == hr) { if (data.Length != data2.Length) { throw new InvalidOperationException("MAGIC EXCEPTION: Property bytes length when decompressed didn't match with new uncompression"); } for (int i = 0; i < data.Length; i++) { if (data[i] != data2[i]) { throw new InvalidOperationException("MAGIC EXCEPTION: Property data didn't match with new property uncompression at index " + i.ToString()); } } return data; } } //we don't raise any information that could be used to attack our ISF code //a simple 'ISF Operation Failed' is sufficient since the user can't do //anything to fix bogus ISF throw new InvalidOperationException(StrokeCollectionSerializer.ISFDebugMessage("IsfDecompressPropertyData returned: " + hr.ToString(CultureInfo.InvariantCulture))); #else return data; #endif #if OLD_ISF } #endif }
/// <summary> /// CompressPropertyData /// </summary> /// <param name="data"></param> /// <param name="algorithm"></param> /// <returns></returns> internal static byte[] CompressPropertyData(byte[] data, byte algorithm) { if (data == null) { //we don't raise any information that could be used to attack our ISF code //a simple 'ISF Operation Failed' is sufficient since the user can't do //anything to fix bogus ISF throw new ArgumentNullException("data"); } return AlgoModule.CompressPropertyData(data, algorithm); }
/// <summary> /// DecompressPacketData - take a byte[] or a subset of a byte[] and decompresses it into /// an int[] of packet data (for example, x's in a Stroke) /// </summary> /// <param name="compressedInput">The byte[] to decompress</param> /// <param name="size">In: the max size of the subset of compressedInput to read, out: size read</param> /// <param name="decompressedPackets">The int[] to write the packet data to</param> #endif internal static void DecompressPacketData( #if OLD_ISF Compressor compressor, #endif byte[] compressedInput, ref uint size, int[] decompressedPackets) { #if OLD_ISF // // lock to prevent multi-threaded vulnerabilities // lock (_compressSync) { #endif if (compressedInput == null || size > compressedInput.Length || decompressedPackets == null) { //we don't raise any information that could be used to attack our ISF code //a simple 'ISF Operation Failed' is sufficient since the user can't do //anything to fix bogus ISF throw new InvalidOperationException(StrokeCollectionSerializer.ISFDebugMessage(SR.Get(SRID.DecompressPacketDataFailed))); } #if OLD_ISF uint size2 = size; #endif size = AlgoModule.DecompressPacketData(compressedInput, decompressedPackets); #if OLD_ISF MS.Win32.Penimc.CompressorSafeHandle safeCompressorHandle = (compressor == null) ? MS.Win32.Penimc.CompressorSafeHandle.Null : compressor._compressorHandle; int[] decompressedPackets2 = new int[decompressedPackets.Length]; byte algo = AlgoModule.NoCompression; int hr = MS.Win32.Penimc.UnsafeNativeMethods.IsfDecompressPacketData(safeCompressorHandle, compressedInput, ref size2, (uint)decompressedPackets2.Length, decompressedPackets2, ref algo); if (0 != hr) { //we don't raise any information that could be used to attack our ISF code //a simple 'ISF Operation Failed' is sufficient since the user can't do //anything to fix bogus ISF throw new InvalidOperationException(StrokeCollectionSerializer.ISFDebugMessage("IsfDecompressPacketData returned: " + hr.ToString(CultureInfo.InvariantCulture))); } if (size != size2) { throw new InvalidOperationException("MAGIC EXCEPTION: Packet data bytes read didn't match with new uncompression"); } for (int i = 0; i < decompressedPackets.Length; i++) { if (decompressedPackets[i] != decompressedPackets2[i]) { throw new InvalidOperationException("MAGIC EXCEPTION: Packet data didn't match with new uncompression at index " + i.ToString()); } } } #endif }