1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include <iostream>
#include <string>
#include <windows.h>
#include <winbase.h>
#include <WinReg.h>
void pause()
{
std::cin.sync();
std::cin.ignore();
}
bool ChangeRegistryKey()
{
HKEY RegKey; // Target Hive
HKEY ControlPanel; // Target Registry Key
DWORD RegKeySize; // Size Of Target Registry Key
std::string RegSubKeyName = "Wallpaper"; // Name Of Subkey
BYTE RegKeyData[MAX_PATH]; // Data In The Registry Keys
ZeroMemory(&RegKeyData, sizeof(MAX_PATH));
BYTE Data[] = "C:\\Picture.jpg\0";
DWORD Index = 0;
TCHAR KeyName[MAX_PATH]; // Subkeys In Target Registry Key
ZeroMemory(&KeyName, sizeof(MAX_PATH));
/* Open The Hive Containing The Target Registry Key In This Case HKEY_CURRENT_USER */
if(RegConnectRegistry(NULL, HKEY_CURRENT_USER, &RegKey) != ERROR_SUCCESS)
{
std::cout << "FAILED TO GET HKEY_CURRENT_USER\n" << GetLastError() << std::endl;
return false;
}
/* Open The Registry Key By Passing The Path Relative To The Key You Connected To With RegConnectRegistry Above */
if(RegOpenKey(RegKey, TEXT("Control Panel\\Desktop\\"), &ControlPanel) != ERROR_SUCCESS)
{
std::cout << "FAILED TO OPEN CONTROL PANEL\\DESKTOP\n" << GetLastError() << std::endl;
RegCloseKey(RegKey);
return false;
}
/* The First Call To This Function Is Just To Get The Size Of The Key For Reading And Stores It In RegKeySize */
RegQueryValueEx(ControlPanel, RegSubKeyName.c_str(), NULL, NULL, NULL, &RegKeySize);
/* Now That We Know The Size We Can Tell The Function How Much To Expect */
RegQueryValueEx(ControlPanel, RegSubKeyName.c_str(), NULL, NULL, RegKeyData, &RegKeySize);
/* Display Data Currently Held By The Target Registry Key In Case You Are Interested */
//std::cout << RegKeyData << std::endl;
/* Verify The Contents Of The Registry Key If You Would Like */
/* while(RegEnumKey(ControlPanel, Index, KeyName, MAX_PATH) != ERROR_NO_MORE_ITEMS)
{
Index++;
std::cout << KeyName << std::endl;
ZeroMemory(&KeyName, sizeof(MAX_PATH));
}
std::cout << "\nTHATS ALL OF THE KEYS HERE\n" << Index << std::endl;
pause(); */
/*Use RegSetKey To Change The Target Registry Key */
if(RegSetValueEx(ControlPanel, "Wallpaper", 0, REG_SZ, Data, sizeof(Data)) != ERROR_SUCCESS)
{
std::cout << "FAILED TO SET WALLPAPER\n" << GetLastError() << std::endl;
RegCloseKey(RegKey);
RegCloseKey(ControlPanel);
return false;
}
if(RegSetValueEx(ControlPanel, "OriginalWallpaper", 0, REG_SZ, Data, sizeof(Data)) != ERROR_SUCCESS)
{
std::cout << "FAILED TO SET WALLPAPER\n" << GetLastError() << std::endl;
RegCloseKey(RegKey);
RegCloseKey(ControlPanel);
return false;
}
if(RegSetValueEx(ControlPanel, "ConvertedWallpaper", 0, REG_SZ, Data, sizeof(Data)) != ERROR_SUCCESS)
{
std::cout << "FAILED TO SET WALLPAPER\n" << GetLastError() << std::endl;
RegCloseKey(RegKey);
RegCloseKey(ControlPanel);
return false;
}
RegCloseKey(RegKey);
RegCloseKey(ControlPanel);
return true;
}
int main(int argc, char *argv[])
{
/* Load The Library That Contains The Target Function Using The Windows "TEXT()" Macro */
HMODULE User32 = LoadLibrary("C:\\WINDOWS\\system32\\user32.dll");
std::cout << "1 ERROR CODE AT THIS POINT: " << GetLastError() << std::endl;
/* Make Sure The DLL Loaded Properly */
if(User32 == NULL)
{
std::cout << "FAILED TO LOAD DLL";
pause();
return 1;
}
std::cout << "2 ERROR CODE AT THIS POINT: " << GetLastError() << std::endl;
/* Call Our Function */
if(!ChangeRegistryKey())
{
std::cout << "FAILED TO CONNECT TO REGISTRY\n" << GetLastError() << std::endl;
pause();
return 2;
}
std::cout << "3 ERROR CODE AT THIS POINT: " << GetLastError() << std::endl;
/* Get Exported Functions Address */
LPVOID UpdatePerUserSystemParameters = (LPVOID) GetProcAddress(User32, "UpdatePerUserSystemParameters");
if(UpdatePerUserSystemParameters == NULL)
{
std::cout << "FAILED TO GET FUNCTION ADDRESS\n" << GetLastError() << std::endl;
pause();
return 3;
}
/* You Can Verify The Adderss That The Pointer Holds With DLL Export Viewer By Nirsoft */
//std::cout << UpdatePerUserSystemParameters;
/* Be Lazy, Launch The Function With CreateThread Instead Of Dealing With Function Pointers That Have Unknown Data Types */
HANDLE MyThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) UpdatePerUserSystemParameters, NULL, CREATE_SUSPENDED, NULL);
/* Remind User That The Thread Was Created In Suspended Mode */
std::cout << "Press ENTER To Launch\n";
pause();
/* Resume Thread And Wait For It To Finish */
ResumeThread(MyThread);
WaitForSingleObject(MyThread, INFINITE);
std::cout << "\"MyThread\" Completed\n";
/* Clean Up */
FreeLibrary(User32);
CloseHandle(MyThread);
pause();
return EXIT_SUCCESS;
}
|