• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

E:/PROJECTS/cvsed/mixed/VIRTUA~1/vmxpatch/vmxpatch.cpp

Go to the documentation of this file.
00001 
00007 #include "stdafx.h"
00008 #include "../kdclient/patchapi.h"
00009 #include <conio.h>
00010 
00011 int _tmain(int argc, _TCHAR* argv[])
00012 {
00013         HANDLE hSnap = CreateVMSessionList();
00014         if (hSnap == INVALID_HANDLE_VALUE)
00015         {
00016                 printf("Unexpected error!\n");
00017                 return -1;
00018         }
00019 
00020         int PIDs[9] = {0,};
00021         int PIDCount = 0;
00022 
00023         do 
00024         {
00025                 PIDs[PIDCount++] = GetNextVMSessionPID(hSnap);
00026         } while (PIDs[PIDCount - 1] && (PIDCount < (sizeof(PIDs)/sizeof(PIDs[0]))));
00027                 
00028         if (PIDCount && !PIDs[PIDCount])
00029                 PIDCount--;
00030 
00031         CloseVMSessionList(hSnap);
00032 
00033         if (!PIDCount)
00034         {
00035                 printf("Cannot find vmware-vmx.exe running!\n");
00036                 return 1;
00037         }
00038 
00039         printf("Listing detected VM sessions:\n\n#\tPID\tName\n");
00040         for (int i = 0; i < PIDCount; i++)
00041         {
00042                 wchar_t tszName[128] = {0,};
00043                 GetVMSessionNameW(PIDs[i], tszName, sizeof(tszName)/sizeof(tszName[0]));
00044                 printf("%d\t%d\t%S\t%s\n", i + 1, PIDs[i], tszName, IsVMSessionPatched(PIDs[i]) ? "(already patched)" : "");
00045         }
00046         printf("------------------------------------\nWhich VM session to patch? (1-%d):", PIDCount);
00047         
00048         unsigned idx = _getche() - '1';
00049         printf("\n");
00050         if (idx >= (unsigned)PIDCount)
00051         {
00052                 printf ("Invalid index specified.\n");
00053                 return 2;
00054         }
00055 
00056         if (!PatchVMSessionIfNeeded(PIDs[idx]))
00057         {
00058                 printf ("Failed to patch VM session.\n");
00059                 return 3;
00060         }
00061 
00062         if (MessageBox(0, _T("The vmware-vmx.exe has been successfully patched. You can now use the debugger. Do you want to unpatch it back?"), _T("VM patcher"), MB_ICONQUESTION | MB_YESNO) != IDYES)
00063                 return 0;
00064 
00065         if (!UnpatchVMSessionIfNeeded(PIDs[idx]))
00066         {
00067                 printf ("Failed to unpatch VM session.\n");
00068                 return 3;
00069         }
00070 
00071         return 0;
00072 }
00073