]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Support prameters expansion in auto install script.
authorlongpanda <admin@ventoy.net>
Wed, 15 Jun 2022 12:53:35 +0000 (20:53 +0800)
committerlongpanda <admin@ventoy.net>
Wed, 15 Jun 2022 12:53:35 +0000 (20:53 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h
INSTALL/ventoy/vtoyjump32.exe
INSTALL/ventoy/vtoyjump64.exe
vtoyjump/vtoyjump/vtoyjump.c
vtoyjump/vtoyjump/vtoyjump.h

index 2f1faa3413f77fb250d8f8a249e2ff5707df8334..00ebba5253a2ae442e32f3d61a6b9e1a8c73e002 100644 (file)
@@ -76,7 +76,26 @@ void ventoy_str_toupper(char *str)
     }
 }
 
     }
 }
 
+char *ventoy_str_last(char *str, char ch)
+{
+    char *pos = NULL;
+    char *last = NULL;
+
+    if (!str)
+    {
+        return NULL;
+    }
 
 
+    for (pos = str; *pos; pos++)
+    {
+        if (*pos == ch)
+        {
+            last = pos;
+        }
+    }
+
+    return last;
+}
 
 int ventoy_strcmp(const char *pattern, const char *str)
 {
 
 int ventoy_strcmp(const char *pattern, const char *str)
 {
index facd0ede77c6104a95d92c6d0ef346cc0b3b5040..d598a178092032ec289af8e9cb8bff3ca8a69e7d 100644 (file)
@@ -45,6 +45,7 @@
 #include <grub/charset.h>
 #include <grub/crypto.h>
 #include <grub/lib/crc.h>
 #include <grub/charset.h>
 #include <grub/crypto.h>
 #include <grub/lib/crc.h>
+#include <grub/random.h>
 #include <grub/ventoy.h>
 #include "ventoy_def.h"
 #include "miniz.h"
 #include <grub/ventoy.h>
 #include "ventoy_def.h"
 #include "miniz.h"
@@ -3366,12 +3367,177 @@ end:
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
+static int ventoy_var_expand(int *flag, const char *var, char *value, int len)
+{
+    int i = 0;
+    int n = 0;
+    char c;
+    grub_uint8_t bytes[32];
+
+    if (grub_strncmp(var, "VT_RAND_", 8) == 0)
+    {
+        grub_crypto_get_random(bytes, sizeof(bytes));
+        if (grub_strcmp(var + 8, "9") == 0)
+        {
+            n = 1;
+        }
+        else if (grub_strcmp(var + 8, "99") == 0)
+        {
+            n = 2;
+        }
+        else if (grub_strcmp(var + 8, "999") == 0)
+        {
+            n = 3;
+        }
+        else if (grub_strcmp(var + 8, "9999") == 0)
+        {
+            n = 4;
+        }
+
+        for (i = 0; i < n; i++)
+        {
+            value[i] = '0' + (bytes[i] % 10);
+        }
+    }
+    else
+    {
+        if (*flag == 0)
+        {
+            *flag = 1;
+            grub_printf("\n===================  Parameter Expansion  ===================\n\n");
+        }
+    
+        grub_printf("<%s>: ", var);
+        grub_refresh();
+
+        while (i < (len - 1))
+        {
+            c = grub_getkey();
+            if ((c == '\n') || (c == '\r'))
+            {
+                grub_printf("\n");
+                grub_refresh();
+                break;
+            }
+
+            if (grub_isprint(c))
+            {
+                grub_printf("%c", c);
+                grub_refresh();
+                value[i++] = c;
+                value[i] = 0;
+            }
+            else if (c == '\b')
+            {
+                if (i > 0)
+                {
+                    value[i - 1] = ' ';
+                    grub_printf("\r<%s>: %s", var, value);
+
+                    value[i - 1] = 0;
+                    grub_printf("\r<%s>: %s", var, value);
+                    
+                    grub_refresh();
+                    i--;
+                }
+            }
+        }
+    }
+
+    if (value[0] == 0)
+    {
+        grub_snprintf(value, len, "%s", var);
+    }
+    
+    return 0;
+}
+
+static int ventoy_auto_install_var_expand(install_template *node)
+{
+    int pos = 0;
+    int flag = 0;
+    int newlen = 0;
+    char *start = NULL;
+    char *end = NULL;
+    char *newbuf = NULL;
+    char *curline = NULL;
+    char *nextline = NULL;
+    grub_uint8_t *code = NULL;
+    char value[512];
+
+    code = (grub_uint8_t *)node->filebuf;
+    
+    if ((code[0] == 0xff && code[1] == 0xfe) || (code[0] == 0xfe && code[1] == 0xff))
+    {
+        debug("UCS-2 encoding NOT supported\n");
+        return 0;
+    }
+
+    start = grub_strstr(node->filebuf, "$<");
+    if (!start)
+    {
+        debug("no need to expand variable, no start.\n");
+        return 0;
+    }
+
+    end = grub_strstr(start + 2, ">$");
+    if (!end)
+    {
+        debug("no need to expand variable, no end.\n");
+        return 0;
+    }
+
+    newlen = grub_max(node->filelen * 10, VTOY_SIZE_128KB);
+    newbuf = grub_malloc(newlen);
+    if (!newbuf)
+    {
+        debug("Failed to alloc newbuf %d\n", newlen);
+        return 0;
+    }
+
+    for (curline = node->filebuf; curline; curline = nextline)
+    {
+        nextline = ventoy_get_line(curline);
+
+        start = grub_strstr(curline, "$<");
+        if (start)
+        {
+            end = grub_strstr(start + 2, ">$");
+        }
+
+        if (start && end)
+        {
+            *start = *end = 0;
+            VTOY_APPEND_NEWBUF(curline);
+
+            value[sizeof(value) - 1] = 0;
+            ventoy_var_expand(&flag, start + 2, value, sizeof(value) - 1);
+            VTOY_APPEND_NEWBUF(value);
+            
+            VTOY_APPEND_NEWBUF(end + 2);
+        }
+        else
+        {
+            VTOY_APPEND_NEWBUF(curline);
+        }
+        
+        newbuf[pos++] = '\n';
+    }
+
+    grub_free(node->filebuf);
+    node->filebuf = newbuf;
+    node->filelen = pos;
+
+    return 0;
+}
+
 static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     int i = 0;
     int pos = 0;
     int defidx = 1;
     char *buf = NULL;
 static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     int i = 0;
     int pos = 0;
     int defidx = 1;
     char *buf = NULL;
+    grub_file_t file = NULL;
     char configfile[128];
     install_template *node = NULL;
         
     char configfile[128];
     install_template *node = NULL;
         
@@ -3440,6 +3606,33 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
 
     node->cursel = g_ventoy_last_entry - 1;
 
 
     node->cursel = g_ventoy_last_entry - 1;
 
+    grub_check_free(node->filebuf);
+    node->filelen = 0;
+
+    if (node->cursel >= 0 && node->cursel < node->templatenum)
+    {
+        file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", ventoy_get_env("vtoy_iso_part"), 
+            node->templatepath[node->cursel].path);
+        if (file)
+        {
+            node->filebuf = grub_malloc(file->size + 1);
+            if (node->filebuf)
+            {
+                grub_file_read(file, node->filebuf, file->size);
+                grub_file_close(file);
+                node->filebuf[file->size] = 0;
+                node->filelen = (int)file->size;
+
+                ventoy_auto_install_var_expand(node);
+            }
+        }
+        else
+        {
+            debug("Failed to open auto install script <%s%s>\n", 
+                ventoy_get_env("vtoy_iso_part"), node->templatepath[node->cursel].path);
+        }
+    }
+
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
     VENTOY_CMD_RETURN(GRUB_ERR_NONE);
 }
 
