private void mSearchButton_Click(object sender, EventArgs e)
        {
            if (File.Exists(mBigFileTextBox.Text))
            {
                byte[] bigFile = File.ReadAllBytes(mBigFileTextBox.Text);

                byte[] givenFileBytes = null;
                switch (mTypeComboBox.SelectedIndex)
                {
                case 0:     // search for a file in a bigger file.
                    if (File.Exists(mGivenFileTextBox.Text))
                    {
                        givenFileBytes = File.ReadAllBytes(mGivenFileTextBox.Text);
                    }
                    else
                    {
                        MessageBox.Show("File: " + mGivenFileTextBox.Text + " Not Found!");
                        return;
                    }
                    break;

                case 1:      // ASCII string
                    givenFileBytes = ASCIIEncoding.ASCII.GetBytes(mGivenFileTextBox.Text);
                    break;

                case 2:     // unicode string
                    givenFileBytes = UnicodeEncoding.Unicode.GetBytes(mGivenFileTextBox.Text);
                    break;
                }
                List <long> locations = BinSearch.GetLocationsOfGivenBytes(0L, givenFileBytes, bigFile);

                if (locations.Count > 0)
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (long loc in locations)
                    {
                        builder.Append(String.Format("0x{0:X2}\n", loc));
                    }
                    mFileLocationTextBox.Text = "Locations:\n " + builder.ToString();
                }
                else
                {
                    mFileLocationTextBox.Text = mGivenFileTextBox.Text + ": Not Found.";
                }
            }
        }
        private string FindTgaFileNames(string fileName)
        {
            String retVal = "";

            mMshPath = fileName.Substring(0, fileName.LastIndexOf('\\') + 1);

            byte[]      bytes  = File.ReadAllBytes(fileName);
            byte[]      search = Encoding.ASCII.GetBytes(".tga");
            List <long> locs   = BinSearch.GetLocationsOfGivenBytes(0, search, bytes);

            for (int i = 0; i < locs.Count; i++)
            {
                retVal = retVal + GetStringFromData(bytes, locs[i]) + ".tga";
                if (i != locs.Count - 1)
                {
                    retVal += "; ";
                }
            }
            return(retVal);
        }
Exemple #3
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);
        }
Exemple #4
0
        private static byte[] StripDC(byte[] data)
        {
            byte b = 0;

            byte[]      stripMe   = ASCIIEncoding.ASCII.GetBytes("dc:");
            List <long> locations = BinSearch.GetLocationsOfGivenBytes(0, stripMe, data);

            if (locations.Count == 0)
            {
                return(data);
            }

            List <byte> byteList = new List <byte>(data);

            for (int i = locations.Count - 1; i > -1; i--)
            {
                byteList.RemoveRange((int)locations[i], 3);
                // now, fix up the length of the string.
                b  = byteList[(int)locations[i] - 4];
                b -= 3;
                byteList[(int)locations[i] - 4] = b;
            }
            return(byteList.ToArray());
        }