예제 #1
0
        /// <summary>
        /// Disassemble the .unity3d file.
        /// </summary>
        public void Disassemble()
        {
            _compressedFile.ReadFile();
            _compressedFile.FileReader.BaseStream.Position = _compressedFile.Header.CompressedFileHeaderSize;
            byte[] compressed_file_body = _compressedFile.FileReader.ReadByteArray(_compressedFile.Header.CompressedFileSizeWithoutHeader); //Get the body of the compressed file

            ConsoleIO.Log("Decompressing the .unity3d with Lzma...");
            _decompressedFile = new DecompressedFile(LzmaUtils.Decompress(compressed_file_body));
            _decompressedFile.ReadFile();
        }
예제 #2
0
        public void Open()
        {
            var file       = File.ReadAllBytes(FilePath);
            var fileReader = new FileReader(file);

            //read compressed header
            var signature            = fileReader.ReadString();
            var buildVersion         = fileReader.ReadInt32();
            var webPlayerVersion     = fileReader.ReadString();
            var unityEngineVersion   = fileReader.ReadString();
            var compressedFileSize   = fileReader.ReadInt32();
            var compressedHeaderSize = fileReader.ReadInt32();

            fileReader.SkipBytes(8);
            var compressedBodySize     = fileReader.ReadInt32();
            var uncompressedSize       = fileReader.ReadInt32();
            var compressedFileSize2    = fileReader.ReadInt32();
            var uncompressedHeaderSize = fileReader.ReadInt32();

            if (fileReader.ReadByte() != 0x00) //end of header
            {
                throw new InvalidDataException(string.Format("Expected 0x00 at: {0}.", fileReader.Position.ToString("X2")));
            }
            fileReader.Position = compressedHeaderSize;

            //decompress compressed body
            var fileBody         = fileReader.ReadByteArray(compressedBodySize);
            var decompressedFile = LzmaUtils.Decompress(fileBody);

            //read decompressed header
            fileReader = new FileReader(decompressedFile);
            var files = new WebArchiveFile[fileReader.ReadInt32()];

            for (int i = 0; i < files.Length; i++)
            {
                files[i]        = new WebArchiveFile();
                files[i].Name   = fileReader.ReadString();
                files[i].Offset = fileReader.ReadInt32();
                files[i].Size   = fileReader.ReadInt32();
            }

            //read decompressed body
            for (int i = 0; i < files.Length; i++)
            {
                fileReader.Position = files[i].Offset;
                files[i].Bytes      = fileReader.ReadByteArray(files[i].Size);
            }

            Files            = files;
            CompressedSize   = compressedFileSize;
            UncompressedSize = uncompressedSize;
            Opened           = true;
        }
예제 #3
0
파일: CsvTable.cs 프로젝트: myegos/CoCSharp
 /// <summary>
 /// Reads the specified .csv file from a <see cref="Byte"/> array and decompresses it if specifed.
 /// </summary>
 /// <param name="bytes"><see cref="Byte"/> array of the .csv file.</param>
 /// <param name="compressed">>Whether the .csv file is compressed or not.</param>
 public void Load(byte[] bytes, bool compressed)
 {
     if (compressed)
     {
         using (var mem = new MemoryStream())
         {
             mem.Write(bytes, 0, 9); // fix the header
             mem.Write(new byte[4], 0, 4);
             mem.Write(bytes, 9, bytes.Length - 9);
             Load(LzmaUtils.Decompress(mem.ToArray()));
         }
     }
     else
     {
         Load(bytes);
     }
 }
예제 #4
0
        /// <summary>
        /// Try to disassemble the .unity3d file.
        /// </summary>
        /// <param name="timesToTry">Times to try</param>
        public void BurteForceDisassemble(int timesToTry)
        {
            ConsoleIO.WriteLine("Brute force disassembling file.");
            byte[] buf = null;
            for (int i = 0; i < timesToTry; i++)
            {
                try
                {
                    buf = new byte[_compressedFile.Bytes.Length - i];
                    Buffer.BlockCopy(_compressedFile.Bytes, i, buf, 0, buf.Length);

                    LzmaUtils.Decompress(buf);
                    ConsoleIO.WriteLine("Was able to decompress file at offset: " + i.ToString("X"));
                    _decompressedFile = new DecompressedFile(LzmaUtils.Decompress(buf));
                    break;
                }
                catch { }
                ConsoleIO.WriteLine("Failed to brute force unpack file. Tried: " + i.ToString(), ConsoleIO.LogType.Error);
            }
        }
예제 #5
0
파일: Replay.cs 프로젝트: 02Redpoll/Circles
        /// <summary>
        /// Loads osu! replay from specified <see cref="BinaryReader"/>.
        /// </summary>
        public void Load(OsuBinaryReader reader, bool fullLoad = false)
        {
            Ruleset     = (Ruleset)reader.ReadByte();
            Version     = reader.ReadInt32();
            BeatmapHash = reader.ReadString();
            Username    = reader.ReadString();
            Hash        = reader.ReadString();
            Count300    = reader.ReadUInt16();
            Count100    = reader.ReadUInt16();
            Count50     = reader.ReadUInt16();
            Gekis       = reader.ReadUInt16();
            Katus       = reader.ReadUInt16();
            Misses      = reader.ReadUInt16();
            TotalScore  = reader.ReadUInt32();
            MaxCombo    = reader.ReadUInt16();
            IsPerfect   = reader.ReadBoolean();
            Mods        = (Mods)reader.ReadInt32();

            string lifedata = reader.ReadString();

            if (fullLoad)
            {
                if (!string.IsNullOrEmpty(lifedata))
                {
                    var frames = new List <LifebarFrame>();

                    foreach (string block in lifedata.Split(','))
                    {
                        var pair = block.Split('|');

                        if (pair.Length == 2)
                        {
                            frames.Add(new LifebarFrame
                            {
                                Time  = int.Parse(pair[0]),
                                Value = float.Parse(pair[1], CultureInfo.InvariantCulture)
                            });
                        }
                    }

                    Lifebar = frames.ToArray();
                }
            }

            SubmitDate = new DateTime(reader.ReadInt64(), DateTimeKind.Utc);

            if (fullLoad)
            {
                var frames = new List <DataFrame>();

                foreach (string frame in Encoding.UTF8.GetString(LzmaUtils.Decompress(reader.ReadBytes(reader.ReadInt32()))).Split(','))
                {
                    if (string.IsNullOrEmpty(frame))
                    {
                        break;
                    }

                    var pair = frame.Split('|');

                    if (pair.Length == 4)
                    {
                        if (pair[0] == "-12345")
                        {
                            Seed = int.Parse(pair[3]);

                            break;
                        }

                        frames.Add(new DataFrame
                        {
                            Time    = int.Parse(pair[0]),
                            X       = float.Parse(pair[1], CultureInfo.InvariantCulture),
                            Y       = float.Parse(pair[2], CultureInfo.InvariantCulture),
                            Actions = (Actions)byte.Parse(pair[3])
                        });
                    }
                }

                Data = frames.ToArray();
            }
            else
            {
                int length = reader.ReadInt32();

                reader.BaseStream.Position += length;
            }

            ScoreId = reader.ReadInt64();

            if (Mods.HasFlag(Mods.Target))
            {
                TotalAccuracy = reader.ReadDouble();
            }
        }