Пример #1
0
        private static async Task <bool> DownloadOodleDll()
        {
            using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(2) };
            using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
                                                                      new Uri(WARFRAME_INDEX_URL));
            try
            {
                using var httpResponseMessage = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);

                var lzma = await httpResponseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);

                var input  = new MemoryStream(lzma);
                var output = new MemoryStream();
                Lzma.Decompress(input, output);
                output.Position  = 0;
                using var reader = new StreamReader(output);
                string?line, dllUrl = null;
                while ((line = await reader.ReadLineAsync()) != null)
                {
                    if (line.Contains(OODLE_DLL_NAME))
                    {
                        dllUrl = WARFRAME_CDN_HOST + line.Substring(0, line.IndexOf(','));
                        break;
                    }
                }
                if (dllUrl == null)
                {
                    Log.Warning("Warframe index did not contain oodle dll");
                    return(default);
Пример #2
0
        public static async Task <bool> DownloadOodleDll(string?path)
        {
            using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
            try
            {
                using var indexResponse = await client.GetAsync(WARFRAME_INDEX_URL).ConfigureAwait(false);

                await using var indexLzmaStream = await indexResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);

                await using var indexStream = new MemoryStream();

                Lzma.Decompress(indexLzmaStream, indexStream);
                indexStream.Position = 0;

                string?dllUrl = null;
                using var indexReader = new StreamReader(indexStream);
                while (!indexReader.EndOfStream)
                {
                    var line = await indexReader.ReadLineAsync().ConfigureAwait(false);

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.Contains(OODLE_DLL_NAME))
                    {
                        dllUrl = WARFRAME_CDN_HOST + line[..line.IndexOf(',')];
Пример #3
0
        private ArchiveResult Archive(string scanDirectory, string target)
        {
            try
            {
                string tempFile = Path.GetTempFileName();

                try
                {
                    Lzma.Compress(scanDirectory, tempFile);
                    File.Copy(tempFile, target);
                }
                finally
                {
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                }

                return(new ArchiveResult {
                    Success = true
                });
            }
            catch (Exception e)
            {
                return(new ArchiveResult {
                    Success = false, Exception = e
                });
            }
        }
Пример #4
0
        public void Test_Lzma()
        {
            using (MemoryStream stream1 = new MemoryStream())
                using (FileStream stream2 = new FileStream("temp.lzma", FileMode.Create))
                    //using (MemoryStream stream2 = new MemoryStream())
                    using (MemoryStream stream3 = new MemoryStream())
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            byte[] buffer = new byte[1024 * 1024];
                            _random.NextBytes(buffer);
                            stream1.Write(buffer, 0, buffer.Length);
                        }

                        Stopwatch sw = new Stopwatch();
                        sw.Start();

                        stream1.Seek(0, SeekOrigin.Begin);
                        Lzma.Compress(new WrapperStream(stream1, true), new WrapperStream(stream2, true), _bufferManager);
                        stream2.Seek(0, SeekOrigin.Begin);
                        Lzma.Decompress(new WrapperStream(stream2, true), new WrapperStream(stream3, true), _bufferManager);

                        sw.Stop();
                        Debug.WriteLine(string.Format("Lzma: {0}", sw.Elapsed.ToString()));

                        stream1.Seek(0, SeekOrigin.Begin);
                        stream3.Seek(0, SeekOrigin.Begin);

                        Assert.AreEqual(stream1.Length, stream3.Length);

                        for (; ;)
                        {
                            byte[] buffer1 = new byte[1024 * 32];
                            int    buffer1Length;
                            byte[] buffer2 = new byte[1024 * 32];
                            int    buffer2Length;

                            if ((buffer1Length = stream1.Read(buffer1, 0, buffer1.Length)) <= 0)
                            {
                                break;
                            }
                            if ((buffer2Length = stream3.Read(buffer2, 0, buffer2.Length)) <= 0)
                            {
                                break;
                            }

                            Assert.IsTrue(CollectionUtilities.Equals(buffer1, 0, buffer2, 0, buffer1Length));
                        }
                    }
        }
Пример #5
0
        private byte[] DecryptArray(MethodDef method, byte[] encryptedArray)
        {
            ModuleDefUser tempModule = new ModuleDefUser("TempModule");

            AssemblyDef tempAssembly = new AssemblyDefUser("TempAssembly");

            tempAssembly.Modules.Add(tempModule);

            var tempType = new TypeDefUser("", "TempType", tempModule.CorLibTypes.Object.TypeDefOrRef);

            tempType.Attributes = TypeAttributes.Public | TypeAttributes.Class;
            MethodDef tempMethod = Utils.Clone(method);

            tempMethod.ReturnType = new SZArraySig(tempModule.CorLibTypes.Byte);
            tempMethod.MethodSig.Params.Add(new SZArraySig(tempModule.CorLibTypes.Byte));
            tempMethod.Attributes = MethodAttributes.Public | MethodAttributes.Static;

            for (int i = 0; i < 5; i++)
            {
                tempMethod.Body.Instructions.RemoveAt(2); // read encrypted array from argument
            }
            tempMethod.Body.Instructions.Insert(2, OpCodes.Ldarg_0.ToInstruction());

            for (int i = 0; i < 2; i++)
            {
                tempMethod.Body.Instructions.RemoveAt(tempMethod.Body.Instructions.Count -
                                                      2); // make return decrypted array
            }
            tempType.Methods.Add(tempMethod);
            tempModule.Types.Add(tempType);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                ModuleWriterOptions moduleWriterOptions = new ModuleWriterOptions();
                moduleWriterOptions.MetaDataOptions = new MetaDataOptions();

                tempModule.Write(memoryStream, moduleWriterOptions);

                Assembly   patchedAssembly = Assembly.Load(memoryStream.ToArray());
                var        type            = patchedAssembly.ManifestModule.GetType("TempType");
                var        methods         = type.GetMethods();
                MethodInfo patchedMethod   = methods.First(m => m.IsPublic && m.IsStatic);
                byte[]     decryptedBytes  = (byte[])patchedMethod.Invoke(null, new object[] { encryptedArray });
                return(Lzma.Decompress(decryptedBytes));
            }
        }
