Compare commits

...

8 Commits

Author SHA1 Message Date
longpanda
b976923f00 1.0.77 release 2022-06-19 13:56:49 +08:00
StoyanDimitrov
8db8e07b61 Update Bulgarian translation (#1677) 2022-06-18 16:35:04 +08:00
longpanda
f200c14730 fix build error 2022-06-17 12:25:21 +08:00
longpanda
c090197717 Fix build error 2022-06-17 09:36:01 +08:00
longpanda
3ac17aa825 Fix the issue that install media not recognized when install Clear Linux. (#1674) 2022-06-16 22:49:04 +08:00
longpanda
595b9441e9 Support prameters expansion in auto install script. 2022-06-15 20:53:35 +08:00
longpanda
0f3d48b3d9 Fix the chain load memory alloc failure in UEFI mode. 2022-06-15 20:50:25 +08:00
longpanda
61f289aa8a Fix a bug when booting daphile-21.01 2022-06-14 13:33:59 +08:00
35 changed files with 1968 additions and 258 deletions

View File

@@ -38,6 +38,7 @@
#include <grub/memory.h>
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#include <grub/efi/memory.h>
#endif
#include <grub/ventoy.h>
#include "ventoy_def.h"
@@ -75,7 +76,44 @@ 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_str_all_digit(const char *str)
{
if (NULL == str || 0 == *str)
{
return 0;
}
while (*str)
{
if (*str < '0' || *str > '9')
{
return 0;
}
}
return 1;
}
int ventoy_strcmp(const char *pattern, const char *str)
{
@@ -135,6 +173,22 @@ int ventoy_is_efi_os(void)
return g_efi_os;
}
void * ventoy_alloc_chain(grub_size_t size)
{
void *p = NULL;
p = grub_malloc(size);
#ifdef GRUB_MACHINE_EFI
if (!p)
{
p = grub_efi_allocate_any_pages(GRUB_EFI_BYTES_TO_PAGES(size));
}
#endif
return p;
}
static int ventoy_arch_mode_init(void)
{
#ifdef GRUB_MACHINE_EFI

View File

@@ -45,6 +45,7 @@
#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"
@@ -482,7 +483,7 @@ static int ventoy_load_efiboot_template(char **buf, int *datalen, int *direntoff
return 0;
}
static int ventoy_set_check_result(int ret)
static int ventoy_set_check_result(int ret, const char *msg)
{
char buf[32];
@@ -496,7 +497,8 @@ static int ventoy_set_check_result(int ret)
grub_printf(VTOY_WARNING"\n");
grub_printf(VTOY_WARNING"\n\n\n");
grub_printf("This is NOT a standard Ventoy device and is NOT supported (%d).\n\n", ret);
grub_printf("This is NOT a standard Ventoy device and is NOT supported (%d).\n", ret);
grub_printf("Error message: <%s>\n\n", msg);
grub_printf("You should follow the instructions in https://www.ventoy.net to use Ventoy.\n");
grub_printf("\n\nWill exit after 10 seconds ...... ");
@@ -522,7 +524,7 @@ static int ventoy_check_official_device(grub_device_t dev)
if (dev->disk == NULL || dev->disk->partition == NULL)
{
return ventoy_set_check_result(1 | 0x1000);
return ventoy_set_check_result(1 | 0x1000, "Internal Error");
}
if (0 == ventoy_check_file_exist("(%s,2)/ventoy/ventoy.cpio", dev->disk->name) ||
@@ -530,11 +532,17 @@ static int ventoy_check_official_device(grub_device_t dev)
0 == ventoy_check_file_exist("(%s,2)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
{
#ifndef GRUB_MACHINE_EFI
if (0 == ventoy_check_file_exist("(ventoydisk)/ventoy/ventoy.cpio", dev->disk->name) ||
0 == ventoy_check_file_exist("(ventoydisk)/grub/localboot.cfg", dev->disk->name) ||
0 == ventoy_check_file_exist("(ventoydisk)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
if (0 == ventoy_check_file_exist("(ventoydisk)/ventoy/ventoy.cpio", dev->disk->name))
{
return ventoy_set_check_result(2 | 0x1000);
return ventoy_set_check_result(2 | 0x1000, "File ventoy/ventoy.cpio missing in VTOYEFI partition");
}
else if (0 == ventoy_check_file_exist("(ventoydisk)/grub/localboot.cfg", dev->disk->name))
{
return ventoy_set_check_result(2 | 0x1000, "File grub/localboot.cfg missing in VTOYEFI partition");
}
else if (0 == ventoy_check_file_exist("(ventoydisk)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
{
return ventoy_set_check_result(2 | 0x1000, "File tool/mount.exfat-fuse_aarch64 missing in VTOYEFI partition");
}
else
{
@@ -554,19 +562,19 @@ static int ventoy_check_official_device(grub_device_t dev)
}
if (!file)
{
return ventoy_set_check_result(3 | 0x1000);
return ventoy_set_check_result(3 | 0x1000, "File ventoy/ventoy.cpio open failed in VTOYEFI partition");
}
if (NULL == grub_strstr(file->fs->name, "fat"))
{
grub_file_close(file);
return ventoy_set_check_result(4 | 0x1000);
return ventoy_set_check_result(4 | 0x1000, "VTOYEFI partition is not FAT filesystem");
}
partition = dev->disk->partition;
if (partition->number != 0 || partition->start != 2048)
{
return ventoy_set_check_result(5);
return ventoy_set_check_result(5, "Ventoy partition is not start at 1MB");
}
if (workaround)
@@ -578,7 +586,7 @@ static int ventoy_check_official_device(grub_device_t dev)
(PartTbl[1].LastLBA + 1 - PartTbl[1].StartLBA) != 65536)
{
grub_file_close(file);
return ventoy_set_check_result(6);
return ventoy_set_check_result(6, "Disk partition layout check failed.");
}
}
else
@@ -588,7 +596,7 @@ static int ventoy_check_official_device(grub_device_t dev)
PartTbl[1].SectorCount != 65536)
{
grub_file_close(file);
return ventoy_set_check_result(6);
return ventoy_set_check_result(6, "Disk partition layout check failed.");
}
}
}
@@ -599,7 +607,7 @@ static int ventoy_check_official_device(grub_device_t dev)
if ((partition->number != 1) || (partition->len != 65536) || (offset != partition->start))
{
grub_file_close(file);
return ventoy_set_check_result(7);
return ventoy_set_check_result(7, "Disk partition layout check failed.");
}
}
@@ -611,21 +619,21 @@ static int ventoy_check_official_device(grub_device_t dev)
dev2 = grub_device_open(devname);
if (!dev2)
{
return ventoy_set_check_result(8);
return ventoy_set_check_result(8, "Disk open failed");
}
fs = grub_fs_probe(dev2);
if (!fs)
{
grub_device_close(dev2);
return ventoy_set_check_result(9);
return ventoy_set_check_result(9, "FS probe failed");
}
fs->fs_label(dev2, &label);
if ((!label) || grub_strncmp("VTOYEFI", label, 7))
{
grub_device_close(dev2);
return ventoy_set_check_result(10);
return ventoy_set_check_result(10, "Partition name is not VTOYEFI");
}
grub_device_close(dev2);
@@ -635,7 +643,7 @@ static int ventoy_check_official_device(grub_device_t dev)
disk = grub_disk_open(dev->disk->name);
if (!disk)
{
return ventoy_set_check_result(11);
return ventoy_set_check_result(11, "Disk open failed");
}
grub_memset(mbr, 0, 512);
@@ -644,10 +652,10 @@ static int ventoy_check_official_device(grub_device_t dev)
if (grub_memcmp(g_check_mbr_data, mbr, 0x30) || grub_memcmp(g_check_mbr_data + 0x30, mbr + 0x190, 16))
{
return ventoy_set_check_result(12);
return ventoy_set_check_result(12, "MBR check failed");
}
return ventoy_set_check_result(0);
return ventoy_set_check_result(0, NULL);
}
static int ventoy_check_ignore_flag(const char *filename, const struct grub_dirhook_info *info, void *data)
@@ -3366,12 +3374,234 @@ end:
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static int ventoy_var_expand(int *record, int *flag, const char *var, char *expand, int len)
{
int i = 0;
int n = 0;
char c;
const char *ch = var;
*record = 0;
expand[0] = 0;
while (*ch)
{
if (*ch == '_' || (*ch >= '0' && *ch <= '9') || (*ch >= 'A' && *ch <= 'Z') || (*ch >= 'a' && *ch <= 'z'))
{
ch++;
n++;
}
else
{
debug("Invalid variable letter <%c>\n", *ch);
goto end;
}
}
if (n > 32)
{
debug("Invalid variable length:%d <%s>\n", n, var);
goto end;
}
if (grub_strncmp(var, "VT_", 3) == 0) /* built-in variables */
{
}
else
{
if (*flag == 0)
{
*flag = 1;
grub_printf("\n=================== Variables Expansion ===================\n\n");
}
grub_printf("<%s>: ", var);
grub_refresh();
while (i < (len - 1))
{
c = grub_getkey();
if ((c == '\n') || (c == '\r'))
{
if (i > 0)
{
grub_printf("\n");
grub_refresh();
*record = 1;
break;
}
}
else if (grub_isprint(c))
{
if (i + 1 < (len - 1))
{
grub_printf("%c", c);
grub_refresh();
expand[i++] = c;
expand[i] = 0;
}
}
else if (c == '\b')
{
if (i > 0)
{
expand[i - 1] = ' ';
grub_printf("\r<%s>: %s", var, expand);
expand[i - 1] = 0;
grub_printf("\r<%s>: %s", var, expand);
grub_refresh();
i--;
}
}
}
}
end:
if (expand[0] == 0)
{
grub_snprintf(expand, len, "$$%s$$", var);
}
return 0;
}
static int ventoy_auto_install_var_expand(install_template *node)
{
int pos = 0;
int flag = 0;
int record = 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];
var_node *CurNode = NULL;
var_node *pVarList = NULL;
code = (grub_uint8_t *)node->filebuf;
if (node->filelen >= VTOY_SIZE_1MB)
{
debug("auto install script too long %d\n", node->filelen);
return 0;
}
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);
for (CurNode = pVarList; CurNode; CurNode = CurNode->next)
{
if (grub_strcmp(start + 2, CurNode->var) == 0)
{
grub_snprintf(value, sizeof(value) - 1, "%s", CurNode->val);
break;
}
}
if (!CurNode)
{
value[sizeof(value) - 1] = 0;
ventoy_var_expand(&record, &flag, start + 2, value, sizeof(value) - 1);
if (record)
{
CurNode = grub_zalloc(sizeof(var_node));
if (CurNode)
{
grub_snprintf(CurNode->var, sizeof(CurNode->var), "%s", start + 2);
grub_snprintf(CurNode->val, sizeof(CurNode->val), "%s", value);
CurNode->next = pVarList;
pVarList = CurNode;
}
}
}
VTOY_APPEND_NEWBUF(value);
VTOY_APPEND_NEWBUF(end + 2);
}
else
{
VTOY_APPEND_NEWBUF(curline);
}
if (pos > 0 && newbuf[pos - 1] == '\r')
{
newbuf[pos - 1] = '\n';
}
else
{
newbuf[pos++] = '\n';
}
}
grub_free(node->filebuf);
node->filebuf = newbuf;
node->filelen = pos;
while (pVarList)
{
CurNode = pVarList->next;
grub_free(pVarList);
pVarList = CurNode;
}
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 +3670,34 @@ 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 + 8);
if (node->filebuf)
{
grub_file_read(file, node->filebuf, file->size);
grub_file_close(file);
grub_memset(node->filebuf + file->size, 0, 8);
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);
}

