示例#1
0
        static void TestUsingBinaryFile(string filename, string expected)
        {
            Console.WriteLine("Test using binary file...");
            var data = ReadAllBytes(filename);
            var tlsh = new TlshWrapper();
            var hash = tlsh.Hash(data);

            Console.WriteLine(hash);

            if (hash.Equals(expected, StringComparison.CurrentCultureIgnoreCase))
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("Failed");
            }
        }
示例#2
0
        static void BasicTest()
        {
            var data = "The best documentation is the UNIX source. After all, this is what the "
                       + "system uses for documentation when it decides what to do next! The "
                       + "manuals paraphrase the source code, often having been written at "
                       + "different times and by different people than who wrote the code. "
                       + "Think of them as guidelines. Sometimes they are more like wishes... "
                       + "Nonetheless, it is all too common to turn to the source and find "
                       + "options and behaviors that are not documented in the manual. Sometimes "
                       + "you find options described in the manual that are unimplemented "
                       + "and ignored by the source.";

            var tlsh = new TlshWrapper();
            var hash = tlsh.Hash(Encoding.UTF8.GetBytes(data));

            Console.WriteLine(hash);
            if (hash.Equals("6FF02BEF718027B0160B4391212923ED7F1A463D563B1549B86CF62973B197AD2731F8"))
            {
                Console.WriteLine("Equal");
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dir">dir to text</param>
        /// <param name="fileWithExpected">tlshGetter csv file output (c/o jaysonP)</param>
        static void TestAgainstTlshGetter(string dir, string fileWithExpected)
        {
            var dict = new Dictionary <string, string>();
            var tlsh = new TlshWrapper();

            using (var sw = new StreamWriter("tlsh.csv"))
            {
                foreach (var file in Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories))
                {
                    var sha1 = Hasher.ComputeSha1(file);
                    var data = ReadAllBytes(file);
                    var hash = tlsh.Hash(data);

                    if (!dict.ContainsKey(sha1))
                    {
                        dict.Add(sha1.ToLower(), hash.ToLower());
                    }

                    Console.WriteLine("sha1:{0} tlsh:{1}", sha1, hash);
                    sw.WriteLine("{0},{1},{2}", file, sha1, hash);
                }
            }


            // compare
            var expected = FileToDict(fileWithExpected);
            var result   = dict.Count == expected.Count && !dict.Except(expected).Any();

            var result1 = dict.All(x => expected.Any(y => x.Value == y.Value));

            if (result && result1)
            {
                Console.WriteLine("Passed");
            }
            else
            {
                Console.WriteLine("Failed");
            }
        }