Esempio n. 1
0
        private bool IsCorrectType(long current, byte[] data, byte[] searchBytes)
        {
            bool retVal = false;
            long loc    = BinSearch.GetLocationOfGivenBytes(current, searchBytes, data, 10);

            if (loc == current)
            {
                retVal = true;
            }

            return(retVal);
        }
Esempio n. 2
0
        private string GetInfo()
        {
            string retVal  = "";
            long   loc     = BinSearch.GetLocationOfGivenBytes(mLocation, ScriptSearchForm.BodyBytes, mData);
            long   infoLoc = BinSearch.GetLocationOfGivenBytesBackup(loc, ASCIIEncoding.ASCII.GetBytes("INFO"), mData, 20);

            if (infoLoc > -1)
            {
                retVal = String.Format("-- INFO 0x{0:x} 0x{1:x} 0x{2:x} 0x{3:x} 0x{4:x} 0x{5:x} 0x{6:x} 0x{7:x} ",
                                       mData[infoLoc + 4], mData[infoLoc + 5], mData[infoLoc + 6], mData[infoLoc + 7], mData[infoLoc + 8], mData[infoLoc + 9], mData[infoLoc + 10], mData[infoLoc + 11]);
            }
            return(retVal);
        }
Esempio n. 3
0
        public byte[] GetAssetData()
        {
            byte[] assetData = null;
            if (BinSearch.GetLocationOfGivenBytes(mLocation, ASCIIEncoding.ASCII.GetBytes("lvl_"), mData) == mLocation)
            {
                int bodyLen = GetLengthAtLocation(mLocation + 4);
                assetData = BinSearch.GetArrayChunk(mData, mLocation, bodyLen + 8);
            }
            else
            {
                long loc       = BinSearch.GetLocationOfGivenBytes(mLocation, ScriptSearchForm.BodyBytes, mData);
                int  bodyLen   = GetLengthAtLocation(loc + 4);
                long bodyStart = loc + 8;
                long bodyEnd   = loc + 8 + bodyLen;

                assetData = BinSearch.GetArrayChunk(mData, bodyStart, bodyLen);
            }
            return(assetData);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns AssetList items matching the search criteria
        /// </summary>
        /// <param name="data">The file bytes; something like 'File.ReadAllBytes(fileName);'</param>
        /// <param name="searchBytes">asset type; should be something like 'src_', 'tex_' or 'fx__'; but "LuaP" also works;
        ///  I use  'ASCIIEncoding.ASCII.GetBytes("LuaP")' often.
        ///  1-line usage:
        ///    'GetItems(File.ReadAllBytes(fileName),ASCIIEncoding.ASCII.GetBytes("LuaP"));'
        /// </param>
        /// <returns></returns>
        public static List <AssetListItem> GetItems(byte[] data, byte[] searchBytes)
        {
            List <long>          locations = BinSearch.GetLocationsOfGivenBytes(0L, searchBytes, data);
            List <AssetListItem> retVal    = new List <AssetListItem>();
            AssetListItem        item      = null;

            foreach (long loc in locations)
            {
                item = new AssetListItem(loc, data, searchBytes);
                if (BinSearch.GetLocationOfGivenBytes(loc, BodyBytes, data, 80L) > 0)
                {
                    retVal.Add(item);
                }
                else
                {
                    // NEED TO FIND OUT WHAT SOME OF THESE ARE!!!
                    // System.Diagnostics.Debugger.Log(1, "INFO", "Not adding item:" + item.ToString());
                    Console.Error.WriteLine("I don't know how to classify this item: " + item.ToString());
                    retVal.Add(item);
                }
            }
            return(retVal);
        }
Esempio n. 5
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. 6
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);
        }