Beispiel #1
0
        static void Main(string[] args)
        {
            //HashDictionary hashDic = new HashDictionary();
            //HashCreator hashCreator = new HashCreator(hashDic, Hasher.HasherType.WAR);

            //hashCreator.ParseFilenames(
            //    "D:/Development/GoogleCode/EasyMYP/HashTesterConsole/HashTesterConsole/bin/Debug/tor_filenames.txt");
            //hashCreator.Save();

            Hasher hTOR = new Hasher(Hasher.HasherType.TOR);
            Hasher hWAR = new Hasher(Hasher.HasherType.WAR);
            uint seed = 0xDEADBEEF;
            string sTST = "teststring/2345/somemore/andagain.ext";
            hTOR.Hash(sTST, seed);
            hWAR.Hash(sTST, seed);

            if (hTOR.sh == hWAR.sh)
            {
                if (hTOR.ph == hWAR.ph)
                {
                    seed = 0;
                }
            }
        }
Beispiel #2
0
        long TreatPatternLine(string line, Hasher warhash)
        {
            long result = 0;
            string[] spl_str = line.Replace("[0-9]", "|").Split('|');
            string format = "";
            int occurence = spl_str.Length - 1;
            UpdateResults updResult = UpdateResults.NOT_FOUND;

            if (occurence <= HashCreatorConfig.MaxCombinationPerPattern) //9 = max_int
            {
                long max = (long)Math.Pow(10, occurence);

                for (int i = 0; i < occurence; i++)
                {
                    format += "0";
                }

                for (long i = 0; i < max && active; i++)
                {
                    string cur_i = i.ToString(format);

                    string cur_str = "";

                    //creates the new filename
                    for (int j = 0; j < occurence; j++)
                    {
                        cur_str += spl_str[j];
                        cur_str += cur_i[j];
                    }
                    cur_str += spl_str[occurence];

                    warhash.Hash(cur_str, 0xDEADBEEF);
                    // Thread-safe ???
                    updResult = patternTestHashDic.UpdateHash(warhash.ph, warhash.sh, cur_str, 0);
                    if (updResult == UpdateResults.NAME_UPDATED || updResult == UpdateResults.ARCHIVE_UPDATED)
                        result++;

                    //string brute_str = "";
                    //brute_str = string.Format("{0:X8}#{1:X8}#{2}", (uint)(warhash.ph), (uint)(warhash.sh), cur_str);
                    //AddBruteLine(brute_str);
                }
            }
            return result;
        }
Beispiel #3
0
        /// <summary>
        /// Tries all filenames (complete path) included in the fullFileNameFile file.
        /// </summary>
        /// <param name="fullFileNameFile"></param>
        /// <returns> number of newly found filenames</returns>
        public long ParseFilenames(string fullFileNameFile)
        {
            Start();
            hashDic.CreateHelpers();
            long result = 0;
            if (File.Exists(fullFileNameFile))
            {
                Hasher warhash = new Hasher(hasherType);

                //Read the file
                FileStream fs = new FileStream(fullFileNameFile, FileMode.Open);
                StreamReader reader = new StreamReader(fs);

                HashSet<string> fileList = new HashSet<string>();

                string line;
                while ((line = reader.ReadLine()) != null)
                    fileList.Add(line.ToLower().Replace('\\', '/'));

                reader.Close();
                fs.Close();

                // strip input file from duplicates.
                File.Delete(fullFileNameFile);
                fs = new FileStream(fullFileNameFile, FileMode.Create);
                StreamWriter writer = new StreamWriter(fs);

                foreach (string file in fileList)
                    writer.WriteLine(file);

                writer.Close();
                fs.Close();

                foundNames = new Dictionary<string, bool>();

                foreach (string fn in fileList)
                {
                    foundNames[fn] = false;
                }

                //Just in case someday we want to multi thread.
                parseFileList = fileList.GetEnumerator();
                string filename;
                while ((filename = GetFileName_ParseFilenames()) != null)
                {

                    warhash.Hash(filename, 0xDEADBEEF);
                    UpdateResults found = hashDic.UpdateHash(warhash.ph, warhash.sh, filename, 0);
                    if (found == UpdateResults.NAME_UPDATED || found == UpdateResults.ARCHIVE_UPDATED)
                        result++;
                    if (found != UpdateResults.NOT_FOUND)
                        foundNames[filename] = true;
                }
                if (active)
                {
                    string outputFileRoot = Path.GetDirectoryName(fullFileNameFile) + "/" + Path.GetFileNameWithoutExtension(fullFileNameFile);
                    FileStream ofsFound = new FileStream(outputFileRoot + "-found.txt", FileMode.Create);
                    FileStream ofsNotFound = new FileStream(outputFileRoot + "-notfound.txt", FileMode.Create);
                    StreamWriter swf = new StreamWriter(ofsFound);
                    StreamWriter swnf = new StreamWriter(ofsNotFound);

                    foreach (KeyValuePair<string, Boolean> file in foundNames)
                        if (file.Value == true)
                        {
                            warhash.Hash(file.Key, 0xDEADBEEF);
                            swf.WriteLine("{0:X8}" + HashDictionary.hashSeparator
                                + "{1:X8}" + HashDictionary.hashSeparator
                                + "{2}", warhash.ph, warhash.sh, file.Key);
                        }
                        else
                        {
                            //this is a quick and dirty fix to get some more debug info
                            // to be removed in the future !!!
                            warhash.Hash(file.Key, 0xDEADBEEF);
                            //swnf.WriteLine("{0:X8}" + HashDictionary.hashSeparator
                            //    + "{1:X8}" + HashDictionary.hashSeparator
                            //    + "{2}", warhash.ph, warhash.sh, file.Key);
                            swnf.WriteLine(file.Key);
                        }

                    swnf.Close();
                    swf.Close();
                    ofsFound.Close();
                    ofsNotFound.Close();
                }
            }
            return result;
        }
