9 Commits
Author SHA1 Message Date
TheTank20 79bd667054 Update README.md 2023-12-21 17:55:32 +00:00
TheTank20 5da134e7f0 fixed broken error codes 2023-12-21 12:49:43 -05:00
TheTank20 b64e3d0cb2 Merge remote-tracking branch 'origin/master' 2023-12-21 12:46:34 -05:00
TheTank20 823e44ec56 more fixes 2023-12-21 12:46:26 -05:00
TheTank20 d3e9089700 Fixed errors not showing up 2023-12-21 12:39:22 -05:00
TheTank20 7ca11132b8 fixed again 2023-12-21 16:51:39 +00:00
TheTank20 650f94babf fix build instructions 2023-12-21 16:41:51 +00:00
TheTank20 0dce831512 Remove misplaced test file 2023-12-21 02:04:55 +00:00
TheTank20 a829a21a17 Remove unneeded file 2023-12-21 02:04:41 +00:00
4 changed files with 147 additions and 48 deletions

No files matched your search

+11 -4
View File
@@ -26,6 +26,8 @@ If you're trying to manage products other than Windows, you need `xpmgr_x86.exe`
`--Office2003`: This provides **EXPERIMENTAL** support for Office 2003. When this parameter is used, all other parameters except `--GetInstallationID` and `--SetConfirmationID` are disabled, and those two (attempt) to go what they do on Office 2003, rather than Windows.
`--BypassInstallCheck`: Disables the check to see if Office 2003 is installed. Intended for debugging purposes only. If it doesn't work without this enabled, it probably won't work with it either.
`--GetUsage`: Outputs all the commands you can use.
## Releases
@@ -37,8 +39,13 @@ Make sure Visual Studio 2017 or later is installed. Then, install [TDM-GCC](http
mkdir build
mkdir build\x86
mkdir build\x64
windres icon.rc -O coff -F pe-i386 -o build\x64\icon_x64.res
g++ -m32 -o build\x86\xpmgr_x86 xpmgr.cpp build\x64\icon_x64.res -lole32 -luuid -loleaut32
windres icon.rc -O coff -o build\x86\icon_x86.res
g++ -o build\x64\xpmgr_x64 xpmgr.cpp build\x86\icon_x86.res -lole32 -luuid -loleaut32
windres icon.rc -F pe-i386 -O coff -o build\x86\icon_x86.res
g++ -m32 -o build\x86\xpmgr_x86 xpmgr.cpp build\x86\icon_x86.res -lole32 -luuid -loleaut32
windres icon.rc -O coff -o build\x64\icon_x64.res
g++ -o build\x64\xpmgr_x64 xpmgr.cpp build\x64\icon_x64.res -lole32 -luuid -loleaut32
```
Or, if you like one-liners:
```
mkdir build & mkdir build\x86 & mkdir build\x64 & windres icon.rc -F pe-i386 -O coff -o build\x86\icon_x86.res & g++ -m32 -o build\x86\xpmgr_x86 xpmgr.cpp build\x86\icon_x86.res -lole32 -luuid -loleaut32 & windres icon.rc -O coff -o build\x64\icon_x64.res & g++ -o build\x64\xpmgr_x64 xpmgr.cpp build\x64\icon_x64.res -lole32 -luuid -loleaut32
```
-16
View File
@@ -1,16 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by xpmgr.rc
//
#define IDI_ICON1 101
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
-3
View File
@@ -1,3 +0,0 @@
14037188531115461057117122732036502128316172554233
115654-870803-633253-538651-586936-689612-768696
+136 -25
View File
@@ -223,7 +223,11 @@ static BOOL XP_LoadLicenseManager()
if (!XP_ComInitialized) {
HRESULT status = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(status)) {
std::cout << "An error occurred at CoInitializeEx: ", status;
const char* errorString = "An error occurred at CoInitializeEx:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
std::cout << result;
return FALSE;
}
XP_ComInitialized = TRUE;
@@ -243,7 +247,11 @@ static BOOL XP_LoadLicenseManager()
}
}
if (!good) {
std::cout << "An error occurred at CoCreateInstance: " + status;
const char* errorString = "An error occurred at CoCreateInstance:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
std::cout << result;
return FALSE;
}
}
@@ -255,7 +263,11 @@ static BOOL O2003_LoadLicenseManager()
if (!O2003_ComInitialized) {
HRESULT status = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(status)) {
std::cout << "An error occurred at CoInitializeEx: ", status;
const char* errorString = "An error occurred at CoInitializeEx:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
std::cout << result;
return FALSE;
}
O2003_ComInitialized = TRUE;
@@ -275,7 +287,11 @@ static BOOL O2003_LoadLicenseManager()
}
}
if (!good) {
std::cout << "An error occurred at CoCreateInstance: " + status;
const char* errorString = "An error occurred at CoCreateInstance:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
std::cout << result;
return FALSE;
}
}
@@ -375,12 +391,28 @@ BSTR ConvertCharToBSTR(const char* charString) {
return bstr;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
void safeStrncat(char* destination, const char* source, size_t size) {
size_t destLen = strlen(destination);
size_t srcLen = strlen(source);
if (destLen + srcLen < size) {
// fuck off Microsoft
strncat(destination, source, size - destLen - 1); // -1 for the null terminator
} else {
// Handle buffer overflow error
std::cout << "An error occurred at safeStrncat: Buffer overflow during strncat operation." << std::endl;
}
}
#pragma clang diagnostic pop
bool IsProcessRunning(const wchar_t* processName)
{
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE)
{
std::cerr << "Failed to create process snapshot." << std::endl;
std::cout << "An error occurred at IsProcessRunning: Failed to create process snapshot." << std::endl;
return false;
}
@@ -389,7 +421,7 @@ bool IsProcessRunning(const wchar_t* processName)
if (!Process32FirstW(snapshot, &processEntry))
{
CloseHandle(snapshot);
std::cerr << "Failed to retrieve process information." << std::endl;
std::cout << "An error occurred at IsProcessRunning: Failed to retrieve process information." << std::endl;
return false;
}
@@ -467,7 +499,14 @@ static BSTR XP_GetWPALeft() {
if (FAILED(status)) {
XP_LicenseAgent->Release();
XP_LicenseAgent = NULL;
return SysAllocString(L"An error occurred at GetExpirationInfo: " + status);
const char* errorString = "An error occurred at CoInitializeEx:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
if (dwWPALeft == 0x7FFFFFFF) {
return SysAllocString(L"An error occurred at GetWPALeft: Windows is activated");
@@ -485,7 +524,14 @@ static BSTR XP_GetEvalLeft() {
if (FAILED(status)) {
XP_LicenseAgent->Release();
XP_LicenseAgent = NULL;
return SysAllocString(L"An error occurred at GetExpirationInfo: " + status);
const char* errorString = "An error occurred at GetExpirationInfo:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
if (dwEvalLeft == 0x7FFFFFFF) {
return SysAllocString(L"An error occurred at GetEvalLeft: Not an evaluation copy");
@@ -505,7 +551,14 @@ static BSTR XP_VerifyCheckDigits(BSTR cidChunk) {
LONG pbValue;
HRESULT status = XP_LicenseAgent->VerifyCheckDigits(cidChunk, &pbValue);
if (FAILED(status) || !pbValue) {
return SysAllocString(L"An error occurred at XP_VerifyCheckDigits: " + pbValue);
char errorMessage[70] = "An error occurred at XP_VerifyCheckDigits:";
char pbValueChar[20];
snprintf(errorMessage, sizeof(errorMessage), "%ld", pbValue);
safeStrncat(errorMessage, pbValueChar, sizeof(errorMessage));
int len = MultiByteToWideChar(CP_UTF8, 0, errorMessage, -1, NULL, 0);
OLECHAR* oleCharString = new OLECHAR[len];
MultiByteToWideChar(CP_UTF8, 0, errorMessage, -1, oleCharString, len);
return SysAllocString(oleCharString);
}
return SysAllocString(L"Successfully verified CID chunk");
}
@@ -538,7 +591,15 @@ static BSTR XP_SetConfirmationID(BSTR confirmationID) {
ULONG dwRetCode;
HRESULT status = XP_LicenseAgent->DepositConfirmationId(confirmationID, &dwRetCode);
if (FAILED(status) || dwRetCode) {
return SysAllocString(L"An error occurred at DepositConfirmationId: " + status + dwRetCode);
const char* errorString = "An error occurred at DepositConfirmationId:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X %lu", errorString, static_cast<unsigned int>(status), dwRetCode);
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X %lu", errorString, static_cast<unsigned int>(status), dwRetCode);
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
system("rundll32 setupapi,InstallHinfSection DEL_OOBE_ACTIVATE 132 syssetup.inf"); // remove activation shortcuts
@@ -562,7 +623,14 @@ static BSTR XP_GetInstallationID() {
BSTR installationID = NULL;
HRESULT status = XP_LicenseAgent->GenerateInstallationId(&installationID);
if (FAILED(status) || !installationID) {
return SysAllocString(L"An error occurred at GenerateInstallationId: " + status);
const char* errorString = "An error occurred at GenerateInstallationId:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
else {
return installationID;
@@ -588,7 +656,14 @@ static BSTR XP_SetProductKey(LPWSTR productKey) {
HRESULT status = XP_LicenseAgent->SetProductKey(productKey);
if (FAILED(status)) {
return SysAllocString(L"An error occurred at SetProductKey: " + status);
const char* errorString = "An error occurred at SetProductKey:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
else {
return SysAllocString(L"Successfully set product key");
@@ -604,7 +679,14 @@ static BSTR XP_GetProductID() {
HRESULT status = XP_LicenseAgent->GetProductID(&productID);
if (FAILED(status)) {
return SysAllocString(L"An error occurred at GetProductID: " + status);
const char* errorString = "An error occurred at GetProductID:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
else {
return productID;
@@ -623,7 +705,15 @@ static BSTR O2003_VerifyCheckDigits(BSTR cidChunk) {
int pbValue;
HRESULT status = O2003_LicenseAgent->VerifyCheckDigits(cidChunk, &pbValue);
if (FAILED(status) || !pbValue) {
return SysAllocString(L"An error occurred at XP_VerifyCheckDigits: " + pbValue);
wchar_t error[] = L"An error occurred at XP_VerifyCheckDigits:";
std::wstring numberStr = std::to_wstring(pbValue);
std::wstring result = error + numberStr;
wchar_t buffer[100];
swprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), L"%s 0x%X %d", error, status, pbValue);
return SysAllocString(buffer);
}
return SysAllocString(L"Successfully verified CID chunk");
}
@@ -653,7 +743,14 @@ static BSTR O2003_SetConfirmationID(BSTR confirmationID) {
ULONG dwRetCode;
HRESULT status = O2003_LicenseAgent->DepositConfirmationId(confirmationID, &dwRetCode);
if (FAILED(status) || dwRetCode) {
return SysAllocString(L"An error occurred at DepositConfirmationId: " + status + dwRetCode);
const char* errorString = "An error occurred at DepositConfirmationId:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X %lu", errorString, static_cast<unsigned int>(status), dwRetCode);
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X %lu", errorString, static_cast<unsigned int>(status), dwRetCode);
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
return SysAllocString(L"Successfully set confirmation ID");
@@ -674,7 +771,14 @@ static BSTR O2003_GetInstallationID() {
HRESULT status = O2003_LicenseAgent->GenerateInstallationId(&installationID);
std::cout << "DEBUG: GenerateInstallationID executed";
if (FAILED(status) || !installationID) {
return SysAllocString(L"An error occurred at GenerateInstallationId: " + status);
const char* errorString = "An error occurred at GenerateInstallationId:";
int bufferSize = snprintf(nullptr, 0, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
char* result = new char[bufferSize + 1];
snprintf(result, bufferSize + 1, "%s 0x%08X", errorString, static_cast<unsigned int>(status));
int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, result, -1, nullptr, 0);
OLECHAR* wideResult = new OLECHAR[wideCharSize];
MultiByteToWideChar(CP_UTF8, 0, result, -1, wideResult, wideCharSize);
return SysAllocString(wideResult);
}
else {
return installationID;
@@ -683,6 +787,8 @@ static BSTR O2003_GetInstallationID() {
#pragma endregion
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
int main(int argc, char* argv[])
{
const char* text =
@@ -705,7 +811,11 @@ int main(int argc, char* argv[])
if (cmdOptionExists(argv, argv + argc, "--Office2003")) {
#ifdef ENVIRONMENT32
if (RegistryKeyExists(HKEY_CLASSES_ROOT, "CLSID\\{000C0114-0000-0000-C000-000000000046}")) {
if (cmdOptionExists(argv, argv + argc, "--BypassInstallCheck")) {
specifiedProduct = "Office2003";
}
else if (RegistryKeyExists(HKEY_CLASSES_ROOT, "CLSID\\{000C0114-0000-0000-C000-000000000046}")) {
specifiedProduct = "Office2003";
}
else {
@@ -727,7 +837,7 @@ int main(int argc, char* argv[])
specifiedProduct = "WindowsNT5x";
#endif
if (specifiedProduct == "WindowsNT5x") {
if (std::strcmp(specifiedProduct, "WindowsNT5x") == 0) {
SYSTEM_INFO systemInfo;
GetNativeSystemInfo(&systemInfo);
#ifdef ENVIRONMENT32
@@ -770,7 +880,7 @@ int main(int argc, char* argv[])
}
if (cmdOptionExists(argv, argv + argc, "--GetInstallationID")) {
if (specifiedProduct == "Office2003") {
if (std::strcmp(specifiedProduct, "Office2003") == 0) {
std::cout << ConvertToStdString(O2003_GetInstallationID());
return 0;
}
@@ -778,7 +888,7 @@ int main(int argc, char* argv[])
return 0;
}
else if (cmdOptionExists(argv, argv + argc, "--SetConfirmationID")) {
if (specifiedProduct == "Office2003") {
if (std::strcmp(specifiedProduct, "Office2003") == 0) {
std::cout << ConvertToStdString(O2003_SetConfirmationID(ConvertCharToBSTR(getCmdOption(argv, argv + argc, "--SetConfirmationID"))));
return 0;
}
@@ -787,7 +897,7 @@ int main(int argc, char* argv[])
}
else if (cmdOptionExists(argv, argv + argc, "--GetWPALeft")) {
if (specifiedProduct != "WindowsNT5x") {
if (std::strcmp(specifiedProduct, "WindowsNT5x") != 0) {
std::cout << "An error occurred at specifiedProduct: This command is for Windows management only.";
return 0;
}
@@ -795,7 +905,7 @@ int main(int argc, char* argv[])
return 0;
}
else if (cmdOptionExists(argv, argv + argc, "--GetEvalLeft")) {
if (specifiedProduct != "WindowsNT5x") {
if (std::strcmp(specifiedProduct, "WindowsNT5x") != 0) {
std::cout << "An error occurred at specifiedProduct: This command is for Windows management only.";
return 0;
}
@@ -804,7 +914,7 @@ int main(int argc, char* argv[])
}
else if (cmdOptionExists(argv, argv + argc, "--SetProductKey")) {
if (specifiedProduct != "WindowsNT5x") {
if (std::strcmp(specifiedProduct, "WindowsNT5x") != 0) {
std::cout << "An error occurred at specifiedProduct: This command is for Windows management only.";
return 0;
}
@@ -812,7 +922,7 @@ int main(int argc, char* argv[])
return 0;
}
else if (cmdOptionExists(argv, argv + argc, "--GetProductID")) {
if (specifiedProduct != "WindowsNT5x") {
if (std::strcmp(specifiedProduct, "WindowsNT5x") != 0) {
std::cout << "An error occurred at specifiedProduct: This command is for Windows management only.";
return 0;
}
@@ -824,4 +934,5 @@ int main(int argc, char* argv[])
std::cout << text;
return 0;
}
}
}
#pragma clang diagnostic pop