index d1163628a65d04c536d5e3388d2f594d4b5529fa..3ce2374f5b40f849d75cf76cc64da1ffa503b4c9 100644 (file)
 #define VTOY_SIZE_512KB   (512 * 1024)
 #define VTOY_SIZE_1KB     1024
 #define VTOY_SIZE_32KB    (32 * 1024)
 #define VTOY_SIZE_512KB   (512 * 1024)
 #define VTOY_SIZE_1KB     1024
 #define VTOY_SIZE_32KB    (32 * 1024)
+#define VTOY_SIZE_128KB   (128 * 1024)
 
 #define JSON_SUCCESS    0
 #define JSON_FAILED     1
 #define JSON_NOT_FOUND  2
 
 
 #define JSON_SUCCESS    0
 #define JSON_FAILED     1
 #define JSON_NOT_FOUND  2
 
+#define WINDATA_FLAG_TEMPLATE   1
+
 #define ulong unsigned long
 #define ulonglong  unsigned long long
 
 #define ulong unsigned long
 #define ulonglong  unsigned long long
 
     return (err);\
 }
 
     return (err);\
 }
 
+#define VTOY_APPEND_NEWBUF(buf) \
+{\
+    char *__c = buf;\
+    while (*__c)\
+    {\
+        newbuf[pos++] = *__c;\
+        __c++;\
+    }\
+}
+
 typedef enum VTOY_FILE_FLT
 {
     VTOY_FILE_FLT_ISO = 0, /* .iso */
 typedef enum VTOY_FILE_FLT
 {
     VTOY_FILE_FLT_ISO = 0, /* .iso */
@@ -488,6 +501,7 @@ typedef struct wim_tail
     grub_uint8_t *jump_bin_data;
     grub_uint32_t bin_raw_len;
     grub_uint32_t bin_align_len;
     grub_uint8_t *jump_bin_data;
     grub_uint32_t bin_raw_len;
     grub_uint32_t bin_align_len;
+    grub_uint32_t windata_flag;
 
     grub_uint8_t *new_meta_data;
     grub_uint32_t new_meta_len;
 
     grub_uint8_t *new_meta_data;
     grub_uint32_t new_meta_len;
@@ -853,6 +867,9 @@ typedef struct install_template
     int templatenum;
     file_fullpath *templatepath;
 
     int templatenum;
     file_fullpath *templatepath;
 
+    char *filebuf;
+    int filelen;
+
     struct install_template *next;
 }install_template;
 
     struct install_template *next;
 }install_template;
 
