Skip to content

Instantly share code, notes, and snippets.

@Justasic
Created March 19, 2014 01:05
Show Gist options
  • Save Justasic/9633530 to your computer and use it in GitHub Desktop.
Save Justasic/9633530 to your computer and use it in GitHub Desktop.
This was just a template keygen I use for solving crackmes on http://crackmes.de/
#include <Windows.h>
#include <malloc.h>
#include <tchar.h>
#include <string>
#include <cstring>
#include <memory.h>
#include <cstdlib>
inline LPWSTR char2wchar(const char *str)
{
wchar_t *wtext = (wchar_t*)malloc(strlen(str));
mbstowcs(wtext, str, (1 << 16));
return wtext;
}
// FUnction prototypes
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
HBRUSH CreateHexBrush(int hex)
{
int red = ((hex >> 16) & 0xFF) / 1.0;
int green = ((hex >> 8) & 0xFF) / 1.0;
int blue = ((hex) & 0xFF) / 1.0;
if (red < 256 && green < 256 && blue < 256)
return CreateSolidBrush(RGB(red, green, blue));
return NULL;
}
HINSTANCE hInst;
const char szClassName[] = "Keygen Sample";
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpSzArgument, int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hInst = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS | CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = CreateHexBrush(0xF0F0F0);
if (!RegisterClassEx(&wincl))
return 0;
hwnd = CreateWindowEx(
0, // Extended possibilities for variation
szClassName, // Class name
"Keygen", // Window title
(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX),
CW_USEDEFAULT, // Window decides position
CW_USEDEFAULT, // where the window ends up on the screen
235, // Width
135, // Height
HWND_DESKTOP, // The window is a child-window of desktop
NULL, // No Menu
hThisInstance,
NULL // No Creation data
);
ShowWindow(hwnd, nFunsterStil);
while (GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
// WIndow procedure for handling window drawing and events
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lparam)
{
switch (message)
{
case WM_CREATE:
LOGFONT lf;
HFONT hMyFont;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfWeight = FW_NORMAL;
lf.lfHeight = 15;
strcpy(lf.lfFaceName, "Arial");
hMyFont = CreateFontIndirect(&lf);
CreateWindowEx(WS_EX_CLIENTEDGE, "button", "Generate", WS_VISIBLE | WS_CHILD, 15, 55, 65, 20, hwnd, (HMENU)1, NULL, NULL);
CreateWindowEx(WS_EX_CLIENTEDGE, "button", "Leave", WS_VISIBLE | WS_CHILD, 140, 55, 65, 20, hwnd, (HMENU)2, NULL, NULL);
CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_CENTER, 15, 5, 190, 20, hwnd, (HMENU)3, NULL, NULL);
CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "Click Generate", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_CENTER | ES_READONLY | ES_UPPERCASE, 15, 25, 190, 20, hwnd, (HMENU)4, NULL, NULL);
CreateWindow("STATIC", "Created by Justasic", WS_VISIBLE | WS_CHILD | SS_CENTER, 25, 80, 150, 15, hwnd, (HMENU)5, NULL, NULL);
// Create the control fonts since the windows normal ones suck
for (int i = 1; i < 6; ++i)
SendMessage(GetDlgItem(hwnd, i), WM_SETFONT, (WPARAM)hMyFont, 0);
break;
case WM_COMMAND:
if (LOWORD(wParam) == 1)
{
HWND output = GetDlgItem(hwnd, 3);
HWND genbutton = GetDlgItem(hwnd, 4);
// Gegerate button called, do ur calcs here.
const char *str = "Sry. No implement.";
SetWindowText(output, str);
}
if (LOWORD(wParam) == 2)
PostQuitMessage(0);
break;
case WM_CTLCOLORSTATIC:
// Set the colour of the text for our URL
if ((HWND)lparam == GetDlgItem(hwnd, 5))
{
// we're about to draw the static
// set the text colour in (HDC)lParam
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255, 0, 0));
return (BOOL)CreateSolidBrush(GetSysColor(COLOR_MENU));
}
break;
case VK_ESCAPE:
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd, message, wParam, lparam);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment