Example #1
0
        public void ParseNsoData(byte[] fileData, string path)
        {
            this.fileName = this.GetNsoName(path);
            int       count     = Marshal.SizeOf(typeof(NsoHeader));
            GCHandle  gcHandle  = GCHandle.Alloc((object)((IEnumerable <byte>)fileData).Skip <byte>(0).Take <byte>(count).ToArray <byte>(), GCHandleType.Pinned);
            NsoHeader structure = (NsoHeader)Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof(NsoHeader));

            gcHandle.Free();
            byte[] array = ((IEnumerable <byte>)fileData).Skip <byte>((int)structure.RoFileOffset).Take <byte>((int)structure.RoFileSize).ToArray <byte>();
            this.roBinary = new byte[(int)structure.RoSize];
            if (((int)structure.Flags & 2) == 2)
            {
                if (Lz4.LZ4_decompress_safe(array, 0, this.roBinary, 0, array.Length, this.roBinary.Length) != this.roBinary.Length)
                {
                    throw new Exception("lz4の展開に失敗しました。\n" + path);
                }
            }
            else
            {
                array.CopyTo((Array)this.roBinary, 0);
            }
            if (structure.EmbededSize <= 0U)
            {
                return;
            }
            this.apiInfoBinary = new byte[(int)structure.EmbededSize];
            Array.Copy((Array)this.roBinary, (long)structure.EmbededOffset, (Array)this.apiInfoBinary, 0L, (long)this.apiInfoBinary.Length);
        }
Example #2
0
 public static int LZ4_decompress_safe(byte[] source, int sourceOffset, byte[] dest, int destOffset, int compressedSize, int maxDecompressedSize)
 {
     using (new Lz4.ScopedGCHandle((object)source, GCHandleType.Pinned))
     {
         using (new Lz4.ScopedGCHandle((object)dest, GCHandleType.Pinned))
             return(Lz4.LZ4_decompress_safe(Marshal.UnsafeAddrOfPinnedArrayElement <byte>(source, sourceOffset), Marshal.UnsafeAddrOfPinnedArrayElement <byte>(dest, destOffset), compressedSize, maxDecompressedSize));
     }
 }
Example #3
0
 public static int LZ4_compress_default(byte[] source, byte[] dest, int sourceSize, int maxDestSize)
 {
     using (new Lz4.ScopedGCHandle((object)source, GCHandleType.Pinned))
     {
         using (new Lz4.ScopedGCHandle((object)dest, GCHandleType.Pinned))
             return(Lz4.LZ4_compress_default(Marshal.UnsafeAddrOfPinnedArrayElement <byte>(source, 0), Marshal.UnsafeAddrOfPinnedArrayElement <byte>(dest, 0), sourceSize, maxDestSize));
     }
 }