Author: hbelusca Date: Sun Sep 28 16:27:30 2014 New Revision: 64367
URL: http://svn.reactos.org/svn/reactos?rev=64367&view=rev Log: [NTVDM] - Add the possibility to dump the VM memory either in text or binary mode. - Initialize the VM memory to 0xFF to track potential memory misuses (diagnostics purposes). Things may crash, or not!
Modified: trunk/reactos/subsystems/ntvdm/emulator.c trunk/reactos/subsystems/ntvdm/emulator.h trunk/reactos/subsystems/ntvdm/lang/cs-CZ.rc trunk/reactos/subsystems/ntvdm/lang/de-DE.rc trunk/reactos/subsystems/ntvdm/lang/en-US.rc trunk/reactos/subsystems/ntvdm/lang/es-ES.rc trunk/reactos/subsystems/ntvdm/lang/fr-FR.rc trunk/reactos/subsystems/ntvdm/lang/it-IT.rc trunk/reactos/subsystems/ntvdm/lang/pl-PL.rc trunk/reactos/subsystems/ntvdm/lang/ro-RO.rc trunk/reactos/subsystems/ntvdm/lang/ru-RU.rc trunk/reactos/subsystems/ntvdm/ntvdm.c trunk/reactos/subsystems/ntvdm/resource.h
Modified: trunk/reactos/subsystems/ntvdm/emulator.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/emulator.c... ============================================================================== --- trunk/reactos/subsystems/ntvdm/emulator.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/emulator.c [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -430,13 +430,22 @@
/* PUBLIC FUNCTIONS ***********************************************************/
-VOID DumpMemory(VOID) -{ - static ULONG DumpNumber = 0; - - HANDLE hFile; - WCHAR FileName[MAX_PATH]; - +static VOID +DumpMemoryRaw(HANDLE hFile) +{ + PVOID Buffer; + SIZE_T Size; + + /* Dump the VM memory */ + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + Buffer = REAL_TO_PHYS(NULL); + Size = MAX_ADDRESS - (ULONG_PTR)(NULL); + WriteFile(hFile, Buffer, Size, &Size, NULL); +} + +static VOID +DumpMemoryTxt(HANDLE hFile) +{ #define LINE_SIZE 75 + 2 ULONG i; PBYTE Ptr1, Ptr2; @@ -444,8 +453,61 @@ PCHAR Line; SIZE_T LineSize;
+ /* Dump the VM memory */ + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + Ptr1 = Ptr2 = REAL_TO_PHYS(NULL); + while (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr1) > 0) + { + Ptr1 = Ptr2; + Line = LineBuffer; + + /* Print the address */ + Line += snprintf(Line, LINE_SIZE + LineBuffer - Line, "%08x ", PHYS_TO_REAL(Ptr1)); + + /* Print up to 16 bytes... */ + + /* ... in hexadecimal form first... */ + i = 0; + while (i++ <= 0x0F && (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr1) > 0)) + { + Line += snprintf(Line, LINE_SIZE + LineBuffer - Line, " %02x", *Ptr1); + ++Ptr1; + } + + /* ... align with spaces if needed... */ + RtlFillMemory(Line, 0x0F + 4 - i, ' '); + Line += 0x0F + 4 - i; + + /* ... then in character form. */ + i = 0; + while (i++ <= 0x0F && (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr2) > 0)) + { + *Line++ = ((*Ptr2 >= 0x20 && *Ptr2 <= 0x7E) || (*Ptr2 >= 0x80 && *Ptr2 < 0xFF) ? *Ptr2 : '.'); + ++Ptr2; + } + + /* Newline */ + *Line++ = '\r'; + *Line++ = '\n'; + + /* Finally write the line to the file */ + LineSize = Line - LineBuffer; + WriteFile(hFile, LineBuffer, LineSize, &LineSize, NULL); + } +} + +VOID DumpMemory(BOOLEAN TextFormat) +{ + static ULONG DumpNumber = 0; + + HANDLE hFile; + WCHAR FileName[MAX_PATH]; + /* Build a suitable file name */ - _snwprintf(FileName, MAX_PATH, L"memdump%lu.txt", DumpNumber); + _snwprintf(FileName, MAX_PATH, + L"memdump%lu.%s", + DumpNumber, + TextFormat ? L"txt" : L"dat"); ++DumpNumber;
DPRINT1("Creating memory dump file '%S'...\n", FileName); @@ -466,47 +528,11 @@ return; }
- /* Dump the VM memory */ - SetFilePointer(hFile, 0, NULL, FILE_BEGIN); - Ptr1 = Ptr2 = REAL_TO_PHYS(NULL); - while (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr1) > 0) - { - Ptr1 = Ptr2; - Line = LineBuffer; - - /* Print the address */ - Line += snprintf(Line, LINE_SIZE + LineBuffer - Line, "%08x ", PHYS_TO_REAL(Ptr1)); - - /* Print up to 16 bytes... */ - - /* ... in hexadecimal form first... */ - i = 0; - while (i++ <= 0x0F && (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr1) > 0)) - { - Line += snprintf(Line, LINE_SIZE + LineBuffer - Line, " %02x", *Ptr1); - ++Ptr1; - } - - /* ... align with spaces if needed... */ - RtlFillMemory(Line, 0x0F + 4 - i, ' '); - Line += 0x0F + 4 - i; - - /* ... then in character form. */ - i = 0; - while (i++ <= 0x0F && (MAX_ADDRESS - (ULONG_PTR)PHYS_TO_REAL(Ptr2) > 0)) - { - *Line++ = ((*Ptr2 >= 0x20 && *Ptr2 <= 0x7E) || (*Ptr2 >= 0x80 && *Ptr2 < 0xFF) ? *Ptr2 : '.'); - ++Ptr2; - } - - /* Newline */ - *Line++ = '\r'; - *Line++ = '\n'; - - /* Finally write the line to the file */ - LineSize = Line - LineBuffer; - WriteFile(hFile, LineBuffer, LineSize, &LineSize, NULL); - } + /* Dump the VM memory in the chosen format */ + if (TextFormat) + DumpMemoryTxt(hFile); + else + DumpMemoryRaw(hFile);
/* Close the file */ CloseHandle(hFile); @@ -517,12 +543,14 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput) { /* Allocate memory for the 16-bit address space */ - BaseAddress = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_ADDRESS); + BaseAddress = HeapAlloc(GetProcessHeap(), /*HEAP_ZERO_MEMORY*/ 0, MAX_ADDRESS); if (BaseAddress == NULL) { wprintf(L"FATAL: Failed to allocate VDM memory.\n"); return FALSE; } + // For diagnostics purposes!! + FillMemory(BaseAddress, MAX_ADDRESS, 0xFF);
/* Initialize I/O ports */ /* Initialize RAM */
Modified: trunk/reactos/subsystems/ntvdm/emulator.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/emulator.h... ============================================================================== --- trunk/reactos/subsystems/ntvdm/emulator.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/emulator.h [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -98,7 +98,7 @@
/* FUNCTIONS ******************************************************************/
-VOID DumpMemory(VOID); +VOID DumpMemory(BOOLEAN TextFormat);
VOID WINAPI EmulatorReadMemory (
Modified: trunk/reactos/subsystems/ntvdm/lang/cs-CZ.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/cs-CZ... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/cs-CZ.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/cs-CZ.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -15,6 +15,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Dump &Memory" - IDS_VDM_QUIT , "&UkonÄit ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "&UkonÄit ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/lang/de-DE.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/de-DE... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/de-DE.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/de-DE.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -9,6 +9,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Dump &Memory" - IDS_VDM_QUIT , "ReactOS VDM b&eenden" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "ReactOS VDM b&eenden" END
Modified: trunk/reactos/subsystems/ntvdm/lang/en-US.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/en-US... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/en-US.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/en-US.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -9,6 +9,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Dump &Memory" - IDS_VDM_QUIT , "&Quit the ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "&Quit the ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/lang/es-ES.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/es-ES... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/es-ES.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/es-ES.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -9,6 +9,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Dump &Memory" - IDS_VDM_QUIT , "&Salir de ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "&Salir de ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/lang/fr-FR.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/fr-FR... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/fr-FR.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/fr-FR.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -9,6 +9,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Vidage &Mémoire" - IDS_VDM_QUIT , "&Quitter la ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Vidage Mémoire (&Texte)" + IDS_VDM_DUMPMEM_BIN, "Vidage Mémoire (&Binaire)" + IDS_VDM_QUIT , "&Quitter la ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/lang/it-IT.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/it-IT... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/it-IT.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/it-IT.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -9,6 +9,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Dump &Memory" - IDS_VDM_QUIT , "&Esci da ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "&Esci da ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/lang/pl-PL.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/pl-PL... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/pl-PL.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/pl-PL.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -11,6 +11,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Zrzut &PamiÄci" - IDS_VDM_QUIT , "&Wyjdź z ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "&Wyjdź z ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/lang/ro-RO.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/ro-RO... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/ro-RO.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/ro-RO.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -9,5 +9,7 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "I&eÈire din ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "I&eÈire din ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/lang/ru-RU.rc URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/lang/ru-RU... ============================================================================== --- trunk/reactos/subsystems/ntvdm/lang/ru-RU.rc [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/lang/ru-RU.rc [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -9,6 +9,7 @@
STRINGTABLE BEGIN - IDS_VDM_DUMPMEM, "Ðамп &памÑÑи" - IDS_VDM_QUIT , "&ÐÑйÑи из ReactOS VDM" + IDS_VDM_DUMPMEM_TXT, "Dump Memory (&Text)" + IDS_VDM_DUMPMEM_BIN, "Dump Memory (&Binary)" + IDS_VDM_QUIT , "&ÐÑйÑи из ReactOS VDM" END
Modified: trunk/reactos/subsystems/ntvdm/ntvdm.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/ntvdm.c?re... ============================================================================== --- trunk/reactos/subsystems/ntvdm/ntvdm.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/ntvdm.c [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -51,8 +51,9 @@
static const VDM_MENUITEM VdmMenuItems[] = { - { IDS_VDM_DUMPMEM, NULL, ID_VDM_DUMPMEM }, - { IDS_VDM_QUIT , NULL, ID_VDM_QUIT }, + { IDS_VDM_DUMPMEM_TXT, NULL, ID_VDM_DUMPMEM_TXT }, + { IDS_VDM_DUMPMEM_BIN, NULL, ID_VDM_DUMPMEM_BIN }, + { IDS_VDM_QUIT , NULL, ID_VDM_QUIT },
{ 0, NULL, 0 } /* End of list */ }; @@ -337,8 +338,12 @@ ShowPointer = !ShowPointer; break;
- case ID_VDM_DUMPMEM: - DumpMemory(); + case ID_VDM_DUMPMEM_TXT: + DumpMemory(TRUE); + break; + + case ID_VDM_DUMPMEM_BIN: + DumpMemory(FALSE); break;
case ID_VDM_QUIT:
Modified: trunk/reactos/subsystems/ntvdm/resource.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/ntvdm/resource.h... ============================================================================== --- trunk/reactos/subsystems/ntvdm/resource.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/ntvdm/resource.h [iso-8859-1] Sun Sep 28 16:27:30 2014 @@ -2,16 +2,18 @@
/* Menu IDs */ #define ID_SHOWHIDE_MOUSE 1000 -#define ID_VDM_DUMPMEM 1001 -#define ID_VDM_QUIT 1002 +#define ID_VDM_DUMPMEM_TXT 1001 +#define ID_VDM_DUMPMEM_BIN 1002 +#define ID_VDM_QUIT 1003
/* String IDs */ #define IDS_HIDE_MOUSE 100 #define IDS_SHOW_MOUSE 101 #define IDS_VDM_MENU 102
-#define IDS_VDM_DUMPMEM 200 -#define IDS_VDM_QUIT 201 +#define IDS_VDM_DUMPMEM_TXT 200 +#define IDS_VDM_DUMPMEM_BIN 201 +#define IDS_VDM_QUIT 202
/* Icon */ #define IDI_APPICON 1