mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-08-28 08:21:14 +00:00
IA32 ARM64 support
This commit is contained in:
@@ -41,7 +41,6 @@
|
||||
#include <grub/time.h>
|
||||
#include <grub/video.h>
|
||||
#include <grub/acpi.h>
|
||||
#include <grub/relocator.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/ventoy.h>
|
||||
#include "ventoy_def.h"
|
||||
@@ -97,6 +96,7 @@ char *g_wimiso_path = NULL;
|
||||
int g_vhdboot_enable = 0;
|
||||
|
||||
grub_uint64_t g_conf_replace_offset = 0;
|
||||
grub_uint64_t g_svd_replace_offset = 0;
|
||||
conf_replace *g_conf_replace_node = NULL;
|
||||
grub_uint8_t *g_conf_replace_new_buf = NULL;
|
||||
int g_conf_replace_new_len = 0;
|
||||
@@ -446,8 +446,8 @@ static grub_err_t ventoy_cmd_break(grub_extcmd_context_t ctxt, int argc, char **
|
||||
grub_printf(" 03/13: hook / (+cat log)\r\n");
|
||||
grub_printf("\r\n");
|
||||
grub_printf(" debug:\r\n");
|
||||
grub_printf(" 0: debug is on\r\n");
|
||||
grub_printf(" 1: debug is off\r\n");
|
||||
grub_printf(" 0: debug is off\r\n");
|
||||
grub_printf(" 1: debug is on\r\n");
|
||||
grub_printf("\r\n");
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
@@ -1651,7 +1651,7 @@ int ventoy_check_device(grub_device_t dev)
|
||||
|
||||
if (0 == ventoy_check_file_exist("(%s,2)/ventoy/ventoy.cpio", dev->disk->name) ||
|
||||
0 == ventoy_check_file_exist("(%s,2)/grub/localboot.cfg", dev->disk->name) ||
|
||||
0 == ventoy_check_file_exist("(%s,2)/tool/mount.exfat-fuse_64", dev->disk->name))
|
||||
0 == ventoy_check_file_exist("(%s,2)/tool/mount.exfat-fuse_aarch64", dev->disk->name))
|
||||
{
|
||||
return ventoy_check_device_result(2 | 0x1000);
|
||||
}
|
||||
@@ -2057,6 +2057,8 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
|
||||
grub_env_set(args[1], value);
|
||||
}
|
||||
|
||||
g_svd_replace_offset = 0;
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
@@ -2607,67 +2609,6 @@ static grub_err_t ventoy_cmd_dump_img_sector(grub_extcmd_context_t ctxt, int arg
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
static grub_err_t ventoy_cmd_relocator_chaindata(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static grub_err_t ventoy_cmd_relocator_chaindata(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int rc = 0;
|
||||
ulong chain_len = 0;
|
||||
char *chain_data = NULL;
|
||||
char *relocator_addr = NULL;
|
||||
grub_relocator_chunk_t ch;
|
||||
struct grub_relocator *relocator = NULL;
|
||||
char envbuf[64] = { 0 };
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
(void)args;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
chain_data = (char *)grub_strtoul(args[0], NULL, 16);
|
||||
chain_len = grub_strtoul(args[1], NULL, 10);
|
||||
|
||||
relocator = grub_relocator_new ();
|
||||
if (!relocator)
|
||||
{
|
||||
debug("grub_relocator_new failed %p %lu\n", chain_data, chain_len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = grub_relocator_alloc_chunk_addr (relocator, &ch,
|
||||
0x100000, // GRUB_LINUX_BZIMAGE_ADDR,
|
||||
chain_len);
|
||||
if (rc)
|
||||
{
|
||||
debug("grub_relocator_alloc_chunk_addr failed %d %p %lu\n", rc, chain_data, chain_len);
|
||||
grub_relocator_unload (relocator);
|
||||
return 1;
|
||||
}
|
||||
|
||||
relocator_addr = get_virtual_current_address(ch);
|
||||
|
||||
grub_memcpy(relocator_addr, chain_data, chain_len);
|
||||
|
||||
grub_relocator_unload (relocator);
|
||||
|
||||
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (unsigned long)relocator_addr);
|
||||
grub_env_set("vtoy_chain_relocator_addr", envbuf);
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static grub_err_t ventoy_cmd_test_block_list(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_uint32_t i;
|
||||
@@ -3926,6 +3867,7 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_raw_chain_data", ventoy_cmd_raw_chain_data, 0, NULL, "", "", NULL },
|
||||
{ "vt_get_vtoy_type", ventoy_cmd_get_vtoy_type, 0, NULL, "", "", NULL },
|
||||
|
||||
{ "vt_skip_svd", ventoy_cmd_skip_svd, 0, NULL, "", "", NULL },
|
||||
{ "vt_cpio_busybox64", ventoy_cmd_cpio_busybox_64, 0, NULL, "", "", NULL },
|
||||
{ "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },
|
||||
{ "vt_trailer_cpio", ventoy_cmd_trailer_cpio, 0, NULL, "", "", NULL },
|
||||
@@ -3983,13 +3925,13 @@ static cmd_para ventoy_cmds[] =
|
||||
{ "vt_wim_chain_data", ventoy_cmd_wim_chain_data, 0, NULL, "", "", NULL },
|
||||
|
||||
{ "vt_add_replace_file", ventoy_cmd_add_replace_file, 0, NULL, "", "", NULL },
|
||||
{ "vt_relocator_chaindata", ventoy_cmd_relocator_chaindata, 0, NULL, "", "", NULL },
|
||||
{ "vt_test_block_list", ventoy_cmd_test_block_list, 0, NULL, "", "", NULL },
|
||||
{ "vt_file_exist_nocase", ventoy_cmd_file_exist_nocase, 0, NULL, "", "", NULL },
|
||||
|
||||
|
||||
{ "vt_load_plugin", ventoy_cmd_load_plugin, 0, NULL, "", "", NULL },
|
||||
{ "vt_check_plugin_json", ventoy_cmd_plugin_check_json, 0, NULL, "", "", NULL },
|
||||
{ "vt_check_password", ventoy_cmd_check_password, 0, NULL, "", "", NULL },
|
||||
|
||||
{ "vt_1st_line", ventoy_cmd_read_1st_line, 0, NULL, "", "", NULL },
|
||||
{ "vt_file_strstr", ventoy_cmd_file_strstr, 0, NULL, "", "", NULL },
|
||||
@@ -4019,7 +3961,24 @@ GRUB_MOD_INIT(ventoy)
|
||||
cmd_para *cur = NULL;
|
||||
|
||||
ventoy_env_init();
|
||||
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
if (grub_strcmp(GRUB_TARGET_CPU, "i386") == 0)
|
||||
{
|
||||
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "ia32");
|
||||
}
|
||||
else if (grub_strcmp(GRUB_TARGET_CPU, "arm64") == 0)
|
||||
{
|
||||
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "aa64");
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "uefi");
|
||||
}
|
||||
#else
|
||||
grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "legacy");
|
||||
#endif
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ventoy_cmds); i++)
|
||||
{
|
||||
cur = ventoy_cmds + i;
|
||||
|
@@ -52,11 +52,14 @@
|
||||
|
||||
#define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
#define VTOY_DUAL_MODE_SUFFIX "uefi"
|
||||
#else
|
||||
#define VTOY_DUAL_MODE_SUFFIX "legacy"
|
||||
#endif
|
||||
#define VTOY_PWD_CORRUPTED(err) \
|
||||
{\
|
||||
grub_printf("\n\n Password corrupted, will reboot after 5 seconds.\n\n"); \
|
||||
grub_refresh(); \
|
||||
grub_sleep(5); \
|
||||
grub_exit(); \
|
||||
return (err);\
|
||||
}
|
||||
|
||||
typedef struct ventoy_initrd_ctx
|
||||
{
|
||||
@@ -245,6 +248,7 @@ extern ventoy_guid g_ventoy_guid;
|
||||
extern ventoy_img_chunk_list g_img_chunk_list;
|
||||
extern ventoy_img_chunk_list g_wimiso_chunk_list;
|
||||
extern char *g_wimiso_path;
|
||||
extern char g_arch_mode_suffix[64];
|
||||
|
||||
extern int g_ventoy_debug;
|
||||
void ventoy_debug(const char *fmt, ...);
|
||||
@@ -496,6 +500,7 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
|
||||
grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
|
||||
@@ -825,6 +830,15 @@ typedef struct image_list
|
||||
struct image_list *next;
|
||||
}image_list;
|
||||
|
||||
typedef struct vtoy_password
|
||||
{
|
||||
int pathlen;
|
||||
char isopath[256];
|
||||
grub_uint8_t sha256[32];
|
||||
|
||||
struct vtoy_password *next;
|
||||
}vtoy_password;
|
||||
|
||||
extern int g_ventoy_menu_esc;
|
||||
extern int g_ventoy_suppress_esc;
|
||||
extern int g_ventoy_last_entry;
|
||||
@@ -837,6 +851,7 @@ extern int g_vhdboot_enable;
|
||||
extern int g_plugin_image_list;
|
||||
extern ventoy_gpt_info *g_ventoy_part_info;
|
||||
extern grub_uint64_t g_conf_replace_offset;
|
||||
extern grub_uint64_t g_svd_replace_offset;
|
||||
extern conf_replace *g_conf_replace_node;
|
||||
extern grub_uint8_t *g_conf_replace_new_buf;
|
||||
extern int g_conf_replace_new_len;
|
||||
@@ -880,6 +895,7 @@ int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, gr
|
||||
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
|
||||
void ventoy_plugin_dump_persistence(void);
|
||||
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
@@ -898,6 +914,7 @@ grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **
|
||||
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args);
|
||||
int ventoy_check_password(const grub_uint8_t *pwdsha256, int retry);
|
||||
|
||||
#endif /* __VENTOY_DEF_H__ */
|
||||
|
||||
|
@@ -740,6 +740,11 @@ static grub_uint32_t ventoy_linux_get_override_chunk_count(void)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
if (g_svd_replace_offset > 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -753,6 +758,11 @@ static grub_uint32_t ventoy_linux_get_override_chunk_size(void)
|
||||
count++;
|
||||
}
|
||||
|
||||
if (g_svd_replace_offset > 0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
return sizeof(ventoy_override_chunk) * count;
|
||||
}
|
||||
|
||||
@@ -829,6 +839,14 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove
|
||||
cur++;
|
||||
}
|
||||
|
||||
if (g_svd_replace_offset > 0)
|
||||
{
|
||||
cur->img_offset = g_svd_replace_offset;
|
||||
cur->override_size = 1;
|
||||
cur->override_data[0] = 0xFF;
|
||||
cur++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -995,12 +1013,15 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
static int ventoy_cpio_busybox64(cpio_newc_header *head)
|
||||
static int ventoy_cpio_busybox64(cpio_newc_header *head, const char *file)
|
||||
{
|
||||
char *name;
|
||||
int namelen;
|
||||
int offset;
|
||||
int count = 0;
|
||||
char filepath[128];
|
||||
|
||||
grub_snprintf(filepath, sizeof(filepath), "ventoy/busybox/%s", file);
|
||||
|
||||
name = (char *)(head + 1);
|
||||
while (name[0] && count < 2)
|
||||
@@ -1010,7 +1031,7 @@ static int ventoy_cpio_busybox64(cpio_newc_header *head)
|
||||
grub_memcpy(name, "ventoy/busybox/32h", 18);
|
||||
count++;
|
||||
}
|
||||
else if (grub_strcmp(name, "ventoy/busybox/64h") == 0)
|
||||
else if (grub_strcmp(name, filepath) == 0)
|
||||
{
|
||||
grub_memcpy(name, "ventoy/busybox/ash", 18);
|
||||
count++;
|
||||
@@ -1037,10 +1058,48 @@ grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char
|
||||
(void)args;
|
||||
|
||||
debug("ventoy_cmd_busybox_64 %d\n", argc);
|
||||
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf);
|
||||
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, args[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i;
|
||||
grub_file_t file;
|
||||
char buf[16];
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", args[0]);
|
||||
if (!file)
|
||||
{
|
||||
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
buf[0] = 0;
|
||||
grub_file_seek(file, (17 + i) * 2048);
|
||||
grub_file_read(file, buf, 16);
|
||||
|
||||
if (buf[0] == 2 && grub_strncmp(buf + 1, "CD001", 5) == 0)
|
||||
{
|
||||
debug("Find SVD at VD %d\n", i);
|
||||
g_svd_replace_offset = (17 + i) * 2048;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 10)
|
||||
{
|
||||
debug("SVD not found %d\n", (int)g_svd_replace_offset);
|
||||
}
|
||||
|
||||
grub_file_close(file);
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
@@ -1258,7 +1317,12 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
|
||||
if (grub_strcmp(args[3], "busybox=64") == 0)
|
||||
{
|
||||
debug("cpio busybox proc %s\n", args[3]);
|
||||
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf);
|
||||
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "64h");
|
||||
}
|
||||
else if (grub_strcmp(args[3], "busybox=a64") == 0)
|
||||
{
|
||||
debug("cpio busybox proc %s\n", args[3]);
|
||||
ventoy_cpio_busybox64((cpio_newc_header *)g_ventoy_cpio_buf, "a64");
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include <grub/datetime.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/font.h>
|
||||
#include <grub/ventoy.h>
|
||||
@@ -39,9 +40,13 @@
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
char g_arch_mode_suffix[64];
|
||||
static char g_iso_disk_name[128];
|
||||
static grub_uint8_t g_boot_pwd = 0;
|
||||
static grub_uint8_t g_boot_sha256[32];
|
||||
static install_template *g_install_template_head = NULL;
|
||||
static dud *g_dud_head = NULL;
|
||||
static vtoy_password *g_pwd_head = NULL;
|
||||
static persistence_config *g_persistence_head = NULL;
|
||||
static menu_alias *g_menu_alias_head = NULL;
|
||||
static menu_class *g_menu_class_head = NULL;
|
||||
@@ -695,6 +700,173 @@ static int ventoy_plugin_dud_entry(VTOY_JSON *json, const char *isodisk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int i = 0;
|
||||
int len = 0;
|
||||
const char *iso = NULL;
|
||||
const char *pwd = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
VTOY_JSON *pCNode = NULL;
|
||||
vtoy_password *node = NULL;
|
||||
vtoy_password *tail = NULL;
|
||||
vtoy_password *next = NULL;
|
||||
char bytes[3];
|
||||
|
||||
(void)isodisk;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
debug("Not object %d\n", json->enDataType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (g_pwd_head)
|
||||
{
|
||||
for (node = g_pwd_head; node; node = next)
|
||||
{
|
||||
next = node->next;
|
||||
grub_free(node);
|
||||
}
|
||||
|
||||
g_pwd_head = NULL;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
if (pNode->pcName && grub_strcmp("bootpwd", pNode->pcName) == 0)
|
||||
{
|
||||
len = (int)grub_strlen(pNode->unData.pcStrVal);
|
||||
if (len == 64)
|
||||
{
|
||||
g_boot_pwd = 1;
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
bytes[0] = pNode->unData.pcStrVal[i * 2];
|
||||
bytes[1] = pNode->unData.pcStrVal[i * 2 + 1];
|
||||
bytes[2] = 0;
|
||||
g_boot_sha256[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (pNode->pcName && grub_strcmp("menupwd", pNode->pcName) == 0)
|
||||
{
|
||||
for (pCNode = pNode->pstChild; pCNode; pCNode = pCNode->pstNext)
|
||||
{
|
||||
if (pCNode->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
iso = vtoy_json_get_string_ex(pCNode->pstChild, "file");
|
||||
pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd");
|
||||
if (iso && pwd && iso[0] == '/')
|
||||
{
|
||||
node = grub_zalloc(sizeof(vtoy_password));
|
||||
if (node)
|
||||
{
|
||||
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso);
|
||||
len = (int)grub_strlen(pwd);
|
||||
if (len != 64)
|
||||
{
|
||||
grub_free(node);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
bytes[0] = pwd[i * 2];
|
||||
bytes[1] = pwd[i * 2 + 1];
|
||||
bytes[2] = 0;
|
||||
node->sha256[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16);
|
||||
}
|
||||
|
||||
if (g_pwd_head)
|
||||
{
|
||||
tail->next = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pwd_head = node;
|
||||
}
|
||||
tail = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int len = 0;
|
||||
const char *iso = NULL;
|
||||
const char *pwd = NULL;
|
||||
VTOY_JSON *pNode = NULL;
|
||||
VTOY_JSON *pCNode = NULL;
|
||||
|
||||
if (json->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
grub_printf("Not object %d\n", json->enDataType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
|
||||
{
|
||||
if (pNode->pcName && grub_strcmp("bootpwd", pNode->pcName) == 0)
|
||||
{
|
||||
len = (int)grub_strlen(pNode->unData.pcStrVal);
|
||||
if (len != 64)
|
||||
{
|
||||
grub_printf("Invalid bootpwd len :%d\n", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("bootpwd:<%s>\n", pNode->unData.pcStrVal);
|
||||
}
|
||||
}
|
||||
else if (pNode->pcName && grub_strcmp("menupwd", pNode->pcName) == 0)
|
||||
{
|
||||
for (pCNode = pNode->pstChild; pCNode; pCNode = pCNode->pstNext)
|
||||
{
|
||||
if (pCNode->enDataType != JSON_TYPE_OBJECT)
|
||||
{
|
||||
grub_printf("Not object %d\n", pCNode->enDataType);
|
||||
continue;
|
||||
}
|
||||
|
||||
iso = vtoy_json_get_string_ex(pCNode->pstChild, "file");
|
||||
if (iso)
|
||||
{
|
||||
if (0 == ventoy_plugin_check_path(isodisk, iso))
|
||||
{
|
||||
pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd");
|
||||
|
||||
len = (int)grub_strlen(pwd);
|
||||
if (len != 64)
|
||||
{
|
||||
grub_printf("Invalid sha256 len <%d>\n", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("file:<%s> [OK]\n", iso);
|
||||
grub_printf("pwd:<%s>\n\n", pwd);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("No file found\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
int autosel = 0;
|
||||
@@ -1439,6 +1611,7 @@ static plugin_entry g_plugin_entries[] =
|
||||
{ "image_list", ventoy_plugin_image_list_entry, ventoy_plugin_image_list_check },
|
||||
{ "conf_replace", ventoy_plugin_conf_replace_entry, ventoy_plugin_conf_replace_check },
|
||||
{ "dud", ventoy_plugin_dud_entry, ventoy_plugin_dud_check },
|
||||
{ "password", ventoy_plugin_pwd_entry, ventoy_plugin_pwd_check },
|
||||
};
|
||||
|
||||
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
|
||||
@@ -1453,7 +1626,7 @@ static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
|
||||
{
|
||||
for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++)
|
||||
{
|
||||
grub_snprintf(key, sizeof(key), "%s_%s", g_plugin_entries[i].key, VTOY_DUAL_MODE_SUFFIX);
|
||||
grub_snprintf(key, sizeof(key), "%s_%s", g_plugin_entries[i].key, g_arch_mode_suffix);
|
||||
if (grub_strcmp(g_plugin_entries[i].key, cur->pcName) == 0 || grub_strcmp(key, cur->pcName) == 0)
|
||||
{
|
||||
debug("Plugin entry for %s\n", g_plugin_entries[i].key);
|
||||
@@ -1478,7 +1651,7 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/ventoy/ventoy.json", args[0]);
|
||||
file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/ventoy/ventoy.json", args[0]);
|
||||
if (!file)
|
||||
{
|
||||
return GRUB_ERR_NONE;
|
||||
@@ -1522,6 +1695,18 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
|
||||
|
||||
grub_free(buf);
|
||||
|
||||
if (g_boot_pwd)
|
||||
{
|
||||
grub_printf("\n\n\n\n");
|
||||
if (ventoy_check_password(g_boot_sha256, 3))
|
||||
{
|
||||
grub_printf("\n!!! Password check failed, will exit after 5 seconds. !!!\n");
|
||||
grub_refresh();
|
||||
grub_sleep(5);
|
||||
grub_exit();
|
||||
}
|
||||
}
|
||||
|
||||
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
|
||||
}
|
||||
|
||||
@@ -1920,6 +2105,86 @@ int ventoy_plugin_load_dud(dud *node, const char *isopart)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const grub_uint8_t * ventoy_plugin_get_password(const char *isopath)
|
||||
{
|
||||
int len;
|
||||
vtoy_password *node = NULL;
|
||||
|
||||
if ((!g_pwd_head) || (!isopath))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = (int)grub_strlen(isopath);
|
||||
for (node = g_pwd_head; node; node = node->next)
|
||||
{
|
||||
if (node->pathlen == len && grub_strncmp(isopath, node->isopath, len) == 0)
|
||||
{
|
||||
return node->sha256;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ventoy_check_password(const grub_uint8_t *pwdsha256, int retry)
|
||||
{
|
||||
char input[128];
|
||||
grub_uint8_t sha256[32];
|
||||
|
||||
while (retry--)
|
||||
{
|
||||
grub_memset(input, 0, sizeof(input));
|
||||
|
||||
grub_printf("Enter password: ");
|
||||
grub_refresh();
|
||||
grub_password_get(input, sizeof(input));
|
||||
|
||||
grub_crypto_hash(GRUB_MD_SHA256, sha256, input, grub_strlen(input));
|
||||
|
||||
if (grub_memcmp(pwdsha256, sha256, 32) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf("Invalid password!\n\n");
|
||||
grub_refresh();
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int ret;
|
||||
const grub_uint8_t *sha256 = NULL;
|
||||
|
||||
(void)ctxt;
|
||||
(void)argc;
|
||||
|
||||
sha256 = ventoy_plugin_get_password(args[0]);
|
||||
if (sha256)
|
||||
{
|
||||
if (0 == ventoy_check_password(sha256, 1))
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
grub_errno = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -1937,7 +2202,7 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch
|
||||
return 0;
|
||||
}
|
||||
|
||||
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s/ventoy/ventoy.json", args[0]);
|
||||
file = ventoy_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/ventoy/ventoy.json", args[0]);
|
||||
if (!file)
|
||||
{
|
||||
grub_printf("Plugin json file /ventoy/ventoy.json does NOT exist.\n");
|
||||
@@ -1969,7 +2234,7 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch
|
||||
goto end;
|
||||
}
|
||||
|
||||
grub_snprintf(key, sizeof(key), "%s_%s", args[1], VTOY_DUAL_MODE_SUFFIX);
|
||||
grub_snprintf(key, sizeof(key), "%s_%s", args[1], g_arch_mode_suffix);
|
||||
for (node = json->pstChild; node; node = node->pstNext)
|
||||
{
|
||||
if (grub_strcmp(node->pcName, args[1]) == 0 || grub_strcmp(node->pcName, key) == 0)
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#ifndef __VENTOY_H__
|
||||
#define __VENTOY_H__
|
||||
|
||||
#define COMPILE_ASSERT(expr) extern char __compile_assert[(expr) ? 1 : -1]
|
||||
#define COMPILE_ASSERT(a, expr) extern char __compile_assert##a[(expr) ? 1 : -1]
|
||||
|
||||
#define VENTOY_COMPATIBLE_STR "VENTOY COMPATIBLE"
|
||||
#define VENTOY_COMPATIBLE_STR_LEN 17
|
||||
@@ -139,11 +139,23 @@ typedef struct ventoy_windows_data
|
||||
}ventoy_windows_data;
|
||||
|
||||
|
||||
typedef struct ventoy_secure_data
|
||||
{
|
||||
grub_uint8_t magic1[16]; /* VENTOY_GUID */
|
||||
grub_uint8_t diskuuid[16];
|
||||
grub_uint8_t Checksum[16];
|
||||
grub_uint8_t adminSHA256[32];
|
||||
grub_uint8_t reserved[4000];
|
||||
grub_uint8_t magic2[16]; /* VENTOY_GUID */
|
||||
}ventoy_secure_data;
|
||||
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
// compile assert check : sizeof(ventoy_os_param) must be 512
|
||||
COMPILE_ASSERT(sizeof(ventoy_os_param) == 512);
|
||||
COMPILE_ASSERT(1,sizeof(ventoy_os_param) == 512);
|
||||
COMPILE_ASSERT(2,sizeof(ventoy_secure_data) == 4096);
|
||||
|
||||
|
||||
|
||||
@@ -242,7 +254,6 @@ typedef struct ventoy_grub_param
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
||||
int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, ventoy_img_chunk_list *chunk_list);
|
||||
void grub_iso9660_set_nojoliet(int nojoliet);
|
||||
|
@@ -17,11 +17,23 @@ all_modules_legacy="date drivemap blocklist regexp newc vga_text ntldr search at
|
||||
net_modules_uefi="efinet net tftp http"
|
||||
all_modules_uefi="blocklist ventoy test regexp newc search at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux relocator jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop efi_uga video_bochs video_cirrus video video_fb gfxterm_background gfxterm_menu"
|
||||
|
||||
all_modules_arm64_uefi="blocklist ventoy test regexp newc search gcry_md5 hashsum gzio xzio lzopio ext2 xfs read halt sleep serial terminfo png password_pbkdf2 gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback part_apple minicmd diskfilter linux jpeg iso9660 udf hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo configfile normal terminal gettext chain priority_queue bufio datetime cat extcmd crypto gzio boot all_video efi_gop video video_fb gfxterm_background gfxterm_menu"
|
||||
|
||||
|
||||
if [ "$1" = "uefi" ]; then
|
||||
all_modules="$net_modules_uefi $all_modules_uefi "
|
||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
|
||||
|
||||
|
||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi
|
||||
|
||||
#grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" -c "$VT_DIR/LiveCD/GRUB/embed.cfg" --prefix '/EFI/boot' --output "$VT_DIR/LiveCD/GRUB/bootx64.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
|
||||
elif [ "$1" = "i386efi" ]; then
|
||||
all_modules="$net_modules_uefi $all_modules_uefi "
|
||||
|
||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubia32_real.efi" --format 'i386-efi' --compression 'auto' $all_modules_uefi
|
||||
elif [ "$1" = "arm64" ]; then
|
||||
all_modules="$net_modules_uefi $all_modules_arm64_uefi "
|
||||
|
||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/BOOTAA64.EFI" --format 'arm64-efi' --compression 'auto' $all_modules_arm64_uefi
|
||||
else
|
||||
all_modules="$net_modules_legacy $all_modules_legacy "
|
||||
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/grub/i386-pc/core.img" --format 'i386-pc' --compression 'auto' $all_modules_legacy 'fat' 'part_msdos' 'biosdisk'
|
||||
@@ -37,17 +49,50 @@ if [ "$1" = "uefi" ]; then
|
||||
rm -f $VT_DIR/GRUB2/NBP/core.efi
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
|
||||
|
||||
rm -f $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod
|
||||
rm -rf $VT_DIR/INSTALL/grub/x86_64-efi
|
||||
mkdir -p $VT_DIR/INSTALL/grub/x86_64-efi
|
||||
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/x86_64-efi/normal.mod $VT_DIR/INSTALL/grub/x86_64-efi/normal.mod || exit 1
|
||||
|
||||
#copy other modules
|
||||
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/ | egrep '\.(lst|mod)$' | while read line; do
|
||||
if ! echo $all_modules | grep -q " ${line%.mod} "; then
|
||||
echo "Copy $line ..."
|
||||
rm -f $VT_DIR/INSTALL/grub/x86_64-efi/$line
|
||||
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi/$line $VT_DIR/INSTALL/grub/x86_64-efi/
|
||||
fi
|
||||
done
|
||||
elif [ "$1" = "i386efi" ]; then
|
||||
rm -f $VT_DIR/GRUB2/NBP/core.efi
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
|
||||
|
||||
rm -rf $VT_DIR/INSTALL/grub/i386-efi
|
||||
mkdir -p $VT_DIR/INSTALL/grub/i386-efi
|
||||
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-efi/normal.mod $VT_DIR/INSTALL/grub/i386-efi/normal.mod || exit 1
|
||||
|
||||
#copy other modules
|
||||
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/i386-efi/ | egrep '\.(lst|mod)$' | while read line; do
|
||||
if ! echo $all_modules | grep -q " ${line%.mod} "; then
|
||||
echo "Copy $line ..."
|
||||
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-efi/$line $VT_DIR/INSTALL/grub/i386-efi/
|
||||
fi
|
||||
done
|
||||
elif [ "$1" = "arm64" ]; then
|
||||
rm -f $VT_DIR/GRUB2/NBP/core.efi
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/arm64-efi/core.efi $VT_DIR/GRUB2/NBP/core.efi || exit 1
|
||||
|
||||
rm -rf $VT_DIR/INSTALL/grub/arm64-efi
|
||||
mkdir -p $VT_DIR/INSTALL/grub/arm64-efi
|
||||
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/arm64-efi/normal.mod $VT_DIR/INSTALL/grub/arm64-efi/normal.mod || exit 1
|
||||
|
||||
#copy other modules
|
||||
ls -1 $VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi/ | egrep '\.(lst|mod)$' | while read line; do
|
||||
if ! echo $all_modules | grep -q " ${line%.mod} "; then
|
||||
echo "Copy $line ..."
|
||||
cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/arm64-efi/$line $VT_DIR/INSTALL/grub/arm64-efi/
|
||||
fi
|
||||
done
|
||||
else
|
||||
rm -f $VT_DIR/GRUB2/NBP/core.0
|
||||
cp -a $VT_DIR/GRUB2/PXE/grub2/i386-pc/core.0 $VT_DIR/GRUB2/NBP/core.0 || exit 1
|
||||
|
Reference in New Issue
Block a user