]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Make injection plugin available in WIMBOOT mode. (#1834)
authorlongpanda <admin@ventoy.net>
Tue, 13 Sep 2022 13:32:35 +0000 (21:32 +0800)
committerlongpanda <admin@ventoy.net>
Tue, 13 Sep 2022 13:32:35 +0000 (21:32 +0800)
INSTALL/ventoy/vtoyjump32.exe
INSTALL/ventoy/vtoyjump64.exe
vtoyjump/vtoyjump/vtoyjump.c
vtoyjump/vtoyjump/vtoyjump.h

index 91e7c2040085625c02a521416297d363ef32b78b..23bb57519b13b2b4ad51f5a2e0fb096e2c817144 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump32.exe and b/INSTALL/ventoy/vtoyjump32.exe differ
index 3d381fe59315597720b4041ed49f1b395c7f15df..28c623df826bfa60a4b285fe0965711eaaaba25f 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump64.exe and b/INSTALL/ventoy/vtoyjump64.exe differ
index 8cc54c84cdef4a3542d72c439044c0ed9e967c86..613e8d06184e99135f2b32d001e2fe2bcf9a5d5d 100644 (file)
@@ -36,6 +36,7 @@ static ventoy_guid g_ventoy_guid = VENTOY_GUID;
 static HANDLE g_vtoylog_mutex = NULL;\r
 static HANDLE g_vtoyins_mutex = NULL;\r
 \r
+static INT g_winpeshl_ini_updated = 0;\r
 static DWORD g_vtoy_disk_drive;\r
 \r
 static CHAR g_prog_full_path[MAX_PATH];\r
@@ -51,6 +52,8 @@ static CHAR g_prog_name[MAX_PATH];
 \r
 #define VTOY_AUTO_FILE   "X:\\_vtoy_auto_install"\r
 \r
+#define WINPESHL_INI    "X:\\Windows\\system32\\winpeshl.ini"\r
+\r
 #define LOG_FILE  "X:\\Windows\\system32\\ventoy.log"\r
 #define MUTEX_LOCK(hmutex)  if (hmutex != NULL) LockStatus = WaitForSingleObject(hmutex, INFINITE)\r
 #define MUTEX_UNLOCK(hmutex)  if (hmutex != NULL && WAIT_OBJECT_0 == LockStatus) ReleaseMutex(hmutex)\r
@@ -1962,6 +1965,31 @@ static BOOL CheckVentoyDisk(DWORD DiskNum)
     return FALSE;\r
 }\r
 \r
