This repository has been archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
954 additions
and
1,145 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
.vs/ | ||
src/.vs | ||
src/ARM | ||
src/x64 | ||
src/W11Boost | ||
src/Release | ||
src/Debug | ||
.vs | ||
.vscode | ||
.cache | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(src/CMakeLists.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
cmake_minimum_required(VERSION 3.29.5) | ||
project(W11Boost VERSION 1.1 LANGUAGES CXX C) | ||
|
||
function(replace_manifest TARGET_NAME MANIFEST_FILE) | ||
if(NOT TARGET_NAME) | ||
message(FATAL_ERROR "You must provide a target") | ||
endif() | ||
|
||
if(NOT MANIFEST_FILE) | ||
message(FATAL_ERROR "You must provide a manifest file") | ||
endif() | ||
|
||
add_custom_command( | ||
TARGET ${TARGET_NAME} | ||
POST_BUILD | ||
COMMAND "mt.exe" -manifest \"${MANIFEST_FILE}\" \"-outputresource:$<TARGET_FILE:${TARGET_NAME}>\" -nologo | ||
) | ||
endfunction() | ||
|
||
file(GLOB SRC_FILES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.c") | ||
|
||
add_executable(W11Boost WIN32 ${SRC_FILES} W11Boost.rc) | ||
|
||
target_compile_features(W11Boost PUBLIC c_std_23) | ||
set_target_properties(W11Boost PROPERTIES | ||
CMAKE_C_STANDARD 23 | ||
CMAKE_C_STANDARD_REQUIRED ON | ||
CMAKE_C_EXTENSIONS OFF | ||
) | ||
replace_manifest(W11Boost ${CMAKE_SOURCE_DIR}/app.manifest) | ||
add_definitions(-DUNICODE -D_UNICODE) | ||
target_link_options(W11Boost PRIVATE -municode -mwindows) | ||
target_compile_options(W11Boost PRIVATE -Wall -Wextra -Werror -Wno-missing-field-initializers) | ||
|
||
# Include headers | ||
target_include_directories(W11Boost PRIVATE ${CMAKE_SOURCE_DIR}) | ||
|
||
target_link_libraries(W11Boost PRIVATE | ||
gpedit.lib | ||
userenv.lib | ||
wininet.lib | ||
shlwapi.lib | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
#define __STDC_WANT_LIB_EXT1__ 1 | ||
#include "Common.h" | ||
#include <UserEnv.h> | ||
#include <Shlwapi.h> | ||
#include <fcntl.h> | ||
#include <Shlwapi.h> | ||
#include <shellapi.h> | ||
#include <libloaderapi.h> | ||
#include <wchar.h> | ||
#include <time.h> | ||
#include <stdio.h> | ||
|
||
const CLSID _CLSID_GroupPolicyObject = { | ||
0xea502722, 0xa23d, 0x11d1, {0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3}}; | ||
const IID _IID_IGroupPolicyObject = { | ||
0xea502723, 0xa23d, 0x11d1, {0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3}}; | ||
const CLSID _CLSID_GPESnapIn = { | ||
0x8fc0b734, 0xa0e1, 0x11d1, {0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3}}; | ||
GUID RegistryID = {0x35378EAC, | ||
0x683F, | ||
0x11D2, | ||
{0xA8, 0x9A, 0x00, 0xC0, 0x4F, 0xBB, 0xCF, 0xA2}}; | ||
GUID RegistryID; | ||
IGroupPolicyObject *pGPO; | ||
HKEY hKey; | ||
HKEY hSubKey; | ||
LONG result; | ||
|
||
wchar_t *get_log_directory() { | ||
wchar_t currentPath[MAX_PATH]; | ||
GetModuleFileNameW(NULL, currentPath, MAX_PATH); | ||
|
||
wchar_t *removeExe = wcsrchr(currentPath, L'\\'); | ||
if (removeExe != NULL) { | ||
*removeExe = L'\0'; | ||
} | ||
|
||
const wchar_t *dirName = L"W11Boost Logs"; | ||
wchar_t *fullPath = (wchar_t *)malloc(MAX_PATH * sizeof(wchar_t)); | ||
swprintf_s(fullPath, MAX_PATH, L"%s\\%s", currentPath, dirName); | ||
|
||
// Ensure double-null termination | ||
size_t len = wcslen(fullPath); | ||
if (len + 2 < MAX_PATH) { | ||
fullPath[len + 1] = L'\0'; | ||
} | ||
return fullPath; | ||
} | ||
|
||
utf8_result wide_string_to_utf8(const wchar_t *wide_string) { | ||
if (wide_string == NULL || *wide_string == U'\0') | ||
return (utf8_result){NULL, false}; | ||
|
||
size_t wide_length = 0; | ||
while (wide_string[wide_length] != U'\0') | ||
wide_length++; | ||
|
||
size_t size_needed = WideCharToMultiByte(CP_UTF8, 0, wide_string, wide_length, | ||
NULL, 0, NULL, NULL); | ||
if (size_needed <= 0) | ||
return (utf8_result){NULL, false}; | ||
|
||
char *result = (char *)malloc(size_needed + 1); | ||
if (result == NULL) | ||
return (utf8_result){NULL, false}; | ||
|
||
int converted_result = | ||
WideCharToMultiByte(CP_UTF8, 0, wide_string, (int)wide_length, &result[0], | ||
size_needed, NULL, NULL); | ||
if (converted_result <= 0) { | ||
free(result); | ||
return (utf8_result){NULL, true}; | ||
} | ||
result[size_needed] = '\0'; | ||
return (utf8_result){result, false}; // if SUCCESS (0), proceed | ||
} | ||
|
||
int log_registry(const wchar_t *subKey, const wchar_t *valueName, | ||
const char *typeName) { | ||
wchar_t *currentDir = get_log_directory(); | ||
wchar_t logLocation[MAX_PATH]; | ||
swprintf_s(logLocation, MAX_PATH, L"%s\\Registry.log", currentDir); | ||
|
||
FILE *logFile = NULL; | ||
errno_t err = _wfopen_s(&logFile, logLocation, L"a"); | ||
if (err != 0 || logFile == NULL) | ||
return EXIT_FAILURE; | ||
|
||
if (logFile) { | ||
time_t now; | ||
time(&now); | ||
|
||
struct tm timeInfo; | ||
localtime_s(&timeInfo, &now); | ||
|
||
char timeString[20]; // 19 char + 1 null terminator | ||
strftime(timeString, sizeof(timeString), "%d-%m-%Y %H:%M:%S", &timeInfo); | ||
|
||
utf8_result narrow_subKey = wide_string_to_utf8(subKey); | ||
utf8_result narrow_valueName = wide_string_to_utf8(valueName); | ||
|
||
if (!narrow_subKey.error && !narrow_valueName.error) { | ||
fprintf_s(logFile, "%s %s %s\\%s\n", timeString, typeName, | ||
narrow_subKey.string, narrow_valueName.string); | ||
} | ||
} | ||
fclose(logFile); | ||
free(currentDir); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
LSTATUS set_dword(HKEY hKey, const wchar_t *subKey, const wchar_t *valueName, | ||
const DWORD value) { | ||
result = RegCreateKeyExW(hKey, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, | ||
KEY_WRITE, NULL, &hSubKey, NULL); | ||
|
||
if (result == ERROR_SUCCESS) | ||
result = RegSetValueExW(hSubKey, valueName, 0, REG_DWORD, | ||
(const BYTE *)&value, sizeof(DWORD)); | ||
|
||
const char *typeName = " - DWORD: "; | ||
log_registry(subKey, valueName, typeName); | ||
|
||
result = RegCloseKey(hSubKey); | ||
return result; | ||
} | ||
|
||
LSTATUS set_string(HKEY hKey, const wchar_t *subKey, const wchar_t *valueName, | ||
const wchar_t *value) { | ||
result = RegCreateKeyExW(hKey, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, | ||
KEY_WRITE, NULL, &hSubKey, NULL); | ||
|
||
if (result != ERROR_SUCCESS) | ||
return EXCEPTION_EXECUTE_HANDLER; | ||
|
||
result = RegSetValueExW(hSubKey, valueName, 0, REG_SZ, (const BYTE *)value, | ||
sizeof(wchar_t)); | ||
|
||
if (result != ERROR_SUCCESS) | ||
return EXCEPTION_EXECUTE_HANDLER; | ||
|
||
result = RegCloseKey(hSubKey); | ||
|
||
if (result != ERROR_SUCCESS) | ||
return EXCEPTION_EXECUTE_HANDLER; | ||
|
||
const char *typeName = " - SZ: "; | ||
log_registry(subKey, valueName, typeName); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
LSTATUS set_environment(HKEY hKey, const wchar_t *valueName, | ||
const wchar_t *value) { | ||
const wchar_t *subKey = | ||
L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"; | ||
result = RegOpenKeyExW(hKey, subKey, 0, KEY_ALL_ACCESS, &hSubKey); | ||
|
||
if (result == ERROR_SUCCESS) | ||
result = | ||
RegSetValueExW(hSubKey, valueName, 0, REG_EXPAND_SZ, | ||
(const BYTE *)value, (wcslen(value) * sizeof(wchar_t))); | ||
|
||
const char *typeName = " - EXPAND_SZ: "; | ||
log_registry(subKey, valueName, typeName); | ||
|
||
result = RegCloseKey(hSubKey); | ||
return result; | ||
} | ||
|
||
LSTATUS remove_subkey(HKEY hKey, const wchar_t *subKey, | ||
const wchar_t *valueName) { | ||
HKEY hSubKey; | ||
result = RegOpenKeyExW(hKey, subKey, 0, KEY_WRITE, &hSubKey); | ||
|
||
if (result == ERROR_SUCCESS) | ||
result = RegDeleteValueW(hSubKey, valueName); | ||
|
||
const char *typeName = " - Removed subkey: "; | ||
log_registry(subKey, valueName, typeName); | ||
|
||
result = RegCloseKey(hSubKey); | ||
return result; | ||
} | ||
|
||
void gp_cleanup(HRESULT hr) { | ||
RegCloseKey(hKey); | ||
|
||
if (SUCCEEDED(hr)) | ||
hr = pGPO->lpVtbl->Save(pGPO, TRUE, TRUE, &RegistryID, | ||
(GUID *)&_CLSID_GPESnapIn); | ||
|
||
// Apply new policy objects to the registry | ||
RefreshPolicyEx(TRUE, RP_FORCE); | ||
|
||
if (pGPO) | ||
pGPO->lpVtbl->Release(pGPO); | ||
} | ||
|
||
int start_command_and_wait(wchar_t *cmdLine) { | ||
STARTUPINFOW si; | ||
PROCESS_INFORMATION pi; | ||
|
||
SecureZeroMemory(&si, sizeof(si)); | ||
si.cb = sizeof(si); | ||
SecureZeroMemory(&pi, sizeof(pi)); | ||
|
||
if (!CreateProcessW(NULL, cmdLine, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, | ||
NULL, &si, &pi)) | ||
return EXIT_FAILURE; | ||
|
||
WaitForSingleObject(pi.hProcess, INFINITE); | ||
|
||
CloseHandle(pi.hProcess); | ||
CloseHandle(pi.hThread); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
bool append_wchar_t(const wchar_t *original, const wchar_t *append, | ||
wchar_t *result) { | ||
wcscpy_s(result, MAX_PATH, original); | ||
if (SUCCEEDED(PathAppendW(result, append))) | ||
return true; | ||
|
||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef COMMON_H | ||
#define COMMON_H | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> // Always first | ||
#include <combaseapi.h> | ||
#include <prsht.h> | ||
#include <gpedit.h> // Requires prsht.h first; not unused | ||
#include <stdbool.h> | ||
|
||
extern const CLSID _CLSID_GroupPolicyObject; | ||
extern const IID _IID_IGroupPolicyObject; | ||
extern const CLSID _CLSID_GPESnapIn; | ||
|
||
extern GUID RegistryID; | ||
extern IGroupPolicyObject *pGPO; | ||
extern HKEY hKey; | ||
extern HKEY hSubKey; | ||
extern LONG result; | ||
|
||
typedef struct { | ||
char *string; | ||
bool error; | ||
} utf8_result; | ||
|
||
int install_privacy_mode(); | ||
utf8_result wide_string_to_utf8(const wchar_t *wide_string); | ||
int log_registry(const wchar_t *subKey, const wchar_t *valueName, | ||
const char *typeName); | ||
LSTATUS set_dword(HKEY hKey, const wchar_t *subKey, const wchar_t *valueName, | ||
const DWORD value); | ||
|
||
LSTATUS set_string(HKEY hKey, const wchar_t *subKey, const wchar_t *valueName, | ||
const wchar_t *value); | ||
LSTATUS set_environment(HKEY hKey, const wchar_t *valueName, | ||
const wchar_t *value); | ||
LSTATUS remove_subkey(HKEY hKey, const wchar_t *subKey, | ||
const wchar_t *valueName); | ||
void gp_cleanup(HRESULT hr); | ||
int start_command_and_wait(wchar_t *cmdLine); | ||
bool append_wchar_t(const wchar_t *original, const wchar_t *append, | ||
wchar_t *result); | ||
int download_file(const wchar_t *url, const wchar_t *destination); | ||
int install_microsoft_store(); | ||
void restorepoint_prep(); | ||
int create_restore_point(); | ||
int gp_edits(); | ||
wchar_t *get_log_directory(); | ||
|
||
#endif // COMMON_H |
Oops, something went wrong.