added logger

triing to add logger and some queue features (main loop can send and retrieve items form queue based on schedule and communication with dekstop interface)
This commit is contained in:
jakani24
2023-12-23 20:15:44 +01:00
parent 45f8ad413f
commit a7e323618c
92 changed files with 966 additions and 16 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,198 @@
// ma_uninstaller.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms.
//
//todo:
/* remove folders
* remove background task
*/
#include <iostream>
#include <Windows.h>
//check if programm is run as admin
bool is_admin() {
BOOL fIsRunAsAdmin = FALSE;
PSID pAdminSID = NULL;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
&pAdminSID)) {
if (!CheckTokenMembership(NULL, pAdminSID, &fIsRunAsAdmin)) {
fIsRunAsAdmin = FALSE;
}
FreeSid(pAdminSID);
}
return (fIsRunAsAdmin != 0);
}
bool run_as_admin() {
wchar_t szPath[MAX_PATH];
if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath))) {
// Launch itself as admin
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = L"runas";
sei.lpFile = szPath;
sei.hwnd = NULL;
sei.nShow = SW_NORMAL;
if (!ShellExecuteEx(&sei)) {
DWORD dwError = GetLastError();
if (dwError == ERROR_CANCELLED)
{
// The user refused to allow privileges elevation.
return false;
}
}
else {
// End the calling process. User allowd admin rights
return true;
}
}
return false;
}
bool remove_dir(const std::wstring& path) {
// Remove the directory and its contents recursively
if (!RemoveDirectory(path.c_str())) {
DWORD error = GetLastError();
if (error != ERROR_DIR_NOT_EMPTY) {
// Failed to remove the directory
std::wcerr << L"Error removing directory '" << path << L"'. Error code: " << error << std::endl;
return false;
}
// The directory is not empty, so we need to remove its contents first
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile((path + L"\\*").c_str(), &findFileData);
if (hFind == INVALID_HANDLE_VALUE) {
std::wcerr << L"Error finding files in directory '" << path << L"'. Error code: " << GetLastError() << std::endl;
return false;
}
do {
if (wcscmp(findFileData.cFileName, L".") != 0 && wcscmp(findFileData.cFileName, L"..") != 0) {
std::wstring filePath = path + L"\\" + findFileData.cFileName;
if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// Recursively remove subdirectories
if (!remove_dir(filePath)) {
FindClose(hFind);
return false;
}
}
else {
// Delete files in the directory
if (DeleteFile(filePath.c_str()) == FALSE) {
std::wcerr << L"Error deleting file '" << filePath << L"'. Error code: " << GetLastError() << std::endl;
FindClose(hFind);
return false;
}
}
}
} while (FindNextFile(hFind, &findFileData) != 0);
FindClose(hFind);
// Try to remove the directory again after its contents have been deleted
if (!RemoveDirectory(path.c_str())) {
std::wcerr << L"Error removing directory '" << path << L"'. Error code: " << GetLastError() << std::endl;
return false;
}
}
return true;
}
int main()
{
printf("Welcome to the Cyberhex uninstaller!\n");
int error = 0;
if (!is_admin()) {
printf("We are not administrator, requesting UAC\n");
if (!run_as_admin()) {
printf("We did not get administrative rights. Please restart the uninstaller!\n");
MessageBox(NULL, L"Please start the uninstaller with amdin privileges!", L"Error", MB_OK);
exit(1);
}
else {
//we started the app as admin. This process can be terminated now
exit(0);
}
}
else {
printf("Removing directorys\n");
printf("Removing directory for application\n");
error = remove_dir(L"C:\\Program Files\\Cyberhex");
if (error == 0)
error = 4;
else
error = 0;
if (error == 0) {
printf("Removing background task\n");
SC_HANDLE hSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);
if (!hSCManager) {
//std::cerr << "Failed to open service control manager. Error code: " << GetLastError() << std::endl;
//return 1;
error = 1;
}
LPCWSTR serviceName = L"cyberhex_background_service";
SC_HANDLE hService = OpenService(hSCManager, serviceName, DELETE);
if (!hService) {
//std::cerr << "Failed to open service. Error code: " << GetLastError() << std::endl;
CloseServiceHandle(hSCManager);
//return 1;
error = 2;
}
if (!DeleteService(hService)) {
//std::cerr << "Failed to delete service. Error code: " << GetLastError() << std::endl;
error = 3;
}
else {
//std::cout << "Service deleted successfully." << std::endl;
}
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
}
}
switch (error) {
case 0:
printf("Uninstall finished successfully!\n");
MessageBox(NULL, L"Uninstall finished successfully!", L"Success", MB_OK);
break;
case 1:
printf("Failed to open service control manager.\n");
MessageBox(NULL, L"Failed to open service control manager!", L"Error", MB_OK);
break;
case 2:
printf("Failed to open service.\n");
MessageBox(NULL, L"Failed to open service!", L"Error", MB_OK);
break;
case 3:
printf("Failed to delete service.\n");
MessageBox(NULL, L"Failed to delete service!", L"Error", MB_OK);
break;
case 4:
printf("Failed to remove directory.\n");
MessageBox(NULL, L"Failed to remove directory!", L"Error", MB_OK);
default:
printf("Unknown error\n");
MessageBox(NULL, L"Unknown error!", L"Error", MB_OK);
break;
}
}
// Programm ausführen: STRG+F5 oder Menüeintrag "Debuggen" > "Starten ohne Debuggen starten"
// Programm debuggen: F5 oder "Debuggen" > Menü "Debuggen starten"
// Tipps für den Einstieg:
// 1. Verwenden Sie das Projektmappen-Explorer-Fenster zum Hinzufügen/Verwalten von Dateien.
// 2. Verwenden Sie das Team Explorer-Fenster zum Herstellen einer Verbindung mit der Quellcodeverwaltung.
// 3. Verwenden Sie das Ausgabefenster, um die Buildausgabe und andere Nachrichten anzuzeigen.
// 4. Verwenden Sie das Fenster "Fehlerliste", um Fehler anzuzeigen.
// 5. Wechseln Sie zu "Projekt" > "Neues Element hinzufügen", um neue Codedateien zu erstellen, bzw. zu "Projekt" > "Vorhandenes Element hinzufügen", um dem Projekt vorhandene Codedateien hinzuzufügen.
// 6. Um dieses Projekt später erneut zu öffnen, wechseln Sie zu "Datei" > "Öffnen" > "Projekt", und wählen Sie die SLN-Datei aus.