@@ -1061,15 +1078,15 @@ extern grub_uint32_t g_ventoy_plat_data;
 void ventoy_str_tolower(char *str);
 void ventoy_str_toupper(char *str);
 char * ventoy_get_line(char *start);
 void ventoy_str_tolower(char *str);
 void ventoy_str_toupper(char *str);
 char * ventoy_get_line(char *start);
+char *ventoy_str_last(char *str, char ch);
 int ventoy_cmp_img(img_info *img1, img_info *img2);
 void ventoy_swap_img(img_info *img1, img_info *img2);
 int ventoy_cmp_img(img_info *img1, img_info *img2);
 void ventoy_swap_img(img_info *img1, img_info *img2);
-char * ventoy_plugin_get_cur_install_template(const char *isopath);
+char * ventoy_plugin_get_cur_install_template(const char *isopath, install_template **cur);
 install_template * ventoy_plugin_find_install_template(const char *isopath);
 persistence_config * ventoy_plugin_find_persistent(const char *isopath);
 grub_uint64_t ventoy_get_vtoy_partsize(int part);
 void ventoy_plugin_dump_injection(void);
 void ventoy_plugin_dump_auto_install(void);
 install_template * ventoy_plugin_find_install_template(const char *isopath);
 persistence_config * ventoy_plugin_find_persistent(const char *isopath);
 grub_uint64_t ventoy_get_vtoy_partsize(int part);
 void ventoy_plugin_dump_injection(void);
 void ventoy_plugin_dump_auto_install(void);
-int ventoy_fill_windows_rtdata(void *buf, char *isopath);
 int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
 const char * ventoy_plugin_get_injection(const char *isopath);
 const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
 int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, ventoy_img_chunk_list *chunk_list);
 const char * ventoy_plugin_get_injection(const char *isopath);
 const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
index 244a684ef8d4ab92d67f7b5de2beaf9ea25cb8cb..f0ac3251bdbe92cec0dac3010232f6b370965c35 100644 (file)
@@ -1211,6 +1211,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
     grub_file_t file;
     grub_file_t archfile;
     grub_file_t tmpfile;
     grub_file_t file;
     grub_file_t archfile;
     grub_file_t tmpfile;
+    install_template *template_node = NULL;
     ventoy_img_chunk_list chunk_list;
 
     (void)ctxt;
     ventoy_img_chunk_list chunk_list;
 
     (void)ctxt;
@@ -1257,26 +1258,17 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
         persistent_buf = (char *)(chunk_list.chunk);
     }
 
         persistent_buf = (char *)(chunk_list.chunk);
     }
 
