Beispiel #1
0
        public bool Edit(SM_USER user)
        {
            try
            {
                SM_USER editedUser = DB.SM_USER.SingleOrDefault(u => u.ID_User == user.ID_User);

                if (!user.TX_Email.Equals(editedUser.TX_Email))
                {
                    return(false);
                }
                editedUser.TX_Email          = user.TX_Email;
                editedUser.TX_FirstName      = user.TX_FirstName;
                editedUser.TX_SecondName     = user.TX_SecondName;
                editedUser.TX_LastName       = user.TX_LastName;
                editedUser.TX_SecondLastName = user.TX_SecondLastName;
                editedUser.TX_Phone          = user.TX_Phone;

                if (user.PasswordChanged)
                {
                    editedUser.TX_Password = HashHandler.CreateHash(user.TX_Password);
                }

                DB.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #2
0
        public void ScanFile(string filePath)
        {
            ThreadPool.QueueUserWorkItem(async i =>
            {
                var scanJob = new ScanJob(filePath);
                Task <InfoModel> infoModel    = VirusTotalScanner.ScanFile(scanJob);
                List <YaraResult> yaraResults = new List <YaraResult>();
                string scanMessage            = null;
                try
                {
                    yaraResults = YaraScanner.ScanFile(scanJob);
                }
                catch (Exception e)
                {
                    scanMessage = e.Message;
                }

                InfoModel model   = await infoModel;
                model.YaraResults = yaraResults;

                // Check if virus total throw error
                model.Date = DateTime.Now;
                if (model.ScandId == null)
                {
                    byte[] modelToBytes = Encoding.UTF8.GetBytes(model.GetHashCode().ToString());
                    model.SHA1          = HashHandler.ComputeSha1Hash(modelToBytes);
                    model.SHA256        = HashHandler.ComputeSha256Hash(modelToBytes);
                    model.ScandId       = model.SHA256;
                    model.FilePath      = scanJob.mFilePath;
                    model.Positives     = 0;
                    model.Total         = 0;
                    model.ReportTag     = Tag.WARNING;
                }
                else
                {
                    if (model.Positives == 0 && model.YaraResults.Count == 0)
                    {
                        model.ReportTag = Tag.OK;
                    }
                    else if (model.Positives == 0 && model.YaraResults.Count > 0)
                    {
                        model.ReportTag = Tag.WARNING;
                    }
                    else
                    {
                        model.ReportTag = Tag.DANGER;
                    }
                }

                if (scanMessage != null)
                {
                    model.Messages.Add(scanMessage);
                }

                foreach (IListener listener in GetListeners().Keys)
                {
                    listener.OnFileScanned(model);
                }
            });
        }
Beispiel #3
0
        public void ComputeSha256Hash_AreEqual_True()
        {
            string Input          = "cryptographic hash functions";
            string ExpectedOutput = "b8921348ed613a01d5ace11c754f459214b6f81d5e7937354c561eb25fb9e7ce";
            string Output         = HashHandler.ComputeSha256Hash(Input);
            string ErrorFeedback  = $"Incorrect Values: Expected - {ExpectedOutput}, Received - {Output} ";

            Assert.AreEqual(ExpectedOutput, Output, ErrorFeedback);
        }
Beispiel #4
0
        public IActionResult Login(LoginRequestDto request, [FromServices] IStudentsDbService isdbs)
        {
            var salt  = isdbs.getSalt(request.Eska);
            var passw = HashHandler.CreateHash(request.Haslo, salt);


            using (var con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s18309;Integrated Security=True"))
                using (var com = new SqlCommand())
                {
                    com.Connection  = con;
                    com.CommandText = ("select 1  from Student where IndexNumber = @index AND Password = @Pass");
                    com.Parameters.AddWithValue("Pass", passw);
                    com.Parameters.AddWithValue("index", request.Eska);


                    con.Open();

                    var dr = com.ExecuteReader();

                    if (!dr.Read())
                    {
                        return(BadRequest("Wrong login or password"));
                    }
                }

            //=-----------------------------------------------------------------------------
            var claims = new[] {
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim(ClaimTypes.Name, "1"),
                new Claim(ClaimTypes.Role, "employee"),
                new Claim(ClaimTypes.Role, "student")
            };

            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("DefinietlyNotASecretKeyasd213qwsdeq234123saw"));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(
                issuer: "Gakko",
                audience: "Students",
                claims: claims,
                expires: DateTime.Now.AddMinutes(10),
                signingCredentials: creds
                );
            var refreshTokenik = Guid.NewGuid();

            isdbs.SetREFRESHTOKEN(request.Eska, refreshTokenik.ToString());
            return(Ok(new
            {
                token = new JwtSecurityTokenHandler().WriteToken(token),
                refreshToken = refreshTokenik
            }));
        }
Beispiel #5
0
        public void CalculateHash_AreEqual_True()
        {
            int    index          = 2;
            string previousHash   = "b8921348ed613a01d5ace11c754f459214b6f81d5e7937354c561eb25fb9e7ce";
            string timeStamp      = "1512845815";
            string data           = "Test Block";
            int    nonce          = 0;
            string ExpectedOutput = "1d2fbc9e5b458798d667b24386f6a76f0bd24268e184e209bf4cc51d6168b24e";
            string Output         = HashHandler.CalculateHash(index.ToString(), previousHash, timeStamp, data, nonce);
            string ErrorFeedback  = $"Incorrect Values: Expected - {ExpectedOutput}, Received - {Output} ";

            Assert.AreEqual(ExpectedOutput, Output, ErrorFeedback);
        }
Beispiel #6
0
        private void btnCheckValue_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var fullPath = openFileDialog1.FileName;
                var text     = System.IO.File.ReadAllText(fullPath, Encoding.ASCII);

                var hash   = new HashHandler();
                var result = hash.ConvertFromHash(text);
                MessageBox.Show("Start : " + result.Start.ToString("dd.MM.yyyy") + " - End : " + result.End.ToString("dd.MM.yyyy HH.mm.ss"));
            }
        }
