Author: hbelusca Date: Sat May 17 23:49:35 2014 New Revision: 63342
URL: http://svn.reactos.org/svn/reactos?rev=63342&view=rev Log: [NTVDM] Add a memory dump facility.
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/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] Sat May 17 23:49:35 2014 @@ -337,6 +337,87 @@
/* PUBLIC FUNCTIONS ***********************************************************/
+VOID DumpMemory(VOID) +{ + static ULONG DumpNumber = 0; + + HANDLE hFile; + WCHAR FileName[MAX_PATH]; + +#define LINE_SIZE 75 + 2 + ULONG i; + PBYTE Ptr1, Ptr2; + CHAR LineBuffer[LINE_SIZE]; + PCHAR Line; + SIZE_T LineSize; + + /* Build a suitable file name */ + _snwprintf(FileName, MAX_PATH, L"memdump%lu.txt", DumpNumber); + ++DumpNumber; + + /* Always create the dump file */ + hFile = CreateFileW(FileName, + GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + DPRINT1("Error when creating '%S' for memory dumping, GetLastError() = %u\n", + FileName, GetLastError()); + 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 += snprintf(Line, LINE_SIZE + LineBuffer - Line, "%c", + (*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); + } + + /* Close the file */ + CloseHandle(hFile); +} + DWORD WINAPI PumpConsoleInput(LPVOID Parameter);
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
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] Sat May 17 23:49:35 2014 @@ -98,6 +98,8 @@
/* FUNCTIONS ******************************************************************/
+VOID DumpMemory(VOID); + VOID WINAPI EmulatorReadMemory ( PFAST486_STATE State,
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] Sat May 17 23:49:35 2014 @@ -15,5 +15,6 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "&UkonÄit ReactOS VDM" + IDS_VDM_DUMPMEM, "Dump &Memory" + 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] Sat May 17 23:49:35 2014 @@ -9,5 +9,6 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "ReactOS VDM b&eenden" + IDS_VDM_DUMPMEM, "Dump &Memory" + 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] Sat May 17 23:49:35 2014 @@ -9,5 +9,6 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "&Quit the ReactOS VDM" + IDS_VDM_DUMPMEM, "Dump &Memory" + 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] Sat May 17 23:49:35 2014 @@ -9,5 +9,6 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "&Salir de ReactOS VDM" + IDS_VDM_DUMPMEM, "Dump &Memory" + 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] Sat May 17 23:49:35 2014 @@ -9,5 +9,6 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "&Quitter la ReactOS VDM" + IDS_VDM_DUMPMEM, "Vidage &Mémoire" + 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] Sat May 17 23:49:35 2014 @@ -9,5 +9,6 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "&Esci da ReactOS VDM" + IDS_VDM_DUMPMEM, "Dump &Memory" + 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] Sat May 17 23:49:35 2014 @@ -11,5 +11,6 @@
STRINGTABLE BEGIN - IDS_VDM_QUIT, "&Wyjdź z ReactOS VDM" + IDS_VDM_DUMPMEM, "Dump &Memory" + IDS_VDM_QUIT , "&Wyjdź z 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] Sat May 17 23:49:35 2014 @@ -51,7 +51,8 @@
static const VDM_MENUITEM VdmMenuItems[] = { - { IDS_VDM_QUIT, NULL, ID_VDM_QUIT }, + { IDS_VDM_DUMPMEM, NULL, ID_VDM_DUMPMEM }, + { IDS_VDM_QUIT , NULL, ID_VDM_QUIT },
{ 0, NULL, 0 } /* End of list */ }; @@ -368,6 +369,10 @@ ShowPointer = !ShowPointer; break;
+ case ID_VDM_DUMPMEM: + DumpMemory(); + break; + case ID_VDM_QUIT: /* Stop the VDM */ EmulatorTerminate();
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] Sat May 17 23:49:35 2014 @@ -1,14 +1,19 @@ #pragma once
+/* Menu IDs */ #define ID_SHOWHIDE_MOUSE 1000 -#define ID_VDM_QUIT 1001 +#define ID_VDM_DUMPMEM 1001 +#define ID_VDM_QUIT 1002
+/* String IDs */ #define IDS_HIDE_MOUSE 100 #define IDS_SHOW_MOUSE 101 #define IDS_VDM_MENU 102
-#define IDS_VDM_QUIT 200 +#define IDS_VDM_DUMPMEM 200 +#define IDS_VDM_QUIT 201
+/* Icon */ #define IDI_APPICON 1
/* EOF */