Esempio n. 1
0
        /// <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
        }
Esempio n. 2
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _compressorHandle.Dispose();
            _disposed = true;
            _compressorHandle = null;
        }
Esempio n. 3
0
 internal Compressor(byte[] data, ref uint size)
 {
     if (data == null || data.Length != size)
     {
         //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.InitializingCompressorFailed)));
     }
     
     _compressorHandle = MS.Win32.Penimc.UnsafeNativeMethods.IsfLoadCompressor(data, ref size);
     if (_compressorHandle.IsInvalid)
     {
         //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.InitializingCompressorFailed)));
     }
 }
Esempio n. 4
0
        /// <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
        }