Beispiel #4
0
        private void calc(object parameter)
        {
            Hasher warhash = new Hasher(hasherType);
            HashSet<string> dirList = ((ThreadParam)parameter).dirList;
            HashSet<string> filenameList = ((ThreadParam)parameter).filenameList;
            HashSet<string> extensionList = ((ThreadParam)parameter).extensionList;
            int jstart = ((ThreadParam)parameter).jstart;
            int jend = ((ThreadParam)parameter).jend;
            string outputFileRoot = ((ThreadParam)parameter).outputFileRoot;

            long filenamesFoundinThread = 0;

            //string[] dirListPart;
            //if (dirList.Count != 0)
            //{
            //    dirListPart = new string[dirList.Count];
            //    dirList.CopyTo(dirListPart);
            //    for (int j = jstart; j < jend; j++)
            //        dirListPart[j] += '/';
            //}
            //else
            //{
            //    dirListPart = new String[1];
            //    dirListPart.SetValue("", 0);
            //    jstart = 0;
            //    jend = 1;
            //}

            if (extensionList.Count == 0)
            {
                extensionList.Add("");
            }

            string directoryName;
            // get the directory name from the pool
            // Also allows for a cleaner exit if necessary through the Stop method
            while ((directoryName = GetDirectoryFromPoolManager()) != null)
            {
                foreach (string filename in filenameList)
                {
                    foreach (string extension in extensionList)
                    {
                        string cur_str = directoryName + filename;
                        // We may have a problem with files ending with '.' ?
                        if (extension.CompareTo("") != 0)
                            cur_str += "." + extension;

                        cur_str = cur_str.Replace('\\', '/').ToLower();
                        warhash.Hash(cur_str, 0xDEADBEEF);
                        // not that sure if UpdateHash is really Thread Safe...
                        UpdateResults found = hashDic.UpdateHash(warhash.ph, warhash.sh, cur_str, 0);
                        if (found == UpdateResults.NAME_UPDATED || found == UpdateResults.ARCHIVE_UPDATED)
                        {
                            filenamesFoundinThread++;
                        }
                        if (outputFileRoot != null)
                            if (found != UpdateResults.NOT_FOUND)
                                lock (lock_filefound) // may move this lock to the end of the loop.
                                {
                                    foundNames[filename] = true;
                                }
                    }
                }
                TriggerFilenameTestEvent(new MYPFilenameTestEventArgs(Event_FilenameTestType.TestRunning, extensionList.Count));
            }

            if (filenamesFoundinThread != 0)
                lock (lock_filefound)
                {
                    filenamesFoundInTest += filenamesFoundinThread;
                }
        }
