From 1ed7bc95963efc82ea35de5ab7e096c1b2f8ac13 Mon Sep 17 00:00:00 2001 From: longpanda Date: Tue, 23 Jun 2026 21:19:46 +0800 Subject: [PATCH] Ventoy Secure Boot Policy Update - Update Ventoy grub code to match the new policy. --- .../grub-2.04/grub-core/kern/corecmd.c | 195 ++++++++++++ GRUB2/MOD_SRC/grub-2.04/grub-core/kern/env.c | 7 +- .../grub-2.04/grub-core/loader/i386/linux.c | 74 +++-- .../grub-2.04/grub-core/ventoy/ventoy.c | 130 +++++++- .../grub-2.04/grub-core/ventoy/ventoy_cmd.c | 41 ++- .../grub-2.04/grub-core/ventoy/ventoy_def.h | 12 + .../grub-core/ventoy/ventoy_plugin.c | 288 +++++++++--------- GRUB2/MOD_SRC/grub-2.04/include/grub/env.h | 5 + 8 files changed, 562 insertions(+), 190 deletions(-) create mode 100644 GRUB2/MOD_SRC/grub-2.04/grub-core/kern/corecmd.c diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/kern/corecmd.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/kern/corecmd.c new file mode 100644 index 00000000..69c85d03 --- /dev/null +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/kern/corecmd.c @@ -0,0 +1,195 @@ +/* corecmd.c - critical commands which are registered in kernel */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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. + * + * GRUB 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 GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* set ENVVAR=VALUE */ +static grub_err_t +grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + char *var; + char *val; + + if (argc < 1) + { + struct grub_env_var *env; + FOR_SORTED_ENV (env) + grub_printf ("%s=%s\n", env->name, grub_env_get (env->name)); + return 0; + } + + var = argv[0]; + val = grub_strchr (var, '='); + if (! val) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "not an assignment"); + + val[0] = 0; + grub_env_set (var, val + 1); + val[0] = '='; + + return 0; +} + +static grub_err_t +grub_core_cmd_unset (struct grub_command *cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + if (argc < 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("one argument expected")); + + grub_env_unset (argv[0]); + return 0; +} + +/* insmod MODULE */ +static grub_err_t +grub_core_cmd_insmod (struct grub_command *cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_dl_t mod; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); + + /* For simple, just disable insmod when SecureBoot is enabled. */ + if (g_sys_sb && g_sb_policy == VTOY_SB_POLICY_CHECK) + { + return grub_error (GRUB_ERR_BAD_SIGNATURE, "Cannot insmod when SecureBoot is enabled and Policy is check."); + } + + if (argv[0][0] == '/' || argv[0][0] == '(' || argv[0][0] == '+') + mod = grub_dl_load_file (argv[0]); + else + mod = grub_dl_load (argv[0]); + + if (mod) + grub_dl_ref (mod); + + return 0; +} + +static int +grub_mini_print_devices (const char *name, void *data __attribute__ ((unused))) +{ + grub_printf ("(%s) ", name); + + return 0; +} + +static int +grub_mini_print_files (const char *filename, + const struct grub_dirhook_info *info, + void *data __attribute__ ((unused))) +{ + grub_printf ("%s%s ", filename, info->dir ? "/" : ""); + + return 0; +} + +/* ls [ARG] */ +static grub_err_t +grub_core_cmd_ls (struct grub_command *cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + if (argc < 1) + { + grub_device_iterate (grub_mini_print_devices, NULL); + grub_xputs ("\n"); + grub_refresh (); + } + else + { + char *device_name; + grub_device_t dev = 0; + grub_fs_t fs; + char *path; + + device_name = grub_file_get_device_name (argv[0]); + if (grub_errno) + goto fail; + dev = grub_device_open (device_name); + if (! dev) + goto fail; + + fs = grub_fs_probe (dev); + path = grub_strchr (argv[0], ')'); + if (! path) + path = argv[0]; + else + path++; + + if (! *path && ! device_name) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument"); + goto fail; + } + + if (! *path) + { + if (grub_errno == GRUB_ERR_UNKNOWN_FS) + grub_errno = GRUB_ERR_NONE; + + grub_printf ("(%s): Filesystem is %s.\n", + device_name, fs ? fs->name : "unknown"); + } + else if (fs) + { + (fs->fs_dir) (dev, path, grub_mini_print_files, NULL); + grub_xputs ("\n"); + grub_refresh (); + } + + fail: + if (dev) + grub_device_close (dev); + + grub_free (device_name); + } + + return grub_errno; +} + +void +grub_register_core_commands (void) +{ + grub_command_t cmd; + cmd = grub_register_command ("set", grub_core_cmd_set, + N_("[ENVVAR=VALUE]"), + N_("Set an environment variable.")); + if (cmd) + cmd->flags |= GRUB_COMMAND_FLAG_EXTRACTOR; + grub_register_command ("unset", grub_core_cmd_unset, + N_("ENVVAR"), + N_("Remove an environment variable.")); + grub_register_command ("ls", grub_core_cmd_ls, + N_("[ARG]"), N_("List devices or files.")); + grub_register_command ("insmod", grub_core_cmd_insmod, + N_("MODULE"), N_("Insert a module.")); +} diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/kern/env.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/kern/env.c index 896f4385..e008204f 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/kern/env.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/kern/env.c @@ -22,6 +22,9 @@ #include #include +grub_uint8_t g_sys_sb = 0; +grub_uint8_t g_sb_policy = VTOY_SB_POLICY_BYPASS; + /* The initial context. */ static struct grub_env_context initial_context; @@ -238,12 +241,12 @@ grub_env_export (const char *name) if (! var) { grub_err_t err; - + err = grub_env_set (name, ""); if (err) return err; var = grub_env_find (name); - } + } var->global = 1; return GRUB_ERR_NONE; diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/loader/i386/linux.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/loader/i386/linux.c index d5e1a800..f4cf2018 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/loader/i386/linux.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/loader/i386/linux.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -297,7 +299,7 @@ grub_linux_setup_video (struct linux_kernel_params *params) params->lfb_size >>= 16; params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA; break; - + case GRUB_VIDEO_DRIVER_EFI_UGA: case GRUB_VIDEO_DRIVER_EFI_GOP: params->have_vga = GRUB_VIDEO_LINUX_TYPE_EFIFB; @@ -413,11 +415,11 @@ static void ventoy_debug_pause(void) { char key; - if (0 == ventoy_debug) + if (0 == ventoy_debug) { return; } - + grub_printf("press Enter to continue ......\n"); while (1) { @@ -426,7 +428,7 @@ static void ventoy_debug_pause(void) { break; } - } + } } static int ventoy_preboot(void) @@ -435,7 +437,7 @@ static int ventoy_preboot(void) const char *file; char buf[128]; - if (ventoy_debug) + if (ventoy_debug) { grub_printf("ventoy_preboot %d %d\n", ventoy_linux_argc, ventoy_initrd_called); ventoy_debug_pause(); @@ -462,7 +464,7 @@ static int ventoy_preboot(void) ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(file); } - if (ventoy_debug) + if (ventoy_debug) { grub_printf("========== initrd list ==========\n"); for (i = 0; i < ventoy_extra_initrd_num; i++) @@ -470,7 +472,7 @@ static int ventoy_preboot(void) grub_printf("%s\n", ventoy_extra_initrd_list[i]); } grub_printf("=================================\n"); - + ventoy_debug_pause(); } @@ -500,7 +502,7 @@ static int ventoy_boot_opt_filter(char *opt) } return 0; } - + if (grub_strncmp(opt, "init=", 5) == 0) { opt[0] = 'v'; @@ -521,12 +523,12 @@ static int ventoy_boot_opt_filter(char *opt) { return 1; } - + if (grub_strncmp(opt, "loglevel=", 9) == 0) { return 1; } - + if (grub_strcmp(opt, "splash") == 0) { return 1; @@ -573,7 +575,7 @@ static int ventoy_bootopt_hook(int argc, char *argv[]) { ventoy_linux_args[count] = ventoy_linux_args[i + (LINUX_MAX_ARGC / 2)]; ventoy_linux_args[i + (LINUX_MAX_ARGC / 2)] = NULL; - + if (ventoy_linux_args[count][0] == '@') { env = grub_env_get(ventoy_linux_args[count] + 1); @@ -619,7 +621,7 @@ static int ventoy_bootopt_hook(int argc, char *argv[]) { if (0 == ventoy_boot_opt_filter(last)) { - ventoy_linux_args[count++] = grub_strdup(last); + ventoy_linux_args[count++] = grub_strdup(last); } break; } @@ -634,7 +636,7 @@ static int ventoy_bootopt_hook(int argc, char *argv[]) } else { - count++; + count++; } } @@ -662,10 +664,10 @@ static int ventoy_bootopt_hook(int argc, char *argv[]) for (i = 0; i < count; i++) { grub_printf("%s ", ventoy_linux_args[i]); - } + } grub_printf("\n================================\n"); } - + return 0; } @@ -677,7 +679,7 @@ grub_cmd_extra_initrd_append (grub_command_t cmd __attribute__ ((unused)), char *pos = NULL; char *end = NULL; char buf[256] = {0}; - + if (argc != 1) { return 1; @@ -703,10 +705,10 @@ grub_cmd_extra_initrd_append (grub_command_t cmd __attribute__ ((unused)), { grub_snprintf(buf, sizeof(buf), "newc:%s:%s", end + 1, argv[0]); } - + if (ventoy_extra_initrd_num < 256) { - ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf); + ventoy_extra_initrd_list[ventoy_extra_initrd_num++] = grub_strdup(buf); } } @@ -718,7 +720,7 @@ grub_cmd_extra_initrd_reset (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) { int i; - + (void)argc; (void)argv; @@ -750,6 +752,16 @@ grub_linux_boot (void) grub_size_t mmap_size; grub_size_t cl_offset; + /* To be simple, just deny to boot linux kernel when SecureBoot is enabled and Policy is check */ + if (g_sys_sb && g_sb_policy == VTOY_SB_POLICY_CHECK) + { + grub_printf("\n\n ######### Can not do linux boot in SecureBoot Policy Check #######\n\n"); + grub_refresh(); + grub_sleep(5); + grub_errno = GRUB_ERR_BAD_SIGNATURE; + return 0; + } + ventoy_preboot(); #ifdef GRUB_MACHINE_IEEE1275 @@ -924,9 +936,9 @@ grub_linux_boot (void) &efi_desc_size, &efi_desc_version); if (err) return err; - + /* Note that no boot services are available from here. */ - efi_mmap_target = ctx.real_mode_target + efi_mmap_target = ctx.real_mode_target + ((grub_uint8_t *) efi_mmap_buf - (grub_uint8_t *) real_mode_mem); /* Pass EFI parameters. */ if (grub_le_to_cpu16 (ctx.params->version) >= 0x0208) @@ -1008,7 +1020,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), if (tip) { grub_printf("%s\n", tip); - grub_refresh(); + grub_refresh(); } } @@ -1086,7 +1098,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), align = 0; relocatable = 0; } - + if (grub_le_to_cpu16 (lh.version) >= 0x020a) { min_align = lh.min_alignment; @@ -1361,7 +1373,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - (sizeof (LINUX_IMAGE) - 1), GRUB_VERIFY_KERNEL_CMDLINE); } - + if (err) goto fail; } @@ -1495,7 +1507,7 @@ ventoy_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (ventoy_linux_argc == 0) { - return grub_cmd_initrd(cmd, argc, argv); + return grub_cmd_initrd(cmd, argc, argv); } grub_snprintf(buf, sizeof(buf), "mem:%s:size:%s", grub_env_get("ventoy_cpio_addr"), grub_env_get("ventoy_cpio_size")); @@ -1526,7 +1538,7 @@ ventoy_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), } grub_printf("=================================\n"); } - + return grub_cmd_initrd(cmd, ventoy_extra_initrd_num, ventoy_extra_initrd_list); } @@ -1537,7 +1549,7 @@ grub_cmd_set_boot_opt (grub_command_t cmd __attribute__ ((unused)), int i; const char *vtdebug; grub_command_t regcmd; - + for (i = 0; i < argc; i++) { ventoy_linux_args[ventoy_linux_argc + (LINUX_MAX_ARGC / 2) ] = grub_strdup(argv[i]); @@ -1559,7 +1571,7 @@ grub_cmd_set_boot_opt (grub_command_t cmd __attribute__ ((unused)), ventoy_linux16_func = regcmd->func; regcmd->func = grub_cmd_linux; } - + regcmd = grub_command_find("initrd16"); if (regcmd) { @@ -1576,7 +1588,7 @@ grub_cmd_unset_boot_opt (grub_command_t cmd __attribute__ ((unused)), { int i; grub_command_t regcmd; - + (void)argc; (void)argv; @@ -1612,7 +1624,7 @@ grub_cmd_unset_boot_opt (grub_command_t cmd __attribute__ ((unused)), } ventoy_initrd16_func = NULL; } - + return 0; } @@ -1633,7 +1645,7 @@ GRUB_MOD_INIT(linux) 0, N_("Load initrd.")); cmd_set_bootopt = grub_register_command ("vt_set_boot_opt", grub_cmd_set_boot_opt, 0, N_("set ext boot opt")); cmd_unset_bootopt = grub_register_command ("vt_unset_boot_opt", grub_cmd_unset_boot_opt, 0, N_("unset ext boot opt")); - + cmd_extra_initrd_append = grub_register_command ("vt_img_extra_initrd_append", grub_cmd_extra_initrd_append, 0, N_("")); cmd_extra_initrd_reset = grub_register_command ("vt_img_extra_initrd_reset", grub_cmd_extra_initrd_reset, 0, N_("")); diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c index 68958cdf..1e9e27dc 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c @@ -49,6 +49,8 @@ int g_ventoy_debug = 0; static int g_efi_os = 0xFF; grub_uint32_t g_ventoy_plat_data; +static VTOY_SHIM *g_vtoy_shim = NULL; + void ventoy_debug(const char *fmt, ...) { va_list args; @@ -298,9 +300,119 @@ void ventoy_memfile_env_set(const char *prefix, const void *buf, unsigned long l return; } +#ifdef GRUB_MACHINE_EFI +static void ventoy_get_uefi_version(char *str, grub_size_t len) +{ + grub_efi_uint8_t uefi_minor_1, uefi_minor_2; + + uefi_minor_1 = (grub_efi_system_table->hdr.revision & 0xffff) / 10; + uefi_minor_2 = (grub_efi_system_table->hdr.revision & 0xffff) % 10; + grub_snprintf(str, len, "%d.%d", (grub_efi_system_table->hdr.revision >> 16), uefi_minor_1); + if (uefi_minor_2) + grub_snprintf(str, len, "%s.%d", str, uefi_minor_2); +} + +int ventoy_set_sb_policy(void) +{ + const char *env = NULL; + static int set_once = 0; + + /* no need when SecureBoot is disabled */ + if (g_sys_sb == 0) + { + return 0; + } + + /* can only set once */ + if (set_once > 0) + { + return 0; + } + set_once = 1; + + /* VTOY_SECURE_BOOT_POLICY only take affect once during init */ + env = grub_env_get("VTOY_SECURE_BOOT_POLICY"); + if (env) + { + g_sb_policy = (grub_uint8_t)(env[0] - '0'); + } + + if (g_sb_policy == VTOY_SB_POLICY_BYPASS) + { + if (g_vtoy_shim && g_vtoy_shim->ByPassSB) + { + g_vtoy_shim->ByPassSB(); + } + } + else if (g_sb_policy == VTOY_SB_POLICY_CHECK) + { + if (g_vtoy_shim && g_vtoy_shim->CheckSB) + { + g_vtoy_shim->CheckSB(); + } + } + + return 0; +} + +static void ventoy_get_uefi_sb(void) +{ + grub_uint8_t *var = NULL; + grub_size_t size = 0; + grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; + + var = grub_efi_get_variable("SecureBoot", &global, &size); + if (var && size == 1 && *var == 1) + { + g_sys_sb = 1; + } + + grub_check_free(var); +} + +static int ventoy_secure_boot_init(void) +{ + grub_efi_guid_t ProtGuid = VTOY_SHIM_POLICY_GUID; + + ventoy_get_uefi_sb(); + + if (g_sys_sb == 0) + { + return 0; + } + + + /* + * When SecureBoot enabled, Ventoy grub must be launched by Ventoy Shim. + * Currently only x86_64 support this feature. + */ + if (g_ventoy_plat_data == VTOY_PLAT_X86_64_UEFI) + { + g_vtoy_shim = grub_efi_locate_protocol(&ProtGuid, NULL); + if (g_vtoy_shim == NULL || g_vtoy_shim->ByPassSB == NULL || g_vtoy_shim->CheckSB == NULL) + { + grub_cls(); + grub_printf(VTOY_WARNING"\n"); + grub_printf(VTOY_WARNING"\n"); + grub_printf(VTOY_WARNING"\n\n\n"); + + grub_printf("Ventoy grub is not launched by Ventoy shim.\n\n"); + grub_refresh(); + + ventoy_prompt_end(); + } + } + + return 0; +} + + +#endif + static int ventoy_arch_mode_init(void) { #ifdef GRUB_MACHINE_EFI + if (grub_strcmp(GRUB_TARGET_CPU, "i386") == 0) { g_ventoy_plat_data = VTOY_PLAT_I386_UEFI; @@ -329,19 +441,6 @@ static int ventoy_arch_mode_init(void) return 0; } -#ifdef GRUB_MACHINE_EFI -static void ventoy_get_uefi_version(char *str, grub_size_t len) -{ - grub_efi_uint8_t uefi_minor_1, uefi_minor_2; - - uefi_minor_1 = (grub_efi_system_table->hdr.revision & 0xffff) / 10; - uefi_minor_2 = (grub_efi_system_table->hdr.revision & 0xffff) % 10; - grub_snprintf(str, len, "%d.%d", (grub_efi_system_table->hdr.revision >> 16), uefi_minor_1); - if (uefi_minor_2) - grub_snprintf(str, len, "%s.%d", str, uefi_minor_2); -} -#endif - static int ventoy_calc_totalmem(grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, void *data) { grub_uint64_t *total_mem = (grub_uint64_t *)data; @@ -497,6 +596,11 @@ GRUB_MOD_INIT(ventoy) ventoy_hwinfo_init(); ventoy_env_init(); ventoy_arch_mode_init(); + +#ifdef GRUB_MACHINE_EFI + ventoy_secure_boot_init(); +#endif + ventoy_register_all_cmd(); } diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c index 5ca3a42f..5c4fc143 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c @@ -4723,7 +4723,7 @@ static grub_err_t ventoy_cmd_img_unhook_root(grub_extcmd_context_t ctxt, int arg static grub_err_t ventoy_cmd_check_secureboot_var(grub_extcmd_context_t ctxt, int argc, char **args) { int ret = 1; - grub_uint8_t *var; + grub_uint8_t *var = NULL; grub_size_t size; grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; @@ -4734,6 +4734,7 @@ static grub_err_t ventoy_cmd_check_secureboot_var(grub_extcmd_context_t ctxt, in var = grub_efi_get_variable("SecureBoot", &global, &size); if (var && *var == 1) { + grub_free(var); return 0; } @@ -5118,7 +5119,7 @@ int ventoy_load_part_table(const char *diskname) return 0; } -static void ventoy_prompt_end(void) +void ventoy_prompt_end(void) { int op = 0; char c; @@ -6412,6 +6413,40 @@ static grub_err_t ventoy_cmd_load_menu_lang(grub_extcmd_context_t ctxt, int argc VENTOY_CMD_RETURN(0); } +static grub_err_t ventoy_cmd_sb_info(grub_extcmd_context_t ctxt, int argc, char **args) +{ + const char *policy = NULL; + + (void)ctxt; + (void)argc; + (void)args; + +#ifdef GRUB_MACHINE_EFI + + if (g_sb_policy == VTOY_SB_POLICY_BYPASS) + { + policy = "ByPass"; + } + else if (g_sb_policy == VTOY_SB_POLICY_CHECK) + { + policy = "Check"; + } + else + { + policy = "XXX"; + } + + grub_printf("UEFI Firmware Secure Boot: %s\n", g_sys_sb ? "Enable" : "Disable"); + grub_printf("Ventoy Secure Boot Policy: %s\n", policy); +#else + grub_printf("Non EFI mode!\n"); +#endif + + grub_refresh(); + + VENTOY_CMD_RETURN(0); +} + static int ventoy_chksum_pathcmp(int chktype, char *rlpath, char *rdpath) { char *pos1 = NULL; @@ -7060,6 +7095,8 @@ static cmd_para ventoy_cmds[] = { "vt_pop_menu_lang", ventoy_cmd_pop_menulang, 0, NULL, "", "", NULL }, { "vt_linux_initrd", ventoy_cmd_linux_initrd, 0, NULL, "", "", NULL }, + { "vt_sbinfo", ventoy_cmd_sb_info, 0, NULL, "", "", NULL }, + }; int ventoy_register_all_cmd(void) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h index 16fc1235..3f9e0024 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h @@ -195,6 +195,16 @@ typedef struct cpio_newc_header #define check_free(p, func) if (p) { func(p); p = NULL; } #define grub_check_free(p) if (p) { grub_free(p); p = NULL; } +#define VTOY_SHIM_POLICY_GUID {0x90a29d14, 0x3968, 0x48fe, { 0x85, 0x81, 0x6b, 0x7f, 0x7d, 0xc4, 0x70, 0x55 }}; + +typedef void (*VTOY_BYPASS_SB)(void); +typedef void (*VTOY_CHECK_SB)(void); +typedef struct _VTOY_SHIM{ + VTOY_BYPASS_SB ByPassSB; + VTOY_CHECK_SB CheckSB; +} VTOY_SHIM; + + typedef int (*grub_char_check_func)(int c); #define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit) @@ -1326,6 +1336,8 @@ int ventoy_ctrl_var_init(void); int ventoy_global_var_init(void); grub_err_t ventoy_cmd_push_menulang(grub_extcmd_context_t ctxt, int argc, char **args); grub_err_t ventoy_cmd_pop_menulang(grub_extcmd_context_t ctxt, int argc, char **args); +void ventoy_prompt_end(void); +int ventoy_set_sb_policy(void); #endif /* __VENTOY_DEF_H__ */ diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c index 44354f77..f628cdf9 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c @@ -1,5 +1,5 @@ /****************************************************************************** - * ventoy_plugin.c + * ventoy_plugin.c * * Copyright (c) 2020, longpanda * @@ -7,12 +7,12 @@ * 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 . * @@ -111,13 +111,13 @@ static int ventoy_plugin_control_check(VTOY_JSON *json, const char *isodisk) if (pChild->enDataType == JSON_TYPE_STRING) { if (grub_strcmp(pChild->pcName, "VTOY_DEFAULT_IMAGE") == 0) - { + { grub_printf("%s: %s [%s]\n", pChild->pcName, pChild->unData.pcStrVal, ventoy_check_file_exist("%s%s", isodisk, pChild->unData.pcStrVal) ? "OK" : "NOT EXIST"); } else { - grub_printf("%s: %s\n", pChild->pcName, pChild->unData.pcStrVal); + grub_printf("%s: %s\n", pChild->pcName, pChild->unData.pcStrVal); } } else @@ -169,7 +169,7 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk) int exist = 0; const char *value; VTOY_JSON *node; - + value = vtoy_json_get_string_ex(json->pstChild, "file"); if (value) { @@ -182,7 +182,7 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk) { exist = ventoy_check_file_exist("%s/ventoy/%s", isodisk, value); } - + if (exist == 0) { grub_printf("Theme file %s does NOT exist\n", value); @@ -221,13 +221,13 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk) } } } - + value = vtoy_json_get_string_ex(json->pstChild, "gfxmode"); if (value) { grub_printf("gfxmode: %s\n", value); } - + value = vtoy_json_get_string_ex(json->pstChild, "display_mode"); if (value) { @@ -245,13 +245,13 @@ static int ventoy_plugin_theme_check(VTOY_JSON *json, const char *isodisk) { grub_printf("ventoy_left: %s\n", value); } - + value = vtoy_json_get_string_ex(json->pstChild, "ventoy_top"); if (value) { grub_printf("ventoy_top: %s\n", value); } - + value = vtoy_json_get_string_ex(json->pstChild, "ventoy_color"); if (value) { @@ -304,7 +304,7 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk) { grub_snprintf(filepath, sizeof(filepath), "%s/ventoy/%s", isodisk, value); } - + if (ventoy_check_file_exist(filepath) == 0) { debug("Theme file %s does not exist\n", filepath); @@ -391,27 +391,27 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk) grub_snprintf(val, sizeof(val), "%d", g_theme_res_fit); ventoy_env_export("vtoy_res_fit", val); } - + if (g_theme_id > g_theme_num || g_theme_id < 0) { g_theme_id = 0; } } - + value = vtoy_json_get_string_ex(json->pstChild, "gfxmode"); if (value) { debug("vtoy_gfxmode %s\n", value); ventoy_env_export("vtoy_gfxmode", value); } - + value = vtoy_json_get_string_ex(json->pstChild, "display_mode"); if (value) { debug("display_mode %s\n", value); ventoy_env_export("vtoy_display_mode", value); } - + value = vtoy_json_get_string_ex(json->pstChild, "serial_param"); if (value) { @@ -424,13 +424,13 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk) { ventoy_env_export(ventoy_left_key, value); } - + value = vtoy_json_get_string_ex(json->pstChild, "ventoy_top"); if (value) { ventoy_env_export(ventoy_top_key, value); } - + value = vtoy_json_get_string_ex(json->pstChild, "ventoy_color"); if (value) { @@ -442,7 +442,7 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk) { for (node = node->pstChild; node; node = node->pstNext) { - if (node->enDataType == JSON_TYPE_STRING && + if (node->enDataType == JSON_TYPE_STRING && ventoy_check_file_exist("%s%s", isodisk, node->unData.pcStrVal)) { grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, node->unData.pcStrVal); @@ -467,7 +467,7 @@ static int ventoy_plugin_check_path(const char *path, const char *file) grub_printf("%s contains invalid '\\' \n", file); return 1; } - + if (grub_strstr(file, "//")) { grub_printf("%s contains invalid double slash\n", file); @@ -491,8 +491,8 @@ static int ventoy_plugin_check_path(const char *path, const char *file) static int ventoy_plugin_check_fullpath ( - VTOY_JSON *json, - const char *isodisk, + VTOY_JSON *json, + const char *isodisk, const char *key, int *pathnum ) @@ -502,7 +502,7 @@ static int ventoy_plugin_check_fullpath int cnt = 0; VTOY_JSON *node = json; VTOY_JSON *child = NULL; - + while (node) { if (0 == grub_strcmp(key, node->pcName)) @@ -547,9 +547,9 @@ static int ventoy_plugin_check_fullpath static int ventoy_plugin_parse_fullpath ( - VTOY_JSON *json, - const char *isodisk, - const char *key, + VTOY_JSON *json, + const char *isodisk, + const char *key, file_fullpath **fullpath, int *pathnum ) @@ -559,7 +559,7 @@ static int ventoy_plugin_parse_fullpath VTOY_JSON *node = json; VTOY_JSON *child = NULL; file_fullpath *path = NULL; - + while (node) { if (0 == grub_strcmp(key, node->pcName)) @@ -583,7 +583,7 @@ static int ventoy_plugin_parse_fullpath debug("%s%s file not found\n", isodisk, node->unData.pcStrVal); return 1; } - + path = (file_fullpath *)grub_zalloc(sizeof(file_fullpath)); if (path) { @@ -605,12 +605,12 @@ static int ventoy_plugin_parse_fullpath count++; } debug("%s is array type data, count=%d\n", node->pcName, count); - + path = (file_fullpath *)grub_zalloc(sizeof(file_fullpath) * count); if (path) { *fullpath = path; - + for (count = 0, child = node->pstChild; child; child = child->pstNext) { if (ventoy_check_file_exist("%s%s", isodisk, child->unData.pcStrVal)) @@ -650,15 +650,15 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk { grub_printf("NOT object type\n"); } - + if ((iso = vtoy_json_get_string_ex(pNode->pstChild, "image")) != NULL) { pos = grub_strchr(iso, '*'); if (pos || 0 == ventoy_plugin_check_path(isodisk, iso)) { - grub_printf("image: %s [%s]\n", iso, (pos ? "*" : "OK")); + grub_printf("image: %s [%s]\n", iso, (pos ? "*" : "OK")); ventoy_plugin_check_fullpath(pNode->pstChild, isodisk, "template", &pathnum); - + if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel)) { if (autosel >= 0 && autosel <= pathnum) @@ -670,7 +670,7 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk grub_printf("autosel: %d [FAIL]\n", autosel); } } - + if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout)) { if (timeout >= 0) @@ -694,7 +694,7 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk { grub_printf("parent: %s [OK]\n", iso); ventoy_plugin_check_fullpath(pNode->pstChild, isodisk, "template", &pathnum); - + if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "autosel", &autosel)) { if (autosel >= 0 && autosel <= pathnum) @@ -706,7 +706,7 @@ static int ventoy_plugin_auto_install_check(VTOY_JSON *json, const char *isodisk grub_printf("autosel: %d [FAIL]\n", autosel); } } - + if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout)) { if (timeout >= 0) @@ -772,7 +772,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk type = auto_install_type_parent; iso = vtoy_json_get_string_ex(pNode->pstChild, "parent"); } - + if (iso && iso[0] == '/') { if (0 == ventoy_plugin_parse_fullpath(pNode->pstChild, isodisk, "template", &templatepath, &pathnum)) @@ -794,7 +794,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk node->autosel = autosel; } } - + if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout)) { if (timeout >= 0) @@ -807,7 +807,7 @@ static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk { node->next = g_install_template_head; } - + g_install_template_head = node; } } @@ -836,7 +836,7 @@ static int ventoy_plugin_dud_check(VTOY_JSON *json, const char *isodisk) { grub_printf("NOT object type\n"); } - + iso = vtoy_json_get_string_ex(pNode->pstChild, "image"); if (iso) { @@ -908,7 +908,7 @@ static int ventoy_plugin_dud_entry(VTOY_JSON *json, const char *isodisk) { node->next = g_dud_head; } - + g_dud_head = node; } else @@ -931,7 +931,7 @@ static int ventoy_plugin_parse_pwdstr(char *pwdstr, vtoy_password *pwd) char *pos; char bytes[3]; vtoy_password tmpPwd; - + len = (int)grub_strlen(pwdstr); if (len > 64) { @@ -955,7 +955,7 @@ static int ventoy_plugin_parse_pwdstr(char *pwdstr, vtoy_password *pwd) bytes[0] = pwdstr[4 + i * 2]; bytes[1] = pwdstr[4 + i * 2 + 1]; bytes[2] = 0; - + if (grub_isxdigit(bytes[0]) && grub_isxdigit(bytes[1])) { tmpPwd.md5[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16); @@ -982,7 +982,7 @@ static int ventoy_plugin_parse_pwdstr(char *pwdstr, vtoy_password *pwd) if (NULL == pwd) grub_printf("Invalid md5 salt password format %s\n", pwdstr); return 1; } - + ch = *pos; *pos = 0; grub_snprintf(tmpPwd.salt, sizeof(tmpPwd.salt), "%s", pwdstr + 4); @@ -994,7 +994,7 @@ static int ventoy_plugin_parse_pwdstr(char *pwdstr, vtoy_password *pwd) bytes[0] = pos[i * 2]; bytes[1] = pos[i * 2 + 1]; bytes[2] = 0; - + if (grub_isxdigit(bytes[0]) && grub_isxdigit(bytes[1])) { tmpPwd.md5[i] = (grub_uint8_t)grub_strtoul(bytes, NULL, 16); @@ -1038,10 +1038,10 @@ static int ventoy_plugin_get_pwd_type(const char *pwd) grub_snprintf(pwdtype, sizeof(pwdtype), "%spwd", g_menu_prefix[i]); if (grub_strcmp(pwdtype, pwd) == 0) { - return img_type_start + i; + return img_type_start + i; } } - + return -1; } @@ -1099,9 +1099,9 @@ static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk) if (!iso) { type = vtoy_menu_pwd_parent; - iso = vtoy_json_get_string_ex(pCNode->pstChild, "parent"); - } - + iso = vtoy_json_get_string_ex(pCNode->pstChild, "parent"); + } + pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd"); if (iso && pwd && iso[0] == '/') { @@ -1259,7 +1259,7 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk) { grub_printf("NOT object type\n"); } - + iso = vtoy_json_get_string_ex(pNode->pstChild, "image"); if (iso) { @@ -1280,7 +1280,7 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk) grub_printf("autosel: %d [FAIL]\n", autosel); } } - + if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout)) { if (timeout >= 0) @@ -1292,7 +1292,7 @@ static int ventoy_plugin_persistence_check(VTOY_JSON *json, const char *isodisk) grub_printf("timeout: %d [FAIL]\n", timeout); } } - } + } else { grub_printf("image: %s [FAIL]\n", iso); @@ -1361,7 +1361,7 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk) node->autosel = autosel; } } - + if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "timeout", &timeout)) { if (timeout >= 0) @@ -1374,7 +1374,7 @@ static int ventoy_plugin_persistence_entry(VTOY_JSON *json, const char *isodisk) { node->next = g_persistence_head; } - + g_persistence_head = node; } } @@ -1408,7 +1408,7 @@ static int ventoy_plugin_menualias_check(VTOY_JSON *json, const char *isodisk) path = vtoy_json_get_string_ex(pNode->pstChild, "dir"); type = vtoy_alias_directory; } - + alias = vtoy_json_get_string_ex(pNode->pstChild, "alias"); if (path && path[0] == '/' && alias) { @@ -1483,7 +1483,7 @@ static int ventoy_plugin_menualias_entry(VTOY_JSON *json, const char *isodisk) path = vtoy_json_get_string_ex(pNode->pstChild, "dir"); type = vtoy_alias_directory; } - + alias = vtoy_json_get_string_ex(pNode->pstChild, "alias"); if (path && path[0] == '/' && alias) { @@ -1498,7 +1498,7 @@ static int ventoy_plugin_menualias_entry(VTOY_JSON *json, const char *isodisk) { node->next = g_menu_alias_head; } - + g_menu_alias_head = node; } } @@ -1527,13 +1527,13 @@ static int ventoy_plugin_menutip_check(VTOY_JSON *json, const char *isodisk) { grub_printf("left: <%s>\n", tip); } - + tip = vtoy_json_get_string_ex(json->pstChild, "top"); if (tip) { grub_printf("top: <%s>\n", tip); } - + tip = vtoy_json_get_string_ex(json->pstChild, "color"); if (tip) { @@ -1550,7 +1550,7 @@ static int ventoy_plugin_menutip_check(VTOY_JSON *json, const char *isodisk) path = vtoy_json_get_string_ex(pNode->pstChild, "dir"); type = vtoy_tip_directory; } - + if (path && path[0] == '/') { if (vtoy_tip_image_file == type) @@ -1592,7 +1592,7 @@ static int ventoy_plugin_menutip_check(VTOY_JSON *json, const char *isodisk) grub_printf("tip1: <%s>\n", tip); else grub_printf("tip1: \n"); - + tip = vtoy_json_get_string_ex(pNode->pstChild, "tip2"); if (tip) grub_printf("tip2: <%s>\n", tip); @@ -1649,13 +1649,13 @@ static int ventoy_plugin_menutip_entry(VTOY_JSON *json, const char *isodisk) { grub_env_set("VTOY_TIP_LEFT", tip); } - + tip = vtoy_json_get_string_ex(json->pstChild, "top"); if (tip) { grub_env_set("VTOY_TIP_TOP", tip); } - + tip = vtoy_json_get_string_ex(json->pstChild, "color"); if (tip) { @@ -1671,7 +1671,7 @@ static int ventoy_plugin_menutip_entry(VTOY_JSON *json, const char *isodisk) path = vtoy_json_get_string_ex(pNode->pstChild, "dir"); type = vtoy_tip_directory; } - + if (path && path[0] == '/') { node = grub_zalloc(sizeof(menu_tip)); @@ -1700,7 +1700,7 @@ static int ventoy_plugin_menutip_entry(VTOY_JSON *json, const char *isodisk) { node->next = g_menu_tip_head; } - + g_menu_tip_head = node; } } @@ -1754,12 +1754,12 @@ static int ventoy_plugin_injection_check(VTOY_JSON *json, const char *isodisk) } else { - grub_printf("image: <%s> [%s]\n", path, ventoy_check_file_exist("%s%s", isodisk, path) ? "OK" : "NOT EXIST"); + grub_printf("image: <%s> [%s]\n", path, ventoy_check_file_exist("%s%s", isodisk, path) ? "OK" : "NOT EXIST"); } } else { - grub_printf("parent: <%s> [%s]\n", path, + grub_printf("parent: <%s> [%s]\n", path, ventoy_is_dir_exist("%s%s", isodisk, path) ? "OK" : "NOT EXIST"); } @@ -1806,7 +1806,7 @@ static int ventoy_plugin_injection_entry(VTOY_JSON *json, const char *isodisk) type = injection_type_parent; path = vtoy_json_get_string_ex(pNode->pstChild, "parent"); } - + archive = vtoy_json_get_string_ex(pNode->pstChild, "archive"); if (path && path[0] == '/' && archive && archive[0] == '/') { @@ -1821,7 +1821,7 @@ static int ventoy_plugin_injection_entry(VTOY_JSON *json, const char *isodisk) { node->next = g_injection_head; } - + g_injection_head = node; } } @@ -1878,7 +1878,7 @@ static int ventoy_plugin_menuclass_entry(VTOY_JSON *json, const char *isodisk) type = vtoy_class_directory; } } - + class = vtoy_json_get_string_ex(pNode->pstChild, "class"); if (key && class) { @@ -1931,11 +1931,11 @@ static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk) key = vtoy_json_get_string_ex(pNode->pstChild, "parent"); if (!key) { - name = "dir"; - key = vtoy_json_get_string_ex(pNode->pstChild, "dir"); + name = "dir"; + key = vtoy_json_get_string_ex(pNode->pstChild, "dir"); } } - + class = vtoy_json_get_string_ex(pNode->pstChild, "class"); if (key && class) { @@ -1986,7 +1986,7 @@ static int ventoy_plugin_custom_boot_entry(VTOY_JSON *json, const char *isodisk) key = vtoy_json_get_string_ex(pNode->pstChild, "dir"); type = vtoy_custom_boot_directory; } - + cfg = vtoy_json_get_string_ex(pNode->pstChild, "vcfg"); if (key && cfg) { @@ -2042,10 +2042,10 @@ static int ventoy_plugin_custom_boot_check(VTOY_JSON *json, const char *isodisk) key = vtoy_json_get_string_ex(pNode->pstChild, "file"); if (!key) { - key = vtoy_json_get_string_ex(pNode->pstChild, "dir"); + key = vtoy_json_get_string_ex(pNode->pstChild, "dir"); type = vtoy_custom_boot_directory; } - + cfg = vtoy_json_get_string_ex(pNode->pstChild, "vcfg"); len = (int)grub_strlen(cfg); if (key && cfg) @@ -2057,7 +2057,7 @@ static int ventoy_plugin_custom_boot_check(VTOY_JSON *json, const char *isodisk) else { grub_printf("%s: <%s>\n", (type == vtoy_custom_boot_directory) ? "dir" : "file", key); - grub_printf("vcfg: <%s>\n\n", cfg); + grub_printf("vcfg: <%s>\n\n", cfg); } } } @@ -2158,7 +2158,7 @@ static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk if (ventoy_check_file_exist("%s%s", isodisk, isof)) { grub_printf("iso:<%s> [OK]\n", isof); - + grub_snprintf(cmd, sizeof(cmd), "loopback vtisocheck \"%s%s\"", isodisk, isof); grub_script_execute_sourcecode(cmd); @@ -2179,7 +2179,7 @@ static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk { grub_printf("org:<%s> [NOT Exist]\n", orgf); } - + grub_script_execute_sourcecode("loopback -d vtisocheck"); } else if (grub_strchr(isof, '*')) @@ -2202,20 +2202,20 @@ static int ventoy_plugin_conf_replace_check(VTOY_JSON *json, const char *isodisk } else { - grub_printf("new1:<%s> [OK]\n", newf); + grub_printf("new1:<%s> [OK]\n", newf); } grub_file_close(file); } else { - grub_printf("new:<%s> [NOT Exist]\n", newf); + grub_printf("new:<%s> [NOT Exist]\n", newf); } if (JSON_SUCCESS == vtoy_json_get_int(pNode->pstChild, "img", &img)) { - grub_printf("img:<%d>\n", img); + grub_printf("img:<%d>\n", img); } - + grub_printf("\n"); } } @@ -2261,7 +2261,7 @@ static int ventoy_plugin_auto_memdisk_entry(VTOY_JSON *json, const char *isodisk { node->next = g_auto_memdisk_head; } - + g_auto_memdisk_head = node; } } @@ -2398,7 +2398,7 @@ static int ventoy_plugin_image_list_check(VTOY_JSON *json, const char *isodisk) return 0; } -static plugin_entry g_plugin_entries[] = +static plugin_entry g_plugin_entries[] = { { "control", ventoy_plugin_control_entry, ventoy_plugin_control_check, 0 }, { "theme", ventoy_plugin_theme_entry, ventoy_plugin_theme_check, 0 }, @@ -2440,7 +2440,7 @@ static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk) } } - + for (cur = json; cur; cur = cur->pstNext) { for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++) @@ -2466,7 +2466,7 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a grub_uint8_t *code = NULL; grub_file_t file; VTOY_JSON *json = NULL; - + (void)ctxt; (void)argc; @@ -2489,7 +2489,7 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a grub_file_close(file); return 1; } - + buf[file->size] = 0; grub_file_read(file, buf, file->size); grub_file_close(file); @@ -2517,13 +2517,13 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a grub_free(buf); return 1; } - + ret = vtoy_json_parse(json, buf + offset); if (ret) { grub_env_set("VTOY_PLUGIN_SYNTAX_ERROR", "1"); grub_env_export("VTOY_PLUGIN_SYNTAX_ERROR"); - + debug("Failed to parse json string %d\n", ret); grub_free(buf); return 1; @@ -2536,7 +2536,7 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a grub_free(buf); if (g_boot_pwd.type) - { + { grub_printf("\n\n======= %s ======\n\n", grub_env_get("VTOY_TEXT_MENU_VER")); if (ventoy_check_password(&g_boot_pwd, 3)) { @@ -2556,6 +2556,10 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a grub_env_unset("VTOY_MENU_TIP_ENABLE"); } +#ifdef GRUB_MACHINE_EFI + ventoy_set_sb_policy(); +#endif + VENTOY_CMD_RETURN(GRUB_ERR_NONE); } @@ -2580,12 +2584,12 @@ void ventoy_plugin_dump_auto_install(void) for (node = g_install_template_head; node; node = node->next) { - grub_printf("\n%s:<%s> <%d>\n", + grub_printf("\n%s:<%s> <%d>\n", (node->type == auto_install_type_file) ? "IMAGE" : "PARENT", node->isopath, node->templatenum); for (i = 0; i < node->templatenum; i++) { - grub_printf("SCRIPT %d:<%s>\n", i, node->templatepath[i].path); + grub_printf("SCRIPT %d:<%s>\n", i, node->templatepath[i].path); } } @@ -2605,7 +2609,7 @@ void ventoy_plugin_dump_persistence(void) for (i = 0; i < node->backendnum; i++) { - grub_printf("PERSIST %d:<%s>", i, node->backendpath[i].path); + grub_printf("PERSIST %d:<%s>", i, node->backendpath[i].path); rc = ventoy_plugin_get_persistent_chunklist(node->isopath, i, &chunk_list); if (rc == 0) { @@ -2643,7 +2647,7 @@ install_template * ventoy_plugin_find_install_template(const char *isopath) } } } - + for (node = g_install_template_head; node; node = node->next) { if (node->type == auto_install_type_parent) @@ -2744,7 +2748,7 @@ int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, vento node->backendpath[index].vlnk_add = 1; } } - + file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", g_iso_disk_name, path); if (!file) { @@ -2758,13 +2762,13 @@ int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, vento { goto end; } - + chunk_list->max_chunk = DEFAULT_CHUNK_NUM; chunk_list->cur_chunk = 0; start = file->device->disk->partition->start; ventoy_get_block_list(file, chunk_list, start); - + if (0 != ventoy_check_block_list(file, chunk_list, start, NULL, 0)) { grub_free(chunk_list->chunk); @@ -2802,7 +2806,7 @@ const char * ventoy_plugin_get_injection(const char *isopath) } } } - + for (node = g_injection_head; node; node = node->next) { if (node->type == injection_type_parent) @@ -2830,7 +2834,7 @@ const char * ventoy_plugin_get_menu_alias(int type, const char *isopath) len = (int)grub_strlen(isopath); for (node = g_menu_alias_head; node; node = node->next) { - if (node->type == type && node->pathlen && + if (node->type == type && node->pathlen && node->pathlen == len && ventoy_strcmp(node->isopath, isopath) == 0) { return node->alias; @@ -2853,7 +2857,7 @@ const menu_tip * ventoy_plugin_get_menu_tip(int type, const char *isopath) len = (int)grub_strlen(isopath); for (node = g_menu_tip_head; node; node = node->next) { - if (node->type == type && node->pathlen && + if (node->type == type && node->pathlen && node->pathlen == len && ventoy_strcmp(node->isopath, isopath) == 0) { return node; @@ -2873,10 +2877,10 @@ const char * ventoy_plugin_get_menu_class(int type, const char *name, const char { return NULL; } - - namelen = (int)grub_strlen(name); - pathlen = (int)grub_strlen(path); - + + namelen = (int)grub_strlen(name); + pathlen = (int)grub_strlen(path); + if (vtoy_class_image_file == type) { for (node = g_menu_class_head; node; node = node->next) @@ -2894,7 +2898,7 @@ const char * ventoy_plugin_get_menu_class(int type, const char *name, const char } } } - + for (node = g_menu_class_head; node; node = node->next) { if (node->type != type) @@ -2929,7 +2933,7 @@ int ventoy_plugin_add_custom_boot(const char *vcfgpath) { int len; custom_boot *node = NULL; - + node = grub_zalloc(sizeof(custom_boot)); if (node) { @@ -2948,7 +2952,7 @@ int ventoy_plugin_add_custom_boot(const char *vcfgpath) } g_custom_boot_head = node; } - + return 0; } @@ -2964,19 +2968,19 @@ const char * ventoy_plugin_get_custom_boot(const char *isopath) } len = (int)grub_strlen(isopath); - + for (node = g_custom_boot_head; node; node = node->next) { if (node->type == vtoy_custom_boot_image_file) { if (node->pathlen == len && grub_strncmp(isopath, node->path, len) == 0) { - return node->cfg; + return node->cfg; } } else { - if (node->pathlen < len && isopath[node->pathlen] == '/' && + if (node->pathlen < len && isopath[node->pathlen] == '/' && grub_strncmp(isopath, node->path, node->pathlen) == 0) { for (i = node->pathlen + 1; i < len; i++) @@ -2989,7 +2993,7 @@ const char * ventoy_plugin_get_custom_boot(const char *isopath) if (i >= len) { - return node->cfg; + return node->cfg; } } } @@ -3008,7 +3012,7 @@ grub_err_t ventoy_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, cha for (node = g_custom_boot_head; node; node = node->next) { - grub_printf("[%s] <%s>:<%s>\n", (node->type == vtoy_custom_boot_directory) ? "dir" : "file", + grub_printf("[%s] <%s>:<%s>\n", (node->type == vtoy_custom_boot_directory) ? "dir" : "file", node->path, node->cfg); } @@ -3025,7 +3029,7 @@ int ventoy_plugin_check_memdisk(const char *isopath) return 0; } - len = (int)grub_strlen(isopath); + len = (int)grub_strlen(isopath); for (node = g_auto_memdisk_head; node; node = node->next) { if (node->pathlen == len && ventoy_strncmp(node->isopath, isopath, len) == 0) @@ -3048,8 +3052,8 @@ int ventoy_plugin_get_image_list_index(int type, const char *name) return 0; } - len = (int)grub_strlen(name); - + len = (int)grub_strlen(name); + for (node = g_image_list_head; node; node = node->next, index++) { if (vtoy_class_directory == type) @@ -3083,7 +3087,7 @@ int ventoy_plugin_find_conf_replace(const char *iso, conf_replace *nodes[VTOY_MA } len = (int)grub_strlen(iso); - + for (node = g_conf_replace_head; node; node = node->next) { if (node->pathlen == len && ventoy_strncmp(node->isopath, iso, len) == 0) @@ -3095,7 +3099,7 @@ int ventoy_plugin_find_conf_replace(const char *iso, conf_replace *nodes[VTOY_MA } } } - + return n; } @@ -3117,7 +3121,7 @@ dud * ventoy_plugin_find_dud(const char *iso) return node; } } - + return NULL; } @@ -3134,16 +3138,16 @@ int ventoy_plugin_load_dud(dud *node, const char *isopart) debug("file %d has been loaded\n", i); continue; } - + file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", isopart, node->dudpath[i].path); if (file) { buf = grub_malloc(file->size); if (buf) { - grub_file_read(file, buf, file->size); + grub_file_read(file, buf, file->size); node->files[i].size = (int)file->size; - node->files[i].buf = buf; + node->files[i].buf = buf; } grub_file_close(file); } @@ -3166,7 +3170,7 @@ static const vtoy_password * ventoy_plugin_get_password(const char *isopath) if (g_pwd_head) { - len = (int)grub_strlen(isopath); + len = (int)grub_strlen(isopath); for (node = g_pwd_head; node; node = node->next) { if (node->type == vtoy_menu_pwd_file) @@ -3179,7 +3183,7 @@ static const vtoy_password * ventoy_plugin_get_password(const char *isopath) } for (node = g_pwd_head; node; node = node->next) - { + { if (node->type == vtoy_menu_pwd_parent) { if (node->pathlen < len && ventoy_plugin_is_parent(node->isopath, node->pathlen, isopath)) @@ -3217,7 +3221,7 @@ grub_err_t ventoy_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char { int ret; const vtoy_password *pwd = NULL; - + (void)ctxt; (void)argc; @@ -3251,7 +3255,7 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch grub_file_t file; VTOY_JSON *node = NULL; VTOY_JSON *json = NULL; - + (void)ctxt; if (argc != 3) @@ -3273,7 +3277,7 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch grub_printf("Failed to malloc memory %lu.\n", (ulong)(file->size + 1)); goto end; } - + buf[file->size] = 0; grub_file_read(file, buf, file->size); @@ -3313,7 +3317,7 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch if (!node) { grub_printf("%s is NOT found in ventoy.json\n", args[1]); - goto end; + goto end; } } @@ -3323,12 +3327,12 @@ grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, ch { if (g_plugin_entries[i].checkfunc) { - ret = g_plugin_entries[i].checkfunc(node, args[2]); + ret = g_plugin_entries[i].checkfunc(node, args[2]); } break; } } - + end: check_free(file, grub_file_close); check_free(json, vtoy_json_destroy); @@ -3365,7 +3369,7 @@ grub_err_t ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, cha { return 0; } - + for (node = g_theme_head; node; node = node->next) { name = grub_strstr(node->theme.path, ")/"); @@ -3377,22 +3381,22 @@ grub_err_t ventoy_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, cha { name = node->theme.path; } - - pos += grub_snprintf(buf + pos, bufsize - pos, + + pos += grub_snprintf(buf + pos, bufsize - pos, "menuentry \"%s\" --class=debug_theme_item --class=debug_theme_select --class=F5tool {\n" "vt_set_theme_path \"%s\"\n" "}\n", name, node->theme.path); } - pos += grub_snprintf(buf + pos, bufsize - pos, + pos += grub_snprintf(buf + pos, bufsize - pos, "menuentry \"$VTLANG_RETURN_PREVIOUS\" --class=vtoyret VTOY_RET {\n" "echo 'Return ...'\n" "}\n"); grub_script_execute_sourcecode(buf); grub_free(buf); - + return 0; } @@ -3421,12 +3425,12 @@ grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **arg } debug("g_theme_num = %d\n", g_theme_num); - + if (g_theme_num == 0) { goto end; } - + if (g_theme_id > 0 && g_theme_id <= g_theme_num) { for (i = 0; i < (grub_uint32_t)(g_theme_id - 1) && node; i++) @@ -3499,10 +3503,10 @@ grub_err_t ventoy_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **arg if (argc > 0 && grub_strcmp(args[0], "switch") == 0) { - grub_snprintf(g_ventoy_theme_path, sizeof(g_ventoy_theme_path), "%s", pThemePath[mod]); + grub_snprintf(g_ventoy_theme_path, sizeof(g_ventoy_theme_path), "%s", pThemePath[mod]); } else - { + { debug("random theme %s\n", pThemePath[mod]); grub_env_set("theme", pThemePath[mod]); } @@ -3594,7 +3598,7 @@ int ventoy_plugin_load_menu_lang(int init, const char *lang) { ventoy_menu_push_key(GRUB_TERM_ESC); ventoy_menu_push_key(GRUB_TERM_ESC); - g_ventoy_menu_refresh = 1; + g_ventoy_menu_refresh = 1; } ret = 0; @@ -3619,7 +3623,7 @@ grub_err_t ventoy_cmd_cur_menu_lang(grub_extcmd_context_t ctxt, int argc, char * { grub_printf("%s\n", g_cur_menu_language); grub_printf("%s\n", g_ventoy_hotkey_tip); - grub_refresh(); + grub_refresh(); } VENTOY_CMD_RETURN(0); diff --git a/GRUB2/MOD_SRC/grub-2.04/include/grub/env.h b/GRUB2/MOD_SRC/grub-2.04/include/grub/env.h index 3c601e44..6a5e69dc 100644 --- a/GRUB2/MOD_SRC/grub-2.04/include/grub/env.h +++ b/GRUB2/MOD_SRC/grub-2.04/include/grub/env.h @@ -24,6 +24,11 @@ #include #include +#define VTOY_SB_POLICY_BYPASS 0 +#define VTOY_SB_POLICY_CHECK 1 +extern grub_uint8_t EXPORT_VAR(g_sys_sb); +extern grub_uint8_t EXPORT_VAR(g_sb_policy); + struct grub_env_var; typedef const char *(*grub_env_read_hook_t) (struct grub_env_var *var,