Пример #6
0
        private void LZMACRToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult warning = MessageBox.Show(
                "After the SC file has been compressed, the tool will clear all previous data to prevent reading errors.\nContinue?",
                "Beware!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (warning == DialogResult.Yes)
            {
                using (SaveFileDialog dlg = new SaveFileDialog())
                {
                    dlg.Filter          = "Supercell Graphics (SC) | *.sc";
                    dlg.FileName        = GetFileName(_scFile.GetInfoFileName());
                    dlg.OverwritePrompt = false;
                    dlg.CreatePrompt    = false;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        Lzma.CompressCR(_scFile.GetInfoFileName(), dlg.FileName);

                        dlg.Title    = "Please enter texture file location";
                        dlg.Filter   = "Supercell Texture (SC) | *_tex.sc";
                        dlg.FileName = GetFileName(_scFile.GetTextureFileName());
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            Lzma.CompressCR(_scFile.GetTextureFileName(), dlg.FileName);
                        }
                    }
                }

                saveToolStripMenuItem.Visible               = false;
                reloadToolStripMenuItem.Visible             = false;
                exportAllShapeToolStripMenuItem.Visible     = false;
                exportAllChunkToolStripMenuItem.Visible     = false;
                exportAllAnimationToolStripMenuItem.Visible = false;
                compressionToolStripMenuItem.Visible        = false;
                addTextureToolStripMenuItem.Visible         = false;

                treeView1.Nodes.Clear();

                pictureBox1.Image = null;
                label1.Text       = null;
                _scFile           = null;
            }
        }
Пример #7
0
 public Stream Decompress(Stream input)
 {
     return(Lzma.Decompress(input));
 }
