コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputPath"></param>
        /// <param name="outputPath"></param>
        /// <returns></returns>
        private static ScriptFile ProcessScriptfile(string inputPath, string outputPath)
        {
            /* A ScriptFile tends to skip around the offset table */
            MemoryStream buffer = new MemoryStream();

            using (Stream fs = File.OpenRead(inputPath))
            {
                (Program.CompressedInput ? new GZipStream(fs, CompressionMode.Decompress) : fs).CopyTo(buffer);
            }

            ScriptFile scriptFile = new ScriptFile(buffer, Program.Codeset);

            if (outputPath != null)
            {
                using (Stream stream = File.Create(outputPath))
                    scriptFile.Save(Program.CompressedOutput ? new GZipStream(stream, CompressionMode.Compress) : stream, true);
            }
            else
            {
                scriptFile.Save(Console.OpenStandardOutput(), false);
            }

            buffer.Close();
            return(scriptFile);
        }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="scriptFile"></param>
 /// <param name="outputPath"></param>
 /// <returns></returns>
 private static ScriptFile SaveScriptFile(ScriptFile scriptFile, string outputPath)
 {
     if (outputPath != null)
     {
         using (Stream stream = File.Create(outputPath))
             scriptFile.Save(Program.CompressedOutput ? new GZipStream(stream, CompressionMode.Compress) : stream, true);
     }
     else
     {
         scriptFile.Save(Console.OpenStandardOutput(), false);
     }
     return(scriptFile);
 }
コード例 #3
0
        private void fileToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "GTA V Script Files|*.xsc;*.csc;*.ysc";
#if !DEBUG
            try
            {
#endif
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DateTime   Start = DateTime.Now;
                ScriptFile file  = new ScriptFile(ofd.OpenFile(), (Path.GetExtension(ofd.FileName) != ".ysc"));
                file.Save(Path.Combine(Path.GetDirectoryName(ofd.FileName),
                                       Path.GetFileNameWithoutExtension(ofd.FileName) + ".c"));
                file.Close();
                if ((Path.GetExtension(ofd.FileName) != ".ysc"))
                {
                    ScriptFile.npi.savefile();
                }
                else
                {
                    ScriptFile.X64npi.savefile();
                }
                updatestatus("File Saved, Time taken: " + (DateTime.Now - Start).ToString());
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            updatestatus("Error decompiling script " + ex.Message);
        }
#endif
        }
コード例 #4
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "GTA V Script Files|*.xsc;*.csc;*.ysc;*.ysc.full";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DateTime Start = DateTime.Now;
                filename    = Path.GetFileNameWithoutExtension(ofd.FileName);
                loadingfile = true;
                fctb1.Clear();
                listView1.Items.Clear();
                updatestatus("Opening Script File...");
                string ext = Path.GetExtension(ofd.FileName);
                if (ext == ".full")                 //handle openIV exporting pc scripts as *.ysc.full
                {
                    ext = Path.GetExtension(Path.GetFileNameWithoutExtension(ofd.FileName));
                }
#if !DEBUG
                try
                {
#endif
                fileopen = new ScriptFile(ofd.OpenFile(), ext != ".ysc");
#if !DEBUG
            }
            catch (Exception ex)
            {
                updatestatus("Error decompiling script " + ex.Message);
                return;
            }
#endif
                updatestatus("Decompiled Script File, Time taken: " + (DateTime.Now - Start).ToString());
                MemoryStream ms = new MemoryStream();

                fileopen.Save(ms, false);


                foreach (KeyValuePair <string, Tuple <int, int> > locations in fileopen.Function_loc)
                {
                    listView1.Items.Add(new ListViewItem(new string[] { locations.Key, locations.Value.Item1.ToString(), locations.Value.Item2.ToString() }));
                }
                fileopen.Close();
                StreamReader sr = new StreamReader(ms);
                ms.Position = 0;
                updatestatus("Loading Text in Viewer...");
                fctb1.Text = sr.ReadToEnd();
                SetFileName(filename);
                ScriptOpen = true;
                updatestatus("Ready, Time taken: " + (DateTime.Now - Start).ToString());
                if (ext != ".ysc")
                {
                    ScriptFile.npi.savefile();
                }
                else
                {
                    ScriptFile.X64npi.savefile();
                }
            }
        }
コード例 #5
0
 private void Decompile()
 {
     while (CompileList.Count > 0)
     {
         Tuple <string, bool> scriptToDecode;
         lock (Program.ThreadLock)
         {
             scriptToDecode = CompileList.Dequeue();
         }
         try
         {
             ScriptFile scriptFile = new ScriptFile((Stream)File.OpenRead(scriptToDecode.Item1), scriptToDecode.Item2);
             scriptFile.Save(Path.Combine(SaveDirectory, Path.GetFileNameWithoutExtension(scriptToDecode.Item1) + ".c"));
             scriptFile.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error decompiling script " + Path.GetFileNameWithoutExtension(scriptToDecode.Item1) + " - " + ex.Message);
         }
     }
     Program.ThreadCount--;
 }