-    template_file = ventoy_plugin_get_cur_install_template(args[1]);
+    template_file = ventoy_plugin_get_cur_install_template(args[1], &template_node);
     if (template_file)
     {
     if (template_file)
     {
-        debug("auto install template: <%s>\n", template_file);
-        tmpfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[2], template_file);
-        if (tmpfile)
-        {
-            debug("auto install script size %d\n", (int)tmpfile->size);
-            template_size = tmpfile->size;
-            template_buf = grub_malloc(template_size);
-            if (template_buf)
-            {
-                grub_file_read(tmpfile, template_buf, template_size);
-            }
-
-            grub_file_close(tmpfile);
-        }
-        else
+        debug("auto install template: <%s> <addr:%p> <len:%d>\n", 
+            template_file, template_node->filebuf, template_node->filelen);
+        
+        template_size = template_node->filelen;
+        template_buf = grub_malloc(template_size);
+        if (template_buf)
         {
         {
-            debug("Failed to open install script %s%s\n", args[2], template_file);
+            grub_memcpy(template_buf, template_node->filebuf, template_size);
         }
     }
     else
         }
     }
     else
@@ -1363,15 +1355,14 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
     {
         headlen = ventoy_cpio_newc_fill_head(buf, template_size, template_buf, "ventoy/autoinstall");
         buf += headlen + ventoy_align(template_size, 4);
     {
         headlen = ventoy_cpio_newc_fill_head(buf, template_size, template_buf, "ventoy/autoinstall");
         buf += headlen + ventoy_align(template_size, 4);
+        grub_check_free(template_buf);
     }
 
     if (persistent_size > 0 && persistent_buf)
     {
         headlen = ventoy_cpio_newc_fill_head(buf, persistent_size, persistent_buf, "ventoy/ventoy_persistent_map");
         buf += headlen + ventoy_align(persistent_size, 4);
     }
 
     if (persistent_size > 0 && persistent_buf)
     {
         headlen = ventoy_cpio_newc_fill_head(buf, persistent_size, persistent_buf, "ventoy/ventoy_persistent_map");
         buf += headlen + ventoy_align(persistent_size, 4);
-
-        grub_free(persistent_buf);
-        persistent_buf = NULL;
+        grub_check_free(persistent_buf);
     }
 
     if (injection_size > 0 && injection_buf)
     }
 
     if (injection_size > 0 && injection_buf)
index b7152f9a173a2c0f191e315ab7e4f13137b6a745..1d6e760876d2a4546ddceede58031a099149a59b 100644 (file)
@@ -2641,10 +2641,15 @@ install_template * ventoy_plugin_find_install_template(const char *isopath)
     return NULL;
 }
 
     return NULL;
 }
 
-char * ventoy_plugin_get_cur_install_template(const char *isopath)
+char * ventoy_plugin_get_cur_install_template(const char *isopath, install_template **cur)
 {
     install_template *node = NULL;
 
 {
     install_template *node = NULL;
 
+    if (cur)
+    {
+        *cur = NULL;
+    }
+
     node = ventoy_plugin_find_install_template(isopath);
     if ((!node) || (!node->templatepath))
     {
     node = ventoy_plugin_find_install_template(isopath);
     if ((!node) || (!node->templatepath))
     {
@@ -2656,6 +2661,11 @@ char * ventoy_plugin_get_cur_install_template(const char *isopath)
         return NULL;
     }
 
         return NULL;
     }
 
+    if (cur)
+    {
+        *cur = node;
+    }
+
     return node->templatepath[node->cursel].path;
 }
 
     return node->templatepath[node->cursel].path;
 }
 
index 23bbc8b7e10183e8dfda37c3915994e4871ba998..987b04ac82bffb22a768d5463994c36a7c92bd92 100644 (file)
@@ -1015,7 +1015,7 @@ static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directo
     return 0;
 }
 
     return 0;
 }
 
-static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, grub_uint8_t *exe_data)
+static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, grub_uint8_t *exe_data, int windatalen)
 {
     int pe64 = 0;
     char file[256];
 {
     int pe64 = 0;
     char file[256];
@@ -1030,14 +1030,14 @@ static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, g
     jump_align = ventoy_align(jump_len, 16);
     
     wim_data->jump_exe_len = jump_len;
     jump_align = ventoy_align(jump_len, 16);
     
     wim_data->jump_exe_len = jump_len;
-    wim_data->bin_raw_len = jump_align + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data) + exe_len;
+    wim_data->bin_raw_len = jump_align + sizeof(ventoy_os_param) + windatalen + exe_len;
     wim_data->bin_align_len = ventoy_align(wim_data->bin_raw_len, 2048);
     
     wim_data->jump_bin_data = grub_malloc(wim_data->bin_align_len);
     if (wim_data->jump_bin_data)
     {
         grub_memcpy(wim_data->jump_bin_data, jump_data, jump_len);
     wim_data->bin_align_len = ventoy_align(wim_data->bin_raw_len, 2048);
     
     wim_data->jump_bin_data = grub_malloc(wim_data->bin_align_len);
     if (wim_data->jump_bin_data)
     {
         grub_memcpy(wim_data->jump_bin_data, jump_data, jump_len);
-        grub_memcpy(wim_data->jump_bin_data + jump_align + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data), exe_data, exe_len);
+        grub_memcpy(wim_data->jump_bin_data + jump_align + sizeof(ventoy_os_param) + windatalen, exe_data, exe_len);
     }
 
     debug("jump_exe_len:%u bin_raw_len:%u bin_align_len:%u\n", 
     }
 
     debug("jump_exe_len:%u bin_raw_len:%u bin_align_len:%u\n", 
@@ -1046,26 +1046,68 @@ static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, g
     return 0;
 }
 
     return 0;
 }
 