Пример #8
0
        public void Load()
        {
            var sw = Stopwatch.StartNew();

            while (true)
            {
                using (var texReader = new BinaryReader(File.OpenRead(_textureFile)))
                {
                    Byte[] IsCompressed = texReader.ReadBytes(2);
                    if (BitConverter.ToString(IsCompressed) == "53-43")
                    {
                        texReader.BaseStream.Seek(26, SeekOrigin.Begin);
                        DialogResult result =
                            MessageBox.Show("The tool detected that you have load a compressed file.\nWould you like to decompress and load it?\nPlease note,Choosing to decompressed will override the compressed file with a new one",
                                            "SC File Is Compresed", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                        if (result == DialogResult.Yes)
                        {
                            string IsSc = BitConverter.ToString(texReader.ReadBytes(2));
                            texReader.Close();
                            if (IsSc == "53-43")
                            {
                                Lzham.DecompressSc(_textureFile);
                            }
                            else
                            {
                                Lzma.Decompress(_textureFile);
                            }
                            continue;
                        }
                        break;
                    }

                    Console.WriteLine(texReader.BaseStream.Length);
                    texReader.BaseStream.Seek(0, SeekOrigin.Begin);
                    while (true)
                    {
                        long texoffset  = texReader.BaseStream.Position;
                        var  packetId   = texReader.ReadByte();
                        var  packetSize = texReader.ReadUInt32();
                        if (packetSize > 0)
                        {
                            var tex = new Texture(this);
                            tex.SetOffset(texoffset);
                            tex.Read(packetId, packetSize, texReader);
                            this._textures.Add(tex);
                            if (texReader.BaseStream.Position != texReader.BaseStream.Length)
                            {
                                continue;
                            }
                        }
                        _eofTexOffset = texoffset;
                        break;
                    }
                }
                break;
            }

            while (true)
            {
                using (var reader = new BinaryReader(File.OpenRead(_infoFile)))
                {
                    Byte[] IsCompressed = reader.ReadBytes(2);
                    Console.WriteLine(BitConverter.ToString(IsCompressed) == "53-43");
                    if (BitConverter.ToString(IsCompressed) == "53-43")
                    {
                        reader.BaseStream.Seek(26, SeekOrigin.Begin);
                        DialogResult result = MessageBox.Show("The tool detected that you have load a compressed file.\nWould you like to decompress and load it?\nPlease note,Choosing to decompressed will override the compressed file with a new one",
                                                              @"SC File Is Compresed", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                        if (result == DialogResult.Yes)
                        {
                            string IsSc = BitConverter.ToString(reader.ReadBytes(2));
                            reader.Close();
                            if (IsSc == "53-43")
                            {
                                Lzham.DecompressSc(_infoFile);
                            }
                            else
                            {
                                Lzma.Decompress(_infoFile);
                            }
                            continue;
                        }
                        break;
                    }

                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    var shapeCount          = reader.ReadUInt16(); // a1 + 8
                    var movieClipCount      = reader.ReadUInt16(); // a1 + 12
                    var textureCount        = reader.ReadUInt16(); // a1 + 16
                    var textFieldCount      = reader.ReadUInt16(); // a1 + 24
                    var matrixCount         = reader.ReadUInt16(); // a1 + 28
                    var colorTransformCount = reader.ReadUInt16(); // a1 + 32

                    int colorTransfromID = 0;

#if DEBUG
                    Console.WriteLine(@"ShapeCount: " + shapeCount);
                    Console.WriteLine(@"MovieClipCount: " + movieClipCount);
                    Console.WriteLine(@"TextureCount: " + textureCount);
                    Console.WriteLine(@"TextFieldCount: " + textFieldCount);
                    Console.WriteLine(@"Matrix2x3Count: " + matrixCount);
                    Console.WriteLine(@"ColorTransformCount: " + colorTransformCount);
#endif
                    // 5 useless bytes, not even used by Supercell
                    reader.ReadByte();   // 1 octet
                    reader.ReadUInt16(); // 2 octets
                    reader.ReadUInt16(); // 2 octets

                    _exportStartOffset = reader.BaseStream.Position;
                    _exportCount       = reader.ReadUInt16(); // a1 + 20
                    Console.WriteLine(@"ExportCount: " + _exportCount);

                    // Reads the Export IDs.
                    for (int i = 0; i < _exportCount; i++)
                    {
                        var export = new Export(this);
                        export.SetId(reader.ReadUInt16());
                        _exports.Add(export);
                    }

                    // Reads the Export names.
                    for (int i = 0; i < _exportCount; i++)
                    {
                        var nameLength = reader.ReadByte();
                        var name       = Encoding.UTF8.GetString(reader.ReadBytes(nameLength));
                        var export     = (Export)_exports[i];
                        export.SetExportName(name);
                    }

                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        long offset = reader.BaseStream.Position;

                        var datatag = reader.ReadByte();
                        var tag     = datatag.ToString("X2"); //Block type
                        var tagSize = reader.ReadUInt32();    //Size in bytes
#if DEBUG
                        //Console.WriteLine("dataBlockTag: " + tag);
                        //Console.WriteLine("dataBlockSize: " + tagSize);
#endif
                        switch (tag)
                        {
                        default:
                            //Console.WriteLine("dataBlockTag: " + tag);
                            //Console.WriteLine("dataBlockSize: " + tagSize);
                            var defaultDataBlockContent = reader.ReadBytes(Convert.ToInt32(tagSize));
                            defaultDataBlockContent = null;
                            break;

                        case "00":
                            _eofOffset = offset;
                            foreach (ScObject t in _exports)
                            {
                                int index = _movieClips.FindIndex(movie => movie.Id == t.Id);
                                if (index != -1)
                                {
                                    ((Export)t).SetDataObject((MovieClip)_movieClips[index]);
                                }
                            }
                            break;

                        case "01":
                        case "18":
                            if (tagSize > 6)
                            {
                                var texture = new Texture(this);
                                texture.SetOffset(offset);
                                texture.Read(UInt32.Parse(tag), tagSize, reader);
                                //_eofTexOffset = reader.BaseStream.Position;
                                this._textures.Add(texture);
                            }
                            else
                            {
                                var pixelFormat = reader.ReadByte();
                                var width       = reader.ReadUInt16();
                                var height      = reader.ReadUInt16();

                                Console.WriteLine("pixelFormat: " + pixelFormat);
                                Console.WriteLine("width: " + width);
                                Console.WriteLine("height: " + height);
                            }
                            break;

                        case "02":
                        case "12":
                            var shape = new Shape(this);
                            shape.SetOffset(offset);
                            shape.Read(reader, tag);
                            this._shapes.Add(shape);
                            break;

                        case "03":
                        case "0C":
                            var movieClip = new MovieClip(this, datatag);
                            movieClip.SetOffset(offset);
                            movieClip.Read(reader, tag);
                            _movieClips.Add(movieClip);
                            break;

                        case "08":
                            float[] Points = new float[6];
                            for (int Index = 0; Index < 6; Index++)
                            {
                                Points[Index] = reader.ReadInt32();
                            }
                            Matrix _Matrix = new Matrix(Points[0] / 1024, Points[1] / 1024, Points[2] / 1024,
                                                        Points[3] / 1024, Points[4] / -20, Points[5] / -20);
                            this._matrixs.Add(_Matrix);
                            //Console.WriteLine("\t matrixVal: " + Points[0] / 1024 + "\n\t matrixVal: " + Points[1] / 1024 + "\n\t matrixVal: " + Points[2] / 1024 + "\n\t matrixVal: " + Points[3] / 1024 + "\n\t matrixVal: " + Points[4] / -20 + "\n\t matrixVal: " + Points[5] / -20);
                            break;

                        case "09":
                            var ra = reader.ReadByte();
                            var ga = reader.ReadByte();
                            var ba = reader.ReadByte();
                            var am = reader.ReadByte();
                            var rm = reader.ReadByte();
                            var gm = reader.ReadByte();
                            var bm = reader.ReadByte();
                            this._colors.Add(new Tuple <Color, byte, Color>(Color.FromArgb(ra, ga, ba), am, Color.FromArgb(rm, gm, bm)));
                            //int id = this._colors.Count - 1;
                            //Console.WriteLine("\t -ct-" + id + "--ColorA: rgb(" + this._colors[id].Item1.R + "," + this._colors[id].Item1.G + "," + this._colors[id].Item1.B + ") & " + this._colors[id].Item2 + " & rgb(" + this._colors[id].Item3.R + "," + this._colors[id].Item3.G + "," + this._colors[id].Item3.B + ")");
                            break;
                        }
                    }

                    sw.Stop();
                    Program.Interface.Text = $@"Royale Editor :  {Path.GetFileNameWithoutExtension(_textureFile)}";
                    Program.Interface.Update();
                    Console.WriteLine(@"SC File loading finished in {0}ms", sw.Elapsed.TotalMilliseconds);
                }
                break;
            }
        }