View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ma_uninstaller", "ma_uninstaller.vcxproj", "{A8DFEDE3-F066-4583-94C9-257F88DFF56A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Debug|x64.ActiveCfg = Debug|x64
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Debug|x64.Build.0 = Debug|x64
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Debug|x86.ActiveCfg = Debug|Win32
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Debug|x86.Build.0 = Debug|Win32
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Release|x64.ActiveCfg = Release|x64
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Release|x64.Build.0 = Release|x64
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Release|x86.ActiveCfg = Release|Win32
{A8DFEDE3-F066-4583-94C9-257F88DFF56A}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {53B44BA8-CBBC-4D67-A9ED-B37B204BD2C5}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a8dfede3-f066-4583-94c9-257f88dff56a}</ProjectGuid>
<RootNamespace>mauninstaller</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ma_uninstaller.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Quelldateien">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Headerdateien">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Ressourcendateien">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ma_uninstaller.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_uninstaller\x64\Debug\ma_uninstaller.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

Binary file not shown.

View File

@@ -0,0 +1,2 @@
 ma_uninstaller.cpp
ma_uninstaller.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_uninstaller\x64\Debug\ma_uninstaller.exe

Binary file not shown.

View File

@@ -0,0 +1 @@
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_uninstaller\ma_uninstaller.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_uninstaller\x64\Debug\ma_uninstaller.obj

View File

@@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.38.33130:TargetPlatformVersion=10.0.22621.0:VcpkgTriplet=x64-windows:
Debug|x64|C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_uninstaller\|

View File

@@ -0,0 +1 @@
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\ma_uninstaller\x64\Debug\ma_uninstaller.exe

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@