Exemplo n.º 1
0
        private void RefreshProcessesBtn_Click(object sender, EventArgs e) // Refresh the processes lists both of them.
        {
            ListBox TempLB = new ListBox();

            DeniedProcessesListBox.Items.Clear();

            HIDGuardianAPI.RemoveAllWhitelistedProcesses(); // Remove all added processes and then add HIDer's pid.
            HIDGuardianAPI.AddWhitelistedProcess(Process.GetCurrentProcess().Id.ToString());

            foreach (Process process in Process.GetProcesses()) // Iterate over processes and check if the refreshed processes are not available in the allowed listbox, if they are not, add them to the main list. If they are, add them to a temp list then refresh the allowed whitelist listbox with the temp list. This is used because some processes added to the allowed list might have been terminated, so they need to be removed.
            {
                if (!process.ProcessName.Contains("HIDer") && process.ProcessName != "System" && process.ProcessName != "Idle")
                {
                    if (AllowedProcessesListBox.FindStringExact(process.ProcessName + ":" + process.Id) == -1)
                    {
                        DeniedProcessesListBox.Items.Add(process.ProcessName + ":" + process.Id);
                    }
                    else
                    {
                        HIDGuardianAPI.AddWhitelistedProcess(process.Id.ToString()); // Re-add the removed processes.
                        TempLB.Items.Add(process.ProcessName + ":" + process.Id);
                    }
                }
            }

            AllowedProcessesListBox.Items.Clear();
            if (TempLB.Items.Count > 0)
            {
                MoveListBoxItems(TempLB, AllowedProcessesListBox);
            }
        }
