示例#1
0
 static extern unsafe int TECkit_Compile(
     byte *txt,
     UInt32 len,
     byte doCompression,
     Delegate errFunc,
     void *userData,
     Byte **outTable,
     UInt32 *outLen);
示例#2
0
 extern unsafe public static Byte *NeAACDecDecode2(
     IntPtr hDecoder,
     ref PInvoke_libfaad2.frameInfo frameInfo,
     Byte *buffer,
     Int32 buffer_size,
     Byte **pOutbuffer,
     Int32 out_buffer_size
     );
示例#3
0
        public static Dictionary <String, String> CreateStrMap(byte **key, byte **val)
        {
            Dictionary <String, String> map = new Dictionary <string, string>();
            Byte **ppKey = key;
            Byte **ppVal = val;

            while (ppKey != null && ppVal != null)
            {
                String strKey = Marshal.PtrToStringAnsi((IntPtr)(*ppKey));
                String strVal = Marshal.PtrToStringAnsi((IntPtr)(*ppVal));
                if (String.IsNullOrEmpty(strKey) == false && String.IsNullOrEmpty(strVal) == false)
                {
                    map[strKey] = map[strVal];
                }

                ppKey++;
                ppVal++;
            }
            return(map);
        }
示例#4
0
        /// <summary>
        /// Get the data of the entry linked by the specified unique ID.
        /// All the data will be allocated in memory. It may fail.
        ///
        /// Return false if the entry does not exist.
        /// </summary>
        public Boolean GetEntryData(UInt32 ID, Byte **pData, Int32 *pLength)
        {
            *pData = null;

            Entry *pEntry = null;

            lock (Entries)
            {
                if (!Entries.ContainsKey(ID))
                {
                    return(false);
                }
                pEntry = (Entry *)Entries[ID];
            }

            using (FileStream Stream = new FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                Stream.Seek(pEntry->Offset, SeekOrigin.Begin);

                Byte[] Buffer  = new Byte[Kernel.MAX_BUFFER_SIZE];
                *      pData   = (Byte *)Kernel.malloc((Int32)pEntry->Size);
                *      pLength = (Int32)pEntry->Size;

                Int32 Count = (Int32)(pEntry->Size / Buffer.Length);
                Int32 Rest  = (Int32)(pEntry->Size % Buffer.Length);

                Int32 Pos = 0;
                for (Int32 i = 0; i < Count; i++)
                {
                    Stream.Read(Buffer, 0, Buffer.Length);
                    Kernel.memcpy((*pData) + Pos, Buffer, Buffer.Length);
                    Pos += Buffer.Length;
                }

                Stream.Read(Buffer, 0, Rest);
                Kernel.memcpy((*pData) + Pos, Buffer, Rest);
            }
            return(true);
        }
        public static unsafe void ReadPreAllocatedBytePtrArray(IPropertyContainer propertyContainer, UInt32 key, Byte[][] buffers)
        {
            var pinnedArrays = new GCHandle[buffers.Length];

            // Pin arrays
            for (var i = 0; i < buffers.Length; i++)
            {
                pinnedArrays[i] = GCHandle.Alloc(buffers[i], GCHandleType.Pinned);
            }

            Byte **pointerArray = stackalloc Byte *[buffers.Length];

            for (var i = 0; i < buffers.Length; i++)
            {
                pointerArray[i] = (Byte *)(pinnedArrays[i].AddrOfPinnedObject().ToPointer());
            }

            propertyContainer.ReadProperty(key, new IntPtr(sizeof(IntPtr) * buffers.Length), pointerArray);

            for (var i = 0; i < buffers.Length; i++)
            {
                pinnedArrays[i].Free();
            }
        }
