Ejemplo n.º 1
0
 internal Entry(FPS4 FPS4, EntryStruct EntryStruct, String Name)
 {
     this.FPS4        = FPS4;
     this.EntryStruct = EntryStruct;
     this.Name        = Name;
     this._Stream     = SliceStream.CreateWithLength((EntryStruct.Offset == 0) ? FPS4.DavStream : FPS4.DatStream, EntryStruct.Offset, EntryStruct.LengthReal);
 }
Ejemplo n.º 2
0
Archivo: TSS.cs Proyecto: talestra/tov
 public String ReadStringz(int TextOffset)
 {
     if (TextOffset < 0 || TextOffset >= TextStream.Length)
     {
         return("");
     }
     return((SliceStream.CreateWithLength(TextStream, TextOffset)).ReadStringz(Encoding: Encoding.UTF8));
 }
Ejemplo n.º 3
0
            public Stream Open()
            {
#if false
                if (MappedFileIndex > 0)
                {
                    return(SliceStream.CreateWithLength(new ZeroStream(this.EntryStruct.LengthReal), 0, this.EntryStruct.LengthReal));
                }
#endif
                return(SliceStream.CreateWithLength(this._Stream, 0, this._Stream.Length));
            }
Ejemplo n.º 4
0
        static public Stream ReadStream(this Stream Stream, long ToRead = -1)
        {
            if (ToRead == -1)
            {
                ToRead = Stream.Available();
            }
            var ReadedStream = SliceStream.CreateWithLength(Stream, Stream.Position, ToRead);

            Stream.Skip(ToRead);
            return(ReadedStream);
        }