-int ventoy_fill_windows_rtdata(void *buf, char *isopath)
+static int ventoy_get_windows_rtdata_len(const char *iso, int *flag)
 {
 {
+    int size = 0;
+    int template_file_len = 0;
     char *pos = NULL;
     char *script = NULL;
     char *pos = NULL;
     char *script = NULL;
+    install_template *template_node = NULL;
+
+    *flag = 0;
+    size = (int)sizeof(ventoy_windows_data);
+    
+    pos = grub_strstr(iso, "/");
+    if (!pos)
+    {
+        return size;
+    }
+    
+    script = ventoy_plugin_get_cur_install_template(pos, &template_node);
+    if (script)
+    {
+        (*flag) |= WINDATA_FLAG_TEMPLATE;
+        template_file_len = template_node->filelen;
+    }
+
+    return size + template_file_len;
+}
+
+static int ventoy_fill_windows_rtdata(void *buf, char *isopath, int dataflag)
+{
+    int template_len = 0;
+    char *pos = NULL;
+    char *end = NULL;
+    char *script = NULL;
     const char *env = NULL;
     const char *env = NULL;
+    install_template *template_node = NULL;
     ventoy_windows_data *data = (ventoy_windows_data *)buf;
 
     grub_memset(data, 0, sizeof(ventoy_windows_data));
 
     ventoy_windows_data *data = (ventoy_windows_data *)buf;
 
     grub_memset(data, 0, sizeof(ventoy_windows_data));
 
+    env = grub_env_get("VTOY_WIN11_BYPASS_CHECK");
+    if (env && env[0] == '1' && env[1] == 0)
+    {
+        data->windows11_bypass_check = 1;
+    }
+
     pos = grub_strstr(isopath, "/");
     if (!pos)
     {
         return 1;
     }
 
     pos = grub_strstr(isopath, "/");
     if (!pos)
     {
         return 1;
     }
 
-    script = ventoy_plugin_get_cur_install_template(pos);
-    if (script)
+    if (dataflag & WINDATA_FLAG_TEMPLATE)
     {
     {
-        debug("auto install script <%s>\n", script);
-        grub_snprintf(data->auto_install_script, sizeof(data->auto_install_script) - 1, "%s", script);
+        script = ventoy_plugin_get_cur_install_template(pos, &template_node);
+        if (script)
+        {
+            data->auto_install_len = template_len = template_node->filelen;
+            debug("auto install script OK <%s> <len:%d>\n", script, template_len);
+            end = ventoy_str_last(script, '/');
+            grub_snprintf(data->auto_install_script, sizeof(data->auto_install_script) - 1, "%s", end ? end + 1 : script);
+            grub_memcpy(data + 1, template_node->filebuf, template_len);
+        }
     }
     else
     {
     }
     else
     {
@@ -1090,12 +1132,6 @@ int ventoy_fill_windows_rtdata(void *buf, char *isopath)
         debug("injection archive not configed %s\n", pos);
     }
 
         debug("injection archive not configed %s\n", pos);
     }
 
-    env = grub_env_get("VTOY_WIN11_BYPASS_CHECK");
-    if (env && env[0] == '1' && env[1] == 0)
-    {
-        data->windows11_bypass_check = 1;
-    }
-
     return 0;
 }
 
     return 0;
 }
 
