You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
defender-control/src/defender-control/main.cpp

83 lines
1.9 KiB
C++

3 years ago
// to-do:
3 years ago
// make a ui for this
2 years ago
// argument support -s check
3 years ago
//
#include "dcontrol.hpp"
#include "wmic.hpp"
3 years ago
#include "trusted.hpp"
2 years ago
bool check_silent(int argc, char** argv)
{
for (int i = 0; i < argc; i++)
{
if (!strcmp(argv[i], "-s"))
return true;
}
return false;
}
int main(int argc, char** argv)
3 years ago
{
2 years ago
auto silent = check_silent(argc, argv);
3 years ago
if (!trusted::has_admin())
{
3 years ago
printf("Must run as admin!\n");
2 years ago
if (!silent)
system("pause");
3 years ago
return EXIT_FAILURE;
}
3 years ago
3 years ago
// Because we are a primary token, we can't swap ourselves with an impersonation token.
// There will always be a need to re-create the process with the token as primary.
2 years ago
// we check for argc == 1, assuming we aren't launching with any parameters
//
if (!trusted::is_system_group()) // && argc == 1
3 years ago
{
printf("Restarting with privileges\n");
2 years ago
trusted::create_process(util::get_current_path().append(silent ? " -s" : ""));
3 years ago
return EXIT_SUCCESS;
}
3 years ago
try
{
dcontrol::kill_smartscreen();
dcontrol::manage_windefend(false);
dcontrol::toggle_tamper(false);
printf(dcontrol::check_defender() ?
2 years ago
"Windows defender is currently ACTIVE\n" :
"Windows defender is currently OFF\n");
3 years ago
#if DEFENDER_CONFIG == DEFENDER_DISABLE
3 years ago
if (dcontrol::disable_defender())
{
dcontrol::manage_security_center(false);
3 years ago
printf("Disabled windows defender!\n");
}
3 years ago
else
printf("Failed to disable defender...\n");
#elif DEFENDER_CONFIG == DEFENDER_ENABLE
3 years ago
if (dcontrol::enable_defender())
printf("Enabled windows defender!\n");
else
printf("Failed to enable defender...\n");
#elif DEFENDER_CONFIG == DEFENDER_GUI
3 years ago
#endif
3 years ago
}
catch (std::exception e)
3 years ago
{
printf("%s\n", e.what());
}
3 years ago
2 years ago
if (!silent)
system("pause");
return EXIT_SUCCESS;
3 years ago
}