Puntoinfinito

Crackme with windows GUI

Aug 29th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.94 KB | None | 0 0
  1. //Preprocessor files
  2. #include <windows.h>
  3.  
  4. #define submitButton  101
  5. #define passwordEdit  102
  6.  
  7. //Define variables
  8. const char g_szClass[]   = "CrackMe!";
  9. const char g_szCaption[] = "CrackMe!";
  10. MSG Msg;
  11. HWND hWindow;
  12. WNDCLASSEX wcex;
  13.  
  14. HWND hSubmitButton;
  15. HWND hPasswordEdit;
  16.  
  17. char counter;
  18. char password[sizeof(g_szCaption)];
  19. char userPassword[] = "Thank you for trying out my CrackMe. This is just a taster of what a CrackMe is like. Please note that this is very, very simple to crack. :)";
  20.  
  21. //Error function
  22. DWORD WINAPI error() {
  23.      MessageBox(NULL, NULL, "Error", MB_ICONERROR | MB_OK);
  24.      PostQuitMessage(0);
  25. }
  26.  
  27. DWORD WINAPI encryptPassword() {
  28.       for(counter = false; counter < sizeof(g_szCaption); counter++)
  29.                  password[counter] = g_szCaption[counter];
  30. }
  31.                  
  32. DWORD WINAPI checkPassword() {
  33.       if(strcmp(password, userPassword) == false)
  34.                       MessageBox(NULL, "Congratulations! You cracked the password.", "CrackMe!", MB_ICONEXCLAMATION | MB_OK);
  35.      
  36.       else
  37.           MessageBox(NULL, "Sorry, the password you entered was incorrect.", "CrackMe!", MB_ICONEXCLAMATION | MB_OK);
  38. }
  39.      
  40.      
  41. //Message procedure
  42. long FAR PASCAL WindowProc(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  43.      switch(uMsg) {
  44.                   case WM_CREATE:
  45.                        hPasswordEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", false, WS_VISIBLE | WS_CHILD | WS_BORDER, 10, 10, 124, 27, hWindow, (HMENU)passwordEdit, false, NULL);
  46.                        hSubmitButton = CreateWindowEx(false, "Button", "Submit", WS_VISIBLE | WS_CHILD | WS_BORDER, 24, 45, 95, 25, hWindow, (HMENU)submitButton, false, NULL);
  47.                        break;
  48.                  
  49.                   case WM_COMMAND:
  50.                        switch(LOWORD(wParam)) {
  51.                                               if(!HIWORD(wParam)) {
  52.                                                                   case submitButton:
  53.                                                                        GetDlgItemText(hWindow, passwordEdit, userPassword, 100);
  54.                                                                        checkPassword();
  55.                                               }
  56.                        }
  57.                        break;
  58.                          
  59.                   case WM_DESTROY:
  60.                        PostQuitMessage(false);
  61.                        break;
  62.                   }
  63.                  
  64.      return DefWindowProc(hWindow, uMsg, wParam, lParam);
  65. }
  66.  
  67. //WinMain
  68. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, PSTR szCmdLine, int nCmdShow) {
  69.     encryptPassword();
  70.    
  71.     //Create the window class & register it
  72.     wcex.cbSize         = sizeof(wcex);
  73.     wcex.style          = CS_CLASSDC;
  74.     wcex.lpfnWndProc    = WindowProc;
  75.     wcex.cbClsExtra     = 0;
  76.     wcex.cbWndExtra     = 0;
  77.     wcex.hInstance      = hInst;
  78.     wcex.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  79.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  80.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 0);
  81.     wcex.lpszMenuName   = NULL;
  82.     wcex.lpszClassName  = g_szClass;
  83.     wcex.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
  84.    
  85.     if(!RegisterClassEx(&wcex))
  86.       error();
  87.  
  88.     //Create window
  89.     hWindow = CreateWindow(g_szClass, g_szCaption, WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 150, 100, NULL, NULL, hInst, NULL);
  90.    
  91.     //Show and update the window
  92.     ShowWindow(hWindow, SW_NORMAL);
  93.     UpdateWindow(hWindow);
  94.  
  95.     //Enter the message pump
  96.     ZeroMemory(&Msg, sizeof(MSG));
  97.     while(Msg.message != WM_QUIT) {
  98.                       //Handle windows messages (if any)
  99.                       if(PeekMessage(&Msg, NULL, false, false, PM_REMOVE)) {
  100.                                            TranslateMessage(&Msg);
  101.                                            DispatchMessage(&Msg);
  102.                       }
  103.     }
  104.    
  105.     return false;
  106. }
Add Comment
Please, Sign In to add comment