@@ -1125,7 +1161,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
         if (wim_data->jump_bin_data)
         {
             grub_memcpy(wim_data->jump_bin_data + jump_align, param, sizeof(ventoy_os_param));        
         if (wim_data->jump_bin_data)
         {
             grub_memcpy(wim_data->jump_bin_data + jump_align, param, sizeof(ventoy_os_param));        
-            ventoy_fill_windows_rtdata(wim_data->jump_bin_data + jump_align + sizeof(ventoy_os_param), isopath);
+            ventoy_fill_windows_rtdata(wim_data->jump_bin_data + jump_align + sizeof(ventoy_os_param), isopath, wim_data->windata_flag);
         }
 
         grub_crypto_hash(GRUB_MD_SHA1, wim_data->bin_hash.sha1, wim_data->jump_bin_data, wim_data->bin_raw_len);
         }
 
         grub_crypto_hash(GRUB_MD_SHA1, wim_data->bin_hash.sha1, wim_data->jump_bin_data, wim_data->bin_raw_len);
@@ -1168,7 +1204,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
     return 0;
 }
 
     return 0;
 }
 
-static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
+static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch, int windatalen)
 {
     int rc;
     grub_uint16_t i;
 {
     int rc;
     grub_uint16_t i;
@@ -1285,7 +1321,7 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
 
         if (0 == ventoy_read_resource(file, head, &(patch->replace_look->resource), (void **)&(exe_data)))
         {
 
         if (0 == ventoy_read_resource(file, head, &(patch->replace_look->resource), (void **)&(exe_data)))
         {
-            ventoy_cat_exe_file_data(wim_data, exe_len, exe_data);
+            ventoy_cat_exe_file_data(wim_data, exe_len, exe_data, windatalen);
             grub_free(exe_data);
         }
         else
             grub_free(exe_data);
         }
         else
@@ -1330,15 +1366,20 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
 
 grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args)
 {
 
 grub_err_t ventoy_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args)
 {
+    int datalen = 0;
+    int dataflag = 0;
     wim_patch *node = g_wim_patch_head;
 
     (void)ctxt;
     (void)argc;
     (void)args;
 
     wim_patch *node = g_wim_patch_head;
 
     (void)ctxt;
     (void)argc;
     (void)args;
 
+    datalen = ventoy_get_windows_rtdata_len(args[1], &dataflag);
+
     while (node)
     {
     while (node)
     {
-        if (0 == ventoy_wimdows_locate_wim(args[0], node))
+        node->wim_data.windata_flag = dataflag;
+        if (0 == ventoy_wimdows_locate_wim(args[0], node, datalen))
         {
             node->valid = 1;
             g_wim_valid_patch_count++;
         {
             node->valid = 1;
             g_wim_valid_patch_count++;
@@ -1751,6 +1792,8 @@ end:
 
 grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, char **args)
 {
 
 grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, char **args)
 {
+    int datalen = 0;
+    int dataflag = 0;
     grub_uint32_t size = 0;
     const char *addr = NULL;
     ventoy_chain_head *chain = NULL;
     grub_uint32_t size = 0;
     const char *addr = NULL;
     ventoy_chain_head *chain = NULL;
@@ -1776,7 +1819,9 @@ grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc,
         return 1;
     }
 
         return 1;
     }
 
-    size = sizeof(ventoy_os_param) + sizeof(ventoy_windows_data);
+    datalen = ventoy_get_windows_rtdata_len(chain->os_param.vtoy_img_path, &dataflag);
+
+    size = sizeof(ventoy_os_param) + datalen;
     param = (ventoy_os_param *)grub_zalloc(size);
     if (!param)
     {
     param = (ventoy_os_param *)grub_zalloc(size);
     if (!param)
     {
@@ -1784,7 +1829,7 @@ grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc,
     }
 
     grub_memcpy(param, &chain->os_param, sizeof(ventoy_os_param));
     }
 
     grub_memcpy(param, &chain->os_param, sizeof(ventoy_os_param));
-    ventoy_fill_windows_rtdata(param + 1, param->vtoy_img_path);
+    ventoy_fill_windows_rtdata(param + 1, param->vtoy_img_path, dataflag);
 
     grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (unsigned long)param);
     grub_env_set("vtoy_wimboot_mem_addr", envbuf);
 
     grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (unsigned long)param);
     grub_env_set("vtoy_wimboot_mem_addr", envbuf);
index 9199fa4100a8436fbeb49147b5de13494f25aa45..9b5bb4a80e28547f0f1873a1425b36ce2d634a4d 100644 (file)
@@ -139,7 +139,13 @@ typedef struct ventoy_windows_data
     char auto_install_script[384];
     char injection_archive[384];
     grub_uint8_t windows11_bypass_check;
     char auto_install_script[384];
     char injection_archive[384];
     grub_uint8_t windows11_bypass_check;
-    grub_uint8_t reserved[255];
+
+    grub_uint32_t auto_install_len;
+    
+    grub_uint8_t reserved[255 - 4];
+
+    /* auto_intall file buf */
+    /* ...... + auto_install_len */
 }ventoy_windows_data;
 
 
 }ventoy_windows_data;
 
 
