Esempio n. 1
0
        private void mScriptSearchButton_Click(object sender, EventArgs e)
        {
            ScriptSearchForm f = new ScriptSearchForm();

            f.ShowDialog();
            f.Dispose();
        }
Esempio n. 2
0
        private static string ShowLuaListing(byte[] luacCode)
        {
            string fileName = ".\\decompile.luac";

            File.WriteAllBytes(fileName, luacCode);

            string output = ScriptSearchForm.RunCommand(Program.Luac, " -l " + fileName, true);

            return(output);
        }
Esempio n. 3
0
        public static int LuacCodeSize(string luaSourceFile)
        {
            int    retVal = -1;
            string result = ScriptSearchForm.RunCommand(Program.Luac, " -s -o tmp.luac " + luaSourceFile, true);

            if (result.Length < 10)
            {
                FileInfo info = new FileInfo(".\\tmp.luac");
                retVal = (int)info.Length;
            }
            return(retVal);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName">the base .lvl file to splice the code into</param>
        /// <param name="newCode"></param>
        /// <returns>The file the data was saved to; null on error</returns>
        public string SpliceInNewCode(string newCode)
        {
            string tmpLuaFileName = ".\\_spliceTmp.lua";

            File.WriteAllText(tmpLuaFileName, newCode);

            string result = ScriptSearchForm.RunCommand(Program.Luac, " -s -o tmp.luac " + tmpLuaFileName, true);

            if (result.Trim() != "")
            {
                MessageBox.Show("Error compiling code", result);
                return(null);
            }
            byte[] newLuacCode = File.ReadAllBytes("tmp.luac");

            string newLvlFile = StringInputDlg.GetString("new lvl file name", "Save the file as what?>");

            if (newLvlFile != null)
            {
                try
                {
                    if (!String.IsNullOrEmpty(ScriptSearchForm.CurrentFile))
                    {
                        int lastSlash = ScriptSearchForm.CurrentFile.LastIndexOf(Path.DirectorySeparatorChar);
                        if (lastSlash > -1)
                        {
                            newLvlFile = tmpLuaFileName = ScriptSearchForm.CurrentFile.Substring(0, lastSlash + 1) + newLvlFile;
                        }
                    }
                    using (FileStream fs = File.OpenWrite(newLvlFile))
                    {
                        BinaryWriter bw = new BinaryWriter(fs);
                        bw.BaseStream.Write(mData, 0, (int)(this.BodyStart - 4));
                        bw.Write(newLuacCode.Length + 1);
                        bw.BaseStream.Write(newLuacCode, 0, newLuacCode.Length);
                        bw.BaseStream.Write(mData, (int)this.BodyEnd, (int)(mData.Length - this.BodyEnd));
                        bw.Close();
                        MessageBox.Show("Saved to " + newLvlFile);
                        return(newLvlFile);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Error splicing in new code");
                }
            }
            return(null);
        }
Esempio n. 5
0
        private void SearchForGivenText()
        {
            mListBox.Items.Clear();
            string searchString = mSearchTextBox.Text;

            string[]             lvlFiles = Directory.GetFiles(mDirectoryTextBox.Text, "*.lvl", SearchOption.AllDirectories);
            List <AssetListItem> items    = null;

            foreach (string file in lvlFiles)
            {
                // find items whose name contains the given text.
                items = ScriptSearchForm.GetItems(File.ReadAllBytes(file), ASCIIEncoding.ASCII.GetBytes("LuaP"));
                foreach (AssetListItem item in items)
                {
                    if (item.GetName().IndexOf(searchString) > -1)
                    {
                        mListBox.Items.Add(item);
                    }
                }
            }
            mStatusLabel.Text = mListBox.Items.Count + " Items found.";
        }
Esempio n. 6
0
        /*public string GetName()
         * {
         *  long loc = BinSearch.GetLocationOfGivenBytes(mLocation, ASCIIEncoding.ASCII.GetBytes("NAME"), mData, 80);
         *  if (loc > -1) return GetName(loc, mData);
         *  return "";
         * }*/
        /// <summary> Gets the name of the source file that was munged into this data. </summary>
        public string GetName()
        {
            int    headChunkLength = -1;
            string name            = "";
            long   loc1            = -1;
            long   loc             = BinSearch.GetLocationOfGivenBytes(mLocation, ASCIIEncoding.ASCII.GetBytes("scr_"), mData, 40);

            if (loc < 0)
            {
                loc1 = BinSearch.GetLocationOfGivenBytes(mLocation, ASCIIEncoding.ASCII.GetBytes("mcfg"), mData, 80);
                if (loc1 > 0)
                {
                    headChunkLength = ScriptSearchForm.GetLengthAtLocation(loc1 + 4, mData);
                    loc1            = BinSearch.GetLocationOfGivenBytes(loc1 + headChunkLength - 8, ASCIIEncoding.ASCII.GetBytes("scr_"), mData, 80);
                }
            }
            else
            {
                loc1 = loc;
            }

            if (loc1 > 0)
            {
                loc = BinSearch.GetLocationOfGivenBytes(loc1, ASCIIEncoding.ASCII.GetBytes("NAME"), mData, 80);
            }
            if (loc > -1)
            {
                int nameLen = mData[(int)loc + 4] - 1; // -1 for null byte
                if (loc > 0)
                {
                    // NAME + 4 bytes later = 8
                    name = Encoding.ASCII.GetString(mData, (int)loc + 8, (int)nameLen);
                }
            }
            return(name);
        }
Esempio n. 7
0
        private string GetBody()
        {
            long   loc     = BinSearch.GetLocationOfGivenBytes(mLocation, ScriptSearchForm.BodyBytes, mData);
            int    bodyLen = GetLengthAtLocation(loc + 4);
            string name    = GetName();

            string retVal = String.Format("-- NAME: {0} mLocation: 0x{1:x}; Body Length: {2}, Body Start: 0x{3:x}, Body End: 0x{4:x}",
                                          name, mLocation, bodyLen, loc + 8, loc + 8 + bodyLen);

            if (IsLuaCode)
            {
                if (ScriptSearchForm.ShowPcLuaCode)
                {
                    string sourceFileName = FindSourceFile(name);
                    string code           = LookupPCcode(sourceFileName);
                    int    sz             = ScriptSearchForm.LuacCodeSize(sourceFileName);
                    if (bodyLen == sz)
                    {
                        retVal += "\n-- ********* LUAC Code Size MATCH!!! ***********";
                        byte[] b = File.ReadAllBytes(".\\tmp.luac");
                        byte[] c = this.GetAssetData();
                        int    i = 0;
                        for (i = 0; i < c.Length; i++)
                        {
                            if (b[i] != c[i])
                            {
                                break;
                            }
                        }
                        if (i == c.Length)
                        {
                            retVal += "\n-- ********* Binary Equal !!! ***********";
                        }
                    }
                    retVal = retVal + string.Format("\n-- {0}\n-- PC luac code size = {1}; PC code:\n{2}", sourceFileName, sz, code);
                }
                else if (ScriptSearchForm.ShowDecompiledLuaCode)
                {
                    string listing = ShowLuaListing(this.GetAssetData());
                    string luaCode = "";
                    try
                    {
                        luaCode = DecompileLuacListing(listing);
                    }
                    catch (Exception ex)
                    {
                        luaCode = ex.Message + "\n" + ex.StackTrace;
                    }
                    retVal = string.Format("\n-- {0}\n{1}", GetName(), luaCode);
                }
                else
                {
                    string listing = ShowLuaListing(this.GetAssetData());
                    retVal = string.Format("\n-- {0}\n-- luac -l listing \n{1}", GetName(), listing);
                }
            }
            else
            {
                retVal = retVal + String.Format("\n-- 50 bytes, including the previous 30 bytes {0}", BinSearch.GetByteString(mLocation - 30, mData, 50));
            }
            return(retVal);
        }