Exemplo n.º 2
0
        private void HandleDevices() // Add available and hidden devices from previous time, that the application stored in the file (settings.ini). All hidden devices are stored on application exit.
        {
            string devices = HIDGuardianAPI.GetDevicesList().TrimEnd(';');

            if (AffectedDevices != "") // Add affected hidden devices from last time acquired from the settings.ini
            {
                foreach (string affecteddevice in AffectedDevices.Split(';'))
                {
                    if (affecteddevice.Contains(":"))
                    {
                        HIDGuardianAPI.HideDevice(affecteddevice.Split(':')[1]);
                        HIDGuardianAPI.ReplugHID(affecteddevice.Split(':')[1]);
                        HiddenDevicesListBox.Items.Add(affecteddevice);
                    }
                }
            }

            if (devices != "") // Add all (available) devices excluding the ones from the last segment.
            {
                foreach (string device in devices.Split(';'))
                {
                    if (!AffectedDevices.Contains(device))
                    {
                        AvailableDevicesListBox.Items.Add(device);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            string path = Application.StartupPath;

            if (Directory.Exists(path + @"\update") && !IsDirectoryEmpty(path + @"\update")) // This is used to make it easier for the user to install the external resources required for the project.
            {
                ProcessUpdates(path);
            }

            DevConAvailable = CheckDevCon();

            if (DevConAvailable) // Check if devcon is available. Close the application if it is not.
            {
                LoadSettings();
                CheckExternalResources();

                // if (HIDGuardianAPI.IsWebsiteAvailable()) // Check if the website is available. If it is not, do not proceed. HidGuardianWebAPI only.

                HIDGuardianAPI.RemoveAllWhitelistedProcesses();                                  // Remove all processes from last run in case the user crashed the application.
                HIDGuardianAPI.AddWhitelistedProcess(Process.GetCurrentProcess().Id.ToString()); // This is probably not necessary. Check later.

                UnhideDevices();                                                                 // In case the user crashed the application instead of closing it.
                HandleProcesses();                                                               // Deal with available processes and add whitelisted processes based on the stored settings (settings.ini file). HandleProcesses is called before HandleDevices because HandleDevices refreshes (replugs) the hidden devices making them available for the whitelisted processes from this step.
                HandleDevices();                                                                 // Add available and hidden devices from previous time, that the application stored in the file (settings.ini). All hidden devices are stored on application exit.
            }
            else
            {
                DisplayMissing();
            }
        }
Exemplo n.º 4
0
 private void UninstallHidGuardianBtn_Click(object sender, EventArgs e)
 {
     if (HIDGuardianAPI.UninstallHidGuardian())
     {
         InstallHidGuardianBtn.Enabled   = true;
         UninstallHidGuardianBtn.Enabled = false;
     }
 }
Exemplo n.º 5
0
 private void StopHidCerberusBtn_Click(object sender, EventArgs e)
 {
     if (HIDGuardianAPI.StopHidCerberus())
     {
         StartHidCerberusBtn.Enabled = true;
         StopHidCerberusBtn.Enabled  = false;
     }
 }
Exemplo n.º 6
0
 private void InstallViGEmBtn_Click(object sender, EventArgs e)
 {
     if (HIDGuardianAPI.InstallViGEm())
     {
         InstallViGEmBtn.Enabled   = false;
         UninstallViGEmBtn.Enabled = true;
     }
 }
Exemplo n.º 7
0
 private void DenyProcessBtn_Click(object sender, EventArgs e)
 {
     if (AllowedProcessesListBox.SelectedIndex != -1)
     {
         HIDGuardianAPI.RemoveWhitelistedProcess(AllowedProcessesListBox.SelectedItem.ToString().Split(':')[1]);
         MoveSelectedListBoxItem(AllowedProcessesListBox, DeniedProcessesListBox);
     }
 }
Exemplo n.º 8
0
 private void UnhideDeviceBtn_Click(object sender, EventArgs e)
 {
     if (HiddenDevicesListBox.SelectedIndex != -1)
     {
         string hid = HiddenDevicesListBox.SelectedItem.ToString().Split(':')[1];
         HIDGuardianAPI.UnhideDevice(hid);
         MoveSelectedListBoxItem(HiddenDevicesListBox, AvailableDevicesListBox);
         HIDGuardianAPI.ReplugHID(hid);
     }
 }
Exemplo n.º 9
0
 private void HideDeviceBtn_Click(object sender, EventArgs e)
 {
     if (AvailableDevicesListBox.SelectedIndex != -1)
     {
         string hid = AvailableDevicesListBox.SelectedItem.ToString().Split(':')[1];
         HIDGuardianAPI.HideDevice(hid);
         MoveSelectedListBoxItem(AvailableDevicesListBox, HiddenDevicesListBox);
         HIDGuardianAPI.ReplugHID(hid); // ReplugHID is used to fresh the devices so the user does not have to restart or unplug/replug the devices.
     }
 }
Exemplo n.º 10
0
        private void UnhideDevices()
        {
            string prevaffecteddevices = HIDGuardianAPI.GetAffectedDevicesList(); // Get a list of available hidden devices from last run.

            foreach (string prevaffecteddevice in prevaffecteddevices.Split(';'))
            {
                HIDGuardianAPI.UnhideDevice(prevaffecteddevice);
                HIDGuardianAPI.ReplugHID(prevaffecteddevice); // Iterate over the list of affected devices from the last run and replug them (to refresh them).
            }
        }
Exemplo n.º 11
0
 private void UnhideAllBtn_Click(object sender, EventArgs e)
 {
     HIDGuardianAPI.UnhideAllDevices();
     foreach (var device in HiddenDevicesListBox.Items)
     {
         string hid = device.ToString().Split(':')[1];
         HIDGuardianAPI.UnhideDevice(hid);
         HIDGuardianAPI.ReplugHID(hid);
     }
     MoveListBoxItems(HiddenDevicesListBox, AvailableDevicesListBox);
 }
Exemplo n.º 12
0
        private void CheckExternalResources() // Used to check what is installed/available and what is not to handle the disabling/hiding of controls.
        {
            if (HIDGuardianAPI.IsViGEmBusInstalled())
            {
                InstallViGEmBtn.Enabled = false;
            }
            else
            {
                UninstallViGEmBtn.Enabled = false;
                HIDerTab.SelectedIndex    = 2;
            }

            if (HIDGuardianAPI.IsHidGuardianInstalled())
            {
                InstallHidGuardianBtn.Enabled = false;
            }
            else
            {
                UninstallHidGuardianBtn.Enabled = false;
                HIDerTab.SelectedIndex          = 2;
            }

            if (HIDGuardianAPI.IsHidCerberusAvailable(Application.StartupPath))
            {
                if (HIDGuardianAPI.IsHidCerberusInstalled())
                {
                    InstallHidCerberusBtn.Enabled = false;
                    if (HIDGuardianAPI.IsHidCerberusRunning())
                    {
                        StartHidCerberusBtn.Enabled = false;
                    }
                    else
                    {
                        StopHidCerberusBtn.Enabled = false;
                    }
                }
                else
                {
                    UninstallHidCerberusBtn.Enabled = false;
                    StartHidCerberusBtn.Enabled     = false;
                    StopHidCerberusBtn.Enabled      = false;
                }
            }
            else
            {
                HidCerberusLbl.Visible          = false;
                InstallHidCerberusBtn.Visible   = false;
                UninstallHidCerberusBtn.Visible = false;
                StartHidCerberusBtn.Visible     = false;
                StopHidCerberusBtn.Visible      = false;
            }
        }
Exemplo n.º 13
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e) // On exit
 {
     if (DevConAvailable)
     {
         string devices   = "";
         string processes = "";
         HIDGuardianAPI.RemoveAllWhitelistedProcesses();    // Remove all added processes.
         UnhideDevices();                                   // Remove and unhide hidden devices.
         foreach (var device in HiddenDevicesListBox.Items) // Store the settings.
         {
             devices += device.ToString() + ";";
         }
         foreach (var process in PermenantProccessesTextBox.Text.TrimEnd(';').Split(';'))
         {
             processes += process + ";";
         }
         File.WriteAllText("settings.ini", "devices=" + devices + "\r\n" + "processes=" + processes);
     }
 }
Exemplo n.º 14
0
 private void HandleProcesses()
 {
     foreach (Process process in Process.GetProcesses()) // Iterate over the list of available processes skipping this program, system, and idle processes.
     {
         if (!process.ProcessName.Contains("HIDer") && process.ProcessName != "System" && process.ProcessName != "Idle")
         {
             string whitelistedprocesses = PermenantProccessesTextBox.Text;
             if (whitelistedprocesses != "" && whitelistedprocesses.Contains(process.ProcessName + ";")) // If the current process name matches one from permenant proccesses (PermenantProccessesTextBox.Text), it is added to the HidGuardian whitelist.
             {
                 HIDGuardianAPI.AddWhitelistedProcess(process.Id.ToString());
                 AllowedProcessesListBox.Items.Add(process.ProcessName + ":" + process.Id);
             }
             else
             {
                 DeniedProcessesListBox.Items.Add(process.ProcessName + ":" + process.Id); // Everything else goes in here.
             }
         }
     }
 }
Exemplo n.º 15
0
 private void DenyAllProcessBtn_Click(object sender, EventArgs e)
 {
     HIDGuardianAPI.RemoveAllWhitelistedProcesses();
     HIDGuardianAPI.AddWhitelistedProcess(Process.GetCurrentProcess().Id.ToString());
     MoveListBoxItems(AllowedProcessesListBox, DeniedProcessesListBox);
 }