Further decomposition
This commit is contained in:
parent
aafe5ce277
commit
1b6d38d222
8
header.h
8
header.h
|
@ -129,12 +129,13 @@ void generateServerKey(
|
||||||
ul32 *prefix
|
ul32 *prefix
|
||||||
);
|
);
|
||||||
|
|
||||||
void generate2003(char *pkey, EC_GROUP *ec, EC_POINT *generator, BIGNUM *order, BIGNUM *priv, ul32 *osfamily, ul32 *prefix);
|
|
||||||
|
|
||||||
// utilities.cpp
|
// utilities.cpp
|
||||||
void endiannessConvert(byte *data, int length);
|
void endiannessConvert(byte *data, int length);
|
||||||
ul32 randomRange(ul32 dwLow, ul32 dwHigh);
|
ul32 randomRange(ul32 dwLow, ul32 dwHigh);
|
||||||
|
|
||||||
|
void stopAudio();
|
||||||
|
bool playAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags);
|
||||||
|
|
||||||
EC_GROUP *initializeEllipticCurve(
|
EC_GROUP *initializeEllipticCurve(
|
||||||
const char *pSel,
|
const char *pSel,
|
||||||
long aSel,
|
long aSel,
|
||||||
|
@ -153,6 +154,9 @@ EC_GROUP *initializeEllipticCurve(
|
||||||
void unbase24(ul32 *byteSeq, const char *cdKey);
|
void unbase24(ul32 *byteSeq, const char *cdKey);
|
||||||
void base24(char *cdKey, ul32 *byteSeq);
|
void base24(char *cdKey, ul32 *byteSeq);
|
||||||
|
|
||||||
|
void formatXP(WCHAR *pBSection, WCHAR *pCSection, WCHAR *pText);
|
||||||
|
void formatServer(WCHAR *pText);
|
||||||
|
|
||||||
// windows.cpp
|
// windows.cpp
|
||||||
bool InitializeWindow(HINSTANCE hInstance);
|
bool InitializeWindow(HINSTANCE hInstance);
|
||||||
|
|
||||||
|
|
79
key.cpp
79
key.cpp
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "header.h"
|
#include "header.h"
|
||||||
|
|
||||||
/* Convert from byte sequence to the CD-key. */
|
/* Converts from byte sequence to the CD-key. */
|
||||||
void base24(char *cdKey, ul32 *byteSeq) {
|
void base24(char *cdKey, ul32 *byteSeq) {
|
||||||
byte rbs[16];
|
byte rbs[16];
|
||||||
BIGNUM *z;
|
BIGNUM *z;
|
||||||
|
@ -30,7 +30,7 @@ void base24(char *cdKey, ul32 *byteSeq) {
|
||||||
BN_free(z);
|
BN_free(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert from CD-key to a byte sequence. */
|
/* Converts from CD-key to a byte sequence. */
|
||||||
void unbase24(ul32 *byteSeq, const char *cdKey) {
|
void unbase24(ul32 *byteSeq, const char *cdKey) {
|
||||||
byte pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
|
byte pDecodedKey[PK_LENGTH + NULL_TERMINATOR]{};
|
||||||
BIGNUM *y = BN_new();
|
BIGNUM *y = BN_new();
|
||||||
|
@ -66,3 +66,78 @@ void unbase24(ul32 *byteSeq, const char *cdKey) {
|
||||||
// Reverse the byte sequence.
|
// Reverse the byte sequence.
|
||||||
endiannessConvert((byte *) byteSeq, n);
|
endiannessConvert((byte *) byteSeq, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Formats Windows XP key output. */
|
||||||
|
void formatXP(WCHAR *pBSection, WCHAR *pCSection, WCHAR *pText) {
|
||||||
|
WCHAR pFPK[32]{};
|
||||||
|
|
||||||
|
int pSSection = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < wcslen(pCSection); i++)
|
||||||
|
pSSection -= pCSection[i] - '0';
|
||||||
|
|
||||||
|
while (pSSection < 0)
|
||||||
|
pSSection += 7;
|
||||||
|
|
||||||
|
char pKey[PK_LENGTH + NULL_TERMINATOR]{};
|
||||||
|
ul32 msDigits = _wtoi(pBSection),
|
||||||
|
lsDigits = _wtoi(pCSection);
|
||||||
|
|
||||||
|
ul32 nRPK = msDigits * 1'000'000 + lsDigits,
|
||||||
|
hash = 0,
|
||||||
|
bKey[4]{},
|
||||||
|
bSig[2]{};
|
||||||
|
|
||||||
|
bool bValid = keyXP(pKey, nRPK);
|
||||||
|
|
||||||
|
unbase24(bKey, pKey);
|
||||||
|
unpackXP(nullptr, &hash, bSig, bKey);
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]);
|
||||||
|
|
||||||
|
wsprintfW(
|
||||||
|
pText,
|
||||||
|
L"Product ID:\tPPPPP-%03d-%06d%d-23XXX\r\n\r\nBytecode:\t%08lX %08lX %08lX %08lX\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n",
|
||||||
|
nRPK / 1'000'000,
|
||||||
|
nRPK % 1'000'000,
|
||||||
|
pSSection,
|
||||||
|
bKey[3], bKey[2], bKey[1], bKey[0],
|
||||||
|
hash,
|
||||||
|
bSig[1], bSig[0],
|
||||||
|
bValid ? L"True" : L"False",
|
||||||
|
pFPK
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Formats Windows Server 2003 key output. */
|
||||||
|
void formatServer(WCHAR *pText) {
|
||||||
|
WCHAR pFPK[32]{};
|
||||||
|
|
||||||
|
char pKey[PK_LENGTH + NULL_TERMINATOR]{};
|
||||||
|
ul32 hash = 0,
|
||||||
|
osFamily = 0,
|
||||||
|
prefix = 0,
|
||||||
|
bKey[4]{},
|
||||||
|
bSig[2]{};
|
||||||
|
|
||||||
|
bool bValid = keyServer(pKey);
|
||||||
|
|
||||||
|
unbase24(bKey, pKey);
|
||||||
|
unpackServer(&osFamily, &hash, bSig, &prefix, bKey);
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]);
|
||||||
|
|
||||||
|
wsprintfW(
|
||||||
|
pText,
|
||||||
|
L"Bytecode:\t%08lX %08lX %08lX %08lX\r\nOS Family:\t%d\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nPrefix:\t\t%04lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n",
|
||||||
|
bKey[3], bKey[2], bKey[1], bKey[0],
|
||||||
|
osFamily,
|
||||||
|
hash,
|
||||||
|
bSig[1], bSig[0],
|
||||||
|
prefix,
|
||||||
|
bValid ? L"True" : L"False",
|
||||||
|
pFPK
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,34 @@ void endiannessConvert(byte *data, int length) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Generates a random 32-bit integer in range. */
|
||||||
|
ul32 randomRange(ul32 dwLow, ul32 dwHigh) {
|
||||||
|
return rand() % (dwHigh - dwLow) + dwLow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Stops current asynchronously played audio. */
|
||||||
|
void stopAudio() {
|
||||||
|
PlaySoundW(nullptr, nullptr, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Plays audio stored as a resource. */
|
||||||
|
bool playAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags) {
|
||||||
|
HANDLE hResInfo = FindResourceW(hInstance, lpName, L"WAVE");
|
||||||
|
|
||||||
|
if (hResInfo == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
HANDLE hRes = LoadResource(hInstance, (HRSRC)hResInfo);
|
||||||
|
|
||||||
|
if (hRes == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
WCHAR *lpRes = (WCHAR *)LockResource(hRes);
|
||||||
|
FreeResource(hRes);
|
||||||
|
|
||||||
|
return sndPlaySoundW(lpRes, SND_MEMORY | bFlags);
|
||||||
|
}
|
||||||
|
|
||||||
/* Initializes the elliptic curve. */
|
/* Initializes the elliptic curve. */
|
||||||
EC_GROUP *initializeEllipticCurve(
|
EC_GROUP *initializeEllipticCurve(
|
||||||
const char *pSel,
|
const char *pSel,
|
||||||
|
@ -85,8 +113,3 @@ EC_GROUP *initializeEllipticCurve(
|
||||||
|
|
||||||
return eCurve;
|
return eCurve;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generates a random 32-bit integer in range. */
|
|
||||||
ul32 randomRange(ul32 dwLow, ul32 dwHigh) {
|
|
||||||
return rand() % (dwHigh - dwLow) + dwLow;
|
|
||||||
}
|
|
101
windows.cpp
101
windows.cpp
|
@ -22,102 +22,6 @@ const WCHAR *pAboutLink = L"https://github.com/Endermanch/XPKeygen",
|
||||||
bool bServer = false,
|
bool bServer = false,
|
||||||
bMusic = true;
|
bMusic = true;
|
||||||
|
|
||||||
void formatXP(WCHAR *pBSection, WCHAR *pCSection, WCHAR *pText) {
|
|
||||||
WCHAR pFPK[32]{};
|
|
||||||
|
|
||||||
int pSSection = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < wcslen(pCSection); i++)
|
|
||||||
pSSection -= pCSection[i] - '0';
|
|
||||||
|
|
||||||
while (pSSection < 0)
|
|
||||||
pSSection += 7;
|
|
||||||
|
|
||||||
char pKey[PK_LENGTH + NULL_TERMINATOR]{};
|
|
||||||
ul32 msDigits = _wtoi(pBSection),
|
|
||||||
lsDigits = _wtoi(pCSection);
|
|
||||||
|
|
||||||
ul32 nRPK = msDigits * 1'000'000 + lsDigits,
|
|
||||||
hash = 0,
|
|
||||||
bKey[4]{},
|
|
||||||
bSig[2]{};
|
|
||||||
|
|
||||||
bool bValid = keyXP(pKey, nRPK);
|
|
||||||
|
|
||||||
unbase24(bKey, pKey);
|
|
||||||
unpackXP(nullptr, &hash, bSig, bKey);
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]);
|
|
||||||
|
|
||||||
wsprintfW(
|
|
||||||
pText,
|
|
||||||
L"Product ID:\tPPPPP-%03d-%06d%d-23XXX\r\n\r\nBytecode:\t%08lX %08lX %08lX %08lX\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n",
|
|
||||||
nRPK / 1'000'000,
|
|
||||||
nRPK % 1'000'000,
|
|
||||||
pSSection,
|
|
||||||
bKey[3], bKey[2], bKey[1], bKey[0],
|
|
||||||
hash,
|
|
||||||
bSig[1], bSig[0],
|
|
||||||
bValid ? L"True" : L"False",
|
|
||||||
pFPK
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void formatServer(WCHAR *pText) {
|
|
||||||
WCHAR pFPK[32]{};
|
|
||||||
|
|
||||||
char pKey[PK_LENGTH + NULL_TERMINATOR]{};
|
|
||||||
ul32 hash = 0,
|
|
||||||
osFamily = 0,
|
|
||||||
prefix = 0,
|
|
||||||
bKey[4]{},
|
|
||||||
bSig[2]{};
|
|
||||||
|
|
||||||
bool bValid = keyServer(pKey);
|
|
||||||
|
|
||||||
unbase24(bKey, pKey);
|
|
||||||
unpackServer(&osFamily, &hash, bSig, &prefix, bKey);
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
wsprintfW(pFPK, L"%s%s%.5S", pFPK, i != 0 ? L"-" : L"", &pKey[5 * i]);
|
|
||||||
|
|
||||||
wsprintfW(
|
|
||||||
pText,
|
|
||||||
L"Bytecode:\t%08lX %08lX %08lX %08lX\r\nOS Family:\t%d\r\nHash:\t\t%08lX\r\nSignature:\t%08lX %08lX\r\nPrefix:\t\t%04lX\r\nCurve Point:\t%s\r\n\r\n%s\r\n",
|
|
||||||
bKey[3], bKey[2], bKey[1], bKey[0],
|
|
||||||
osFamily,
|
|
||||||
hash,
|
|
||||||
bSig[1], bSig[0],
|
|
||||||
prefix,
|
|
||||||
bValid ? L"True" : L"False",
|
|
||||||
pFPK
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void StopAudio() {
|
|
||||||
PlaySoundW(nullptr, nullptr, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PlayAudio(HINSTANCE hInstance, WCHAR *lpName, UINT bFlags) {
|
|
||||||
HANDLE hResInfo = FindResourceW(hInstance, lpName, L"WAVE");
|
|
||||||
|
|
||||||
if (hResInfo == nullptr)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
HANDLE hRes = LoadResource(hInstance, (HRSRC)hResInfo);
|
|
||||||
|
|
||||||
if (hRes == nullptr)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
WCHAR *lpRes = (WCHAR *)LockResource(hRes);
|
|
||||||
FreeResource(hRes);
|
|
||||||
|
|
||||||
return sndPlaySoundW(lpRes, SND_MEMORY | bFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bitmap link processor. */
|
/* Bitmap link processor. */
|
||||||
LRESULT BitmapLinkProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
|
LRESULT BitmapLinkProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
|
||||||
static TRACKMOUSEEVENT trackMouse;
|
static TRACKMOUSEEVENT trackMouse;
|
||||||
|
@ -232,6 +136,7 @@ LRESULT StaticLinkProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam, UI
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Main window processor. */
|
||||||
LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lParam) {
|
LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lParam) {
|
||||||
static HINSTANCE hInstance;
|
static HINSTANCE hInstance;
|
||||||
|
|
||||||
|
@ -442,7 +347,7 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar
|
||||||
case STN_CLICKED:
|
case STN_CLICKED:
|
||||||
if (bMusic) {
|
if (bMusic) {
|
||||||
SendMessageW((HWND)lParam, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBMusicOff);
|
SendMessageW((HWND)lParam, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBMusicOff);
|
||||||
StopAudio();
|
stopAudio();
|
||||||
|
|
||||||
bMusic = false;
|
bMusic = false;
|
||||||
}
|
}
|
||||||
|
@ -622,6 +527,7 @@ LRESULT CALLBACK WNDProc(HWND hWindow, UINT uMessage, WPARAM wParam, LPARAM lPar
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialize system fonts. */
|
||||||
void InitializeFonts(HFONT *hLabelFont, HFONT *hSmolFont, HFONT *hBoldFont, HFONT *hCaptionFont) {
|
void InitializeFonts(HFONT *hLabelFont, HFONT *hSmolFont, HFONT *hBoldFont, HFONT *hCaptionFont) {
|
||||||
NONCLIENTMETRICSW nonClientMetrics;
|
NONCLIENTMETRICSW nonClientMetrics;
|
||||||
|
|
||||||
|
@ -648,6 +554,7 @@ void InitializeFonts(HFONT *hLabelFont, HFONT *hSmolFont, HFONT *hBoldFont, HFON
|
||||||
*hCaptionFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont);
|
*hCaptionFont = CreateFontIndirectW(&nonClientMetrics.lfMessageFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialize main window. */
|
||||||
bool InitializeWindow(HINSTANCE hInstance) {
|
bool InitializeWindow(HINSTANCE hInstance) {
|
||||||
HFONT hLabelFont,
|
HFONT hLabelFont,
|
||||||
hSmolFont,
|
hSmolFont,
|
||||||
|
|
Loading…
Reference in New Issue