Combreal

Crackme01

Feb 15th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <commctrl.h>
  3. #include "resource.h"
  4.  
  5. const char g_szClassName[] = "myWindowClass";
  6.  
  7. #define IDC_MAIN_EDIT   101
  8. #define IDC_BUTTON  1000
  9. #define IDC_STATUSBAR 1001
  10.  
  11. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  12. {
  13.     const char* password = "Djoby";
  14.     LPTSTR editText;
  15.     HWND hEdit;
  16.     HWND hText;
  17.     HWND hButton;
  18.     HWND hStatus;
  19.     HBRUSH g_hbrBackground = CreateSolidBrush(RGB(0xFF, 0xFF, 0xFF));
  20.     switch(msg)
  21.     {
  22.         case WM_CREATE:
  23.         {
  24.             hText = CreateWindowEx(0, "STATIC", "Entrez le mot de passe :",
  25.                 WS_CHILD | WS_VISIBLE,
  26.                 20, 0, 170, 20, hwnd, 0, GetModuleHandle(NULL) ,0);
  27.  
  28.             hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
  29.                 WS_CHILD | WS_VISIBLE | ES_MULTILINE,
  30.                 20, 25, 200, 20, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
  31.  
  32.             hButton = CreateWindowEx(0, "BUTTON", "OK",
  33.                 WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
  34.                 90, 50, 50, 20, hwnd, (HMENU)IDC_BUTTON, GetModuleHandle(NULL) ,0);
  35.  
  36.             hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
  37.                 WS_CHILD | WS_VISIBLE | WS_BORDER,
  38.                 0, 75, 260, 20,
  39.                 hwnd, (HMENU)IDC_STATUSBAR, GetModuleHandle(NULL), NULL);
  40.             if(hText == NULL)
  41.                 MessageBox(hwnd, "Could not create textControl.", "Error", MB_OK | MB_ICONERROR);
  42.             if(hEdit == NULL)
  43.                 MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
  44.             if(hButton == NULL)
  45.                 MessageBox(hwnd, "Could not create button.", "Error", MB_OK | MB_ICONERROR);
  46.             if(hStatus == NULL)
  47.                 MessageBox(hwnd, "Could not create statusBar.", "Error", MB_OK | MB_ICONERROR);
  48.         }
  49.         break;
  50.         case WM_COMMAND:
  51.             if(wParam == IDC_BUTTON)
  52.             {
  53.                 int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_MAIN_EDIT));
  54.                 if(len > 0)
  55.                 {
  56.                     char* buf;
  57.                     buf = (char*)GlobalAlloc(GPTR, len + 1);
  58.                     GetDlgItemText(hwnd, IDC_MAIN_EDIT, buf, len + 1);
  59.                     editText=buf;
  60.                     if(strcmp(buf, password) == 0)
  61.                     {  
  62.                         SetWindowText(GetDlgItem( hwnd, IDC_STATUSBAR ), "Mot de passe correct.");
  63.                     }
  64.                     else
  65.                     {
  66.                         SetWindowText(GetDlgItem( hwnd, IDC_STATUSBAR ), "Mot de passe incorrect.");
  67.                     }
  68.                     GlobalFree((HANDLE)buf);
  69.                 }
  70.             }
  71.         break;
  72.         case WM_CTLCOLORDLG:
  73.             return (LONG)g_hbrBackground;
  74.         case WM_CTLCOLORSTATIC:
  75.         {
  76.             HDC hdcStatic = (HDC)wParam;
  77.             SetTextColor(hdcStatic, RGB(0, 0, 0));
  78.             SetBkMode(hdcStatic, TRANSPARENT);
  79.             return (LONG)g_hbrBackground;
  80.         }
  81.         break;
  82.         case WM_CLOSE:
  83.             DestroyWindow(hwnd);
  84.         break;
  85.         case WM_DESTROY:
  86.             PostQuitMessage(0);
  87.         break;
  88.         default:
  89.             return DefWindowProc(hwnd, msg, wParam, lParam);
  90.     }
  91.     return 0;
  92. }
  93.  
  94. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  95.     LPSTR lpCmdLine, int nCmdShow)
  96. {
  97.     WNDCLASSEX wc;
  98.     HWND hwnd;
  99.     MSG Msg;
  100.  
  101.  
  102.     wc.cbSize        = sizeof(WNDCLASSEX);
  103.     wc.style         = 0;
  104.     wc.lpfnWndProc   = WndProc;
  105.     wc.cbClsExtra    = 0;
  106.     wc.cbWndExtra    = 0;
  107.     wc.hInstance     = hInstance;
  108.     wc.hIcon         = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  109.     wc.hCursor       = NULL;
  110.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  111.     wc.lpszMenuName  = NULL;
  112.     wc.lpszClassName = g_szClassName;
  113.     wc.hIconSm       = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
  114.  
  115.     if(!RegisterClassEx(&wc))
  116.     {
  117.         MessageBox(NULL, "Window Registration Failed!", "Error!",
  118.             MB_ICONEXCLAMATION | MB_OK);
  119.         return 0;
  120.     }
  121.  
  122.     hwnd = CreateWindowEx(
  123.         WS_EX_CLIENTEDGE,
  124.         g_szClassName,
  125.         "Crackme 01",
  126.         WS_OVERLAPPEDWINDOW,
  127.         CW_USEDEFAULT, CW_USEDEFAULT, 260, 150,
  128.         NULL, NULL, hInstance, NULL);
  129.  
  130.     if(hwnd == NULL)
  131.     {
  132.         MessageBox(NULL, "Window Creation Failed!", "Error!",
  133.             MB_ICONEXCLAMATION | MB_OK);
  134.         return 0;
  135.     }
  136.  
  137.     ShowWindow(hwnd, nCmdShow);
  138.     UpdateWindow(hwnd);
  139.  
  140.     while(GetMessage(&Msg, NULL, 0, 0) > 0)
  141.     {
  142.         TranslateMessage(&Msg);
  143.         DispatchMessage(&Msg);
  144.     }
  145.     return Msg.wParam;
  146. }
Add Comment
Please, Sign In to add comment