Beispiel #7
0
        public SM_USER Create(SM_USER user)
        {
            try
            {
                user.TX_Password = HashHandler.CreateHash(user.TX_Password);

                DB.SM_USER.Add(user);
                DB.SaveChanges();
                return(DB.SM_USER.OrderByDescending(x => x.ID_User).FirstOrDefault());
            }
            catch (Exception ex)
            {
                return(user);
            }
        }
Beispiel #8
0
        public void CalculateHashForBlock_AreEqual_True()
        {
            int    index        = 2;
            string previousHash = "b8921348ed613a01d5ace11c754f459214b6f81d5e7937354c561eb25fb9e7ce";
            long   timeStamp    = 1512845815;
            string data         = "Test Block";
            string hash         = "d1436fa411c6072a89ba0de742c6703a428b7477105decf544254fee7bb23282";
            int    difficulty   = 0;
            int    nonce        = 0;

            Block block = new Block(index, previousHash, timeStamp, data, hash, difficulty, nonce);

            string ExpectedOutput = "1d2fbc9e5b458798d667b24386f6a76f0bd24268e184e209bf4cc51d6168b24e";
            string Output         = HashHandler.CalculateHashForBlock(block);

            string ErrorFeedback = $"Incorrect Values: Expected - {ExpectedOutput}, Received - {Output} ";

            Assert.AreEqual(ExpectedOutput, Output, ErrorFeedback);
        }
Beispiel #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var start = new DateTime(dtpStart.Value.Year, dtpStart.Value.Month, dtpStart.Value.Day, 0, 0, 0);
                var end   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

                var hash         = new HashHandler();
                var stringToSave = hash.ConvertFromStartEnd(start, end);

                var defaultPath     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                var defaultFilename = "Numerolog." + start.ToString("dd.MM.yyyy") + "-" + end.ToString("dd.MM.yyyy") + ".ins";

                saveFileDialog1.InitialDirectory             = defaultPath;
                saveFileDialog1.FileName                     = defaultFilename;
                saveFileDialog1.Filter                       = "Installation file|*.ins";
                saveFileDialog1.Title                        = "Save hash file";
                saveFileDialog1.OverwritePrompt              = true;
                saveFileDialog1.CheckPathExists              = true;
                saveFileDialog1.AddExtension                 = true;
                saveFileDialog1.SupportMultiDottedExtensions = true;
                saveFileDialog1.DefaultExt                   = ".ins";

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if (string.IsNullOrEmpty(saveFileDialog1.FileName))
                    {
                        MessageBox.Show("No filename was provided.");
                        return;
                    }

                    defaultFilename = Path.Combine(saveFileDialog1.InitialDirectory, saveFileDialog1.FileName);
                    System.IO.File.WriteAllText(defaultFilename, stringToSave, Encoding.ASCII);

                    MessageBox.Show("Successfully saved.", "Confirmation", MessageBoxButtons.OK);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc != null ? exc.Message : "Failed to save.", "Oops...", MessageBoxButtons.OK);
            }
        }