Ejemplo n.º 5
0
        static public Stream GetStreamByLBA(Stream Stream, long LBA, long Size = -1)
        {
            var Offset = LBA * (long)SECTOR_SIZE;

            if (Offset >= Stream.Length)
            {
                throw(new Exception("File too small for a Xbox360 Iso File"));
            }
            //Console.WriteLine("0x{0:X8}", Offset);
            return(SliceStream.CreateWithLength(Stream, Offset, Size));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="toRead"></param>
        /// <returns></returns>
        public static SliceStream ReadStream(this Stream stream, long toRead = -1)
        {
            if (toRead == -1)
            {
                toRead = stream.Available();
            }
            var readedStream = SliceStream.CreateWithLength(stream, stream.Position, toRead);

            stream.Skip(toRead);
            return(readedStream);
        }
Ejemplo n.º 7
0
        protected void WriteChunk(string Name, Action Writer)
        {
            Stream.WriteStringz(Name, 4, Encoding.ASCII);
            BinaryWriter.Write((uint)0);
            var ChunkSizeStream = SliceStream.CreateWithLength(Stream, Stream.Position - 4, 4);
            var BackPosition    = Stream.Position;
            {
                Writer();
            }
            var ChunkLength = Stream.Position - BackPosition;

            new BinaryWriter(ChunkSizeStream).Write((uint)ChunkLength);
        }
Ejemplo n.º 8
0
            public Stream OpenRead()
            {
                switch (LocalFileHeader.CompressionMethod)
                {
                case CompressionMethod.Stored:
                    return(SliceStream.CreateWithLength(CompressedStream));

                case CompressionMethod.Deflate:
                    return(new DeflateStream(SliceStream.CreateWithLength(CompressedStream), CompressionMode.Decompress));

                default:
                    throw(new NotImplementedException("Not Implementeed : " + LocalFileHeader.CompressionMethod));
                }
            }
Ejemplo n.º 9
0
        override public void Load(Stream Stream)
        {
            this.Stream = Stream;
            var HeaderStruct = Stream.ReadStruct <HeaderStruct>();

            Debug.Assert(HeaderStruct.Magic == "TO8CHTX");
            Debug.Assert(HeaderStruct.FileSize <= Stream.Length);
            StreamEntries = SliceStream.CreateWithLength(Stream, HeaderStruct.OffsetEntries);
            StreamTexts   = SliceStream.CreateWithLength(Stream, HeaderStruct.OffsetTexts);
            for (int n = 0; n < HeaderStruct.TextCount; n++)
            {
                var EntryStruct = StreamEntries.ReadStruct <EntryStruct>();
                var Entry       = new Entry();
                Entry.Load(this, EntryStruct);
                Entries.Add(Entry);
            }
        }
Ejemplo n.º 10
0
Archivo: TSS.cs Proyecto: talestra/tov
        public TSS Load(Stream Stream)
        {
            this.Stream = Stream;
            var BinaryReader = new BinaryReader(Stream);

            Header = Stream.ReadStruct <HeaderStruct>();

            if (Header.Magic != "TSS")
            {
                throw(new Exception("Not a TSS file!"));
            }

            this.CodeStream = new MemoryStream(SliceStream.CreateWithBounds(Stream, Header.CodeStart, Header.TextStart).ReadAll());

            var TextData = SliceStream.CreateWithLength(Stream, Header.TextStart, Header.TextLen).ReadAll();

            this.TextStream = new MemoryStream();
            this.TextStream.WriteBytes(TextData);
            this.TextStream.Position = 0;

            return(this);
        }
Ejemplo n.º 11
0
            private IEnumerable <dynamic> GetElements(bool AsInt)
            {
                var ArrayStream = SliceStream.CreateWithLength(TSS.TextStream, ArrayPointer, ArrayNumberOfBytes);
                {
                    switch (ValuesType)
                    {
                    case ValueType.String:
                        if (!AsInt)
                        {
                            for (int n = 0; n < ArrayNumberOfElements; n++)
                            {
                                yield return(TSS.ReadStringz((int)(uint)ArrayStream.ReadStruct <uint_be>()));
                            }
                        }
                        else
                        {
                            for (int n = 0; n < ArrayNumberOfElements; n++)
                            {
                                yield return((int)(uint)ArrayStream.ReadStruct <uint_be>());
                            }
                        }
                        break;

                    case ValueType.Integer32Signed:
                        for (int n = 0; n < ArrayNumberOfElements; n++)
                        {
                            yield return((int)(uint)ArrayStream.ReadStruct <uint_be>());
                        }
                        break;

                    case ValueType.Float32:
                        if (!AsInt)
                        {
                            for (int n = 0; n < ArrayNumberOfElements; n++)
                            {
                                yield return((float)ArrayStream.ReadStruct <float_be>());
                            }
                        }
                        else
                        {
                            for (int n = 0; n < ArrayNumberOfElements; n++)
                            {
                                yield return((int)(uint)ArrayStream.ReadStruct <uint_be>());
                            }
                        }
                        break;

                    default:
                    {
                        Console.Error.WriteLine("Unhandled " + ValuesType + "(" + ArrayPointer + "," + ArrayNumberOfBytes + ")[" + ArrayNumberOfElements + "]");
                        //if (ArrayNumberOfElements == 0)
                        //{
                        //	yield return "<TODO " + "Unhandled " + ValuesType + "(" + ArrayPointer + "," + ArrayNumberOfBytes + ")>";
                        //}
                        //else
                        {
                            yield return("<TODO " + "Unhandled " + ValuesType + ">");

                            for (int n = 0; n < ArrayNumberOfBytes; n++)
                            {
                                yield return("" + ArrayStream.ReadStruct <byte>());
                            }
                        }
                    }
                    break;
                        //throw (new Exception("Unhandled " + ValuesType));
                    }
                }
            }
Ejemplo n.º 12
0
Archivo: TSS.cs Proyecto: talestra/tov
 public int CountStringz(int TextOffset)
 {
     return((SliceStream.CreateWithLength(TextStream, TextOffset)).CountStringzBytes(AlignTo4: false, AlignPosition: (int)TextOffset));
 }
Ejemplo n.º 13
0
 static public SliceStream SliceWithLength(this Stream BaseStream, long ThisStart = 0, long ThisLength = -1, bool?CanWrite = null)
 {
     return(SliceStream.CreateWithLength(BaseStream, ThisStart, ThisLength, CanWrite));
 }
Ejemplo n.º 14
0
 static public SliceStream Slice(this Stream BaseStream)
 {
     return(SliceStream.CreateWithLength(BaseStream));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="baseStream"></param>
 /// <param name="thisStart"></param>
 /// <param name="thisLength"></param>
 /// <param name="canWrite"></param>
 /// <returns></returns>
 public static SliceStream SliceWithLength(this Stream baseStream, long thisStart = 0, long thisLength = -1,
                                           bool?canWrite = null)
 {
     return(SliceStream.CreateWithLength(baseStream, thisStart, thisLength, canWrite));
 }
Ejemplo n.º 16
0
        public override void DecodeFile(Stream InputStream, Stream OutputStream)
        {
            byte[] CompressedBytes   = new byte[0x10000];
            byte[] UncompressedBytes = new byte[0x10000];

            var BinaryWriter = new BinaryWriter(OutputStream);

            using (var LZXState = new LZXState(17))
            {
                var BinaryReader = new BinaryReader(InputStream);

                HeaderStruct HeaderStruct = InputStream.ReadStruct <HeaderStruct>();
                if (!HeaderStruct.Magic.SequenceEqual(Signature))
                {
                    throw (new Exception("File is not a TOV.LZX"));
                }
                if (HeaderStruct.Magic1 != 0x20000)
                {
                    throw (new Exception("Invalid LZX"));
                }
                if (HeaderStruct.Magic2 != 0x80000)
                {
                    throw (new Exception("Invalid LZX"));
                }
                if (HeaderStruct.Magic3 != 0x00000)
                {
                    throw (new Exception("Invalid LZX"));
                }
                if (HeaderStruct.Magic4 != 0x00000)
                {
                    throw (new Exception("Invalid LZX"));
                }
                if (HeaderStruct.UncompressedSize != HeaderStruct.UncompressedSize2)
                {
                    throw (new Exception("Invalid LZX"));
                }
                if (HeaderStruct.CompressedSize != HeaderStruct.CompressedSize2)
                {
                    throw (new Exception("Invalid LZX"));
                }
                if (HeaderStruct.CompressedSizePlus4 != HeaderStruct.CompressedSize + 4)
                {
                    throw (new Exception("Invalid LZX"));
                }
                //if (InputStream.Position != 0x34);

                //Console.WriteLine(InputStream.Length);
                //Console.WriteLine(0x34 + HeaderStruct.CompressedSize);
                if (InputStream.Length < 0x34 + HeaderStruct.CompressedSize)
                {
                    throw(new Exception("Invalid LZX"));
                }

                var DataInputStream  = SliceStream.CreateWithLength(InputStream, 0x34, HeaderStruct.CompressedSize);
                var DataBinaryReader = new BinaryReader(DataInputStream);
                DataInputStream.Position = 0;

                while (DataInputStream.Position < DataInputStream.Length)
                {
                    ushort UncompressedChunkLength, CompressedChunkLength;

                    //Console.WriteLine(DataInputStream.Position + ":" + DataInputStream.Length);

                    // Read Chunk's size.
                    {
                        byte Byte1, Byte2;

                        Byte1 = DataBinaryReader.ReadByte();
                        if (Byte1 != 0xFF)
                        {
                            Byte2 = DataBinaryReader.ReadByte();
                            UncompressedChunkLength = 0x8000;
                            CompressedChunkLength   = (ushort)((Byte1 << 8) | Byte2);
                        }
                        else
                        {
                            UncompressedChunkLength = DataBinaryReader.ReadUint16Endian(Endianness.BigEndian);
                            CompressedChunkLength   = DataBinaryReader.ReadUint16Endian(Endianness.BigEndian);
                        }

                        if (CompressedChunkLength >= UncompressedChunkLength)
                        {
                            //Console.WriteLine("CompressedChunkLength >= UncompressedChunkLength");
                            //Console.WriteLine("{0} -> {1}", CompressedChunkLength, UncompressedChunkLength);
                        }
                    }

                    //Console.WriteLine("CHUNK: {0,8:X}, {1,8:X}, {2,8:X}", DataInputStream.Position, CompressedChunkLength, UncompressedChunkLength);

                    if (CompressedChunkLength == 0)
                    {
                        DataInputStream.Seek(-2, SeekOrigin.Current);
                        Debug.WriteLine("WARNING: Block with length 0: end!");
                        break;
                    }

                    DataInputStream.Read(CompressedBytes, 0, CompressedChunkLength);

                    //Debug.Assert(CompressedChunkLength < UncompressedChunkLength);

                    {
                        fixed(byte *CompressedBytesPtr = CompressedBytes)
                        fixed(byte *UncompressedBytesPtr = UncompressedBytes)
                        {
                            //Console.WriteLine("{0} -> {1}", CompressedChunkLength, UncompressedChunkLength);
                            LZXState.Decompress(CompressedBytesPtr, UncompressedBytesPtr, CompressedChunkLength, UncompressedChunkLength);
                        }

                        BinaryWriter.Write(UncompressedBytes, 0, UncompressedChunkLength);
                    }
                }

                //Console.WriteLine("{0:X}", DataInputStream.Position);
                //Console.WriteLine("{0:X}", DataInputStream.Length);
                //Console.WriteLine("{0:X}", HeaderStruct.FileSizeMinusX30 + 0x30);

                if (DataInputStream.Position != DataInputStream.Length)
                {
                    throw(new Exception("Not readed all the contents"));
                }
                if (!(SliceStream.CreateWithLength(InputStream, 0x34 + HeaderStruct.CompressedSize)).ReadAll().All(Byte => (Byte == 0)))
                {
                    throw(new Exception("?"));
                }
            }
        }