diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c index 2f1faa34..00ebba52 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c @@ -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) { diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c index facd0ede..d598a178 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include "ventoy_def.h" #include "miniz.h" @@ -3366,12 +3367,177 @@ end: 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; + grub_file_t file = 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; + 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); } diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h index d1163628..3ce2374f 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h @@ -36,11 +36,14 @@ #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 WINDATA_FLAG_TEMPLATE 1 + #define ulong unsigned long #define ulonglong unsigned long long @@ -84,6 +87,16 @@ 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 */ @@ -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_uint32_t windata_flag; 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; + char *filebuf; + int filelen; + 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); +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); -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); -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); diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c index 244a684e..f0ac3251 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c @@ -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; + install_template *template_node = NULL; 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); } - 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) { - 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 template: <%s> \n", + template_file, template_node->filebuf, template_node->filelen); + + template_size = template_node->filelen; + template_buf = grub_malloc(template_size); + if (template_buf) { - 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("Failed to open install script %s%s\n", args[2], template_file); + grub_memcpy(template_buf, template_node->filebuf, template_size); } } 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); + 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); - - grub_free(persistent_buf); - persistent_buf = NULL; + grub_check_free(persistent_buf); } if (injection_size > 0 && injection_buf) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c index b7152f9a..1d6e7608 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c @@ -2641,10 +2641,15 @@ install_template * ventoy_plugin_find_install_template(const char *isopath) 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; + if (cur) + { + *cur = NULL; + } + 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; } + if (cur) + { + *cur = node; + } + return node->templatepath[node->cursel].path; } diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c index 23bbc8b7..987b04ac 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c @@ -1015,7 +1015,7 @@ static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directo 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]; @@ -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; - 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); - 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", @@ -1046,26 +1046,68 @@ static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, g 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; + 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; + install_template *template_node = NULL; 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; } - 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> \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 { @@ -1090,12 +1132,6 @@ int ventoy_fill_windows_rtdata(void *buf, char *isopath) 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; } @@ -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)); - 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); @@ -1168,7 +1204,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath) 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; @@ -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))) { - 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 @@ -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) { + int datalen = 0; + int dataflag = 0; wim_patch *node = g_wim_patch_head; (void)ctxt; (void)argc; (void)args; + datalen = ventoy_get_windows_rtdata_len(args[1], &dataflag); + 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++; @@ -1751,6 +1792,8 @@ end: 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; @@ -1776,7 +1819,9 @@ grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, 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) { @@ -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)); - 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); diff --git a/GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h b/GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h index 9199fa41..9b5bb4a8 100644 --- a/GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h +++ b/GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h @@ -139,7 +139,13 @@ typedef struct ventoy_windows_data 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; diff --git a/INSTALL/ventoy/vtoyjump32.exe b/INSTALL/ventoy/vtoyjump32.exe index 430cbac7..6a3f12d1 100644 Binary files a/INSTALL/ventoy/vtoyjump32.exe and b/INSTALL/ventoy/vtoyjump32.exe differ diff --git a/INSTALL/ventoy/vtoyjump64.exe b/INSTALL/ventoy/vtoyjump64.exe index d0399e24..5ffe4955 100644 Binary files a/INSTALL/ventoy/vtoyjump64.exe and b/INSTALL/ventoy/vtoyjump64.exe differ diff --git a/vtoyjump/vtoyjump/vtoyjump.c b/vtoyjump/vtoyjump/vtoyjump.c index 7c3d8037..81f5b0db 100644 --- a/vtoyjump/vtoyjump/vtoyjump.c +++ b/vtoyjump/vtoyjump/vtoyjump.c @@ -47,6 +47,8 @@ static CHAR g_prog_name[MAX_PATH]; #define AUTO_RUN_BAT "X:\\VentoyAutoRun.bat" #define AUTO_RUN_LOG "X:\\VentoyAutoRun.log" +#define VTOY_AUTO_FILE "X:\\_vtoy_auto_install" + #define LOG_FILE "X:\\Windows\\system32\\ventoy.log" #define MUTEX_LOCK(hmutex) if (hmutex != NULL) LockStatus = WaitForSingleObject(hmutex, INFINITE) #define MUTEX_UNLOCK(hmutex) if (hmutex != NULL && WAIT_OBJECT_0 == LockStatus) ReleaseMutex(hmutex) @@ -255,9 +257,25 @@ End: return rc; } -static BOOL CheckPeHead(BYTE *Head) +static BOOL CheckPeHead(BYTE *Buffer, DWORD Size, DWORD Offset) { UINT32 PeOffset; + BYTE *Head = NULL; + DWORD End; + ventoy_windows_data *pdata = NULL; + + Head = Buffer + Offset; + pdata = (ventoy_windows_data *)Head; + Head += sizeof(ventoy_windows_data); + + if (pdata->auto_install_script[0] && pdata->auto_install_len > 0) + { + End = Offset + sizeof(ventoy_windows_data) + pdata->auto_install_len + 60; + if (End < Size) + { + Head += pdata->auto_install_len; + } + } if (Head[0] != 'M' || Head[1] != 'Z') { @@ -1647,11 +1665,10 @@ static int VentoyHook(ventoy_os_param *param) if (g_windows_data.auto_install_script[0]) { - sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", VtoyLetter, g_windows_data.auto_install_script); - if (IsFileExist("%s", IsoPath)) + if (IsFileExist("%s", VTOY_AUTO_FILE)) { - Log("use auto install script %s...", IsoPath); - ProcessUnattendedInstallation(IsoPath); + Log("use auto install script %s...", VTOY_AUTO_FILE); + ProcessUnattendedInstallation(VTOY_AUTO_FILE); } else { @@ -1724,6 +1741,25 @@ static int VentoyHook(ventoy_os_param *param) return 0; } +static int ExtractWindowsDataFile(char *databuf) +{ + int len = 0; + char *filedata = NULL; + ventoy_windows_data *pdata = (ventoy_windows_data *)databuf; + + Log("ExtractWindowsDataFile: auto install <%s:%d>", pdata->auto_install_script, pdata->auto_install_len); + + filedata = databuf + sizeof(ventoy_windows_data); + + if (pdata->auto_install_script[0] && pdata->auto_install_len > 0) + { + SaveBuffer2File(VTOY_AUTO_FILE, filedata, pdata->auto_install_len); + filedata += pdata->auto_install_len; + len = pdata->auto_install_len; + } + + return len; +} int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile) { @@ -1741,6 +1777,7 @@ int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile) memcpy(&g_os_param, buf, sizeof(ventoy_os_param)); memcpy(&g_windows_data, buf + sizeof(ventoy_os_param), sizeof(ventoy_windows_data)); + ExtractWindowsDataFile(buf + sizeof(ventoy_os_param)); memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved)); if (g_os_param_reserved[0] == 1) @@ -1800,6 +1837,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile) { int rc = 1; int stat = 0; + int exlen = 0; DWORD Pos; DWORD PeStart; DWORD FileSize; @@ -1835,12 +1873,13 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile) for (PeStart = 0; PeStart < FileSize; PeStart += 16) { if (CheckOsParam((ventoy_os_param *)(Buffer + PeStart)) && - CheckPeHead(Buffer + PeStart + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data))) + CheckPeHead(Buffer, FileSize, PeStart + sizeof(ventoy_os_param))) { Log("Find os pararm at %u", PeStart); memcpy(&g_os_param, Buffer + PeStart, sizeof(ventoy_os_param)); - memcpy(&g_windows_data, Buffer + PeStart + sizeof(ventoy_os_param), sizeof(ventoy_windows_data)); + memcpy(&g_windows_data, Buffer + PeStart + sizeof(ventoy_os_param), sizeof(ventoy_windows_data)); + exlen = ExtractWindowsDataFile(Buffer + PeStart + sizeof(ventoy_os_param)); memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved)); if (g_os_param_reserved[0] == 1) @@ -1858,7 +1897,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile) } } - PeStart += sizeof(ventoy_os_param) + sizeof(ventoy_windows_data); + PeStart += sizeof(ventoy_os_param) + sizeof(ventoy_windows_data) + exlen; sprintf_s(LunchFile, MAX_PATH, "ventoy\\%s", GetFileNameInPath(ExeFileName)); MUTEX_LOCK(g_vtoyins_mutex); diff --git a/vtoyjump/vtoyjump/vtoyjump.h b/vtoyjump/vtoyjump/vtoyjump.h index 3a8fcb61..1e37338e 100644 --- a/vtoyjump/vtoyjump/vtoyjump.h +++ b/vtoyjump/vtoyjump/vtoyjump.h @@ -72,7 +72,15 @@ typedef struct ventoy_windows_data 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;