View File

@@ -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;
@@ -587,6 +601,7 @@ typedef struct chk_case_fs_dir
grub_fs_t fs;
}chk_case_fs_dir;
int ventoy_str_all_digit(const char *str);
int ventoy_strcmp(const char *pattern, const char *str);
int ventoy_strncmp (const char *pattern, const char *str, grub_size_t n);
void ventoy_fill_os_param(grub_file_t file, ventoy_os_param *param);
@@ -853,6 +868,9 @@ typedef struct install_template
int templatenum;
file_fullpath *templatepath;
char *filebuf;
int filelen;
struct install_template *next;
}install_template;
@@ -1061,15 +1079,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);
@@ -1191,6 +1209,14 @@ typedef struct browser_node
struct browser_node *next;
}browser_node;
typedef struct var_node
{
char var[128];
char val[256];
struct var_node *next;
}var_node;
extern char *g_tree_script_buf;
extern int g_tree_script_pos;
extern int g_tree_script_pre;
@@ -1206,6 +1232,7 @@ grub_err_t ventoy_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **a
grub_err_t ventoy_cmd_browser_disk(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_get_fs_type(const char *fs);
int ventoy_img_name_valid(const char *filename, grub_size_t namelen);
void * ventoy_alloc_chain(grub_size_t size);
#endif /* __VENTOY_DEF_H__ */

View 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;
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> <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("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)
@@ -1623,10 +1614,10 @@ grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, cha
}
}
chain = grub_malloc(size);
chain = ventoy_alloc_chain(size);
if (!chain)
{
grub_printf("Failed to alloc chain memory size %u\n", size);
grub_printf("Failed to alloc chain linux memory size %u\n", size);
grub_file_close(file);
return 1;
}

View File

@@ -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;
}

View File

@@ -1185,10 +1185,10 @@ grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char
}
}
chain = grub_malloc(size);
chain = ventoy_alloc_chain(size);
if (!chain)
{
grub_printf("Failed to alloc chain memory size %u\n", size);
grub_printf("Failed to alloc chain unix memory size %u\n", size);
grub_file_close(file);
return 1;
}

View File

@@ -687,10 +687,10 @@ grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char
}
}
chain = grub_malloc(size);
chain = ventoy_alloc_chain(size);
if (!chain)
{
grub_printf("Failed to alloc chain memory size %u\n", size);
grub_printf("Failed to alloc chain raw memory size %u\n", size);
grub_file_close(file);
return 1;
}

View File

@@ -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> <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
{
@@ -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);
@@ -1896,10 +1941,10 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
}
}
chain = grub_malloc(size);
chain = ventoy_alloc_chain(size);
if (!chain)
{
grub_printf("Failed to alloc chain memory size %u\n", size);
grub_printf("Failed to alloc chain win1 memory size %u\n", size);
grub_file_close(file);
return 1;
}
@@ -2129,10 +2174,10 @@ static grub_err_t ventoy_vlnk_wim_chain_data(grub_file_t wimfile)
}
}
chain = grub_malloc(size);
chain = ventoy_alloc_chain(size);
if (!chain)
{
grub_printf("Failed to alloc chain memory size %u\n", size);
grub_printf("Failed to alloc chain win2 memory size %u\n", size);
grub_file_close(file);
return 1;
}
@@ -2294,10 +2339,10 @@ static grub_err_t ventoy_normal_wim_chain_data(grub_file_t wimfile)
}
}
chain = grub_malloc(size);
chain = ventoy_alloc_chain(size);
if (!chain)
{
grub_printf("Failed to alloc chain memory size %u\n", size);
grub_printf("Failed to alloc chain win3 memory size %u\n", size);
grub_file_close(file);
return 1;
}

View 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;
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;

View File