コード例 #6
0
        private void bulkDecompiler(string path, string theFileName)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.FileName = theFileName;
            DateTime Start = DateTime.Now;

            filename    = Path.GetFileNameWithoutExtension(ofd.FileName);
            loadingfile = true;
            fctb1.Clear();
            listView1.Items.Clear();
            updatestatus("Opening Script File...");
            string ext = Path.GetExtension(ofd.FileName);

            if (ext == ".full") //handle openIV exporting pc scripts as *.ysc.full
            {
                ext = Path.GetExtension(Path.GetFileNameWithoutExtension(ofd.FileName));
            }
#if !DEBUG
            try
            {
#endif
            fileopen = new ScriptFile(ofd.OpenFile(), ext != ".ysc");
#if !DEBUG
        }
        catch (Exception ex)
        {
            updatestatus("Error decompiling script " + ex.Message);
            return;
        }
#endif
            updatestatus("Decompiled Script File, Time taken: " + (DateTime.Now - Start).ToString());
            MemoryStream ms = new MemoryStream();

            fileopen.Save(ms, false);


            foreach (KeyValuePair <string, Tuple <int, int> > locations in fileopen.Function_loc)
            {
                listView1.Items.Add(new ListViewItem(new string[] { locations.Key, locations.Value.Item1.ToString(), locations.Value.Item2.ToString() }));
            }
            fileopen.Close();
            StreamReader sr = new StreamReader(ms);
            ms.Position = 0;
            updatestatus("Loading Text in Viewer...");
            fctb1.Text = sr.ReadToEnd();
            SetFileName(filename);
            ScriptOpen = true;
            updatestatus("Ready, Time taken: " + (DateTime.Now - Start).ToString());
            if (ext != ".ysc")
            {
                ScriptFile.npi.savefile();
            }
            else
            {
                ScriptFile.X64npi.savefile();
            }

            bool exists = Directory.Exists(path + "\\decomplied");
            if (!exists)
            {
                Directory.CreateDirectory(path + "\\decomplied");
            }

            using (StreamWriter sw = new StreamWriter(path + "\\decomplied\\" + Path.GetFileNameWithoutExtension(ofd.FileName) + ".c4", true))
            {
                sw.WriteLine(fctb1.Text);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            ThreadLock = new object();
            Config     = new Ini.IniFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini"));
            if (!File.Exists(Config.path))
            {
                Config.IniWriteValue("Base", "IntStyle", "int");
                Config.IniWriteBool("Base", "Show_Array_Size", true);
                Config.IniWriteBool("Base", "Reverse_Hashes", true);
                Config.IniWriteBool("Base", "Declare_Variables", true);
                Config.IniWriteBool("Base", "Shift_Variables", true);
                Config.IniWriteBool("View", "Show_Nat_Namespace", true);
                Config.IniWriteBool("Base", "Show_Func_Pointer", false);
                Config.IniWriteBool("Base", "Use_MultiThreading", false);
                Config.IniWriteBool("Base", "Include_Function_Position", false);
                Config.IniWriteBool("Base", "Uppercase_Natives", false);
                Config.IniWriteBool("Base", "Hex_Index", false);
                Config.IniWriteBool("View", "Line_Numbers", true);
            }
            Find_Show_Array_Size();
            Find_Reverse_Hashes();
            Find_Declare_Variables();
            Find_Shift_Variables();
            Find_Show_Func_Pointer();
            Find_Use_MultiThreading();
            Find_IncFuncPos();
            Find_Nat_Namespace();
            Find_Hex_Index();
            Find_Upper_Natives();
            //Build NativeFiles from Directory if file exists, if not use the files in the resources
            string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                       "natives.dat");

            if (File.Exists(path))
            {
                nativefile = new NativeFile(File.OpenRead(path));
            }
            else
            {
                nativefile = new NativeFile(new MemoryStream(Properties.Resources.natives));
            }


            path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                "x64natives.dat");
            if (File.Exists(path))
            {
                x64nativefile = new x64NativeFile(File.OpenRead(path));
            }
            else
            {
                x64nativefile = new x64NativeFile(new MemoryStream(Properties.Resources.x64natives));
            }

            ScriptFile.npi      = new NativeParamInfo();
            ScriptFile.hashbank = new Hashes();

            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            else
            {
                DateTime Start = DateTime.Now;
                string   ext   = Path.GetExtension(args[0]);
                if (ext == ".full")                 //handle openIV exporting pc scripts as *.ysc.full
                {
                    ext = Path.GetExtension(Path.GetFileNameWithoutExtension(args[0]));
                }
                ScriptFile fileopen;
                Console.WriteLine("Decompiling " + args[0] + "...");
                try
                {
                    fileopen = new ScriptFile(File.OpenRead(args[0]), ext != ".ysc");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error decompiling script " + ex.Message);
                    return;
                }
                Console.WriteLine("Decompiled in " + (DateTime.Now - Start).ToString());
                fileopen.Save(File.OpenWrite(args[0] + ".c"), true);
                Console.WriteLine("Extracing native table...");
                StreamWriter fw = new StreamWriter(File.OpenWrite(args[0] + " native table.txt"));
                foreach (ulong nat in fileopen.X64NativeTable._nativehash)
                {
                    string temps = nat.ToString("X");
                    while (temps.Length < 16)
                    {
                        temps = "0" + temps;
                    }
                    fw.WriteLine(temps);
                }
                fw.Flush();
                fw.Close();
                Console.WriteLine("All done & saved!");
            }
        }