+static int GetWinpeshlIniFileAttr(WinpeshlIniAttr *pAttr)\r
+{\r
+    HANDLE hFile;\r
+    SYSTEMTIME systime;\r
+\r
+    hFile = CreateFileA(WINPESHL_INI, FILE_READ_EA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);\r
+    if (hFile == INVALID_HANDLE_VALUE)\r
+    {\r
+        Log("Could not open the file<%s>, error:%u", WINPESHL_INI, GetLastError());\r
+        return 1;\r
+    }\r
+\r
+    pAttr->FileSize = (INT)GetFileSize(hFile, NULL);\r
+    GetFileTime(hFile, &pAttr->CreateTime, &pAttr->LastAccessTime, &pAttr->LastWriteTime);\r
+\r
+    FileTimeToSystemTime(&pAttr->LastWriteTime, &systime);\r
+    Log("Winpeshl.ini size:%d LastWriteTime:<%04u/%02u/%02u %02u:%02u:%02u.%03u>", \r
+        pAttr->FileSize,\r
+        systime.wYear, systime.wMonth, systime.wDay, \r
+        systime.wHour, systime.wMinute, systime.wSecond, \r
+        systime.wMilliseconds);\r
+\r
+    CloseHandle(hFile);\r
+    return 0;\r
+}\r
 \r
 static int VentoyHook(ventoy_os_param *param)\r
 {\r
@@ -1984,6 +2012,8 @@ static int VentoyHook(ventoy_os_param *param)
 \r
        Log("VentoyHook Path:<%s>", param->vtoy_img_path);\r
 \r
+    g_winpeshl_ini_updated = 0;\r
+\r
     if (IsUTF8Encode(param->vtoy_img_path))\r
     {\r
         Log("This file is UTF8 encoding");\r
@@ -2180,9 +2210,35 @@ static int VentoyHook(ventoy_os_param *param)
         sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", VtoyLetter, g_windows_data.injection_archive);\r
         if (IsFileExist("%s", IsoPath))\r
         {\r
+            int rc1 = -1, rc2 = -1;\r
+            WinpeshlIniAttr Attr1, Attr2;\r
+            memset(&Attr1, 0, sizeof(Attr1));\r
+            memset(&Attr2, 0, sizeof(Attr2));\r
+\r
             Log("decompress injection archive %s...", IsoPath);\r
+\r
+            if (IsFileExist(WINPESHL_INI))\r
+            {\r
+                rc1 = GetWinpeshlIniFileAttr(&Attr1);\r
+            }\r
+\r
             DecompressInjectionArchive(IsoPath, VtoyDiskNum);\r
 \r
+            if (IsFileExist(WINPESHL_INI))\r
+            {\r
+                rc2 = GetWinpeshlIniFileAttr(&Attr2);\r
+                if (rc1 == rc2 && rc1 == 0)\r
+                {\r
+                    if (Attr1.FileSize != Attr2.FileSize ||\r
+                        Attr1.LastWriteTime.dwHighDateTime != Attr2.LastWriteTime.dwHighDateTime ||\r
+                        Attr1.LastWriteTime.dwLowDateTime != Attr2.LastWriteTime.dwLowDateTime)\r
+                    {\r
+                        Log("winpeshl.ini file updated");\r
+                        g_winpeshl_ini_updated = 1;\r
+                    }\r
+                }\r
+            }\r
+\r
             if (IsFileExist("%s", AUTO_RUN_BAT))\r
             {\r
                 HANDLE hOut;\r
@@ -2441,6 +2497,7 @@ int real_main(int argc, char **argv)
 {\r
        int i = 0;\r
        int rc = 0;\r
+    int wimboot = 0;\r
        CHAR NewFile[MAX_PATH];\r
        CHAR LunchFile[MAX_PATH];\r
        CHAR CallParam[1024] = { 0 };\r
@@ -2468,6 +2525,7 @@ int real_main(int argc, char **argv)
 \r
        if (strstr(argv[0], "vtoyjump.exe"))\r
        {\r
+        wimboot = 1;\r
                rc = VentoyJumpWimboot(argc, argv, LunchFile);\r
        }\r
        else\r
@@ -2490,6 +2548,11 @@ int real_main(int argc, char **argv)
                sprintf_s(LunchFile, sizeof(LunchFile), "%s", g_prog_full_path);\r
                Log("Final lunchFile is <%s>", LunchFile);\r
        }\r
+    else if (wimboot && g_winpeshl_ini_updated)\r
+    {\r
+        sprintf_s(LunchFile, MAX_PATH, "X:\\Windows\\system32\\winpeshl.exe");\r
+        Log("Recall winpeshl.exe");\r
+    }\r
     else\r
     {\r
         Log("We don't need to recover original <%s>", g_prog_name);\r
index d45998552096abfa49d7bc7053b6753f074df825..f4abb264b94ed6043e5a5bf1818048659698aab3 100644 (file)
@@ -152,6 +152,14 @@ typedef struct VTOY_GPT_INFO
 #pragma pack()
 \r
 \r
+typedef struct WinpeshlIniAttr\r
+{\r
+    INT FileSize;\r
+    FILETIME CreateTime;\r
+    FILETIME LastAccessTime;\r
+    FILETIME LastWriteTime;\r
+}WinpeshlIniAttr;\r
+\r
 \r
 typedef struct VarDiskInfo\r
 {\r
@@ -187,4 +195,5 @@ int unxz(unsigned char *in, int in_size,
     unsigned char *out, int *in_used,\r
     void(*error)(char *x));\r
 \r
+\r
 #endif\r