示例#6
0
        private unsafe UInt32 UnsafeCompress(Byte[] source, UInt32 start, Byte[] destination, UInt32 size)
        {
            fixed(Byte *source_f = source, destination_c = destination)
            {
                Byte *       source_c  = source_f + start;
                UInt32       headerlen = 8 * 4;
                Byte *       last_byte = source_c + size - 1;
                Byte *       src       = source_c + 1;
                Byte **      hashtable = (Byte **)(destination_c + size + 36000 - sizeof(Byte *) * 4096 - (((Int64)(destination_c + size)) % 8));
                const UInt32 SEQLEN    = 2 + (1 << 11);
                Byte *       cword_ptr = destination_c + headerlen;
                Byte *       dst       = destination_c + headerlen + 4 + 1;
                Byte *       prev_dst  = dst;
                Byte *       prev_src  = src;
                UInt32       cword_val = 1 << 30;
                UInt32       hash;
                UInt32 *     header = (UInt32 *)destination_c;
                Byte *       guarentee_uncompressed = last_byte - 4 * 4;

                MemCopy(&header[(Int32)HeaderFields.QCLZ], "QCLZ");
                destination_c[0] = (Byte)'Q'; destination_c[1] = (Byte)'C';
                destination_c[2] = (Byte)'L'; destination_c[3] = (Byte)'Z';
                FastWrite(3, &header[(Int32)HeaderFields.VERSION], 4);
                FastWrite(size, &header[(Int32)HeaderFields.UNCOMPSIZE], 4);

                //for (hash = 0; hash < 4096; ++hash) hashtable[hash] = source_c;

                *(destination_c + headerlen + 4) = *source_c;

                while (src < guarentee_uncompressed - SEQLEN)
                {
                    UInt32 fetch;
                    if ((cword_val & 1) == 1)
                    {
                        if (dst + SEQLEN + 128 > destination_c + size + SEQLEN + 256)
                        {
                            MemCopy(destination_c + headerlen, source_c, size);
                            FastWrite(0, &header[(Int32)HeaderFields.COMPRESSIBLE], 4);
                            FastWrite(size + headerlen + 4, &header[(Int32)HeaderFields.COMPSIZE], 4);
                            MemCopy(destination_c + FastRead(&header[(Int32)HeaderFields.COMPSIZE], 4) - 4, "QCLZ");
                            return(FastRead(&header[(Int32)HeaderFields.COMPSIZE], 4));
                        }

                        FastWrite((UInt32)((cword_val >> 1) | (1 << (4 * 8 - 1))), cword_ptr, 4);
                        cword_ptr = dst;
                        dst      += 4;
                        cword_val = 0x80000000;

                        if (dst - prev_dst > src - prev_src && src + 2 * SEQLEN < guarentee_uncompressed)
                        {
                            while (src < prev_src + SEQLEN - 4 * 8)
                            {
                                FastWrite(0x80000000, dst - 4, 4);
                                MemCopyUP(dst, src, 4 * 8 - 1);
                                dst += 4 * 8 - 1 + 4;
                                src += 4 * 8 - 1;
                            }
                            prev_src  = src;
                            prev_dst  = dst;
                            cword_ptr = dst - 4;
                        }
                    }

                    if (FastRead(src, 4) == FastRead(src + 1, 4))
                    {
                        Byte *orig_src;
                        fetch    = FastRead(src, 4);
                        orig_src = src;
                        src     += 4 + 1;
                        while (fetch == FastRead(src, 4) && src < orig_src + SEQLEN - 4)
                        {
                            src += 4;
                        }
                        FastWrite(((fetch & 0xFF) << 16) | (UInt32)((src - orig_src) << 4) | 15, dst, 4);
                        dst      += 3;
                        cword_val = (cword_val >> 1) | 0x80000000;
                    }
                    else
                    {
                        Byte *o;
                        fetch = FastRead(src, 4);
                        hash  = ((fetch >> 12) ^ fetch) & 0x0FFF;

                        if (hashtable[hash] == (byte *)0)
                        {
                            hashtable[hash] = source_c;
                        }

                        o = hashtable[hash];
                        hashtable[hash] = src;

                        Boolean tmp;
                        if (BitConverter.IsLittleEndian)
                        {
                            tmp = src - o <= 131071 && src - o > 3 && (((*(UInt32 *)o) ^ (*(UInt32 *)src)) & 0xFFFFFF) == 0;
                        }
                        else
                        {
                            tmp = src - o <= 131071 && src - o > 3 && *src == *o && *(src + 1) == *(o + 1) && *(src + 2) == *(o + 2);
                        }
                        if (tmp)
                        {
                            UInt32 offset = (UInt32)(src - o);
                            UInt32 matchlen;

                            if (BitConverter.IsLittleEndian)
                            {
                                tmp = (*(UInt32 *)o) != (*(UInt32 *)src);
                            }
                            else
                            {
                                tmp = *(o + 3) != *(src + 3);
                            }
                            if (tmp)
                            {
                                if (offset <= 63)
                                {
                                    *dst = (Byte)(offset << 2);
                                    ++dst;
                                    cword_val = (cword_val >> 1) | 0x80000000;
                                    src      += 3;
                                }
                                else if (offset <= 16383)
                                {
                                    UInt32 f = (offset << 2) | 1;
                                    FastWrite(f, dst, 2);
                                    dst      += 2;
                                    cword_val = (cword_val >> 1) | 0x80000000;
                                    src      += 3;
                                }
                                else
                                {
                                    *dst = *src;
                                    ++dst;
                                    ++src;
                                    cword_val = (cword_val >> 1);
                                }
                            }
                            else
                            {
                                cword_val = (cword_val >> 1) | 0x80000000;
                                matchlen  = 3;
                                while (*(o + matchlen) == *(src + matchlen) && matchlen < SEQLEN)
                                {
                                    ++matchlen;
                                }

                                src += matchlen;
                                if (matchlen <= 18 && offset <= 1023)
                                {
                                    UInt32 f = ((matchlen - 3) << 2) | (offset << 6) | 2;
                                    FastWrite(f, dst, 2);
                                    dst += 2;
                                }
                                else if (matchlen <= 34 && offset <= 65535)
                                {
                                    UInt32 f = ((matchlen - 3) << 3) | (offset << 8) | 3;
                                    FastWrite(f, dst, 3);
                                    dst += 3;
                                }
                                else if (matchlen >= 3)
                                {
                                    UInt32 f = ((matchlen - 3) << 4) | (offset << 15) | 7;
                                    FastWrite(f, dst, 4);
                                    dst += 4;
                                }
                            }
                        }
                        else
                        {
                            *dst = *src;
                            ++dst;
                            ++src;
                            cword_val = (cword_val >> 1);
                        }
                    }
                }

                while (src <= last_byte)
                {
                    if ((UInt32)(dst - destination_c - 1 + 4) > source.Length)
                    {
                        //compression is bigger than original data
                        return(0);
                    }

                    if ((cword_val & 1) == 1)
                    {
                        FastWrite((cword_val >> 1) | 0x80000000, cword_ptr, 4);
                        cword_ptr = dst;
                        dst      += 4;
                        cword_val = 0x80000000;
                    }

                    *dst = *src;
                    ++dst;
                    ++src;
                    cword_val = (cword_val >> 1);
                }

                while ((cword_val & 1) != 1)
                {
                    cword_val = (cword_val >> 1);
                }

                if ((UInt32)(dst - destination_c - 1 + 4) > source.Length)
                {
                    //compression is bigger than original data
                    return(0);
                }

                FastWrite((cword_val >> 1) | 0x80000000, cword_ptr, 4);
                dst += 4;

                FastWrite(1, &header[(Int32)HeaderFields.COMPRESSIBLE], 4);
                FastWrite((UInt32)(dst - destination_c - 1 + 4), &header[(Int32)HeaderFields.COMPSIZE], 4);
                MemCopy(destination_c + FastRead(&header[(Int32)HeaderFields.COMPSIZE], 4) - 4, "QCLZ");
            }

            return(GetCompressedSize(destination));
        }