index 430cbac7d4640a2811654d016d6af16e6e1884da..6a3f12d1f688c774bcc28b969cc69e9416bfa616 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump32.exe and b/INSTALL/ventoy/vtoyjump32.exe differ
index d0399e24574860bd48e9b60510071b5c83410ccb..5ffe4955c6c44f0f7317fcffd93f329b03b87958 100644 (file)
Binary files a/INSTALL/ventoy/vtoyjump64.exe and b/INSTALL/ventoy/vtoyjump64.exe differ
index 7c3d80377ce2012ad466ff0fce8aa160f1ea0c3f..81f5b0db787ef61896f45ee86b760af18a0abc45 100644 (file)
@@ -47,6 +47,8 @@ static CHAR g_prog_name[MAX_PATH];
 #define AUTO_RUN_BAT    "X:\\VentoyAutoRun.bat"\r
 #define AUTO_RUN_LOG    "X:\\VentoyAutoRun.log"\r
 \r
 #define AUTO_RUN_BAT    "X:\\VentoyAutoRun.bat"\r
 #define AUTO_RUN_LOG    "X:\\VentoyAutoRun.log"\r
 \r
+#define VTOY_AUTO_FILE   "X:\\_vtoy_auto_install"\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
 #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
@@ -255,9 +257,25 @@ End:
        return rc;\r
 }\r
 \r
        return rc;\r
 }\r
 \r
