updating installer
i updated all installers to use tasks instead of services, made the uninstaller to work, and overworked the whole installing process
This commit is contained in:
@@ -19,6 +19,243 @@ Tasks to do:
|
||||
- create folder for communication
|
||||
|
||||
*/
|
||||
//create task thx chatgpt ;)#define _WIN32_DCOM
|
||||
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <comdef.h>
|
||||
#include <taskschd.h>
|
||||
#pragma comment(lib, "taskschd.lib")
|
||||
#pragma comment(lib, "comsupp.lib")
|
||||
|
||||
using namespace std;
|
||||
|
||||
int CreateTask()
|
||||
{
|
||||
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "CoInitializeEx failed: " << hex << hr << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
hr = CoInitializeSecurity(
|
||||
NULL,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
||||
RPC_C_IMP_LEVEL_IMPERSONATE,
|
||||
NULL,
|
||||
0,
|
||||
NULL);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "CoInitializeSecurity failed: " << hex << hr << endl;
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
LPCWSTR wszTaskName = L"CyberhexBackgroundTask";
|
||||
wstring wstrExecutablePath = L"c:\\program files\\cyberhex\\secure\\app\\cyberhex.exe";
|
||||
|
||||
ITaskService* pService = NULL;
|
||||
hr = CoCreateInstance(CLSID_TaskScheduler,
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_ITaskService,
|
||||
(void**)&pService);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Failed to create an instance of ITaskService: " << hex << hr << endl;
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
hr = pService->Connect(_variant_t(), _variant_t(),
|
||||
_variant_t(), _variant_t());
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "ITaskService::Connect failed: " << hex << hr << endl;
|
||||
pService->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
ITaskFolder* pRootFolder = NULL;
|
||||
hr = pService->GetFolder(_bstr_t(L"\\"), &pRootFolder);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot get Root Folder pointer: " << hex << hr << endl;
|
||||
pService->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
pRootFolder->DeleteTask(_bstr_t(wszTaskName), 0);
|
||||
|
||||
ITaskDefinition* pTask = NULL;
|
||||
hr = pService->NewTask(0, &pTask);
|
||||
|
||||
pService->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Failed to create a task definition: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
IPrincipal* pPrincipal = NULL;
|
||||
hr = pTask->get_Principal(&pPrincipal);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot get principal pointer: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
hr = pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);
|
||||
pPrincipal->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot set highest privilege level: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
ITaskSettings* pSettings = NULL;
|
||||
hr = pTask->get_Settings(&pSettings);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot get settings pointer: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
hr = pSettings->put_DisallowStartIfOnBatteries(VARIANT_FALSE); // Set to allow start on batteries
|
||||
pSettings->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot set start on batteries: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
ITriggerCollection* pTriggerCollection = NULL;
|
||||
hr = pTask->get_Triggers(&pTriggerCollection);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot get trigger collection: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
ITrigger* pTrigger = NULL;
|
||||
hr = pTriggerCollection->Create(TASK_TRIGGER_BOOT, &pTrigger);
|
||||
pTriggerCollection->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot create the trigger: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
IActionCollection* pActionCollection = NULL;
|
||||
hr = pTask->get_Actions(&pActionCollection);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot get Task collection pointer: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
IAction* pAction = NULL;
|
||||
hr = pActionCollection->Create(TASK_ACTION_EXEC, &pAction);
|
||||
pActionCollection->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot create the action: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
IExecAction* pExecAction = NULL;
|
||||
hr = pAction->QueryInterface(
|
||||
IID_IExecAction, (void**)&pExecAction);
|
||||
pAction->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "QueryInterface call failed for IExecAction: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
hr = pExecAction->put_Path(_bstr_t(wstrExecutablePath.c_str()));
|
||||
pExecAction->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Cannot set path of executable: " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
IRegisteredTask* pRegisteredTask = NULL;
|
||||
VARIANT varPassword;
|
||||
varPassword.vt = VT_EMPTY;
|
||||
hr = pRootFolder->RegisterTaskDefinition(
|
||||
_bstr_t(wszTaskName),
|
||||
pTask,
|
||||
TASK_CREATE_OR_UPDATE,
|
||||
_variant_t(L"SYSTEM"),
|
||||
varPassword,
|
||||
TASK_LOGON_SERVICE_ACCOUNT,
|
||||
_variant_t(L""),
|
||||
&pRegisteredTask);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
cout << "Error saving the Task : " << hex << hr << endl;
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
CoUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "Success! Task successfully registered." << endl;
|
||||
|
||||
pRootFolder->Release();
|
||||
pTask->Release();
|
||||
pRegisteredTask->Release();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//check if programm is run as admin
|
||||
bool is_admin() {
|
||||
BOOL fIsRunAsAdmin = FALSE;
|
||||
@@ -205,11 +442,11 @@ int check_cert(const char* cert, const char* secrets_path) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
char* secrets = new char[300];
|
||||
char* secrets = new char[505];
|
||||
while (!feof(fp)) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
fscanf_s(fp, "%s", secrets, 500); // get the secret
|
||||
if (strcmp("cert", secrets) == 0) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
fscanf_s(fp, "%s", secrets, 500); // get the secret
|
||||
if (strcmp(cert, secrets) == 0) {
|
||||
delete[] secrets;
|
||||
return 0;
|
||||
@@ -227,17 +464,20 @@ char* get_apikey(const char* secrets_path) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
char* secrets = new char[300];
|
||||
char* secrets = new char[505];
|
||||
while (!feof(fp)) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
fscanf_s(fp, "%s", secrets, 500); // get the secret
|
||||
if (strcmp("apikey", secrets) == 0) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
fscanf_s(fp, "%s", secrets, 500); // get the secret
|
||||
fclose(fp);
|
||||
return secrets;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
delete[] secrets;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
char* get_machineid(const char* secrets_path) {
|
||||
FILE* fp;
|
||||
@@ -250,12 +490,15 @@ char* get_machineid(const char* secrets_path) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
if (strcmp("machineid", secrets) == 0) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
fclose(fp);
|
||||
return secrets;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
delete[] secrets;
|
||||
return 0;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
char* get_server(const char* secrets_path) {
|
||||
FILE* fp;
|
||||
@@ -268,12 +511,130 @@ char* get_server(const char* secrets_path) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
if (strcmp("server", secrets) == 0) {
|
||||
fscanf_s(fp, "%s", secrets, 295); // get the secret
|
||||
fclose(fp);
|
||||
return secrets;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
delete[] secrets;
|
||||
return 0;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
int update_db(const char* folder_path) {
|
||||
//download the databases from the server
|
||||
for (char firstChar = '0'; firstChar <= 'f'; ++firstChar) {
|
||||
for (char secondChar = '0'; secondChar <= 'f'; ++secondChar) {
|
||||
// Ensure that the characters are valid hexadecimal digits
|
||||
if (!std::isxdigit(firstChar) || !std::isxdigit(secondChar) or std::isupper(firstChar) or std::isupper(secondChar)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create the filename based on the naming convention
|
||||
|
||||
char file_name[]= { firstChar, secondChar ,'.','j','d','b','f','\0' };
|
||||
//create the strings to download the files
|
||||
char* url = new char[300];
|
||||
char* output_path = new char[300];
|
||||
strcpy_s(url, 295, get_server("setup.txt"));
|
||||
strcat_s(url, 295, "/database_srv/");
|
||||
strcat_s(url, 295, file_name);
|
||||
strcpy_s(output_path, 295, folder_path);
|
||||
strcat_s(output_path, 295, "\\");
|
||||
strcat_s(output_path, 295, file_name);
|
||||
printf("%s\n", url);
|
||||
int res = download_file_from_srv(url, output_path);
|
||||
if (res != 0) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
delete[] url;
|
||||
delete[] output_path;
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int update_settings(const char* settings_type) {
|
||||
//create the strings to download the files
|
||||
char* url = new char[1000];
|
||||
strcpy_s(url, 1000, get_server("setup.txt"));
|
||||
strcat_s(url, 1000, "/api/php/settings/get_settings.php?");//need to add machine_id and apikey
|
||||
strcat_s(url, 1000, settings_type);
|
||||
strcat_s(url, 1000, "&machine_id=");
|
||||
strcat_s(url, 1000, get_machineid(SECRETS));
|
||||
strcat_s(url, 1000, "&apikey=");
|
||||
strcat_s(url, 1000, get_apikey(SECRETS));
|
||||
int res = 1;
|
||||
if (strcmp(settings_type, "settings") == 0)
|
||||
res = download_file_from_srv(url, SETTINGS_DB);
|
||||
else if (strcmp(settings_type, "rtp_included") == 0)
|
||||
res = download_file_from_srv(url, INCLUDED_FOLDERS);
|
||||
else if (strcmp(settings_type, "rtp_excluded") == 0)
|
||||
res = download_file_from_srv(url, EXCLUDED_FOLDERS);
|
||||
else if (strcmp(settings_type, "sched") == 0)
|
||||
res = download_file_from_srv(url, SCHED_PATH);
|
||||
//int res = 0;
|
||||
if (res != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
delete[] url;
|
||||
return 0;
|
||||
}
|
||||
int action_update_settings() {
|
||||
//update the settings
|
||||
int err = 0;
|
||||
if (update_settings("settings") != 0) {
|
||||
err = 9;
|
||||
}
|
||||
//update the included folders
|
||||
if (update_settings("rtp_included") != 0) {
|
||||
err = 9;
|
||||
}
|
||||
//update the excluded folders
|
||||
if (update_settings("rtp_excluded") != 0) {
|
||||
err = 9;
|
||||
}
|
||||
//update the schedule
|
||||
if (update_settings("sched") != 0) {
|
||||
err = 9;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
int action_update_db() {
|
||||
//update the databases
|
||||
return update_db(DB_DIR);
|
||||
}
|
||||
int copy(const char* source_path, const char* destination_path) {
|
||||
FILE* source_file, * destination_file;
|
||||
char buffer[4096]; // Buffer to store data read from source file
|
||||
|
||||
// Open source file for reading
|
||||
if (fopen_s(&source_file, source_path, "rb") != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Open destination file for writing
|
||||
if (fopen_s(&destination_file, destination_path, "wb") != 0) {
|
||||
fclose(source_file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Copy contents from source to destination
|
||||
size_t bytes_read;
|
||||
while ((bytes_read = fread(buffer, 1, sizeof(buffer), source_file)) > 0) {
|
||||
fwrite(buffer, 1, bytes_read, destination_file);
|
||||
}
|
||||
|
||||
// Close files
|
||||
fclose(source_file);
|
||||
fclose(destination_file);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
@@ -283,7 +644,7 @@ int main()
|
||||
printf("We are not administrator, requesting UAC\n");
|
||||
if (!run_as_admin()) {
|
||||
printf("We did not get administrative rights. Please restart the installer!\n");
|
||||
MessageBox(NULL, L"Please start the installer with amdin privileges!", L"Error", MB_OK);
|
||||
MessageBox(NULL, L"Please start the installer with admin privileges!", L"Error", MB_OK);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
@@ -332,92 +693,98 @@ int main()
|
||||
FILE* fp;
|
||||
char*apikey=get_apikey("secrets.txt");
|
||||
char*machineid=get_machineid("secrets.txt");
|
||||
char* server_url = get_server("setup.txt");
|
||||
char*server_url = get_server("setup.txt");
|
||||
printf("%s\n", server_url);
|
||||
//copy secrets.txt into the secrets folder
|
||||
if (rename("secrets.txt", SECRETS)!=0) {
|
||||
error = 8;
|
||||
}
|
||||
//download all the other files
|
||||
//download the settings:
|
||||
if (error == 0) {
|
||||
printf("Downloading settings from server\n");
|
||||
error = action_update_settings();
|
||||
}
|
||||
if (error == 0) {
|
||||
printf("Downloading databases from server\n");
|
||||
error = action_update_db();
|
||||
}
|
||||
|
||||
|
||||
if (error == 0) {
|
||||
printf("Downloading files from server\n");
|
||||
printf("Downloading cyberhex.exe\n");
|
||||
error=download_file_from_srv("https://cyberhex.org/download/cyberhex.exe", "C:\\Program Files\\cyberhex\\secure\\app\\cyberhex.exe");
|
||||
printf("Moving files into secure directorys\n");
|
||||
printf("Movin cyberhex.exe\n");
|
||||
//!!need to change: download in advance and then move to the correct folder
|
||||
//error=download_file_from_srv("https://github.com/jakani24/cyberhex_bin_distro/raw/main/client_backend.exe", "C:\\Program Files\\cyberhex\\secure\\app\\cyberhex.exe");
|
||||
if(rename("client_backend.exe", "C:\\Program Files\\cyberhex\\secure\\app\\cyberhex.exe")!=0)
|
||||
error = 7;
|
||||
if (error == 0) {
|
||||
printf("Downloading libcrypto-3-x64.dll\n");
|
||||
error = download_file_from_srv("https://cyberhex.org/download/libcrypto-3-x64.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcrypto-3-x64.dll");
|
||||
printf("Moving libcrypto-3-x64.dll\n");
|
||||
//error = download_file_from_srv("https://github.com/jakani24/cyberhex_bin_distro/raw/main/libcrypto-3-x64.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcrypto-3-x64.dll");
|
||||
if(rename("libcrypto-3-x64.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcrypto-3-x64.dll")!=0)
|
||||
error = 7;
|
||||
}if (error == 0) {
|
||||
printf("Downloading libcurl.dll\n");
|
||||
error = download_file_from_srv("https://cyberhex.org/download/libcurl.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcurl.dll");
|
||||
printf("Moving libcurl.dll\n");
|
||||
//error = download_file_from_srv("https://github.com/jakani24/cyberhex_bin_distro/raw/main/libcurl.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcurl.dll");
|
||||
if(rename("libcurl.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcurl.dll")!=0)
|
||||
error = 7;
|
||||
}if (error == 0) {
|
||||
printf("Downloading zlib1.dll\n");
|
||||
error = download_file_from_srv("https://cyberhex.org/download/zlib1.dll", "C:\\Program Files\\cyberhex\\secure\\app\\zlib1.dll");
|
||||
printf("Moving zlib1.dll\n");
|
||||
if(rename("zlib1.dll", "C:\\Program Files\\cyberhex\\secure\\app\\zlib1.dll")!=0)
|
||||
error = 7;
|
||||
//error = download_file_from_srv("https://github.com/jakani24/cyberhex_bin_distro/raw/main/zlib1.dll", "C:\\Program Files\\cyberhex\\secure\\app\\zlib1.dll");
|
||||
}if (error == 0) {
|
||||
printf("Downloading cyberhex_desktop.dll\n");
|
||||
error = download_file_from_srv("https://cyberhex.org/download/cyberhex_desktop.exe", "C:\\Program Files\\cyberhex\\app\\cyberhex_desktop.exe");
|
||||
printf("Moving cyberhex_desktop.exe\n");
|
||||
if(rename("client_frontend.exe", "C:\\Program Files\\cyberhex\\app\\cyberhex_desktop.exe")!=0)
|
||||
error = 7;
|
||||
//error = download_file_from_srv("https://github.com/jakani24/cyberhex_bin_distro/raw/main/client_frontend.exe", "C:\\Program Files\\cyberhex\\app\\cyberhex_desktop.exe");
|
||||
}if (error == 0) {
|
||||
printf("Moving msvcp140.dll\n");
|
||||
//error = download_file_from_srv("https://github.com/jakani24/cyberhex_bin_distro/raw/main/libcurl.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcurl.dll");
|
||||
if (copy("msvcp140.dll", "C:\\Program Files\\cyberhex\\secure\\app\\msvcp140.dll") != 0)
|
||||
error = 7;
|
||||
if (copy("msvcp140.dll", "C:\\Program Files\\cyberhex\\app\\msvcp140.dll") != 0)
|
||||
error = 7;
|
||||
}if (error == 0) {
|
||||
printf("Moving msvcp140d.dll\n");
|
||||
//error = download_file_from_srv("https://github.com/jakani24/cyberhex_bin_distro/raw/main/libcurl.dll", "C:\\Program Files\\cyberhex\\secure\\app\\libcurl.dll");
|
||||
if (copy("msvcp140d.dll", "C:\\Program Files\\cyberhex\\secure\\app\\msvcp140d.dll") != 0)
|
||||
error = 7;
|
||||
if (copy("msvcp140d.dll", "C:\\Program Files\\cyberhex\\app\\msvcp140d.dll") != 0)
|
||||
error = 7;
|
||||
}if (error == 0) {
|
||||
printf("Moving vcruntime140.dll\n");
|
||||
if (copy("vcruntime140.dll", "C:\\Program Files\\cyberhex\\secure\\app\\vcruntime140.dll") != 0)
|
||||
error = 7;
|
||||
if (copy("vcruntime140.dll", "C:\\Program Files\\cyberhex\\app\\vcruntime140.dll") != 0)
|
||||
error = 7;
|
||||
}if (error == 0) {
|
||||
printf("Moving vcruntime140d.dll\n");
|
||||
if (copy("vcruntime140d.dll", "C:\\Program Files\\cyberhex\\secure\\app\\vcruntime140d.dll") != 0)
|
||||
error = 7;
|
||||
if (copy("vcruntime140d.dll", "C:\\Program Files\\cyberhex\\app\\vcruntime140d.dll") != 0)
|
||||
error = 7;
|
||||
}if (error == 0) {
|
||||
printf("Moving vcruntime140_1d.dll\n");
|
||||
if (copy("vcruntime140_1d.dll", "C:\\Program Files\\cyberhex\\secure\\app\\vcruntime140_1d.dll") != 0)
|
||||
error = 7;
|
||||
if (copy("vcruntime140_1d.dll", "C:\\Program Files\\cyberhex\\app\\vcruntime140_1d.dll") != 0)
|
||||
error = 7;
|
||||
}if (error == 0) {
|
||||
printf("Moving ucrtbased.dll\n");
|
||||
if (copy("ucrtbased.dll", "C:\\Program Files\\cyberhex\\secure\\app\\ucrtbased.dll") != 0)
|
||||
error = 7;
|
||||
if (copy("ucrtbased.dll", "C:\\Program Files\\cyberhex\\app\\ucrtbased.dll") != 0)
|
||||
error = 7;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//create background service
|
||||
if (error == 0) {
|
||||
printf("Creating background service\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;
|
||||
error = 4;
|
||||
}
|
||||
|
||||
LPCWSTR serviceName = L"cyberhex_background_service";
|
||||
LPCWSTR servicePath = L"C:\\Program Files\\cyberhex\\secure\\app\\cyberhex.exe";
|
||||
|
||||
SC_HANDLE hService = CreateService(
|
||||
hSCManager,
|
||||
serviceName,
|
||||
serviceName,
|
||||
SERVICE_ALL_ACCESS,
|
||||
SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL,
|
||||
servicePath,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (!hService) {
|
||||
//std::cerr << "Failed to create service. Error code: " << GetLastError() << std::endl;
|
||||
CloseServiceHandle(hSCManager);
|
||||
error = 5;
|
||||
}
|
||||
|
||||
// Configure the service to run with LocalSystem account (administrator rights)
|
||||
if (!ChangeServiceConfig(
|
||||
hService,
|
||||
SERVICE_NO_CHANGE,
|
||||
SERVICE_NO_CHANGE,
|
||||
SERVICE_NO_CHANGE,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
L"LocalSystem",
|
||||
nullptr,
|
||||
nullptr
|
||||
)) {
|
||||
//std::cerr << "Failed to configure service. Error code: " << GetLastError() << std::endl
|
||||
error = 6;
|
||||
}
|
||||
else {
|
||||
//std::cout << "Service created and configured successfully." << std::endl;
|
||||
//no error
|
||||
}
|
||||
|
||||
CloseServiceHandle(hService);
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
HRESULT hr = CreateTask();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
std::cerr << "Task creation failed!" << std::endl;
|
||||
error=5;
|
||||
}
|
||||
}
|
||||
switch (error) {
|
||||
@@ -451,14 +818,23 @@ int main()
|
||||
MessageBox(NULL, L"Failed to configure service", L"Error", MB_OK);
|
||||
break;
|
||||
case 7:
|
||||
printf("Failed to download file\n");
|
||||
MessageBox(NULL, L"Failed to download file", L"Error", MB_OK);
|
||||
printf("Failed to move file\n");
|
||||
MessageBox(NULL, L"Failed to move file", L"Error", MB_OK);
|
||||
break;
|
||||
case 8:
|
||||
printf("Failed to open secrets.txt\n");
|
||||
MessageBox(NULL, L"Failed to open secrets.txt", L"Error", MB_OK);
|
||||
printf("Failed to move secrets.txt\n");
|
||||
MessageBox(NULL, L"Failed to move secrets.txt", L"Error", MB_OK);
|
||||
break;
|
||||
case 9:
|
||||
printf("Failed to download settings\n");
|
||||
MessageBox(NULL, L"Failed to download settings", L"Error", MB_OK);
|
||||
break;
|
||||
case 10:
|
||||
printf("Failed to download database file\n");
|
||||
MessageBox(NULL, L"Failed to download database file", L"Error", MB_OK);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
system("pause");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user