[NTVDM] In non-STANDALONE builds, check whether we are started as a VDM and bail...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 27 Nov 2021 00:06:21 +0000 (01:06 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 27 Nov 2021 23:26:43 +0000 (00:26 +0100)
subsystems/mvdm/ntvdm/ntvdm.c

index d7e88cb..bedc20e 100644 (file)
@@ -20,6 +20,9 @@
 
 #include "dos/dem.h"
 
+/* Extra PSDK/NDK Headers */
+#include <ndk/psfuncs.h>
+
 /* VARIABLES ******************************************************************/
 
 NTVDM_SETTINGS GlobalSettings;
@@ -473,9 +476,6 @@ PrintMessageAnsi(IN CHAR_PRINT CharPrint,
 INT
 wmain(INT argc, WCHAR *argv[])
 {
-    NtVdmArgc = argc;
-    NtVdmArgv = argv;
-
 #ifdef STANDALONE
 
     if (argc < 2)
@@ -485,8 +485,27 @@ wmain(INT argc, WCHAR *argv[])
         return 0;
     }
 
+#else
+
+    /* For non-STANDALONE builds, we must be started as a VDM */
+    NTSTATUS Status;
+    ULONG VdmPower = 0;
+    Status = NtQueryInformationProcess(NtCurrentProcess(),
+                                       ProcessWx86Information,
+                                       &VdmPower,
+                                       sizeof(VdmPower),
+                                       NULL);
+    if (!NT_SUCCESS(Status) || (VdmPower == 0))
+    {
+        /* Not a VDM, bail out */
+        return 0;
+    }
+
 #endif
 
+    NtVdmArgc = argc;
+    NtVdmArgv = argv;
+
 #ifdef ADVANCED_DEBUGGING
     {
     INT i = 20;