-static BOOL CheckPeHead(BYTE *Head)\r
+static BOOL CheckPeHead(BYTE *Buffer, DWORD Size, DWORD Offset)\r
 {\r
        UINT32 PeOffset;\r
 {\r
        UINT32 PeOffset;\r
+    BYTE *Head = NULL;\r
+    DWORD End;\r
+    ventoy_windows_data *pdata = NULL;\r
+\r
+    Head = Buffer + Offset;\r
+    pdata = (ventoy_windows_data *)Head;\r
+    Head += sizeof(ventoy_windows_data);\r
+\r
+    if (pdata->auto_install_script[0] && pdata->auto_install_len > 0)\r
+    {\r
+        End = Offset + sizeof(ventoy_windows_data) + pdata->auto_install_len + 60;\r
+        if (End < Size)\r
+        {\r
+            Head += pdata->auto_install_len;\r
+        }\r
+    }\r
 \r
        if (Head[0] != 'M' || Head[1] != 'Z')\r
        {\r
 \r
        if (Head[0] != 'M' || Head[1] != 'Z')\r
        {\r
@@ -1647,11 +1665,10 @@ static int VentoyHook(ventoy_os_param *param)
     \r
     if (g_windows_data.auto_install_script[0])\r
     {\r
     \r
     if (g_windows_data.auto_install_script[0])\r
     {\r
-        sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", VtoyLetter, g_windows_data.auto_install_script);\r
-        if (IsFileExist("%s", IsoPath))\r
+        if (IsFileExist("%s", VTOY_AUTO_FILE))\r
         {\r
         {\r
-            Log("use auto install script %s...", IsoPath);\r
-            ProcessUnattendedInstallation(IsoPath);\r
+            Log("use auto install script %s...", VTOY_AUTO_FILE);\r
+            ProcessUnattendedInstallation(VTOY_AUTO_FILE);\r
         }\r
         else\r
         {\r
         }\r
         else\r
         {\r
@@ -1724,6 +1741,25 @@ static int VentoyHook(ventoy_os_param *param)
     return 0;\r
 }\r
 \r
     return 0;\r
 }\r
 \r
+static int ExtractWindowsDataFile(char *databuf)\r
+{\r
+    int len = 0;\r
+    char *filedata = NULL;\r
+    ventoy_windows_data *pdata = (ventoy_windows_data *)databuf;\r
+\r
+    Log("ExtractWindowsDataFile: auto install <%s:%d>", pdata->auto_install_script, pdata->auto_install_len);\r
+\r
+    filedata = databuf + sizeof(ventoy_windows_data);\r
+\r
+    if (pdata->auto_install_script[0] && pdata->auto_install_len > 0)\r
+    {\r
+        SaveBuffer2File(VTOY_AUTO_FILE, filedata, pdata->auto_install_len);\r
+        filedata += pdata->auto_install_len;\r
+        len = pdata->auto_install_len;\r
+    }\r
+    \r
+    return len;\r
+}\r
 \r
 int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile)\r
 {\r
 \r
 int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile)\r
 {\r
@@ -1741,6 +1777,7 @@ int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile)
 \r
     memcpy(&g_os_param, buf, sizeof(ventoy_os_param));\r
     memcpy(&g_windows_data, buf + sizeof(ventoy_os_param), sizeof(ventoy_windows_data));\r
 \r
     memcpy(&g_os_param, buf, sizeof(ventoy_os_param));\r
     memcpy(&g_windows_data, buf + sizeof(ventoy_os_param), sizeof(ventoy_windows_data));\r
+    ExtractWindowsDataFile(buf + sizeof(ventoy_os_param));\r
     memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved));\r
 \r
     if (g_os_param_reserved[0] == 1)\r
     memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved));\r
 \r
     if (g_os_param_reserved[0] == 1)\r
@@ -1800,6 +1837,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
 {\r
        int rc = 1;\r
     int stat = 0;\r
 {\r
        int rc = 1;\r
     int stat = 0;\r
+    int exlen = 0;\r
        DWORD Pos;\r
        DWORD PeStart;\r
     DWORD FileSize;\r
        DWORD Pos;\r
        DWORD PeStart;\r
     DWORD FileSize;\r
@@ -1835,12 +1873,13 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
        for (PeStart = 0; PeStart < FileSize; PeStart += 16)\r
        {\r
                if (CheckOsParam((ventoy_os_param *)(Buffer + PeStart)) && \r
        for (PeStart = 0; PeStart < FileSize; PeStart += 16)\r
        {\r
                if (CheckOsParam((ventoy_os_param *)(Buffer + PeStart)) && \r
-            CheckPeHead(Buffer + PeStart + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data)))\r
+            CheckPeHead(Buffer, FileSize, PeStart + sizeof(ventoy_os_param)))\r
                {\r
                        Log("Find os pararm at %u", PeStart);\r
 \r
             memcpy(&g_os_param, Buffer + PeStart, sizeof(ventoy_os_param));\r
                {\r
                        Log("Find os pararm at %u", PeStart);\r
 \r
             memcpy(&g_os_param, Buffer + PeStart, sizeof(ventoy_os_param));\r
-            memcpy(&g_windows_data, Buffer + PeStart + sizeof(ventoy_os_param), sizeof(ventoy_windows_data));            \r
+            memcpy(&g_windows_data, Buffer + PeStart + sizeof(ventoy_os_param), sizeof(ventoy_windows_data));  \r
+            exlen = ExtractWindowsDataFile(Buffer + PeStart + sizeof(ventoy_os_param));\r
             memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved));\r
 \r
             if (g_os_param_reserved[0] == 1)\r
             memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved));\r
 \r
             if (g_os_param_reserved[0] == 1)\r
@@ -1858,7 +1897,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
                                }\r
                        }\r
 \r
                                }\r
                        }\r
 \r
-                       PeStart += sizeof(ventoy_os_param) + sizeof(ventoy_windows_data);\r
+                       PeStart += sizeof(ventoy_os_param) + sizeof(ventoy_windows_data) + exlen;\r
                        sprintf_s(LunchFile, MAX_PATH, "ventoy\\%s", GetFileNameInPath(ExeFileName));\r
 \r
             MUTEX_LOCK(g_vtoyins_mutex);\r
                        sprintf_s(LunchFile, MAX_PATH, "ventoy\\%s", GetFileNameInPath(ExeFileName));\r
 \r
             MUTEX_LOCK(g_vtoyins_mutex);\r
index 3a8fcb6115e256550d2c574154a60657049d2cb1..1e37338e9e2c621d62a388f3f21d62d45e034708 100644 (file)
@@ -72,7 +72,15 @@ typedef struct ventoy_windows_data
     char auto_install_script[384];
     char injection_archive[384];
     UINT8 windows11_bypass_check;
     char auto_install_script[384];
     char injection_archive[384];
     UINT8 windows11_bypass_check;
-    UINT8 reserved[255];
+
+    UINT32 auto_install_len;
+    
+    UINT8 reserved[255 - 4];
+
+    /* auto install script file data ... + auto_install_len */
+    /* ...... */
+
+    
 }ventoy_windows_data;
 
 
 }ventoy_windows_data;