示例#7
0
            /// <summary>
            /// Get the data of the entry linked by the specified path.
            /// All the data will be allocated in memory. It may fail.
            ///
            /// Return false if the entry does not exist.
            /// </summary>
            public Boolean GetEntryData(String Path, Byte **pData, Int32 *pLength)
            {
                *pData = null;

                if (Path.StartsWith("/") || Path.StartsWith("\\"))
                {
                    return(false);
                }

                Entry Entry;

                lock (Entries)
                {
                    if (!Entries.TryGetValue(Path.ToLowerInvariant().Replace('\\', '/'), out Entry))
                    {
                        return(false);
                    }
                }

                *pData   = (Byte *)Kernel.malloc((Int32)Entry.UncompressedSize);
                *pLength = (Int32)Entry.UncompressedSize;
                using (FileStream Input = new FileStream(TpdFile.GetFilename(), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[] Buffer = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Byte[] Tmp    = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Int32  Pos    = 0;

                    Input.Seek(Entry.Offset, SeekOrigin.Begin);

                    {
                        ZStream Stream = new ZStream();
                        Stream.inflateInit();

                        Int32 Result = 0;
                        Int32 Length = 0;
                        do
                        {
                            Stream.avail_in      = Input.Read(Buffer, 0, Kernel.MAX_BUFFER_SIZE);
                            Stream.next_in       = Buffer;
                            Stream.next_in_index = 0;

                            if (Stream.avail_in == 0)
                            {
                                break;
                            }

                            do
                            {
                                Stream.avail_out      = Kernel.MAX_BUFFER_SIZE;
                                Stream.next_out       = Tmp;
                                Stream.next_out_index = 0;

                                Result = Stream.inflate(zlibConst.Z_NO_FLUSH);

                                Length = Kernel.MAX_BUFFER_SIZE - Stream.avail_out;
                                Kernel.memcpy((*pData) + Pos, Tmp, Length);
                                Pos += Length;
                            }while (Stream.avail_out == 0);
                        }while (Result != zlibConst.Z_STREAM_END);

                        Stream.inflateEnd();
                    }
                }
                return(true);
            }
示例#8
0
 /// Get the data of the entry linked by the specified path.
 /// All the data will be allocated in memory. It may fail.
 ///
 /// Return false if the entry does not exist.
 /// </summary>
 public Boolean GetEntryData(String Path, Byte **pData, Int32 *pLength)
 {
     return(Package.GetEntryData(Path, pData, pLength));
 }