@@ -0,0 +1,43 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
NEWROOT=$(grep switch_root /init | awk '{print $3}')
for i in 'usr/bin' 'usr/sbin'; do
if [ -f $NEWROOT/$i/udevadm ]; then
UPATH=$i
break
fi
done
blkdev_num=$(dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
sed "s#UPATH=.*#UPATH=/$UPATH#" -i /ventoy/hook/clear/udevadm
sed "s#DM=.*#DM=$vtDM#" -i /ventoy/hook/clear/udevadm
mv $NEWROOT/$UPATH/udevadm $NEWROOT/$UPATH/udevadm_bk
cp -a /ventoy/hook/clear/udevadm $NEWROOT/$UPATH/udevadm
chmod 777 $NEWROOT/$UPATH/udevadm

View File

@@ -0,0 +1,12 @@
#!/bin/bash
UPATH=/usr/bin
DM=dm-0
rm -f $UPATH/udevadm
mv $UPATH/udevadm_bk $UPATH/udevadm
echo 1 > /tmp/vthidden
mount --bind /tmp/vthidden /sys/block/$DM/hidden
exec $UPATH/udevadm "$@"

View File

@@ -26,3 +26,6 @@ else
echo "find_installer" >> $VTLOG
$SED "/\$.*find_installer/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/clear/disk-hook.sh" -i /init
fi
#issue 1674
$SED "/switch_root/i $BUSYBOX_PATH/sh $VTOY_PATH/hook/clear/hidden-hook.sh" -i /init

View File

@@ -19,6 +19,8 @@
. /ventoy/hook/ventoy-hook-lib.sh
/sbin/mdev -s
# Just for KVM test environment
$BUSYBOX_PATH/modprobe virtio_blk 2>/dev/null
$BUSYBOX_PATH/modprobe virtio_pci 2>/dev/null
@@ -34,3 +36,6 @@ for i in 0 1 2 3 4 5 6 7 8 9; do
done
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
$BUSYBOX_PATH/rm -f /dev/dm-*

View File

@@ -19,6 +19,6 @@
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "/mount_boot /i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
$SED "/mount_boot[^(]*$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/daphile/disk_hook.sh" -i /init
$SED "s#'\.\*/block/mmcblk[^ ]*'#'\.\*/block/dm-[0-9]*'#" -i /init

View File

@@ -34,3 +34,7 @@ fi
vtlog "${vtdiskname#/dev/}2 found..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2"
if [ -f /ventoy/autoinstall ]; then
sh /ventoy/hook/default/auto_install_varexp.sh /ventoy/autoinstall
fi

View File

@@ -44,10 +44,15 @@ if [ $vtSplit -eq 1 ]; then
vtlog "Line number: $vtLine $vtLine1 $vtLine2"
sed -n "1,${vtLine1}p" $VTOY_PATH/autoinstall >/tmpcidata/user-data
sed -n "${vtLine2},\$p" $VTOY_PATH/autoinstall >/tmpcidata/meta-data
sh /ventoy/hook/default/auto_install_varexp.sh /tmpcidata/user-data
sh /ventoy/hook/default/auto_install_varexp.sh /tmpcidata/meta-data
else
vtlog "only user-data avaliable"
cp -a $VTOY_PATH/autoinstall /tmpcidata/user-data
touch /tmpcidata/meta-data
sh /ventoy/hook/default/auto_install_varexp.sh /tmpcidata/user-data
fi

View File

@@ -0,0 +1,53 @@
#!/bin/sh
#************************************************************************************
# Copyright (c) 2022, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
PATH=$PATH:/ventoy/busybox:/ventoy/tool
vlog() {
echo "$@" >> /ventoy/autoinstall.log
}
if grep -q '\$\$VT_' /ventoy/autoinstall; then
vlog "======== auto install variables expansion ======="
else
vlog "======== auto install variables expansion no need ======="
exit 0
fi
if [ -f /ventoy/ventoy_os_param ]; then
VTOYDISK=$(vtoydump -f /ventoy/ventoy_os_param | awk -F'#' '{print $1}')
vlog VTOYDISK=$VTOYDISK
if [ -b "$VTOYDISK" ]; then
vlog "$VTOYDISK exist OK"
else
vlog "$VTOYDISK does NOT exist"
exit 0
fi
if [ -n "$1" -a -f "$1" ]; then
vtoyexpand "$1" "$VTOYDISK"
else
vlog "File $1 not exist"
fi
else
vlog "os param file not exist"
exit 0
fi

View File

@@ -29,10 +29,12 @@ ventoy_add_kernel_udev_rule "loop6" "$VTOY_PATH/hook/rhel6/udev_disk_hook.sh %k"
if [ -f $VTOY_PATH/autoinstall ]; then
$BUSYBOX_PATH/mv /sbin/loader /sbin/loader_bk
$BUSYBOX_PATH/mv $VTOY_PATH/tool/loader /sbin/loader
$BUSYBOX_PATH/cp -a $VTOY_PATH/tool/loader /sbin/loader
RawCmdLine=$($BUSYBOX_PATH/cat /proc/cmdline)
echo -n "/sbin/loader_bk" > "/ventoy/loader_exec_file"
echo -n "--cmdline=$RawCmdLine ks=file:$VTOY_PATH/autoinstall" > "/ventoy/loader_exec_cmdline"
#echo 111 > "/ventoy/loader_debug"
echo "/bin/sh /ventoy/hook/rhel6/ventoy-varexp.sh" > "/ventoy/loader_hook_cmd"
fi

View File

@@ -0,0 +1,37 @@
#!/bin/sh
#************************************************************************************
# Copyright (c) 2022, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
PATH=$PATH:/ventoy/busybox:/ventoy/tool
if grep -q '\$\$VT_' /ventoy/autoinstall; then
:
else
exit 0
fi
if [ -f /sbin/hald ]; then
mv /sbin/hald /sbin/hald_bk
cp -a /ventoy/tool/hald /sbin/hald
rm -f "/ventoy/loader_exec_cmdline"
echo "/bin/sh /ventoy/hook/default/auto_install_varexp.sh /ventoy/autoinstall" > "/ventoy/loader_hook_cmd"
echo -n "/sbin/hald_bk" > "/ventoy/loader_exec_file"
fi
exit 0

View File

@@ -0,0 +1,24 @@
#!/bin/sh
#************************************************************************************
# Copyright (c) 2022, longpanda <admin@ventoy.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#************************************************************************************
if [ -f /run/install/ks.cfg ]; then
sh /ventoy/hook/default/auto_install_varexp.sh /run/install/ks.cfg
fi
exit 0

View File

@@ -128,3 +128,6 @@ if [ -e /usr/sbin/anaconda-diskroot ]; then
$SED 's/^mount $dev $repodir/mount -oro $dev $repodir/' -i /usr/sbin/anaconda-diskroot
fi
if [ -f $VTOY_PATH/autoinstall ]; then
cp -a $VTOY_PATH/hook/rhel7/ventoy-autoexp.sh /lib/dracut/hooks/pre-mount/99-ventoy-autoexp.sh
fi

View File

@@ -40,3 +40,11 @@ fi
if $GREP -q 'mediacheck=1' /proc/cmdline; then
ventoy_copy_device_mapper "${vtdiskname}"
fi
if [ -f /ventoy/autoinstall ]; then
sh /ventoy/hook/default/auto_install_varexp.sh /ventoy/autoinstall
fi
if [ -f /autoinst.xml ]; then
sh /ventoy/hook/default/auto_install_varexp.sh /autoinst.xml
fi

View File

@@ -185,7 +185,7 @@ function locate_initrd {
}
function locate_wim {
vt_windows_locate_wim_patch (loop)
vt_windows_locate_wim_patch (loop) "$1"
if [ -n "${vtdebug_flag}" ]; then
echo '###############################################'
@@ -615,7 +615,7 @@ function uefi_windows_menu_func {
fi
ventoy_debug_pause
locate_wim
locate_wim "${chosen_path}"
fi
vt_windows_chain_data "${1}${chosen_path}"
@@ -1044,7 +1044,7 @@ function legacy_windows_menu_func {
fi
ventoy_debug_pause
locate_wim
locate_wim "${chosen_path}"
fi
vt_windows_chain_data "${1}${chosen_path}"
@@ -2145,7 +2145,7 @@ function img_unsupport_menuentry {
#############################################################
#############################################################
set VENTOY_VERSION="1.0.76"
set VENTOY_VERSION="1.0.77"
#ACPI not compatible with Window7/8, so disable by default
set VTOY_PARAM_NO_ACPI=1

Binary file not shown.

Binary file not shown.

View File

@@ -2359,61 +2359,61 @@
},
{
"name":"Bulgarian (Български)",
"FontFamily":"Courier New",
"FontFamily":"Segoe",
"FontSize":16,
"Author":"jekovcar",
"STR_ERROR":"Грешка",
"STR_WARNING":"Предупреждение",
"STR_INFO":"Информация",
"STR_INCORRECT_DIR":"Моля, стартирайте в друга директория!",
"STR_INCORRECT_TREE_DIR":"Не ме стартирайте оттук, моля, изтеглете инсталационен пакет и го стартирайте в друго място.",
"STR_INCORRECT_DIR":"Стартирайте от правилната папка!",
"STR_INCORRECT_TREE_DIR":"Не стартирайте оттук, изтеглете инсталационен пакет и стартирайте него.",
"STR_DEVICE":"Устройство",
"STR_LOCAL_VER":"Ventoy в пакета",
"STR_DISK_VER":"Ventoy на устройството",
"STR_STATUS":"Статус - ГОТОВ",
"STR_INSTALL":"Инсталирай",
"STR_UPDATE":"Обнови",
"STR_UPDATE_TIP":"Обновяването е безопасно, ISO-файловете няма да се променят.#@Продължаваме?",
"STR_INSTALL_TIP":"Диска ще се форматира и всички данни изтрият.#@Продължаваме?",
"STR_INSTALL_TIP2":"Диска ще се форматира и всички данни изтрият..#@ДЕЙСТВИТЕЛНО ще продължите?",
"STR_INSTALL_SUCCESS":"Поздрави!#@Ventoy бе успешно инсталиран на устройството.",
"STR_INSTALL_FAILED":"По време на инсталирането на Ventoy възникна грешка. Подсъединете устройството и опитайте отново. Проверете log.txt за грешки.",
"STR_UPDATE_SUCCESS":"Поздрави!#@Ventoy бе успешно обновен на устройството.",
"STR_UPDATE_FAILED":"По време на обновяването на Ventoy възникна грешка. Подсъединете устройството и опитайте отново. Проверете log.txt за грешки.",
"STR_WAIT_PROCESS":"Процеса е стартиран, моля изчакайте...",
"STR_MENU_OPTION":"Опции",
"STR_STATUS":"Състояние - В готовност",
"STR_INSTALL":"Инсталиране",
"STR_UPDATE":"Обновяване",
"STR_UPDATE_TIP":"Обновяването е безопасно, файловете на ISO няма да бъдат променени.#@Продължаване?",
"STR_INSTALL_TIP":"Устройството ще бъде форматирано, а всички данни - премахнати.#@Продължаване?",
"STR_INSTALL_TIP2":"Устройството ще бъде форматирано, а всички данни - премахнати.#@Продължаване? (повторно потвърждаване)",
"STR_INSTALL_SUCCESS":"Поздравления!#@Ventoy е успешно инсталиран на устройството.",
"STR_INSTALL_FAILED":"По време на инсталацията е възникнала грешка. Можете да поставите отново USB устройството и да опитате отново. Проверете log.txt за подробности. Ако инсталацията винаги е неуспешна, направете справка с често задаваните въпроси на официалната страница.",
"STR_UPDATE_SUCCESS":"Поздравление!#@Ventoy е успешно обновен на устройството.",
"STR_UPDATE_FAILED":"По време на обновяването е възникнала грешка. Можете да поставите отново USB устройството и да опитате отново. Проверете log.txt за подробности. Ако обновяването винаги е неуспешно, направете справка с често задаваните въпроси на официалната страница.",
"STR_WAIT_PROCESS":"Работи, моля изчакайте",
"STR_MENU_OPTION":"Настройки",
"STR_MENU_SECURE_BOOT":"Поддръжка на Secure Boot",
"STR_MENU_PART_CFG":"Допълнителен дял",
"STR_BTN_OK":"ОК",
"STR_BTN_OK":"Добре",
"STR_BTN_CANCEL":"Отказ",
"STR_PRESERVE_SPACE":"Създай Допълнителен дял в края на диска",
"STR_SPACE_VAL_INVALID":"Неправилен размер на дяла",
"STR_MENU_CLEAR":"Изтрий Ventoy",
"STR_CLEAR_SUCCESS":"Ventoy бе успешно изтрит от устройството.",
"STR_CLEAR_FAILED":"По време на изтриването на Ventoy възникна грешка. Подсъединете устройството и опитайте отново. Проверете log.txt за грешки.",
"STR_MENU_PART_STYLE":"Стил на оразмеряване на дяловете",
"STR_DISK_2TB_MBR_ERROR":"Моля, изберете GPT за дискове по-големи от 2ТБ",
"STR_SHOW_ALL_DEV":"Покажи всички устройства",
"STR_PART_ALIGN_4KB":"Подравни дяловете с размер 4КБ",
"STR_PRESERVE_SPACE":"Създаване на допълнителен дял в края на диска",
"STR_SPACE_VAL_INVALID":"Невярна стойност за запазено пространство",
"STR_MENU_CLEAR":"Премахване на Ventoy",
"STR_CLEAR_SUCCESS":"Ventoy е успешно премахнат от устройството.",
"STR_CLEAR_FAILED":"По време на премахването е възникнала грешка. Можете да поставите отново USB устройството и да опитате отново. Проверете log.txt за подробности.",
"STR_MENU_PART_STYLE":"Вид на дяловете",
"STR_DISK_2TB_MBR_ERROR":"Изберете GPT за устройства по-големи от 2ТБ",
"STR_SHOW_ALL_DEV":"Показване на всички устройства",
"STR_PART_ALIGN_4KB":"Подравняване на дяловете по 4КБ",
"STR_WEB_COMMUNICATION_ERR":"Грешка при свързване:",
"STR_WEB_REMOTE_ABNORMAL":"Грешка при свързване: Отдалечената връзка е недействителна",
"STR_WEB_REQUEST_TIMEOUT":"Грешка при свързване: Изтекло време за изчакване на заявката",
"STR_WEB_SERVICE_UNAVAILABLE":"Грешка при свързване: Службата е недостъпна",
"STR_WEB_TOKEN_MISMATCH":"Статуса на агента е обновен. Повторете по-късно.",
"STR_WEB_SERVICE_BUSY":"Службата е заета, Повторете по-късно.",
"STR_MENU_VTSI_CREATE":"Generate VTSI File",
"STR_VTSI_CREATE_TIP":"Сега няма да се записва на диска, само ще се генерира VTSI файл#@Продължаваме?",
"STR_VTSI_CREATE_SUCCESS":"VTSI файла бе създаден успешно!#@Може да използвате Rufus(3.15+) да го запишете на устройството за инсталацията с Ventoy.",
"STR_VTSI_CREATE_FAILED":"VTSI файла създаване се провали.",
"STR_MENU_PART_RESIZE":"Non-destructive Install",
"STR_PART_RESIZE_TIP":"Ventoy will try non-destructive installation if possible. #@Continue?",
"STR_PART_RESIZE_SUCCESS":"Congratulations!#@Ventoy non-destructive installation successfully finished.",
"STR_PART_RESIZE_FAILED":"Non-destructive installation failed, Check log.txt for details.",
"STR_PART_RESIZE_UNSUPPORTED":"Ventoy non-destructive installation stopped because some conditions cannot be met. Check log.txt for details.",
"STR_INSTALL_YES_TIP1":"Warning: Data will be lost!",
"STR_INSTALL_YES_TIP2":"Please enter YES in the text box below to confirm that you indeed want to do a fresh install instead of upgrade.",
"STR_WEB_SERVICE_UNAVAILABLE":"Грешка при свързване: Услугата е недостъпна",
"STR_WEB_TOKEN_MISMATCH":"Статуса на демона е обновен, опитайте по-късно.",
"STR_WEB_SERVICE_BUSY":"Услугата е заета, опитайте по-късно.",
"STR_MENU_VTSI_CREATE":"Създаване на файл на VTSI",
"STR_VTSI_CREATE_TIP":"Този път няма да се записва на устройството, а само ще се създаде файл на VTSI#@Продължаване?",
"STR_VTSI_CREATE_SUCCESS":"Файлът на VTSI е създаден успешно!#@Може да използвате Rufus(3.15+), за да го запишете на устройството и така да завършите инсталацията на Ventoy.",
"STR_VTSI_CREATE_FAILED":"Грешка при създаване на файла на VTSI.",
"STR_MENU_PART_RESIZE":"Неразрушително инсталиране",
"STR_PART_RESIZE_TIP":"Ventoy ще направи опит за неразрушително инсталиране, ако е възможно.#@Продължаване?",
"STR_PART_RESIZE_SUCCESS":"Поздравления!#@Неразрушителното инсталиране на Ventoy е успешно.",
"STR_PART_RESIZE_FAILED":"Неразрушителното инсталиране на Ventoy е неуспешно. Проверете log.txt за подробности.",
"STR_PART_RESIZE_UNSUPPORTED":"Неразрушителното инсталиране на Ventoy е спряна, защото някои от условията не могат да бъдат изпълнени. Проверете log.txt за подробности.",
"STR_INSTALL_YES_TIP1":"Внимание: Ще има загуба на данни!",
"STR_INSTALL_YES_TIP2":"Въведете „YES“ в полето отдолу, за да потвърдите, че искате да извършите нова инсталация вместо обновяване.",
"STRXXX":""
},
{

554
VtoyTool/vtoyexpand.c Normal file
View File

@@ -0,0 +1,554 @@
/******************************************************************************
* vtoyexpand.c ---- ventoy auto install script variable expansion
*
* Copyright (c) 2022, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/fs.h>
#include <dirent.h>
#include "vtoytool.h"
#ifndef O_BINARY
#define O_BINARY 0
#endif
#define TMP_FILE "/ventoy/tmp_var_expansion"
#define SIZE_1MB (1024 * 1024)
#define ulong unsigned long
#define ulonglong unsigned long long
typedef struct disk_info
{
char name[128];
ulonglong size;
int isUSB;
int isSDX;
}disk_info;
static disk_info *g_disk_list = NULL;
static int g_disk_num = 0;
static const char *g_vtoy_disk_name = NULL;
static void vlog(const char *fmt, ...)
{
int n = 0;
va_list arg;
FILE *fp = NULL;
char log[1024];
fp = fopen("/ventoy/autoinstall.log", "a+");
if (fp)
{
va_start(arg, fmt);
n += vsnprintf(log, sizeof(log) - 1, fmt, arg);
va_end(arg);
fwrite(log, 1, n, fp);
fclose(fp);
}
}
static int copy_file(const char *file1, const char *file2)
{
int n;
int size;
int ret = 1;
FILE *fp1 = NULL;
FILE *fp2 = NULL;
char *buf = NULL;
fp1 = fopen(file1, "rb");
if (!fp1)
{
vlog("Failed to read file <%s>\n", file1);
goto end;
}
fp2 = fopen(file2, "wb+");
if (!fp2)
{
vlog("Failed to create file <%s>\n", file2);
goto end;
}
fseek(fp1, 0, SEEK_END);
size = (int)ftell(fp1);
fseek(fp1, 0, SEEK_SET);
buf = malloc(size);
if (!buf)
{
vlog("Failed to malloc buf\n");
goto end;
}
n = fread(buf, 1, size, fp1);
if (n != size)
{
vlog("Failed to read <%s> %d %d\n", file1, n, size);
goto end;
}
n = fwrite(buf, 1, size, fp2);
if (n != size)
{
vlog("Failed to write <%s> %d %d\n", file2, n, size);
goto end;
}
ret = 0;
end:
if (fp1)
fclose(fp1);
if (fp2)
fclose(fp2);
if (buf)
free(buf);
return ret;
}
static int vtoy_is_possible_blkdev(const char *name)
{
if (name[0] == '.')
{
return 0;
}
/* /dev/ramX */
if (name[0] == 'r' && name[1] == 'a' && name[2] == 'm')
{
return 0;
}
/* /dev/loopX */
if (name[0] == 'l' && name[1] == 'o' && name[2] == 'o' && name[3] == 'p')
{
return 0;
}
/* /dev/dm-X */
if (name[0] == 'd' && name[1] == 'm' && name[2] == '-' && IS_DIGIT(name[3]))
{
return 0;
}
/* /dev/srX */
if (name[0] == 's' && name[1] == 'r' && (name[2] >= '0' && name[2] <= '9'))
{
return 0;
}
return 1;
}
static ulonglong vtoy_get_disk_size_in_byte(const char *disk)
{
int fd;
int rc;
unsigned long long size = 0;
char diskpath[256] = {0};
char sizebuf[64] = {0};
// Try 1: get size from sysfs
snprintf(diskpath, sizeof(diskpath) - 1, "/sys/block/%s/size", disk);
if (access(diskpath, F_OK) >= 0)
{
vlog("get disk size from sysfs for %s\n", disk);
fd = open(diskpath, O_RDONLY | O_BINARY);
if (fd >= 0)
{
read(fd, sizebuf, sizeof(sizebuf));
size = strtoull(sizebuf, NULL, 10);
close(fd);
return (size * 512);
}
}
else
{
vlog("%s not exist \n", diskpath);
}
// Try 2: get size from ioctl
snprintf(diskpath, sizeof(diskpath) - 1, "/dev/%s", disk);
fd = open(diskpath, O_RDONLY);
if (fd >= 0)
{
vlog("get disk size from ioctl for %s\n", disk);
rc = ioctl(fd, BLKGETSIZE64, &size);
if (rc == -1)
{
size = 0;
vlog("failed to ioctl %d\n", rc);
}
close(fd);
}
else
{
vlog("failed to open %s %d\n", diskpath, errno);
}
vlog("disk %s size %llu bytes\n", disk, (ulonglong)size);
return size;
}
static int get_disk_num(void)
{
int n = 0;
DIR* dir = NULL;
struct dirent* p = NULL;
dir = opendir("/sys/block");
if (!dir)
{
return 0;
}
while ((p = readdir(dir)) != NULL)
{
n++;
}
closedir(dir);
return n;
}
static int is_usb_disk(const char *diskname)
{
int rc;
char dstpath[1024] = { 0 };
char syspath[1024] = { 0 };
snprintf(syspath, sizeof(syspath), "/sys/block/%s", diskname);
rc = readlink(syspath, dstpath, sizeof(dstpath) - 1);
if (rc > 0 && strstr(dstpath, "/usb"))
{
return 1;
}
return 0;
}
static int get_all_disk(void)
{
int i = 0;
int j = 0;
int num = 0;
ulonglong cursize = 0;
DIR* dir = NULL;
struct dirent* p = NULL;
disk_info *node = NULL;
disk_info tmpnode;
num = get_disk_num();
if (num <= 0)
{
return 1;
}
g_disk_list = malloc(num * sizeof(disk_info));
if (!g_disk_list)
{
return 1;
}
memset(g_disk_list, 0, num * sizeof(disk_info));
dir = opendir("/sys/block");
if (!dir)
{
return 0;
}
while (((p = readdir(dir)) != NULL) && g_disk_num < num)
{
if (!vtoy_is_possible_blkdev(p->d_name))
{
vlog("disk %s is filted by name\n", p->d_name);
continue;
}
cursize = vtoy_get_disk_size_in_byte(p->d_name);
node = g_disk_list + g_disk_num;
g_disk_num++;
snprintf(node->name, sizeof(node->name), p->d_name);
node->size = cursize;
node->isUSB = is_usb_disk(p->d_name);
if (strncmp(node->name, "sd", 2) == 0)
{
node->isSDX = 1;
}
}
closedir(dir);
/* sort disks */
for (i = 0; i < g_disk_num; i++)
{
for (j = i + 1; j < g_disk_num; j++)
{
if (g_disk_list[i].isSDX && g_disk_list[j].isSDX)
{
if (strcmp(g_disk_list[i].name, g_disk_list[j].name) > 0)
{
memcpy(&tmpnode, g_disk_list + i, sizeof(tmpnode));
memcpy(g_disk_list + i, g_disk_list + j, sizeof(tmpnode));
memcpy(g_disk_list + j, &tmpnode, sizeof(tmpnode));
}
}
}
}
vlog("============ DISK DUMP BEGIN ===========\n");
for (i = 0; i < g_disk_num; i++)
{
node = g_disk_list + i;
vlog("[%d] %s %dGB(%llu) USB:%d\n", i, node->name,
node->size / 1024 / 1024 / 1024, node->size, node->isUSB);
}
vlog("============ DISK DUMP END ===========\n");
return 0;
}
static int expand_var(const char *var, char *value, int len)
{
int i;
int index = -1;
ulonglong uiDst = 0;
ulonglong delta = 0;
ulonglong maxsize = 0;
ulonglong maxdelta = 0xFFFFFFFFFFFFFFFFULL;
disk_info *node = NULL;
value[0] = 0;
if (strcmp(var, "VT_LINUX_DISK_SDX_1ST_NONVTOY") == 0)
{
for (i = 0; i < g_disk_num; i++)
{
node = g_disk_list + i;
if (node->size > 0 && node->isSDX && strcmp(node->name, g_vtoy_disk_name) != 0)
{
vlog("%s=<%s>\n", var, node->name);
snprintf(value, len, "%s", node->name);
return 0;
}
}
vlog("[Error] %s not found\n", var);
}
else if (strcmp(var, "VT_LINUX_DISK_SDX_1ST_NONUSB") == 0)
{
for (i = 0; i < g_disk_num; i++)
{
node = g_disk_list + i;
if (node->size > 0 && node->isSDX && node->isUSB == 0)
{
vlog("%s=<%s>\n", var, node->name);
snprintf(value, len, "%s", node->name);
return 0;
}
}
vlog("[Error] %s not found\n", var);
}
else if (strcmp(var, "VT_LINUX_DISK_MAX_SIZE") == 0)
{
for (i = 0; i < g_disk_num; i++)
{
node = g_disk_list + i;
if (node->size > 0 && node->size > maxsize)
{
index = i;
maxsize = node->size;
}
}
if (index >= 0)
{
vlog("%s=<%s>\n", var, g_disk_list[index].name);
snprintf(value, len, "%s", g_disk_list[index].name);
return 0;
}
else
{
vlog("[Error] %s not found\n", var);
}
}
else if (strncmp(var, "VT_LINUX_DISK_CLOSEST_", 22) == 0)
{
uiDst = strtoul(var + 22, NULL, 10);
uiDst = uiDst * (1024ULL * 1024ULL * 1024ULL);
for (i = 0; i < g_disk_num; i++)
{
node = g_disk_list + i;
if (node->size == 0)
{
continue;
}
if (node->size > uiDst)
{
delta = node->size - uiDst;
}
else
{
delta = uiDst - node->size;
}
if (delta < maxdelta)
{
index = i;
maxdelta = delta;
}
}
if (index >= 0)
{
vlog("%s=<%s>\n", var, g_disk_list[index].name);
snprintf(value, len, "%s", g_disk_list[index].name);
return 0;
}
else
{
vlog("[Error] %s not found\n", var);
}
}
else
{
vlog("Invalid var name <%s>\n", var);
snprintf(value, len, "$$%s$$", var);
}
if (value[0] == 0)
{
snprintf(value, len, "$$%s$$", var);
}
return 0;
}
int vtoyexpand_main(int argc, char **argv)
{
FILE *fp = NULL;
FILE *fout = NULL;
char *start = NULL;
char *end = NULL;
char line[4096];
char value[256];
vlog("========= vtoyexpand_main %d ========\n", argc);
if (argc != 3)
{
return 1;
}
g_vtoy_disk_name = argv[2];
if (strncmp(g_vtoy_disk_name, "/dev/", 5) == 0)
{
g_vtoy_disk_name += 5;
}
vlog("<%s> <%s> <%s>\n", argv[1], argv[2], g_vtoy_disk_name);
get_all_disk();
fp = fopen(argv[1], "r");
if (!fp)
{
vlog("Failed to open file <%s>\n", argv[1]);
return 1;
}
fout = fopen(TMP_FILE, "w+");
if (!fout)
{
vlog("Failed to create file <%s>\n", TMP_FILE);
fclose(fp);
return 1;
}
memset(line, 0, sizeof(line));
memset(value, 0, sizeof(value));
while (fgets(line, sizeof(line), fp))
{
start = strstr(line, "$$VT_");
if (start)
{
end = strstr(start + 5, "$$");
}
if (start && end)
{
*start = 0;
fprintf(fout, "%s", line);
*end = 0;
expand_var(start + 2, value, sizeof(value));
fprintf(fout, "%s", value);
fprintf(fout, "%s", end + 2);
memset(value, 0, sizeof(value));
}
else
{
fprintf(fout, "%s", line);
}
line[0] = line[4095] = 0;
}
fclose(fp);
fclose(fout);
vlog("delete file <%s>\n", argv[1]);
remove(argv[1]);
vlog("Copy file <%s> --> <%s>\n", TMP_FILE, argv[1]);
copy_file(TMP_FILE, argv[1]);
return 0;
}
// wrapper main
#ifndef BUILD_VTOY_TOOL
int main(int argc, char **argv)
{
return vtoyexpand_main(argc, argv);
}
#endif

View File

@@ -91,10 +91,6 @@ int vtoyloader_main(int argc, char **argv)
{
rc = vtoy_read_file_to_buf(HOOK_CMD_FILE, g_hook_cmd, sizeof(g_hook_cmd) - 1);
debug("g_hook_cmd=<%s>\n", g_hook_cmd);
// call hook script
rc = system(g_hook_cmd);
debug("system return code =<%d> errno=<%d>\n", rc, errno);
}
cmdline = (char *)malloc(CMDLINE_BUF_LEN);
@@ -156,6 +152,13 @@ int vtoyloader_main(int argc, char **argv)
debug("execv [%s]...\n", cmdlist[0]);
// call hook script
if (g_hook_cmd[0])
{
rc = system(g_hook_cmd);
debug("system return code =<%d> errno=<%d>\n", rc, errno);
}
execv(cmdlist[0], cmdlist);
return 0;

View File

@@ -38,6 +38,7 @@ int vtoyloader_main(int argc, char **argv);
int vtoyvine_main(int argc, char **argv);
int vtoyksym_main(int argc, char **argv);
int vtoykmod_main(int argc, char **argv);
int vtoyexpand_main(int argc, char **argv);
static char *g_vtoytool_name = NULL;
static cmd_def g_cmd_list[] =
@@ -46,8 +47,10 @@ static cmd_def g_cmd_list[] =
{ "vtoydump", vtoydump_main },
{ "vtoydm", vtoydm_main },
{ "loader", vtoyloader_main },
{ "hald", vtoyloader_main },
{ "vtoyksym", vtoyksym_main },
{ "vtoykmod", vtoykmod_main },
{ "vtoyexpand", vtoyexpand_main },
{ "--install", vtoytool_install },
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -36,6 +36,8 @@ static ventoy_guid g_ventoy_guid = VENTOY_GUID;
static HANDLE g_vtoylog_mutex = NULL;
static HANDLE g_vtoyins_mutex = NULL;
static DWORD g_vtoy_disk_drive;
static CHAR g_prog_full_path[MAX_PATH];
static CHAR g_prog_dir[MAX_PATH];
static CHAR g_prog_name[MAX_PATH];
@@ -47,6 +49,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 +259,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')
{
@@ -742,7 +762,7 @@ static int VentoyFatDiskRead(uint32 Sector, uint8 *Buffer, uint32 SectorCount)
bRet = ReadFile(g_FatPhyDrive, Buffer, ReadSize, &dwSize, NULL);
if (bRet == FALSE || dwSize != ReadSize)
{
Log("ReadFile error bRet:%u WriteSize:%u dwSize:%u ErrCode:%u\n", bRet, ReadSize, dwSize, GetLastError());
Log("ReadFile error bRet:%u WriteSize:%u dwSize:%u ErrCode:%u", bRet, ReadSize, dwSize, GetLastError());
}
return 1;
@@ -1273,12 +1293,485 @@ End:
return rc;
}
static int UnattendNeedVarExpand(const char *script)
{
FILE *fp = NULL;
char szLine[4096];
fopen_s(&fp, script, "r");
if (!fp)
{
return 0;
}
szLine[0] = szLine[4095] = 0;
while (fgets(szLine, sizeof(szLine) - 1, fp))
{
if (strstr(szLine, "$$VT_"))
{
fclose(fp);
return 1;
}
szLine[0] = szLine[4095] = 0;
}
fclose(fp);
return 0;
}
static int ExpandSingleVar(VarDiskInfo *pDiskInfo, int DiskNum, const char *var, char *value, int len)
{
int i;
int index = -1;
UINT64 uiDst = 0;
UINT64 uiDelta = 0;
UINT64 uiMaxSize = 0;
UINT64 uiMaxDelta = ULLONG_MAX;
value[0] = 0;
if (strcmp(var, "VT_WINDOWS_DISK_1ST_NONVTOY") == 0)
{
for (i = 0; i < DiskNum; i++)
{
if (pDiskInfo[i].Capacity > 0 && i != g_vtoy_disk_drive)
{
Log("%s=<PhyDrive%d>", var, i);
sprintf_s(value, len, "%d", i);
return 0;
}
}
}
else if (strcmp(var, "VT_WINDOWS_DISK_1ST_NONUSB") == 0)
{
for (i = 0; i < DiskNum; i++)
{
if (pDiskInfo[i].Capacity > 0 && pDiskInfo[i].BusType != BusTypeUsb)
{
Log("%s=<PhyDrive%d>", var, i);
sprintf_s(value, len, "%d", i);
return 0;
}
}
}
else if (strcmp(var, "VT_WINDOWS_DISK_MAX_SIZE") == 0)
{
for (i = 0; i < DiskNum; i++)
{
if (pDiskInfo[i].Capacity > 0 && pDiskInfo[i].Capacity > uiMaxSize)
{
index = i;
uiMaxSize = pDiskInfo[i].Capacity;
}
}
Log("%s=<PhyDrive%d>", var, index);
sprintf_s(value, len, "%d", index);
}
else if (strncmp(var, "VT_WINDOWS_DISK_CLOSEST_", 24) == 0)
{
uiDst = strtoul(var + 24, NULL, 10);
uiDst = uiDst * (1024ULL * 1024ULL * 1024ULL);
for (i = 0; i < DiskNum; i++)
{
if (pDiskInfo[i].Capacity == 0)
{
continue;
}
if (pDiskInfo[i].Capacity > uiDst)
{
uiDelta = pDiskInfo[i].Capacity - uiDst;
}
else
{
uiDelta = uiDst - pDiskInfo[i].Capacity;
}
if (uiDelta < uiMaxDelta)
{
uiMaxDelta = uiDelta;
index = i;
}
}
Log("%s=<PhyDrive%d>", var, index);
sprintf_s(value, len, "%d", index);
}
else
{
Log("Invalid var name <%s>", var);
sprintf_s(value, len, "$$%s$$", var);
}
if (value[0] == 0)
{
sprintf_s(value, len, "$$%s$$", var);
}
return 0;
}
static void TrimString(CHAR *String)
{
CHAR *Pos1 = String;
CHAR *Pos2 = String;
size_t Len = strlen(String);
while (Len > 0)
{
if (String[Len - 1] != ' ' && String[Len - 1] != '\t')
{
break;
}
String[Len - 1] = 0;
Len--;
}
while (*Pos1 == ' ' || *Pos1 == '\t')
{
Pos1++;
}
while (*Pos1)
{
*Pos2++ = *Pos1++;
}
*Pos2++ = 0;
return;
}
static int GetRegDwordValue(HKEY Key, LPCSTR SubKey, LPCSTR ValueName, DWORD *pValue)
{
HKEY hKey;
DWORD Type;
DWORD Size;
LSTATUS lRet;
DWORD Value;
lRet = RegOpenKeyExA(Key, SubKey, 0, KEY_QUERY_VALUE, &hKey);
Log("RegOpenKeyExA <%s> Ret:%ld", SubKey, lRet);
if (ERROR_SUCCESS == lRet)
{
Size = sizeof(Value);
lRet = RegQueryValueExA(hKey, ValueName, NULL, &Type, (LPBYTE)&Value, &Size);
Log("RegQueryValueExA <%s> ret:%u Size:%u Value:%u", ValueName, lRet, Size, Value);
*pValue = Value;
RegCloseKey(hKey);
return 0;
}
else
{
return 1;
}
}
static const CHAR * GetBusTypeString(int Type)
{
switch (Type)
{
case BusTypeUnknown: return "unknown";
case BusTypeScsi: return "SCSI";
case BusTypeAtapi: return "Atapi";
case BusTypeAta: return "ATA";
case BusType1394: return "1394";
case BusTypeSsa: return "SSA";
case BusTypeFibre: return "Fibre";
case BusTypeUsb: return "USB";
case BusTypeRAID: return "RAID";
case BusTypeiScsi: return "iSCSI";
case BusTypeSas: return "SAS";
case BusTypeSata: return "SATA";
case BusTypeSd: return "SD";
case BusTypeMmc: return "MMC";
case BusTypeVirtual: return "Virtual";
case BusTypeFileBackedVirtual: return "FileBackedVirtual";
case BusTypeSpaces: return "Spaces";
case BusTypeNvme: return "Nvme";
}
return "unknown";
}
static int GetHumanReadableGBSize(UINT64 SizeBytes)
{
int i;
int Pow2 = 1;
double Delta;
double GB = SizeBytes * 1.0 / 1000 / 1000 / 1000;
if ((SizeBytes % 1073741824) == 0)
{
return (int)(SizeBytes / 1073741824);
}
for (i = 0; i < 12; i++)
{
if (Pow2 > GB)
{
Delta = (Pow2 - GB) / Pow2;
}
else
{
Delta = (GB - Pow2) / Pow2;
}
if (Delta < 0.05)
{
return Pow2;
}
Pow2 <<= 1;
}
return (int)GB;
}
static int EnumerateAllDisk(VarDiskInfo **ppDiskInfo, int *pDiskNum)
{
int i;
DWORD Value;
int DiskNum = 0;
BOOL bRet;
DWORD dwBytes;
VarDiskInfo *pDiskInfo = NULL;
HANDLE Handle = INVALID_HANDLE_VALUE;
CHAR PhyDrive[128];
GET_LENGTH_INFORMATION LengthInfo;
STORAGE_PROPERTY_QUERY Query;
STORAGE_DESCRIPTOR_HEADER DevDescHeader;
STORAGE_DEVICE_DESCRIPTOR *pDevDesc;
if (GetRegDwordValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\disk\\Enum", "Count", &Value) == 0)
{
DiskNum = (int)Value;
}
else
{
Log("Failed to read disk count");
return 1;
}
Log("Current phy disk count:%d", DiskNum);
if (DiskNum <= 0)
{
return 1;
}
pDiskInfo = malloc(DiskNum * sizeof(VarDiskInfo));
if (!pDiskInfo)
{
Log("Failed to alloc");
return 1;
}
memset(pDiskInfo, 0, DiskNum * sizeof(VarDiskInfo));
for (i = 0; i < DiskNum; i++)
{
SAFE_CLOSE_HANDLE(Handle);
safe_sprintf(PhyDrive, "\\\\.\\PhysicalDrive%d", i);
Handle = CreateFileA(PhyDrive, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
Log("Create file Handle:%p %s status:%u", Handle, PhyDrive, LASTERR);
if (Handle == INVALID_HANDLE_VALUE)
{
continue;
}
bRet = DeviceIoControl(Handle,
IOCTL_DISK_GET_LENGTH_INFO, NULL,
0,
&LengthInfo,
sizeof(LengthInfo),
&dwBytes,
NULL);
if (!bRet)
{
Log("DeviceIoControl IOCTL_DISK_GET_LENGTH_INFO failed error:%u", LASTERR);
continue;
}
Log("PHYSICALDRIVE%d size %llu bytes", i, (ULONGLONG)LengthInfo.Length.QuadPart);
Query.PropertyId = StorageDeviceProperty;
Query.QueryType = PropertyStandardQuery;
bRet = DeviceIoControl(Handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&Query,
sizeof(Query),
&DevDescHeader,
sizeof(STORAGE_DESCRIPTOR_HEADER),
&dwBytes,
NULL);
if (!bRet)
{
Log("DeviceIoControl1 error:%u dwBytes:%u", LASTERR, dwBytes);
continue;
}
if (DevDescHeader.Size < sizeof(STORAGE_DEVICE_DESCRIPTOR))
{
Log("Invalid DevDescHeader.Size:%u", DevDescHeader.Size);
continue;
}
pDevDesc = (STORAGE_DEVICE_DESCRIPTOR *)malloc(DevDescHeader.Size);
if (!pDevDesc)
{
Log("failed to malloc error:%u len:%u", LASTERR, DevDescHeader.Size);
continue;
}
bRet = DeviceIoControl(Handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&Query,
sizeof(Query),
pDevDesc,
DevDescHeader.Size,
&dwBytes,
NULL);
if (!bRet)
{
Log("DeviceIoControl2 error:%u dwBytes:%u", LASTERR, dwBytes);
free(pDevDesc);
continue;
}
pDiskInfo[i].RemovableMedia = pDevDesc->RemovableMedia;
pDiskInfo[i].BusType = pDevDesc->BusType;
pDiskInfo[i].DeviceType = pDevDesc->DeviceType;
pDiskInfo[i].Capacity = LengthInfo.Length.QuadPart;
if (pDevDesc->VendorIdOffset)
{
safe_strcpy(pDiskInfo[i].VendorId, (char *)pDevDesc + pDevDesc->VendorIdOffset);
TrimString(pDiskInfo[i].VendorId);
}
if (pDevDesc->ProductIdOffset)
{
safe_strcpy(pDiskInfo[i].ProductId, (char *)pDevDesc + pDevDesc->ProductIdOffset);
TrimString(pDiskInfo[i].ProductId);
}
if (pDevDesc->ProductRevisionOffset)
{
safe_strcpy(pDiskInfo[i].ProductRev, (char *)pDevDesc + pDevDesc->ProductRevisionOffset);
TrimString(pDiskInfo[i].ProductRev);
}
if (pDevDesc->SerialNumberOffset)
{
safe_strcpy(pDiskInfo[i].SerialNumber, (char *)pDevDesc + pDevDesc->SerialNumberOffset);
TrimString(pDiskInfo[i].SerialNumber);
}
free(pDevDesc);
SAFE_CLOSE_HANDLE(Handle);
}
Log("########## DUMP DISK BEGIN ##########");
for (i = 0; i < DiskNum; i++)
{
Log("PhyDrv:%d BusType:%-4s Removable:%u Size:%dGB(%llu) Name:%s %s",
i, GetBusTypeString(pDiskInfo[i].BusType), pDiskInfo[i].RemovableMedia,
GetHumanReadableGBSize(pDiskInfo[i].Capacity), pDiskInfo[i].Capacity,
pDiskInfo[i].VendorId, pDiskInfo[i].ProductId);
}
Log("Ventoy disk is PhyDvr%d", g_vtoy_disk_drive);
Log("########## DUMP DISK END ##########");
*ppDiskInfo = pDiskInfo;
*pDiskNum = DiskNum;
return 0;
}
static int UnattendVarExpand(const char *script, const char *tmpfile)
{
FILE *fp = NULL;
FILE *fout = NULL;
char *start = NULL;
char *end = NULL;
char szLine[4096];
char szValue[256];
int DiskNum = 0;
VarDiskInfo *pDiskInfo = NULL;
Log("UnattendVarExpand ...");
if (EnumerateAllDisk(&pDiskInfo, &DiskNum))
{
Log("Failed to EnumerateAllDisk");
return 1;
}
fopen_s(&fp, script, "r");
if (!fp)
{
free(pDiskInfo);
return 0;
}
fopen_s(&fout, tmpfile, "w+");
if (!fout)
{
fclose(fp);
free(pDiskInfo);
return 0;
}
szLine[0] = szLine[4095] = 0;
while (fgets(szLine, sizeof(szLine) - 1, fp))
{
start = strstr(szLine, "$$VT_");
if (start)
{
end = strstr(start + 5, "$$");
}
if (start && end)
{
*start = 0;
fprintf(fout, "%s", szLine);
*end = 0;
ExpandSingleVar(pDiskInfo, DiskNum, start + 2, szValue, sizeof(szValue) - 1);
fprintf(fout, "%s", szValue);
fprintf(fout, "%s", end + 2);
}
else
{
fprintf(fout, "%s", szLine);
}
szLine[0] = szLine[4095] = 0;
}
fclose(fp);
fclose(fout);
free(pDiskInfo);
return 0;
}
//#define VAR_DEBUG 1
static int ProcessUnattendedInstallation(const char *script)
{
DWORD dw;
HKEY hKey;
LSTATUS Ret;
CHAR Letter;
CHAR TmpFile[MAX_PATH];
CHAR CurDir[MAX_PATH];
Log("Copy unattended XML ...");
@@ -1293,16 +1786,34 @@ static int ProcessUnattendedInstallation(const char *script)
{
Letter = 'X';
}
sprintf_s(CurDir, sizeof(CurDir), "%C:\\Autounattend.xml", Letter);
Log("Copy file <%s> --> <%s>", script, CurDir);
CopyFile(script, CurDir, FALSE);
#ifdef VAR_DEBUG
sprintf_s(CurDir, sizeof(CurDir), "%C:\\AutounattendXXX.xml", Letter);
#else
sprintf_s(CurDir, sizeof(CurDir), "%C:\\Autounattend.xml", Letter);
#endif
if (UnattendNeedVarExpand(script))
{
sprintf_s(TmpFile, sizeof(TmpFile), "%C:\\__Autounattend", Letter);
UnattendVarExpand(script, TmpFile);
Log("Expand Copy file <%s> --> <%s>", script, CurDir);
CopyFile(TmpFile, CurDir, FALSE);
}
else
{
Log("No var expand copy file <%s> --> <%s>", script, CurDir);
CopyFile(script, CurDir, FALSE);
}
#ifndef VAR_DEBUG
Ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "System\\Setup", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw);
if (ERROR_SUCCESS == Ret)
{
Ret = RegSetValueEx(hKey, "UnattendFile", 0, REG_SZ, CurDir, (DWORD)(strlen(CurDir) + 1));
}
#endif
return 0;
}
@@ -1475,7 +1986,7 @@ static int VentoyHook(ventoy_os_param *param)
if (IsUTF8Encode(param->vtoy_img_path))
{
Log("This file is UTF8 encoding\n");
Log("This file is UTF8 encoding");
}
for (i = 0; i < 5; i++)
@@ -1604,6 +2115,8 @@ static int VentoyHook(ventoy_os_param *param)
return 1;
}
g_vtoy_disk_drive = VtoyDiskNum;
Drives = GetLogicalDrives();
Log("Drives before mount: 0x%x", Drives);
@@ -1647,11 +2160,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 +2236,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 +2272,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 +2332,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 +2368,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 +2392,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);

View File

@@ -1,29 +1,29 @@
/******************************************************************************
* vtoyjump.h
*
* Copyright (c) 2020, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __VTOYJUMP_H__
#define __VTOYJUMP_H__
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#define SIZE_1MB (1024 * 1024)
#define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
/******************************************************************************
* vtoyjump.h
*
* Copyright (c) 2020, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __VTOYJUMP_H__
#define __VTOYJUMP_H__
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#define SIZE_1MB (1024 * 1024)
#define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
@@ -67,98 +67,124 @@ typedef struct ventoy_os_param
UINT8 reserved[27];
}ventoy_os_param;
typedef struct ventoy_windows_data
{
char auto_install_script[384];
char injection_archive[384];
UINT8 windows11_bypass_check;
UINT8 reserved[255];
typedef struct ventoy_windows_data
{
char auto_install_script[384];
char injection_archive[384];
UINT8 windows11_bypass_check;
UINT32 auto_install_len;
UINT8 reserved[255 - 4];
/* auto install script file data ... + auto_install_len */
/* ...... */
}ventoy_windows_data;
typedef struct PART_TABLE
{
UINT8 Active; // 0x00 0x80
UINT8 StartHead;
UINT16 StartSector : 6;
UINT16 StartCylinder : 10;
UINT8 FsFlag;
UINT8 EndHead;
UINT16 EndSector : 6;
UINT16 EndCylinder : 10;
UINT32 StartSectorId;
UINT32 SectorCount;
}PART_TABLE;
typedef struct MBR_HEAD
{
UINT8 BootCode[446];
PART_TABLE PartTbl[4];
UINT8 Byte55;
UINT8 ByteAA;
}MBR_HEAD;
typedef struct VTOY_GPT_HDR
{
CHAR Signature[8]; /* EFI PART */
UINT8 Version[4];
UINT32 Length;
UINT32 Crc;
UINT8 Reserved1[4];
UINT64 EfiStartLBA;
UINT64 EfiBackupLBA;
UINT64 PartAreaStartLBA;
UINT64 PartAreaEndLBA;
GUID DiskGuid;
UINT64 PartTblStartLBA;
UINT32 PartTblTotNum;
UINT32 PartTblEntryLen;
UINT32 PartTblCrc;
UINT8 Reserved2[420];
}VTOY_GPT_HDR;
typedef struct VTOY_GPT_PART_TBL
{
GUID PartType;
GUID PartGuid;
UINT64 StartLBA;
UINT64 LastLBA;
UINT64 Attr;
UINT16 Name[36];
}VTOY_GPT_PART_TBL;
typedef struct VTOY_GPT_INFO
{
MBR_HEAD MBR;
VTOY_GPT_HDR Head;
VTOY_GPT_PART_TBL PartTbl[128];
}VTOY_GPT_INFO;
typedef struct PART_TABLE
{
UINT8 Active; // 0x00 0x80
UINT8 StartHead;
UINT16 StartSector : 6;
UINT16 StartCylinder : 10;
UINT8 FsFlag;
UINT8 EndHead;
UINT16 EndSector : 6;
UINT16 EndCylinder : 10;
UINT32 StartSectorId;
UINT32 SectorCount;
}PART_TABLE;
typedef struct MBR_HEAD
{
UINT8 BootCode[446];
PART_TABLE PartTbl[4];
UINT8 Byte55;
UINT8 ByteAA;
}MBR_HEAD;
typedef struct VTOY_GPT_HDR
{
CHAR Signature[8]; /* EFI PART */
UINT8 Version[4];
UINT32 Length;
UINT32 Crc;
UINT8 Reserved1[4];
UINT64 EfiStartLBA;
UINT64 EfiBackupLBA;
UINT64 PartAreaStartLBA;
UINT64 PartAreaEndLBA;
GUID DiskGuid;
UINT64 PartTblStartLBA;
UINT32 PartTblTotNum;
UINT32 PartTblEntryLen;
UINT32 PartTblCrc;
UINT8 Reserved2[420];
}VTOY_GPT_HDR;
typedef struct VTOY_GPT_PART_TBL
{
GUID PartType;
GUID PartGuid;
UINT64 StartLBA;
UINT64 LastLBA;
UINT64 Attr;
UINT16 Name[36];
}VTOY_GPT_PART_TBL;
typedef struct VTOY_GPT_INFO
{
MBR_HEAD MBR;
VTOY_GPT_HDR Head;
VTOY_GPT_PART_TBL PartTbl[128];
}VTOY_GPT_INFO;
#pragma pack()
#define SAFE_CLOSE_HANDLE(handle) \
{\
if (handle != INVALID_HANDLE_VALUE) \
{\
CloseHandle(handle); \
(handle) = INVALID_HANDLE_VALUE; \
}\
}
#define LASTERR GetLastError()
int unxz(unsigned char *in, int in_size,
int(*fill)(void *dest, unsigned int size),
int(*flush)(void *src, unsigned int size),
unsigned char *out, int *in_used,
void(*error)(char *x));
#endif
typedef struct VarDiskInfo
{
UINT64 Capacity;
int BusType;
BOOL RemovableMedia;
BYTE DeviceType;
CHAR VendorId[128];
CHAR ProductId[128];
CHAR ProductRev[128];
CHAR SerialNumber[128];
}VarDiskInfo;
#define SAFE_CLOSE_HANDLE(handle) \
{\
if (handle != INVALID_HANDLE_VALUE) \
{\
CloseHandle(handle); \
(handle) = INVALID_HANDLE_VALUE; \
}\
}
#define safe_sprintf(dst, fmt, ...) sprintf_s(dst, sizeof(dst), fmt, __VA_ARGS__)
#define safe_strcpy(dst, src) strcpy_s(dst, sizeof(dst), src)
#define LASTERR GetLastError()
int unxz(unsigned char *in, int in_size,
int(*fill)(void *dest, unsigned int size),
int(*flush)(void *src, unsigned int size),
unsigned char *out, int *in_used,
void(*error)(char *x));
#endif