Beispiel #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileNameFile"></param>
        /// <param name="dirNameFile"></param>
        /// <param name="extNameFile"></param>
        /// <returns></returns>
        public long ParseDirFilenamesExt(string fileNameFile, string dirNameFile, string extNameFile)
        {
            Start();
            //hashDic.CreateHelpers();
            long result = 0;
            if (File.Exists(fileNameFile) && File.Exists(dirNameFile))
            {
                Hasher warhash = new Hasher(hasherType);
                UpdateResults found = UpdateResults.NOT_FOUND;

                //fileoutput
                string outputFileRoot = Path.GetDirectoryName(fileNameFile) + "/" + Path.GetFileNameWithoutExtension(fileNameFile);
                FileStream ofsFound = new FileStream(outputFileRoot + "-found.txt", FileMode.Create);
                FileStream ofsNotFound = new FileStream(outputFileRoot + "-notfound.txt", FileMode.Create);
                StreamWriter swf = new StreamWriter(ofsFound);
                StreamWriter swnf = new StreamWriter(ofsNotFound);

                //Read the file
                FileStream fs = new FileStream(fileNameFile, FileMode.Open);
                StreamReader fs_reader = new StreamReader(fs);
                FileStream ds = new FileStream(dirNameFile, FileMode.Open);
                StreamReader ds_reader = new StreamReader(ds);
                FileStream es = new FileStream(extNameFile, FileMode.Open);
                StreamReader es_reader = new StreamReader(es);

                HashSet<string> fileList = new HashSet<string>();
                HashSet<string> dirList = new HashSet<string>();
                HashSet<string> extList = new HashSet<string>();

                string line;
                while ((line = ds_reader.ReadLine()) != null)
                    dirList.Add(line.ToLower().Replace('\\', '/').Replace("//", "/"));

                ds_reader.Close();
                ds.Close();

                while ((line = es_reader.ReadLine()) != null)
                    extList.Add(line.ToLower().Replace('\\', '/').Replace("//", "/"));

                es_reader.Close();
                es.Close();

                string tempExt = "";
                while ((line = fs_reader.ReadLine()) != null)
                {
                    tempExt = "";
                    if (line.Contains("."))
                    {
                        tempExt = line.Substring(line.LastIndexOf('.') + 1);
                    }
                    if (extList.Contains(tempExt))
                    {
                        line = line.Substring(0, line.LastIndexOf('.'));
                    }
                    else if (tempExt != "")
                    {
                        // extList.Add(tempExt);
                    }
                    fileList.Add(line.ToLower().Replace('\\', '/').Replace("//", "/"));
                }

                fs_reader.Close();
                fs.Close();

                // strip input file from duplicates.
                File.Delete(fileNameFile);
                fs = new FileStream(fileNameFile, FileMode.Create);
                StreamWriter fs_writer = new StreamWriter(fs);

                foreach (string file in fileList)
                    fs_writer.WriteLine(file);

                fs_writer.Close();
                fs.Close();

                // strip input dir file from duplicates.
                File.Delete(dirNameFile);
                ds = new FileStream(dirNameFile, FileMode.Create);
                StreamWriter ds_writer = new StreamWriter(ds);

                foreach (string dir in dirList)
                    ds_writer.WriteLine(dir);

                ds_writer.Close();
                ds.Close();

                // strip input ext file from duplicates.
                File.Delete(extNameFile);
                es = new FileStream(extNameFile, FileMode.Create);
                StreamWriter es_writer = new StreamWriter(es);

                foreach (string ext in extList)
                    es_writer.WriteLine(ext);

                es_writer.Close();
                es.Close();

                //generate the whole dir / filename listing possible
                foreach (string d in dirList)
                {
                    foreach (string f in fileList)
                    {
                        foreach (string e in extList)
                        {
                            line = d + '/' + f + "." + e;
                            line = line.Replace("//", "/").Replace("//", "/");
                            // fullFileList.Add(line);

                            warhash.Hash(line, 0xDEADBEEF);
                            found = hashDic.UpdateHash(warhash.ph, warhash.sh, line, 0);
                            if (found == UpdateResults.NAME_UPDATED || found == UpdateResults.ARCHIVE_UPDATED)
                            {
                                result++;
                                swf.WriteLine(line);
                            }
                            else if (found == UpdateResults.NOT_FOUND)
                            {
                                //swnf.WriteLine("{0:X8}" + HashDictionary.hashSeparator
                                //    + "{1:X8}" + HashDictionary.hashSeparator
                                //    + "{2}", warhash.ph, warhash.sh, file.Key);
                                //swnf.WriteLine(line);
                            }
                        }
                    }
                }

                swnf.Close();
                swf.Close();
                ofsFound.Close();
                ofsNotFound.Close();
            }
            return result;
        }