]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Compatibility improvement for some WinPE
authorlongpanda <admin@ventoy.net>
Mon, 2 Aug 2021 13:03:43 +0000 (21:03 +0800)
committerlongpanda <admin@ventoy.net>
Mon, 2 Aug 2021 13:03:43 +0000 (21:03 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
INSTALL/VentoyWeb.sh
INSTALL/ventoy/vtoyjump32.exe
INSTALL/ventoy/vtoyjump64.exe
vtoyjump/vtoyjump/vtoyjump.c

index b524011425f8e538a03e868bcc5201a8701b3149..f841aba6644c5d21acf579cd49ffca6efd624e66 100644 (file)
@@ -69,6 +69,9 @@
 #define VTOY_ARCH_CPIO  "ventoy_x86.cpio"
 #endif
 
 #define VTOY_ARCH_CPIO  "ventoy_x86.cpio"
 #endif
 
+#define ventoy_varg_4(arg) arg[0], arg[1], arg[2], arg[3]
+#define ventoy_varg_8(arg) arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7]
+
 #define VTOY_PWD_CORRUPTED(err) \
 {\
     grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
 #define VTOY_PWD_CORRUPTED(err) \
 {\
     grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
index 3bcadc4d95672ad07f7e035090fae7d085b86ee9..9f7615cea5f8c48f47672de236a774da2c1a645a 100644 (file)
@@ -660,30 +660,22 @@ static wim_directory_entry * search_full_wim_dirent
 
 static wim_directory_entry * search_replace_wim_dirent(void *meta_data, wim_directory_entry *dir)
 {
 
 static wim_directory_entry * search_replace_wim_dirent(void *meta_data, wim_directory_entry *dir)
 {
-    wim_directory_entry *wim_dirent1 = NULL;
-    wim_directory_entry *wim_dirent2 = NULL;
+    wim_directory_entry *wim_dirent = NULL;
     const char *pecmd_path[] = { "Windows", "System32", "pecmd.exe", NULL };
     const char *pecmd_path[] = { "Windows", "System32", "pecmd.exe", NULL };
-    const char *wpeinit_path[] = { "Windows", "System32", "wpeinit.exe", NULL };
     const char *winpeshl_path[] = { "Windows", "System32", "winpeshl.exe", NULL };
 
     const char *winpeshl_path[] = { "Windows", "System32", "winpeshl.exe", NULL };
 
-    wim_dirent1 = search_full_wim_dirent(meta_data, dir, pecmd_path);
-    debug("search pecmd.exe %p\n", wim_dirent1);
-    if (wim_dirent1)
+    wim_dirent = search_full_wim_dirent(meta_data, dir, pecmd_path);
+    debug("search pecmd.exe %p\n", wim_dirent);
+    if (wim_dirent)
     {
     {
-        wim_dirent2 = search_full_wim_dirent(meta_data, dir, wpeinit_path);
-        debug("search wpeinit.exe %p\n", wim_dirent1);
-        if (wim_dirent2)
-        {
-            return wim_dirent2;
-        }
-        return wim_dirent1;
+        return wim_dirent;
     }
 
     }
 
-    wim_dirent1 = search_full_wim_dirent(meta_data, dir, winpeshl_path);
-    debug("search winpeshl.exe %p\n", wim_dirent1);
-    if (wim_dirent1)
+    wim_dirent = search_full_wim_dirent(meta_data, dir, winpeshl_path);
+    debug("search winpeshl.exe %p\n", wim_dirent);
+    if (wim_dirent)
     {
     {
-        return wim_dirent1;
+        return wim_dirent;
     }
 
     return NULL;
     }
 
     return NULL;
@@ -745,6 +737,27 @@ static grub_uint64_t ventoy_get_stream_len(wim_directory_entry *dir)
     return offset;
 }
 
     return offset;
 }
 
+static int ventoy_update_stream_hash(wim_patch *patch, wim_directory_entry *dir)
+{
+    grub_uint16_t i;
+    grub_uint64_t offset = 0;
+    wim_stream_entry *stream = (wim_stream_entry *)((char *)dir + dir->len);
+
+    for (i = 0; i < dir->streams; i++)
+    {
+        if (grub_memcmp(stream->hash.sha1, patch->old_hash.sha1, sizeof(wim_hash)) == 0)
+        {
+            debug("find target stream %u, name_len:%u upadte hash\n", i, stream->name_len);
+            grub_memcpy(stream->hash.sha1, &(patch->wim_data.bin_hash), sizeof(wim_hash));
+        }
+
+        offset += stream->len;
+        stream = (wim_stream_entry *)((char *)stream + stream->len);
+    }
+
+    return offset;
+}
+
 static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directory_entry *dir)
 {
     if ((meta_data == NULL) || (dir == NULL))
 static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directory_entry *dir)
 {
     if ((meta_data == NULL) || (dir == NULL))
@@ -772,6 +785,7 @@ static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directo
 
         if (dir->streams)
         {
 
         if (dir->streams)
         {
+            ventoy_update_stream_hash(patch, dir);
             dir = (wim_directory_entry *)((char *)dir + dir->len + ventoy_get_stream_len(dir));
         }
         else
             dir = (wim_directory_entry *)((char *)dir + dir->len + ventoy_get_stream_len(dir));
         }
         else
@@ -932,6 +946,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
 static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
 {
     int rc;
 static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
 {
     int rc;
+    grub_uint16_t i;
     grub_file_t file;
     grub_uint32_t exe_len;
     grub_uint8_t *exe_data = NULL;
     grub_file_t file;
     grub_uint32_t exe_len;
     grub_uint8_t *exe_data = NULL;
@@ -940,6 +955,7 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
     wim_security_header *security = NULL;
     wim_directory_entry *rootdir = NULL;
     wim_directory_entry *search = NULL;
     wim_security_header *security = NULL;
     wim_directory_entry *rootdir = NULL;
     wim_directory_entry *search = NULL;
+    wim_stream_entry *stream = NULL;
     wim_header *head = &(patch->wim_data.wim_header);    
     wim_tail *wim_data = &patch->wim_data;
     
     wim_header *head = &(patch->wim_data.wim_header);    
     wim_tail *wim_data = &patch->wim_data;
     
@@ -1002,8 +1018,28 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
     }
     
     debug("find replace file at %p\n", search);
     }
     
     debug("find replace file at %p\n", search);
-    
-    grub_memcpy(&patch->old_hash, search->hash.sha1, sizeof(wim_hash));
+
+    grub_memset(&patch->old_hash, 0, sizeof(wim_hash));
+    if (grub_memcmp(&patch->old_hash, search->hash.sha1, sizeof(wim_hash)) == 0)
+    {
+        debug("search hash all 0, now do deep search\n");
+        stream = (wim_stream_entry *)((char *)search + search->len);
+        for (i = 0; i < search->streams; i++)
+        {
+            if (stream->name_len == 0)
+            {
+                grub_memcpy(&patch->old_hash, stream->hash.sha1, sizeof(wim_hash));
+                debug("new search hash: %02x %02x %02x %02x %02x %02x %02x %02x\n", 
+                    ventoy_varg_8(patch->old_hash.sha1));
+                break;
+            }
+            stream = (wim_stream_entry *)((char *)stream + stream->len);
+        }
+    }
+    else
+    {
+        grub_memcpy(&patch->old_hash, search->hash.sha1, sizeof(wim_hash));        
+    }
 
     debug("read lookup offset:%llu size:%llu\n", (ulonglong)head->lookup.offset, (ulonglong)head->lookup.raw_size);
     lookup = grub_malloc(head->lookup.raw_size);
 
     debug("read lookup offset:%llu size:%llu\n", (ulonglong)head->lookup.offset, (ulonglong)head->lookup.raw_size);
     lookup = grub_malloc(head->lookup.raw_size);
@@ -1030,8 +1066,8 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
     }
     else
     {
     }
     else
     {
-        debug("failed to find lookup entry for replace file 0x%02x 0x%02x\n", 
-               patch->old_hash.sha1[0],  patch->old_hash.sha1[1]);
+        debug("failed to find lookup entry for replace file %02x %02x %02x %02x\n", 
+            ventoy_varg_4(patch->old_hash.sha1));
     }
 
     wim_data->wim_raw_size = (grub_uint32_t)file->size;
     }
 
     wim_data->wim_raw_size = (grub_uint32_t)file->size;
index 061120b809455101896eca73f063195ccd9f630f..76ed0d567e5903ba8eaafd0f89c69c0c777400ea 100644 (file)
@@ -45,6 +45,7 @@ if [ ! -f ./boot/boot.img ]; then
     if [ -d ./grub ]; then
         echo "Don't run VentoyWeb.sh here, please download the released install package, and run the script in it."
     else
     if [ -d ./grub ]; then
         echo "Don't run VentoyWeb.sh here, please download the released install package, and run the script in it."
     else
+        echo "Current directory is $PWD"
         echo "Please run under the correct directory!" 
     fi
     exit 1
         echo "Please run under the correct directory!" 
     fi
     exit 1
index 06ea4bd0ddde8e2d28d9ae4a1431358b3f68b33f..9c0cf8dd143688acd781017c8ab9aa60a80a52a5 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump32.exe and b/INSTALL/ventoy/vtoyjump32.exe differ
index be90eabbdd4339231fd105acbdbf995f3c868f5f..3c95c985264beb282f9c97f307845718b8cc51e5 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump64.exe and b/INSTALL/ventoy/vtoyjump64.exe differ
index 4598ea038f741ed371b061cdc061d5982120dd51..efc2acb83f46c1f66f4dd06ae5d7d0b6a1680733 100644 (file)
@@ -41,25 +41,26 @@ void Log(const char *Fmt, ...)
        FILE *File = NULL;\r
        SYSTEMTIME Sys;\r
        char szBuf[1024];\r
        FILE *File = NULL;\r
        SYSTEMTIME Sys;\r
        char szBuf[1024];\r
+    DWORD PID = GetCurrentProcessId();\r
 \r
        GetLocalTime(&Sys);\r
        Len += sprintf_s(szBuf, sizeof(szBuf),\r
 \r
        GetLocalTime(&Sys);\r
        Len += sprintf_s(szBuf, sizeof(szBuf),\r
-               "[%4d/%02d/%02d %02d:%02d:%02d.%03d] ",\r
+               "[%4d/%02d/%02d %02d:%02d:%02d.%03d] [%u] ",\r
                Sys.wYear, Sys.wMonth, Sys.wDay,\r
                Sys.wHour, Sys.wMinute, Sys.wSecond,\r
                Sys.wYear, Sys.wMonth, Sys.wDay,\r
                Sys.wHour, Sys.wMinute, Sys.wSecond,\r
-               Sys.wMilliseconds);\r
+        Sys.wMilliseconds, PID);\r
 \r
        va_start(Arg, Fmt);\r
        Len += vsnprintf_s(szBuf + Len, sizeof(szBuf)-Len, sizeof(szBuf)-Len, Fmt, Arg);\r
        va_end(Arg);\r
 \r
 \r
        va_start(Arg, Fmt);\r
        Len += vsnprintf_s(szBuf + Len, sizeof(szBuf)-Len, sizeof(szBuf)-Len, Fmt, Arg);\r
        va_end(Arg);\r
 \r
-       fopen_s(&File, "ventoy.log", "a+");\r
-       if (File)\r
-       {\r
-               fwrite(szBuf, 1, Len, File);\r
-               fwrite("\n", 1, 1, File);\r
-               fclose(File);\r
-       }\r
+    fopen_s(&File, "ventoy.log", "a+");\r
+    if (File)\r
+    {\r
+        fwrite(szBuf, 1, Len, File);\r
+        fwrite("\n", 1, 1, File);\r
+        fclose(File);\r
+    }\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -1410,159 +1411,43 @@ End:
        return rc;\r
 }\r
 \r
        return rc;\r
 }\r
 \r