Beispiel #10
0
        public async Task <CTO <bool> > SubmitHashes()
        {
            var hashHandler = new HashHandler();

            var requestItem = new HashCrackRequestItem();

            requestItem.HashType      = HashTypes.MD5;
            requestItem.MaximumLength = 50;
            requestItem.MinimumLength = 1;
            requestItem.Hashes        = new List <string> {
                Hashes
            };

            ; var result = await hashHandler.SubmitHashes(requestItem);

            if (result.HasError)
            {
                return(new CTO <bool>(false, result.Exception));
            }

            return(new CTO <bool>(true));
        }
Beispiel #11
0
        private SM_USER AuthenticateWithUserAndPassword(string useremail, string password, int application)
        {
            try
            {
                var user = DB.SM_USER.SingleOrDefault(x => x.TX_Email.Equals(useremail));

                if (user == null)
                {
                    return(null);
                }

                if (!HashHandler.Validate(password, user.TX_Password))
                {
                    return(null);
                }

                return(user.WithoutPassword());
            }
            catch (Exception e)
            {
                return(null);
            }
        }
 public string GenerateCode(UrlModelDto dto)
 {
     try
     {
         string   code  = HashHandler.Hash(dto.MainLink) + GetLastUrlAddressId().ToString().PadLeft(4, '0');
         UrlModel model = new UrlModel()
         {
             MainLink  = dto.MainLink,
             ShortLink = code,
             ViewCount = 0,
             CreateIp  = dto.CreateIp
         };
         if (DataAccess.Insert(model) <= 0)
         {
             throw new Exception("خطا در سرور");
         }
         return(code);
     }
     catch (Exception ex)
     {
         AddException(ex);
         return("");
     }
 }
        /// <summary>
        /// Check if dependencies are all OK
        /// </summary>
        private static void CheckDependencies()
        {
            // Check internet connection
            Console.Write("Verifying internet connection . . . ");
            if (NetworkInterface.GetIsNetworkAvailable())
            {
                Console.Write("OK!");
                Console.WriteLine();
            }
            else
            {
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine("You are not connected to the internet, the application cannot function without it!");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(2);
            }

            var hap = "HtmlAgilityPack.dll";

            if (File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Verifying HAP MD5 hash . . . ");

                var hash = HashHandler.CalculateMD5(hap);

                if (hash.md5 != HashHandler.HAP_HASH && hash.error == false)
                {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine("Deleting the invalid HAP file.");

                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }

                    // delete HAP file as it couldn't be verified
                }
                else if (hash.error)
                {
                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                if (debug)
                {
                    Console.WriteLine($"Generated hash: {hash.md5}");
                    Console.WriteLine($"Known hash:     {HashHandler.HAP_HASH}");
                }
            }

            if (!File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Attempting to download HtmlAgilityPack.dll . . . ");

                try {
                    using (var webClient = new WebClient()) {
                        webClient.DownloadFile($"https://github.com/ElPumpo/TinyNvidiaUpdateChecker/releases/download/v{offlineVer}/HtmlAgilityPack.dll", "HtmlAgilityPack.dll");
                    }

                    Console.Write("OK!");
                    Console.WriteLine();
                } catch (Exception ex) {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine();
                }
            }

            // compare HAP version, too
            var currentHapVersion = AssemblyName.GetAssemblyName(hap).Version.ToString();

            if (new Version(HashHandler.HAP_VERSION).CompareTo(new Version(currentHapVersion)) != 0)
            {
                Console.WriteLine($"ERROR: The current HAP libary v{currentHapVersion} does not match the required v{HashHandler.HAP_VERSION}");
                Console.WriteLine("The application will not continue to prevent further errors");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(1);
            }

            if (SettingManager.ReadSettingBool("Minimal install"))
            {
                if (LibaryHandler.EvaluateLibary() == null)
                {
                    Console.WriteLine("Doesn't seem like either WinRAR or 7-Zip is installed! We are disabling the minimal install feature for you.");
                    SettingManager.SetSetting("Minimal install", "false");
                }
            }

            Console.WriteLine();
        }
        /// <summary>
        /// Check if dependencies are all OK
        /// </summary>
        private static void CheckDependencies()
        {
            // Check internet connection
            Console.Write("Verifying internet connection . . . ");
            switch (NetworkInterface.GetIsNetworkAvailable())
            {
            case true:
                Console.Write("OK!");
                Console.WriteLine();
                break;

            default:
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine("No internet connection was found, the application will now terminate!");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(2);
                break;
            }

            var hap = "HtmlAgilityPack.dll";

            if (File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Verifying HAP hash . . . ");
                var hash = HashHandler.CalculateMD5(hap);

                if (hash.md5 != HashHandler.HAP_HASH && hash.error == false)
                {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine("Deleting the invalid HAP file.");

                    try {
                        //fFile.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }

                    // delete HAP file as it couldn't be verified
                }
                else if (hash.error)
                {
                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                if (debug)
                {
                    Console.WriteLine("Generated hash: " + hash.md5);
                    Console.WriteLine("Known hash:     " + HashHandler.HAP_HASH);
                }
            }

            if (!File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Attempting to download HtmlAgilityPack.dll . . . ");

                try {
                    using (WebClient webClient = new WebClient()) {
                        webClient.DownloadFile($"https://github.com/ElPumpo/TinyNvidiaUpdateChecker/releases/download/v{offlineVer}/HtmlAgilityPack.dll", "HtmlAgilityPack.dll");
                    }
                    Console.Write("OK!");
                    Console.WriteLine();
                } catch (Exception ex) {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine();
                }
            }
            var currentHapVersion = AssemblyName.GetAssemblyName(hap).Version.ToString();

            // compare HAP version too
            if (new Version(HashHandler.HAP_VERSION).CompareTo(new Version(currentHapVersion)) > 0)
            {
                Console.WriteLine("ERROR: The current HAP libary v{0} does not match the wanted v{1}", currentHapVersion, HashHandler.HAP_VERSION);
                Console.WriteLine("The application has been terminated to prevent a error message by .NET");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(1);
            }

            if (SettingManager.ReadSettingBool("Minimal install"))
            {
                if (LibaryHandler.EvaluateLibary() == null)
                {
                    Console.WriteLine("Doesn't seem like either WinRAR or 7-Zip is installed!");
                    DialogResult dialogUpdates = MessageBox.Show("Do you want to disable the minimal install feature and use the traditional way?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dialogUpdates == DialogResult.Yes)
                    {
                        SettingManager.SetSetting("Minimal install", "false");
                    }
                    else
                    {
                        Console.WriteLine("The application will terminate itself");
                        if (showUI)
                        {
                            Console.ReadKey();
                        }
                        Environment.Exit(1);
                    }
                }
            }

            Console.WriteLine();
        }
Beispiel #15
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!local)
            {
                try
                {
                    var files   = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.ins");
                    var authDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Auth");
                    var hash    = new HashHandler();
                    if (files == null || files.Length == 0)
                    {
                        // Check PC name in other directory
                        var di = new DirectoryInfo(authDir);
                        if (!di.Exists)
                        {
                            MessageBox.Show("No license file was provided.");
                            ShutDownForm();
                        }
                        else
                        {
                            var dirFiles = Directory.GetFiles(authDir, "*.ins");
                            if (dirFiles == null)
                            {
                                MessageBox.Show("No license file was provided.");
                                ShutDownForm();
                            }
                            else if (dirFiles.Length == 1)
                            {
                                var text       = System.IO.File.ReadAllText(dirFiles[0], Encoding.ASCII);
                                var licensedPC = hash.Decode(text);
                                if (string.IsNullOrEmpty(licensedPC))
                                {
                                    MessageBox.Show("Empty license file.");
                                    ShutDownForm();
                                }
                                else if (!Environment.MachineName.Equals(licensedPC))
                                {
                                    MessageBox.Show("Application was licensed for other PC...WTF, bro?");
                                    ShutDownForm();
                                }
                            }
                            else if (dirFiles.Length > 1)
                            {
                                MessageBox.Show("More than 1 license file exists...WTF?");
                                ShutDownForm();
                            }
                        }
                    }
                    else if (files.Length == 1)
                    {
                        var text = System.IO.File.ReadAllText(files[0], Encoding.ASCII);

                        var result = hash.ConvertFromHash(text);
                        var now    = DateTime.Now;
                        if (result == null)
                        {
                            MessageBox.Show("Broken activation file.");
                            ShutDownForm();
                        }
                        else if (now < result.Start || now > result.End)
                        {
                            MessageBox.Show("You can activate app in this interval of dates only: " + result.Start.ToString("dd.MM.yyyy HH.mm.ss") + " - " + result.End.ToString("dd.MM.yyyy HH.mm.ss"));
                            ShutDownForm();
                        }
                        else
                        {
                            // App may be activated
                            var di = new DirectoryInfo(authDir);
                            if (!di.Exists)
                            {
                                di.Create();
                            }
                            else
                            {
                                var dirFiles = di.GetFiles();
                                for (int i = 0; i < dirFiles.Length; i++)
                                {
                                    var f = new FileInfo(dirFiles[i].FullName);
                                    f.Delete();
                                }
                            }

                            var fi           = new FileInfo(files[0]);
                            var stringToSave = hash.Encode(Environment.MachineName);
                            File.WriteAllText(Path.Combine(authDir, fi.Name), stringToSave, Encoding.ASCII);
                            File.Delete(files[0]);
                            AppShortcutToDesktop("Numerology");
                            MessageBox.Show("Successfully activated for : " + Environment.MachineName);
                        }
                    }
                    else if (files.Length > 1)
                    {
                        MessageBox.Show("There are more than 1 .ins file in start directory.");
                        ShutDownForm();
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Error, while authentication check: " + exc.Message);
                    ShutDownForm();
                }
                this.Text = "Нумерология (licensed for: " + Environment.MachineName + ").";
            }
            else
            {
                // For Yana only
                this.Text = "Нумерология (private version).";
            }

            if (!isAuthProblem)
            {
                InitUI();
                numerologyObject = InitNumerologyObject();

                var customersFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CUSTOMER_FOLDER_NAME);
                if (!Directory.Exists(customersFolderPath))
                {
                    Directory.CreateDirectory(customersFolderPath);
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Check if dependencies are all OK
        /// </summary>
        private static void CheckDependencies()
        {
            // Check internet connection
            Console.Write("Searching for a network connection . . . ");
            switch (NetworkInterface.GetIsNetworkAvailable())
            {
            case true:
                Console.Write("OK!");
                Console.WriteLine();
                break;

            default:
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine("No network connection was found, the application will now determinate!");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(2);
                break;
            }
            var hap = "HtmlAgilityPack.dll";

            if (File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Verifying HAP hash . . . ");
                var hash = HashHandler.CalculateMD5(hap);

                if (hash.md5 != HashHandler.HASH_HAP && hash.error == false)
                {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine("Deleting the invalid HAP file.");

                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }

                    // delete HAP file as it couldn't be verified
                }
                else if (hash.error)
                {
                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                if (debug)
                {
                    Console.WriteLine("Generated hash: " + hash.md5);
                    Console.WriteLine("Known hash:     " + HashHandler.HASH_HAP);
                }
            }

            if (!File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Attempting to download HtmlAgilityPack.dll . . . ");

                try {
                    using (WebClient webClient = new WebClient()) {
                        webClient.DownloadFile("https://github.com/ElPumpo/TinyNvidiaUpdateChecker/releases/download/v" + offlineVer + "/HtmlAgilityPack.dll", "HtmlAgilityPack.dll");
                    }
                    Console.Write("OK!");
                    Console.WriteLine();
                } catch (Exception ex) {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine();
                }
            }

            if (ShouldMakeInstaller)
            {
                if (LibaryHandler.EvaluateLibary() == null)
                {
                    Console.WriteLine("Doesn't seem like either WinRAR or 7-Zip is installed!");
                    DialogResult dialogUpdates = MessageBox.Show("Do you want to disable the minimal install feature and use the traditional way?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dialogUpdates == DialogResult.Yes)
                    {
                        SettingManager.SetSetting("Minimal install", "false");
                    }
                    else
                    {
                        Console.WriteLine("The application will determinate itself");
                        if (showUI)
                        {
                            Console.ReadKey();
                        }
                        Environment.Exit(1);
                    }
                }
            }

            Console.WriteLine();
        }
Beispiel #17
0
        public void Node_ManualSetCheck_Equal()
        {
            Node L1    = new Node();
            Node L2    = new Node();
            Node L1_L2 = new Node();

            Node L3    = new Node();
            Node L4    = new Node();
            Node L3_L4 = new Node();

            Node MerkleRoot = new Node();

            //Set Values
            L1.Value = HashHandler.ComputeSha256Hash("test1");
            L2.Value = HashHandler.ComputeSha256Hash("test2");
            string test = L1.Value + L1.Value;

            L1_L2.Value = HashHandler.ComputeSha256Hash(L1.Value + L1.Value);

            L3.Value    = HashHandler.ComputeSha256Hash("test4");
            L4.Value    = HashHandler.ComputeSha256Hash("test5");
            L3_L4.Value = HashHandler.ComputeSha256Hash(L3.Value + L4.Value);

            MerkleRoot.Value = HashHandler.ComputeSha256Hash(L1_L2.Value + L3_L4.Value);

            //Set Left & Right Nodes
            L1_L2.Left  = L1;
            L1_L2.Right = L2;

            L3_L4.Left  = L3;
            L3_L4.Right = L4;

            MerkleRoot.Left  = L1_L2;
            MerkleRoot.Right = L3_L4;

            //Verify Values
            string ExpectedL1Value   = "1b4f0e9851971998e732078544c96b36c3d01cedf7caa332359d6f1d83567014";
            string ExpectedL2Value   = "60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752";
            string ExpectedL1L2Value = "98866d999ba299056e0e79ba9137709a181fbccd230d6d3a6cc004da6e7bce83";

            string ExpectedL3Value   = "a4e624d686e03ed2767c0abd85c14426b0b1157d2ce81d27bb4fe4f6f01d688a";
            string ExpectedL4Value   = "a140c0c1eda2def2b830363ba362aa4d7d255c262960544821f556e16661b6ff";
            string ExpectedL3L4Value = "e6a5f59435aef23f707527906a695fc6efcf12eea365eec4020e763e94efe8e7";

            string ExpectedRootValue = "7f9878cb4a60aceec0bad755a979b015f415196c69be854629cb5db4e6661aae";

            Assert.AreEqual(ExpectedL1Value, L1.Value);
            Assert.AreEqual(ExpectedL2Value, L2.Value);
            Assert.AreEqual(ExpectedL1L2Value, L1_L2.Value);

            Assert.AreEqual(ExpectedL3Value, L3.Value);
            Assert.AreEqual(ExpectedL4Value, L4.Value);
            Assert.AreEqual(ExpectedL3L4Value, L3_L4.Value);

            Assert.AreEqual(ExpectedRootValue, MerkleRoot.Value);

            //Verify if the Object Reference is the same
            Assert.AreSame(L1, L1_L2.Left);
            Assert.AreSame(L2, L1_L2.Right);

            Assert.AreSame(L3, L3_L4.Left);
            Assert.AreSame(L4, L3_L4.Right);

            Assert.AreSame(L1_L2, MerkleRoot.Left);
            Assert.AreSame(L3_L4, MerkleRoot.Right);
        }
Beispiel #18
0
        private static bool ValidateField(KeyValuePair <uint, byte[]> kvCurrent, KeyValuePair <uint, byte[]> kvNext, out FieldInfo overrideFieldInfo)
        {
            FieldInfo fieldInfo = new FieldInfo();

            overrideFieldInfo = fieldInfo;

            uint currentKey = kvCurrent.Key;

            byte[] currentValue = kvCurrent.Value;

            //string currentKeyName = StringHasher.ResolveHash((int)currentKey) ?? $"{currentKey:X8}";
            string currentKeyName     = "";
            string currentValueString = BitConverter.ToString(currentValue).Replace("-", "");

            string r_currentKeyName;

            if (StringHasher.TryResolveHash((int)currentKey, out r_currentKeyName))
            {
                currentKeyName = r_currentKeyName;
            }

            if (kvNext.Value != null && kvNext.Value.Length > 0)
            {
                uint   nextKey   = kvNext.Key;
                byte[] nextValue = kvNext.Value;

                //string nextKeyName = StringHasher.ResolveHash((int) nextKey);
                string nextKeyName     = "";
                string nextValueString = BitConverter.ToString(nextValue).Replace("-", "");

                string r_nextKeyName;

                if (StringHasher.TryResolveHash((int)nextKey, out r_nextKeyName))
                {
                    nextKeyName = r_nextKeyName;
                }

                /*
                 * var textPrefix = "text_";
                 * var currentKeyGuessName = $"{textPrefix}{nextKeyName}";
                 * uint currentKeyGuessHash = FileFormats.Hashing.CRC32.Compute(currentKeyGuessName);
                 *
                 * if (currentKeyGuessHash == currentKey)
                 * {
                 *  // current key is text of next key
                 *
                 *  //Console.WriteLine($"{currentKeyGuessHash:X8} == {currentKey:X8}");
                 *
                 *  currentValueString = FieldHandling.Deserialize<string>(FieldType.String, currentValue);
                 * }
                 */

                FieldType r_currentFieldType;
                string    r_currentValueString;

                if (currentKeyName == "text_hidName")
                {
                    currentValueString = FieldHandling.Deserialize <string>(FieldType.String, currentValue);

                    Utility.Log("Exporting " + currentValueString);
                }
                else if (TypeGuesser.TryParse(currentValue, out r_currentFieldType, out r_currentValueString))
                {
                    if (r_currentFieldType == FieldType.String)
                    {
                        currentValueString = r_currentValueString;
                    }
                }

                uint  r_nextValueHash32 = 0;
                ulong r_nextValueHash64 = 0;
                ulong nextValueHash     = 0;

                if (uint.TryParse(nextValueString, NumberStyles.HexNumber, null, out r_nextValueHash32))
                {
                    nextValueHash = r_nextValueHash32;

                    //Console.WriteLine($"Parsing uint: {nextValueHash:X8}");
                }
                else if (ulong.TryParse(nextValueString, NumberStyles.HexNumber, null, out r_nextValueHash64))
                {
                    nextValueHash = r_nextValueHash64;

                    //Console.WriteLine($"Parsing ulong: {nextValueHash:X16}");
                }

                ulong[] hashValues = HashHandler.CollectHashes(currentValueString);

                var hashTypeIterator = 0;

                for (int b = 0; b < hashValues.Length; b++)
                {
                    ulong hash = hashValues[b];

                    //Console.WriteLine($"Iterating hash: {hash:X}");

                    if (hash > 0 && hash == nextValueHash)
                    {
                        hashTypeIterator = b;

                        //Console.WriteLine($"{hash:X} == {nextValueHash:X}");

                        break;
                    }
                }

                ulong resolvedHash = hashValues[hashTypeIterator];

                if (hashTypeIterator > 0 && resolvedHash == nextValueHash)
                {
                    // current value is text of next value
                    //string fieldName = nextKeyName ?? $"{nextValueHash:X8}";

                    if (string.IsNullOrEmpty(nextKeyName))
                    {
                        fieldInfo.key.type = "hash";
                        fieldInfo.key.name = $"{nextKey:X8}";
                    }
                    else
                    {
                        fieldInfo.key.type = "name";
                        fieldInfo.key.name = nextKeyName;
                    }

                    fieldInfo.value.type  = Convert.ToString((HashType)hashTypeIterator);
                    fieldInfo.value.value = currentValueString;

                    Console.WriteLine($"{fieldInfo.key.name} = {currentValueString}");

                    overrideFieldInfo = fieldInfo;

                    //Utility.Log($"{fieldName} = \"{currentValueString}\"");
                    //Utility.Log($"Found text value of field \"{fieldName}\": \"{currentValueString}\"");
                    //Utility.Log($"Element:\n\tcurrent:\n\t\tname: {currentKey:X8} -> {currentKeyName}\n\t\tvalue: {currentValueString} -> {resolvedHash:X8}\n\tnext:\n\t\tname: {nextKeyName} -> {nextKey:X8}\n\t\tvalue: {nextValueString}");

                    return(false);
                }
            }

            return(true);
        }