home *** CD-ROM | disk | FTP | other *** search
/ The Elite Hackers Toolkit / TheEliteHackersToolkitVolume1_1998.rar / HACKERS.BIN / appcraks / WD95_V21.ZIP / WDUMP95.CPP < prev    next >
C/C++ Source or Header  |  1998-02-04  |  13KB  |  468 lines

  1. /*------------------------------------------------------------
  2. WDump95.CPP -- Memory Dumper for Windows '95
  3. made in 1998 by The Key "...when cracking is not enough..."
  4. Based on source code of Quine's Softdump.
  5. ------------------------------------------------------------*/
  6.  
  7. #include <windows.h>
  8. #include "resource.h"
  9. #include "ezfont.h"
  10.  
  11. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  12. BOOL    CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
  13. BOOL    CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM);
  14. BOOL    GenerateAddress(HWND);
  15. BOOL    Dump(HWND);
  16. BOOL    NewFile(HWND);
  17.  
  18. HINSTANCE hInstance;
  19. HWND    hwnd; //handle of main window
  20.  
  21. static char szAppName[] = "WDump95" ;
  22. char    szCompletePath[500];
  23. char    szFilename[500];
  24. char    szSize[100];
  25. char    szTempString[1000];
  26. BOOL    bSizeConversion;
  27. DWORD    dwFilenameLen=0;
  28. HFONT    hAddressFont;
  29. HDC        hAddressDC;
  30.  
  31. HANDLE    hFileMap=0;
  32. HANDLE    hFile=0;
  33. LPVOID    pMappedFile=0;
  34. DWORD    dwSize=0;
  35. DWORD*    lpdwResult=0;
  36.  
  37. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  38.                     PSTR szCmdLine, int iCmdShow)
  39. {
  40.     MSG         msg ;
  41.     WNDCLASSEX  wndclass ;
  42.  
  43.     wndclass.cbSize        = sizeof (wndclass) ;
  44.     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  45.     wndclass.lpfnWndProc   = WndProc ;
  46.     wndclass.cbClsExtra    = 0 ;
  47.     wndclass.cbWndExtra    = 0 ;
  48.     wndclass.hInstance     = hInstance ;
  49.     wndclass.hIcon         = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_MAINICON)) ;
  50.     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  51.     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  52.     wndclass.lpszMenuName  = NULL ;
  53.     wndclass.lpszClassName = szAppName ;
  54.     wndclass.hIconSm       = NULL ;    //put the small icon of .hIcon member
  55.  
  56.     RegisterClassEx (&wndclass) ;
  57.  
  58.     hwnd = CreateWindow (szAppName,         // window class name
  59.         "WDump95",                 // window caption
  60.         WS_OVERLAPPEDWINDOW,     // window style
  61.         CW_USEDEFAULT,           // initial x position
  62.         CW_USEDEFAULT,           // initial y position
  63.         CW_USEDEFAULT,           // initial x size
  64.         CW_USEDEFAULT,           // initial y size
  65.         NULL,                    // parent window handle
  66.         NULL,                    // window menu handle
  67.         hInstance,               // program instance handle
  68.         NULL) ;                     // creation parameters
  69.  
  70.     ShowWindow (hwnd, SW_MINIMIZE) ;
  71.     UpdateWindow (hwnd) ;
  72.  
  73.     while (GetMessage (&msg, NULL, 0, 0))
  74.     {
  75.         TranslateMessage (&msg) ;
  76.         DispatchMessage (&msg) ;
  77.     }
  78.     return msg.wParam ;
  79. }
  80.  
  81. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  82. {
  83.     DWORD    i;
  84.     DWORD    dwPathLen;
  85.  
  86.     switch (iMsg)
  87.     {
  88.     case WM_CREATE :
  89.         hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
  90.  
  91.         // Prepare path
  92.         dwPathLen = GetModuleFileName( GetModuleHandle(NULL), szCompletePath, 500);
  93.         for ( i=dwPathLen ; (i>0) && (szCompletePath[i] != '\\') ; i-- );
  94.         szCompletePath[i]=0x0;
  95.  
  96.         PostMessage(hwnd, WM_COMMAND, 0x77777777,0);
  97.         return 0 ;
  98.  
  99.     case WM_COMMAND :
  100.         if (wParam == 0x77777777)
  101.         {
  102.             DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), hwnd, (DLGPROC) DialogProc);
  103.             DestroyWindow(hwnd);
  104.         }
  105.         return 0 ;
  106.  
  107.     case WM_DESTROY :
  108.         PostQuitMessage (0) ;
  109.         return 0 ;
  110.  
  111.     }
  112.  
  113.     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  114. }
  115.  
  116. BOOL CALLBACK DialogProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  117. {
  118.  
  119.     switch (iMsg)
  120.     {
  121.  
  122.     case WM_INITDIALOG:
  123.         SetClassLong (hDlg, GCL_HICON, (long) LoadIcon (hInstance, MAKEINTRESOURCE(IDI_MAINICON)));
  124.         EnableWindow(GetDlgItem(hDlg, IDC_DUMP), FALSE);
  125.         hAddressDC = GetDC(GetDlgItem(hDlg, IDC_ADDRESS));
  126.         hAddressFont = EzCreateFont (hAddressDC, "MS Sans Serif", 180, 0, 0, TRUE);
  127.         SelectObject (hAddressDC, hAddressFont);
  128.         SendMessage(GetDlgItem(hDlg, IDC_ADDRESS), WM_SETFONT, (WPARAM) hAddressFont, MAKELPARAM(TRUE, 0));
  129.         return FALSE ;
  130.         break;
  131.  
  132.     case WM_COMMAND :
  133.         switch (LOWORD (wParam))
  134.         {
  135.  
  136.         case IDCANCEL :
  137. #ifndef _DEBUG
  138.             if ( MessageBox(hDlg, "Are you sure you want to quit WDump95?",szAppName,
  139.                 MB_YESNO | MB_ICONQUESTION ) == IDNO ) return 0;
  140. #endif
  141.             
  142.             // If file was not dumped assume user don't need it and therefore delete it.
  143.  
  144.             if ( IsWindowEnabled(GetDlgItem(hDlg, IDC_DUMP)) )
  145.             {
  146.                 UnmapViewOfFile (pMappedFile);
  147.                 CloseHandle (hFileMap);
  148.                 CloseHandle (hFile);
  149.                 DeleteFile (szFilename);
  150.             }
  151.             EndDialog (hDlg, 0) ;
  152.             return TRUE ;
  153.             break;
  154.  
  155.         case IDC_GENERATE :
  156.             GenerateAddress(hDlg);
  157.             return TRUE ;
  158.             break;
  159.  
  160.         case IDC_DUMP :
  161.             Dump(hDlg);
  162.             return TRUE ;
  163.             break;
  164.  
  165.         case IDC_NEW :
  166.             NewFile(hDlg);
  167.             return TRUE ;
  168.             break;
  169.  
  170.         case IDC_ABOUT :
  171.             DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUT), hDlg, (DLGPROC) AboutProc);
  172.             return TRUE ;
  173.             break;
  174.  
  175.         };
  176.  
  177.     case WM_DESTROY:
  178.         DeleteObject(hAddressFont);
  179.         return FALSE ;
  180.         break;
  181.  
  182.     }
  183.         return FALSE ;
  184. }
  185.  
  186. BOOL    GenerateAddress(HWND hDlg)
  187. {
  188.  
  189.     BYTE*    i;
  190.     WIN32_FIND_DATA    wfd;
  191.  
  192.     // Change cursor (pointer) to "wait" state
  193.  
  194.     SetCursor( LoadCursor(hInstance,MAKEINTRESOURCE(IDC_WAITCUR)) );
  195.     
  196.     // Check if already exist and ask for overwrite authorization
  197.  
  198.     dwFilenameLen = GetDlgItemText(hDlg, IDC_FILENAME, szFilename, 500);
  199.     if ( (FindFirstFile(szFilename, &wfd))!=INVALID_HANDLE_VALUE )
  200.     {
  201.             if ( MessageBox(hDlg,
  202.             "File already exist.\nDo you want to overwrite it ?",
  203.             szAppName,
  204.             MB_YESNO | MB_ICONEXCLAMATION ) == IDNO )
  205.             {
  206.                 return FALSE;
  207.             }
  208.     }
  209.  
  210.     // Get and check file size
  211.  
  212.     dwSize = GetDlgItemInt(hDlg, IDC_SIZEFILE, &bSizeConversion, FALSE);
  213.     dwSize = dwSize * (1024) ;
  214.     if ( (dwSize<1) || (dwSize>((1024*1024)*1024) || (bSizeConversion==FALSE) ))
  215.     {
  216.         MessageBox(hDlg,
  217.             "Wrong file size.\nPlease enter a correct value.\nBetween 1 Kb and 1 Gb.",
  218.             szAppName,
  219.             MB_OK | MB_ICONERROR );
  220.         return FALSE;
  221.     }
  222.  
  223.     // Get and check filename
  224.  
  225.     dwFilenameLen = GetDlgItemText(hDlg, IDC_FILENAME, szFilename, 500);
  226.  
  227.     if ( dwFilenameLen<1 )
  228.     {
  229.         MessageBox(hDlg,
  230.             "Wrong filename.\nPlease enter a correct name.",
  231.             szAppName,
  232.             MB_OK | MB_ICONERROR );
  233.         return FALSE;
  234.     }
  235.  
  236.     // Create and check MemoryMapped file
  237.  
  238.     hFile = CreateFile ( (LPCTSTR) szFilename, GENERIC_READ | GENERIC_WRITE,
  239.         FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0);
  240.  
  241.     if (!hFile)
  242.     {
  243.         MessageBox(hDlg,
  244.             "Error while opening file.\nPlease check input data and retry.\n",
  245.             szAppName,
  246.             MB_OK | MB_ICONERROR );
  247.         return FALSE;
  248.     }
  249.  
  250.     hFileMap = CreateFileMapping ( hFile, NULL, PAGE_READWRITE | SEC_COMMIT, 0, dwSize, NULL);
  251.  
  252.     if (!hFileMap)
  253.     {
  254.         wsprintf(szTempString, "Unable to create file mapping.\nError Code: %d.\n", GetLastError());
  255.         MessageBox(hDlg,
  256.             szTempString,
  257.             szAppName,
  258.             MB_OK | MB_ICONERROR );
  259.         CloseHandle (hFile);
  260.         return FALSE;
  261.     }
  262.  
  263.     pMappedFile = MapViewOfFile ( hFileMap, FILE_MAP_WRITE, 0, 0, 0);
  264.  
  265.     if (!pMappedFile)
  266.     {
  267.         wsprintf(szTempString, "MapViewOfFile failed.\nError code: %d.", GetLastError());
  268.         MessageBox(hDlg,
  269.             szTempString,
  270.             szAppName,
  271.             MB_OK | MB_ICONERROR );
  272.         CloseHandle (hFileMap);
  273.         CloseHandle (hFile);
  274.         return FALSE;
  275.     }
  276.  
  277.     // Force the pages into memory, and stick in identifier
  278.  
  279.     i = (BYTE*)pMappedFile;
  280.     for ( ; i<(BYTE*)((DWORD)pMappedFile+dwSize); i++) *i = 0xCC;
  281.     strcpy((char*)pMappedFile, "WDump95 by The Key");
  282.  
  283.     // Write it to the disk
  284.  
  285.     FlushViewOfFile(pMappedFile,0);
  286.  
  287.     // Show Address
  288.  
  289.     wsprintf(szTempString, "0x%X\0", (DWORD)pMappedFile);
  290.     SetDlgItemText(hDlg, IDC_ADDRESS, szTempString);
  291.  
  292.     // Disable "Generate Address" button
  293.  
  294.     EnableWindow(GetDlgItem(hDlg, IDC_GENERATE), FALSE);
  295.  
  296.     // Enable "Dump" button
  297.  
  298.     EnableWindow(GetDlgItem(hDlg, IDC_DUMP), TRUE);
  299.  
  300.     // Show filename and filesize in main window caption
  301.  
  302.     wsprintf(szTempString, "%s - %ld KB", szFilename, dwSize/1024);
  303.     SetWindowText(hwnd, szTempString);
  304.  
  305.     // Change cursor (pointer) to normal state
  306.  
  307.     SetCursor( LoadCursor(NULL, IDC_ARROW));
  308.  
  309.     return TRUE;
  310. }
  311.  
  312. BOOL    Dump(HWND hDlg)
  313. {
  314.  
  315.     if ( !FlushViewOfFile(pMappedFile,0) )
  316.     {
  317.         MessageBox(hDlg,
  318.             "FlushViewOfFile failed.\nCheck to make sure file is ok.\n",
  319.             szAppName,
  320.             MB_OK | MB_ICONERROR );
  321.         UnmapViewOfFile ( pMappedFile);
  322.         CloseHandle ( hFileMap );
  323.         CloseHandle ( hFile );
  324.         return FALSE;
  325.     }
  326.  
  327.     UnmapViewOfFile ( pMappedFile);
  328.     CloseHandle ( hFileMap );
  329.     CloseHandle ( hFile );
  330.     MessageBox(hDlg,
  331.         "Memory dumped successfully.\nThank you for using WDump95.",
  332.         szAppName,
  333.         MB_OK | MB_ICONINFORMATION );
  334.  
  335.     // Enable "Generate Address" button
  336.  
  337.     EnableWindow(GetDlgItem(hDlg, IDC_GENERATE), TRUE);
  338.  
  339.     // Disable "Dump" button
  340.  
  341.     EnableWindow(GetDlgItem(hDlg, IDC_DUMP), FALSE);
  342.  
  343.     // Clear Address viewer
  344.  
  345.     SetWindowText(GetDlgItem(hDlg, IDC_ADDRESS), "N/A\0");
  346.  
  347.     return TRUE;
  348. }
  349.  
  350. BOOL    NewFile(HWND hDlg)
  351. {
  352.     UnmapViewOfFile (pMappedFile);
  353.     CloseHandle (hFileMap);
  354.     CloseHandle (hFile);
  355.     if ( IsWindowEnabled(GetDlgItem(hDlg, IDC_DUMP)) )
  356.     {
  357.         DeleteFile (szFilename);
  358.     }
  359.     EnableWindow(GetDlgItem(hDlg, IDC_GENERATE), TRUE);
  360.     EnableWindow(GetDlgItem(hDlg, IDC_DUMP), FALSE);
  361.     SetWindowText(hwnd, "WDump95");
  362.     SetWindowText(GetDlgItem(hDlg, IDC_ADDRESS), "N/A\0");
  363.     return TRUE;
  364. }
  365.  
  366. BOOL    CALLBACK AboutProc    (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  367. {
  368.  
  369.     static    HWND hName;
  370.     static    HWND hAboutText;
  371.     static    HFONT hFontName;
  372.     static    HDC hDCName;
  373.     static char szAboutText[] = "\r\n"
  374.                                 "WDump95 v2.10 by THE KEY - \"when cracking is not enough\""
  375.                                 "\r\n"
  376.                                 "\r\n"
  377.                                 "WDump95 is a \"memory dumper\", that "
  378.                                 "is a cracking tool to save chunks of memory "
  379.                                 "to a disk file. It creates a memory mapped file, "
  380.                                 "that is a memory space shared between all processes, "
  381.                                 "so you can copy data in and then save those on "
  382.                                 "the disk for further analysis/processing. "
  383.                                 "File name and file size can be set as you "
  384.                                 "like. File size can be between 1 Kb and 1 Gb. "
  385.                                 "\r\n"
  386.                                 "\r\n"
  387.                                 "To use this memory dumper simply type a filename, if "
  388.                                 "you want you can include a path, and then type the file "
  389.                                 "size in kilobytes. Then press the \"Generate Address\" "
  390.                                 "button that will create the memory buffer and "
  391.                                 "will display the address you can use inside your "
  392.                                 "debugger. After you did your work in the debugger "
  393.                                 "you save the buffer to the file through the "
  394.                                 "\"Dump\" button. If you are not satisfied with the "
  395.                                 "current filename or file size press \"New\" button "
  396.                                 "and enter the new values. "
  397.                                 "\r\n"
  398.                                 "\r\n"
  399.                                 "This useful tool was developed by THE KEY. "
  400.                                 "It is based on source code of Quine's Softdump. "
  401.                                 "The development of this tool would not be possible "
  402.                                 "without the help of Quine's source code. "
  403.                                 "For this reason THE KEY "
  404.                                 "decided to release the source code of WDump95 letting, "
  405.                                 "in this way, other crackers/programmers enhance this "
  406.                                 "program and release it to the public again. All this "
  407.                                 "to encourage the cracking world to create free, "
  408.                                 "powerful, cracking tools. "
  409.                                 "\r\n"
  410.                                 "\r\n"
  411.                                 "\r\n"
  412.                                 "\r\n"
  413.                                 "\r\n"
  414.                                 "\t\t        THE KEY "
  415.                                 "\r\n"
  416.                                 "\t      ...when cracking is not enough..."
  417.                                 "\r\n"
  418.                                 "\r\n"
  419.                                 "\r\n"
  420.                                 "\r\n"
  421.                                 " \0 ";
  422.  
  423.     static char szGreet[] =        "\r\n"
  424.                                 "\r\n"
  425.                                 "\r\n"
  426.                                 "\r\n"
  427.                                 "\t\t        THE KEY "
  428.                                 "\r\n"
  429.                                 "\t      ...when cracking is not enough..."
  430.                                 "\r\n"
  431.                                 "\r\n"
  432.                                 "\r\n"
  433.                                 "\r\n"
  434.                                 " \0 ";
  435.     switch (iMsg)
  436.     {
  437.  
  438.     case WM_INITDIALOG:
  439.         hAboutText = GetDlgItem(hDlg, IDC_ABOUTTEXT);
  440.         hName = GetDlgItem(hDlg, IDC_ABOUTNAME);
  441.         hDCName = GetDC(hName);
  442.         hFontName = EzCreateFont (hDCName, "MS Sans Serif", 240, 0, EZ_ATTR_BOLD, TRUE);
  443.         SelectObject (hDCName, hFontName);
  444.         SendMessage(hName, WM_SETFONT, (WPARAM) hFontName, MAKELPARAM(TRUE, 0));
  445.  
  446.         SetWindowText(hAboutText, szAboutText);
  447.  
  448.         return FALSE ;
  449.  
  450.     case WM_COMMAND :
  451.         switch (LOWORD (wParam))
  452.         {
  453.         case IDOK :
  454.         case IDCANCEL :
  455.             SetWindowText(hAboutText, szGreet);
  456.             UpdateWindow(hAboutText);
  457.             Sleep(4000);            
  458.             EndDialog(hDlg,0);
  459.             break;
  460.         }
  461.  
  462.         case WM_DESTROY:
  463.             DeleteObject(hFontName);
  464.             return FALSE ;
  465.  
  466.     }
  467.     return FALSE ;
  468. }