-static int GetPecmdParam(const char *argv, char *CallParamBuf, DWORD BufLen)\r
+int main(int argc, char **argv)\r
 {\r
 {\r
-    HKEY hKey;\r
-    LSTATUS Ret;\r
-    DWORD dw;\r
-    DWORD Type;\r
+    int i = 0;\r
+    int rc = 0;\r
     CHAR *Pos = NULL;\r
     CHAR *Pos = NULL;\r
-    CHAR CallParam[256] = { 0 };\r
-    CHAR FileName[MAX_PATH];\r
-\r
-    Log("GetPecmdParam <%s>", argv);\r
-\r
-    *CallParamBuf = 0;\r
-\r
-    strcpy_s(FileName, sizeof(FileName), argv);\r
-    for (dw = 0, Pos = FileName; *Pos; Pos++)\r
-    {\r
-        dw++;\r
-        *Pos = toupper(*Pos);\r
-    }\r
-\r
-    Log("dw=%lu argv=<%s>", dw, FileName);\r
-\r
-    if (dw >= 9 && strcmp(FileName + dw - 9, "PECMD.EXE") == 0)\r
-    {\r
-        Log("Get parameters for pecmd.exe");\r
-        Ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "System\\Setup", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw);\r
-        if (ERROR_SUCCESS == Ret)\r
-        {\r
-            memset(FileName, 0, sizeof(FileName));\r
-            dw = sizeof(FileName);\r
-            Ret = RegQueryValueEx(hKey, "CmdLine", NULL, &Type, FileName, &dw);\r
-            if (ERROR_SUCCESS == Ret && Type == REG_SZ)\r
-            {\r
-                strcpy_s(CallParam, sizeof(CallParam), FileName);\r
-                Log("CmdLine:<%s>", CallParam);\r
-\r
-                if (_strnicmp(CallParam, "PECMD.EXE", 9) == 0)\r
-                {\r
-                    Pos = CallParam + 9;\r
-                    if (*Pos == ' ' || *Pos == '\t')\r
-                    {\r
-                        Pos++;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    Pos = CallParam;\r
-                }\r
-\r
-                Log("CmdLine2:<%s>", Pos);\r
-                sprintf_s(CallParamBuf, BufLen, " %s", Pos);\r
-            }\r
-            else\r
-            {\r
-                Log("Failed to RegQueryValueEx %lu %lu", Ret, Type);\r
-            }\r
+    CHAR CurDir[MAX_PATH];\r
+    CHAR LunchFile[MAX_PATH];\r
+    CHAR CallParam[1024] = { 0 };\r
+    STARTUPINFOA Si;\r
+    PROCESS_INFORMATION Pi;\r
 \r
 \r
-            RegCloseKey(hKey);\r
-            return 1;\r
-        }\r
-        else\r
-        {\r
-            Log("Failed to create reg key %lu", Ret);\r
-        }\r
-    }\r
-    else\r
+    if (argv[0] && argv[0][0] && argv[0][1] == ':')\r
     {\r
     {\r
-        Log("This is NOT pecmd.exe");\r
-    }\r
-\r
-    return 0;\r
-}\r
-\r
-static int GetWpeInitParam(char **argv, int argc, char *CallParamBuf, DWORD BufLen)\r
-{\r
-    int i;\r
-    DWORD dw;\r
-    CHAR *Pos = NULL;\r
-    CHAR FileName[MAX_PATH];\r
-\r
-    Log("GetWpeInitParam argc=%d", argc);\r
-\r
-    *CallParamBuf = 0;\r
+        GetCurrentDirectoryA(sizeof(CurDir), CurDir);\r
 \r
 \r
-    strcpy_s(FileName, sizeof(FileName), argv[0]);\r
-    for (dw = 0, Pos = FileName; *Pos; Pos++)\r
-    {\r
-        dw++;\r
-        *Pos = toupper(*Pos);\r
-    }\r
+        strcpy_s(LunchFile, sizeof(LunchFile), argv[0]);\r
+        Pos = (char *)GetFileNameInPath(LunchFile);\r
 \r
 \r
-    Log("dw=%lu argv=<%s>", dw, FileName);\r
+        strcat_s(CurDir, sizeof(CurDir), "\\");\r
+        strcat_s(CurDir, sizeof(CurDir), Pos);\r
 \r
 \r
-    if (dw >= 11 && strcmp(FileName + dw - 11, "WPEINIT.EXE") == 0)\r
-    {\r
-        Log("Get parameters for WPEINIT.EXE");\r
-        for (i = 1; i < argc; i++)\r
+        if (_stricmp(argv[0], CurDir) != 0)\r
         {\r
         {\r
-            strcat_s(CallParamBuf, BufLen, " ");\r
-            strcat_s(CallParamBuf, BufLen, argv[i]);\r
+            *Pos = 0;\r
+            SetCurrentDirectoryA(LunchFile);\r
         }\r
         }\r
-\r
-        return 1;\r
-    }\r
-    else\r
-    {\r
-        Log("This is NOT wpeinit.exe");\r
     }\r
     }\r
-    \r
-    return 0;\r
-}\r
-\r
-\r
-int main(int argc, char **argv)\r
-{\r
-    int i = 0;\r
-    int rc = 0;\r
-       CHAR *Pos = NULL;\r
-       CHAR CurDir[MAX_PATH];\r
-       CHAR LunchFile[MAX_PATH];\r
-    CHAR CallParam[1024] = { 0 };\r
-       STARTUPINFOA Si;\r
-       PROCESS_INFORMATION Pi;\r
 \r
 \r
-       if (argv[0] && argv[0][0] && argv[0][1] == ':')\r
-       {\r
-               GetCurrentDirectoryA(sizeof(CurDir), CurDir);\r
-\r
-               strcpy_s(LunchFile, sizeof(LunchFile), argv[0]);\r
-               Pos = (char *)GetFileNameInPath(LunchFile);\r
-\r
-               strcat_s(CurDir, sizeof(CurDir), "\\");\r
-               strcat_s(CurDir, sizeof(CurDir), Pos);\r
-               \r
-               if (_stricmp(argv[0], CurDir) != 0)\r
-               {\r
-                       *Pos = 0;\r
-                       SetCurrentDirectoryA(LunchFile);\r
-               }\r
-       }\r
-\r
-       Log("######## VentoyJump ##########");\r
-       Log("argc = %d argv[0] = <%s>", argc, argv[0]);\r
-\r
-    //special process for some WinPE\r
-    if (_stricmp(argv[0], "WPEINIT.EXE") == 0)\r
+    Log("######## VentoyJump ##########");\r
+    Log("argc = %d", argc);\r
+    for (i = 0; i < argc; i++)\r
     {\r
     {\r
-        GetCurrentDirectoryA(sizeof(CurDir), CurDir);\r
-        if (_stricmp(CurDir, "X:\\") == 0)\r
+        Log("argv[%d]=<%s>", i, argv[i]);\r
+        if (i > 0)\r
         {\r
         {\r
-            Log("Set current directory to system32");\r
-            SetCurrentDirectoryA("X:\\Windows\\System32");\r
+            strcat_s(CallParam, sizeof(CallParam), " ");\r
+            strcat_s(CallParam, sizeof(CallParam), argv[i]);\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
@@ -1577,11 +1462,6 @@ int main(int argc, char **argv)
                Log("Current directory = <%s>", CurDir);\r
        }\r
 \r
                Log("Current directory = <%s>", CurDir);\r
        }\r
 \r
-    if (0 == GetWpeInitParam(argv, argc, CallParam, sizeof(CallParam)))\r
-    {\r
-        GetPecmdParam(argv[0], CallParam, sizeof(CallParam));\r
-    }\r
-\r
     GetStartupInfoA(&Si);\r
 \r
     memset(LunchFile, 0, sizeof(LunchFile));\r
     GetStartupInfoA(&Si);\r
 \r
     memset(LunchFile, 0, sizeof(LunchFile));\r
@@ -1597,6 +1477,14 @@ int main(int argc, char **argv)
 \r
     Log("LunchFile=<%s> CallParam=<%s>", LunchFile, CallParam);\r
 \r
 \r
     Log("LunchFile=<%s> CallParam=<%s>", LunchFile, CallParam);\r
 \r
+    if (_stricmp(argv[0], "PECMD.EXE") == 0 && _stricmp(LunchFile, "ventoy\\PECMD.EXE") == 0)\r
+    {\r
+        MoveFileA("PECMD.EXE", "PECMD_BACK.EXE");\r
+        MoveFileA("ventoy\\PECMD.EXE", "PECMD.EXE");\r
+        sprintf_s(LunchFile, sizeof(LunchFile), "%s", "PECMD.EXE");\r
+        Log("Move original PECMD.EXE <%s>", LunchFile);\r
+    }\r
+\r
     if (g_os_param_reserved[0] == 3)\r
     {\r
         Log("Open log for debug ...");\r
     if (g_os_param_reserved[0] == 3)\r
     {\r
         Log("Open log for debug ...");\r