diff --git a/src/grub2/Makefile.am b/src/grub2/Makefile.am new file mode 100644 index 0000000..d84c2ef --- /dev/null +++ b/src/grub2/Makefile.am @@ -0,0 +1,507 @@ +AUTOMAKE_OPTIONS = subdir-objects -Wno-portability + +DEPDIR=.deps-core + +include $(top_srcdir)/conf/Makefile.common + +CC=$(TARGET_CC) +CPP=$(TARGET_CC) +CCAS=$(TARGET_CC) +RANLIB=$(TARGET_RANLIB) +STRIP=$(TARGET_STRIP) + +MACHO2IMG=$(top_builddir)/grub-macho2img + +AM_CFLAGS = $(TARGET_CFLAGS) +AM_LDFLAGS = $(TARGET_LDFLAGS) +AM_CPPFLAGS = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT) +AM_CCASFLAGS = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT) + +CFLAGS_PROGRAM += $(CFLAGS_PLATFORM) +LDFLAGS_PROGRAM += $(LDFLAGS_PLATFORM) +CPPFLAGS_PROGRAM += $(CPPFLAGS_PLATFORM) +CCASFLAGS_PROGRAM += $(CCASFLAGS_PLATFORM) + +CFLAGS_LIBRARY += $(CFLAGS_PLATFORM) -fno-builtin +CPPFLAGS_LIBRARY += $(CPPFLAGS_PLATFORM) +CCASFLAGS_LIBRARY += $(CCASFLAGS_PLATFORM) + +build-grub-pep2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c + $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=64 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pep2elf\" $^ +CLEANFILES += build-grub-pep2elf$(BUILD_EXEEXT) + +build-grub-pe2elf$(BUILD_EXEEXT): $(top_srcdir)/util/grub-pe2elf.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c + $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_TARGET_WORDSIZE=32 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-pe2elf\" $^ +CLEANFILES += build-grub-pe2elf$(BUILD_EXEEXT) + +# gentrigtables +gentrigtables$(BUILD_EXEEXT): gentrigtables.c + $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) $< $(BUILD_LIBM) +CLEANFILES += gentrigtables$(BUILD_EXEEXT) + +build-grub-module-verifier$(BUILD_EXEEXT): $(top_srcdir)/util/grub-module-verifier.c $(top_srcdir)/util/grub-module-verifier32.c $(top_srcdir)/util/grub-module-verifier64.c $(top_srcdir)/grub-core/kern/emu/misc.c $(top_srcdir)/util/misc.c + $(BUILD_CC) -o $@ -I$(top_srcdir)/include $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $(BUILD_LDFLAGS) -DGRUB_BUILD=1 -DGRUB_UTIL=1 -DGRUB_BUILD_PROGRAM_NAME=\"build-grub-module-verifier\" $^ +CLEANFILES += build-grub-module-verifier$(BUILD_EXEEXT) + +# trigtables.c +trigtables.c: gentrigtables$(BUILD_EXEEXT) gentrigtables.c $(top_srcdir)/configure.ac + ./gentrigtables$(BUILD_EXEEXT) > $@ +CLEANFILES += trigtables.c + +# XXX Use Automake's LEX & YACC support +grub_script.tab.h: script/parser.y + $(YACC) -d -p grub_script_yy -b grub_script $< +grub_script.tab.c: grub_script.tab.h +CLEANFILES += grub_script.tab.c grub_script.tab.h + +# For the lexer. +grub_script.yy.h: script/yylex.l + $(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $< +grub_script.yy.c: grub_script.yy.h + +rs_decoder.h: $(srcdir)/lib/reed_solomon.c + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Os -I$(top_builddir) -S -DSTANDALONE -o $@ $< -g0 -mregparm=3 -ffreestanding + +CLEANFILES += grub_script.yy.c grub_script.yy.h + +include $(srcdir)/Makefile.core.am + +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dl.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/list.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/misc.h +if COND_emu +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt-emu.h +else +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/compiler-rt.h +endif +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h + +if COND_i386_pc +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pxe.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +endif + +if COND_i386_xen_pvh +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h +endif + +if COND_i386_efi +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h +endif + +if COND_i386_coreboot +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +endif + +if COND_i386_multiboot +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +endif + +if COND_i386_qemu +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +endif + +if COND_i386_ieee1275 +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +endif + +if COND_i386_xen +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/xen/hypercall.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h +endif + +if COND_x86_64_xen +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/xen.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/x86_64/xen/hypercall.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h +endif + +if COND_x86_64_efi +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h +endif + +if COND_ia64_efi +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +endif + +if COND_mips +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/cpu/kernel.h +endif + +if COND_mips_arc +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arc/arc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +endif + +if COND_mips_qemu_mips +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +endif + +if COND_mips_loongson +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/time.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cs5536.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pci.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/serial.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/loader.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +endif + +if COND_mips_qemu_mips +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h +endif + +if COND_mips64_efi +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/loongson.h +endif + +if COND_powerpc_ieee1275 +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +endif + +if COND_sparc64_ieee1275 +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/terminfo.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +endif + +if COND_arm_uboot +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/uboot.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/uboot/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/lib/arg.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h +endif + +if COND_arm_coreboot +KERNEL_HEADER_FILES += $(top_builddir)/include/grub/keyboard_layouts.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dma.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/coreboot/kernel.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdtbus.h +endif + +if COND_arm_efi +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/arm/system.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +endif + +if COND_arm64_efi +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +endif + +if COND_riscv32_efi +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +endif + +if COND_riscv64_efi +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h +endif + +if COND_emu +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h +if COND_GRUB_EMU_SDL +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h +endif +if COND_GRUB_EMU_PCI +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libpciaccess.h +endif +endif + +symlist.h: $(top_builddir)/config.h $(KERNEL_HEADER_FILES) + @list='$^'; \ + for p in $$list; do \ + echo "#include <$$p>" >> $@ || (rm -f $@; exit 1); \ + done +CLEANFILES += symlist.h +BUILT_SOURCES += symlist.h + +symlist.c: symlist.h gensymlist.sh + $(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) -DGRUB_SYMBOL_GENERATOR=1 symlist.h > symlist.p || (rm -f symlist.p; exit 1) + cat symlist.p | $(SHELL) $(srcdir)/gensymlist.sh $(top_builddir)/config.h $(KERNEL_HEADER_FILES) >$@ || (rm -f $@; exit 1) + rm -f symlist.p +CLEANFILES += symlist.c +BUILT_SOURCES += symlist.c + +if COND_HAVE_ASM_USCORE +ASM_PREFIX=_ +else +ASM_PREFIX= +endif + +noinst_DATA += kernel_syms.lst + +kernel_syms.lst: $(KERNEL_HEADER_FILES) $(top_builddir)/config.h + $(TARGET_CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS_KERNEL) $(CPPFLAGS) $(CFLAGS) -DGRUB_SYMBOL_GENERATOR=1 $^ >kernel_syms.input + cat kernel_syms.input | grep -v '^#' | sed -n \ + -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ + -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '"$(ASM_PREFIX)"'\1/;p;}' \ + | sort -u >$@ + rm -f kernel_syms.input +CLEANFILES += kernel_syms.lst + +if COND_emu +kern/emu/grub_emu-main.$(OBJEXT):grub_emu_init.h +grub_emu-grub_emu_init.$(OBJEXT):grub_emu_init.h +kern/emu/grub_emu_dyn-main.$(OBJEXT):grub_emu_init.h +grub_emu_dyn-grub_emu_init.$(OBJEXT):grub_emu_init.h + +grub_emu_init.h: genemuinitheader.sh $(MODULE_FILES) + rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinitheader.sh $(TARGET_NM) > $@ +CLEANFILES += grub_emu_init.h + +grub_emu_init.c: grub_emu_init.h genemuinit.sh $(MODULE_FILES) + rm -f $@; echo $(MODULE_FILES) | sh $(srcdir)/genemuinit.sh $(TARGET_NM) > $@ +CLEANFILES += grub_emu_init.c +endif + +# List files + +fs.lst: $(MARKER_FILES) + (for pp in $^; do \ + b=`basename $$pp .marker`; \ + if grep 'FS_LIST_MARKER' $$pp >/dev/null 2>&1; then \ + echo $$b; \ + fi; \ + done) | sort -u > $@ +platform_DATA += fs.lst +CLEANFILES += fs.lst + +command.lst: $(MARKER_FILES) + (for pp in $^; do \ + b=`basename $$pp .marker`; \ + sed -n \ + -e "/EXTCOMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \ + -e "/P1COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $$b/;p;}" \ + -e "/COMMAND_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \ + done) | sort -u > $@ +platform_DATA += command.lst +CLEANFILES += command.lst + +partmap.lst: $(MARKER_FILES) + (for pp in $^; do \ + b=`basename $$pp .marker`; \ + if grep 'PARTMAP_LIST_MARKER' $$pp >/dev/null 2>&1; then \ + echo $$b; \ + fi; \ + done) | sort -u > $@ +platform_DATA += partmap.lst +CLEANFILES += partmap.lst + +terminal.lst: $(MARKER_FILES) + (for pp in $^; do \ + b=`basename $$pp .marker`; \ + sed -n \ + -e "/INPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \ + -e "/OUTPUT_TERMINAL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \ + done) | sort -u > $@ +platform_DATA += terminal.lst +CLEANFILES += terminal.lst + +fdt.lst: $(MARKER_FILES) + (for pp in $^; do \ + b=`basename $$pp .marker`; \ + sed -n \ + -e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/i\1: $$b/;p;}" \ + -e "/FDT_DRIVER_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/o\1: $$b/;p;}" $$pp; \ + done) | sort -u > $@ +platform_DATA += fdt.lst +CLEANFILES += fdt.lst + +parttool.lst: $(MARKER_FILES) + (for pp in $^; do \ + b=`basename $$pp .marker`; \ + sed -n \ + -e "/PARTTOOL_LIST_MARKER *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $$b/;p;}" $$pp; \ + done) | sort -u > $@ +platform_DATA += parttool.lst +CLEANFILES += parttool.lst + +video.lst: $(MARKER_FILES) + (for pp in $^; do \ + b=`basename $$pp .marker`; \ + if grep 'VIDEO_LIST_MARKER' $$pp >/dev/null 2>&1; then \ + echo $$b; \ + fi; \ + done) | sort -u > $@ +platform_DATA += video.lst +CLEANFILES += video.lst + +# but, crypto.lst is simply copied +crypto.lst: $(srcdir)/lib/libgcrypt-grub/cipher/crypto.lst + cp $^ $@ +platform_DATA += crypto.lst +CLEANFILES += crypto.lst + +syminfo.lst: gensyminfo.sh kernel_syms.lst $(MODULE_FILES) + cat kernel_syms.lst > $@.new + for m in $(MODULE_FILES); do \ + sh $< $$m >> $@.new || exit 1; \ + done + mv $@.new $@ + +# generate global module dependencies list +moddep.lst: syminfo.lst genmoddep.awk video.lst + cat $< | sort | $(AWK) -f $(srcdir)/genmoddep.awk > $@ || (rm -f $@; exit 1) +platform_DATA += moddep.lst +CLEANFILES += config.log syminfo.lst moddep.lst + +$(MOD_FILES): %.mod : genmod.sh moddep.lst %.module$(EXEEXT) build-grub-module-verifier$(BUILD_EXEEXT) + TARGET_OBJ2ELF=@TARGET_OBJ2ELF@ sh $^ $@ +platform_DATA += $(MOD_FILES) +platform_DATA += modinfo.sh +CLEANFILES += $(MOD_FILES) + +if COND_ENABLE_EFIEMU +efiemu32.o: efiemu/runtime/efiemu.c $(TARGET_OBJ2ELF) + -rm -f $@ + -rm -f $@.bin + $(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m32 -Wall -Werror -nostdlib -static -O2 -c -o $@.bin $< + if test "x$(TARGET_APPLE_LINKER)" = x1; then \ + $(TARGET_OBJCONV) -felf32 -nu -nd $@.bin $@ || exit 1; \ + rm -f $@.bin ; \ + elif test ! -z "$(TARGET_OBJ2ELF)"; then \ + $(TARGET_OBJ2ELF) $@.bin || (rm -f $@.bin; exit 1); \ + mv $@.bin $@ ; \ + else \ + mv $@.bin $@ ; \ + fi + +# Link format -arch,x86_64 means Apple linker +efiemu64_c.o: efiemu/runtime/efiemu.c + $(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -nostdlib -Wall -Werror -O2 -mcmodel=large -mno-red-zone -c -o $@ $< + +efiemu64_s.o: efiemu/runtime/efiemu.S + $(TARGET_CC) $(DEFS) $(INCLUDES) $(CPPFLAGS_EFIEMU) $(CPPFLAGS_DEFAULT) -m64 -Wall -Werror -nostdlib -O2 -mcmodel=large -mno-red-zone -c -o $@ $< + +efiemu64.o: efiemu64_c.o efiemu64_s.o $(TARGET_OBJ2ELEF) + -rm -f $@ + -rm -f $@.bin + $(TARGET_CC) -m64 $(EFIEMU64_LINK_FORMAT) -nostdlib -static -Wl,-r -o $@.bin $^ + if test "x$(EFIEMU64_LINK_FORMAT)" = x-arch,x86_64; then \ + $(TARGET_OBJCONV) -felf64 -nu -nd $@.bin $@ || exit 1; \ + rm -f $@.bin; \ + else \ + mv $@.bin $@ ; \ + fi + +platform_DATA += efiemu32.o efiemu64.o +CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_s.o +endif + +windowsdir=$(top_builddir)/$(PACKAGE)-$(VERSION)-for-windows +windowsdir: $(PROGRAMS) $(starfield_DATA) $(platform_DATA) + test -d $(windowsdir)/$(target_cpu)-$(platform) || mkdir $(windowsdir)/$(target_cpu)-$(platform) + for x in $(platform_DATA); do \ + cp -fp $$x $(windowsdir)/$(target_cpu)-$(platform)/$$x; \ + done diff --git a/src/grub2/Makefile.core.def b/src/grub2/Makefile.core.def new file mode 100644 index 0000000..1ab201e --- /dev/null +++ b/src/grub2/Makefile.core.def @@ -0,0 +1,2586 @@ +AutoGen definitions Makefile.tpl; + +transform_data = { + installdir = noinst; + name = gensyminfo.sh; + common = gensyminfo.sh.in; +}; + +transform_data = { + installdir = noinst; + name = genmod.sh; + common = genmod.sh.in; +}; + +transform_data = { + installdir = noinst; + name = modinfo.sh; + common = modinfo.sh.in; +}; + +transform_data = { + installdir = platform; + name = gmodule.pl; + common = gmodule.pl.in; +}; + +transform_data = { + installdir = platform; + name = gdb_grub; + common = gdb_grub.in; +}; + +transform_data = { + installdir = platform; + name = grub.chrp; + common = boot/powerpc/grub.chrp.in; + enable = powerpc_ieee1275; +}; + +transform_data = { + installdir = platform; + name = bootinfo.txt; + common = boot/powerpc/bootinfo.txt.in; + enable = powerpc_ieee1275; +}; + +kernel = { + name = kernel; + + nostrip = emu; + + emu_ldflags = '-Wl,-r,-d'; + i386_efi_ldflags = '-Wl,-r,-d'; + i386_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; + x86_64_efi_ldflags = '-Wl,-r,-d'; + x86_64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; + + ia64_efi_cflags = '-fno-builtin -fpic -minline-int-divide-max-throughput'; + ia64_efi_ldflags = '-Wl,-r,-d'; + ia64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; + + arm_efi_ldflags = '-Wl,-r,-d'; + arm_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; + + arm64_efi_ldflags = '-Wl,-r,-d'; + arm64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; + + riscv32_efi_ldflags = '-Wl,-r,-d'; + riscv32_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; + + riscv64_efi_ldflags = '-Wl,-r,-d'; + riscv64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame'; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_coreboot_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_coreboot_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_multiboot_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_multiboot_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_ieee1275_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_ieee1275_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x10000'; + i386_xen_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_xen_ldflags = '$(TARGET_IMG_BASE_LDOPT),0'; + x86_64_xen_ldflags = '$(TARGET_IMG_LDFLAGS)'; + x86_64_xen_ldflags = '$(TARGET_IMG_BASE_LDOPT),0'; + i386_xen_pvh_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_xen_pvh_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x100000'; + + mips_loongson_ldflags = '-Wl,-Ttext,0x80200000'; + powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000'; + sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400'; + mips_arc_ldflags = '-Wl,-Ttext,$(TARGET_LINK_ADDR)'; + mips_qemu_mips_ldflags = '-Wl,-Ttext,0x80200000'; + + mips_arc_cppflags = '-DGRUB_DECOMPRESSOR_LINK_ADDR=$(TARGET_DECOMPRESSOR_LINK_ADDR)'; + i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; + emu_cflags = '$(CFLAGS_GNULIB)'; + emu_cppflags = '$(CPPFLAGS_GNULIB)'; + arm_uboot_ldflags = '-Wl,-r,-d'; + arm_uboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; + + mips64_efi_ldflags = '-Wl,-r,-d'; + mips64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame -R .MIPS.abiflags'; + + arm_coreboot_ldflags = '-Wl,-r,-d'; + arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; + + i386_pc_startup = kern/i386/pc/startup.S; + i386_efi_startup = kern/i386/efi/startup.S; + x86_64_efi_startup = kern/x86_64/efi/startup.S; + i386_xen_startup = kern/i386/xen/startup.S; + x86_64_xen_startup = kern/x86_64/xen/startup.S; + i386_xen_pvh_startup = kern/i386/xen/startup_pvh.S; + i386_qemu_startup = kern/i386/qemu/startup.S; + i386_ieee1275_startup = kern/i386/ieee1275/startup.S; + i386_coreboot_startup = kern/i386/coreboot/startup.S; + i386_multiboot_startup = kern/i386/coreboot/startup.S; + mips_startup = kern/mips/startup.S; + mips64_efi_startup = kern/mips64/efi/startup.S; + sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S; + powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S; + arm_uboot_startup = kern/arm/startup.S; + arm_coreboot_startup = kern/arm/startup.S; + arm_efi_startup = kern/arm/efi/startup.S; + arm64_efi_startup = kern/arm64/efi/startup.S; + riscv32_efi_startup = kern/riscv/efi/startup.S; + riscv64_efi_startup = kern/riscv/efi/startup.S; + + common = kern/command.c; + common = kern/corecmd.c; + common = kern/device.c; + common = kern/disk.c; + common = kern/dl.c; + common = kern/env.c; + common = kern/err.c; + common = kern/file.c; + common = kern/fs.c; + common = kern/list.c; + common = kern/main.c; + common = kern/misc.c; + common = kern/parser.c; + common = kern/partition.c; + common = kern/rescue_parser.c; + common = kern/rescue_reader.c; + common = kern/term.c; + + noemu = kern/compiler-rt.c; + noemu = kern/mm.c; + noemu = kern/time.c; + noemu = kern/generic/millisleep.c; + + noemu_nodist = symlist.c; + + mips = kern/generic/rtc_get_time_ms.c; + + ieee1275 = disk/ieee1275/ofdisk.c; + ieee1275 = kern/ieee1275/cmain.c; + ieee1275 = kern/ieee1275/ieee1275.c; + ieee1275 = kern/ieee1275/mmap.c; + ieee1275 = kern/ieee1275/openfw.c; + ieee1275 = term/ieee1275/console.c; + ieee1275 = kern/ieee1275/init.c; + + uboot = disk/uboot/ubootdisk.c; + uboot = kern/uboot/uboot.c; + uboot = kern/uboot/init.c; + uboot = kern/uboot/hw.c; + uboot = term/uboot/console.c; + arm_uboot = kern/arm/uboot/init.c; + arm_uboot = kern/arm/uboot/uboot.S; + + arm_coreboot = kern/arm/coreboot/init.c; + arm_coreboot = kern/arm/coreboot/timer.c; + arm_coreboot = kern/arm/coreboot/coreboot.S; + arm_coreboot = lib/fdt.c; + arm_coreboot = bus/fdt.c; + arm_coreboot = term/ps2.c; + arm_coreboot = term/arm/pl050.c; + arm_coreboot = term/arm/cros.c; + arm_coreboot = term/arm/cros_ec.c; + arm_coreboot = bus/spi/rk3288_spi.c; + arm_coreboot = commands/keylayouts.c; + arm_coreboot = kern/arm/coreboot/dma.c; + + terminfoinkernel = term/terminfo.c; + terminfoinkernel = term/tparm.c; + terminfoinkernel = commands/extcmd.c; + terminfoinkernel = lib/arg.c; + + softdiv = lib/division.c; + + i386 = kern/i386/dl.c; + i386_xen = kern/i386/dl.c; + i386_xen_pvh = kern/i386/dl.c; + + i386_coreboot = kern/i386/coreboot/init.c; + i386_multiboot = kern/i386/coreboot/init.c; + i386_qemu = kern/i386/qemu/init.c; + i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c; + coreboot = video/coreboot/cbfb.c; + + efi = disk/efi/efidisk.c; + efi = kern/efi/efi.c; + efi = kern/efi/init.c; + efi = kern/efi/mm.c; + efi = term/efi/console.c; + efi = kern/acpi.c; + efi = kern/efi/acpi.c; + i386_coreboot = kern/i386/pc/acpi.c; + i386_multiboot = kern/i386/pc/acpi.c; + i386_coreboot = kern/acpi.c; + i386_multiboot = kern/acpi.c; + + x86 = kern/i386/tsc.c; + x86 = kern/i386/tsc_pit.c; + i386_efi = kern/i386/efi/tsc.c; + x86_64_efi = kern/i386/efi/tsc.c; + i386_efi = kern/i386/tsc_pmtimer.c; + i386_coreboot = kern/i386/tsc_pmtimer.c; + x86_64_efi = kern/i386/tsc_pmtimer.c; + + i386_efi = kern/i386/efi/init.c; + i386_efi = bus/pci.c; + + x86_64 = kern/x86_64/dl.c; + x86_64_xen = kern/x86_64/dl.c; + x86_64_efi = kern/x86_64/efi/callwrap.S; + x86_64_efi = kern/i386/efi/init.c; + x86_64_efi = bus/pci.c; + + xen = kern/i386/tsc.c; + xen = kern/i386/xen/tsc.c; + x86_64_xen = kern/x86_64/xen/hypercall.S; + i386_xen = kern/i386/xen/hypercall.S; + xen = kern/xen/init.c; + xen = term/xen/console.c; + xen = disk/xen/xendisk.c; + xen = commands/boot.c; + + i386_xen_pvh = commands/boot.c; + i386_xen_pvh = disk/xen/xendisk.c; + i386_xen_pvh = kern/i386/tsc.c; + i386_xen_pvh = kern/i386/xen/tsc.c; + i386_xen_pvh = kern/i386/xen/pvh.c; + i386_xen_pvh = kern/xen/init.c; + i386_xen_pvh = term/xen/console.c; + + ia64_efi = kern/ia64/efi/startup.S; + ia64_efi = kern/ia64/efi/init.c; + ia64_efi = kern/ia64/dl.c; + ia64_efi = kern/ia64/dl_helper.c; + ia64_efi = kern/ia64/cache.c; + + arm_efi = kern/arm/efi/init.c; + arm_efi = kern/efi/fdt.c; + + arm64_efi = kern/arm64/efi/init.c; + arm64_efi = kern/efi/fdt.c; + + riscv32_efi = kern/riscv/efi/init.c; + riscv32_efi = kern/efi/fdt.c; + + riscv64_efi = kern/riscv/efi/init.c; + riscv64_efi = kern/efi/fdt.c; + + i386_pc = kern/i386/pc/init.c; + i386_pc = kern/i386/pc/mmap.c; + i386_pc = term/i386/pc/console.c; + + i386_qemu = bus/pci.c; + i386_qemu = kern/vga_init.c; + i386_qemu = kern/i386/qemu/mmap.c; + + coreboot = kern/coreboot/mmap.c; + i386_coreboot = kern/i386/coreboot/cbtable.c; + coreboot = kern/coreboot/cbtable.c; + arm_coreboot = kern/arm/coreboot/cbtable.c; + + i386_multiboot = kern/i386/multiboot_mmap.c; + + mips = kern/mips/cache.S; + mips = kern/mips/dl.c; + mips = kern/mips/init.c; + + mips_qemu_mips = kern/mips/qemu_mips/init.c; + mips_qemu_mips = term/ns8250.c; + mips_qemu_mips = term/serial.c; + mips_qemu_mips = term/at_keyboard.c; + mips_qemu_mips = term/ps2.c; + mips_qemu_mips = commands/boot.c; + mips_qemu_mips = commands/keylayouts.c; + mips_qemu_mips = term/i386/pc/vga_text.c; + mips_qemu_mips = kern/vga_init.c; + + mips_arc = kern/mips/arc/init.c; + mips_arc = term/arc/console.c; + mips_arc = disk/arc/arcdisk.c; + + mips_loongson = term/ns8250.c; + mips_loongson = bus/bonito.c; + mips_loongson = bus/cs5536.c; + mips_loongson = bus/pci.c; + mips_loongson = kern/mips/loongson/init.c; + mips_loongson = term/at_keyboard.c; + mips_loongson = term/ps2.c; + mips_loongson = commands/boot.c; + mips_loongson = term/serial.c; + mips_loongson = video/sm712.c; + mips_loongson = video/sis315pro.c; + mips_loongson = video/radeon_fuloong2e.c; + mips_loongson = video/radeon_yeeloong3a.c; + extra_dist = video/sm712_init.c; + extra_dist = video/sis315_init.c; + mips_loongson = commands/keylayouts.c; + + mips64 = kern/mips64/init.c; + mips64 = kern/mips64/dl.c; + mips64 = kern/mips64/cache.S; + mips64 = kern/generic/rtc_get_time_ms.c; + mips64_efi = kern/mips64/efi/init.c; + mips64_efi = kern/mips64/efi/loongson.c; + mips64_efi = lib/mips64/efi/loongson.c; + mips64_efi = lib/mips64/efi/loongson_asm.S; + + powerpc_ieee1275 = kern/powerpc/cache.S; + powerpc_ieee1275 = kern/powerpc/dl.c; + powerpc_ieee1275 = kern/powerpc/compiler-rt.S; + + sparc64_ieee1275 = kern/sparc64/cache.S; + sparc64_ieee1275 = kern/sparc64/dl.c; + sparc64_ieee1275 = kern/sparc64/ieee1275/ieee1275.c; + sparc64_ieee1275 = disk/ieee1275/obdisk.c; + + arm = kern/arm/dl.c; + arm = kern/arm/dl_helper.c; + arm = kern/arm/cache_armv6.S; + arm = kern/arm/cache_armv7.S; + extra_dist = kern/arm/cache.S; + arm = kern/arm/cache.c; + arm = kern/arm/compiler-rt.S; + + arm64 = kern/arm64/cache.c; + arm64 = kern/arm64/cache_flush.S; + arm64 = kern/arm64/dl.c; + arm64 = kern/arm64/dl_helper.c; + + riscv32 = kern/riscv/cache.c; + riscv32 = kern/riscv/cache_flush.S; + riscv32 = kern/riscv/dl.c; + + riscv64 = kern/riscv/cache.c; + riscv64 = kern/riscv/cache_flush.S; + riscv64 = kern/riscv/dl.c; + + emu = disk/host.c; + emu = kern/emu/cache_s.S; + emu = kern/emu/hostdisk.c; + emu = osdep/unix/hostdisk.c; + emu = osdep/exec.c; + extra_dist = osdep/unix/exec.c; + emu = osdep/devmapper/hostdisk.c; + emu = osdep/hostdisk.c; + emu = kern/emu/hostfs.c; + emu = kern/emu/main.c; + emu = kern/emu/argp_common.c; + emu = kern/emu/misc.c; + emu = kern/emu/mm.c; + emu = kern/emu/time.c; + emu = kern/emu/cache.c; + emu = osdep/emuconsole.c; + extra_dist = osdep/unix/emuconsole.c; + extra_dist = osdep/windows/emuconsole.c; + emu = osdep/dl.c; + extra_dist = osdep/unix/dl.c; + extra_dist = osdep/windows/dl.c; + emu = osdep/sleep.c; + emu = osdep/init.c; + emu = osdep/emunet.c; + extra_dist = osdep/linux/emunet.c; + extra_dist = osdep/basic/emunet.c; + emu = osdep/cputime.c; + extra_dist = osdep/unix/cputime.c; + extra_dist = osdep/windows/cputime.c; + + videoinkernel = term/gfxterm.c; + videoinkernel = font/font.c; + videoinkernel = font/font_cmd.c; + videoinkernel = io/bufio.c; + videoinkernel = video/fb/fbblit.c; + videoinkernel = video/fb/fbfill.c; + videoinkernel = video/fb/fbutil.c; + videoinkernel = video/fb/video_fb.c; + videoinkernel = video/video.c; + + extra_dist = kern/i386/int.S; + extra_dist = kern/i386/realmode.S; + extra_dist = boot/i386/pc/lzma_decode.S; + extra_dist = kern/mips/cache_flush.S; +}; + +program = { + name = grub-emu; + mansection = 1; + + emu = kern/emu/full.c; + emu_nodist = grub_emu_init.c; + + ldadd = 'kernel.exec$(EXEEXT)'; + ldadd = '$(MODULE_FILES)'; + ldadd = 'lib/gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + + enable = emu; +}; + +program = { + name = grub-emu-lite; + + emu = kern/emu/lite.c; + emu_nodist = symlist.c; + + ldadd = 'kernel.exec$(EXEEXT)'; + ldadd = 'lib/gnulib/libgnu.a $(LIBINTL) $(LIBUTIL) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + + enable = emu; +}; + +image = { + name = boot; + i386_pc = boot/i386/pc/boot.S; + i386_qemu = boot/i386/qemu/boot.S; + sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + + i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)'; + i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)'; + + /* The entry point for a.out binaries on sparc64 starts + at 0x4000. Since we are writing the 32 bytes long a.out + header in the assembly code ourselves, we need to tell + the linker to adjust the start of the text segment to + 0x4000 - 0x20 = 0x3fe0. + */ + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; + sparc64_ieee1275_objcopyflags = '-O binary'; + + objcopyflags = '-O binary'; + enable = i386_pc; + enable = i386_qemu; + enable = sparc64_ieee1275; +}; + +image = { + name = boot_hybrid; + i386_pc = boot/i386/pc/boot.S; + + cppflags = '-DHYBRID_BOOT=1'; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + + objcopyflags = '-O binary'; + enable = i386_pc; +}; + +image = { + name = cdboot; + + i386_pc = boot/i386/pc/cdboot.S; + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + + sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S; + + /* See comment for sparc64_ieee1275_ldflags above. */ + sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0'; + sparc64_ieee1275_objcopyflags = '-O binary'; + sparc64_ieee1275_cppflags = '-DCDBOOT=1'; + + objcopyflags = '-O binary'; + + enable = sparc64_ieee1275; + enable = i386_pc; +}; + +image = { + name = pxeboot; + i386_pc = boot/i386/pc/pxeboot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + + objcopyflags = '-O binary'; + enable = i386_pc; +}; + +image = { + name = diskboot; + i386_pc = boot/i386/pc/diskboot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8000'; + + sparc64_ieee1275 = boot/sparc64/ieee1275/diskboot.S; + sparc64_ieee1275_ldflags = '-Wl,-Ttext=0x4200'; + + objcopyflags = '-O binary'; + + enable = i386_pc; + enable = sparc64_ieee1275; +}; + +image = { + name = lnxboot; + i386_pc = boot/i386/pc/lnxboot.S; + + i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; + i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x6000'; + + objcopyflags = '-O binary'; + enable = i386_pc; +}; + +image = { + name = xz_decompress; + mips = boot/mips/startup_raw.S; + common = boot/decompressor/minilib.c; + common = boot/decompressor/xz.c; + common = lib/xzembed/xz_dec_bcj.c; + common = lib/xzembed/xz_dec_lzma2.c; + common = lib/xzembed/xz_dec_stream.c; + common = kern/compiler-rt.c; + + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -DGRUB_EMBED_DECOMPRESSOR=1'; + + objcopyflags = '-O binary'; + mips_ldflags = '-Wl,-Ttext,$(TARGET_DECOMPRESSOR_LINK_ADDR)'; + cflags = '-Wno-unreachable-code'; + enable = mips; +}; + +image = { + name = none_decompress; + mips = boot/mips/startup_raw.S; + common = boot/decompressor/none.c; + + cppflags = '-DGRUB_EMBED_DECOMPRESSOR=1'; + + objcopyflags = '-O binary'; + mips_ldflags = '-Wl,-Ttext,$(TARGET_DECOMPRESSOR_LINK_ADDR)'; + enable = mips; +}; + +image = { + name = lzma_decompress; + i386_pc = boot/i386/pc/startup_raw.S; + i386_pc_nodist = rs_decoder.h; + + objcopyflags = '-O binary'; + ldflags = '$(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT),0x8200'; + enable = i386_pc; +}; + +image = { + name = fwstart; + mips_loongson = boot/mips/loongson/fwstart.S; + objcopyflags = '-O binary'; + ldflags = '-Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; + enable = mips_loongson; +}; + +image = { + name = fwstart_fuloong2f; + mips_loongson = boot/mips/loongson/fuloong2f.S; + objcopyflags = '-O binary'; + ldflags = '-Wl,-N,-S,-Ttext,0xbfc00000,-Bstatic'; + enable = mips_loongson; +}; + +module = { + name = disk; + common = lib/disk.c; + extra_dist = kern/disk_common.c; +}; + +module = { + name = trig; + common_nodist = trigtables.c; + extra_dist = gentrigtables.c; +}; + +module = { + name = cs5536; + x86 = bus/cs5536.c; + enable = x86; +}; + +module = { + name = lsspd; + mips_loongson = commands/mips/loongson/lsspd.c; + enable = mips_loongson; +}; + +module = { + name = usb; + common = bus/usb/usb.c; + common = bus/usb/usbtrans.c; + common = bus/usb/usbhub.c; + enable = usb; +}; + +module = { + name = usbserial_common; + common = bus/usb/serial/common.c; + enable = usb; +}; + +module = { + name = usbserial_pl2303; + common = bus/usb/serial/pl2303.c; + enable = usb; +}; + +module = { + name = usbserial_ftdi; + common = bus/usb/serial/ftdi.c; + enable = usb; +}; + +module = { + name = usbserial_usbdebug; + common = bus/usb/serial/usbdebug_late.c; + enable = usb; +}; + +module = { + name = uhci; + common = bus/usb/uhci.c; + enable = pci; +}; + +module = { + name = ohci; + common = bus/usb/ohci.c; + enable = pci; +}; + +module = { + name = ehci; + common = bus/usb/ehci.c; + arm_coreboot = bus/usb/ehci-fdt.c; + pci = bus/usb/ehci-pci.c; + enable = pci; + enable = arm_coreboot; +}; + +module = { + name = pci; + common = bus/pci.c; + i386_ieee1275 = bus/i386/ieee1275/pci.c; + + enable = i386_pc; + enable = i386_ieee1275; + enable = i386_coreboot; + enable = i386_multiboot; +}; + +module = { + name = nativedisk; + common = commands/nativedisk.c; + + enable = x86; + enable = mips_loongson; + enable = mips_qemu_mips; +}; + +module = { + name = emupci; + common = bus/emu/pci.c; + common = commands/lspci.c; + + enable = emu; + condition = COND_GRUB_EMU_PCI; +}; + +module = { + name = lsdev; + common = commands/arc/lsdev.c; + + enable = mips_arc; +}; + +module = { + name = lsxen; + common = commands/xen/lsxen.c; + + enable = xen; +}; + +module = { + name = cmostest; + common = commands/i386/cmostest.c; + enable = cmos; +}; + +module = { + name = cmosdump; + common = commands/i386/cmosdump.c; + enable = cmos; +}; + +module = { + name = iorw; + common = commands/iorw.c; + enable = x86; +}; + +module = { + name = cbtable; + common = kern/i386/coreboot/cbtable.c; + common = kern/coreboot/cbtable.c; + enable = i386_pc; + enable = i386_efi; + enable = i386_qemu; + enable = i386_multiboot; + enable = i386_ieee1275; + enable = x86_64_efi; +}; + +module = { + name = cbtime; + common = commands/i386/coreboot/cb_timestamps.c; + enable = x86; +}; + +module = { + name = cbls; + common = commands/i386/coreboot/cbls.c; + enable = x86; +}; + +module = { + name = cbmemc; + common = term/i386/coreboot/cbmemc.c; + enable = x86; +}; + +module = { + name = regexp; + common = commands/regexp.c; + common = commands/wildcard.c; + common = lib/gnulib/regex.c; + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; +}; + +module = { + name = acpi; + + common = commands/acpi.c; + i386_pc = kern/acpi.c; + i386_pc = kern/i386/pc/acpi.c; + + enable = efi; + enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; +}; + +module = { + name = lsacpi; + + common = commands/lsacpi.c; + + enable = efi; + enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; +}; + +module = { + name = lsefisystab; + + common = commands/efi/lsefisystab.c; + + enable = efi; +}; + +module = { + name = lssal; + + common = commands/efi/lssal.c; + + enable = efi; +}; + +module = { + name = lsefimmap; + + common = commands/efi/lsefimmap.c; + + enable = efi; +}; + +module = { + name = lsefi; + common = commands/efi/lsefi.c; + enable = efi; +}; + +module = { + name = efifwsetup; + efi = commands/efi/efifwsetup.c; + enable = efi; +}; + +module = { + name = blocklist; + common = commands/blocklist.c; +}; + +module = { + name = blscfg; + common = commands/blscfg.c; + common = commands/loadenv.h; + enable = powerpc_ieee1275; + enable = efi; + enable = i386_pc; + enable = emu; +}; + +module = { + name = boot; + common = commands/boot.c; + i386_pc = lib/i386/pc/biosnum.c; + enable = x86; + enable = emu; + enable = sparc64_ieee1275; + enable = powerpc_ieee1275; + enable = mips_arc; + enable = mips64_efi; + enable = ia64_efi; + enable = arm_efi; + enable = arm64_efi; + enable = arm_uboot; + enable = arm_coreboot; + enable = riscv32_efi; + enable = riscv64_efi; +}; + +module = { + name = cat; + common = commands/cat.c; +}; + +module = { + name = cmp; + common = commands/cmp.c; +}; + +module = { + name = configfile; + common = commands/configfile.c; +}; + +module = { + name = cpuid; + common = commands/i386/cpuid.c; + enable = x86; + enable = i386_xen_pvh; + enable = i386_xen; + enable = x86_64_xen; +}; + +module = { + name = date; + common = commands/date.c; +}; + +module = { + name = drivemap; + + i386_pc = commands/i386/pc/drivemap.c; + i386_pc = commands/i386/pc/drivemap_int13h.S; + enable = i386_pc; +}; + +module = { + name = echo; + common = commands/echo.c; +}; + +module = { + name = eval; + common = commands/eval.c; +}; + +module = { + name = extcmd; + common = commands/extcmd.c; + common = lib/arg.c; + enable = terminfomodule; +}; + +module = { + name = fixvideo; + common = commands/efi/fixvideo.c; + enable = i386_efi; + enable = x86_64_efi; +}; + +module = { + name = fwload; + efi = commands/efi/fwload.c; + enable = efi; +}; + +module = { + name = gptsync; + common = commands/gptsync.c; +}; + +module = { + name = halt; + nopc = commands/halt.c; + i386_pc = commands/i386/pc/halt.c; + i386_pc = commands/acpihalt.c; + i386_coreboot = commands/acpihalt.c; + i386_multiboot = commands/acpihalt.c; + i386_efi = commands/acpihalt.c; + x86_64_efi = commands/acpihalt.c; + i386_multiboot = lib/i386/halt.c; + i386_coreboot = lib/i386/halt.c; + i386_qemu = lib/i386/halt.c; + xen = lib/xen/halt.c; + i386_xen_pvh = lib/xen/halt.c; + efi = lib/efi/halt.c; + ieee1275 = lib/ieee1275/halt.c; + emu = lib/emu/halt.c; + uboot = lib/dummy/halt.c; + arm_coreboot = lib/dummy/halt.c; +}; + +module = { + name = reboot; + i386 = lib/i386/reboot.c; + i386 = lib/i386/reboot_trampoline.S; + powerpc_ieee1275 = lib/ieee1275/reboot.c; + sparc64_ieee1275 = lib/ieee1275/reboot.c; + mips_arc = lib/mips/arc/reboot.c; + mips_loongson = lib/mips/loongson/reboot.c; + mips_qemu_mips = lib/mips/qemu_mips/reboot.c; + xen = lib/xen/reboot.c; + i386_xen_pvh = lib/xen/reboot.c; + uboot = lib/uboot/reboot.c; + arm_coreboot = lib/dummy/reboot.c; + common = commands/reboot.c; +}; + +module = { + name = hashsum; + common = commands/hashsum.c; +}; + +module = { + name = pgp; + common = commands/pgp.c; + cflags = '$(CFLAGS_POSIX)'; + cppflags = '-I$(srcdir)/lib/posix_wrap'; +}; + +module = { + name = verifiers; + common = commands/verifiers.c; +}; + +module = { + name = shim_lock; + common = commands/efi/shim_lock.c; + enable = x86_64_efi; +}; + +module = { + name = hdparm; + common = commands/hdparm.c; + enable = pci; + enable = mips_qemu_mips; +}; + +module = { + name = help; + common = commands/help.c; +}; + +module = { + name = hexdump; + common = commands/hexdump.c; + common = lib/hexdump.c; +}; + +module = { + name = keystatus; + common = commands/keystatus.c; +}; + +module = { + name = loadbios; + common = commands/efi/loadbios.c; + enable = i386_efi; + enable = x86_64_efi; +}; + +module = { + name = loadenv; + common = commands/loadenv.c; + common = commands/loadenv.h; + common = lib/envblk.c; +}; + +module = { + name = ls; + common = commands/ls.c; +}; + +module = { + name = lsmmap; + common = commands/lsmmap.c; +}; + +module = { + name = lspci; + common = commands/lspci.c; + + enable = pci; +}; + +module = { + name = memrw; + common = commands/memrw.c; +}; + +module = { + name = minicmd; + common = commands/minicmd.c; +}; + +module = { + name = parttool; + common = commands/parttool.c; +}; + +module = { + name = password; + common = commands/password.c; +}; + +module = { + name = password_pbkdf2; + common = commands/password_pbkdf2.c; +}; + +module = { + name = play; + x86 = commands/i386/pc/play.c; + enable = x86; +}; + +module = { + name = spkmodem; + x86 = term/spkmodem.c; + enable = x86; +}; + +module = { + name = morse; + x86 = term/morse.c; + enable = x86; +}; + +module = { + name = probe; + common = commands/probe.c; +}; + +module = { + name = read; + common = commands/read.c; +}; + +module = { + name = search; + common = commands/search_wrap.c; + extra_dist = commands/search.c; +}; + +module = { + name = search_fs_file; + common = commands/search_file.c; +}; + +module = { + name = search_fs_uuid; + common = commands/search_uuid.c; +}; + +module = { + name = search_label; + common = commands/search_label.c; +}; + +module = { + name = setpci; + common = commands/setpci.c; + enable = pci; +}; + +module = { + name = pcidump; + common = commands/pcidump.c; + enable = pci; +}; + +module = { + name = sleep; + common = commands/sleep.c; +}; + +module = { + name = smbios; + + common = commands/smbios.c; + efi = commands/efi/smbios.c; + i386_pc = commands/i386/pc/smbios.c; + i386_coreboot = commands/i386/pc/smbios.c; + i386_multiboot = commands/i386/pc/smbios.c; + + enable = efi; + enable = i386_pc; + enable = i386_coreboot; + enable = i386_multiboot; +}; + +module = { + name = suspend; + ieee1275 = commands/ieee1275/suspend.c; + enable = i386_ieee1275; + enable = powerpc_ieee1275; +}; + +module = { + name = escc; + ieee1275 = term/ieee1275/escc.c; + enable = powerpc_ieee1275; +}; + +module = { + name = terminal; + common = commands/terminal.c; +}; + +module = { + name = test; + common = commands/test.c; +}; + +module = { + name = true; + common = commands/true.c; +}; + +module = { + name = usbtest; + common = commands/usbtest.c; + enable = usb; +}; + +module = { + name = videoinfo; + common = commands/videoinfo.c; +}; + +module = { + name = videotest; + common = commands/videotest.c; +}; + +module = { + name = xnu_uuid; + common = commands/xnu_uuid.c; +}; + +module = { + name = dm_nv; + common = disk/dmraid_nvidia.c; +}; + +module = { + name = loopback; + common = disk/loopback.c; +}; + +module = { + name = cryptodisk; + common = disk/cryptodisk.c; +}; + +module = { + name = luks; + common = disk/luks.c; + common = disk/AFSplitter.c; +}; + +module = { + name = geli; + common = disk/geli.c; +}; + +module = { + name = lvm; + common = disk/lvm.c; +}; + +module = { + name = ldm; + common = disk/ldm.c; +}; + +module = { + name = mdraid09; + common = disk/mdraid_linux.c; +}; + +module = { + name = mdraid09_be; + common = disk/mdraid_linux_be.c; +}; + +module = { + name = mdraid1x; + common = disk/mdraid1x_linux.c; +}; + +module = { + name = diskfilter; + common = disk/diskfilter.c; +}; + +module = { + name = raid5rec; + common = disk/raid5_recover.c; +}; + +module = { + name = raid6rec; + common = disk/raid6_recover.c; +}; + +module = { + name = scsi; + common = disk/scsi.c; +}; + +module = { + name = memdisk; + common = disk/memdisk.c; +}; + +module = { + name = ata; + common = disk/ata.c; + enable = pci; + enable = mips_qemu_mips; +}; + +module = { + name = ahci; + common = disk/ahci.c; + enable = pci; +}; + +module = { + name = pata; + common = disk/pata.c; + enable = pci; + enable = mips_qemu_mips; +}; + +module = { + name = biosdisk; + i386_pc = disk/i386/pc/biosdisk.c; + enable = i386_pc; +}; + +module = { + name = usbms; + common = disk/usbms.c; + enable = usb; +}; + +module = { + name = nand; + ieee1275 = disk/ieee1275/nand.c; + enable = i386_ieee1275; +}; + +module = { + name = efiemu; + common = efiemu/main.c; + common = efiemu/i386/loadcore32.c; + common = efiemu/i386/loadcore64.c; + i386_pc = efiemu/i386/pc/cfgtables.c; + i386_coreboot = efiemu/i386/pc/cfgtables.c; + i386_multiboot = efiemu/i386/pc/cfgtables.c; + i386_ieee1275 = efiemu/i386/nocfgtables.c; + i386_qemu = efiemu/i386/nocfgtables.c; + common = efiemu/mm.c; + common = efiemu/loadcore_common.c; + common = efiemu/symbols.c; + common = efiemu/loadcore32.c; + common = efiemu/loadcore64.c; + common = efiemu/prepare32.c; + common = efiemu/prepare64.c; + common = efiemu/pnvram.c; + common = efiemu/i386/coredetect.c; + + extra_dist = efiemu/prepare.c; + extra_dist = efiemu/loadcore.c; + extra_dist = efiemu/runtime/efiemu.S; + extra_dist = efiemu/runtime/efiemu.c; + + enable = i386_pc; + enable = i386_coreboot; + enable = i386_ieee1275; + enable = i386_multiboot; + enable = i386_qemu; +}; + +module = { + name = font; + common = font/font.c; + common = font/font_cmd.c; + enable = videomodules; +}; + +module = { + name = procfs; + common = fs/proc.c; +}; + +module = { + name = affs; + common = fs/affs.c; +}; + +module = { + name = afs; + common = fs/afs.c; +}; + +module = { + name = bfs; + common = fs/bfs.c; +}; + +module = { + name = zstd; + common = lib/zstd/debug.c; + common = lib/zstd/entropy_common.c; + common = lib/zstd/error_private.c; + common = lib/zstd/fse_decompress.c; + common = lib/zstd/huf_decompress.c; + common = lib/zstd/module.c; + common = lib/zstd/xxhash.c; + common = lib/zstd/zstd_common.c; + common = lib/zstd/zstd_decompress.c; + cflags = '$(CFLAGS_POSIX) -Wno-undef'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/zstd'; +}; + +module = { + name = btrfs; + common = fs/btrfs.c; + common = lib/crc.c; + cflags = '$(CFLAGS_POSIX) -Wno-undef'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -I$(srcdir)/lib/zstd -DMINILZO_HAVE_CONFIG_H'; +}; + +module = { + name = archelp; + common = fs/archelp.c; +}; + +module = { + name = cbfs; + common = fs/cbfs.c; +}; + +module = { + name = cpio; + common = fs/cpio.c; +}; + +module = { + name = cpio_be; + common = fs/cpio_be.c; +}; + +module = { + name = newc; + common = fs/newc.c; +}; + +module = { + name = odc; + common = fs/odc.c; +}; + +module = { + name = ext2; + common = fs/ext2.c; +}; + +module = { + name = fat; + common = fs/fat.c; +}; + +module = { + name = exfat; + common = fs/exfat.c; +}; + +module = { + name = f2fs; + common = fs/f2fs.c; +}; + +module = { + name = fshelp; + common = fs/fshelp.c; +}; + +module = { + name = hfs; + common = fs/hfs.c; +}; + +module = { + name = hfsplus; + common = fs/hfsplus.c; +}; + +module = { + name = hfspluscomp; + common = fs/hfspluscomp.c; +}; + +module = { + name = iso9660; + common = fs/iso9660.c; +}; + +module = { + name = jfs; + common = fs/jfs.c; +}; + +module = { + name = minix; + common = fs/minix.c; +}; + +module = { + name = minix2; + common = fs/minix2.c; +}; + +module = { + name = minix3; + common = fs/minix3.c; +}; + +module = { + name = minix_be; + common = fs/minix_be.c; +}; + +module = { + name = minix2_be; + common = fs/minix2_be.c; +}; + +module = { + name = minix3_be; + common = fs/minix3_be.c; +}; + +module = { + name = nilfs2; + common = fs/nilfs2.c; +}; + +module = { + name = ntfs; + common = fs/ntfs.c; +}; + +module = { + name = ntfscomp; + common = fs/ntfscomp.c; +}; + +module = { + name = reiserfs; + common = fs/reiserfs.c; +}; + +module = { + name = romfs; + common = fs/romfs.c; +}; + +module = { + name = sfs; + common = fs/sfs.c; +}; + +module = { + name = squash4; + common = fs/squash4.c; + cflags = '$(CFLAGS_POSIX) -Wno-undef'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed -I$(srcdir)/lib/minilzo -I$(srcdir)/lib/zstd -DMINILZO_HAVE_CONFIG_H'; +}; + +module = { + name = tar; + common = fs/tar.c; +}; + +module = { + name = udf; + common = fs/udf.c; +}; + +module = { + name = ufs1; + common = fs/ufs.c; +}; + +module = { + name = ufs1_be; + common = fs/ufs_be.c; +}; + +module = { + name = ufs2; + common = fs/ufs2.c; +}; + +module = { + name = xfs; + common = fs/xfs.c; +}; + +module = { + name = zfs; + common = fs/zfs/zfs.c; + common = fs/zfs/zfs_lzjb.c; + common = fs/zfs/zfs_lz4.c; + common = fs/zfs/zfs_sha256.c; + common = fs/zfs/zfs_fletcher.c; +}; + +module = { + name = zfscrypt; + common = fs/zfs/zfscrypt.c; +}; + +module = { + name = zfsinfo; + common = fs/zfs/zfsinfo.c; +}; + +module = { + name = macbless; + common = commands/macbless.c; +}; + +module = { + name = pxe; + i386_pc = net/drivers/i386/pc/pxe.c; + enable = i386_pc; +}; + +module = { + name = gettext; + common = gettext/gettext.c; +}; + +module = { + name = gfxmenu; + common = gfxmenu/gfxmenu.c; + common = gfxmenu/view.c; + common = gfxmenu/font.c; + common = gfxmenu/icon_manager.c; + common = gfxmenu/theme_loader.c; + common = gfxmenu/widget-box.c; + common = gfxmenu/gui_canvas.c; + common = gfxmenu/gui_circular_progress.c; + common = gfxmenu/gui_box.c; + common = gfxmenu/gui_label.c; + common = gfxmenu/gui_list.c; + common = gfxmenu/gui_image.c; + common = gfxmenu/gui_progress_bar.c; + common = gfxmenu/gui_util.c; + common = gfxmenu/gui_string_util.c; +}; + +/* Added by longpanda for Hiperiso Project */ +module = { + name = hiperiso; + common = hiperiso/hiperiso.c; + common = hiperiso/hiperiso_cmd.c; + common = hiperiso/hiperiso_linux.c; + common = hiperiso/hiperiso_unix.c; + common = hiperiso/hiperiso_windows.c; + common = hiperiso/hiperiso_vhd.c; + common = hiperiso/hiperiso_plugin.c; + common = hiperiso/hiperiso_json.c; + common = hiperiso/hiperiso_browser.c; + common = hiperiso/lzx.c; + common = hiperiso/xpress.c; + common = hiperiso/huffman.c; + common = hiperiso/miniz.c; +}; + +module = { + name = setkey; + common = term/setkey.c; +}; + +module = { + name = mouse; + efi = term/efi/mouse.c; + enable = efi; +}; + +module = { + name = hello; + common = hello/hello.c; +}; + +module = { + name = gzio; + common = io/gzio.c; +}; + +module = { + name = offsetio; + common = io/offset.c; +}; + +module = { + name = bufio; + common = io/bufio.c; + enable = videomodules; +}; + +module = { + name = elf; + common = kern/elf.c; + + extra_dist = kern/elfXX.c; +}; + +module = { + name = crypto; + common = lib/crypto.c; + + extra_dist = lib/libgcrypt-grub/cipher/crypto.lst; +}; + +module = { + name = pbkdf2; + common = lib/pbkdf2.c; +}; + +module = { + name = relocator; + common = lib/relocator.c; + x86 = lib/i386/relocator16.S; + x86 = lib/i386/relocator32.S; + x86 = lib/i386/relocator64.S; + i386_xen_pvh = lib/i386/relocator16.S; + i386_xen_pvh = lib/i386/relocator32.S; + i386_xen_pvh = lib/i386/relocator64.S; + i386 = lib/i386/relocator_asm.S; + i386_xen_pvh = lib/i386/relocator_asm.S; + x86_64 = lib/x86_64/relocator_asm.S; + i386_xen = lib/i386/relocator_asm.S; + x86_64_xen = lib/x86_64/relocator_asm.S; + x86 = lib/i386/relocator.c; + x86 = lib/i386/relocator_common_c.c; + i386_xen_pvh = lib/i386/relocator.c; + i386_xen_pvh = lib/i386/relocator_common_c.c; + ieee1275 = lib/ieee1275/relocator.c; + efi = lib/efi/relocator.c; + mips = lib/mips/relocator_asm.S; + mips = lib/mips/relocator.c; + mips64 = lib/mips64/relocator_asm.S; + mips64 = lib/mips64/relocator.c; + powerpc = lib/powerpc/relocator_asm.S; + powerpc = lib/powerpc/relocator.c; + xen = lib/xen/relocator.c; + i386_xen = lib/i386/xen/relocator.S; + x86_64_xen = lib/x86_64/xen/relocator.S; + xen = lib/i386/relocator_common_c.c; + x86_64_efi = lib/x86_64/efi/relocator.c; + + extra_dist = lib/i386/relocator_common.S; + extra_dist = kern/powerpc/cache_flush.S; + + enable = mips; + enable = mips64; + enable = powerpc; + enable = x86; + enable = i386_xen_pvh; + enable = xen; +}; + +module = { + name = datetime; + cmos = lib/cmos_datetime.c; + efi = lib/efi/datetime.c; + uboot = lib/dummy/datetime.c; + arm_coreboot = lib/dummy/datetime.c; + sparc64_ieee1275 = lib/ieee1275/datetime.c; + powerpc_ieee1275 = lib/ieee1275/datetime.c; + sparc64_ieee1275 = lib/ieee1275/cmos.c; + powerpc_ieee1275 = lib/ieee1275/cmos.c; + xen = lib/xen/datetime.c; + i386_xen_pvh = lib/xen/datetime.c; + + mips_arc = lib/arc/datetime.c; + enable = noemu; +}; + +module = { + name = setjmp; + common = lib/setjmp.S; + extra_dist = lib/i386/setjmp.S; + extra_dist = lib/mips/setjmp.S; + extra_dist = lib/x86_64/setjmp.S; + extra_dist = lib/sparc64/setjmp.S; + extra_dist = lib/powerpc/setjmp.S; + extra_dist = lib/ia64/setjmp.S; + extra_dist = lib/ia64/longjmp.S; + extra_dist = lib/arm/setjmp.S; + extra_dist = lib/arm64/setjmp.S; + extra_dist = lib/riscv/setjmp.S; +}; + +module = { + name = aout; + common = loader/aout.c; + enable = x86; +}; + +module = { + name = bsd; + x86 = loader/i386/bsd.c; + x86 = loader/i386/bsd32.c; + x86 = loader/i386/bsd64.c; + + extra_dist = loader/i386/bsdXX.c; + extra_dist = loader/i386/bsd_pagetable.c; + + enable = x86; +}; + +module = { + name = plan9; + i386_pc = loader/i386/pc/plan9.c; + enable = i386_pc; +}; + + +module = { + name = linux16; + common = loader/i386/pc/linux.c; + enable = x86; +}; + +module = { + name = ntldr; + i386_pc = loader/i386/pc/ntldr.c; + enable = i386_pc; +}; + + +module = { + name = truecrypt; + i386_pc = loader/i386/pc/truecrypt.c; + enable = i386_pc; +}; + + +module = { + name = freedos; + i386_pc = loader/i386/pc/freedos.c; + enable = i386_pc; +}; + +module = { + name = pxechain; + i386_pc = loader/i386/pc/pxechainloader.c; + enable = i386_pc; +}; + +module = { + name = multiboot2; + cppflags = "-DGRUB_USE_MULTIBOOT2"; + + common = loader/multiboot.c; + common = loader/multiboot_mbi2.c; + enable = x86; + enable = i386_xen_pvh; + enable = mips; +}; + +module = { + name = multiboot; + common = loader/multiboot.c; + x86 = loader/i386/multiboot_mbi.c; + i386_xen_pvh = loader/i386/multiboot_mbi.c; + extra_dist = loader/multiboot_elfxx.c; + enable = x86; + enable = i386_xen_pvh; +}; + +module = { + name = xen_boot; + arm64 = loader/arm64/xen_boot.c; + enable = arm64; +}; + +module = { + name = linux; + x86 = loader/i386/linux.c; + i386_xen_pvh = loader/i386/linux.c; + xen = loader/i386/xen.c; + i386_pc = lib/i386/pc/vesa_modes_table.c; + i386_xen_pvh = lib/i386/pc/vesa_modes_table.c; + mips = loader/mips/linux.c; + mips64 = loader/mips64/linux.c; + powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c; + sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; + ia64_efi = loader/ia64/efi/linux.c; + arm_coreboot = loader/arm/linux.c; + arm_efi = loader/arm64/linux.c; + arm_uboot = loader/arm/linux.c; + arm64 = loader/arm64/linux.c; + riscv32 = loader/riscv/linux.c; + riscv64 = loader/riscv/linux.c; + common = loader/linux.c; + common = lib/cmdline.c; + enable = noemu; +}; + +module = { + name = fdt; + efi = loader/efi/fdt.c; + common = lib/fdt.c; + enable = fdt; +}; + +module = { + name = xnu; + x86 = loader/xnu_resume.c; + x86 = loader/i386/xnu.c; + x86 = loader/xnu.c; + + /* Code is pretty generic but relies on RNG which + is available only on few platforms. It's not a + big deal as xnu needs ACPI anyway and we have + RNG on all platforms with ACPI. + */ + enable = i386_multiboot; + enable = i386_coreboot; + enable = i386_pc; + enable = i386_efi; + enable = x86_64_efi; +}; + +module = { + name = random; + x86 = lib/i386/random.c; + common = lib/random.c; + + i386_multiboot = kern/i386/tsc_pmtimer.c; + i386_coreboot = kern/i386/tsc_pmtimer.c; + i386_pc = kern/i386/tsc_pmtimer.c; + + enable = i386_multiboot; + enable = i386_coreboot; + enable = i386_pc; + enable = i386_efi; + enable = x86_64_efi; +}; + +module = { + name = macho; + + common = loader/macho.c; + common = loader/macho32.c; + common = loader/macho64.c; + common = loader/lzss.c; + extra_dist = loader/machoXX.c; +}; + +module = { + name = appleldr; + common = loader/efi/appleloader.c; + enable = i386_efi; + enable = x86_64_efi; +}; + +module = { + name = chain; + efi = loader/efi/chainloader.c; + i386_pc = loader/i386/pc/chainloader.c; + i386_coreboot = loader/i386/coreboot/chainloader.c; + i386_coreboot = lib/LzmaDec.c; + enable = i386_pc; + enable = i386_coreboot; + enable = efi; +}; + +module = { + name = mmap; + common = mmap/mmap.c; + x86 = mmap/i386/uppermem.c; + x86 = mmap/i386/mmap.c; + i386_xen_pvh = mmap/i386/uppermem.c; + i386_xen_pvh = mmap/i386/mmap.c; + + i386_pc = mmap/i386/pc/mmap.c; + i386_pc = mmap/i386/pc/mmap_helper.S; + + efi = mmap/efi/mmap.c; + + mips = mmap/mips/uppermem.c; + + enable = x86; + enable = i386_xen_pvh; + enable = ia64_efi; + enable = arm_efi; + enable = arm64_efi; + enable = riscv32_efi; + enable = riscv64_efi; + enable = mips; + enable = mips64_efi; +}; + +module = { + name = normal; + common = normal/main.c; + common = normal/cmdline.c; + common = normal/dyncmd.c; + common = normal/auth.c; + common = normal/autofs.c; + common = normal/color.c; + common = normal/completion.c; + common = normal/datetime.c; + common = normal/menu.c; + common = normal/menu_entry.c; + common = normal/menu_text.c; + common = normal/misc.c; + common = normal/crypto.c; + common = normal/term.c; + common = normal/context.c; + common = normal/charset.c; + common = lib/getline.c; + + common = script/main.c; + common = script/script.c; + common = script/execute.c; + common = script/function.c; + common = script/lexer.c; + common = script/argv.c; + + common = commands/menuentry.c; + + common = unidata.c; + common_nodist = grub_script.tab.c; + common_nodist = grub_script.yy.c; + common_nodist = grub_script.tab.h; + common_nodist = grub_script.yy.h; + + extra_dist = script/yylex.l; + extra_dist = script/parser.y; + + cflags = '$(CFLAGS_POSIX) -Wno-redundant-decls'; + cppflags = '$(CPPFLAGS_POSIX)'; +}; + +module = { + name = part_acorn; + common = partmap/acorn.c; +}; + +module = { + name = part_amiga; + common = partmap/amiga.c; +}; + +module = { + name = part_apple; + common = partmap/apple.c; +}; + +module = { + name = part_gpt; + common = partmap/gpt.c; +}; + +module = { + name = part_msdos; + common = partmap/msdos.c; +}; + +module = { + name = part_sun; + common = partmap/sun.c; +}; + +module = { + name = part_plan; + common = partmap/plan.c; +}; + +module = { + name = part_dvh; + common = partmap/dvh.c; +}; + +module = { + name = part_bsd; + common = partmap/bsdlabel.c; +}; + +module = { + name = part_sunpc; + common = partmap/sunpc.c; +}; + +module = { + name = part_dfly; + common = partmap/dfly.c; +}; + +module = { + name = msdospart; + common = parttool/msdospart.c; +}; + +module = { + name = at_keyboard; + common = term/at_keyboard.c; + common = term/ps2.c; + enable = x86; +}; + +module = { + name = gfxterm; + common = term/gfxterm.c; + enable = videomodules; +}; + +module = { + name = gfxterm_background; + common = term/gfxterm_background.c; +}; + +module = { + name = serial; + common = term/serial.c; + x86 = term/ns8250.c; + ieee1275 = term/ieee1275/serial.c; + mips_arc = term/arc/serial.c; + efi = term/efi/serial.c; + + enable = terminfomodule; + enable = ieee1275; + enable = mips_arc; +}; + +module = { + name = sendkey; + i386_pc = commands/i386/pc/sendkey.c; + enable = i386_pc; +}; + +module = { + name = terminfo; + common = term/terminfo.c; + common = term/tparm.c; + enable = terminfomodule; +}; + +module = { + name = usb_keyboard; + common = term/usb_keyboard.c; + enable = usb; +}; + +module = { + name = vga; + common = video/i386/pc/vga.c; + enable = i386_pc; +}; + +module = { + name = vga_text; + common = term/i386/pc/vga_text.c; + enable = i386_pc; +}; + +module = { + name = mda_text; + common = term/i386/pc/mda_text.c; + enable = i386_pc; + enable = i386_coreboot_multiboot_qemu; +}; + +module = { + name = video_cirrus; + x86 = video/cirrus.c; + enable = x86; +}; + +module = { + name = video_bochs; + x86 = video/bochs.c; + enable = x86; +}; + +module = { + name = functional_test; + common = tests/lib/functional_test.c; + common = tests/lib/test.c; + common = tests/checksums.h; + common = tests/video_checksum.c; + common = tests/fake_input.c; + common = video/capture.c; +}; + +module = { + name = exfctest; + common = tests/example_functional_test.c; +}; + +module = { + name = strtoull_test; + common = tests/strtoull_test.c; +}; + +module = { + name = setjmp_test; + common = tests/setjmp_test.c; +}; + +module = { + name = signature_test; + common = tests/signature_test.c; + common = tests/signatures.h; +}; + +module = { + name = sleep_test; + common = tests/sleep_test.c; +}; + +module = { + name = xnu_uuid_test; + common = tests/xnu_uuid_test.c; +}; + +module = { + name = pbkdf2_test; + common = tests/pbkdf2_test.c; +}; + +module = { + name = legacy_password_test; + common = tests/legacy_password_test.c; + enable = i386_pc; + enable = i386_xen_pvh; + enable = i386_efi; + enable = x86_64_efi; + enable = emu; + enable = xen; +}; + +module = { + name = div; + common = lib/division.c; + enable = no_softdiv; +}; + +module = { + name = div_test; + common = tests/div_test.c; +}; + +module = { + name = mul_test; + common = tests/mul_test.c; +}; + +module = { + name = shift_test; + common = tests/shift_test.c; +}; + +module = { + name = cmp_test; + common = tests/cmp_test.c; +}; + +module = { + name = ctz_test; + common = tests/ctz_test.c; +}; + +module = { + name = bswap_test; + common = tests/bswap_test.c; +}; + +module = { + name = videotest_checksum; + common = tests/videotest_checksum.c; +}; + +module = { + name = gfxterm_menu; + common = tests/gfxterm_menu.c; +}; + +module = { + name = cmdline_cat_test; + common = tests/cmdline_cat_test.c; +}; + +module = { + name = bitmap; + common = video/bitmap.c; +}; + +module = { + name = bitmap_scale; + common = video/bitmap_scale.c; +}; + +module = { + name = efi_gop; + efi = video/efi_gop.c; + enable = efi; +}; + +module = { + name = efi_uga; + efi = video/efi_uga.c; + enable = i386_efi; + enable = x86_64_efi; +}; + +module = { + name = jpeg; + common = video/readers/jpeg.c; +}; + +module = { + name = png; + common = video/readers/png.c; +}; + +module = { + name = tga; + common = video/readers/tga.c; +}; + +module = { + name = vbe; + common = video/i386/pc/vbe.c; + enable = i386_pc; +}; + +module = { + name = video_fb; + common = video/fb/video_fb.c; + common = video/fb/fbblit.c; + common = video/fb/fbfill.c; + common = video/fb/fbutil.c; + enable = videomodules; +}; + +module = { + name = video; + common = video/video.c; + enable = videomodules; +}; + +module = { + name = video_colors; + common = video/colors.c; +}; + +module = { + name = ieee1275_fb; + ieee1275 = video/ieee1275.c; + enable = powerpc_ieee1275; +}; + +module = { + name = sdl; + emu = video/emu/sdl.c; + enable = emu; + condition = COND_GRUB_EMU_SDL; +}; + +module = { + name = datehook; + common = hook/datehook.c; +}; + +module = { + name = net; + common = net/net.c; + common = net/dns.c; + common = net/bootp.c; + common = net/ip.c; + common = net/udp.c; + common = net/tcp.c; + common = net/icmp.c; + common = net/icmp6.c; + common = net/ethernet.c; + common = net/arp.c; + common = net/netbuff.c; +}; + +module = { + name = tftp; + common = net/tftp.c; +}; + +module = { + name = http; + common = net/http.c; +}; + +module = { + name = ofnet; + common = net/drivers/ieee1275/ofnet.c; + enable = ieee1275; +}; + +module = { + name = ubootnet; + common = net/drivers/uboot/ubootnet.c; + enable = uboot; +}; + +module = { + name = efinet; + common = net/drivers/efi/efinet.c; + enable = efi; +}; + +module = { + name = emunet; + emu = net/drivers/emu/emunet.c; + enable = emu; +}; + +module = { + name = legacycfg; + common = commands/legacycfg.c; + common = lib/legacy_parse.c; + emu = lib/i386/pc/vesa_modes_table.c; + i386_efi = lib/i386/pc/vesa_modes_table.c; + x86_64_efi = lib/i386/pc/vesa_modes_table.c; + xen = lib/i386/pc/vesa_modes_table.c; + + enable = i386_pc; + enable = i386_xen_pvh; + enable = i386_efi; + enable = x86_64_efi; + enable = emu; + enable = xen; +}; + +module = { + name = syslinuxcfg; + common = lib/syslinux_parse.c; + common = commands/syslinuxcfg.c; +}; + +module = { + name = test_blockarg; + common = tests/test_blockarg.c; +}; + +module = { + name = xzio; + common = io/xzio.c; + common = lib/xzembed/xz_dec_bcj.c; + common = lib/xzembed/xz_dec_lzma2.c; + common = lib/xzembed/xz_dec_stream.c; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed'; + cflags='-Wno-unreachable-code'; +}; + +module = { + name = lzopio; + common = io/lzopio.c; + common = lib/minilzo/minilzo.c; + cflags = '$(CFLAGS_POSIX) -Wno-undef -Wno-redundant-decls -Wno-error'; + cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H'; +}; + +module = { + name = testload; + common = commands/testload.c; +}; + +module = { + name = backtrace; + x86 = lib/i386/backtrace.c; + i386_xen_pvh = lib/i386/backtrace.c; + i386_xen = lib/i386/backtrace.c; + x86_64_xen = lib/i386/backtrace.c; + common = lib/backtrace.c; + enable = x86; + enable = i386_xen_pvh; + enable = i386_xen; + enable = x86_64_xen; +}; + +module = { + name = lsapm; + common = commands/i386/pc/lsapm.c; + enable = i386_pc; +}; + +module = { + name = keylayouts; + common = commands/keylayouts.c; + enable = x86; +}; + +module = { + name = priority_queue; + common = lib/priority_queue.c; +}; + +module = { + name = time; + common = commands/time.c; +}; + +module = { + name = cacheinfo; + common = commands/cacheinfo.c; + condition = COND_ENABLE_CACHE_STATS; +}; + +module = { + name = boottime; + common = commands/boottime.c; + condition = COND_ENABLE_BOOT_TIME_STATS; +}; + +module = { + name = adler32; + common = lib/adler32.c; +}; + +module = { + name = crc64; + common = lib/crc64.c; +}; + +module = { + name = mpi; + common = lib/libgcrypt-grub/mpi/mpiutil.c; + common = lib/libgcrypt-grub/mpi/mpi-bit.c; + common = lib/libgcrypt-grub/mpi/mpi-add.c; + common = lib/libgcrypt-grub/mpi/mpi-mul.c; + common = lib/libgcrypt-grub/mpi/mpi-mod.c; + common = lib/libgcrypt-grub/mpi/mpi-gcd.c; + common = lib/libgcrypt-grub/mpi/mpi-div.c; + common = lib/libgcrypt-grub/mpi/mpi-cmp.c; + common = lib/libgcrypt-grub/mpi/mpi-inv.c; + common = lib/libgcrypt-grub/mpi/mpi-pow.c; + common = lib/libgcrypt-grub/mpi/mpi-mpow.c; + common = lib/libgcrypt-grub/mpi/mpih-lshift.c; + common = lib/libgcrypt-grub/mpi/mpih-mul.c; + common = lib/libgcrypt-grub/mpi/mpih-mul1.c; + common = lib/libgcrypt-grub/mpi/mpih-mul2.c; + common = lib/libgcrypt-grub/mpi/mpih-mul3.c; + common = lib/libgcrypt-grub/mpi/mpih-add1.c; + common = lib/libgcrypt-grub/mpi/mpih-sub1.c; + common = lib/libgcrypt-grub/mpi/mpih-div.c; + common = lib/libgcrypt-grub/mpi/mpicoder.c; + common = lib/libgcrypt-grub/mpi/mpih-rshift.c; + common = lib/libgcrypt-grub/mpi/mpi-inline.c; + common = lib/libgcrypt_wrap/mem.c; + + cflags = '$(CFLAGS_GCRY) -Wno-redundant-decls -Wno-sign-compare'; + cppflags = '$(CPPFLAGS_GCRY)'; +}; + +module = { + name = all_video; + common = lib/fake_module.c; +}; + +module = { + name = gdb; + common = gdb/cstub.c; + common = gdb/gdb.c; + i386 = gdb/i386/idt.c; + i386 = gdb/i386/machdep.S; + i386 = gdb/i386/signal.c; + enable = i386; +}; + +module = { + name = testspeed; + common = commands/testspeed.c; +}; + +module = { + name = tpm; + common = commands/tpm.c; + efi = commands/efi/tpm.c; + enable = x86_64_efi; +}; + +module = { + name = tr; + common = commands/tr.c; +}; + +module = { + name = progress; + common = lib/progress.c; +}; + +module = { + name = file; + common = commands/file.c; + common = commands/file32.c; + common = commands/file64.c; + extra_dist = commands/fileXX.c; + common = loader/i386/xen_file.c; + common = loader/i386/xen_file32.c; + common = loader/i386/xen_file64.c; + extra_dist = loader/i386/xen_fileXX.c; +}; +module = { + name = rdmsr; + common = commands/i386/rdmsr.c; + enable = x86; +}; +module = { + name = wrmsr; + common = commands/i386/wrmsr.c; + enable = x86; +}; diff --git a/src/grub2/buildgrub.sh b/src/grub2/buildgrub.sh new file mode 100644 index 0000000..996dd99 --- /dev/null +++ b/src/grub2/buildgrub.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +VT_GRUB_DIR=$PWD + +rm -rf INSTALL +rm -rf SRC +rm -rf NBP +rm -rf PXE + +mkdir SRC +mkdir NBP +mkdir PXE + +tar -xf grub-2.04.tar.xz -C ./SRC/ + +/bin/cp -a ./MOD_SRC/grub-2.04 ./SRC/ + +cd ./SRC/grub-2.04 + + +# build for x86_64-efi +echo '======== build grub2 for x86_64-efi ===============' +make distclean +./autogen.sh +./configure --with-platform=efi --prefix=$VT_GRUB_DIR/INSTALL/ +make -j 16 || exit 1 +sh install.sh uefi + + +#build for i386-efi +echo '======== build grub2 for i386-efi ===============' +make distclean +./autogen.sh +./configure --target=i386 --with-platform=efi --prefix=$VT_GRUB_DIR/INSTALL/ +make -j 16 || exit 1 +sh install.sh i386efi + + + +#build for arm64 EFI +echo '======== build grub2 for arm64-efi ===============' +PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin +make distclean +./autogen.sh +./configure --prefix=$VT_GRUB_DIR/INSTALL/ \ +--target=aarch64 --with-platform=efi \ +--host=x86_64-linux-gnu \ +HOST_CC=x86_64-linux-gnu-gcc \ +BUILD_CC=gcc \ +TARGET_CC=aarch64-linux-gnu-gcc \ +TARGET_OBJCOPY=aarch64-linux-gnu-objcopy \ +TARGET_STRIP=aarch64-linux-gnu-strip TARGET_NM=aarch64-linux-gnu-nm \ +TARGET_RANLIB=aarch64-linux-gnu-ranlib +make -j 16 || exit 1 +sh install.sh arm64 + + +#build for mips64el EFI +#http://ftp.loongnix.org/os/loongnix-server/1.7/os/Source/SPackages/grub2-2.02-0.40.lns7.14.loongnix.src.rpm +make distclean +./autogen.sh +./configure --prefix=/home/share/Hiperiso/GRUB2/INSTALL/ \ +--target=mips64el --with-platform=efi \ +--host=x86_64-linux-gnu \ +HOST_CC=x86_64-linux-gnu-gcc \ +BUILD_CC=gcc \ +TARGET_CC="mips-linux-gnu-gcc -mabi=64 -Wno-error=cast-align -Wno-error=misleading-indentation" \ +TARGET_OBJCOPY=mips-linux-gnu-objcopy \ +TARGET_STRIP=mips-linux-gnu-strip TARGET_NM=mips-linux-gnu-nm \ +TARGET_RANLIB=mips-linux-gnu-ranlib +make -j 16 || exit 1 +sh install.sh mips64el + + + +# build for i386-pc +echo '======== build grub2 for i386-pc ===============' +make distclean +./autogen.sh +./configure --target=i386 --with-platform=pc --prefix=$VT_GRUB_DIR/INSTALL/ +make -j 16 || exit 1 +sh install.sh + + + +cd ../../ + diff --git a/src/grub2/grub/arm64-efi/command.lst b/src/grub2/grub/arm64-efi/command.lst new file mode 100644 index 0000000..aefec3f Binary files /dev/null and b/src/grub2/grub/arm64-efi/command.lst differ diff --git a/src/grub2/grub/arm64-efi/crypto.lst b/src/grub2/grub/arm64-efi/crypto.lst new file mode 100644 index 0000000..bd0a97c Binary files /dev/null and b/src/grub2/grub/arm64-efi/crypto.lst differ diff --git a/src/grub2/grub/arm64-efi/fdt.lst b/src/grub2/grub/arm64-efi/fdt.lst new file mode 100644 index 0000000..ea28d9e Binary files /dev/null and b/src/grub2/grub/arm64-efi/fdt.lst differ diff --git a/src/grub2/grub/arm64-efi/fs.lst b/src/grub2/grub/arm64-efi/fs.lst new file mode 100644 index 0000000..12c6c9d Binary files /dev/null and b/src/grub2/grub/arm64-efi/fs.lst differ diff --git a/src/grub2/grub/arm64-efi/moddep.lst b/src/grub2/grub/arm64-efi/moddep.lst new file mode 100644 index 0000000..c3cca20 Binary files /dev/null and b/src/grub2/grub/arm64-efi/moddep.lst differ diff --git a/src/grub2/grub/arm64-efi/partmap.lst b/src/grub2/grub/arm64-efi/partmap.lst new file mode 100644 index 0000000..720c55e Binary files /dev/null and b/src/grub2/grub/arm64-efi/partmap.lst differ diff --git a/src/grub2/grub/arm64-efi/parttool.lst b/src/grub2/grub/arm64-efi/parttool.lst new file mode 100644 index 0000000..bfa2d4a Binary files /dev/null and b/src/grub2/grub/arm64-efi/parttool.lst differ diff --git a/src/grub2/grub/arm64-efi/terminal.lst b/src/grub2/grub/arm64-efi/terminal.lst new file mode 100644 index 0000000..0f853df Binary files /dev/null and b/src/grub2/grub/arm64-efi/terminal.lst differ diff --git a/src/grub2/grub/arm64-efi/video.lst b/src/grub2/grub/arm64-efi/video.lst new file mode 100644 index 0000000..ad1dbd0 Binary files /dev/null and b/src/grub2/grub/arm64-efi/video.lst differ diff --git a/src/grub2/grub/checksum.cfg b/src/grub2/grub/checksum.cfg new file mode 100644 index 0000000..bdc4fc8 --- /dev/null +++ b/src/grub2/grub/checksum.cfg @@ -0,0 +1,96 @@ + +unset vtchkdef +vt_hisochksum_exist "${HISO_CHKSUM_FILE_PATH}" + +if [ "$VT_EXIST_MD5" = "1" ]; then + if [ -z "$vtchkdef" ]; then + set default=0 + set vtchkdef=1 + fi + menuentry "$VTLANG_CHKSUM_MD5_CALC_CHK" --class=checksum_md5 { + md5sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + vt_cmp_checksum 0 "${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +else + menuentry "$VTLANG_CHKSUM_MD5_CALC" --class=checksum_md5 { + md5sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +fi + +if [ "$VT_EXIST_SHA1" = "1" ]; then + if [ -z "$vtchkdef" ]; then + set default=1 + set vtchkdef=1 + fi + menuentry "$VTLANG_CHKSUM_SHA1_CALC_CHK" --class=checksum_sha1 { + sha1sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + vt_cmp_checksum 1 "${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +else + menuentry "$VTLANG_CHKSUM_SHA1_CALC" --class=checksum_sha1 { + sha1sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +fi + + + +if [ "$VT_EXIST_SHA256" = "1" ]; then + if [ -z "$vtchkdef" ]; then + set default=2 + set vtchkdef=1 + fi + menuentry "$VTLANG_CHKSUM_SHA256_CALC_CHK" --class=checksum_sha256 { + sha256sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + vt_cmp_checksum 2 "${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +else + menuentry "$VTLANG_CHKSUM_SHA256_CALC" --class=checksum_sha256 { + sha256sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +fi + + + +if [ "$VT_EXIST_SHA512" = "1" ]; then + if [ -z "$vtchkdef" ]; then + set default=3 + set vtchkdef=1 + fi + menuentry "$VTLANG_CHKSUM_SHA512_CALC_CHK" --class=checksum_sha512{ + sha512sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + vt_cmp_checksum 3 "${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +else + menuentry "$VTLANG_CHKSUM_SHA512_CALC" --class=checksum_sha512{ + sha512sum "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" + + echo -en "\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } +fi + + +menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo 'Return ...' +} diff --git a/src/grub2/grub/debug.cfg b/src/grub2/grub/debug.cfg new file mode 100644 index 0000000..0c029fe --- /dev/null +++ b/src/grub2/grub/debug.cfg @@ -0,0 +1,294 @@ +# +# VTLANG_CTRL_TEMP_SET must be the first +# And the inside item order can not be changed +# +submenu "$VTLANG_CTRL_TEMP_SET" --class=debug_temp_set --class=F5tool { + menuentry "[ $HISO_WIN11_BYPASS_CHECK ] $VTLANG_WIN11_BYPASS_CHECK" --class=debug_temp_win11_bypass --class=debug_temp_set --class=F5tool \ + HISO_RUN_SET_0_0 { + if [ "$HISO_WIN11_BYPASS_CHECK" = "0" ]; then + set HISO_WIN11_BYPASS_CHECK=1 + else + set HISO_WIN11_BYPASS_CHECK=0 + fi + } + + menuentry "[ $HISO_WIN11_BYPASS_NRO ] $VTLANG_WIN11_BYPASS_NRO" --class=debug_temp_win11_nro --class=debug_temp_set --class=F5tool \ + HISO_RUN_SET_1_0 { + if [ "$HISO_WIN11_BYPASS_NRO" = "0" ]; then + set HISO_WIN11_BYPASS_NRO=1 + else + set HISO_WIN11_BYPASS_NRO=0 + fi + } + + menuentry "[ $HISO_SECONDARY_BOOT_MENU ] $VTLANG_SECONDARY_BOOT_MENU" --class=debug_temp_second_menu --class=debug_temp_set --class=F5tool \ + HISO_RUN_SET_2_0 { + if [ "$HISO_SECONDARY_BOOT_MENU" = "0" ]; then + set HISO_SECONDARY_BOOT_MENU=1 + else + set HISO_SECONDARY_BOOT_MENU=0 + fi + } + + menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." + } +} + + +if [ "$grub_platform" != "pc" ]; then + submenu "$VTLANG_WIN_UEFI_RES_LOCK" --class=debug_uefi_res_lock --class=F5tool { + set vtActive0="[ ]" + set vtActive1="[ ]" + set vtActive2="[ ]" + set vtActive3="[ ]" + if [ "$HISO_WIN_UEFI_RES_LOCK" = "0" ]; then + set vtActive0="[*]" + elif [ "$HISO_WIN_UEFI_RES_LOCK" = "1" ]; then + set vtActive1="[*]" + elif [ "$HISO_WIN_UEFI_RES_LOCK" = "2" ]; then + set vtActive2="[*]" + elif [ "$HISO_WIN_UEFI_RES_LOCK" = "3" ]; then + set vtActive3="[*]" + fi + + menuentry "$vtActive0 $VTLANG_UEFI_RES_LOCK_NONE" --class=debug_uefi_res_lock0 --class=F5tool HISO_RUN_SET_0_1 { + set HISO_WIN_UEFI_RES_LOCK=0 + } + menuentry "$vtActive1 $VTLANG_UEFI_RES_LOCK_MAX" --class=debug_uefi_res_lock1 --class=F5tool HISO_RUN_SET_1_1 { + set HISO_WIN_UEFI_RES_LOCK=1 + } + menuentry "$vtActive2 $VTLANG_UEFI_RES_LOCK_1024_768" --class=debug_uefi_res_lock2 --class=F5tool HISO_RUN_SET_2_1 { + set HISO_WIN_UEFI_RES_LOCK=2 + } + menuentry "$vtActive3 $VTLANG_UEFI_RES_LOCK_BE1024_768" --class=debug_uefi_res_lock3 --class=F5tool HISO_RUN_SET_3_1 { + set HISO_WIN_UEFI_RES_LOCK=3 + } + + menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." + } + } +fi + + +submenu "$VTLANG_MENU_LANG" --class=debug_menu_lang --class=F5tool { + source $prefix/menulang.cfg +} + +source $prefix/power.cfg +source $prefix/hwinfo.cfg +source $prefix/keyboard.cfg + +submenu "$VTLANG_RESOLUTION_CFG" --class=debug_resolution --class=F5tool { + menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." + } + + vt_update_cur_video_mode VT_CUR_MODE + set vdid=0 + while [ $vdid -lt $HISO_VIDEO_MODE_NUM ]; do + vt_get_video_mode $vdid vtCurMode + + unset vtActive + if [ "$vtCurMode" = "$VT_CUR_MODE" ]; then + set vtActive="[*]" + fi + + menuentry "$vtCurMode $vtActive" --class=debug_videomode --class=debug_resolution --class=F5tool HISO_RUN_RET { + terminal_output console + set gfxmode=$1 + terminal_output gfxterm + if [ "$hiso_res_fit" = "1" ]; then + vt_set_theme switch + fi + } + + vt_incr vdid 1 + done +} + +submenu "$VTLANG_SCREEN_MODE" --class=debug_screen_mode --class=F5tool { + menuentry "$VTLANG_SCREEN_TEXT_MODE" --class=debug_text_mode --class=debug_screen_mode --class=F5tool { + vt_push_menu_lang en_US + terminal_output console + } + menuentry "$VTLANG_SCREEN_GUI_MODE" --class=debug_gui_mode --class=debug_screen_mode --class=F5tool { + terminal_output gfxterm + vt_pop_menu_lang + } + menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." + } +} + +if [ -n "$HISO_THEME_COUNT" -a $HISO_THEME_COUNT -gt 1 ]; then + submenu "$VTLANG_THEME_SELECT" --class=debug_theme_select --class=F5tool { + vt_select_theme_cfg + } +fi + +if [ "$grub_platform" != "pc" ]; then + submenu "$VTLANG_UEFI_UTIL" --class=debug_util --class=F5tool { + menuentry "$VTLANG_UTIL_SHOW_EFI_DRV" --class=debug_util_efidrv --class=debug_util --class=F5tool { + vt_push_pager + chainloader ${hiso_path}/hisoutil_${HISO_EFI_ARCH}.efi env_param=${env_param} ${vtdebug_flag} feature=show_efi_drivers + boot + vt_pop_pager + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } + + menuentry "$VTLANG_UTIL_FIX_BLINIT_FAIL" --class=debug_util_blinit --class=debug_util --class=F5tool { + chainloader ${hiso_path}/hisoutil_${HISO_EFI_ARCH}.efi env_param=${env_param} ${vtdebug_flag} feature=fix_windows_mmap + boot + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + } + + menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." + } + } +fi + + +submenu "$VTLANG_JSON_CHK_JSON" --class=debug_json --class=F5tool { + menuentry "$VTLANG_JSON_CHK_CONTROL" --class=debug_control --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path control $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_THEME" --class=debug_theme --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path theme $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_AUTOINS" --class=debug_autoinstall --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path auto_install $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_PERSIST" --class=debug_persistence --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path persistence $hiso_iso_part + + echo -e "\n############### dump persistence ###############" + vt_dump_persistence + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_MENU_ALIAS" --class=debug_menualias --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path menu_alias $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_MENU_TIP" --class=debug_menutip --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path menu_tip $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_MENU_CLASS" --class=debug_menuclass --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path menu_class $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_INJECTION" --class=debug_injection --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path injection $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_AUTO_MEMDISK" --class=debug_automemdisk --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path auto_memdisk $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_IMG_LIST" --class=debug_imagelist --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path image_list $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_IMG_BLIST" --class=debug_imageblacklist --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path image_blacklist $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_CONF_REPLACE" --class=debug_bootconf_replace --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path conf_replace $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_DUD" --class=debug_dud --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path dud $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_JSON_CHK_PASSWORD" --class=debug_pwd --class=debug_json --class=F5tool { + set pager=1 + vt_check_plugin_json $vt_plugin_path password $hiso_iso_part + + echo -en "\n$VTLANG_ENTER_EXIT ..." + read vtInputKey + unset pager + } + + menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." + } +} + + +menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." +} diff --git a/src/grub2/grub/distro/fwts.cfg b/src/grub2/grub/distro/fwts.cfg new file mode 100644 index 0000000..6b138dc --- /dev/null +++ b/src/grub2/grub/distro/fwts.cfg @@ -0,0 +1,15 @@ +set label="writable" + +menuentry 'Firmware Test Suite' --class ubuntu --class gnu-linux --class gnu --class os { + set root='vtimghd,4' + linux /boot/vmlinuz root=LABEL=$label ro console=tty1 console=ttyS0 quiet + initrd /boot/initrd.img +} + +menuentry 'Firmware Test Suite (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os { + set root='vtimghd,4' + echo 'Loading Linux ...' + linux /boot/vmlinuz root=LABEL=$label ro recovery nomodeset + echo 'Loading initial ramdisk ...' + initrd /boot/initrd.img +} diff --git a/src/grub2/grub/fonts/ascii.pf2 b/src/grub2/grub/fonts/ascii.pf2 new file mode 100644 index 0000000..d81ac8b Binary files /dev/null and b/src/grub2/grub/fonts/ascii.pf2 differ diff --git a/src/grub2/grub/fonts/unicode.pf2 b/src/grub2/grub/fonts/unicode.pf2 new file mode 100644 index 0000000..b340859 Binary files /dev/null and b/src/grub2/grub/fonts/unicode.pf2 differ diff --git a/src/grub2/grub/grub.cfg b/src/grub2/grub/grub.cfg new file mode 100644 index 0000000..57063ef --- /dev/null +++ b/src/grub2/grub/grub.cfg @@ -0,0 +1,473 @@ +insmod regexp + +if [ "$grub_platform" = "pc" ]; then + insmod setkey +fi + +function hiperiso_pause { + echo "press Enter to continue ......" + read hisoTmpPause +} + +function hiperiso_debug_pause { + if [ -n "${vtdebug_flag}" ]; then + echo "press Enter to continue ......" + read hisoTmpPause + fi +} + +function hiperiso_cli_console { + if [ -z "$hiso_display_mode" ]; then + terminal_output console + elif [ "$hiso_display_mode" = "GUI" ]; then + terminal_output console + fi +} + +function hiperiso_gui_console { + if [ -z "$hiso_display_mode" ]; then + terminal_output gfxterm + elif [ "$hiso_display_mode" = "GUI" ]; then + terminal_output gfxterm + fi +} + +function hiperiso_language { + configfile $hiso_grub_path/menulang.cfg +} + +function hiperiso_diagnosis { + vt_enum_video_mode + configfile $hiso_grub_path/debug.cfg +} + +function hiperiso_localboot { + configfile $hiso_grub_path/localboot.cfg +} + +function hiperiso_ext_menu { + if [ -e $hiso_plugin_path/hiperiso/hiperiso_grub.cfg ]; then + set hiperiso_new_context=1 + configfile $hiso_plugin_path/hiperiso/hiperiso_grub.cfg + unset hiperiso_new_context + else + echo "hiperiso_grub.cfg NOT exist." + echo -en "\n$HISOLANG_ENTER_EXIT ..." + read hisoInputKey + fi +} + +function hiperiso_show_help { + if [ -f $hiso_grub_path/help.tar.gz ]; then + if [ -z "$hiso_help_txt_mem_addr" ]; then + vt_load_file_to_mem "auto" $hiso_grub_path/help.tar.gz hiso_help_txt_mem + fi + loopback hiso_help_tarfs mem:${hiso_help_txt_mem_addr}:size:${hiso_help_txt_mem_size} + vt_cur_menu_lang hisoCurLang + if [ -f "(hiso_help_tarfs)/help/${hisoCurLang}.txt" ]; then + cat "(hiso_help_tarfs)/help/${hisoCurLang}.txt" + else + cat "(hiso_help_tarfs)/help/en_US.txt" + fi + loopback -d hiso_help_tarfs + fi +} + +function hiperiso_load_menu_lang_file { + if [ -f $hiso_grub_path/menu.tar.gz ]; then + vt_load_file_to_mem "auto" $hiso_grub_path/menu.tar.gz hiso_menu_lang_mem + loopback hiso_menu_tarfs mem:${hiso_menu_lang_mem_addr}:size:${hiso_menu_lang_mem_size} + fi +} + +function hiperiso_checksum { + if [ -f "${hiso_iso_part}${HISO_CHKSUM_FILE_PATH}" ]; then + configfile $hiso_grub_path/checksum.cfg + fi +} + +function iso_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + if vt_check_custom_boot "${hiso_chosen_path}" hiso_vcfg; then + set hiso_chosen_path="${hiso_chosen_path}" + vt_file_basefile "${hiso_chosen_path}" hiso_chosen_file + export hiso_chosen_path + export hiso_chosen_file + hiperiso_debug_pause + configfile "${hiso_iso_part}${hiso_vcfg}" + true + else + hiperiso_boot "${hiso_chosen_path}" + fi +} + +function miso_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + hiperiso_boot "${hiso_chosen_path}" memdisk +} + +function iso_unsupport_menuentry { + echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n" + echo -en "\n$HISOLANG_ENTER_EXIT ..." + read hisoInputKey +} + +function wim_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + hiperiso_boot "${hiso_chosen_path}" +} + +function wim_unsupport_menuentry { + iso_unsupport_menuentry +} + +function efi_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + hiperiso_boot "${hiso_chosen_path}" +} + +function efi_unsupport_menuentry { + iso_unsupport_menuentry +} + +function vhd_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + hiperiso_boot "${hiso_chosen_path}" +} + +function vhd_unsupport_menuentry { + iso_unsupport_menuentry +} + +function hiso_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + hiperiso_boot "${hiso_chosen_path}" +} + +function hiso_unsupport_menuentry { + iso_unsupport_menuentry +} + +function img_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + hiperiso_boot "${hiso_chosen_path}" +} + +function img_unsupport_menuentry { + iso_unsupport_menuentry +} + +function mimg_common_menuentry { + vt_chosen_img_path hiso_chosen_path hiso_chosen_size hiso_chosen_name + + if vt_check_password "${hiso_chosen_path}"; then + return + fi + + hiperiso_boot "${hiso_chosen_path}" memdisk +} + +set HIPERISO_VERSION="1.0.0" + +set HISO_PARAM_NO_ACPI=1 + +set HISO_DEFAULT_MENU_MODE=0 + +set HISO_MEM_DISK_STR="[Memdisk]" +set HISO_ISO_RAW_STR="Compatible Mode" +set HISO_GRUB2_MODE_STR="GRUB2 Mode" +set HISO_WIMBOOT_MODE_STR="WIMBOOT Mode" +set HISO_ISO_UEFI_DRV_STR="UEFI FS" + +set HISO_F2_CMD="vt_browser_disk" +set HISO_F4_CMD="hiperiso_localboot" +set HISO_F5_CMD="hiperiso_diagnosis" +set HISO_F6_CMD="hiperiso_ext_menu" +set HISO_HELP_CMD="hiperiso_show_help" +set HISO_CHKSUM_CMD="hiperiso_checksum" +set HISO_HELP_TXT_LANGUAGE="en_US" +set HISO_CHKSUM_FILE_PATH="X" +set HISO_LANG_CMD="hiperiso_language" + +if [ "$grub_platform" = "pc" ]; then + set HISO_TEXT_MENU_VER="hiperiso $HIPERISO_VERSION BIOS www.hiperiso.net" +else + if [ "$grub_cpu" = "i386" ]; then + set HISO_EFI_ARCH=ia32 + set HISO_TEXT_MENU_VER="hiperiso $HIPERISO_VERSION IA32 www.hiperiso.net" + elif [ "$grub_cpu" = "arm64" ]; then + set HISO_EFI_ARCH=aa64 + set HISO_TEXT_MENU_VER="hiperiso $HIPERISO_VERSION AA64 www.hiperiso.net" + elif [ "$grub_cpu" = "mips64el" ]; then + set HISO_EFI_ARCH=mips + set HISO_TEXT_MENU_VER="hiperiso $HIPERISO_VERSION MIPS www.hiperiso.net" + else + set HISO_EFI_ARCH=x64 + set HISO_TEXT_MENU_VER="hiperiso $HIPERISO_VERSION UEFI www.hiperiso.net" + fi +fi + +vt_device $root hiso_dev + +if [ "$hiso_dev" = "tftp" ]; then + set hiso_path=($root) + for hisoid in 0 1 2 3; do + if [ -f (hd$hisoid,2)/EFI/hiperiso/initramfs.cpio.gz ]; then + set hiso_iso_part=(hd$hisoid,1) + set hiso_efi_part=(hd$hisoid,2) + set hisodev=hd$hisoid + break + fi + done + loadfont ascii + + if [ -n "$hiso_efi_part" ]; then + set hiso_grub_path=$hiso_efi_part/grub + vt_load_file_to_mem "auto" $hiso_grub_path/fonts/unicode.pf2 hiso_font_mem + loadfont mem:${hiso_font_mem_addr}:size:${hiso_font_mem_size} + fi + + if [ -f $hiso_iso_part/hiperiso/hiperiso.json ]; then + set hiso_plugin_path=$hiso_iso_part + else + set hiso_plugin_path=$hiso_grub_path + vt_load_plugin $hiso_plugin_path + fi +else + if [ "$prefix" = "(hiperisodisk)/grub" ]; then + set hiso_path=(hiperisodisk)/hiperiso + else + set hiso_path=($root)/hiperiso + fi + + set hisodev=$hiso_dev + set hiso_iso_part=($hiso_dev,1) + set hiso_efi_part=($hiso_dev,2) + set hiso_grub_path=$hiso_efi_part/grub + + if [ -f $hiso_grub_path/fonts/unicode.pf2 ]; then + vt_load_file_to_mem "auto" $hiso_grub_path/fonts/unicode.pf2 hiso_font_mem + loadfont mem:${hiso_font_mem_addr}:size:${hiso_font_mem_size} + fi + + set hiso_plugin_path=$hiso_iso_part +fi + +vt_load_part_table $hisodev + +hiperiso_load_menu_lang_file + +if [ -f $hiso_iso_part/hiperiso/hiperiso.json ]; then + clear + vt_load_plugin $hiso_iso_part + clear +else + vt_check_json_path_case $hiso_iso_part +fi + +vt_update_sb_policy + +if [ -n "$HISO_MENU_LANGUAGE" ]; then + vt_init_menu_lang "$HISO_MENU_LANGUAGE" +else + vt_init_menu_lang en_US +fi + +if [ -n "$HISO_MENU_TIMEOUT" ]; then + set timeout=$HISO_MENU_TIMEOUT +else + unset timeout +fi + +if [ $HISO_DEFAULT_MENU_MODE -eq 0 ]; then + set HISO_F3_CMD="vt_dynamic_menu 1 1" +else + set HISO_F3_CMD="vt_dynamic_menu 1 0" +fi + +terminal_output console + +if [ -n "$hiso_gfxmode" ]; then + set gfxmode=$hiso_gfxmode + set gfxpayload=keep +else + set gfxmode=1024x768 + set gfxpayload=keep +fi + +if [ "$hiso_display_mode" = "CLI" ]; then + terminal_output console +elif [ "$hiso_display_mode" = "serial" ]; then + if [ -n "$hiso_serial_param" ]; then + serial $hiso_serial_param + fi + terminal_input serial + terminal_output serial +elif [ "$hiso_display_mode" = "serial_console" ]; then + if [ -n "$hiso_serial_param" ]; then + serial $hiso_serial_param + fi + terminal_input serial console + terminal_output serial console +else + if [ "$hiso_gfxmode" = "max" ]; then + set gfxmode=1024x768 + terminal_output gfxterm + vt_enum_video_mode + vt_get_video_mode 0 hisoCurMode + terminal_output console + set gfxmode=$hisoCurMode + terminal_output gfxterm + elif [ "$hiso_res_fit" = "1" ]; then + terminal_output gfxterm + fi + + if [ -n "$hiso_theme" ]; then + vt_set_theme + else + set theme=$hiso_grub_path/themes/hiperiso/theme.txt + fi + terminal_output gfxterm +fi + +if [ "$grub_platform" = "efi" ]; then + set mouse_delta=4000 +fi + +if [ -n "$HISO_DEFAULT_KBD_LAYOUT" ]; then + set_keyboard_layout "$HISO_DEFAULT_KBD_LAYOUT" +fi + +if [ -n "$HISO_PLUGIN_PATH_CASE_MISMATCH" ]; then + clear + echo "$HISO_PLUGIN_PATH_CASE_MISMATCH" + echo -e "\n\nPath case does not match! hiperiso directory and hiperiso.json MUST be all lowercase!" + echo -e "\n\npress ENTER to continue ..." + read hisoInputKey +fi + +if [ -n "$HISO_PLUGIN_SYNTAX_ERROR" ]; then + clear + echo -e "\n Syntax error detected in hiperiso.json, please check! \n" + echo -e "\n press ENTER to continue ..." + read hisoInputKey +fi + +vt_clear_key + +export theme +export gfxmode +export gfxpayload +export hisodev +export hiso_path +export vtdebug_flag +export hiso_iso_fs +export hiso_iso_part +export hiso_efi_part +export HIPERISO_VERSION +export HISO_CUR_VIDEO_MODE +export HISO_EFI_ARCH +export HISO_MEM_DISK_STR +export HISO_ISO_RAW_STR +export HISO_GRUB2_MODE_STR +export HISO_WIMBOOT_MODE_STR +export HISO_ISO_UEFI_DRV_STR +export HISO_F2_CMD +export HISO_F3_CMD +export HISO_F4_CMD +export HISO_F5_CMD +export HISO_F6_CMD +export HISO_HELP_CMD +export HISO_CHKSUM_CMD +export HISO_HELP_TXT_LANGUAGE +export HISO_CHKSUM_FILE_PATH +export HISO_LANG_CMD + +set hiperiso_img_count=0 +vt_list_img $hiso_iso_part hiperiso_img_count + +if [ $hiperiso_img_count -gt 0 ]; then + if [ $HISO_DEFAULT_MENU_MODE -eq 0 ]; then + vt_dynamic_menu 0 0 + else + vt_dynamic_menu 0 1 + fi +else + if [ -n "$HISO_NO_ISO_TIP" ]; then + NO_ISO_MENU="No ISO or supported IMG files found, $HISO_NO_ISO_TIP" + elif [ -n "$HISO_DEFAULT_SEARCH_ROOT" ]; then + NO_ISO_MENU="No ISO or supported IMG files found, please check HISO_DEFAULT_SEARCH_ROOT" + else + NO_ISO_MENU="No ISO or supported IMG files found" + fi + menuentry "$NO_ISO_MENU (Press enter to reboot ...)" { + echo -e "\n Rebooting ... " + reboot + } +fi + +if [ -n "$HISO_DEFAULT_IMAGE" ]; then + if regexp --set 1:hisoHotkey --set 2:hisoDefault "(F[2-9])>(.*)" "$HISO_DEFAULT_IMAGE"; then + set default="$hisoDefault" + if [ -z "$HISO_MENU_TIMEOUT" ]; then + set timeout=0 + else + set timeout=$HISO_MENU_TIMEOUT + fi + export timeout + export default + + vt_fn_mutex_lock 1 + + if [ "$hisoHotkey" = "F2" ]; then + unset timeout + vt_browser_disk + elif [ "$hisoHotkey" = "F4" ]; then + hiperiso_localboot + elif [ "$hisoHotkey" = "F5" ]; then + hiperiso_diagnosis + elif [ "$hisoHotkey" = "F6" ]; then + hiperiso_ext_menu + fi + + vt_fn_mutex_lock 0 + + unset timeout + unset default + fi +fi diff --git a/src/grub2/grub/help/ar_AR.txt b/src/grub2/grub/help/ar_AR.txt new file mode 100644 index 0000000..e7b07b3 --- /dev/null +++ b/src/grub2/grub/help/ar_AR.txt @@ -0,0 +1,18 @@ + L - اختيار اللغة +F1 - عرض معلومات المساعدة +F2 - استعراض وتشغيل الملفات في القرص المحلي +F3 - تبديل وضع القائمة بين Treeview <-> ListView +F4 - تشغيل ويندوز / لينكس على القرص المحلي +F5 - الأدوات المساعده +F6 - تحميل قائمة Grub2 المخصصة +F7 - التبديل بين وضع الواجهة الرسومية <-> وضع النص + +m / Ctrl + m - تحقق من صحة الملفات الصور (md5 / sha1 / sha256 / sha512) +d / Ctrl + d - وضع Memdisk (فقط للصغير WinPE / LiveCD ISO / IMG) +w / Ctrl + w - وضع WIMBOOT (فقط للويندوز القياسي ISO) +r / Ctrl + r - وضع Grub2 (يدعم بعض توزيعات لينكس) +i / Ctrl + i - وضع متوافق (فقط للتدقيق) +u / Ctrl + u - تحميل برنامج التشغيل EFI ISO (فقط للتدقيق، غير مستخدم رسمي) + + +اضغط على ESC للعودة ...... diff --git a/src/grub2/grub/help/bn_BN.txt b/src/grub2/grub/help/bn_BN.txt new file mode 100644 index 0000000..b9faa3d --- /dev/null +++ b/src/grub2/grub/help/bn_BN.txt @@ -0,0 +1,19 @@ + L - ভাষা নির্বাচন করুন +F1 - এই সাহায্য তথ্য প্রদর্শন করুন +F2 - স্থানীয় ডিস্কে ফাইলটি browse করুন এবং boot করুন +F3 - Treeview <-> ListView এর মধ্যে মেনু মোড পরিবর্তন করুন +F4 - স্থানীয় ডিস্কে Windows/Linux boot করুন +F5 - ইউটিলিটিস +F6 - কাস্টম Grub2 মেনু লোড করুন +F7 - GUI মোড <-> TEXT মোডের মধ্যে স্যুইচ করুন + +m/Ctrl+m - চেকসাম ইমেজ ফাইল (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk মোড (শুধুমাত্র ছোট WinPE/LiveCD ISO/IMG জন্য) +w/Ctrl+w - WIMBOOT মোড (শুধুমাত্র Windows/WinPE ISO জন্য) +r/Ctrl+r - Grub2 মোড (শুধুমাত্র কিছু Linux distro জন্য) +i/Ctrl+i - Compatible মোড (শুধুমাত্র debug জন্য) +u/Ctrl+u - ISO efi ড্রাইভার লোড করুন (শুধুমাত্র debug জন্য, সরকারীভাবে ব্যবহার করা যাবে না) + + + +ফিরে আসতে ESC টিপুন ...... diff --git a/src/grub2/grub/help/cs_CZ.txt b/src/grub2/grub/help/cs_CZ.txt new file mode 100644 index 0000000..53a5f0c --- /dev/null +++ b/src/grub2/grub/help/cs_CZ.txt @@ -0,0 +1,19 @@ + L - Výběr jazyka +F1 - Zobrazení nápovědy +F2 - Procházet spouštět soubory na disku +F3 - Přepínat mezi zobrazením stromu a seznamu +F4 - Spustit Windows/Linux na disku +F5 - Nástroje +F6 - Nahrát vlastní Grub2 nabídku +F7 - Přepínat mezi grafickým a textovým režimem + +m/Ctrl+m - Kontrolní součky obrazů (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk režim (pouze pro malé WinPE/LiveCD ISO/IMG) +w/Ctrl+w - WIMBOOT režim (pouze pro Windows/WinPE ISO soubory) +r/Ctrl+r - Grub2 režim (pouze pro některé linuxové distribuce) +i/Ctrl+i - Režim kompatibility (pouze pro ladění) +u/Ctrl+u - Nahrát ISO EFI ovladač (pouze pro ladění, oficiálně nejde použít) + + + +Stiskněte ESC pro návrat ...... diff --git a/src/grub2/grub/help/de_DE.txt b/src/grub2/grub/help/de_DE.txt new file mode 100644 index 0000000..8c4c328 --- /dev/null +++ b/src/grub2/grub/help/de_DE.txt @@ -0,0 +1,19 @@ + L - Sprache auswählen +F1 - Zeigt dieses Hilfemenü +F2 - Durchsuchen und starten von Dateien auf lokalem Datenträger +F3 - Wechsel zwischen Baum-/Listenansicht +F4 - Windows/Linux von lokalem Datenträger starten +F5 - Werkzeuge +F6 - Benutzerdefiniertes Grub2-Menü laden +F7 - Wechseln zwischen Grafik-/Text-Modus + +m/Strg+m - Prüfsumme von Abbilddatei prüfen (md5/sha1/sha256/sha512) +d/Strg+d - Memdisk-Modus (Nur für kleine WinPE/LiveCD ISO/IMG) +w/Strg+w - WIMBOOT-Modus (Nur für Windows/WinPE ISO) +r/Strg+r - Grub2-Modus (Nur für einige Linux-Distributionen) +i/Strg+i - Kompatibilitäts-Modus (Nur für Fehleranalyse) +u/Strg+u - ISO EFI-Treiber laden (Nur für Fehleranalyse, darf offiziell nicht benutzt werden) + + + +ESC für Zurück drücken...... diff --git a/src/grub2/grub/help/el_GR.txt b/src/grub2/grub/help/el_GR.txt new file mode 100644 index 0000000..3cc35e9 --- /dev/null +++ b/src/grub2/grub/help/el_GR.txt @@ -0,0 +1,19 @@ + L - Επιλογή Γλώσσας +F1 - Εμφάνιση πληροφοριών βοήθειας +F2 - Περιήγηση και εκκίνηση αρχείων στον τοπικό δίσκο +F3 - Εναλλαγή λειτουργίας μενού μεταξύ Προβολής Δένδρου <-> Προβολή Λίστας +F4 - Εκκίνηση Windows/Linux στον τοπικό δίσκο +F5 - Εργαλεία +F6 - Φόρτωση προσαρμοσμένου μενού Grub2 +F7 - Εναλλαγή μεταξύ Λειτουργίας GUI <-> Λειτουργίας ΚΕΙΜΕΝΟΥ + +m/Ctrl+m - Αρχεία εικόνας Checksum (md5/sha1/sha256/sha512) +d/Ctrl+d - Λειτουργία Memdisk (Μόνο για μικρά WinPE/LiveCD ISO/IMG) +w/Ctrl+w - Λειτουργία WIMBOOT (Μόνο για αρχεία ISO Windows/WinPE) +r/Ctrl+r - Λειτουργία Grub2 (Μόνο για ορισμένες διανομές Linux) +i/Ctrl+i - Λειτουργία Συμβατότητας (Μόνο για εντοπισμό σφαλμάτων - debugging) +u/Ctrl+u - Φόρτωση προγράμματος οδήγησης ISO EFI (Μόνο για εντοπισμό σφαλμάτων - debugging, δεν μπορεί να χρησιμοποιηθεί επίσημα) + + + +Πατήστε ESC για επιστροφή ...... \ No newline at end of file diff --git a/src/grub2/grub/help/en_US.txt b/src/grub2/grub/help/en_US.txt new file mode 100644 index 0000000..a065f70 --- /dev/null +++ b/src/grub2/grub/help/en_US.txt @@ -0,0 +1,19 @@ + L - Language Select +F1 - Display help information +F2 - Browse and boot files in the local disk +F3 - Switch menu mode between Treeview <-> ListView +F4 - Boot Windows/Linux on the local disk +F5 - Utilities +F6 - Load Custom Grub2 Menu +F7 - Switch between GUI Mode <-> TEXT Mode + +m/Ctrl+m - Checksum image files (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk Mode (Only for small WinPE/LiveCD ISO/IMG) +w/Ctrl+w - WIMBOOT Mode (Only for Windows/WinPE ISO files) +r/Ctrl+r - Grub2 Mode (Only for some Linux distros) +i/Ctrl+i - Compatible Mode (Only for debugging) +u/Ctrl+u - Load ISO EFI driver (Only for debugging, cannot be used officially) + + + +Press ESC to return ...... diff --git a/src/grub2/grub/help/es_ES.txt b/src/grub2/grub/help/es_ES.txt new file mode 100644 index 0000000..11e144d --- /dev/null +++ b/src/grub2/grub/help/es_ES.txt @@ -0,0 +1,19 @@ + L - Seleccionar idioma +F1 - Mostrar información de ayuda +F2 - Navegar y arrancar archivos en el disco local +F3 - Cambiar modo de menú entre Vista de árbol <-> Vista de lista +F4 - Arrancar Windows/Linux en el disco local +F5 - Utilidades +F6 - Cargar menú de Grub2 personalizado +F7 - Cambiar entre Modo GUI <-> Modo texto + +m/Ctrl+m - Suma de comprobación de archivos de imagen (md5/sha1/sha256/sha512) +d/Ctrl+d - Modo Memdisk (Sólo para WinPE/LiveCD ISO/IMG pequeños) +w/Ctrl+w - Modo WIMBOOT (Sólo para archivos Windows/WinPE ISO) +r/Ctrl+r - Modo Grub2 (Sólo para algunas distros de Linux) +i/Ctrl+i - Modo compatible (Sólo para depuración) +u/Ctrl+u - Cargar controlador ISO EFI (Sólo para depuración, uso no oficial) + + + +Presiona ESC para regresar ...... diff --git a/src/grub2/grub/help/fa_IR.txt b/src/grub2/grub/help/fa_IR.txt new file mode 100644 index 0000000..5d1e8a9 --- /dev/null +++ b/src/grub2/grub/help/fa_IR.txt @@ -0,0 +1,19 @@ + L - انتخاب زبان +F1 - نمایش راهنما +F2 - مرور و بوت کردن فایل‌ها در دیسک محلی +F3 - تغییر حالت منو بین درختی <-> لیستی +F4 - بوت کردن ویندوز/لینوکس روی دیسک محلی +F5 - ابزار های کمکی +F6 - بارگیری منوی سفارشی Grub2 +F7 - تغییر حالت بین حالت GUI <-> حالت TEXT + +m/Ctrl+m - اعتبارسنجی فایل ایمیج (md5/sha1/sha256/sha512) +d/Ctrl+d - حالت Memdisk (فقط برای ایمیج های کوچک WinPE/LiveCD ISO/IMG) +w/Ctrl+w - حالت WIMBOOT (فقط برای فایل های ایزو Windows/WinPE) +r/Ctrl+r - حالت Grub2 (فقط برای برخی از توزیع های لینوکس) +i/Ctrl+i - حالت سازگار (فقط برای مشکل زدایی) +u/Ctrl+u - بارگیری درایور ISO EFI (تنها برای مشکل زدایی، نمیتوان به صورت رسمی استفاده کرد) + + + +جهت بازگشت دکمه ESC را کلیک کنید ...... diff --git a/src/grub2/grub/help/fr_FR.txt b/src/grub2/grub/help/fr_FR.txt new file mode 100644 index 0000000..1c8fa18 --- /dev/null +++ b/src/grub2/grub/help/fr_FR.txt @@ -0,0 +1,19 @@ + L - Sélection de la langue +F1 - Afficher l’aide +F2 - Démarrer à partir d’un disque local +F3 - Basculer l’affichage Vue en arbre <-> Vue en liste +F4 - Démarrer un système Windows ou Linux local +F5 - Utilitaires +F6 - Charger le menu GRUB 2 personnalisé +F7 - Basculer entre le mode graphique <-> mode texte + +m/Ctrl+m - Somme de contrôle des images (md5/sha1/sha256/sha512) +d/Ctrl+d - Mode Memdisk (pour WinPE/LiveCD ISO/IMG uniquement) +w/Ctrl+w - Mode WIMBOOT (pour images Windows/WinPE uniquement) +r/Ctrl+r - Mode GRUB 2 (pour quelques distributions Linux uniquement) +i/Ctrl+i - Mode Compatible (pour débug uniquement) +u/Ctrl+u - Charger l’ISO d’un pilote EFI (pour débug uniquement) + + + +Appuyer sur Echap pour sortir… diff --git a/src/grub2/grub/help/hi_HI.txt b/src/grub2/grub/help/hi_HI.txt new file mode 100644 index 0000000..fb1ed99 --- /dev/null +++ b/src/grub2/grub/help/hi_HI.txt @@ -0,0 +1,19 @@ + L - भाषा का चयन +F1 - इस सहायता जानकारी को प्रदर्शित करें +F2 - स्थानीय डिस्क में फ़ाइलें ब्राउज़ करें और बूट करें +F3 - TreeView <-> ListView के बीच मेन्यू मोड स्विच करें +F4 - स्थानीय डिस्क में Windows/Linux बूट करें +F5 - यूटिलिटीज +F6 - कस्टम Grub2 मेनू लोड करें +F7 - GUI मोड <-> Text मोड के बीच स्विच करें + +m/Ctrl+m - चेकसम इमेज फाइल्स (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk मोड (केवल small WinPE/LiveCD ISO/IMG के लिए) +w/Ctrl+w - WIMBOOT मोड (केवल Windows/WinPE ISO के लिए) +r/Ctrl+r - Grub2 मोड (केवल कुछ Linux distros के लिए) +i/Ctrl+i - Compatible मोड (केवल डिबग के लिए) +u/Ctrl+u - ISO efi ड्राइवर लोड करें (केवल debug के लिए, आधिकारिक तौर पर इस्तेमाल नहीं किया जा सकता) + + + +वापस जाने के लिए ESC दबाएं ...... diff --git a/src/grub2/grub/help/hr_HR.txt b/src/grub2/grub/help/hr_HR.txt new file mode 100644 index 0000000..cb2c60d --- /dev/null +++ b/src/grub2/grub/help/hr_HR.txt @@ -0,0 +1,19 @@ + L - Izaberite jezik +F1 - Prikazuje ove informacije +F2 - Pokreće imidž fajlove na lokalnom disku +F3 - Mijenja meni između TreeView <-> ListView +F4 - Pokreće Windows/Linux na lokalnom disku +F5 - Alati +F6 - Učitava prilagođen GRUB2 meni +F7 - Mijenja između GUI <-> TEXT načina rada + +m/Ctrl+m - Generira heš odabranog imidž fajla (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk način rada (samo za male WinPE/LiveCD imidž fajlove) +w/Ctrl+w - WIMBOOT način rada (samo za Windows/WinPE imidž fajlove) +r/Ctrl+r - GRUB2 način rada (samo za neke Linux distribucije) +i/Ctrl+i - Kompatibilni način rada (samo za testiranje) +u/Ctrl+u - Učitava EFI drajver za imidž fajlove (samo za testiranje) + + + +Pritisnite ESC za povratak ...... diff --git a/src/grub2/grub/help/hu_HU.txt b/src/grub2/grub/help/hu_HU.txt new file mode 100644 index 0000000..a57e406 --- /dev/null +++ b/src/grub2/grub/help/hu_HU.txt @@ -0,0 +1,19 @@ + L - Nyelv kiválasztása +F1 - Súgóinformációk megjelenítése +F2 - Helyi lemezen lévő fájlok tallózása és indítása +F3 - Menü mód váltása fanézet <-> listanézet között +F4 - Windows/Linux indítása a helyi lemezről +F5 - Segédprogramok +F6 - Egyéni Grub2 menü betöltése +F7 - Váltás grafikus mód <-> szöveges mód között + +m/Ctrl+m - Lemezképfájlok ellenőrzőösszege (md5/sha1/sha256/sha512) +d/Ctrl+d - Memórialemez mód (csak kis WinPE/LiveCD ISO/IMG esetén) +w/Ctrl+w - WIMBOOT mód (csak Windows/WinPE ISO esetén) +r/Ctrl+r - Grub2 mód (csak néhány Linux disztribúció esetén) +i/Ctrl+i - Kompatibilis mód (csak hibakereséshez) +u/Ctrl+u - ISO EFI illesztőprogram betöltés (csak hibakereséshez, hivatalosan nem használható) + + + +Nyomja meg az ESC billentyűt a visszalépéshez ...... \ No newline at end of file diff --git a/src/grub2/grub/help/id_ID.txt b/src/grub2/grub/help/id_ID.txt new file mode 100644 index 0000000..2d96f24 --- /dev/null +++ b/src/grub2/grub/help/id_ID.txt @@ -0,0 +1,19 @@ + L - Pilih Bahasa +F1 - Tampilkan bantuan informasi ini +F2 - Jelajah dan jalankan boot berkas pada disk lokal +F3 - Beralih mode menu antara Treeview <-> ListView +F4 - Jalankan boot ke Windows/Linux pada disk lokal +F5 - Alat Utilitas +F6 - Memuat ubah suai Grub2 Menu +F7 - Beralih antara mode GUI <-> Mode TEXT + +m/Ctrl+m - Periksa berkas files (md5/sha1/sha256/sha512) +d/Ctrl+d - Mode Memdisk (Hanya untuk ukuran WinPE/LiveCD ISO/IMG yang kecil) +w/Ctrl+w - Mode WIMBOOT (Hanya untuk berkas ISO Windows/WinPE) +r/Ctrl+r - Mode Grub2 (Hanya untuk distro Linux tertentu) +i/Ctrl+i - Mode Kompatibel/Compatible (Hanya untuk debug saja) +u/Ctrl+u - Memuat ISO efi driver (Hanya untuk debug saja, tidak dapat dipakai secara umum) + + + +Tekan ESC untuk kembali ...... diff --git a/src/grub2/grub/help/it_IT.txt b/src/grub2/grub/help/it_IT.txt new file mode 100644 index 0000000..1b14118 --- /dev/null +++ b/src/grub2/grub/help/it_IT.txt @@ -0,0 +1,19 @@ + L - Selezione lingua interfaccia +F1 - Visualizza informazioni Aiuto (questa guida) +F2 - Sfoglia e avvia file nel disco locale +F3 - Cambia modalità menu tra VistaStruttura <-> VistaElenco +F4 - Avvia Windows/Linux dal disco locale +F5 - Utilità +F6 - Carica il menu Grub2 personalizzato +F7 - Cambia modalità GUI <-> modalità TESTO + +m/Ctrl+m - Checksum file immagine (md5/sha1/sha256/sha512) +d/Ctrl+d - Modalità Memdisk (solo per i file ISO/IMG WinPE/LiveCD piccoli) +w/Ctrl+w - Modalità WIMBOOT (solo per i file ISO Windows/WinPE) +r/Ctrl+r - Modalità Grub2 (solo per alcune distro Linux) +i/Ctrl+i - Modalità Compatibile (solo per debugging) +u/Ctrl+u - Carica driver EFI ISO (solo per debugging, non usato ufficialmente) + + + +Premi 'ESC' per continuare... diff --git a/src/grub2/grub/help/ja_JP.txt b/src/grub2/grub/help/ja_JP.txt new file mode 100644 index 0000000..edfa5c5 --- /dev/null +++ b/src/grub2/grub/help/ja_JP.txt @@ -0,0 +1,19 @@ + L - 言語を選択 +F1 - この画面を表示する +F2 - 手元の記憶装置にある起動ファイルを選択して実行する +F3 - 表示形式を切り替える(一覧 ↔ 階層) +F4 - 手元の記憶装置にあるWindowsまたはLinuxを起動する +F5 - 諸機能 +F6 - Grub2の構成を読み込む +F7 - 操作形式を切り替える(GUI ↔ CUI) + +m/Ctrl+m - イメージの検査合計を計算する (md5/sha1/sha256/sha512) +d/Ctrl+d - 主記憶装置上に記憶域を作成する(容量の小さなWinPE・LiveCD専用) +w/Ctrl+w - WIMBOOTモード(Windows/WinPE ISO専用) +r/Ctrl+r - Grub2モード(一部のLinuxディストリビューション専用) +i/Ctrl+i - 互換モード(開発用) +u/Ctrl+u - ISO efiドライバーを読み取る(開発用,非公式) + + + +この画面を閉じるにはESCを押してください ...... diff --git a/src/grub2/grub/help/ka_GE.txt b/src/grub2/grub/help/ka_GE.txt new file mode 100644 index 0000000..6fc55dc --- /dev/null +++ b/src/grub2/grub/help/ka_GE.txt @@ -0,0 +1,19 @@ + L - ინტერფეისის ენის არჩევა +F1 - დამხმარე ინფორმაციის ჩვენება +F2 - ლოკალური დისკის ფაილების დათვალიერება და ჩატვირთვა +F3 - ჩვენების რეჟიმებს შორის გადართვა 'ხის ხედი' <-> 'სიის ხედი' +F4 - ლოკალური დისკიდან Windows/Linux-ის ჩატვირთვა +F5 - ხელსაწყოები +F6 - მომხმარებლის მიერ შექმნილი Grub2 მენიუს ჩატვირთვა +F7 - ჩვენების რეჟიმის გადართვა 'გრაფიკული' <-> 'ტექსტური' + +m/Ctrl+m - ფაილის საკონტროლო ჯამის შემოწმება (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk რეჟიმი (განკუთვნილია მხოლოდ პატარა ზომის WinPE/LiveCD ISO/IMG დისტრიბუტივებისთვის) +w/Ctrl+w - WIMBOOT რეჟიმი (განკუთვნილია მხოლოდ სტანდარტული Windows/WinPE ISO დისტრიბუტივებისთვის) +r/Ctrl+r - Grub2 რეჟიმი (განკუთვნილია მხოლოდ ზოგიერთი Linux დისტრიბუტივებისთვის) +i/Ctrl+i - თავსებადი რეჟიმი (განკუთვნილია მხოლოდ გამართვისთვის) +u/Ctrl+u - ISO EFI დრაივერის ჩატვირთვა (განკუთვნილია მხოლოდ გამართვისთვის, დაუშვებელია ოფიციალური გამოყენება) + + + +დააჭირეთ ESC დაბრუნებისთვის ...... diff --git a/src/grub2/grub/help/ko_KR.txt b/src/grub2/grub/help/ko_KR.txt new file mode 100644 index 0000000..d221eed --- /dev/null +++ b/src/grub2/grub/help/ko_KR.txt @@ -0,0 +1,19 @@ + L - 언어 선택 +F1 - 이 도움말 정보 표시 +F2 - 로컬 디스크에서 파일 찾아보기 및 부팅 +F3 - 트리보기 <-> 목록보기 간에 메뉴 모드 전환 +F4 - 로컬 디스크에서 Windows/Linux 부팅 +F5 - 유틸리티 +F6 - 사용자 지정 Grub2 메뉴 불러오기 +F7 - 그래픽 모드 <-> 텍스트 모드 간에 전환 + +m/Ctrl+m - 이미지 파일 체크섬 (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk 모드 (작은 WinPE/LiveCD ISO/IMG에만 해당) +w/Ctrl+w - WIMBOOT 모드 (표준 Windows/WinPE ISO에만 해당) +r/Ctrl+r - Grub2 모드 (일반 Linux 배포판에만 해당) +i/Ctrl+i - 호환 모드 (디버그 전용, 공식적으로 사용할 수 없음) +u/Ctrl+u - ISO EFI 드라이버 불러오기 (디버그 전용, 공식적으로 사용할 수 없음) + + + +돌아가려면 ESC를 누르십시오 ...... diff --git a/src/grub2/grub/help/lg_UG.txt b/src/grub2/grub/help/lg_UG.txt new file mode 100644 index 0000000..8cee84e --- /dev/null +++ b/src/grub2/grub/help/lg_UG.txt @@ -0,0 +1,19 @@ +L - Londako Olulimi +F1 - Laga obuyambi +F2 - Nnoonya era kozesa Fayiro eziri ku Disk +F3 - Kyusa endabika ya Menu wakati wa Masaasana (Treeview) ne y'olukalala (ListView) +F4 - Ttandika Windows/Linux ku disk erimu +F5 - Ebikozesebwa ebirala +F6 - Kozesa Grub2 menu gyewerobozza +F7 - Okukyuusa okuva mu Bifaananyi (GUI Mode) <-> Bigambo (TEXT Mode) + +m/Ctrl+m - Okukebera Checksum image files (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk Mode (Ya WinPE/LiveCD ISO/IMG entono zokka) +w/Ctrl+w - WIMBOOT Mode (Ya Windows/WinPE ISO zokka) +r/Ctrl+r - Grub2 Mode (Ya nkola za Linux ezimu) +i/Ctrl+i - Compatible Mode (Ya kutereeza kwokka (debugging)) +u/Ctrl+u - Kozesa ISO EFI driver (Ya kutereeza kwokka (debugging), tesobola kukozesebwa mu butongole) + + + +nyiga ESC to okudda emabega ...... diff --git a/src/grub2/grub/help/pl_PL.txt b/src/grub2/grub/help/pl_PL.txt new file mode 100644 index 0000000..590dad1 --- /dev/null +++ b/src/grub2/grub/help/pl_PL.txt @@ -0,0 +1,19 @@ +L - Wybierz język +F1 — Wyświetl informacje pomocy +F2 — przeglądanie i uruchamianie plików na dysku lokalnym +F3 — Przełącz tryb menu pomiędzy Treeview <-> ListView +F4 — Uruchom system Windows/Linux na dysku lokalnym +F5 — Narzędzia +F6 — Załaduj niestandardowe menu Grub2 +F7 - Przełączanie między trybem GUI <-> trybem TEKST + +m/Ctrl+m — Pliki obrazów z sumą kontrolną (md5/sha1/sha256/sha512) +d/Ctrl+d — Tryb Memdisk (tylko dla małych WinPE/LiveCD ISO/IMG) +w/Ctrl+w — tryb WIMBOOT (tylko dla standardowego systemu Windows/WinPE ISO) +r/Ctrl+r — tryb Grub2 (tylko dla niektórych dystrybucji Linuksa) +i/Ctrl+i — tryb zgodności (tylko do debugowania) +u/Ctrl+u — Załaduj sterownik ISO EFI (tylko do debugowania, nie można go oficjalnie używać) + + + +Naciśnij ESC, aby wrócić... \ No newline at end of file diff --git a/src/grub2/grub/help/pt_BR.txt b/src/grub2/grub/help/pt_BR.txt new file mode 100644 index 0000000..b6d29c5 --- /dev/null +++ b/src/grub2/grub/help/pt_BR.txt @@ -0,0 +1,19 @@ + L - Seleção de Idiomas +F1 - Exibir informações de ajuda +F2 - Explorar e inicializar os arquivos no disco local +F3 - Trocar o modo do menu entre Visualização em Árvore <-> Visualização em Lista +F4 - Inicializar o Windows/Linux no disco local +F5 - Utilitários +F6 - Carregar o Menu Personalizado do Grub2 +F7 - Trocar entre o Modo GUI <-> Modo TEXTO + +m/Ctrl+m - Checksum dos arquivos de imagem (md5/sha1/sha256/sha512) +d/Ctrl+d - Modo Memdisk (Só pros pequenos WinPE/LiveCD ISO/IMG) +w/Ctrl+w - Modo WIMBOOT (Só pra arquivos ISO do Windows/WinPE) +r/Ctrl+r - Modo Grub2 (Só pra algumas distros do Linux) +i/Ctrl+i - Modo Compatível (Só pra debugging) +u/Ctrl+u - Carregar o driver EFI da ISO (Só pra debugging, não pode ser usado oficialmente) + + + +Pressione ESC pra retornar... diff --git a/src/grub2/grub/help/pt_PT.txt b/src/grub2/grub/help/pt_PT.txt new file mode 100644 index 0000000..efc5fd0 --- /dev/null +++ b/src/grub2/grub/help/pt_PT.txt @@ -0,0 +1,18 @@ + L - Selecionar idioma +F1 - Mostra esta informação de ajuda +F2 - Navegar e arrancar ficheiros em disco local +F3 - Alternar o modo menu entre Vista de árvore <-> Vista de lista +F4 - Arrancar o Windows/Linux em disco local +F5 - Utilitários +F6 - Carregar menu Grub2 personalizado +F7 - Alternar entre Modo GUI <-> Modo TEXTO + +m/Ctrl+m - Checksum ficheiros de imagem (md5/sha1/sha256/sha512) +d/Ctrl+d - Modo Memdisk (Apenas para pequenos WinPE/LiveCD ISO/IMG) +w/Ctrl+w - Modo WIMBOOT (Apenas para Windows/WinPE ISO padrão) +r/Ctrl+r - Modo Grub2 (Apenas para algumas distros Linux) +i/Ctrl+i - Modo Compatível (Apenas para depuração) +u/Ctrl+u - Carregar o controlador ISO efi (Apenas para depuração, não pode ser utilizado oficialmente) + + +Prima ESC para voltar ...... diff --git a/src/grub2/grub/help/ru_RU.txt b/src/grub2/grub/help/ru_RU.txt new file mode 100644 index 0000000..03d49f1 --- /dev/null +++ b/src/grub2/grub/help/ru_RU.txt @@ -0,0 +1,19 @@ +L - Выбор языка +F1 - Показать эти справочные сведения +F2 - Просмотр и загрузка файлов на локальном диске +F3 - Переключить режим меню между «Вид древом» <-> «Вид списком» +F4 - Загрузка Windows/Linux с локального диска +F5 - Утилиты +F6 - Загрузить пользовательское меню Grub2 +F7 - Переключиться между графическим режимом <-> текстовым режимом + +m/Ctrl+m - Проверить контрольную сумму файлов образа диска (md5/sha1/sha256/sha512) +d/Ctrl+d - Режим Memdisk (только для небольших WinPE/LiveCD ISO/IMG) +w/Ctrl+w - Режим WIMBOOT (только для Windows/WinPE ISO) +r/Ctrl+r - Режим Grub2 (только для некоторых дистрибутивов Linux) +i/Ctrl+i - Совместимый режим (только для отладки) +u/Ctrl+u - Загрузить драйвер ISO EFI (только для отладки, нельзя использовать официально) + + + +Нажмите «ESC», чтобы вернуться ...... diff --git a/src/grub2/grub/help/sl_SI.txt b/src/grub2/grub/help/sl_SI.txt new file mode 100644 index 0000000..cd1b49e --- /dev/null +++ b/src/grub2/grub/help/sl_SI.txt @@ -0,0 +1,19 @@ + L - Izbira jezika +F1 - Prikaz informacij o pomoči +F2 - Brskanje in zagon datotek na lokalnem disku +F3 - Preklop med načinom menija Treeview <-> ListView +F4 - Zagon Windows/Linux na lokalnem disku +F5 - Pripomočki +F6 - Naložitev prilagojenega menija Grub2 +F7 - Preklop med načinom GUI <-> načinom TEXT + +m/Ctrl+m - Preveri kontrolno vsoto slikovnih datotek (md5/sha1/sha256/sha512) +d/Ctrl+d - Način Memdisk (samo za majhne WinPE/LiveCD ISO/IMG) +w/Ctrl+w - Način WIMBOOT (samo za datoteke Windows/WinPE ISO) +r/Ctrl+r – Način Grub2 (samo za nekatere distribucije Linux) +i/Ctrl+i – Združljiv način (samo za odpravljanje napak) +u/Ctrl+u – Naloži ISO EFI gonilnik (samo za odpravljanje napak, uradno se ne more uporabljati) + + + +Pritisnite ESC za vrnitev ...... diff --git a/src/grub2/grub/help/sr_RS.txt b/src/grub2/grub/help/sr_RS.txt new file mode 100644 index 0000000..f00ee59 --- /dev/null +++ b/src/grub2/grub/help/sr_RS.txt @@ -0,0 +1,19 @@ + L - Изаберите језик +F1 - Приказује ове информације +F2 - Покреће имиџ фајлове на локалном диску +F3 - Мења мени између TreeView <-> ListView +F4 - Покреће Windows/Linux на локалном диску +F5 - Алати +F6 - Учитава прилагођен GRUB2 мени +F7 - Мења између GUI <-> TEXT начина рада + +m/Ctrl+m - Генерира хеш одабраног имиџ фајла (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk начин рада (само за мале WinPE/LiveCD имиџ фајлове) +w/Ctrl+w - WIMBOOT начин рада (само за стандардне Windows/WinPE имиџ фајлове) +r/Ctrl+r - GRUB2 начин рада (само за неке Linux дистрибуције) +i/Ctrl+i - Компатибилни начин рада (само за тестирање) +u/Ctrl+u - Учитава EFI драјвер за имиџ фајлове (само за тестирање) + + + +Притисните ESC за повратак ...... diff --git a/src/grub2/grub/help/ta_IN.txt b/src/grub2/grub/help/ta_IN.txt new file mode 100644 index 0000000..3404a35 --- /dev/null +++ b/src/grub2/grub/help/ta_IN.txt @@ -0,0 +1,19 @@ + L - மொழி தேர்வு +F1 - இந்த உதவித் தகவலைக் காட்டு +F2 - உள்ளூர் வட்டில் கோப்புகளை உலாவவும் துவக்கவும் +F3 - Treeview (மரப்பார்வை) <-> ListView (பட்டியல்பார்வை) இடையே மெனு பயன்முறையை மாற்றவும் +F4 - விண்டோஸ்/லினக்ஸை உள்ளூர் வட்டில் துவக்கவும் +F5 - பயன்பாடுகள் +F6 - தனிப்பயன் Grub2 மெனுவை ஏற்றவும் +F7 - GUI பயன்முறை <-> TEXT பயன்முறைக்கு இடையில் மாறவும் + +m/Ctrl+m - செக்சம் படக் கோப்புகள் (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk பயன்முறை (சிறிய WinPE/LiveCD ISO/IMGக்கு மட்டும்) +w/Ctrl+w - WIMBOOT பயன்முறை (நிலையான Windows/WinPE ISO க்கு மட்டும்) +r/Ctrl+r - Grub2 பயன்முறை (சில லினக்ஸ் டிஸ்ட்ரோக்களுக்கு மட்டும்) +i/Ctrl+i - இணக்கமான பயன்முறை (பிழைத்திருத்தத்திற்கு மட்டும்) +u/Ctrl+u - ISO efi இயக்கியை ஏற்றவும் (பிழைத்திருத்தத்திற்கு மட்டும், அதிகாரப்பூர்வமாக பயன்படுத்த முடியாது) + + + +திரும்புவதற்கு ESC ஐ அழுத்தவும் ...... diff --git a/src/grub2/grub/help/tr_TR.txt b/src/grub2/grub/help/tr_TR.txt new file mode 100644 index 0000000..1ebe1e8 --- /dev/null +++ b/src/grub2/grub/help/tr_TR.txt @@ -0,0 +1,19 @@ + L - Dil Seçimi +F1 - Yardım bilgilerini göster +F2 - Yerel diskteki önyükleme dosyalarına göz at ve önyükleme yap +F3 - Menü modunu Ağaç Görünümü <-> Liste Görünümü arasında değiştir +F4 - Windows & Linux'u yerel diskten önyükle +F5 - Hiperiso araçlar menüsü +F6 - Özelleştirilmiş Grub2 menüsünü yükle +F7 - Grafik(GUI) <--> Metin(Text) modları arasında geçiş yap + +m/Ctrl+m - Görüntü dosyalarının sağlama toplamını al (md5/sha1/sha256/sha512) +d/Ctrl+d - Memdisk Modunu başlat(Yalnızca küçük WinPE/LiveCD ISO/IMG'ler için) +w/Ctrl+w - WIMBOOT Modunu başlat(Yalnızca normal Windows/WinPE ISO'ları için) +r/Ctrl+r - Grub2 Modunu başlat (Yalnızca bazı Linux dağıtımları için) +i/Ctrl+i - Uyumluluk Modu (Yalnızca hata ayıklama için) +u/Ctrl+u - ISO EFI sürücüsünü yükle (Sadece hata ayıklama için, resmi olarak kullanılamaz) + + + +Geri dönmek için ESC tuşuna basınız ...... diff --git a/src/grub2/grub/help/uk_UA.txt b/src/grub2/grub/help/uk_UA.txt new file mode 100644 index 0000000..44acc2e --- /dev/null +++ b/src/grub2/grub/help/uk_UA.txt @@ -0,0 +1,19 @@ +L - Обрати мову +F1 - Показати довідку +F2 - Переглянути та завантажити файли з локального диску +F3 - Переключитись між видами деревом <-> списком +F4 - Завантажити Windows/Linux з локального диску +F5 - Інструменти +F6 - Завантажити Custom Grub2 меню +F7 - Переключитись між графічним інтерфейсом <-> текстовим інтерфейсом + +m/Ctrl + m - Контрольна сума образу диску (md5/sha1/sha256/sha512) +d/Ctrl + d - Режим Memdisk (Тільки для невеликих образів WinPE/LiveCD ISO/IMG) +w/Ctrl + w - Режим WIMBOOT (Тільки для ISO-файлів Windows/WinPE) +r/Ctrl + r - Режим Grub2 (Тільки для деяких дистрибутивів Linux) +i/Ctrl + i - Сумісний режим (Тільки для зневадження) +u/Ctrl + u - Завантажити драйвер ISO EFI (Тільки для зневадження, не офіційно) + + + +Натисність ESC для того, щоб повернутися ...... diff --git a/src/grub2/grub/help/vi_VN.txt b/src/grub2/grub/help/vi_VN.txt new file mode 100644 index 0000000..304d5cc --- /dev/null +++ b/src/grub2/grub/help/vi_VN.txt @@ -0,0 +1,19 @@ + L - Lựa chọn ngôn ngữ +F1 - Hiển thị thông tin trợ giúp +F2 - Duyệt tìm và khởi động tệp từ ổ đĩa trên máy +F3 - Chuyển đổi chế độ bảng chọn giữa dạng cây <-> dạng danh sách. +F4 - Khởi động Windows hoặc GNU/Linux trên đĩa cục bộ +F5 - Các tiện ích +F6 - Tải menu GRUB2 tuỳ chọn +F7 - Chuyển giữa giao diện đồ hoạ <-> giao diện văn bản + +m/Ctrl+m - Checksum các tệp ảnh đĩa (md5/sha1/sha256/sha512) +d/Ctrl+d - Chế độ Memdisk (Chỉ dùng cho các tệp ISO/IMG WinPE/LiveCD có kích thước nhỏ) +w/Ctrl+w - Chế độ WIMBOOT (Chỉ dùng cho các tệp ISO Windows/WinPE) +r/Ctrl+r - Chế độ Grub2 (Chỉ dùng cho một vài bản phân phối của GNU/Linux) +i/Ctrl+i - Chế độ tương thích (Chỉ dùng cho việc sửa lỗi) +u/Ctrl+u - Tải ISO của một driver EFI (Chỉ dùng cho việc sửa lỗi, không thể dùng chính thức) + + + +Nhấn ESC để quay lại ...... diff --git a/src/grub2/grub/help/zh_CN.txt b/src/grub2/grub/help/zh_CN.txt new file mode 100644 index 0000000..932a4f2 --- /dev/null +++ b/src/grub2/grub/help/zh_CN.txt @@ -0,0 +1,18 @@ + L - 选择语言 +F1 - 显示本帮助信息 +F2 - 浏览并启动本地硬盘中的镜像文件 +F3 - 菜单显示模式切换。可在列表模式和目录模式之间自由切换。 +F4 - 启动本地硬盘上的 Windows/Linux 等系统。 +F5 - 各类工具 +F6 - 加载自定义 GRUB2 菜单。 +F7 - 界面在文本模式和图形模式之间切换。 + +m/Ctrl+m - 计算文件校验值(md5/sha1/sha256/sha512) +d/Ctrl+d - MEMDISK 模式,把文件加载到内存启动(只适用于文件很小的 WinPE/LiveCD等) +w/Ctrl+w - WIMBOOT 模式 (只适用于 Windows/WinPE 的ISO文件) +r/Ctrl+r - Grub2 模式 (只适用于常见的一些 Linux 系统ISO文件) +i/Ctrl+i - 兼容模式 (只用作调试目的,不能正式使用) +u/Ctrl+u - 加载 ISO efi 驱动(只用作调试目的,不能正式使用) + + +按 ESC 键返回 ...... diff --git a/src/grub2/grub/help/zh_TW.txt b/src/grub2/grub/help/zh_TW.txt new file mode 100644 index 0000000..bbe4dd2 --- /dev/null +++ b/src/grub2/grub/help/zh_TW.txt @@ -0,0 +1,18 @@ +L - 選擇語言 +F1 - 顯示本説明資訊 +F2 - 瀏覽並啟動本地硬碟中的映像檔 +F3 - 功能表顯示模式切換。可在清單模式和目錄模式之間自由切換。 +F4 - 啟動本地硬碟上的 Windows/Linux 等系統。 +F5 - 各類工具 +F6 - 載入自訂 GRUB2 選單。 +F7 - 介面在文字模式和圖形模式之間切換。 + +m/Ctrl+m - 計算檔案校驗值(md5/sha1/sha256/sha512) +d/Ctrl+d - MEMDISK 模式,把檔載入到記憶體啟動(只適用於檔很小的 WinPE/LiveCD等) +w/Ctrl+w - WIMBOOT 模式 (只適用於 Windows/WinPE ISO檔) +r/Ctrl+r - Grub2 模式 (只適用於常見的一些 Linux 系統ISO檔) +i/Ctrl+i - 相容模式 (只用作調試目的,不能正式使用) +u/Ctrl+u - 載入 ISO efi 驅動(只用作調試目的,不能正式使用) + + +按 ESC 鍵返回 ...... diff --git a/src/grub2/grub/hwinfo.cfg b/src/grub2/grub/hwinfo.cfg new file mode 100644 index 0000000..4bb3057 --- /dev/null +++ b/src/grub2/grub/hwinfo.cfg @@ -0,0 +1,64 @@ +menuentry "$VTLANG_HWINFO" --class=debug_hwinfo --class=F5tool { + smbios -t 4 -s 0x10 --set=cpu_brand + + set system_vendor="-"; + smbios -t 1 -s 0x04 --set=system_vendor; + set system_product="-"; + smbios -t 1 -s 0x05 --set=system_product; + set system_version="-"; + smbios -t 1 -s 0x06 --set=system_version; + + set board_vendor="-"; + smbios -t 2 -s 0x04 --set=board_vendor; + set board_product="-"; + smbios -t 2 -s 0x05 --set=board_product; + set board_version="-"; + smbios -t 2 -s 0x06 --set=board_version; + + set bios_vendor="-"; + smbios -t 0 -s 0x04 --set=bios_vendor; + set bios_version="-"; + smbios -t 0 -s 0x05 --set=bios_ver; + set bios_date="-"; + smbios -t 0 -s 0x08 --set=bios_date; + set bios_size="-"; + smbios -t 0 -b 0x09 --set=bios_size; + + + echo "Platform $grub_cpu-$grub_platform" + if [ "$grub_platform" != "pc" ]; then + echo "UEFI Version $grub_uefi_version" + echo "PI Version $grub_pi_version" + if vt_check_secureboot_var; then + echo "Secure Boot Enabled" + else + echo "Secure Boot Disabled" + fi + + vt_sbinfo + fi + + echo "" + echo "CPU Model $cpu_brand" + echo "Physical RAM $grub_total_ram MB" + + echo "" + echo "Manufacturer $system_vendor" + echo "Product Name $system_product" + echo "Version $system_version" + + echo "" + echo "Board Manufacturer $board_vendor" + echo "Board Name $board_product" + echo "Board Version $board_version" + + echo "" + echo "BIOS Manufacturer $bios_vendor" + echo "BIOS Version $bios_ver" + echo "BIOS Date $bios_date" + echo "BIOS ROM Size $bios_size" + + + echo -en "\n\n\n$VTLANG_ENTER_EXIT ..." + read vtInputKey +} diff --git a/src/grub2/grub/i386-efi/command.lst b/src/grub2/grub/i386-efi/command.lst new file mode 100644 index 0000000..896bb3d --- /dev/null +++ b/src/grub2/grub/i386-efi/command.lst @@ -0,0 +1,206 @@ +*acpi: acpi +*all_functional_test: functional_test +*background_image: gfxterm_background +*bls_import: blscfg +*blscfg: blscfg +*cat: cat +*cpuid: cpuid +*crc: hashsum +*cryptomount: cryptodisk +*echo: echo +*extract_syslinux_entries_configfile: syslinuxcfg +*extract_syslinux_entries_source: syslinuxcfg +*file: file +*functional_test: functional_test +*fwconnect: fwload +*fwload: fwload +*gettext: gettext +*hashsum: hashsum +*hdparm: hdparm +*hello: hello +*help: help +*hexdump: hexdump +*inb: iorw +*inl: iorw +*inw: iorw +*keystatus: keystatus +*kfreebsd: bsd +*knetbsd: bsd +*kopenbsd: bsd +*list_env: loadenv +*load_env: loadenv +*loopback: loopback +*ls: ls +*lsacpi: lsacpi +*lspci: lspci +*md5sum: hashsum +*menuentry: normal +*pcidump: pcidump +*probe: probe +*rdmsr: rdmsr +*read_byte: memrw +*read_dword: memrw +*read_word: memrw +*regexp: regexp +*save_env: loadenv +*search: search +*serial: serial +*set_keyboard_layout: setkey +*setkey: setkey +*setpci: setpci +*sha1sum: hashsum +*sha256sum: hashsum +*sha512sum: hashsum +*sleep: sleep +*smbios: smbios +*submenu: normal +*syslinux_configfile: syslinuxcfg +*syslinux_source: syslinuxcfg +*terminfo: terminfo +*test_blockarg: test_blockarg +*testspeed: testspeed +*tr: tr +*trust: pgp +*verify_detached: pgp +*xnu_splash: xnu +*zfskey: zfscrypt +.: configfile +[: test +appleloader: appleldr +authenticate: normal +background_color: gfxterm_background +backtrace: backtrace +badram: mmap +blocklist: blocklist +boot: boot +break: normal +cat: minicmd +cbmemc: cbmemc +chainloader: chain +clear: normal +cmp: cmp +configfile: configfile +continue: normal +coreboot_boottime: cbtime +cutmem: mmap +date: date +distrust: pgp +dump: minicmd +eval: eval +exit: minicmd +export: normal +extract_entries_configfile: configfile +extract_entries_source: configfile +extract_legacy_entries_configfile: legacycfg +extract_legacy_entries_source: legacycfg +fakebios: loadbios +false: true +fix_video: fixvideo +fwsetup: efifwsetup +gdbstub: gdb +gdbstub_break: gdb +gdbstub_stop: gdb +gptsync: gptsync +halt: halt +help: minicmd +hexdump_random: random +initrd16: linux16 +initrd: linux +initrdefi: linux +keymap: keylayouts +kfreebsd_loadenv: bsd +kfreebsd_module: bsd +kfreebsd_module_elf: bsd +knetbsd_module: bsd +knetbsd_module_elf: bsd +kopenbsd_ramdisk: bsd +legacy_check_password: legacycfg +legacy_configfile: legacycfg +legacy_initrd: legacycfg +legacy_initrd_nounzip: legacycfg +legacy_kernel: legacycfg +legacy_password: legacycfg +legacy_source: legacycfg +linux16: linux16 +linux: linux +linuxefi: linux +list_trusted: pgp +loadbios: loadbios +loadfont: font +lscoreboot: cbls +lsefi: lsefi +lsefimmap: lsefimmap +lsefisystab: lsefisystab +lsfonts: font +lsmmap: lsmmap +lsmod: minicmd +lssal: lssal +macppcbless: macbless +mactelbless: macbless +module2: multiboot2 +module: multiboot +multiboot2: multiboot2 +multiboot: multiboot +nativedisk: nativedisk +net_add_addr: net +net_add_dns: net +net_add_route: net +net_bootp: net +net_del_addr: net +net_del_dns: net +net_del_route: net +net_dhcp: net +net_get_dhcp_option: net +net_ipv6_autoconf: net +net_ls_addr: net +net_ls_cards: net +net_ls_dns: net +net_ls_routes: net +net_nslookup: net +normal: normal +normal_exit: normal +outb: iorw +outl: iorw +outw: iorw +parttool: parttool +password: password +password_pbkdf2: password_pbkdf2 +play: play +read: read +reboot: reboot +return: normal +rmmod: minicmd +search.file: search_fs_file +search.fs_label: search_label +search.fs_uuid: search_fs_uuid +setparams: normal +shift: normal +source: configfile +terminal_input: terminal +terminal_output: terminal +test: test +testload: testload +time: time +true: true +usb: usbtest +videoinfo: videoinfo +videotest: videotest +vt_img_extra_initrd_append: linux +vt_img_extra_initrd_reset: linux +vt_set_boot_opt: linux +vt_unset_boot_opt: linux +write_byte: memrw +write_dword: memrw +write_word: memrw +wrmsr: wrmsr +xnu_devprop_load: xnu +xnu_kernel64: xnu +xnu_kernel: xnu +xnu_kext: xnu +xnu_kextdir: xnu +xnu_mkext: xnu +xnu_ramdisk: xnu +xnu_resume: xnu +xnu_uuid: xnu_uuid +zfs-bootfs: zfsinfo +zfsinfo: zfsinfo diff --git a/src/grub2/grub/i386-efi/crypto.lst b/src/grub2/grub/i386-efi/crypto.lst new file mode 100644 index 0000000..77d9efc --- /dev/null +++ b/src/grub2/grub/i386-efi/crypto.lst @@ -0,0 +1,45 @@ +RIJNDAEL: gcry_rijndael +RIJNDAEL192: gcry_rijndael +RIJNDAEL256: gcry_rijndael +AES128: gcry_rijndael +AES-128: gcry_rijndael +AES-192: gcry_rijndael +AES-256: gcry_rijndael +ADLER32: adler32 +CRC64: crc64 +ARCFOUR: gcry_arcfour +BLOWFISH: gcry_blowfish +CAMELLIA128: gcry_camellia +CAMELLIA192: gcry_camellia +CAMELLIA256: gcry_camellia +CAST5: gcry_cast5 +CRC32: gcry_crc +CRC32RFC1510: gcry_crc +CRC24RFC2440: gcry_crc +DES: gcry_des +3DES: gcry_des +DSA: gcry_dsa +IDEA: gcry_idea +MD4: gcry_md4 +MD5: gcry_md5 +RFC2268_40: gcry_rfc2268 +AES: gcry_rijndael +AES192: gcry_rijndael +AES256: gcry_rijndael +RIPEMD160: gcry_rmd160 +RSA: gcry_rsa +SEED: gcry_seed +SERPENT128: gcry_serpent +SERPENT192: gcry_serpent +SERPENT256: gcry_serpent +SHA1: gcry_sha1 +SHA224: gcry_sha256 +SHA256: gcry_sha256 +SHA512: gcry_sha512 +SHA384: gcry_sha512 +TIGER192: gcry_tiger +TIGER: gcry_tiger +TIGER2: gcry_tiger +TWOFISH: gcry_twofish +TWOFISH128: gcry_twofish +WHIRLPOOL: gcry_whirlpool diff --git a/src/grub2/grub/i386-efi/fdt.lst b/src/grub2/grub/i386-efi/fdt.lst new file mode 100644 index 0000000..e69de29 diff --git a/src/grub2/grub/i386-efi/fs.lst b/src/grub2/grub/i386-efi/fs.lst new file mode 100644 index 0000000..0acd240 --- /dev/null +++ b/src/grub2/grub/i386-efi/fs.lst @@ -0,0 +1,37 @@ +affs +afs +bfs +btrfs +cbfs +cpio +cpio_be +exfat +ext2 +f2fs +fat +hfs +hfsplus +iso9660 +jfs +minix +minix2 +minix2_be +minix3 +minix3_be +minix_be +newc +nilfs2 +ntfs +odc +procfs +reiserfs +romfs +sfs +squash4 +tar +udf +ufs1 +ufs1_be +ufs2 +xfs +zfs diff --git a/src/grub2/grub/i386-efi/moddep.lst b/src/grub2/grub/i386-efi/moddep.lst new file mode 100644 index 0000000..b025ad7 --- /dev/null +++ b/src/grub2/grub/i386-efi/moddep.lst @@ -0,0 +1,269 @@ +videotest: font video gfxmenu +odc: archelp +loopback: extcmd +setkey: extcmd +macho: +gcry_des: crypto +memrw: extcmd +terminfo: extcmd +f2fs: fshelp +part_gpt: +romfs: fshelp +read: +lsefimmap: +aout: +gcry_arcfour: crypto +tftp: net priority_queue +newc: archelp +minix2_be: +elf: +videotest_checksum: font functional_test video_fb +password_pbkdf2: crypto gcry_sha512 pbkdf2 normal +gcry_seed: crypto +pcidump: extcmd +bsd: elf serial crypto gcry_md5 verifiers extcmd aout video boot cpuid relocator mmap +sfs: fshelp +reiserfs: fshelp +part_sunpc: +zstd: +gfxmenu: video_colors trig bitmap_scale gfxterm font normal video bitmap +backtrace: +jfs: +help: extcmd normal +configfile: normal +cbls: cbtable +gfxterm_menu: font functional_test procfs normal video_fb +gcry_idea: crypto +tr: extcmd +shift_test: functional_test +ohci: cs5536 usb boot +afs: fshelp +spkmodem: terminfo +usb_keyboard: keylayouts usb +xzio: crypto +syslinuxcfg: extcmd normal +search_fs_file: +wrmsr: +usbms: scsi usb +test_blockarg: extcmd normal +true: +affs: fshelp +iso9660: fshelp +smbios: extcmd +exfat: fshelp +setjmp_test: setjmp functional_test +gfxterm: font video +efinet: net +disk: +appleldr: boot +xfs: fshelp +testspeed: extcmd normal +cpio_be: archelp +functional_test: btrfs extcmd video video_fb +bswap_test: functional_test +sleep: extcmd normal +memdisk: +gcry_rijndael: crypto +mdraid09_be: diskfilter +gettext: +gcry_sha1: crypto +hfspluscomp: gzio hfsplus +cmp: +random: hexdump +offsetio: +file: elf macho extcmd offsetio +usbserial_usbdebug: serial usb usbserial_common +video_colors: +morse: +hashsum: crypto extcmd normal +usb: +halt: acpi +gdb: serial backtrace +gfxterm_background: video_colors bitmap_scale gfxterm extcmd video bitmap +search_fs_uuid: +gcry_dsa: pgp mpi +keystatus: extcmd +linux: ventoy verifiers video boot relocator mmap +geli: cryptodisk crypto gcry_sha512 pbkdf2 gcry_sha256 +cmdline_cat_test: font functional_test normal procfs video_fb +rdmsr: extcmd +part_sun: +cbtable: +pbkdf2_test: functional_test pbkdf2 gcry_sha1 +video_bochs: video video_fb +verifiers: +bufio: +usbserial_ftdi: serial usb usbserial_common +legacy_password_test: functional_test legacycfg +cpuid: extcmd +blscfg: extcmd normal +hdparm: extcmd hexdump +bfs: fshelp +gcry_blowfish: crypto +test: +nilfs2: fshelp +gcry_rsa: pgp mpi +cryptodisk: crypto extcmd procfs +nativedisk: +minicmd: +signature_test: functional_test procfs +ata: scsi +udf: fshelp +gzio: gcry_crc +xnu_uuid: gcry_md5 +uhci: usb +pata: ata +mul_test: functional_test +adler32: crypto +terminal: +div: +ehci: cs5536 usb boot +crypto: +part_bsd: part_msdos +cs5536: +ventoy: ext2 fshelp elf btrfs crypto font gcry_md5 exfat udf datetime div extcmd normal video gcry_sha1 mmap iso9660 +gcry_sha512: crypto +password: crypto normal +fshelp: +sleep_test: functional_test datetime +iorw: extcmd +xnu: macho bitmap_scale random verifiers extcmd boot video bitmap relocator mmap +mmap: +exfctest: functional_test +zfsinfo: zfs +ldm: part_gpt diskfilter part_msdos +eval: normal +part_dvh: +lssal: +blocklist: +ext2: fshelp +net: priority_queue bufio datetime boot +part_acorn: +videoinfo: video +btrfs: zstd lzopio raid6rec gzio +lsmmap: mmap +strtoull_test: functional_test +bitmap: +ntfs: fshelp +multiboot: net linux video boot relocator mmap +gcry_crc: crypto +png: bufio bitmap +jpeg: bufio bitmap +macbless: disk +div_test: functional_test div +regexp: extcmd normal +parttool: normal +usbserial_pl2303: serial usb usbserial_common +cpio: archelp +gcry_rmd160: crypto +fat: fshelp +ufs1_be: +archelp: +http: net +zfs: gzio +raid6rec: diskfilter +lsefisystab: +minix2: +lsacpi: extcmd acpi +datehook: datetime normal +loadenv: disk extcmd +bitmap_scale: bitmap +probe: extcmd +minix3: +tar: archelp +loadbios: +hfs: fshelp +procfs: archelp +boot: +keylayouts: +progress: normal +kernel: +usbtest: usb +relocator: mmap +acpi: extcmd mmap +tga: bufio bitmap +fwload: extcmd +reboot: +serial: extcmd terminfo +zfscrypt: crypto pbkdf2 extcmd zfs gcry_sha1 gcry_rijndael +efi_uga: video video_fb +dm_nv: diskfilter +cmp_test: functional_test +luks: cryptodisk crypto pbkdf2 +font: bufio video +raid5rec: diskfilter +crc64: crypto +datetime: +efifwsetup: +ctz_test: functional_test +video: +cbmemc: cbtable normal terminfo +hfsplus: fshelp +gcry_cast5: crypto +extcmd: +squash4: fshelp zstd lzopio zfs xzio gzio +part_plan: +minix_be: +gcry_whirlpool: crypto +gcry_tiger: crypto +fixvideo: +search: search_fs_uuid search_fs_file extcmd search_label +lspci: extcmd +cbtime: cbtable +video_fb: +minix3_be: +trig: +msdospart: disk parttool +priority_queue: +gcry_twofish: crypto +part_dfly: +xnu_uuid_test: functional_test +diskfilter: +testload: +part_apple: +hexdump: extcmd +date: datetime normal +pbkdf2: crypto +gcry_sha256: crypto +ls: extcmd normal +usbserial_common: serial usb +ntfscomp: ntfs +mouse: +lzopio: crypto +video_cirrus: video video_fb +hello: extcmd +scsi: +linux16: linux boot video relocator mmap +cat: extcmd +ahci: ata boot +pgp: crypto verifiers extcmd mpi gcry_sha1 +normal: terminal crypto verifiers bufio extcmd boot gettext +ufs1: +mdraid09: diskfilter +lvm: diskfilter +chain: net efinet boot +cbfs: archelp +ufs2: +time: +setpci: extcmd +gptsync: disk +search_label: +setjmp: +multiboot2: linux net video boot relocator mmap acpi +gcry_rfc2268: crypto +mdraid1x: diskfilter +mpi: crypto +legacycfg: crypto password gcry_md5 normal +play: +part_amiga: +efi_gop: video video_fb +minix: +echo: extcmd +lsefi: +gcry_serpent: crypto +gcry_md4: crypto +gcry_md5: crypto +part_msdos: +gcry_camellia: crypto +at_keyboard: keylayouts boot +all_video: efi_gop efi_uga video_bochs video_cirrus diff --git a/src/grub2/grub/i386-efi/partmap.lst b/src/grub2/grub/i386-efi/partmap.lst new file mode 100644 index 0000000..761233a --- /dev/null +++ b/src/grub2/grub/i386-efi/partmap.lst @@ -0,0 +1,11 @@ +part_acorn +part_amiga +part_apple +part_bsd +part_dfly +part_dvh +part_gpt +part_msdos +part_plan +part_sun +part_sunpc diff --git a/src/grub2/grub/i386-efi/parttool.lst b/src/grub2/grub/i386-efi/parttool.lst new file mode 100644 index 0000000..68b4b5c --- /dev/null +++ b/src/grub2/grub/i386-efi/parttool.lst @@ -0,0 +1 @@ +msdos: msdospart diff --git a/src/grub2/grub/i386-efi/terminal.lst b/src/grub2/grub/i386-efi/terminal.lst new file mode 100644 index 0000000..9afb9bd --- /dev/null +++ b/src/grub2/grub/i386-efi/terminal.lst @@ -0,0 +1,10 @@ +iat_keyboard: at_keyboard +imouse: mouse +iserial: serial +iserial_*: serial +oaudio: morse +ocbmemc: cbmemc +ogfxterm: gfxterm +oserial: serial +oserial_*: serial +ospkmodem: spkmodem diff --git a/src/grub2/grub/i386-efi/video.lst b/src/grub2/grub/i386-efi/video.lst new file mode 100644 index 0000000..ae9ba23 --- /dev/null +++ b/src/grub2/grub/i386-efi/video.lst @@ -0,0 +1,4 @@ +efi_gop +efi_uga +video_bochs +video_cirrus diff --git a/src/grub2/grub/i386-pc/command.lst b/src/grub2/grub/i386-pc/command.lst new file mode 100644 index 0000000..a21a2f9 --- /dev/null +++ b/src/grub2/grub/i386-pc/command.lst @@ -0,0 +1,212 @@ +*acpi: acpi +*all_functional_test: functional_test +*background_image: gfxterm_background +*bls_import: blscfg +*blscfg: blscfg +*cat: cat +*cpuid: cpuid +*crc: hashsum +*cryptomount: cryptodisk +*drivemap: drivemap +*echo: echo +*extract_syslinux_entries_configfile: syslinuxcfg +*extract_syslinux_entries_source: syslinuxcfg +*file: file +*functional_test: functional_test +*gettext: gettext +*halt: halt +*hashsum: hashsum +*hdparm: hdparm +*hello: hello +*help: help +*hexdump: hexdump +*inb: iorw +*inl: iorw +*inw: iorw +*keystatus: keystatus +*kfreebsd: bsd +*knetbsd: bsd +*kopenbsd: bsd +*list_env: loadenv +*load_env: loadenv +*loopback: loopback +*ls: ls +*lsacpi: lsacpi +*lspci: lspci +*md5sum: hashsum +*menuentry: normal +*pcidump: pcidump +*plan9: plan9 +*probe: probe +*rdmsr: rdmsr +*read_byte: memrw +*read_dword: memrw +*read_word: memrw +*regexp: regexp +*save_env: loadenv +*search: search +*sendkey: sendkey +*serial: serial +*set_keyboard_layout: setkey +*setkey: setkey +*setpci: setpci +*sha1sum: hashsum +*sha256sum: hashsum +*sha512sum: hashsum +*sleep: sleep +*smbios: smbios +*submenu: normal +*syslinux_configfile: syslinuxcfg +*syslinux_source: syslinuxcfg +*terminfo: terminfo +*test_blockarg: test_blockarg +*testspeed: testspeed +*tr: tr +*trust: pgp +*verify_detached: pgp +*xnu_splash: xnu +*zfskey: zfscrypt +.: configfile +[: test +authenticate: normal +background_color: gfxterm_background +backtrace: backtrace +badram: mmap +blocklist: blocklist +boot: boot +break: normal +cat: minicmd +cbmemc: cbmemc +chainloader: chain +clear: normal +cmosclean: cmostest +cmosdump: cmosdump +cmosset: cmostest +cmostest: cmostest +cmp: cmp +configfile: configfile +continue: normal +coreboot_boottime: cbtime +cutmem: mmap +date: date +distrust: pgp +dump: minicmd +efiemu_loadcore: efiemu +efiemu_prepare: efiemu +efiemu_unload: efiemu +eval: eval +exit: minicmd +export: normal +extract_entries_configfile: configfile +extract_entries_source: configfile +extract_legacy_entries_configfile: legacycfg +extract_legacy_entries_source: legacycfg +false: true +freedos: freedos +gdbstub: gdb +gdbstub_break: gdb +gdbstub_stop: gdb +gptsync: gptsync +help: minicmd +hexdump_random: random +initrd16: linux16 +initrd: linux +initrdefi: linux +keymap: keylayouts +kfreebsd_loadenv: bsd +kfreebsd_module: bsd +kfreebsd_module_elf: bsd +knetbsd_module: bsd +knetbsd_module_elf: bsd +kopenbsd_ramdisk: bsd +legacy_check_password: legacycfg +legacy_configfile: legacycfg +legacy_initrd: legacycfg +legacy_initrd_nounzip: legacycfg +legacy_kernel: legacycfg +legacy_password: legacycfg +legacy_source: legacycfg +linux16: linux16 +linux: linux +linuxefi: linux +list_trusted: pgp +loadfont: font +lsapm: lsapm +lscoreboot: cbls +lsfonts: font +lsmmap: lsmmap +lsmod: minicmd +macppcbless: macbless +mactelbless: macbless +module2: multiboot2 +module: multiboot +multiboot2: multiboot2 +multiboot: multiboot +nativedisk: nativedisk +net_add_addr: net +net_add_dns: net +net_add_route: net +net_bootp: net +net_del_addr: net +net_del_dns: net +net_del_route: net +net_dhcp: net +net_get_dhcp_option: net +net_ipv6_autoconf: net +net_ls_addr: net +net_ls_cards: net +net_ls_dns: net +net_ls_routes: net +net_nslookup: net +normal: normal +normal_exit: normal +ntldr: ntldr +outb: iorw +outl: iorw +outw: iorw +parttool: parttool +password: password +password_pbkdf2: password_pbkdf2 +play: play +pxechainloader: pxechain +read: read +reboot: reboot +return: normal +rmmod: minicmd +search.file: search_fs_file +search.fs_label: search_label +search.fs_uuid: search_fs_uuid +setparams: normal +shift: normal +source: configfile +terminal_input: terminal +terminal_output: terminal +test: test +testload: testload +time: time +true: true +truecrypt: truecrypt +usb: usbtest +vbeinfo: videoinfo +vbetest: videotest +videoinfo: videoinfo +videotest: videotest +vt_img_extra_initrd_append: linux +vt_img_extra_initrd_reset: linux +vt_set_boot_opt: linux +vt_unset_boot_opt: linux +write_byte: memrw +write_dword: memrw +write_word: memrw +wrmsr: wrmsr +xnu_devprop_load: xnu +xnu_kernel64: xnu +xnu_kernel: xnu +xnu_kext: xnu +xnu_kextdir: xnu +xnu_mkext: xnu +xnu_ramdisk: xnu +xnu_resume: xnu +xnu_uuid: xnu_uuid +zfs-bootfs: zfsinfo +zfsinfo: zfsinfo diff --git a/src/grub2/grub/i386-pc/crypto.lst b/src/grub2/grub/i386-pc/crypto.lst new file mode 100644 index 0000000..77d9efc --- /dev/null +++ b/src/grub2/grub/i386-pc/crypto.lst @@ -0,0 +1,45 @@ +RIJNDAEL: gcry_rijndael +RIJNDAEL192: gcry_rijndael +RIJNDAEL256: gcry_rijndael +AES128: gcry_rijndael +AES-128: gcry_rijndael +AES-192: gcry_rijndael +AES-256: gcry_rijndael +ADLER32: adler32 +CRC64: crc64 +ARCFOUR: gcry_arcfour +BLOWFISH: gcry_blowfish +CAMELLIA128: gcry_camellia +CAMELLIA192: gcry_camellia +CAMELLIA256: gcry_camellia +CAST5: gcry_cast5 +CRC32: gcry_crc +CRC32RFC1510: gcry_crc +CRC24RFC2440: gcry_crc +DES: gcry_des +3DES: gcry_des +DSA: gcry_dsa +IDEA: gcry_idea +MD4: gcry_md4 +MD5: gcry_md5 +RFC2268_40: gcry_rfc2268 +AES: gcry_rijndael +AES192: gcry_rijndael +AES256: gcry_rijndael +RIPEMD160: gcry_rmd160 +RSA: gcry_rsa +SEED: gcry_seed +SERPENT128: gcry_serpent +SERPENT192: gcry_serpent +SERPENT256: gcry_serpent +SHA1: gcry_sha1 +SHA224: gcry_sha256 +SHA256: gcry_sha256 +SHA512: gcry_sha512 +SHA384: gcry_sha512 +TIGER192: gcry_tiger +TIGER: gcry_tiger +TIGER2: gcry_tiger +TWOFISH: gcry_twofish +TWOFISH128: gcry_twofish +WHIRLPOOL: gcry_whirlpool diff --git a/src/grub2/grub/i386-pc/fdt.lst b/src/grub2/grub/i386-pc/fdt.lst new file mode 100644 index 0000000..e69de29 diff --git a/src/grub2/grub/i386-pc/fs.lst b/src/grub2/grub/i386-pc/fs.lst new file mode 100644 index 0000000..0acd240 --- /dev/null +++ b/src/grub2/grub/i386-pc/fs.lst @@ -0,0 +1,37 @@ +affs +afs +bfs +btrfs +cbfs +cpio +cpio_be +exfat +ext2 +f2fs +fat +hfs +hfsplus +iso9660 +jfs +minix +minix2 +minix2_be +minix3 +minix3_be +minix_be +newc +nilfs2 +ntfs +odc +procfs +reiserfs +romfs +sfs +squash4 +tar +udf +ufs1 +ufs1_be +ufs2 +xfs +zfs diff --git a/src/grub2/grub/i386-pc/moddep.lst b/src/grub2/grub/i386-pc/moddep.lst new file mode 100644 index 0000000..de15670 --- /dev/null +++ b/src/grub2/grub/i386-pc/moddep.lst @@ -0,0 +1,274 @@ +videotest: font video gfxmenu +odc: archelp +loopback: extcmd +setkey: extcmd +macho: +gcry_des: crypto +memrw: extcmd +terminfo: extcmd +f2fs: fshelp +part_gpt: +romfs: fshelp +read: +aout: +gcry_arcfour: crypto +vga_text: +tftp: net priority_queue +newc: archelp +minix2_be: +elf: +videotest_checksum: font functional_test video_fb +password_pbkdf2: crypto gcry_sha512 pbkdf2 normal +gcry_seed: crypto +pcidump: extcmd pci +bsd: elf serial crypto gcry_md5 verifiers extcmd vbe aout video boot cpuid relocator mmap +sfs: fshelp +reiserfs: fshelp +part_sunpc: +zstd: +gfxmenu: video_colors trig bitmap_scale gfxterm font normal video bitmap +backtrace: +jfs: +help: extcmd normal +configfile: normal +cbls: cbtable +gfxterm_menu: font functional_test procfs normal video_fb +gcry_idea: crypto +tr: extcmd +shift_test: functional_test +ohci: cs5536 usb boot pci +afs: fshelp +spkmodem: terminfo +usb_keyboard: keylayouts usb +xzio: crypto +syslinuxcfg: extcmd normal +search_fs_file: +wrmsr: +vga: video video_fb +usbms: scsi usb +test_blockarg: extcmd normal +true: +affs: fshelp +iso9660: fshelp +smbios: extcmd acpi +exfat: fshelp +setjmp_test: setjmp functional_test +gfxterm: font video +disk: +xfs: fshelp +testspeed: extcmd normal +cpio_be: archelp +functional_test: btrfs extcmd video video_fb +pxechain: pxe video boot relocator +bswap_test: functional_test +sleep: extcmd normal +memdisk: +gcry_rijndael: crypto +mdraid09_be: diskfilter +gettext: +gcry_sha1: crypto +hfspluscomp: gzio hfsplus +cmp: +random: hexdump acpi +offsetio: +file: elf macho extcmd offsetio +usbserial_usbdebug: serial usb usbserial_common +video_colors: +morse: +hashsum: crypto extcmd normal +usb: pci +halt: extcmd acpi +gdb: serial backtrace +gfxterm_background: video_colors bitmap_scale gfxterm extcmd video bitmap +search_fs_uuid: +gcry_dsa: pgp mpi +keystatus: extcmd +linux: ventoy verifiers vbe normal video boot relocator mmap +geli: cryptodisk crypto gcry_sha512 pbkdf2 gcry_sha256 +cmdline_cat_test: font functional_test normal procfs video_fb +rdmsr: extcmd +part_sun: +cbtable: +plan9: verifiers extcmd boot video relocator +sendkey: extcmd boot +pbkdf2_test: functional_test pbkdf2 gcry_sha1 +video_bochs: pci video video_fb +verifiers: +bufio: +usbserial_ftdi: serial usb usbserial_common +legacy_password_test: functional_test legacycfg +cpuid: extcmd +blscfg: extcmd normal +hdparm: extcmd hexdump +bfs: fshelp +gcry_blowfish: crypto +test: +nilfs2: fshelp +gcry_rsa: pgp mpi +cryptodisk: crypto extcmd procfs +nativedisk: +minicmd: +signature_test: functional_test procfs +ata: scsi +udf: fshelp +gzio: gcry_crc +xnu_uuid: gcry_md5 +uhci: usb pci +pata: ata pci +mul_test: functional_test +adler32: crypto +terminal: +div: +ehci: cs5536 usb boot pci +crypto: +part_bsd: part_msdos +cs5536: pci +biosdisk: +ventoy: ext2 fshelp elf btrfs crypto font gcry_md5 exfat udf div extcmd datetime normal video gcry_sha1 iso9660 reboot acpi +lsapm: +gcry_sha512: crypto +password: crypto normal +efiemu: gcry_crc crypto cpuid acpi +fshelp: +sleep_test: functional_test datetime +iorw: extcmd +xnu: macho bitmap_scale random verifiers extcmd video bitmap boot relocator efiemu mmap +mmap: boot +exfctest: functional_test +zfsinfo: zfs +ldm: part_gpt diskfilter part_msdos +cmostest: +eval: normal +part_dvh: +blocklist: +ext2: fshelp +net: priority_queue bufio datetime boot +drivemap: extcmd boot mmap +part_acorn: +videoinfo: video +btrfs: zstd lzopio raid6rec gzio +lsmmap: +strtoull_test: functional_test +bitmap: +vbe: video video_fb +ntfs: fshelp +multiboot: net linux vbe video boot relocator mmap lsapm +gcry_crc: crypto +png: bufio bitmap +jpeg: bufio bitmap +macbless: disk +div_test: functional_test div +regexp: extcmd normal +parttool: normal +usbserial_pl2303: serial usb usbserial_common +cpio: archelp +gcry_rmd160: crypto +fat: fshelp +ufs1_be: +truecrypt: video boot relocator gzio mmap +archelp: +ntldr: chain boot video relocator +http: net +zfs: gzio +raid6rec: diskfilter +minix2: +mda_text: +lsacpi: extcmd acpi +datehook: datetime normal +loadenv: disk extcmd +bitmap_scale: bitmap +probe: extcmd +minix3: +tar: archelp +hfs: fshelp +procfs: archelp +boot: +keylayouts: +progress: normal +kernel: +usbtest: usb +relocator: mmap +acpi: extcmd mmap +tga: bufio bitmap +reboot: relocator +serial: extcmd terminfo +zfscrypt: crypto pbkdf2 extcmd zfs gcry_sha1 gcry_rijndael +dm_nv: diskfilter +cmp_test: functional_test +luks: cryptodisk crypto pbkdf2 +font: bufio video +raid5rec: diskfilter +crc64: crypto +datetime: +ctz_test: functional_test +video: +pci: +cbmemc: cbtable normal terminfo +cmosdump: +hfsplus: fshelp +gcry_cast5: crypto +extcmd: +squash4: fshelp zstd lzopio zfs xzio gzio +part_plan: +minix_be: +gcry_whirlpool: crypto +pxe: net boot +gcry_tiger: crypto +search: search_fs_uuid search_fs_file extcmd search_label +lspci: extcmd pci +cbtime: cbtable +video_fb: +minix3_be: +trig: +msdospart: disk parttool +priority_queue: +gcry_twofish: crypto +part_dfly: +xnu_uuid_test: functional_test +diskfilter: +testload: +part_apple: +hexdump: extcmd +date: datetime normal +pbkdf2: crypto +gcry_sha256: crypto +ls: extcmd normal +usbserial_common: serial usb +ntfscomp: ntfs +lzopio: crypto +video_cirrus: pci video video_fb +hello: extcmd +scsi: +linux16: linux boot video relocator mmap +cat: extcmd +ahci: ata boot pci +pgp: crypto verifiers extcmd mpi gcry_sha1 +normal: terminal crypto verifiers bufio extcmd boot gettext +ufs1: +mdraid09: diskfilter +lvm: diskfilter +cbfs: archelp +chain: video boot relocator +ufs2: +time: +setpci: extcmd pci +gptsync: disk +freedos: chain boot video relocator +search_label: +setjmp: +multiboot2: linux net vbe boot video relocator mmap lsapm acpi +gcry_rfc2268: crypto +mdraid1x: diskfilter +mpi: crypto +legacycfg: linux crypto password gcry_md5 normal +play: +part_amiga: +minix: +echo: extcmd +gcry_serpent: crypto +gcry_md4: crypto +gcry_md5: crypto +part_msdos: +gcry_camellia: crypto +at_keyboard: keylayouts boot +all_video: vbe vga video_bochs video_cirrus diff --git a/src/grub2/grub/i386-pc/partmap.lst b/src/grub2/grub/i386-pc/partmap.lst new file mode 100644 index 0000000..761233a --- /dev/null +++ b/src/grub2/grub/i386-pc/partmap.lst @@ -0,0 +1,11 @@ +part_acorn +part_amiga +part_apple +part_bsd +part_dfly +part_dvh +part_gpt +part_msdos +part_plan +part_sun +part_sunpc diff --git a/src/grub2/grub/i386-pc/parttool.lst b/src/grub2/grub/i386-pc/parttool.lst new file mode 100644 index 0000000..68b4b5c --- /dev/null +++ b/src/grub2/grub/i386-pc/parttool.lst @@ -0,0 +1 @@ +msdos: msdospart diff --git a/src/grub2/grub/i386-pc/terminal.lst b/src/grub2/grub/i386-pc/terminal.lst new file mode 100644 index 0000000..2cb224c --- /dev/null +++ b/src/grub2/grub/i386-pc/terminal.lst @@ -0,0 +1,11 @@ +iat_keyboard: at_keyboard +iserial: serial +iserial_*: serial +oaudio: morse +ocbmemc: cbmemc +ogfxterm: gfxterm +omda_text: mda_text +oserial: serial +oserial_*: serial +ospkmodem: spkmodem +ovga_text: vga_text diff --git a/src/grub2/grub/i386-pc/video.lst b/src/grub2/grub/i386-pc/video.lst new file mode 100644 index 0000000..6ca853e --- /dev/null +++ b/src/grub2/grub/i386-pc/video.lst @@ -0,0 +1,4 @@ +vbe +vga +video_bochs +video_cirrus diff --git a/src/grub2/grub/keyboard.cfg b/src/grub2/grub/keyboard.cfg new file mode 100644 index 0000000..41caba9 --- /dev/null +++ b/src/grub2/grub/keyboard.cfg @@ -0,0 +1,62 @@ +submenu "$VTLANG_KEYBRD_LAYOUT" --class=debug_krdlayout --class=F5tool { + menuentry QWERTY_USA --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout QWERTY_USA + } + menuentry AZERTY --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout AZERTY + } + menuentry CZECH_QWERTY --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout CZECH_QWERTY + } + menuentry CZECH_QWERTZ --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout CZECH_QWERTZ + } + menuentry DANISH --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout DANISH + } + menuentry DVORAK_USA --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout DVORAK_USA + } + menuentry FRENCH --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout FRENCH + } + menuentry GERMAN --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout GERMAN + } + menuentry ITALIANO --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout ITALIANO + } + menuentry JAPAN_106 --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout JAPAN_106 + } + menuentry LATIN_USA --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout LATIN_USA + } + menuentry PORTU_BRAZIL --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout PORTU_BRAZIL + } + menuentry QWERTY_UK --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout QWERTY_UK + } + menuentry QWERTZ --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout QWERTZ + } + menuentry QWERTZ_HUN --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout QWERTZ_HUN + } + menuentry QWERTZ_SLOV_CROAT --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout QWERTZ_SLOV_CROAT + } + menuentry SPANISH --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout SPANISH + } + menuentry SWEDISH --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout SWEDISH + } + menuentry TURKISH_Q --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout TURKISH_Q + } + menuentry VIETNAMESE --class=debug_kbd --class=debug_krdlayout --class=F5tool { + set_keyboard_layout VIETNAMESE + } +} diff --git a/src/grub2/grub/localboot.cfg b/src/grub2/grub/localboot.cfg new file mode 100644 index 0000000..c1a2826 --- /dev/null +++ b/src/grub2/grub/localboot.cfg @@ -0,0 +1,222 @@ + +if [ "$grub_platform" = "pc" ]; then + menuentry "$VTLANG_LB_SBOOT_WINDOWS" --class=boot_windows --class=F4boot { + + set partid=3 + while [ $partid -le 128 ]; do + if vt_check_part_exist $partid; then + for bt in bootmgr BOOTMGR Bootmgr BootMGR; do + if [ -f ($hisodev,$partid)/$bt ]; then + set root=($hisodev,$partid) + ntldr /$bt + boot + fi + done + else + break + fi + vt_incr partid 1 + done + + if search -n -s -f /Boot/BCD; then + for bt in bootmgr BOOTMGR Bootmgr BootMGR; do + if [ -f /$bt ]; then + if regexp '^hd0' $root; then + ntldr /$bt + else + drivemap -s hd0 $root + ntldr /$bt + fi + break + fi + done + elif search -n -s -f /NTDETECT.COM; then + drivemap -s hd0 $root + ntldr /ntldr + else + echo "Windows NOT found ..." + fi + } + + menuentry "$VTLANG_LB_SBOOT_G4D" --class=boot_g4d --class=F4boot { + if search -n -s -f /grldr; then + ntldr /grldr + else + echo "Grub4dos NOT found ..." + fi + } + + menuentry "$VTLANG_LB_SBOOT_HDD1" --class=boot_disk --class=F4boot { + set root=(hd0,1) + chainloader +1 + boot + } + + menuentry "$VTLANG_LB_SBOOT_HDD2" --class=boot_disk --class=F4boot { + set root=(hd1,1) + chainloader +1 + boot + } + + menuentry "$VTLANG_LB_SBOOT_HDD3" --class=boot_disk --class=F4boot { + set root=(hd2,1) + chainloader +1 + boot + } + +else + + menuentry "$VTLANG_LB_SBOOT_WINDOWS" --class=boot_windows --class=F4boot { + + set partid=3 + while [ $partid -le 128 ]; do + if vt_check_part_exist $partid; then + if [ -f ($hisodev,$partid)/EFI/Microsoft/Boot/bootmgfw.efi ]; then + set root=($hisodev,$partid) + terminal_output console + chainloader /EFI/Microsoft/Boot/bootmgfw.efi + boot + elif [ -f ($hisodev,$partid)/efi/Microsoft/Boot/bootmgfw.efi ]; then + set root=($hisodev,$partid) + terminal_output console + chainloader /efi/Microsoft/Boot/bootmgfw.efi + boot + elif [ -f ($hisodev,$partid)/VTEFI/Microsoft/Boot/bootmgfw.efi ]; then + set root=($hisodev,$partid) + terminal_output console + chainloader /VTEFI/Microsoft/Boot/bootmgfw.efi + boot + fi + else + break + fi + vt_incr partid 1 + done + + if search -n -s -f /EFI/Microsoft/Boot/bootmgfw.efi; then + terminal_output console + chainloader /EFI/Microsoft/Boot/bootmgfw.efi + boot + elif search -n -s -f /efi/Microsoft/Boot/bootmgfw.efi; then + terminal_output console + chainloader /efi/Microsoft/Boot/bootmgfw.efi + boot + else + echo "Windows NOT found ..." + fi + } + + if [ "$grub_cpu" = "i386" ]; then + menuentry "$VTLANG_LB_SBOOT_IA32EFI" --class=boot_uefi --class=F4boot { + set HISO_SEARCH_NO_HISOEFI=1 + if search -n -s -f /efi/boot/bootia32.efi; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + chainloader /efi/boot/bootia32.efi + boot + elif search -n -s -f /vtefi/boot/bootia32.efi; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + chainloader /vtefi/boot/bootia32.efi + boot + else + unset HISO_SEARCH_NO_HISOEFI + echo "BOOTIA32.EFI NOT found ..." + fi + } + + menuentry "$VTLANG_LB_SBOOT_XORBOOT" --class=boot_xorboot --class=F4boot { + set HISO_SEARCH_NO_HISOEFI=1 + if search -n -s -f /efi/xorboot/xorboot32.xor; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + if [ -f /efi/xorboot/bootia32.efi ]; then + chainloader /efi/xorboot/bootia32.efi + elif [ -f /efi/xorboot/xorboot.efi ]; then + chainloader /efi/xorboot/xorboot.efi + fi + boot + elif search -n -s -f /vtefi/xorboot/xorboot32.xor; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + if [ -f /vtefi/xorboot/bootia32.efi ]; then + chainloader /vtefi/xorboot/bootia32.efi + elif [ -f /vtefi/xorboot/xorboot.efi ]; then + chainloader /vtefi/xorboot/xorboot.efi + fi + boot + else + unset HISO_SEARCH_NO_HISOEFI + echo "xorboot NOT found ..." + fi + } + elif [ "$grub_cpu" = "arm64" ]; then + menuentry "$VTLANG_LB_SBOOT_AA64EFI" --class=boot_uefi --class=F4boot { + set HISO_SEARCH_NO_HISOEFI=1 + if search -n -s -f /efi/boot/bootaa64.efi; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + chainloader /efi/boot/bootaa64.efi + boot + elif search -n -s -f /vtefi/boot/bootaa64.efi; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + chainloader /vtefi/boot/bootaa64.efi + boot + else + unset HISO_SEARCH_NO_HISOEFI + echo "BOOTAA64.EFI NOT found ..." + fi + } + else + menuentry "$VTLANG_LB_SBOOT_X64EFI" --class=boot_uefi --class=F4boot { + set HISO_SEARCH_NO_HISOEFI=1 + if search -n -s -f /efi/boot/bootx64.efi; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + chainloader /efi/boot/bootx64.efi + boot + elif search -n -s -f /vtefi/boot/bootx64.efi; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + chainloader /vtefi/boot/bootx64.efi + boot + else + unset HISO_SEARCH_NO_HISOEFI + echo "BOOTX64.EFI NOT found ..." + fi + } + + menuentry "$VTLANG_LB_SBOOT_XORBOOT" --class=boot_xorboot --class=F4boot { + set HISO_SEARCH_NO_HISOEFI=1 + if search -n -s -f /efi/xorboot/xorboot.xor; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + if [ -f /efi/xorboot/bootx64.efi ]; then + chainloader /efi/xorboot/bootx64.efi + elif [ -f /efi/xorboot/xorboot.efi ]; then + chainloader /efi/xorboot/xorboot.efi + fi + boot + elif search -n -s -f /vtefi/xorboot/xorboot.xor; then + unset HISO_SEARCH_NO_HISOEFI + terminal_output console + if [ -f /vtefi/xorboot/bootx64.efi ]; then + chainloader /vtefi/xorboot/bootx64.efi + elif [ -f /vtefi/xorboot/xorboot.efi ]; then + chainloader /vtefi/xorboot/xorboot.efi + fi + boot + else + unset HISO_SEARCH_NO_HISOEFI + echo "xorboot NOT found ..." + fi + } + fi + + +fi + +menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." +} diff --git a/src/grub2/grub/menu/ar_AR.json b/src/grub2/grub/menu/ar_AR.json new file mode 100644 index 0000000..47cffc6 --- /dev/null +++ b/src/grub2/grub/menu/ar_AR.json @@ -0,0 +1,98 @@ +{ + "VTLANG_LANGUAGE_NAME": "Arabic (العربية)", + + "VTLANG_STR_HOTKEY_LIST": "L: لغة F1: مساعدة F2: تصفح F3: عرض لائحي F4: إقلاع محلي F5: أدوات F6: عوده", + "VTLANG_STR_HOTKEY_TREE": "L: لغة F1: مساعدة F2: تصفح F3: عرض شجري F4: إقلاع محلي F5: أدوات F6: عوده", + "VTLANG_RETURN_PREVIOUS": "عودة إلى القائمة السابقة [Esc]", + "VTLANG_RETURN_PRV_NOESC": "عودة إلى القائمة السابقة", + + "VTLANG_MENU_LANG": "اختيار اللغة في القائمة", + + "VTLANG_LB_SBOOT_WINDOWS": "البحث والإقلاع على Windows", + "VTLANG_LB_SBOOT_G4D": "البحث والإقلاع على Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "الإقلاع على القرص المحلي الأول", + "VTLANG_LB_SBOOT_HDD2": "الإقلاع على القرص المحلي الثاني", + "VTLANG_LB_SBOOT_HDD3": "الإقلاع على القرص المحلي الثالث", + "VTLANG_LB_SBOOT_X64EFI": "البحث والإقلاع على BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "البحث والإقلاع على BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "البحث والإقلاع على BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "البحث والإقلاع على xorboot", + + "VTLANG_FILE_CHKSUM": "تدقيق المجموع للملف", + "VTLANG_CHKSUM_MD5_CALC": "احسب md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "احسب sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "احسب sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "احسب sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "احسب وتحقق md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "احسب وتحقق sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "احسب وتحقق sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "احسب وتحقق sha512sum", + + "VTLANG_POWER": "الطاقة", + "VTLANG_POWER_REBOOT": "إعادة التشغيل", + "VTLANG_POWER_HALT": "إيقاف", + "VTLANG_POWER_BOOT_EFIFW": "إعادة التشغيل إلى إعداد EFI", + + "VTLANG_KEYBRD_LAYOUT": "تخطيطات لوحة المفاتيح", + "VTLANG_HWINFO": "معلومات حول العتاد", + + "VTLANG_RESOLUTION_CFG": "تكوين الدقة", + "VTLANG_SCREEN_MODE": "وضع عرض الشاشة", + "VTLANG_SCREEN_TEXT_MODE": "فرض تحديد وضع النص", + "VTLANG_SCREEN_GUI_MODE": "فرض تحديد وضع الرسومات", + + "VTLANG_THEME_SELECT": "اختر السمة", + + "VTLANG_UEFI_UTIL": "أدوات Hiperiso UEFI المساعدة", + "VTLANG_UTIL_SHOW_EFI_DRV": "عرض برامج تشغيل EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "إصلاح فشل تهيئة Windows BlinitializeLibrary", + + "VTLANG_JSON_CHK_JSON": "التحقق من تكوين json للبرنامج الإضافي (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "التحقق من تكوين برنامج الإضافي العام للتحكم", + "VTLANG_JSON_CHK_THEME": "التحقق من تكوين برنامج الإضافي الخاص بالسمة", + "VTLANG_JSON_CHK_AUTOINS": "التحقق من تكوين برنامج الإضافي للتثبيت التلقائي", + "VTLANG_JSON_CHK_PERSIST": "التحقق من تكوين برنامج الإضافي المستمر", + "VTLANG_JSON_CHK_MENU_ALIAS": "التحقق من تكوين برنامج الإضافي الخاص بالقائمة المستعارة", + "VTLANG_JSON_CHK_MENU_TIP": "التحقق من تكوين برنامج الإضافي الخاص بتلميح القائمة", + "VTLANG_JSON_CHK_MENU_CLASS": "التحقق من تكوين برنامج الإضافي الخاص بفئة القائمة", + "VTLANG_JSON_CHK_INJECTION": "التحقق من تكوين برنامج الإضافي الخاص بالتدخل", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "التحقق من تكوين برنامج الإضافي الخاص بالتثبيت التلقائي لـ memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "التحقق من تكوين برنامج الإضافي الخاص بقائمة الصور", + "VTLANG_JSON_CHK_IMG_BLIST": "التحقق من تكوين برنامج الإضافي الخاص بقائمة سوداء للصور", + "VTLANG_JSON_CHK_CONF_REPLACE": "التحقق من تكوين برنامج الإضافي الخاص باستبدال ملف التكوين للإقلاع", + "VTLANG_JSON_CHK_DUD": "التحقق من تكوين برنامج الإضافي الخاص بـ dud", + "VTLANG_JSON_CHK_PASSWORD": "التحقق من تكوين برنامج الإضافي الخاص بكلمة المرور", + + "VTLANG_NORMAL_MODE": "الإقلاع في الوضع العادي", + "VTLANG_WIMBOOT_MODE": "الإقلاع في وضع wimboot", + "VTLANG_GRUB2_MODE": "الإقلاع في وضع grub2", + "VTLANG_MEMDISK_MODE": "الإقلاع في وضع memdisk", + + "VTLANG_RET_TO_LISTVIEW": "العودة إلى ListView", + "VTLANG_RET_TO_TREEVIEW": "العودة إلى TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "الإقلاع بدون قالب التثبيت التلقائي", + "VTLANG_AUTOINS_USE": "الإقلاع مع", + + "VTLANG_NO_PERSIST": "الإقلاع بدون الاستمرارية", + "VTLANG_PERSIST_USE": "الإقلاع مع", + + "VTLANG_BROWER_RETURN": "العودة", + + "VTLANG_ENTER_EXIT": "اضغط على مفتاح Enter للخروج", + "VTLANG_ENTER_REBOOT": "اضغط على مفتاح Enter لإعادة التشغيل", + "VTLANG_ENTER_CONTINUE": "اضغط على مفتاح Enter للمتابعة", + + "VTLANG_CTRL_TEMP_SET": "إعدادات التحكم المؤقتة", + "VTLANG_WIN11_BYPASS_CHECK": "تجاوز فحص CPU/TPM/SecureBoot عند تثبيت Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "تجاوز متطلبات الحساب عبر الإنترنت عند تثبيت Windows 11", + "VTLANG_LINUX_REMOUNT": "ضم قسم Hiperiso بعد إقلاع Linux", + "VTLANG_SECONDARY_BOOT_MENU": "اظهر قائمة الإقلاع الثانوية", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/bn_BN.json b/src/grub2/grub/menu/bn_BN.json new file mode 100644 index 0000000..c3995f1 --- /dev/null +++ b/src/grub2/grub/menu/bn_BN.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Bengali (বাংলা)", + + "VTLANG_STR_HOTKEY_LIST": "L:ভাষা F1:সাহায্য F2:Browser F3:ListView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:ভাষা F1:সাহায্য F2:Browser F3:TreeView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "পূর্ববর্তী মেনুতে ফিরে যান [Esc]", + "VTLANG_RETURN_PRV_NOESC": "পূর্ববর্তী মেনুতে ফিরে যান", + + "VTLANG_MENU_LANG": "মেনু ভাষা নির্বাচন করুন", + + "VTLANG_LB_SBOOT_WINDOWS": "Windows অনুসন্ধান করুন এবং বুট করুন", + "VTLANG_LB_SBOOT_G4D": "Grub4dos অনুসন্ধান করুন এবং বুট করুন", + "VTLANG_LB_SBOOT_HDD1": "১ম(1st) স্থানীয় ডিস্ক বুট করুন", + "VTLANG_LB_SBOOT_HDD2": "২য়(2nd) স্থানীয় ডিস্ক বুট করুন", + "VTLANG_LB_SBOOT_HDD3": "3য়(3rd) স্থানীয় ডিস্ক বুট করুন", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI অনুসন্ধান করুন এবং বুট করুন", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI অনুসন্ধান করুন এবং বুট করুন", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI অনুসন্ধান করুন এবং বুট করুন", + "VTLANG_LB_SBOOT_XORBOOT": "xorboot অনুসন্ধান করুন এবং বুট করুন", + + "VTLANG_FILE_CHKSUM": "ফাইল চেকসাম", + "VTLANG_CHKSUM_MD5_CALC": "md5sum গণনা করুন", + "VTLANG_CHKSUM_SHA1_CALC": "sha1sum গণনা করুন", + "VTLANG_CHKSUM_SHA256_CALC": "sha256sum গণনা করুন", + "VTLANG_CHKSUM_SHA512_CALC": "sha512sum গণনা করুন", + "VTLANG_CHKSUM_MD5_CALC_CHK": "গণনা করুন এবং md5sum চেক করুন", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "গণনা করুন এবং sha1sum চেক করুন", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "গণনা করুন এবং sha256sum চেক করুন", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "গণনা করুন এবং sha512sum চেক করুন", + + "VTLANG_POWER": "পাওয়ার", + "VTLANG_POWER_REBOOT": "রিবুট", + "VTLANG_POWER_HALT": "হল্ট", + "VTLANG_POWER_BOOT_EFIFW": "EFI সেটআপে রিবুট করুন", + + "VTLANG_KEYBRD_LAYOUT": "কীবোর্ড লেআউট", + "VTLANG_HWINFO": "হার্ডওয়্যার তথ্য", + + "VTLANG_RESOLUTION_CFG": "রেজোলিউশন কনফিগারেশন", + "VTLANG_SCREEN_MODE": "Screen Display মোড", + "VTLANG_SCREEN_TEXT_MODE": "Force Text মোড", + "VTLANG_SCREEN_GUI_MODE": "Force Graphics মোড", + + "VTLANG_THEME_SELECT": "থিম নির্বাচন করুন", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI ইউটিলিটিস", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFI ড্রাইভার দেখান", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windows BlinitializeLibrary ব্যর্থতার সমাধান করুন", + + "VTLANG_JSON_CHK_JSON": "প্লাগইন json কনফিগারেশন পরীক্ষা করুন (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "গ্লোবাল কন্ট্রোল প্লাগইন কনফিগারেশন চেক করুন", + "VTLANG_JSON_CHK_THEME": "থিম প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_AUTOINS": "অটো ইন্সটল প্লাগইন কনফিগারেশন চেক করুন", + "VTLANG_JSON_CHK_PERSIST": "persistence প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_MENU_ALIAS": "menu alias প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_MENU_TIP": "menu tip প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_MENU_CLASS": "menu class প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_INJECTION": "injection প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "auto memdisk প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_IMG_LIST": "image list প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_IMG_BLIST": "image blacklist প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_CONF_REPLACE": "boot conf replace প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_DUD": "dud প্লাগইন কনফিগারেশন পরীক্ষা করুন", + "VTLANG_JSON_CHK_PASSWORD": "password প্লাগইন কনফিগারেশন পরীক্ষা করুন", + + "VTLANG_NORMAL_MODE": "সাধারণ মোডে বুট করুন", + "VTLANG_WIMBOOT_MODE": "wimboot মোডে বুট করুন", + "VTLANG_GRUB2_MODE": "grub2 মোডে বুট করুন", + "VTLANG_MEMDISK_MODE": "memdisk মোডে বুট করুন", + + "VTLANG_RET_TO_LISTVIEW": "ListView-এ ফিরে যান", + "VTLANG_RET_TO_TREEVIEW": "TreeView-এ ফিরে যান", + + "VTLANG_NO_AUTOINS_SCRIPT": "auto install মোড বিনা বুট করুন", + "VTLANG_AUTOINS_USE": "দিয়ে বুট করুন", + + "VTLANG_NO_PERSIST": "persistence বিনা বুট করুন", + "VTLANG_PERSIST_USE": "দিয়ে বুট করুন", + + "VTLANG_BROWER_RETURN": "ফিরে", + + "VTLANG_ENTER_EXIT": "প্রস্থান করার জন্য এন্টার কী টিপুন", + "VTLANG_ENTER_REBOOT": "রিবুট করতে এন্টার কী টিপুন", + "VTLANG_ENTER_CONTINUE": "চালিয়ে যেতে এন্টার কী টিপুন", + + "VTLANG_CTRL_TEMP_SET": "অস্থায়ী নিয়ন্ত্রণ সেটিংস", + "VTLANG_WIN11_BYPASS_CHECK": "Windows 11 ইনস্টল করার সময় CPU/TPM/SecureBoot চেক বাইপাস করুন", + "VTLANG_WIN11_BYPASS_NRO": "Windows 11 ইনস্টল করার সময় অনলাইন অ্যাকাউন্টের প্রয়োজন বাইপাস করুন", + "VTLANG_LINUX_REMOUNT": "লিনাক্স বুটের পরে ভেন্টয় পার্টিশনটি মাউন্ট করুন", + "VTLANG_SECONDARY_BOOT_MENU": "গৌণ বুট মেনু দেখান", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/cs_CZ.json b/src/grub2/grub/menu/cs_CZ.json new file mode 100644 index 0000000..99271a0 --- /dev/null +++ b/src/grub2/grub/menu/cs_CZ.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Czech (Čeština)", + + "VTLANG_STR_HOTKEY_LIST": "L:Jazyk F1:Nápověda F2:Procházet F3:Seznam F4:Místní boot F5:Nástroje F6:Rozšířená nabídka", + "VTLANG_STR_HOTKEY_TREE": "L:Jazyk F1:Nápověda F2:Procházet F3:Strom F4:Místní boot F5:Nástroje F6:Rozšířená nabídka", + "VTLANG_RETURN_PREVIOUS": "Vrátit do předchozí nabídky [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Vrátit do předchozí nabídky", + + "VTLANG_MENU_LANG": "Výběrt jazyka nabídel", + + "VTLANG_LB_SBOOT_WINDOWS": "Najít a spustit Windows", + "VTLANG_LB_SBOOT_G4D": "Najít a spustit Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Spustit 1. místní disk", + "VTLANG_LB_SBOOT_HDD2": "Spustit 2. místní disk", + "VTLANG_LB_SBOOT_HDD3": "Spustit 3. místní disk", + "VTLANG_LB_SBOOT_X64EFI": "Najít a spustit BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Najít a spustit BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Najít a spustit BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Najít a spustit xorboot", + + "VTLANG_FILE_CHKSUM": "Kontrolní součet souboru", + "VTLANG_CHKSUM_MD5_CALC": "Spočítat md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Spočítat sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Spočítat sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Spočítat sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Spočítat a ověřit md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Spočítat a ověřit sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Spočítat a ověřit sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Spočítat a ověřit sha512sum", + + "VTLANG_POWER": "Napájení", + "VTLANG_POWER_REBOOT": "Restartovat", + "VTLANG_POWER_HALT": "Vypnout", + "VTLANG_POWER_BOOT_EFIFW": "Restartovat do EFI nastavení", + + "VTLANG_KEYBRD_LAYOUT": "Rozložení klávesnice", + "VTLANG_HWINFO": "Informace o hardwaru", + + "VTLANG_RESOLUTION_CFG": "Nastavení rolišení", + "VTLANG_SCREEN_MODE": "Nastavení režimu zobrazení", + "VTLANG_SCREEN_TEXT_MODE": "Vynutit textový režim", + "VTLANG_SCREEN_GUI_MODE": "Vynutit grafický režim", + + "VTLANG_THEME_SELECT": "Výběr motivu", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI nástroje", + "VTLANG_UTIL_SHOW_EFI_DRV": "Zobrazit EFI ovladače", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Opravit chybu Windows BlinitializeLibrary", + + "VTLANG_JSON_CHK_JSON": "Zkontrolovat json konfiguraci zásuvných modulů (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Zkontrolovat konfiguraci hlavního zásuvného modulu", + "VTLANG_JSON_CHK_THEME": "Zkontrolovat konfiguraci zásuvného modulu motivů", + "VTLANG_JSON_CHK_AUTOINS": "Zkontrolovat konfiguraci zásuvného modulu automatické instalace", + "VTLANG_JSON_CHK_PERSIST": "Zkontrolovat konfiguraci zásuvného modulu perzistence", + "VTLANG_JSON_CHK_MENU_ALIAS": "Zkontrolovat konfiguraci zásuvného modulu aliasů", + "VTLANG_JSON_CHK_MENU_TIP": "Zkontrolovat konfiguraci zásuvného modulu tip", + "VTLANG_JSON_CHK_MENU_CLASS": "Zkontrolovat konfiguraci zásuvného modulu tříd", + "VTLANG_JSON_CHK_INJECTION": "Zkontrolovat konfiguraci zásuvného modulu injekcí", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Zkontrolovat konfiguraci zásuvného modulu automatického memdisku", + "VTLANG_JSON_CHK_IMG_LIST": "Zkontrolovat konfiguraci zásuvného modulu seznamu obrazů", + "VTLANG_JSON_CHK_IMG_BLIST": "Zkontrolovat konfiguraci zásuvného modulu černé listiny obrazů", + "VTLANG_JSON_CHK_CONF_REPLACE": "Zkontrolovat konfiguraci zásuvného modulu nahrazení konfigurace spouštění", + "VTLANG_JSON_CHK_DUD": "Zkontrolovat konfiguraci zásuvného modulu dud", + "VTLANG_JSON_CHK_PASSWORD": "Zkontrolovat konfiguraci zásuvného modulu hesla", + + "VTLANG_NORMAL_MODE": "Spustit normálně", + "VTLANG_WIMBOOT_MODE": "Spustit v režimu wimboot", + "VTLANG_GRUB2_MODE": "Spustit v režimu grub2", + "VTLANG_MEMDISK_MODE": "Spustit v režimu memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Vrátis do zobrazení seznamu", + "VTLANG_RET_TO_TREEVIEW": "Vrátit do zobrazení stromu", + + "VTLANG_NO_AUTOINS_SCRIPT": "Spustit bez šablony automatické instalace", + "VTLANG_AUTOINS_USE": "Spustit s", + + "VTLANG_NO_PERSIST": "Spustit bez perzistence", + "VTLANG_PERSIST_USE": "Spustit s", + + "VTLANG_BROWER_RETURN": "Vrátit", + + "VTLANG_ENTER_EXIT": "zmáčkněte Enter pro ukončení", + "VTLANG_ENTER_REBOOT": "zmáčkněte Enter pro restart", + "VTLANG_ENTER_CONTINUE": "zmáčkněte enter pro pokračování", + + "VTLANG_CTRL_TEMP_SET": "Dočasné řídící nastavení", + "VTLANG_WIN11_BYPASS_CHECK": "Obejít CPU/TPM/SecureBoot kontrolu při instalaci Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Obejít požadování online účtu při instalaci Windows 11", + "VTLANG_LINUX_REMOUNT": "Připojit Hiperiso oddíl po spuštění Linuxu", + "VTLANG_SECONDARY_BOOT_MENU": "Zobrazit druhou spouštěcí nabídku", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/de_DE.json b/src/grub2/grub/menu/de_DE.json new file mode 100644 index 0000000..f2837d6 --- /dev/null +++ b/src/grub2/grub/menu/de_DE.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "German (Deutsch)", + + "VTLANG_STR_HOTKEY_LIST": "L:Sprache F1:Hilfe F2:Browser F3:Listenansicht F4:Lokaler Start F5:Werkzeuge F6:Erweitert", + "VTLANG_STR_HOTKEY_TREE": "L:Sprache F1:Hilfe F2:Browser F3:Listenansicht F4:Lokaler Start F5:Werkzeuge F6:Erweitert", + "VTLANG_RETURN_PREVIOUS": "Zu vorherigem Menü [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Zu vorherigem Menü", + + "VTLANG_MENU_LANG": "Menüsprache auswählen", + + "VTLANG_LB_SBOOT_WINDOWS": "Windows suchen und starten", + "VTLANG_LB_SBOOT_G4D": "Grub4dos suchen und starten", + "VTLANG_LB_SBOOT_HDD1": "Vom ersten lokalen Datenträger starten", + "VTLANG_LB_SBOOT_HDD2": "Vom zweiten lokalen Datenträger starten", + "VTLANG_LB_SBOOT_HDD3": "Vom dritten lokalen Datenträger starten", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI suchen und starten", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI suchen und starten", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI suchen und starten", + "VTLANG_LB_SBOOT_XORBOOT": "xorboot suchen und starten", + + "VTLANG_FILE_CHKSUM": "Dateiprüfsumme", + "VTLANG_CHKSUM_MD5_CALC": "md5sum berechnen", + "VTLANG_CHKSUM_SHA1_CALC": "sha1sum berechnen", + "VTLANG_CHKSUM_SHA256_CALC": "sha256sum berechnen", + "VTLANG_CHKSUM_SHA512_CALC": "sha512sum berechnen", + "VTLANG_CHKSUM_MD5_CALC_CHK": "md5sum berechnen und prüfen", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "sha1sum berechnen und prüfen", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "sha256sum berechnen und prüfen", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "sha512sum berechnen und prüfen", + + "VTLANG_POWER": "Power", + "VTLANG_POWER_REBOOT": "Neustart", + "VTLANG_POWER_HALT": "Herunterfahren", + "VTLANG_POWER_BOOT_EFIFW": "Neustart in EFI-Konfiguration", + + "VTLANG_KEYBRD_LAYOUT": "Tastaturlayout", + "VTLANG_HWINFO": "Hardwareinformationen", + + "VTLANG_RESOLUTION_CFG": "Auflösungseinstellungen", + "VTLANG_SCREEN_MODE": "Bildschirmanzeigemodus", + "VTLANG_SCREEN_TEXT_MODE": "Textmodus erzwingen", + "VTLANG_SCREEN_GUI_MODE": "Grafikmodus erzwingen", + + "VTLANG_THEME_SELECT": "Design auswählen", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI-Dienstprogramme", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFI-Treiber anzeigen", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windows BlinitializeLibrary Fehler beheben", + + "VTLANG_JSON_CHK_JSON": "Konfiguration des JSON-Plugins prüfen (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Konfiguration des Plugins für die allgemeine Kontrolle prüfen", + "VTLANG_JSON_CHK_THEME": "Konfiguration des Design-Plugins prüfen", + "VTLANG_JSON_CHK_AUTOINS": "Konfiguration des Plugins für die automatische Installation prüfen", + "VTLANG_JSON_CHK_PERSIST": "Konfiguration des Persistenz-Plugins prüfen", + "VTLANG_JSON_CHK_MENU_ALIAS": "Konfiguration des Menü-Alias-Plugin prüfen", + "VTLANG_JSON_CHK_MENU_TIP": "Konfiguration des Menütipp-Plugins prüfen", + "VTLANG_JSON_CHK_MENU_CLASS": "Konfiguration des Menüklassen-Plugins prüfen", + "VTLANG_JSON_CHK_INJECTION": "Konfiguration des Injektions-Plugins prüfen", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Konfiguration des auto-memdisk-Plugins prüfen", + "VTLANG_JSON_CHK_IMG_LIST": "Konfiguration des Abbild-Listen-Plugins prüfen", + "VTLANG_JSON_CHK_IMG_BLIST": "Konfiguration des Abbild-Sperrlisten-Plugins prüfen", + "VTLANG_JSON_CHK_CONF_REPLACE": "Konfiguration des Boot-Conf-Replace-Plugins prüfen", + "VTLANG_JSON_CHK_DUD": "Konfiguration des dud-Plugins prüfen", + "VTLANG_JSON_CHK_PASSWORD": "Konfiguration des Passwort-Plugins prüfen", + + "VTLANG_NORMAL_MODE": "In Normal-Modus starten", + "VTLANG_WIMBOOT_MODE": "In wimboot-Modus starten", + "VTLANG_GRUB2_MODE": "In grub2-Modus starten", + "VTLANG_MEMDISK_MODE": "In memdisk-Modus starten", + + "VTLANG_RET_TO_LISTVIEW": "Zurück zur Listenansicht", + "VTLANG_RET_TO_TREEVIEW": "Zurück zur Baumansicht", + + "VTLANG_NO_AUTOINS_SCRIPT": "Ohne Vorlage für die automatische Installation starten", + "VTLANG_AUTOINS_USE": "Start mit", + + "VTLANG_NO_PERSIST": "Ohne Persistenz starten", + "VTLANG_PERSIST_USE": "Start mit", + + "VTLANG_BROWER_RETURN": "Zurück", + + "VTLANG_ENTER_EXIT": "Drücken Sie zum Beenden die Eingabetaste", + "VTLANG_ENTER_REBOOT": "Drücken Sie die Eingabetaste, um neu zu starten", + "VTLANG_ENTER_CONTINUE": "Drücken Sie die Eingabetaste, um fortzufahren", + + "VTLANG_CTRL_TEMP_SET": "Temporäre Steuerungseinstellungen", + "VTLANG_WIN11_BYPASS_CHECK": "Umgehen Sie die CPU/TPM/SecureBoot-Prüfung bei der Installation von Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Umgehen Sie die Online-Kontoanforderung bei der Installation von Windows 11", + "VTLANG_LINUX_REMOUNT": "Mounten Sie die Hiperiso-Partition nach dem Booten von Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Sekundäres Bootmenü anzeigen", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/el_GR.json b/src/grub2/grub/menu/el_GR.json new file mode 100644 index 0000000..7d97be3 --- /dev/null +++ b/src/grub2/grub/menu/el_GR.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Greek (Ελληνικά)", + + "VTLANG_STR_HOTKEY_LIST": "L:Γλώσσα F1:Βοήθεια F2:Περιήγηση F3:Προβολή Λίστας F4:Εκκίνηση από τοπικό δίσκο F5:Εργαλεία F6:Προσ. Μενού", + "VTLANG_STR_HOTKEY_TREE": "L:Γλώσσα F1:Βοήθεια F2:Περιήγηση F3:Προβολή Δένδρου F4:Εκκίνηση από τοπικό δίσκο F5:Εργαλεία F6:Προσ. Μενού", + "VTLANG_RETURN_PREVIOUS": "Επιστροφή στο προηγούμενο μενού [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Επιστροφή στο προηγούμενο μενού", + + "VTLANG_MENU_LANG": "Επιλογή Γλώσσας Μενού", + + "VTLANG_LB_SBOOT_WINDOWS": "Αναζήτηση και εκκίνηση των Windows", + "VTLANG_LB_SBOOT_G4D": "Αναζήτηση και εκκίνηση του Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Εκκίνηση του 1ου τοπικού δίσκου", + "VTLANG_LB_SBOOT_HDD2": "Εκκίνηση του 2ου τοπικού δίσκου", + "VTLANG_LB_SBOOT_HDD3": "Εκκίνηση του 3ου τοπικού δίσκου", + "VTLANG_LB_SBOOT_X64EFI": "Αναζήτηση και εκκίνηση του BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Αναζήτηση και εκκίνηση του BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Αναζήτηση και εκκίνηση του BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Αναζήτηση και εκκίνηση του xorboot", + + "VTLANG_FILE_CHKSUM": "Αρχείο checksum", + "VTLANG_CHKSUM_MD5_CALC": "Υπολογισμός md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Υπολογισμός sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Υπολογισμός sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Υπολογισμός sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Υπολογισμός και έλεγχος md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Υπολογισμός και έλεγχος sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Υπολογισμός και έλεγχος sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Υπολογισμός και έλεγχος sha512sum", + + "VTLANG_POWER": "Λειτουργία", + "VTLANG_POWER_REBOOT": "Επανεκκίνηση", + "VTLANG_POWER_HALT": "Απενεργοποίηση", + "VTLANG_POWER_BOOT_EFIFW": "Επανεκκίνηση σε EFI setup", + + "VTLANG_KEYBRD_LAYOUT": "Διατάξεις Πληκτρολογίου", + "VTLANG_HWINFO": "Πληροφορίες υλικού", + + "VTLANG_RESOLUTION_CFG": "Διαμόρφωση ανάλυσης", + "VTLANG_SCREEN_MODE": "Λειτουργία Προβολής Οθόνης", + "VTLANG_SCREEN_TEXT_MODE": "Επιβολή λειτουργίας κειμένου", + "VTLANG_SCREEN_GUI_MODE": "Επιβολή λειτουργίας Γραφικών (GUI)", + + "VTLANG_THEME_SELECT": "Επιλογή Θέματος", + + "VTLANG_UEFI_UTIL": "Εργαλεία Hiperiso UEFI", + "VTLANG_UTIL_SHOW_EFI_DRV": "Προβολή EFI Drivers", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Διόρθωση αποτυχίας Windows BlinitializeLibrary", + + "VTLANG_JSON_CHK_JSON": "Ελεγχος διαμόρφωσης json πρόσθετων (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Ελεγχος διαμόρφωσης του πρόσθετου καθολικού ελέγχου", + "VTLANG_JSON_CHK_THEME": "Ελεγχος διαμόρφωσης του πρόσθετου θέματος", + "VTLANG_JSON_CHK_AUTOINS": "Ελεγχος διαμόρφωσης του πρόσθετου αυτόματης εγκατάστασης", + "VTLANG_JSON_CHK_PERSIST": "Ελεγχος διαμόρφωσης του πρόσθετου επιμονής", + "VTLANG_JSON_CHK_MENU_ALIAS": "Ελεγχος διαμόρφωσης του πρόσθετου ψευδώνυμου μενού", + "VTLANG_JSON_CHK_MENU_TIP": "Ελεγχος διαμόρφωσης του πρόσθετου συμβουλών μενού", + "VTLANG_JSON_CHK_MENU_CLASS": "Ελεγχος διαμόρφωσης του πρόσθετου κατηγορίας μενού", + "VTLANG_JSON_CHK_INJECTION": "Ελεγχος διαμόρφωσης του πρόσθετου injection", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Ελεγχος διαμόρφωσης του πρόσθετου auto memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "Ελεγχος διαμόρφωσης του πρόσθετου Λίστα images", + "VTLANG_JSON_CHK_IMG_BLIST": "Ελεγχος διαμόρφωσης του πρόσθετου Μαύρη λίστα images", + "VTLANG_JSON_CHK_CONF_REPLACE": "Ελεγχος διαμόρφωσης του πρόσθετου Αντικατάσταση διαμόρφ. εκκίνησης", + "VTLANG_JSON_CHK_DUD": "Ελεγχος διαμόρφωσης του πρόσθετου dud", + "VTLANG_JSON_CHK_PASSWORD": "Ελεγχος διαμόρφωσης του πρόσθετου Κωδικός πρόσβασης", + + "VTLANG_NORMAL_MODE": "Κανονική εκκίνηση", + "VTLANG_WIMBOOT_MODE": "Εκκίνηση σε λειτουργία wimboot", + "VTLANG_GRUB2_MODE": "Εκκίνηση σε λειτουργία grub2", + "VTLANG_MEMDISK_MODE": "Εκκίνηση σε λειτουργία memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Επιστροφή σε Προβολή Λίστας", + "VTLANG_RET_TO_TREEVIEW": "Επιστροφή σε Προβολή Δένδρου", + + "VTLANG_NO_AUTOINS_SCRIPT": "Εκκίνηση χωρίς πρότυπο αυτόματης εγκατάστασης", + "VTLANG_AUTOINS_USE": "Εκκίνηση", + + "VTLANG_NO_PERSIST": "Εκκίνηση χωρίς επιμονή", + "VTLANG_PERSIST_USE": "Εκκίνηση", + + "VTLANG_BROWER_RETURN": "Επιστροφή", + + "VTLANG_ENTER_EXIT": "πατήστε το πλήκτρο Enter για έξοδο", + "VTLANG_ENTER_REBOOT": "πατήστε το πλήκτρο Enter για επανεκκίνηση", + "VTLANG_ENTER_CONTINUE": "πατήστε το πλήκτρο Enter για να συνεχίσετε", + + "VTLANG_CTRL_TEMP_SET": "Προσωρινές ρυθμίσεις ελέγχου", + "VTLANG_WIN11_BYPASS_CHECK": "Παράκαμψη ελέγχου CPU/TPM/SecureBoot κατά την εγκατάσταση των Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Παράκαμψη της απαίτησης online λογαριασμού κατά την εγκατάσταση των Windows 11", + "VTLANG_LINUX_REMOUNT": "Προσάρτηση διαμερίσματος Hiperiso μετά την εκκίνηση του Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Εμφάνιση δευτερεύοντος μενού εκκίνησης", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} \ No newline at end of file diff --git a/src/grub2/grub/menu/en_US.json b/src/grub2/grub/menu/en_US.json new file mode 100644 index 0000000..47cb7f4 --- /dev/null +++ b/src/grub2/grub/menu/en_US.json @@ -0,0 +1,98 @@ +{ + "VTLANG_LANGUAGE_NAME": "English (English)", + + "VTLANG_STR_HOTKEY_LIST": "L:Language F1:Help F2:Browse F3:ListView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:Language F1:Help F2:Browse F3:TreeView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "Return to previous menu [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Return to previous menu", + + "VTLANG_MENU_LANG": "Menu Language Select", + + "VTLANG_LB_SBOOT_WINDOWS": "Search and boot Windows", + "VTLANG_LB_SBOOT_G4D": "Search and boot Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Boot the 1st local disk", + "VTLANG_LB_SBOOT_HDD2": "Boot the 2nd local disk", + "VTLANG_LB_SBOOT_HDD3": "Boot the 3rd local disk", + "VTLANG_LB_SBOOT_X64EFI": "Search and boot BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Search and boot BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Search and boot BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Search and boot xorboot", + + "VTLANG_FILE_CHKSUM": "File checksum", + "VTLANG_CHKSUM_MD5_CALC": "Calculate md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Calculate sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Calculate sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Calculate sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calculate and check md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calculate and check sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calculate and check sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calculate and check sha512sum", + + "VTLANG_POWER": "Power", + "VTLANG_POWER_REBOOT": "Reboot", + "VTLANG_POWER_HALT": "Halt", + "VTLANG_POWER_BOOT_EFIFW": "Reboot to EFI setup", + + "VTLANG_KEYBRD_LAYOUT": "Keyboard Layouts", + "VTLANG_HWINFO": "Hardware Information", + + "VTLANG_RESOLUTION_CFG": "Resolution Configuration", + "VTLANG_SCREEN_MODE": "Screen Display Mode", + "VTLANG_SCREEN_TEXT_MODE": "Force Text Mode", + "VTLANG_SCREEN_GUI_MODE": "Force Graphics Mode", + + "VTLANG_THEME_SELECT": "Theme Select", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "Show EFI Drivers", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Fixup Windows BlinitializeLibrary Failure", + + "VTLANG_JSON_CHK_JSON": "Check plugin json configuration (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Check global control plugin configuration", + "VTLANG_JSON_CHK_THEME": "Check theme plugin configuration", + "VTLANG_JSON_CHK_AUTOINS": "Check auto install plugin configuration", + "VTLANG_JSON_CHK_PERSIST": "Check persistence plugin configuration", + "VTLANG_JSON_CHK_MENU_ALIAS": "Check menu alias plugin configuration", + "VTLANG_JSON_CHK_MENU_TIP": "Check menu tip plugin configuration", + "VTLANG_JSON_CHK_MENU_CLASS": "Check menu class plugin configuration", + "VTLANG_JSON_CHK_INJECTION": "Check injection plugin configuration", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Check auto memdisk plugin configuration", + "VTLANG_JSON_CHK_IMG_LIST": "Check image list plugin configuration", + "VTLANG_JSON_CHK_IMG_BLIST": "Check image blacklist plugin configuration", + "VTLANG_JSON_CHK_CONF_REPLACE": "Check boot conf replace plugin configuration", + "VTLANG_JSON_CHK_DUD": "Check dud plugin configuration", + "VTLANG_JSON_CHK_PASSWORD": "Check password plugin configuration", + + "VTLANG_NORMAL_MODE": "Boot in normal mode", + "VTLANG_WIMBOOT_MODE": "Boot in wimboot mode", + "VTLANG_GRUB2_MODE": "Boot in grub2 mode", + "VTLANG_MEMDISK_MODE": "Boot in memdisk mode", + + "VTLANG_RET_TO_LISTVIEW": "Return to ListView", + "VTLANG_RET_TO_TREEVIEW": "Return to TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "Boot without auto installation template", + "VTLANG_AUTOINS_USE": "Boot with", + + "VTLANG_NO_PERSIST": "Boot without persistence", + "VTLANG_PERSIST_USE": "Boot with", + + "VTLANG_BROWER_RETURN": "Return", + + "VTLANG_ENTER_EXIT": "press Enter key to exit", + "VTLANG_ENTER_REBOOT": "press Enter key to reboot", + "VTLANG_ENTER_CONTINUE": "press Enter key to continue", + + "VTLANG_CTRL_TEMP_SET": "Temporary Control Settings", + "VTLANG_WIN11_BYPASS_CHECK": "Bypass CPU/TPM/SecureBoot check when install Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Bypass online account requirement when install Windows 11", + "VTLANG_LINUX_REMOUNT": "Mount Hiperiso partition after boot Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Show secondary boot menu", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/es_ES.json b/src/grub2/grub/menu/es_ES.json new file mode 100644 index 0000000..3cbf481 --- /dev/null +++ b/src/grub2/grub/menu/es_ES.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Spanish (Español)", + + "VTLANG_STR_HOTKEY_LIST": "L:Idioma F1:Ayuda F2:Navegar F3:Vista de lista F4:Arranque local F5:Herramientas F6:Menú ext.", + "VTLANG_STR_HOTKEY_TREE": "L:Idioma F1:Ayuda F2:Navegar F3:Vista de árbol F4:Arranque local F5:Herramientas F6:Menú ext.", + "VTLANG_RETURN_PREVIOUS": "Regresar al menú anterior [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Regresar al menú anterior", + + "VTLANG_MENU_LANG": "Selección de idioma del menú", + + "VTLANG_LB_SBOOT_WINDOWS": "Buscar y arrancar Windows", + "VTLANG_LB_SBOOT_G4D": "Buscar y arrancar Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Arrancar el 1er disco local", + "VTLANG_LB_SBOOT_HDD2": "Arrancar el 2do disco local", + "VTLANG_LB_SBOOT_HDD3": "Arrancar el 3er disco local", + "VTLANG_LB_SBOOT_X64EFI": "Buscar y arrancar BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Buscar y arrancar BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Buscar y arrancar BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Buscar y arrancar xorboot", + + "VTLANG_FILE_CHKSUM": "Suma de comprobación del archivo", + "VTLANG_CHKSUM_MD5_CALC": "Calcular md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Calcular sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Calcular sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Calcular sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calcular y comprobar md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calcular y comprobar sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calcular y comprobar sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calcular y comprobar sha512sum", + + "VTLANG_POWER": "Energía", + "VTLANG_POWER_REBOOT": "Reiniciar", + "VTLANG_POWER_HALT": "Apagar", + "VTLANG_POWER_BOOT_EFIFW": "Reiniciar a la configuración EFI", + + "VTLANG_KEYBRD_LAYOUT": "Distribuciones de teclado", + "VTLANG_HWINFO": "Información de hardware", + + "VTLANG_RESOLUTION_CFG": "Configuración de resolución", + "VTLANG_SCREEN_MODE": "Modo de visualización de pantalla", + "VTLANG_SCREEN_TEXT_MODE": "Forzar modo texto", + "VTLANG_SCREEN_GUI_MODE": "Forzar modo gráfico", + + "VTLANG_THEME_SELECT": "Selección de tema", + + "VTLANG_UEFI_UTIL": "Utilidades UEFI de Hiperiso", + "VTLANG_UTIL_SHOW_EFI_DRV": "Mostrar controladores EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Reparar error BlinitializeLibrary de Windows", + + "VTLANG_JSON_CHK_JSON": "Comprobar configuración del complemento de json (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Comprobar configuración del complemento de control global", + "VTLANG_JSON_CHK_THEME": "Comprobar configuración del complemento de tema", + "VTLANG_JSON_CHK_AUTOINS": "Comprobar configuración del complemento de autoinstalación", + "VTLANG_JSON_CHK_PERSIST": "Comprobar configuración del complemento de persistencia", + "VTLANG_JSON_CHK_MENU_ALIAS": "Comprobar configuración del complemento de alias de menú", + "VTLANG_JSON_CHK_MENU_TIP": "Comprobar configuración del complemento de consejo de menú", + "VTLANG_JSON_CHK_MENU_CLASS": "Comprobar configuración del complemento de clases de menú", + "VTLANG_JSON_CHK_INJECTION": "Comprobar configuración del complemento de inyección", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Comprobar configuración del complemento auto memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "Comprobar configuración del complemento de lista de imágenes", + "VTLANG_JSON_CHK_IMG_BLIST": "Comprobar configuración del complemento de lista negra de imágenes", + "VTLANG_JSON_CHK_CONF_REPLACE": "Comprobar configuración del complemento de reemplazo de configuración de arranque", + "VTLANG_JSON_CHK_DUD": "Comprobar configuración del complemento dud", + "VTLANG_JSON_CHK_PASSWORD": "Comprobar configuración del complemento de contraseñas", + + "VTLANG_NORMAL_MODE": "Arrancar en modo normal", + "VTLANG_WIMBOOT_MODE": "Arrancar en modo wimboot", + "VTLANG_GRUB2_MODE": "Arrancar en modo grub2", + "VTLANG_MEMDISK_MODE": "Arrancar en modo memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Regresar a vista de lista", + "VTLANG_RET_TO_TREEVIEW": "regresar a vista de árbol", + + "VTLANG_NO_AUTOINS_SCRIPT": "Arrancar sin plantilla de autoinstalación", + "VTLANG_AUTOINS_USE": "Arrancar con", + + "VTLANG_NO_PERSIST": "Arrancar sin persistencia", + "VTLANG_PERSIST_USE": "Arrancar con", + + "VTLANG_BROWER_RETURN": "Regresar", + + "VTLANG_ENTER_EXIT": "Presiona la tecla Entrar para salir", + "VTLANG_ENTER_REBOOT": "Presiona la tecla Entrar para reiniciar", + "VTLANG_ENTER_CONTINUE": "Presiona la tecla Entrar para continuar", + + "VTLANG_CTRL_TEMP_SET": "Ajustes de control temporales", + "VTLANG_WIN11_BYPASS_CHECK": "Omitir comprobación de CPU/TPM/SecureBoot al instalar Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Omitir requisito de cuenta en línea al instalar Windows 11", + "VTLANG_LINUX_REMOUNT": "Montar partición de Hiperiso después de arrancar Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Mostrar menú de arranque secundario", + "VTLANG_WIN_UEFI_RES_LOCK": "Bloquear la resolución al arrancar Windows/WinPE en modo UEFI", + "VTLANG_UEFI_RES_LOCK_NONE": "Ninguno", + "VTLANG_UEFI_RES_LOCK_MAX": "La más alta", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fija 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "Al menos 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/fa_IR.json b/src/grub2/grub/menu/fa_IR.json new file mode 100644 index 0000000..fb4f2a8 --- /dev/null +++ b/src/grub2/grub/menu/fa_IR.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Persian (فارسی)", + + "VTLANG_STR_HOTKEY_LIST": "L:زبان F1:راهنما F2:مرور F3:نمای لیستی F4:بوت محلی F5:ابزار F6:بازگشت", + "VTLANG_STR_HOTKEY_TREE": "L:زبان F1:راهنما F2:مرور F3:نمای درختی F4:بوت محلی F5:ابزار F6:بازگشت", + "VTLANG_RETURN_PREVIOUS": "بازگشت به منوی قبلی [Esc]", + "VTLANG_RETURN_PRV_NOESC": "بازگشت به منوی قبلی", + + "VTLANG_MENU_LANG": "منوی انتخاب زبان", + + "VTLANG_LB_SBOOT_WINDOWS": "جستجو و بوت ویندوز", + "VTLANG_LB_SBOOT_G4D": "جستجو و بوت Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "بوت اولین دیسک محلی", + "VTLANG_LB_SBOOT_HDD2": "بوت دومین دیسک محلی", + "VTLANG_LB_SBOOT_HDD3": "بوت سومین دیسک محلی", + "VTLANG_LB_SBOOT_X64EFI": "جستجو و بوت BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "جستجو و بوت BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "جستجو و بوت BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "جستجو و بوت xorboot", + + "VTLANG_FILE_CHKSUM": "اعتبارسنجی فایل", + "VTLANG_CHKSUM_MD5_CALC": "محاسبه md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "محاسبه sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "محاسبه sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "محاسبه sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "محاسبه و بررسی md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "محاسبه و بررسی sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "محاسبه و بررسی sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "محاسبه و بررسی sha512sum", + + "VTLANG_POWER": "انرژی", + "VTLANG_POWER_REBOOT": "ریبوت", + "VTLANG_POWER_HALT": "توقف", + "VTLANG_POWER_BOOT_EFIFW": "ریبوت به تنظیمات EFI", + + "VTLANG_KEYBRD_LAYOUT": "نمایه صفحه کلید", + "VTLANG_HWINFO": "اطلاعات سخت افزار", + + "VTLANG_RESOLUTION_CFG": "پیکربندی رزولوشن", + "VTLANG_SCREEN_MODE": "حالت نمایش صفحه", + "VTLANG_SCREEN_TEXT_MODE": "حالت متنی اجباری", + "VTLANG_SCREEN_GUI_MODE": "حالت گرافیکی اجباری", + + "VTLANG_THEME_SELECT": "انتخاب تم", + + "VTLANG_UEFI_UTIL": "ابزار های کمکی Hiperiso UEFI", + "VTLANG_UTIL_SHOW_EFI_DRV": "نمایش درایور های EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "رفع خطای Windows BlinitializeLibrary", + + "VTLANG_JSON_CHK_JSON": "بررسی پیکربندی json افزونه (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "بررسی پیکربندی افزونه کنترل سراسری", + "VTLANG_JSON_CHK_THEME": "بررسی پیکربندی افزونه قالب", + "VTLANG_JSON_CHK_AUTOINS": "بررسی پیکربندی افزونه نصب خودکار", + "VTLANG_JSON_CHK_PERSIST": "بررسی پیکربندی افزونه‌ی تداوم", + "VTLANG_JSON_CHK_MENU_ALIAS": "بررسی پیکربندی افزونه نام مستعار منو", + "VTLANG_JSON_CHK_MENU_TIP": "بررسی پیکربندی افزونه نکته منو", + "VTLANG_JSON_CHK_MENU_CLASS": "بررسی پیکربندی افزونه کلاس منو", + "VTLANG_JSON_CHK_INJECTION": "بررسی پیکربندی افزونه تزریق", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "بررسی پیکربندی افزونه memdisk خودکار", + "VTLANG_JSON_CHK_IMG_LIST": "بررسی پیکربندی افزونه لیست ایمیج ها", + "VTLANG_JSON_CHK_IMG_BLIST": "بررسی پیکربندی افزونه لیست سیاه ایمیج", + "VTLANG_JSON_CHK_CONF_REPLACE": "بررسی پیکربندی افزونه جایگزینی فایل پیکربندی بوت", + "VTLANG_JSON_CHK_DUD": "بررسی پیکربندی افزونه dud", + "VTLANG_JSON_CHK_PASSWORD": "بررسی پیکربندی افزونه کلمه عبور", + + "VTLANG_NORMAL_MODE": "بوت در حالت عادی", + "VTLANG_WIMBOOT_MODE": "بوت در حالت wimboot", + "VTLANG_GRUB2_MODE": "بوت در حالت grub2", + "VTLANG_MEMDISK_MODE": "بوت در حالت memdisk", + + "VTLANG_RET_TO_LISTVIEW": "بازگشت به نمای لیستی", + "VTLANG_RET_TO_TREEVIEW": "بازگشت به نمای درختی", + + "VTLANG_NO_AUTOINS_SCRIPT": "بوت بدون قالب نصب خودکار", + "VTLANG_AUTOINS_USE": "بوت با", + + "VTLANG_NO_PERSIST": "بوت بدون تداوم", + "VTLANG_PERSIST_USE": "بوت با", + + "VTLANG_BROWER_RETURN": "بازگشت", + + "VTLANG_ENTER_EXIT": "جهت خروج دکمه Enter را فشار دهید", + "VTLANG_ENTER_REBOOT": "جهت ریبوت دکمه Enter را فشار دهید", + "VTLANG_ENTER_CONTINUE": "جهت ادامه دکمه Enter را فشار دهید", + + "VTLANG_CTRL_TEMP_SET": "تنظیمات کنترل موقت", + "VTLANG_WIN11_BYPASS_CHECK": "دور زدن بررسی CPU/TPM/SecureBoot در هنگام نصب ویندوز 11", + "VTLANG_WIN11_BYPASS_NRO": "دور زدن نیاز به حساب کاربری آنلاین هنگام نصب ویندوز 11", + "VTLANG_LINUX_REMOUNT": "اتصال پارتیشن Hiperiso بعد از بوت لینوکس", + "VTLANG_SECONDARY_BOOT_MENU": "نمایش منوی بوت ثانویه", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/fr_FR.json b/src/grub2/grub/menu/fr_FR.json new file mode 100644 index 0000000..617027a --- /dev/null +++ b/src/grub2/grub/menu/fr_FR.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "French (Français)", + + "VTLANG_STR_HOTKEY_LIST": "L:Langue F1:Aide F2:Parcourir F3:Affichage liste F4:Démarrage local F5:Outils F6:Menu étendu", + "VTLANG_STR_HOTKEY_TREE": "L:Langue F1:Aide F2:Parcourir F3:Affichage arborescence F4:Démarrage local F5:Outils F6:Menu étendu", + "VTLANG_RETURN_PREVIOUS": "Retour au menu précédent [Echap]", + "VTLANG_RETURN_PRV_NOESC": "Retour au menu précédent", + + "VTLANG_MENU_LANG": "Sélection de la langue des menus", + + "VTLANG_LB_SBOOT_WINDOWS": "Rechercher et démarrer Windows", + "VTLANG_LB_SBOOT_G4D": "Rechercher et démarrer GRUB4DOS", + "VTLANG_LB_SBOOT_HDD1": "Démarrer depuis le 1er disque local", + "VTLANG_LB_SBOOT_HDD2": "Démarrer depuis le 2e disque local", + "VTLANG_LB_SBOOT_HDD3": "Démarrer depuis le 3e disque local", + "VTLANG_LB_SBOOT_X64EFI": "Rechercher et démarrer BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Rechercher et démarrer BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Rechercher et démarrer BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Rechercher et démarrer xorboot", + + "VTLANG_FILE_CHKSUM": "Somme de contrôle du fichier", + "VTLANG_CHKSUM_MD5_CALC": "Calculer MD5", + "VTLANG_CHKSUM_SHA1_CALC": "Calculer SHA1", + "VTLANG_CHKSUM_SHA256_CALC": "Calculer SHA256", + "VTLANG_CHKSUM_SHA512_CALC": "Calculer SHA512", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calculer et vérifier MD5", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calculer et vérifier SHA1", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calculer et vérifier SHA256", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calculer et vérifier SHA512", + + "VTLANG_POWER": "Extinction", + "VTLANG_POWER_REBOOT": "Redémarrer", + "VTLANG_POWER_HALT": "Éteindre", + "VTLANG_POWER_BOOT_EFIFW": "Redémarrer et accéder au menu EFI", + + "VTLANG_KEYBRD_LAYOUT": "Dispositions de clavier", + "VTLANG_HWINFO": "Informations sur le matériel", + + "VTLANG_RESOLUTION_CFG": "Configuration de la résolution", + "VTLANG_SCREEN_MODE": "Mode d’affichage", + "VTLANG_SCREEN_TEXT_MODE": "Mode texte", + "VTLANG_SCREEN_GUI_MODE": "Mode graphique", + + "VTLANG_THEME_SELECT": "Sélection du thème", + + "VTLANG_UEFI_UTIL": "Utilitaires UEFI de Hiperiso", + "VTLANG_UTIL_SHOW_EFI_DRV": "Afficher les pilotes EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Contourner l’échec de Windows BlinitializeLibrary", + + "VTLANG_JSON_CHK_JSON": "Afficher le fichier de configuration (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Afficher la configuration du plugin de contrôle global", + "VTLANG_JSON_CHK_THEME": "Afficher la configuration du plugin de thème", + "VTLANG_JSON_CHK_AUTOINS": "Afficher la configuration du plugin d’installation automatique", + "VTLANG_JSON_CHK_PERSIST": "Afficher la configuration du plugin de persistance", + "VTLANG_JSON_CHK_MENU_ALIAS": "Afficher la configuration du plugin des alias du menu", + "VTLANG_JSON_CHK_MENU_TIP": "Afficher la configuration du plugin des astuces du menu", + "VTLANG_JSON_CHK_MENU_CLASS": "Afficher la configuration du plugin des classes du menu", + "VTLANG_JSON_CHK_INJECTION": "Afficher la configuration du plugin d’injection", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Afficher la configuration du plugin memdisk automatique", + "VTLANG_JSON_CHK_IMG_LIST": "Afficher la configuration du plugin de liste des images", + "VTLANG_JSON_CHK_IMG_BLIST": "Afficher la configuration du plugin de liste noire des images", + "VTLANG_JSON_CHK_CONF_REPLACE": "Afficher la configuration du plugin de substitution des fichiers de démarrage", + "VTLANG_JSON_CHK_DUD": "Afficher la configuration du plugin de disques de mise à jour des pilotes", + "VTLANG_JSON_CHK_PASSWORD": "Afficher la configuration du plugin de mots de passe", + + "VTLANG_NORMAL_MODE": "Démarrer en mode normal", + "VTLANG_WIMBOOT_MODE": "Démarrer en mode WimBoot", + "VTLANG_GRUB2_MODE": "Démarrer en mode GRUB 2", + "VTLANG_MEMDISK_MODE": "Démarrer en mode Memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Revenir à l’affichage en liste", + "VTLANG_RET_TO_TREEVIEW": "Revenir à l’affichage en arborescence", + + "VTLANG_NO_AUTOINS_SCRIPT": "Démarrer en ignorant le modèle d’auto-installation", + "VTLANG_AUTOINS_USE": "Démarrer en chargeant le modèle d’auto-installation", + + "VTLANG_NO_PERSIST": "Démarrer sans persistance", + "VTLANG_PERSIST_USE": "Démarrer avec la persistance", + + "VTLANG_BROWER_RETURN": "Retour", + + "VTLANG_ENTER_EXIT": "appuyez sur la touche Entrée pour quitter", + "VTLANG_ENTER_REBOOT": "appuyez sur la touche Entrée pour redémarrer", + "VTLANG_ENTER_CONTINUE": "appuyez sur la touche Entrée pour continuer", + + "VTLANG_CTRL_TEMP_SET": "Paramètres de contrôle temporaires", + "VTLANG_WIN11_BYPASS_CHECK": "Ignorer la vérification CPU/TPM/SecureBoot lors de l'installation de Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Contourner l'exigence de compte en ligne lors de l'installation de Windows 11", + "VTLANG_LINUX_REMOUNT": "Monter la partition Hiperiso après le démarrage de Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Afficher le menu de démarrage secondaire", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/hi_HI.json b/src/grub2/grub/menu/hi_HI.json new file mode 100644 index 0000000..6fe84bb --- /dev/null +++ b/src/grub2/grub/menu/hi_HI.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Hindi (हिन्दी)", + + "VTLANG_STR_HOTKEY_LIST": "L:भाषा F1:मदद F2:ब्राउज़र F3:ListView F4:स्थानीयबूट F5:उपकरण F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:भाषा F1:मदद F2:ब्राउज़र F3:TreeView F4:स्थानीयबूट F5:उपकरण F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "पिछले मेनू पर लौटें [Esc]", + "VTLANG_RETURN_PRV_NOESC": "पिछले मेनू पर लौटें", + + "VTLANG_MENU_LANG": "मेनू भाषा का चयन करें", + + "VTLANG_LB_SBOOT_WINDOWS": "Windows खोजें और बूट करें", + "VTLANG_LB_SBOOT_G4D": "Grub4dos खोजें और बूट करें", + "VTLANG_LB_SBOOT_HDD1": "पहली(1st) स्थानीय डिस्क को बूट करें", + "VTLANG_LB_SBOOT_HDD2": "दूसरी(2nd) स्थानीय डिस्क बूट करें", + "VTLANG_LB_SBOOT_HDD3": "तीसरी(3rd) स्थानीय डिस्क बूट करें", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI खोजें और बूट करें", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI खोजें और बूट करें", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI खोजें और बूट करें", + "VTLANG_LB_SBOOT_XORBOOT": "xorboot खोजें और बूट करें", + + "VTLANG_FILE_CHKSUM": "फ़ाइल चेकसम", + "VTLANG_CHKSUM_MD5_CALC": "Md5sum की गणना करें", + "VTLANG_CHKSUM_SHA1_CALC": "sha1sum की गणना करें", + "VTLANG_CHKSUM_SHA256_CALC": "sha256sum की गणना करें", + "VTLANG_CHKSUM_SHA512_CALC": "sha512sum की गणना करें", + "VTLANG_CHKSUM_MD5_CALC_CHK": "md5sum की गणना और जाँच करें", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "sha1sum की गणना और जाँच करें", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "sha256sum की गणना और जाँच करें", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "sha512sum की गणना और जाँच करें", + + "VTLANG_POWER": "पावर", + "VTLANG_POWER_REBOOT": "रीबूट", + "VTLANG_POWER_HALT": "हाल्ट", + "VTLANG_POWER_BOOT_EFIFW": "EFI सेटअप के लिए रीबूट करें", + + "VTLANG_KEYBRD_LAYOUT": "कीबोर्ड लेआउट", + "VTLANG_HWINFO": "हार्डवेयर की जानकारी", + + "VTLANG_RESOLUTION_CFG": "रिज़ॉल्यूशन कॉन्फ़िगरेशन", + "VTLANG_SCREEN_MODE": "Screen Display मोड", + "VTLANG_SCREEN_TEXT_MODE": "फोर्स Text मोड", + "VTLANG_SCREEN_GUI_MODE": "फोर्स Graphics मोड", + + "VTLANG_THEME_SELECT": "थीम का चयन", + + "VTLANG_UEFI_UTIL": "वेंटोय UEFI यूटिलिटीज", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFI ड्राइवर्स दिखाएं", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windows BlinitializeLibrary विफलता को ठीक करें", + + "VTLANG_JSON_CHK_JSON": "प्लगइन json विन्यास की जाँच करें (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "global control प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_THEME": "theme प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_AUTOINS": "auto install प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_PERSIST": "persistence प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_MENU_ALIAS": "menu alias प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_MENU_TIP": "menu tip प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_MENU_CLASS": "menu class प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_INJECTION": "injection प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "auto memdisk प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_IMG_LIST": "image list प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_IMG_BLIST": "image blacklist प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_CONF_REPLACE": "boot conf replace प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_DUD": "dud प्लगइन विन्यास की जाँच करें", + "VTLANG_JSON_CHK_PASSWORD": "password प्लगइन विन्यास की जाँच करें", + + "VTLANG_NORMAL_MODE": "सामान्य मोड में बूट करें", + "VTLANG_WIMBOOT_MODE": "wimboot मोड में बूट करें", + "VTLANG_GRUB2_MODE": "grub2 मोड में बूट करें", + "VTLANG_MEMDISK_MODE": "memdisk मोड में बूट करें", + + "VTLANG_RET_TO_LISTVIEW": "ListView पर वापस जाएँ", + "VTLANG_RET_TO_TREEVIEW": "TreeView पर वापस जाएँ", + + "VTLANG_NO_AUTOINS_SCRIPT": "ऑटो इंस्टॉलेशन टेम्पलेट के बिना बूट करें", + "VTLANG_AUTOINS_USE": "के साथ बूट करें", + + "VTLANG_NO_PERSIST": "बिना persistence के बूट करें", + "VTLANG_PERSIST_USE": "के साथ बूट करें", + + "VTLANG_BROWER_RETURN": "लौटें", + + "VTLANG_ENTER_EXIT": "बाहर निकलने के लिए एंटर कुंजी दबाएं", + "VTLANG_ENTER_REBOOT": "रिबूट करने के लिए एंटर कुंजी दबाएं", + "VTLANG_ENTER_CONTINUE": "जारी रखने के लिए एंटर कुंजी दबाएं", + + "VTLANG_CTRL_TEMP_SET": "अस्थायी नियंत्रण सेटिंग्स", + "VTLANG_WIN11_BYPASS_CHECK": "जब विंडोज 11 स्थापित करें, CPU/TPM/SECUREBOOT CHECK को बायपास करें", + "VTLANG_WIN11_BYPASS_NRO": "विंडोज 11 स्थापित करते समय ऑनलाइन खाते की आवश्यकता बाईपास", + "VTLANG_LINUX_REMOUNT": "लिनक्स बूट के बाद वेंटॉय विभाजन को माउंट करें", + "VTLANG_SECONDARY_BOOT_MENU": "द्वितीयक बूट मेनू दिखाएं", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/hr_HR.json b/src/grub2/grub/menu/hr_HR.json new file mode 100644 index 0000000..4ddef87 --- /dev/null +++ b/src/grub2/grub/menu/hr_HR.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Croatian (Hrvatski)", + + "VTLANG_STR_HOTKEY_LIST": "L:Jezik F1:Help F2:Browse F3:ListView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:Jezik F1:Help F2:Browse F3:TreeView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "Return to previous menu [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Return to previous menu", + + "VTLANG_MENU_LANG": "Menu Language Select", + + "VTLANG_LB_SBOOT_WINDOWS": "Search and boot Windows", + "VTLANG_LB_SBOOT_G4D": "Search and boot Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Boot the 1st local disk", + "VTLANG_LB_SBOOT_HDD2": "Boot the 2nd local disk", + "VTLANG_LB_SBOOT_HDD3": "Boot the 3rd local disk", + "VTLANG_LB_SBOOT_X64EFI": "Search and boot BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Search and boot BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Search and boot BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Search and boot xorboot", + + "VTLANG_FILE_CHKSUM": "File checksum", + "VTLANG_CHKSUM_MD5_CALC": "Calculate md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Calculate sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Calculate sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Calculate sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calculate and check md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calculate and check sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calculate and check sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calculate and check sha512sum", + + "VTLANG_POWER": "Power", + "VTLANG_POWER_REBOOT": "Reboot", + "VTLANG_POWER_HALT": "Halt", + "VTLANG_POWER_BOOT_EFIFW": "Reboot to EFI setup", + + "VTLANG_KEYBRD_LAYOUT": "Keyboard Layouts", + "VTLANG_HWINFO": "Hardware Information", + + "VTLANG_RESOLUTION_CFG": "Resolution Configuration", + "VTLANG_SCREEN_MODE": "Screen Display Mode", + "VTLANG_SCREEN_TEXT_MODE": "Force Text Mode", + "VTLANG_SCREEN_GUI_MODE": "Force Graphics Mode", + + "VTLANG_THEME_SELECT": "Theme Select", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "Show EFI Drivers", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Fixup Windows BlinitializeLibrary Failure", + + "VTLANG_JSON_CHK_JSON": "Check plugin json configuration (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Check global control plugin configuration", + "VTLANG_JSON_CHK_THEME": "Check theme plugin configuration", + "VTLANG_JSON_CHK_AUTOINS": "Check auto install plugin configuration", + "VTLANG_JSON_CHK_PERSIST": "Check persistence plugin configuration", + "VTLANG_JSON_CHK_MENU_ALIAS": "Check menu alias plugin configuration", + "VTLANG_JSON_CHK_MENU_TIP": "Check menu tip plugin configuration", + "VTLANG_JSON_CHK_MENU_CLASS": "Check menu class plugin configuration", + "VTLANG_JSON_CHK_INJECTION": "Check injection plugin configuration", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Check auto memdisk plugin configuration", + "VTLANG_JSON_CHK_IMG_LIST": "Check image list plugin configuration", + "VTLANG_JSON_CHK_IMG_BLIST": "Check image blacklist plugin configuration", + "VTLANG_JSON_CHK_CONF_REPLACE": "Check boot conf replace plugin configuration", + "VTLANG_JSON_CHK_DUD": "Check dud plugin configuration", + "VTLANG_JSON_CHK_PASSWORD": "Check password plugin configuration", + + "VTLANG_NORMAL_MODE": "Boot in normal mode", + "VTLANG_WIMBOOT_MODE": "Boot in wimboot mode", + "VTLANG_GRUB2_MODE": "Boot in grub2 mode", + "VTLANG_MEMDISK_MODE": "Boot in memdisk mode", + + "VTLANG_RET_TO_LISTVIEW": "Return to ListView", + "VTLANG_RET_TO_TREEVIEW": "Return to TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "Boot without auto installation template", + "VTLANG_AUTOINS_USE": "Boot with", + + "VTLANG_NO_PERSIST": "Boot without persistence", + "VTLANG_PERSIST_USE": "Boot with", + + "VTLANG_BROWER_RETURN": "Return", + + "VTLANG_ENTER_EXIT": "pritisnite tipku Enter za izlaz", + "VTLANG_ENTER_REBOOT": "pritisnite tipku Enter za ponovno pokretanje", + "VTLANG_ENTER_CONTINUE": "pritisnite tipku Enter za nastavak", + + "VTLANG_CTRL_TEMP_SET": "Temporary Control Settings", + "VTLANG_WIN11_BYPASS_CHECK": "Bypass CPU/TPM/SecureBoot check when install Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Bypass online account requirement when install Windows 11", + "VTLANG_LINUX_REMOUNT": "Mount Hiperiso partition after boot Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Show secondary boot menu", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/hu_HU.json b/src/grub2/grub/menu/hu_HU.json new file mode 100644 index 0000000..7032e4f --- /dev/null +++ b/src/grub2/grub/menu/hu_HU.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Magyar (Hungarian)", + + "VTLANG_STR_HOTKEY_LIST": "L:Nyelv F1:Súgó F2:Tallózás F3:Listanézet F4:Helyi indítás F5:Eszközök F6:Bővített menü", + "VTLANG_STR_HOTKEY_TREE": "L:Nyelv F1:Súgó F2:Tallózás F3:Fanézet F4:Helyi indítás F5:Eszközök F6:Bővített menü", + "VTLANG_RETURN_PREVIOUS": "Vissza az előző menübe [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Vissza az előző menübe", + + "VTLANG_MENU_LANG": "Menü nyelvének kiválasztása", + + "VTLANG_LB_SBOOT_WINDOWS": "Windows keresése és indítása", + "VTLANG_LB_SBOOT_G4D": "Grub4dos keresése és indítása", + "VTLANG_LB_SBOOT_HDD1": "Indítás az 1. helyi lemezről", + "VTLANG_LB_SBOOT_HDD2": "Indítás a 2. helyi lemezről", + "VTLANG_LB_SBOOT_HDD3": "Indítás a 3. helyi lemezről", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI keresése és indítása", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI keresése és indítása", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI keresése és indítása", + "VTLANG_LB_SBOOT_XORBOOT": "xorboot keresése és indítása", + + "VTLANG_FILE_CHKSUM": "Fájl ellenőrzőösszege", + "VTLANG_CHKSUM_MD5_CALC": "md5sum kiszámítása", + "VTLANG_CHKSUM_SHA1_CALC": "sha1sum kiszámítása", + "VTLANG_CHKSUM_SHA256_CALC": "sha256sum kiszámítása", + "VTLANG_CHKSUM_SHA512_CALC": "sha512sum kiszámítása", + "VTLANG_CHKSUM_MD5_CALC_CHK": "md5sum kiszámítása és ellenőrzése", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "sha1sum kiszámítása és ellenőrzése", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "sha256sum kiszámítása és ellenőrzése", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "sha512sum kiszámítása és ellenőrzése", + + "VTLANG_POWER": "Főkapcsoló", + "VTLANG_POWER_REBOOT": "Újraindítás", + "VTLANG_POWER_HALT": "Leállítás", + "VTLANG_POWER_BOOT_EFIFW": "Újraindítás EFI beállításba", + + "VTLANG_KEYBRD_LAYOUT": "Billentyűzetkiosztások", + "VTLANG_HWINFO": "Hardverinformációk", + + "VTLANG_RESOLUTION_CFG": "Felbontás beállítása", + "VTLANG_SCREEN_MODE": "Képernyő megjelenítési módja", + "VTLANG_SCREEN_TEXT_MODE": "Szöveges mód kényszerítése", + "VTLANG_SCREEN_GUI_MODE": "Grafikus mód kényszerítése", + + "VTLANG_THEME_SELECT": "Téma kiválasztása", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI-segédprogramok", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFI-illesztőprogramok megjelenítése", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "A Windows BlinitializeLibrary hibájának javítása", + + "VTLANG_JSON_CHK_JSON": "A bővítmény JSON-beállításának (hiperiso.json) ellenőrzése", + "VTLANG_JSON_CHK_CONTROL": "A globális vezérlőbővítmény beállításának ellenőrzése", + "VTLANG_JSON_CHK_THEME": "A téma bővítmény beállításnak ellenőrzése", + "VTLANG_JSON_CHK_AUTOINS": "Az automatikus telepítés bővítmény beállításának ellenőrzése", + "VTLANG_JSON_CHK_PERSIST": "Az állandóság bővítmény beállításának ellenőrzése", + "VTLANG_JSON_CHK_MENU_ALIAS": "A menüálnév bővítmény beállításának ellenőrzése", + "VTLANG_JSON_CHK_MENU_TIP": "A menütipp bővítmény beállításának ellenőrzése", + "VTLANG_JSON_CHK_MENU_CLASS": "A menüosztály bővítmény beállításának ellenőrzése", + "VTLANG_JSON_CHK_INJECTION": "A befecskendezés bővítmény beállításnak ellenőrzése", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Az automatikus memórialemez bővítmény beállításának ellenőrzése", + "VTLANG_JSON_CHK_IMG_LIST": "A lemezképlista bővítmény beállításnak ellenőrzése", + "VTLANG_JSON_CHK_IMG_BLIST": "A lemezkép-tiltólista bővítmény beállításnak ellenőrzése", + "VTLANG_JSON_CHK_CONF_REPLACE": "Az indítási beállítás csere bővítmény beállításnak ellenőrzése", + "VTLANG_JSON_CHK_DUD": "A dud bővítmény beállításnak ellenőrzése", + "VTLANG_JSON_CHK_PASSWORD": "A jelszó bővítmény beállításnak ellenőrzése", + + "VTLANG_NORMAL_MODE": "Indítás normál módban", + "VTLANG_WIMBOOT_MODE": "Indítás wimboot módban", + "VTLANG_GRUB2_MODE": "Indítás grub2 módban", + "VTLANG_MEMDISK_MODE": "Indítás memórialemez módban", + + "VTLANG_RET_TO_LISTVIEW": "Vissza a listanézethez", + "VTLANG_RET_TO_TREEVIEW": "Vissza a fanézethez", + + "VTLANG_NO_AUTOINS_SCRIPT": "Indítás automatikus telepítési sablon nélkül", + "VTLANG_AUTOINS_USE": "Indítás ezzel:", + + "VTLANG_NO_PERSIST": "Indítás állandóság nélkül", + "VTLANG_PERSIST_USE": "Indítás ezzel:", + + "VTLANG_BROWER_RETURN": "Vissza", + + "VTLANG_ENTER_EXIT": "nyomja meg az Enter billentyűt a kilépéshez", + "VTLANG_ENTER_REBOOT": "nyomja meg az Enter billentyűt az újraindításhoz", + "VTLANG_ENTER_CONTINUE": "nyomja meg az Enter billentyűt a folytatáshoz", + + "VTLANG_CTRL_TEMP_SET": "Ideiglenes vezérlési beállítások", + "VTLANG_WIN11_BYPASS_CHECK": "CPU/TPM/SecureBoot ellenőrzés megkerülése Windows 11 telepítésekor", + "VTLANG_WIN11_BYPASS_NRO": "Internetes fiók követelményének megkerülése Windows 11 telepítésekor", + "VTLANG_LINUX_REMOUNT": "Hiperiso partíció csatolása a Linux indítása után", + "VTLANG_SECONDARY_BOOT_MENU": "Másodlagos indítási menü megjelenítése", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} \ No newline at end of file diff --git a/src/grub2/grub/menu/id_ID.json b/src/grub2/grub/menu/id_ID.json new file mode 100644 index 0000000..b97c8cb --- /dev/null +++ b/src/grub2/grub/menu/id_ID.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Indonesian (Bahasa Indonesia)", + + "VTLANG_STR_HOTKEY_LIST": "L:Bahasa F1:Bantuan F2:Jelajah F3:ListView F4:boot lokal F5:Alat Utilitas F6:Menu Eksternal", + "VTLANG_STR_HOTKEY_TREE": "L:Bahasa F1:Bantuan F2:Jelajah F3:ListView F4:boot lokal F5:Alat Utilitas F6:Menu Eksternal", + "VTLANG_RETURN_PREVIOUS": "Kembali ke menu sebelumnya [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Kembali ke menu sebelumnya", + + "VTLANG_MENU_LANG": "Menu Pilihan Bahasa", + + "VTLANG_LB_SBOOT_WINDOWS": "Mencari dan jalankan boot ke Windows", + "VTLANG_LB_SBOOT_G4D": "Mencari dan jalankan boot ke Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Jalankan boot ke disk lokal 1", + "VTLANG_LB_SBOOT_HDD2": "Jalankan boot ke disk lokal 2", + "VTLANG_LB_SBOOT_HDD3": "Jalankan boot ke disk lokal 3", + "VTLANG_LB_SBOOT_X64EFI": "Jalankan boot ke disk lokal nomor 1 BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Mencari dan jalankan boot ke BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Mencari dan jalankan boot ke BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Mencari dan jalankan boot ke xorboot", + + "VTLANG_FILE_CHKSUM": "Berkas checksum", + "VTLANG_CHKSUM_MD5_CALC": "Menghitung md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Menghitung sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Menghitung sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Menghitung sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Menghitung dan memeriksa md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Menghitung dan memeriksa sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Menghitung dan memeriksa sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Menghitung dan memeriksa sha512sum", + + "VTLANG_POWER": "Daya", + "VTLANG_POWER_REBOOT": "Memulai ulang", + "VTLANG_POWER_HALT": "Mematikan", + "VTLANG_POWER_BOOT_EFIFW": "Memulai ulang menuju EFI setup", + + "VTLANG_KEYBRD_LAYOUT": "Tata letak Keyboard", + "VTLANG_HWINFO": "Informasi Perangkat Keras", + + "VTLANG_RESOLUTION_CFG": "Setelan Resolusi", + "VTLANG_SCREEN_MODE": "Mode Tampilan Layar", + "VTLANG_SCREEN_TEXT_MODE": "Paksa ke Mode Teks", + "VTLANG_SCREEN_GUI_MODE": "Paksa ke Mode Grafis", + + "VTLANG_THEME_SELECT": "Pilih Tema", + + "VTLANG_UEFI_UTIL": "Utilitas UEFI Hiperiso", + "VTLANG_UTIL_SHOW_EFI_DRV": "Tampilkan Driver EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Memperbaiki Kegagalan Windows BlinitializeLibrary", + + "VTLANG_JSON_CHK_JSON": "Periksa setelan plugin (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Periksa setelan plugin global control", + "VTLANG_JSON_CHK_THEME": "Periksa setelan plugin theme", + "VTLANG_JSON_CHK_AUTOINS": "Periksa setelan plugin auto install", + "VTLANG_JSON_CHK_PERSIST": "Periksa setelan plugin persistence", + "VTLANG_JSON_CHK_MENU_ALIAS": "Periksa setelan plugin menu alias", + "VTLANG_JSON_CHK_MENU_TIP": "Periksa setelan plugin tip", + "VTLANG_JSON_CHK_MENU_CLASS": "Periksa setelan class plugin menu", + "VTLANG_JSON_CHK_INJECTION": "Periksa setelan plugin injection", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Periksa setelan plugin auto memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "Periksa setelan plugin image list", + "VTLANG_JSON_CHK_IMG_BLIST": "Periksa setelant plugin image blacklis", + "VTLANG_JSON_CHK_CONF_REPLACE": "Periksa setelan plugin boot conf replace", + "VTLANG_JSON_CHK_DUD": "Periksa setelan plugin dud", + "VTLANG_JSON_CHK_PASSWORD": "Periksa setelan plugin password", + + "VTLANG_NORMAL_MODE": "Jalankan boot di mode normal", + "VTLANG_WIMBOOT_MODE": "Jalankan boot di mode wimboot", + "VTLANG_GRUB2_MODE": "Jalankan boot di mode grub2", + "VTLANG_MEMDISK_MODE": "Jalankan boot di mode memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Kembali ke ListView", + "VTLANG_RET_TO_TREEVIEW": "Kembali ke TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "Jalankan boot tanpa templat instalasi otomatis", + "VTLANG_AUTOINS_USE": "Jalankan boot dengan", + + "VTLANG_NO_PERSIST": "Jalankan boot tanpa persistence", + "VTLANG_PERSIST_USE": "Jalankan boot", + + "VTLANG_BROWER_RETURN": "Kembali", + + "VTLANG_ENTER_EXIT": "tekan tombol Enter untuk keluar", + "VTLANG_ENTER_REBOOT": "tekan tombol Enter untuk memulai ulang", + "VTLANG_ENTER_CONTINUE": "tekan tombol Enter untuk melanjutkan", + + "VTLANG_CTRL_TEMP_SET": "Pengaturan Kontrol Sementara", + "VTLANG_WIN11_BYPASS_CHECK": "Melewati pemeriksaaan CPU/TPM/SecureBoot ketika memasang Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Melewati persyaratan akun online ketika memasang Windows 11", + "VTLANG_LINUX_REMOUNT": "Memuat partisi Hiperiso setelah boot ke Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Tampilkan menu boot sekunder", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/it_IT.json b/src/grub2/grub/menu/it_IT.json new file mode 100644 index 0000000..a5e8fbd --- /dev/null +++ b/src/grub2/grub/menu/it_IT.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Italiano (Italian)", + + "VTLANG_STR_HOTKEY_LIST": "L:Lingua F1:Aiuto F2:Sfoglia F3:VistaElenco F4:BootLocale F5:Strumenti F6:MenuEx", + "VTLANG_STR_HOTKEY_TREE": "L:Lingua F1:Aiuto F2:Sfoglia F3:VistaStruttura F4:BootLocale F5:Strumenti F6:MenuEx", + "VTLANG_RETURN_PREVIOUS": "Torna al menu precedente [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Torna al menu precedente", + + "VTLANG_MENU_LANG": "Selezione lingua interfaccia", + + "VTLANG_LB_SBOOT_WINDOWS": "Cerca e avvia Windows", + "VTLANG_LB_SBOOT_G4D": "Cerca e avvia Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Avvia il 1° disco locale", + "VTLANG_LB_SBOOT_HDD2": "Avvia il 2° disco locale", + "VTLANG_LB_SBOOT_HDD3": "Avvia il 3° disco locale", + "VTLANG_LB_SBOOT_X64EFI": "Cerca e avvia BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Cerca e avvia BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Cerca e avvia BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Cerca e avvia xorboot", + + "VTLANG_FILE_CHKSUM": "File checksum", + "VTLANG_CHKSUM_MD5_CALC": "Calcola md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Calcola sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Calcola sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Calcola sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calcola e controlla md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calcola e controlla sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calcola e controlla sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calcola e controlla sha512sum", + + "VTLANG_POWER": "Spegni il computer", + "VTLANG_POWER_REBOOT": "Riavvia il computer", + "VTLANG_POWER_HALT": "Arresta il computer", + "VTLANG_POWER_BOOT_EFIFW": "Riavvia il computer nell'impostazione EFI", + + "VTLANG_KEYBRD_LAYOUT": "Layout tastiera", + "VTLANG_HWINFO": "Informazioni hardware computer", + + "VTLANG_RESOLUTION_CFG": "Imposta risoluzione schermo", + "VTLANG_SCREEN_MODE": "Modalità schermo (testo/grafica)", + "VTLANG_SCREEN_TEXT_MODE": "Forza modalità testo schermo", + "VTLANG_SCREEN_GUI_MODE": "Forza modalità grafica schermo", + + "VTLANG_THEME_SELECT": "Seleziona tema interfaccia", + + "VTLANG_UEFI_UTIL": "Utilità UEFI Hiperiso", + "VTLANG_UTIL_SHOW_EFI_DRV": "Visualizza driver EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Correzione fallimento BlinitializeLibrary di Windows", + + "VTLANG_JSON_CHK_JSON": "Modifica file .json plugin (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Modifica controllo globale della configurazione dei plugin", + "VTLANG_JSON_CHK_THEME": "Modifica tema configurazione dei plugin", + "VTLANG_JSON_CHK_AUTOINS": "Modifica installazione automatica della configurazione dei plugin", + "VTLANG_JSON_CHK_PERSIST": "Modifica persistenza della configurazione dei plugin", + "VTLANG_JSON_CHK_MENU_ALIAS": "Modifica l'alias del menu della configurazione dei plugin", + "VTLANG_JSON_CHK_MENU_TIP": "Modifica suggerimento del menu della configurazione dei plugin", + "VTLANG_JSON_CHK_MENU_CLASS": "Modifica classe menu configurazione plugin", + "VTLANG_JSON_CHK_INJECTION": "Modifica injection della configurazione plugin", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Modifica memdisk automatico della configurazione dei plugin", + "VTLANG_JSON_CHK_IMG_LIST": "Modifica elenco immagini configurazione plugin", + "VTLANG_JSON_CHK_IMG_BLIST": "Modifica elenco immagini vietate configurazione plugin", + "VTLANG_JSON_CHK_CONF_REPLACE": "Modifica sostituzione configurazione di avvio configurazione dei plugin", + "VTLANG_JSON_CHK_DUD": "Modifica dud configurazione plugin", + "VTLANG_JSON_CHK_PASSWORD": "Modifica password configurazione plugin", + + "VTLANG_NORMAL_MODE": "Avvia in modalità normale", + "VTLANG_WIMBOOT_MODE": "Avvia in modalità wimboot", + "VTLANG_GRUB2_MODE": "Avvia in modalità grub2", + "VTLANG_MEMDISK_MODE": "Avvia in modalità memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Torna alla VistaElenco", + "VTLANG_RET_TO_TREEVIEW": "Torna alla VistaStruttura", + + "VTLANG_NO_AUTOINS_SCRIPT": "Avvia senza il modello installazione automatica", + "VTLANG_AUTOINS_USE": "Avvia con", + + "VTLANG_NO_PERSIST": "Avvia senza persistenza", + "VTLANG_PERSIST_USE": "Avvia con", + + "VTLANG_BROWER_RETURN": "Indietro", + + "VTLANG_ENTER_EXIT": "Premi il tasto 'Invio' per uscire", + "VTLANG_ENTER_REBOOT": "Premi il tasto 'Invio' per riavviare", + "VTLANG_ENTER_CONTINUE": "Premi il tasto 'Invio' per continuare", + + "VTLANG_CTRL_TEMP_SET": "Impostazioni controllo temporaneo", + "VTLANG_WIN11_BYPASS_CHECK": "Durante l'installazione di Windows 11 bypassa il controllo CPU/TPM/SecureBoot ", + "VTLANG_WIN11_BYPASS_NRO": "Durante l'installazione di Windows 11 bypassa il requisito di un account online ", + "VTLANG_LINUX_REMOUNT": "Dopo l'avvio di Linux monta la partizione Hiperiso ", + "VTLANG_SECONDARY_BOOT_MENU": "Visualizza menu di avvio secondario", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/ja_JP.json b/src/grub2/grub/menu/ja_JP.json new file mode 100644 index 0000000..f824484 --- /dev/null +++ b/src/grub2/grub/menu/ja_JP.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Japanese (日本語)", + + "VTLANG_STR_HOTKEY_LIST": "L:言語 F1:説明 F2:閲覧 F3:表示切替(階層) F4:手許から起動 F5:道具 F6:拡張", + "VTLANG_STR_HOTKEY_TREE": "L:言語 F1:説明 F2:閲覧 F3:表示切替(一覧) F4:手許から起動 F5:道具 F6:拡張", + "VTLANG_RETURN_PREVIOUS": "前に戻る [Esc]", + "VTLANG_RETURN_PRV_NOESC": "前に戻る", + + "VTLANG_MENU_LANG": "表示言語", + + "VTLANG_LB_SBOOT_WINDOWS": "Windowsを検索して起動する", + "VTLANG_LB_SBOOT_G4D": "GRUB4DOSを検索して起動する", + "VTLANG_LB_SBOOT_HDD1": "最初の機器を起動します", + "VTLANG_LB_SBOOT_HDD2": "2番目の機器を起動する", + "VTLANG_LB_SBOOT_HDD3": "3番目の機器を起動する", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFIを検索して起動する", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFIを検索して起動する", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFIを検索して起動する", + "VTLANG_LB_SBOOT_XORBOOT": "xorbootを検索して起動する", + + "VTLANG_FILE_CHKSUM": "検査合計", + "VTLANG_CHKSUM_MD5_CALC": "MD5を算出する", + "VTLANG_CHKSUM_SHA1_CALC": "SHA1を算出する", + "VTLANG_CHKSUM_SHA256_CALC": "SHA256を算出する", + "VTLANG_CHKSUM_SHA512_CALC": "SHA512を算出する", + "VTLANG_CHKSUM_MD5_CALC_CHK": "MD5を算出して検証する", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "SHA1を算出して検証する", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "SHA256を算出して検証する", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "SHA512を算出して検証する", + + "VTLANG_POWER": "電源", + "VTLANG_POWER_REBOOT": "再起動", + "VTLANG_POWER_HALT": "電源断", + "VTLANG_POWER_BOOT_EFIFW": "再起動してEFIを構成する", + + "VTLANG_KEYBRD_LAYOUT": "鍵盤配列", + "VTLANG_HWINFO": "機器情報", + + "VTLANG_RESOLUTION_CFG": "画面解像度", + "VTLANG_SCREEN_MODE": "表示の種類", + "VTLANG_SCREEN_TEXT_MODE": "CLI表示を強制する", + "VTLANG_SCREEN_GUI_MODE": "GUI表示を強制する", + + "VTLANG_THEME_SELECT": "外観", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFIドライバを表示する", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windowsが「BlinitializeLibrary Failure」で起動しないのを修正する", + + "VTLANG_JSON_CHK_JSON": "拡張機能のJSON構成ファイル (hiperiso.json) を検査する", + "VTLANG_JSON_CHK_CONTROL": "拡張機能「global control」の構成を検査する", + "VTLANG_JSON_CHK_THEME": "拡張機能「theme」の構成を検査する", + "VTLANG_JSON_CHK_AUTOINS": "拡張機能「auto install」の構成を検査する", + "VTLANG_JSON_CHK_PERSIST": "拡張機能「persistence」の構成を検査する", + "VTLANG_JSON_CHK_MENU_ALIAS": "拡張機能「menu alias」の構成を検査する", + "VTLANG_JSON_CHK_MENU_TIP": "拡張機能「menu tip」の構成を検査する", + "VTLANG_JSON_CHK_MENU_CLASS": "拡張機能「menu class」の構成を検査する", + "VTLANG_JSON_CHK_INJECTION": "拡張機能「injection」の構成を検査する", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "拡張機能「auto memdisk」の構成を検査する", + "VTLANG_JSON_CHK_IMG_LIST": "拡張機能「image list」の構成を検査する", + "VTLANG_JSON_CHK_IMG_BLIST": "拡張機能「image blacklist」の構成を検査する", + "VTLANG_JSON_CHK_CONF_REPLACE": "拡張機能「boot conf replace」の構成を検査する", + "VTLANG_JSON_CHK_DUD": "拡張機能「dud」の構成を検査する", + "VTLANG_JSON_CHK_PASSWORD": "拡張機能「password」の構成を検査する", + + "VTLANG_NORMAL_MODE": "通常どおり起動", + "VTLANG_WIMBOOT_MODE": "WimBootを介して起動", + "VTLANG_GRUB2_MODE": "GRUB2を介して起動", + "VTLANG_MEMDISK_MODE": "MEMDISKを介して起動", + + "VTLANG_RET_TO_LISTVIEW": "一覧表示に切り替える", + "VTLANG_RET_TO_TREEVIEW": "階層表示に切り替える", + + "VTLANG_NO_AUTOINS_SCRIPT": "起動後に自動でインストールを行わない", + "VTLANG_AUTOINS_USE": "自動インストールを行う", + + "VTLANG_NO_PERSIST": "Live環境の永続保管領域を無効にする", + "VTLANG_PERSIST_USE": "有効にする", + + "VTLANG_BROWER_RETURN": "戻る", + + "VTLANG_ENTER_EXIT": "[Enter]を押して終了します", + "VTLANG_ENTER_REBOOT": "[Enter]を押して再起動します", + "VTLANG_ENTER_CONTINUE": "[Enter]を押して続行します", + + "VTLANG_CTRL_TEMP_SET": "Temporary Control Settings", + "VTLANG_WIN11_BYPASS_CHECK": "Bypass CPU/TPM/SecureBoot check when install Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Bypass online account requirement when install Windows 11", + "VTLANG_LINUX_REMOUNT": "Mount Hiperiso partition after boot Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Show secondary boot menu", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/ka_GE.json b/src/grub2/grub/menu/ka_GE.json new file mode 100644 index 0000000..d8eac52 --- /dev/null +++ b/src/grub2/grub/menu/ka_GE.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Georgian (ქართული)", + + "VTLANG_STR_HOTKEY_LIST": "L:ენა F1:დახმარება F2:დათვალიერება F3:სიის ხედი F4:ლოკალური ჩატვირთვა F5:ხელსაწყოები F6:გასვლა", + "VTLANG_STR_HOTKEY_TREE": "L:ენა F1:დახმარება F2:დათვალიერება F3:ხის ხედი F4:ლოკალური ჩატვირთვა F5:ხელსაწყოები F6:გასვლა", + "VTLANG_RETURN_PREVIOUS": "წინა მენიუში დაბრუნება [Esc]", + "VTLANG_RETURN_PRV_NOESC": "წინა მენიუში დაბრუნება", + + "VTLANG_MENU_LANG": "მენიუს ენის არჩევა", + + "VTLANG_LB_SBOOT_WINDOWS": "Windows-ის მოძებნა და ჩატვირთვა", + "VTLANG_LB_SBOOT_G4D": "Grub4dos-ის მოძებნა და ჩატვირთვა", + "VTLANG_LB_SBOOT_HDD1": "1-ლი ლოკალური მყარი დისკიდან ჩატვირთვა", + "VTLANG_LB_SBOOT_HDD2": "მე-2 ლოკალური მყარი დისკიდან ჩატვირთვა", + "VTLANG_LB_SBOOT_HDD3": "მე-3 ლოკალური მყარი დისკიდან ჩატვირთვა", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI-ის მოძებნა და ჩატვირთვა", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI-ის მოძებნა და ჩატვირთვა", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI-ის მოძებნა და ჩატვირთვა", + "VTLANG_LB_SBOOT_XORBOOT": "xorboot-ის მოძებნა და ჩატვირთვა", + + "VTLANG_FILE_CHKSUM": "ფაილის საკონტროლო ჯამი", + "VTLANG_CHKSUM_MD5_CALC": "md5sum გამოთვლა", + "VTLANG_CHKSUM_SHA1_CALC": "sha1sum გამოთვლა", + "VTLANG_CHKSUM_SHA256_CALC": "sha256sum გამოთვლა", + "VTLANG_CHKSUM_SHA512_CALC": "sha512sum გამოთვლა", + "VTLANG_CHKSUM_MD5_CALC_CHK": "md5sum გამოთვლა და შემოწმება", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "sha1sum გამოთვლა და შემოწმება", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "sha256sum გამოთვლა და შემოწმება", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "sha512sum გამოთვლა და შემოწმება", + + "VTLANG_POWER": "კომპიუტერის გამორთვა", + "VTLANG_POWER_REBOOT": "კომპიუტერის გადატვირთვა", + "VTLANG_POWER_HALT": "კომპიუტერის გაჩერება", + "VTLANG_POWER_BOOT_EFIFW": "გადატვირთვა EFI კონფიგურაციის რეჟიმში", + + "VTLANG_KEYBRD_LAYOUT": "კლავიატურის განლაგებები", + "VTLANG_HWINFO": "ინფორმაცია მოწყობილობების შესახებ", + + "VTLANG_RESOLUTION_CFG": "გარჩევადობის კონფიგურაცია", + "VTLANG_SCREEN_MODE": "ჩვენების რეჟიმი", + "VTLANG_SCREEN_TEXT_MODE": "ჩვენების ტექსტური რეჟიმი", + "VTLANG_SCREEN_GUI_MODE": "ჩვენების გრაფიკული რეჟიმი", + + "VTLANG_THEME_SELECT": "თემის არჩევა", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFI დრაივერების ჩვენება", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windows BlinitializeLibrary ხარვეზის გასწორება", + + "VTLANG_JSON_CHK_JSON": "მოდულების json კონფიგურაციის შემოწმება (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "global control მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_THEME": "theme მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_AUTOINS": "auto install მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_PERSIST": "persistence მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_MENU_ALIAS": "menu alias მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_MENU_TIP": "menu tip მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_MENU_CLASS": "menu class მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_INJECTION": "injection მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "auto memdisk მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_IMG_LIST": "image list მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_IMG_BLIST": "image blacklist მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_CONF_REPLACE": "boot conf replace მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_DUD": "dud მოდულის კონფიგურაციის შემოწმება", + "VTLANG_JSON_CHK_PASSWORD": "password მოდულის კონფიგურაციის შემოწმება", + + "VTLANG_NORMAL_MODE": "ჩატვირთვა normal რეჟიმში", + "VTLANG_WIMBOOT_MODE": "ჩატვირთვა wimboot რეჟიმში", + "VTLANG_GRUB2_MODE": "ჩატვირთვა grub2 რეჟიმში", + "VTLANG_MEMDISK_MODE": "ჩატვირთვა memdisk რეჟიმში", + + "VTLANG_RET_TO_LISTVIEW": "სიის ხედის დაბრუნება", + "VTLANG_RET_TO_TREEVIEW": "ხის ხედის დაბრუნება", + + "VTLANG_NO_AUTOINS_SCRIPT": "ჩატვირთვა ავტომატური ინსტალაციის სკრიპტის გარეშე", + "VTLANG_AUTOINS_USE": "ჩატვირთვა ავტომატური ინსტალაციის რეჟიმში", + + "VTLANG_NO_PERSIST": "ჩატვირთვა ცვლილებების შენახვის რეჟიმის გარეშე", + "VTLANG_PERSIST_USE": "ჩატვირთვა ცვლილებების შენახვის რეჟიმში", + + "VTLANG_BROWER_RETURN": "დაბრუნება", + + "VTLANG_ENTER_EXIT": "გასასვლელად დააჭირეთ Enter ღილაკს", + "VTLANG_ENTER_REBOOT": "დააჭირეთ Enter ღილაკს გადატვირთვისთვის", + "VTLANG_ENTER_CONTINUE": "გასაგრძელებლად დააჭირეთ Enter ღილაკს", + + "VTLANG_CTRL_TEMP_SET": "Temporary Control Settings", + "VTLANG_WIN11_BYPASS_CHECK": "Bypass CPU/TPM/SecureBoot check when install Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Bypass online account requirement when install Windows 11", + "VTLANG_LINUX_REMOUNT": "Mount Hiperiso partition after boot Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Show secondary boot menu", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/ko_KR.json b/src/grub2/grub/menu/ko_KR.json new file mode 100644 index 0000000..e2620ef --- /dev/null +++ b/src/grub2/grub/menu/ko_KR.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Korean (한국어)", + + "VTLANG_STR_HOTKEY_LIST": " L:언어 F1:도움말 F2:찾아보기 F3:목록 보기 F4:로컬 부팅 F5:도구 F6:확장 메뉴", + "VTLANG_STR_HOTKEY_TREE": " L:언어 F1:도움말 F2:찾아보기 F3:트리 보기 F4:로컬 부팅 F5:도구 F6:확장 메뉴", + "VTLANG_RETURN_PREVIOUS": "이전 메뉴로 돌아가기 [Esc]", + "VTLANG_RETURN_PRV_NOESC": "이전 메뉴로 돌아가기", + + "VTLANG_MENU_LANG": "메뉴 언어 선택", + + "VTLANG_LB_SBOOT_WINDOWS": "Windows 검색 및 부팅", + "VTLANG_LB_SBOOT_G4D": "Grub4dos 검색 및 부팅", + "VTLANG_LB_SBOOT_HDD1": "첫 번째 로컬 디스크 부팅", + "VTLANG_LB_SBOOT_HDD2": "두 번째 로컬 디스크 부팅", + "VTLANG_LB_SBOOT_HDD3": "세 번째 로컬 디스크 부팅", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI 검색 및 부팅", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI 검색 및 부팅", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI 검색 및 부팅", + "VTLANG_LB_SBOOT_XORBOOT": "xorboot 검색 및 부팅", + + "VTLANG_FILE_CHKSUM": "파일 체크섬", + "VTLANG_CHKSUM_MD5_CALC": "md5 검사값 계산", + "VTLANG_CHKSUM_SHA1_CALC": "sha1 검사값 계산", + "VTLANG_CHKSUM_SHA256_CALC": "sha256 검사값 계산", + "VTLANG_CHKSUM_SHA512_CALC": "sha512 검사값 계산", + "VTLANG_CHKSUM_MD5_CALC_CHK": "md5 검사값 계산 및 확인", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "sha1 검사값 계산 및 확인", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "sha256 검사값 계산 및 확인", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "sha512 검사값 계산 및 확인", + + "VTLANG_POWER": "전원", + "VTLANG_POWER_REBOOT": "다시 시작", + "VTLANG_POWER_HALT": "전원 끄기", + "VTLANG_POWER_BOOT_EFIFW": "UEFI 설정으로 다시 시작", + + "VTLANG_KEYBRD_LAYOUT": "키보드 레이아웃", + "VTLANG_HWINFO": "하드웨어 정보", + + "VTLANG_RESOLUTION_CFG": "해상도 구성", + "VTLANG_SCREEN_MODE": "화면 표시 모드", + "VTLANG_SCREEN_TEXT_MODE": "강제 텍스트 모드", + "VTLANG_SCREEN_GUI_MODE": "강제 그래픽 모드", + + "VTLANG_THEME_SELECT": "테마 선택", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI 유틸리티", + "VTLANG_UTIL_SHOW_EFI_DRV": "UEFI 드라이버 표시", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windows 초기화 라이브러리 오류 복구", + + "VTLANG_JSON_CHK_JSON": "플러그인 파일 구성 확인 (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "전역 제어 플러그인 구성 확인", + "VTLANG_JSON_CHK_THEME": "테마 플러그인 구성 확인", + "VTLANG_JSON_CHK_AUTOINS": "자동 설치 플러그인 구성 확인", + "VTLANG_JSON_CHK_PERSIST": "영구화 플러그인 구성 확인", + "VTLANG_JSON_CHK_MENU_ALIAS": "메뉴 별칭 플러그인 구성 확인", + "VTLANG_JSON_CHK_MENU_TIP": "메뉴 팁 플러그인 구성 확인", + "VTLANG_JSON_CHK_MENU_CLASS": "메뉴 클래스 플러그인 구성 확인", + "VTLANG_JSON_CHK_INJECTION": "주입 플러그인 구성 확인", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "자동 메모리 디스크 플러그인 구성 확인", + "VTLANG_JSON_CHK_IMG_LIST": "이미지 목록 플러그인 구성 확인", + "VTLANG_JSON_CHK_IMG_BLIST": "이미지 블랙리스트 플러그인 구성 확인", + "VTLANG_JSON_CHK_CONF_REPLACE": "부팅 구성 대체 플러그인 구성 확인", + "VTLANG_JSON_CHK_DUD": "드라이버 업데이트 디스크 플러그인 구성 확인", + "VTLANG_JSON_CHK_PASSWORD": "암호 플러그인 구성 확인", + + "VTLANG_NORMAL_MODE": "일반 모드로 부팅", + "VTLANG_WIMBOOT_MODE": "wimboot 모드로 부팅", + "VTLANG_GRUB2_MODE": "grub2 모드로 부팅", + "VTLANG_MEMDISK_MODE": "메모리 디스크 모드로 부팅", + + "VTLANG_RET_TO_LISTVIEW": "목록보기로 돌아가기", + "VTLANG_RET_TO_TREEVIEW": "트리보기로 돌아가기", + + "VTLANG_NO_AUTOINS_SCRIPT": "자동 설치 스크립트 사용 안 함", + "VTLANG_AUTOINS_USE": "부팅 대상", + + "VTLANG_NO_PERSIST": "영구화된 데이터 파일 사용 안 함", + "VTLANG_PERSIST_USE": "부팅 대상", + + "VTLANG_BROWER_RETURN": "돌아가기", + + "VTLANG_ENTER_EXIT": "종료하려면 Enter 키를 누르십시오", + "VTLANG_ENTER_REBOOT": "다시 시작하려면 Enter 키를 누르십시오", + "VTLANG_ENTER_CONTINUE": "계속하려면 Enter 키를 누르십시오", + + "VTLANG_CTRL_TEMP_SET": "임시 제어 설정", + "VTLANG_WIN11_BYPASS_CHECK": "Windows 11 설치 시 CPU/TPM/SecureBoot 검사 회피", + "VTLANG_WIN11_BYPASS_NRO": "Windows 11 설치 시 온라인 계정 요구 사항 무시", + "VTLANG_LINUX_REMOUNT": "Linux 부팅 후 Hiperiso 파티션 마운트", + "VTLANG_SECONDARY_BOOT_MENU": "보조 부팅 메뉴 표시", + "VTLANG_WIN_UEFI_RES_LOCK": "UEFI 부팅 시 Windows/WinPE 해상도 고정", + "VTLANG_UEFI_RES_LOCK_NONE": "고정 안 함", + "VTLANG_UEFI_RES_LOCK_MAX": "최고 해상도로 고정", + "VTLANG_UEFI_RES_LOCK_1024_768": "1024 x 768로 고정", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "1024 x 768 이상으로 고정", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/lg_UG.json b/src/grub2/grub/menu/lg_UG.json new file mode 100644 index 0000000..7721712 --- /dev/null +++ b/src/grub2/grub/menu/lg_UG.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "English (English)", + + "VTLANG_STR_HOTKEY_LIST": "L:Language F1:Help F2:Browse F3:ListView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:Language F1:Help F2:Browse F3:TreeView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "Return to previous menu [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Return to previous menu", + + "VTLANG_MENU_LANG": "Menu Language Select", + + "VTLANG_LB_SBOOT_WINDOWS": "Search and boot Windows", + "VTLANG_LB_SBOOT_G4D": "Search and boot Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Boot the 1st local disk", + "VTLANG_LB_SBOOT_HDD2": "Boot the 2nd local disk", + "VTLANG_LB_SBOOT_HDD3": "Boot the 3rd local disk", + "VTLANG_LB_SBOOT_X64EFI": "Search and boot BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Search and boot BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Search and boot BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Search and boot xorboot", + + "VTLANG_FILE_CHKSUM": "File checksum", + "VTLANG_CHKSUM_MD5_CALC": "Calculate md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Calculate sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Calculate sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Calculate sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calculate and check md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calculate and check sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calculate and check sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calculate and check sha512sum", + + "VTLANG_POWER": "Power", + "VTLANG_POWER_REBOOT": "Reboot", + "VTLANG_POWER_HALT": "Halt", + "VTLANG_POWER_BOOT_EFIFW": "Reboot to EFI setup", + + "VTLANG_KEYBRD_LAYOUT": "Keyboard Layouts", + "VTLANG_HWINFO": "Hardware Information", + + "VTLANG_RESOLUTION_CFG": "Resolution Configuration", + "VTLANG_SCREEN_MODE": "Screen Display Mode", + "VTLANG_SCREEN_TEXT_MODE": "Force Text Mode", + "VTLANG_SCREEN_GUI_MODE": "Force Graphics Mode", + + "VTLANG_THEME_SELECT": "Theme Select", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "Show EFI Drivers", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Fixup Windows BlinitializeLibrary Failure", + + "VTLANG_JSON_CHK_JSON": "Check plugin json configuration (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Check global control plugin configuration", + "VTLANG_JSON_CHK_THEME": "Check theme plugin configuration", + "VTLANG_JSON_CHK_AUTOINS": "Check auto install plugin configuration", + "VTLANG_JSON_CHK_PERSIST": "Check persistence plugin configuration", + "VTLANG_JSON_CHK_MENU_ALIAS": "Check menu alias plugin configuration", + "VTLANG_JSON_CHK_MENU_TIP": "Check menu tip plugin configuration", + "VTLANG_JSON_CHK_MENU_CLASS": "Check menu class plugin configuration", + "VTLANG_JSON_CHK_INJECTION": "Check injection plugin configuration", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Check auto memdisk plugin configuration", + "VTLANG_JSON_CHK_IMG_LIST": "Check image list plugin configuration", + "VTLANG_JSON_CHK_IMG_BLIST": "Check image blacklist plugin configuration", + "VTLANG_JSON_CHK_CONF_REPLACE": "Check boot conf replace plugin configuration", + "VTLANG_JSON_CHK_DUD": "Check dud plugin configuration", + "VTLANG_JSON_CHK_PASSWORD": "Check password plugin configuration", + + "VTLANG_NORMAL_MODE": "Boot in normal mode", + "VTLANG_WIMBOOT_MODE": "Boot in wimboot mode", + "VTLANG_GRUB2_MODE": "Boot in grub2 mode", + "VTLANG_MEMDISK_MODE": "Boot in memdisk mode", + + "VTLANG_RET_TO_LISTVIEW": "Return to ListView", + "VTLANG_RET_TO_TREEVIEW": "Return to TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "Boot without auto installation template", + "VTLANG_AUTOINS_USE": "Boot with", + + "VTLANG_NO_PERSIST": "Boot without persistence", + "VTLANG_PERSIST_USE": "Boot with", + + "VTLANG_BROWER_RETURN": "Return", + + "VTLANG_ENTER_EXIT": "press Enter key to exit", + "VTLANG_ENTER_REBOOT": "press Enter key to reboot", + "VTLANG_ENTER_CONTINUE": "press Enter key to continue", + + "VTLANG_CTRL_TEMP_SET": "Temporary Control Settings", + "VTLANG_WIN11_BYPASS_CHECK": "Bypass CPU/TPM/SecureBoot check when install Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Bypass online account requirement when install Windows 11", + "VTLANG_LINUX_REMOUNT": "Mount Hiperiso partition after boot Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Show secondary boot menu", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/pl_PL.json b/src/grub2/grub/menu/pl_PL.json new file mode 100644 index 0000000..caf692e --- /dev/null +++ b/src/grub2/grub/menu/pl_PL.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Polish (Poland)", + + "VTLANG_STR_HOTKEY_LIST": "L:Język F1:Pomoc F2:Przeglądaj F3:Widok listy F4:Localboot F5:Narzędzia F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:Język F1:Pomoc F2:Przeglądaj F3:Widok drzewa F4:Localboot F5:Narzędzia F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "Powrót do poprzedniego menu [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Powrót do poprzedniego menu", + + "VTLANG_MENU_LANG": "Wybierz język menu", + + "VTLANG_LB_SBOOT_WINDOWS": "Wyszukaj i uruchom Windows", + "VTLANG_LB_SBOOT_G4D": "Wyszukaj i uruchom Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Uruchom pierwszy dysk lokalny", + "VTLANG_LB_SBOOT_HDD2": "Uruchom drugi dysk lokalny", + "VTLANG_LB_SBOOT_HDD3": "Uruchom trzeci dysk lokalny", + "VTLANG_LB_SBOOT_X64EFI": "Wyszukaj i uruchom BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Wyszukaj i uruchom BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Wyszukaj i uruchom BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Wyszukaj i uruchom xorboot", + + "VTLANG_FILE_CHKSUM": "Suma kontrolna pliku", + "VTLANG_CHKSUM_MD5_CALC": "Oblicz sumę md5", + "VTLANG_CHKSUM_SHA1_CALC": "Oblicz sumę sha1", + "VTLANG_CHKSUM_SHA256_CALC": "Oblicz sumę sha256", + "VTLANG_CHKSUM_SHA512_CALC": "Oblicz sumę sha512", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Oblicz i sprawdź sumę md5", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Oblicz i sprawdź sumę sha1", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Oblicz i sprawdź sumę sha256", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Oblicz i sprawdź sumę sha512", + + "VTLANG_POWER": "Opcje zasilania", + "VTLANG_POWER_REBOOT": "Uruchom ponownie", + "VTLANG_POWER_HALT": "Zakończ", + "VTLANG_POWER_BOOT_EFIFW": "Uruchom ponownie i przejdź do konfiguracji EFI", + + "VTLANG_KEYBRD_LAYOUT": "Układy klawiatury", + "VTLANG_HWINFO": "Informacje o konfiguracji sprzętowej", + + "VTLANG_RESOLUTION_CFG": "Konfiguracja rozdzielczości", + "VTLANG_SCREEN_MODE": "Tryb wyświetlania ekranu", + "VTLANG_SCREEN_TEXT_MODE": "Wymuś tryb tekstowy", + "VTLANG_SCREEN_GUI_MODE": "Wymuś tryb graficzny", + + "VTLANG_THEME_SELECT": "Wybierz motyw", + + "VTLANG_UEFI_UTIL": "Narzędzia Hiperiso UEFI", + "VTLANG_UTIL_SHOW_EFI_DRV": "Pokaż sterowniki EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Napraw błąd BlinitializeLibrary systemu Windows", + + "VTLANG_JSON_CHK_JSON": "Sprawdź konfigurację pluginu json (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Sprawdź konfigurację pluginu Global Control", + "VTLANG_JSON_CHK_THEME": "Sprawdź konfigurację pluginu Theme", + "VTLANG_JSON_CHK_AUTOINS": "Sprawdź konfigurację pluginu Auto Installation", + "VTLANG_JSON_CHK_PERSIST": "Sprawdź konfigurację pluginu Persistence", + "VTLANG_JSON_CHK_MENU_ALIAS": "Sprawdź konfigurację pluginu Menu Alias", + "VTLANG_JSON_CHK_MENU_TIP": "Sprawdź konfigurację pluginu Menu Tip", + "VTLANG_JSON_CHK_MENU_CLASS": "Sprawdź konfigurację pluginu Menu Class", + "VTLANG_JSON_CHK_INJECTION": "Sprawdź konfigurację pluginu Injection", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Sprawdź konfigurację pluginu Auto Memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "Sprawdź konfigurację pluginu Image List", + "VTLANG_JSON_CHK_IMG_BLIST": "Sprawdź konfigurację pluginu Blacklist dla obrazów", + "VTLANG_JSON_CHK_CONF_REPLACE": "Sprawdź konfigurację pluginu Boot Conf Replace", + "VTLANG_JSON_CHK_DUD": "Sprawdź konfigurację pluginu DUD (Driver Update Disk)", + "VTLANG_JSON_CHK_PASSWORD": "Sprawdź konfigurację pluginu Password", + + "VTLANG_NORMAL_MODE": "Uruchom w trybie normalnym", + "VTLANG_WIMBOOT_MODE": "Uruchom w trybie Wimboot", + "VTLANG_GRUB2_MODE": "Uruchom w trybie grub2", + "VTLANG_MEMDISK_MODE": "Uruchom w trybie memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Powrót do widoku listy", + "VTLANG_RET_TO_TREEVIEW": "Powrót do widoku drzewa", + + "VTLANG_NO_AUTOINS_SCRIPT": "Uruchom bez szablonu automatycznej instalacji", + "VTLANG_AUTOINS_USE": "Uruchom z", + + "VTLANG_NO_PERSIST": "Uruchom bez persistence (zapisywania ustawień)", + "VTLANG_PERSIST_USE": "Uruchom z", + + "VTLANG_BROWER_RETURN": "Powrót", + + "VTLANG_ENTER_EXIT": "naciśnij klawisz Enter, aby wyjść", + "VTLANG_ENTER_REBOOT": "naciśnij klawisz Enter, aby ponownie uruchomić", + "VTLANG_ENTER_CONTINUE": "naciśnij klawisz Enter, aby kontynuować", + + "VTLANG_CTRL_TEMP_SET": "Tymczasowe ustawienia kontroli", + "VTLANG_WIN11_BYPASS_CHECK": "Pominięcie sprawdzania CPU/TPM/SecureBoot podczas instalacji Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Pominięcie wymogu posiadania konta Microsoft podczas instalacji Windows 11", + "VTLANG_LINUX_REMOUNT": "Zamontuj partycję Hiperiso po uruchomieniu Linuksa", + "VTLANG_SECONDARY_BOOT_MENU": "Pokaż dodatkowe menu rozruchowe (boot menu)", + "VTLANG_WIN_UEFI_RES_LOCK": "Zablokuj rozdzielczość podczas bootowania UEFI Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "Brak", + "VTLANG_UEFI_RES_LOCK_MAX": "Najwyższa", + "VTLANG_UEFI_RES_LOCK_1024_768": "Stała 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "Co najmniej 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/pt_BR.json b/src/grub2/grub/menu/pt_BR.json new file mode 100644 index 0000000..db9c107 --- /dev/null +++ b/src/grub2/grub/menu/pt_BR.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Brazilian Portuguese (Português Brasileiro)", + + "VTLANG_STR_HOTKEY_LIST": "L:Idioma F1:Ajuda F2:Explorar F3:Visualização em Lista F4:Inicialização Local F5:Ferramentas F6:Sair", + "VTLANG_STR_HOTKEY_TREE": "L:Idioma F1:Ajuda F2:Explorar F3:Visualização em Árvore F4:Inicialização Local F5:Ferramentas F6:Sair", + "VTLANG_RETURN_PREVIOUS": "Retornar ao menu anterior [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Retornar ao menu anterior", + + "VTLANG_MENU_LANG": "Menu de Seleção dos Idiomas", + + "VTLANG_LB_SBOOT_WINDOWS": "Procurar e iniciar o Windows", + "VTLANG_LB_SBOOT_G4D": "Procurar e iniciar o Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Iniciar o 1º disco local", + "VTLANG_LB_SBOOT_HDD2": "Iniciar o 2º disco local", + "VTLANG_LB_SBOOT_HDD3": "Iniciar o 3º disco local", + "VTLANG_LB_SBOOT_X64EFI": "Procurar e iniciar o BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Procurar e iniciar o BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Procurar e iniciar o BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Procurar e iniciar o xorboot", + + "VTLANG_FILE_CHKSUM": "Checksum do arquivo", + "VTLANG_CHKSUM_MD5_CALC": "Calcular o md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Calcular o sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Calcular o sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Calcular o sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calcular e verificar o md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calcular e verificar o sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calcular e verificar o sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calcular e verificar o sha512sum", + + "VTLANG_POWER": "Energia", + "VTLANG_POWER_REBOOT": "Reiniciar", + "VTLANG_POWER_HALT": "Desligar", + "VTLANG_POWER_BOOT_EFIFW": "Reiniciar com a configuração do EFI", + + "VTLANG_KEYBRD_LAYOUT": "Esquemas do Teclado", + "VTLANG_HWINFO": "Informações do Hardware", + + "VTLANG_RESOLUTION_CFG": "Configuração da Resolução", + "VTLANG_SCREEN_MODE": "Modo de Exibição da Tela", + "VTLANG_SCREEN_TEXT_MODE": "Forçar o Modo Texto", + "VTLANG_SCREEN_GUI_MODE": "Forçar o Modo Gráfico", + + "VTLANG_THEME_SELECT": "Seleção de Tema", + + "VTLANG_UEFI_UTIL": "Utilitários UEFI do Hiperiso", + "VTLANG_UTIL_SHOW_EFI_DRV": "Mostrar os Drivers EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Consertar a Falha BlinitializeLibrary do Windows", + + "VTLANG_JSON_CHK_JSON": "Verificar a configuração do plugin json (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Verificar a configuração do plugin de controle global", + "VTLANG_JSON_CHK_THEME": "Verificar a configuração do plugin dos temas", + "VTLANG_JSON_CHK_AUTOINS": "Verificar a configuração do plugin de instalação automática", + "VTLANG_JSON_CHK_PERSIST": "Verificar a configuração do plugin de persistência", + "VTLANG_JSON_CHK_MENU_ALIAS": "Verificar a configuração do plugin do menu alias", + "VTLANG_JSON_CHK_MENU_TIP": "Verificar a configuração do plugin do menu das dicas", + "VTLANG_JSON_CHK_MENU_CLASS": "Verificar a configuração do plugin do menu classe", + "VTLANG_JSON_CHK_INJECTION": "Verificar a configuração do plugin de injeção", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Verificar a configuração do plugin automático do memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "Verificar a configuração do plugin da lista de imagens", + "VTLANG_JSON_CHK_IMG_BLIST": "Verificar a configuração do plugin da lista negra de imagens", + "VTLANG_JSON_CHK_CONF_REPLACE": "Verificar a configuração do plugin de substituição da configuração de inicialização", + "VTLANG_JSON_CHK_DUD": "Verificar a configuração do plugin dud", + "VTLANG_JSON_CHK_PASSWORD": "Verificar a configuração do plugin das senhas", + + "VTLANG_NORMAL_MODE": "Iniciar no modo normal", + "VTLANG_WIMBOOT_MODE": "Iniciar no modo wimboot", + "VTLANG_GRUB2_MODE": "Iniciar no modo grub2", + "VTLANG_MEMDISK_MODE": "Iniciar no modo memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Retornar pra Visualização em Lista", + "VTLANG_RET_TO_TREEVIEW": "Retornar para Visualização em Árvore", + + "VTLANG_NO_AUTOINS_SCRIPT": "Iniciar sem modelo de instalação automática", + "VTLANG_AUTOINS_USE": "Iniciar com", + + "VTLANG_NO_PERSIST": "Iniciar sem persistência", + "VTLANG_PERSIST_USE": "Iniciar com", + + "VTLANG_BROWER_RETURN": "Retornar", + + "VTLANG_ENTER_EXIT": "Pressione a tecla Enter pra sair", + "VTLANG_ENTER_REBOOT": "Pressione a tecla Enter pra reiniciar", + "VTLANG_ENTER_CONTINUE": "Pressione a tecla Enter pra continuar", + + "VTLANG_CTRL_TEMP_SET": "Configurações do Controle Temporário", + "VTLANG_WIN11_BYPASS_CHECK": "Ignorar a verificação da CPU/TPM/SecureBoot quando instalar o Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Ignorar o requerimento de conta online quanto instalar o Windows 11", + "VTLANG_LINUX_REMOUNT": "Montar a partição do Hiperiso após iniciar o Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Mostrar o menu secundário da inicialização", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/pt_PT.json b/src/grub2/grub/menu/pt_PT.json new file mode 100644 index 0000000..5d26a71 --- /dev/null +++ b/src/grub2/grub/menu/pt_PT.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Portuguese (Português de Portugal)", + + "VTLANG_STR_HOTKEY_LIST": "L:Idioma F1:Ajuda F2:Navegar F3:Estrutura F4:Arranque local F5:Ferramentas F6:Sair", + "VTLANG_STR_HOTKEY_TREE": "L:Idioma F1:Ajuda F2:Navegar F3:Estrutura F4:Arranque local F5:Ferramentas F6:Sair", + "VTLANG_RETURN_PREVIOUS": "Voltar ao menu anterior [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Voltar ao menu anterior", + + "VTLANG_MENU_LANG": "Seleção de idioma do menu", + + "VTLANG_LB_SBOOT_WINDOWS": "Pesquisar e iniciar o Windows", + "VTLANG_LB_SBOOT_G4D": "Pesquisar e iniciar o Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Arrancar o 1º disco local", + "VTLANG_LB_SBOOT_HDD2": "Arrancar o 2º disco local", + "VTLANG_LB_SBOOT_HDD3": "Arrancar o 3º disco local", + "VTLANG_LB_SBOOT_X64EFI": "Pesquisar e iniciar o BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Pesquisar e iniciar o BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Pesquisar e iniciar o BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Pesquisar e iniciar o xorboot", + + "VTLANG_FILE_CHKSUM": "Checksum do ficheiro", + "VTLANG_CHKSUM_MD5_CALC": "Calcular MD5", + "VTLANG_CHKSUM_SHA1_CALC": "Calcular SHA1", + "VTLANG_CHKSUM_SHA256_CALC": "Calcular SHA256", + "VTLANG_CHKSUM_SHA512_CALC": "Calcular SHA512", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calcular e verificar MD5", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calcular e verificar SHA1", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calcular e verificar SHA256", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calcular e verificar SHA512", + + "VTLANG_POWER": "Energia", + "VTLANG_POWER_REBOOT": "Reiniciar", + "VTLANG_POWER_HALT": "Desligar", + "VTLANG_POWER_BOOT_EFIFW": "Reiniciar com a configuração EFI", + + "VTLANG_KEYBRD_LAYOUT": "Esquemas de teclado", + "VTLANG_HWINFO": "Informação do hardware", + + "VTLANG_RESOLUTION_CFG": "Configuração da resolução", + "VTLANG_SCREEN_MODE": "Modo de exibição", + "VTLANG_SCREEN_TEXT_MODE": "Modo texto", + "VTLANG_SCREEN_GUI_MODE": "Modo gráfico", + + "VTLANG_THEME_SELECT": "Seleção de tema", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "Mostrar controladores EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Corrigir falha BlinitializeLibrary do Windows", + + "VTLANG_JSON_CHK_JSON": "Verificar configuração do plugin json (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Verificar a configuração do plugin de controlo global", + "VTLANG_JSON_CHK_THEME": "Verificar configuração do plugin do tema", + "VTLANG_JSON_CHK_AUTOINS": "Verificar a configuração do plugin de instalação automática", + "VTLANG_JSON_CHK_PERSIST": "Verificar a configuração do plugin de persistência", + "VTLANG_JSON_CHK_MENU_ALIAS": "Verificar a configuração do plugin do menu alias", + "VTLANG_JSON_CHK_MENU_TIP": "Verificar a configuração do plugin do menu de dica", + "VTLANG_JSON_CHK_MENU_CLASS": "Verificar a configuração do plugin do menu classe", + "VTLANG_JSON_CHK_INJECTION": "Verificar a configuração do plugin de injeção", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Verificar a configuração do plugin automático do memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "Verificar configuração do plugin da lista de imagens", + "VTLANG_JSON_CHK_IMG_BLIST": "Verificar configuração do plugin da lista negra de imagens", + "VTLANG_JSON_CHK_CONF_REPLACE": "Verificar a configuração do plugin de substituição de conf. de arranque", + "VTLANG_JSON_CHK_DUD": "Verificar configuração do plugin dud", + "VTLANG_JSON_CHK_PASSWORD": "Verificar configuração do plugin palavra-passe", + + "VTLANG_NORMAL_MODE": "Arrancar no modo normal", + "VTLANG_WIMBOOT_MODE": "Arrancar no modo wimboot", + "VTLANG_GRUB2_MODE": "Arrancar no modo grub2", + "VTLANG_MEMDISK_MODE": "Arrancar no modo memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Voltar para Lista", + "VTLANG_RET_TO_TREEVIEW": "Voltar para Estrutura", + + "VTLANG_NO_AUTOINS_SCRIPT": "Arrancar sem modelo de instalação automática", + "VTLANG_AUTOINS_USE": "Arrancar com", + + "VTLANG_NO_PERSIST": "Arrancar sem persistência", + "VTLANG_PERSIST_USE": "Arrancar com", + + "VTLANG_BROWER_RETURN": "Voltar", + + "VTLANG_ENTER_EXIT": "pressione a tecla Enter para sair", + "VTLANG_ENTER_REBOOT": "pressione a tecla Enter para reiniciar", + "VTLANG_ENTER_CONTINUE": "pressione a tecla Enter para continuar", + + "VTLANG_CTRL_TEMP_SET": "Configurações de Controle Temporário", + "VTLANG_WIN11_BYPASS_CHECK": "Ignorar checagem de CPU/TPM/SecureBoot quando instalando Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Ignorar requerimento de conta online quanto instalando Windows 11", + "VTLANG_LINUX_REMOUNT": "Montar partição Hiperiso após boot do Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Mostar menu seundário de boot", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/ru_RU.json b/src/grub2/grub/menu/ru_RU.json new file mode 100644 index 0000000..afa6f74 --- /dev/null +++ b/src/grub2/grub/menu/ru_RU.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Russian (Русский)", + + "VTLANG_STR_HOTKEY_LIST": "L:Язык F1:Помощь F2:Обзор F3:ВидСписок F4:ЛокалЗагрузка F5:Сервис F6:РасширМеню", + "VTLANG_STR_HOTKEY_TREE": "L:Язык F1:Помощь F2:Обзор F3:ВидДерево F4:ЛокалЗагрузка F5:Сервис F6:РасширМеню", + "VTLANG_RETURN_PREVIOUS": "Вернуться в предыдущее меню [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Вернуться в предыдущее меню", + + "VTLANG_MENU_LANG": "Выбор языка меню", + + "VTLANG_LB_SBOOT_WINDOWS": "Найти и загрузить Windows", + "VTLANG_LB_SBOOT_G4D": "Найти и загрузить Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Загрузить 1-й локальный диск", + "VTLANG_LB_SBOOT_HDD2": "Загрузить 2-й локальный диск", + "VTLANG_LB_SBOOT_HDD3": "Загрузить 3-й локальный диск", + "VTLANG_LB_SBOOT_X64EFI": "Найти и загрузить OOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Найти и загрузить BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Найти и загрузить BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Найти и загрузить xorboot", + + "VTLANG_FILE_CHKSUM": "Контрольная сумма файла", + "VTLANG_CHKSUM_MD5_CALC": "Вычислить md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Вычислить sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Вычислить sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Вычислить sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Вычислить и проверить md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Вычислить и проверить sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Вычислить и проверить sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Вычислить и проверить sha512sum", + + "VTLANG_POWER": "Питание", + "VTLANG_POWER_REBOOT": "Перезагрузить", + "VTLANG_POWER_HALT": "Завершить работу", + "VTLANG_POWER_BOOT_EFIFW": "Перезагрузиться в настройку EFI", + + "VTLANG_KEYBRD_LAYOUT": "Раскладки клавиатуры", + "VTLANG_HWINFO": "Сведения об оборудовании", + + "VTLANG_RESOLUTION_CFG": "Конфигурация разрешения", + "VTLANG_SCREEN_MODE": "Режим отображения экрана", + "VTLANG_SCREEN_TEXT_MODE": "Выбрать текстовый режим", + "VTLANG_SCREEN_GUI_MODE": "Выбрать графический режим", + + "VTLANG_THEME_SELECT": "Выбор темы", + + "VTLANG_UEFI_UTIL": "Утилиты UEFI Hiperiso", + "VTLANG_UTIL_SHOW_EFI_DRV": "Показать драйверы EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Исправить ошибку Windows «BlinitializeLibrary»", + + "VTLANG_JSON_CHK_JSON": "Проверить настройки расширения «json» (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Проверить настройки расширения «global control»", + "VTLANG_JSON_CHK_THEME": "Проверить настройки расширения «theme»", + "VTLANG_JSON_CHK_AUTOINS": "Проверить настройки расширения «auto install»", + "VTLANG_JSON_CHK_PERSIST": "Проверить настройки расширения «persistence»", + "VTLANG_JSON_CHK_MENU_ALIAS": "Проверить настройки расширения «menu alias»", + "VTLANG_JSON_CHK_MENU_TIP": "Проверить настройки расширения «menu tip»", + "VTLANG_JSON_CHK_MENU_CLASS": "Проверить настройки расширения «menu class»", + "VTLANG_JSON_CHK_INJECTION": "Проверить настройки расширения «injection»", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Проверить настройки расширения «auto memdisk»", + "VTLANG_JSON_CHK_IMG_LIST": "Проверить настройки расширения «image list»", + "VTLANG_JSON_CHK_IMG_BLIST": "Проверить настройки расширения «image blacklist»", + "VTLANG_JSON_CHK_CONF_REPLACE": "Проверить настройки расширения «boot conf replace»", + "VTLANG_JSON_CHK_DUD": "Проверить настройки расширения «dud»", + "VTLANG_JSON_CHK_PASSWORD": "Проверить настройки расширения «password»", + + "VTLANG_NORMAL_MODE": "Загрузиться в обычном режиме", + "VTLANG_WIMBOOT_MODE": "Загрузиться в режиме wimboot", + "VTLANG_GRUB2_MODE": "Загрузиться в режиме grub2", + "VTLANG_MEMDISK_MODE": "Загрузиться в режиме memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Вернуться к Виду списком", + "VTLANG_RET_TO_TREEVIEW": "Вернуться к Виду древом", + + "VTLANG_NO_AUTOINS_SCRIPT": "Загрузка без шаблона автоматической установки", + "VTLANG_AUTOINS_USE": "Загрузиться с", + + "VTLANG_NO_PERSIST": "Загрузка без сохраняемости", + "VTLANG_PERSIST_USE": "Загрузиться с", + + "VTLANG_BROWER_RETURN": "Вернуться", + + "VTLANG_ENTER_EXIT": "нажмите клавишу ввода, чтобы выйти", + "VTLANG_ENTER_REBOOT": "нажмите клавишу ввода для перезагрузки", + "VTLANG_ENTER_CONTINUE": "нажмите клавишу ввода, чтобы продолжить", + + "VTLANG_CTRL_TEMP_SET": "Настройки временного управления", + "VTLANG_WIN11_BYPASS_CHECK": "Обойти проверку CPU/TPM/SecureBoot при установке Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Обойти требование сетевой учётной записи при установке Windows 11", + "VTLANG_LINUX_REMOUNT": "Смонтировать раздел Hiperiso после загрузки Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Показать вторичное загрузочное меню", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/sl_si.json b/src/grub2/grub/menu/sl_si.json new file mode 100644 index 0000000..7d9a0f6 --- /dev/null +++ b/src/grub2/grub/menu/sl_si.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Slovenija (Slovenski)", + + "VTLANG_STR_HOTKEY_LIST": "L:Jezik F1:Pomoč F2:Prebrskaj F3:ListView F4:Localboot F5:Orodja F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:Jezik F1:Pomoč F2:Prebrskaj F3:TreeView F4:Localboot F5:Orodja F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "Vrnitev v prejšnji meni [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Vrnitev v prejšnji meni", + + "VTLANG_MENU_LANG": "Izbira jezika menija", + + "VTLANG_LB_SBOOT_WINDOWS": "Iskanje in zagon sistema Windows", + "VTLANG_LB_SBOOT_G4D": "Iskanje in zagon Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Zagon 1. lokalnega diska", + "VTLANG_LB_SBOOT_HDD2": "Zagon 2. lokalnega diska", + "VTLANG_LB_SBOOT_HDD3": "Zagon 3. lokalnega diska", + "VTLANG_LB_SBOOT_X64EFI": "Iskanje in zagon BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Iskanje in zagon BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Iskanje in zagon BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Iskanje in zagon xorboot", + + "VTLANG_FILE_CHKSUM": "File checksum", + "VTLANG_CHKSUM_MD5_CALC": "Izračunaj md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Izračunaj sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Izračunaj sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Izračunaj sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Izračunaj in preveri md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Izračunaj in preveri sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Izračunaj in preveri sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Izračunaj in preveri sha512sum", + + "VTLANG_POWER": "Napajanje", + "VTLANG_POWER_REBOOT": "Ponovni zagon", + "VTLANG_POWER_HALT": "Halt", + "VTLANG_POWER_BOOT_EFIFW": "Ponovni zagon v nastavitev EFI", + + "VTLANG_KEYBRD_LAYOUT": "Postavitev tipkovnice", + "VTLANG_HWINFO": "Informacije o strojni opremi", + + "VTLANG_RESOLUTION_CFG": "Nastavitev ločljivosti", + "VTLANG_SCREEN_MODE": "Način prikaza na zaslonu", + "VTLANG_SCREEN_TEXT_MODE": "Vsili besedilni način", + "VTLANG_SCREEN_GUI_MODE": "Vsili grafični način", + + "VTLANG_THEME_SELECT": "Izbira teme", + + "VTLANG_UEFI_UTIL": "Pripomočki Hiperiso UEFI", + "VTLANG_UTIL_SHOW_EFI_DRV": "Prikaži gonilnike EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Popravek napake Windows BlinitializeLibrary", + + "VTLANG_JSON_CHK_JSON": "Preverite konfiguracijo vtičnika json (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Preverite konfiguracijo globalnega nadzornega vtičnika", + "VTLANG_JSON_CHK_THEME": "Preverite konfiguracijo vtičnika teme", + "VTLANG_JSON_CHK_AUTOINS": "Preverite konfiguracijo vtičnika za samodejno namestitev", + "VTLANG_JSON_CHK_PERSIST": "Preverite konfiguracijo vtičnika persistence", + "VTLANG_JSON_CHK_MENU_ALIAS": "Preverite konfiguracijo vtičnika menija", + "VTLANG_JSON_CHK_MENU_TIP": "Preverite konfiguracijo vtičnika za nasvete menija", + "VTLANG_JSON_CHK_MENU_CLASS": "Preverite konfiguracijo vtičnika razreda menija", + "VTLANG_JSON_CHK_INJECTION": "Check injection plugin configuration", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Preverite konfiguracijo vtičnika Auto Memdisk.", + "VTLANG_JSON_CHK_IMG_LIST": "Preverite konfiguracijo vtičnika za seznam slik", + "VTLANG_JSON_CHK_IMG_BLIST": "Preverite konfiguracijo vtičnika za črno listo slik", + "VTLANG_JSON_CHK_CONF_REPLACE": "Preverite boot conf zamenjajte plugin konfiguracijo", + "VTLANG_JSON_CHK_DUD": "Preverite konfiguracijo vtičnika dud", + "VTLANG_JSON_CHK_PASSWORD": "Preverite konfiguracijo vtičnika za geslo", + + "VTLANG_NORMAL_MODE": "Zagon v običajnem načinu", + "VTLANG_WIMBOOT_MODE": "Zagon v načinu wimboot", + "VTLANG_GRUB2_MODE": "Zagon v načinu grub2", + "VTLANG_MEMDISK_MODE": "Zagon v načinu memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Vrnitev na ListView", + "VTLANG_RET_TO_TREEVIEW": "Vrnitev v TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "Zagon brez predloge za samodejno namestitev", + "VTLANG_AUTOINS_USE": "Zagon z", + + "VTLANG_NO_PERSIST": "Boot without persistence", + "VTLANG_PERSIST_USE": "Zagon z", + + "VTLANG_BROWER_RETURN": "Nazaj", + + "VTLANG_ENTER_EXIT": "za izhod pritisnite tipko Enter", + "VTLANG_ENTER_REBOOT": "pritisnite tipko Enter za ponovni zagon", + "VTLANG_ENTER_CONTINUE": "za nadaljevanje pritisnite tipko Enter", + + "VTLANG_CTRL_TEMP_SET": "Začasne nadzorne nastavitve", + "VTLANG_WIN11_BYPASS_CHECK": "Obid preverjanja CPU/TPM/SecureBoot pri namestitvi sistema Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Obid zahteve po spletnem računu pri namestitvi sistema Windows 11", + "VTLANG_LINUX_REMOUNT": "Priklopi Hiperiso particijo po zagonu Linuxa", + "VTLANG_SECONDARY_BOOT_MENU": "Prikaz sekundarnega zagonskega menija", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/sr_RS.json b/src/grub2/grub/menu/sr_RS.json new file mode 100644 index 0000000..8c987e0 --- /dev/null +++ b/src/grub2/grub/menu/sr_RS.json @@ -0,0 +1,99 @@ + + "VTLANG_LANGUAGE_NAME": "Serbian Latin (Srpski)", + + "VTLANG_STR_HOTKEY_LIST": "L:Језик F1:Help F2:Browse F3:ListView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:Језик F1:Help F2:Browse F3:TreeView F4:Localboot F5:Tools F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "Return to previous menu [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Return to previous menu", + + "VTLANG_MENU_LANG": "Menu Language Select", + + "VTLANG_LB_SBOOT_WINDOWS": "Search and boot Windows", + "VTLANG_LB_SBOOT_G4D": "Search and boot Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Boot the 1st local disk", + "VTLANG_LB_SBOOT_HDD2": "Boot the 2nd local disk", + "VTLANG_LB_SBOOT_HDD3": "Boot the 3rd local disk", + "VTLANG_LB_SBOOT_X64EFI": "Search and boot BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Search and boot BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Search and boot BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Search and boot xorboot", + + "VTLANG_FILE_CHKSUM": "File checksum", + "VTLANG_CHKSUM_MD5_CALC": "Calculate md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Calculate sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Calculate sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Calculate sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Calculate and check md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Calculate and check sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Calculate and check sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Calculate and check sha512sum", + + "VTLANG_POWER": "Power", + "VTLANG_POWER_REBOOT": "Reboot", + "VTLANG_POWER_HALT": "Halt", + "VTLANG_POWER_BOOT_EFIFW": "Reboot to EFI setup", + + "VTLANG_KEYBRD_LAYOUT": "Keyboard Layouts", + "VTLANG_HWINFO": "Hardware Information", + + "VTLANG_RESOLUTION_CFG": "Resolution Configuration", + "VTLANG_SCREEN_MODE": "Screen Display Mode", + "VTLANG_SCREEN_TEXT_MODE": "Force Text Mode", + "VTLANG_SCREEN_GUI_MODE": "Force Graphics Mode", + + "VTLANG_THEME_SELECT": "Theme Select", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "Show EFI Drivers", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Fixup Windows BlinitializeLibrary Failure", + + "VTLANG_JSON_CHK_JSON": "Check plugin json configuration (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Check global control plugin configuration", + "VTLANG_JSON_CHK_THEME": "Check theme plugin configuration", + "VTLANG_JSON_CHK_AUTOINS": "Check auto install plugin configuration", + "VTLANG_JSON_CHK_PERSIST": "Check persistence plugin configuration", + "VTLANG_JSON_CHK_MENU_ALIAS": "Check menu alias plugin configuration", + "VTLANG_JSON_CHK_MENU_TIP": "Check menu tip plugin configuration", + "VTLANG_JSON_CHK_MENU_CLASS": "Check menu class plugin configuration", + "VTLANG_JSON_CHK_INJECTION": "Check injection plugin configuration", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Check auto memdisk plugin configuration", + "VTLANG_JSON_CHK_IMG_LIST": "Check image list plugin configuration", + "VTLANG_JSON_CHK_IMG_BLIST": "Check image blacklist plugin configuration", + "VTLANG_JSON_CHK_CONF_REPLACE": "Check boot conf replace plugin configuration", + "VTLANG_JSON_CHK_DUD": "Check dud plugin configuration", + "VTLANG_JSON_CHK_PASSWORD": "Check password plugin configuration", + + "VTLANG_NORMAL_MODE": "Boot in normal mode", + "VTLANG_WIMBOOT_MODE": "Boot in wimboot mode", + "VTLANG_GRUB2_MODE": "Boot in grub2 mode", + "VTLANG_MEMDISK_MODE": "Boot in memdisk mode", + + "VTLANG_RET_TO_LISTVIEW": "Return to ListView", + "VTLANG_RET_TO_TREEVIEW": "Return to TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "Boot without auto installation template", + "VTLANG_AUTOINS_USE": "Boot with", + + "VTLANG_NO_PERSIST": "Boot without persistence", + "VTLANG_PERSIST_USE": "Boot with", + + "VTLANG_BROWER_RETURN": "Return", + + "VTLANG_ENTER_EXIT": "press Enter key to exit", + "VTLANG_ENTER_REBOOT": "press Enter key to reboot", + "VTLANG_ENTER_CONTINUE": "press Enter key to continue", + + "VTLANG_CTRL_TEMP_SET": "Temporary Control Settings", + "VTLANG_WIN11_BYPASS_CHECK": "Bypass CPU/TPM/SecureBoot check when install Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Bypass online account requirement when install Windows 11", + "VTLANG_LINUX_REMOUNT": "Mount Hiperiso partition after boot Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Show secondary boot menu", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/ta_IN.json b/src/grub2/grub/menu/ta_IN.json new file mode 100644 index 0000000..b6cb4da --- /dev/null +++ b/src/grub2/grub/menu/ta_IN.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Tamil (தமிழ்)", + + "VTLANG_STR_HOTKEY_LIST": "L:மொழி F1:உதவி F2:உலாவுக F3:பட்டியல்பார்வை F4:லோக்கல்பூட் F5:கருவிகள் F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:மொழி F1:உதவி F2:உலாவுக F3:மரப்பார்வை F4:லோக்கல்பூட் F5:கருவிகள் F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "முந்தைய பட்டியலுக்குத் திரும்பு [Esc]", + "VTLANG_RETURN_PRV_NOESC": "முந்தைய பட்டியலுக்குத் திரும்பு", + + "VTLANG_MENU_LANG": "மொழி தேர்வு பட்டியல்", + + "VTLANG_LB_SBOOT_WINDOWS": "விண்டோஸைத் தேடி துவக்கவும்", + "VTLANG_LB_SBOOT_G4D": "Grub4dos ஐத் தேடி துவக்கவும்", + "VTLANG_LB_SBOOT_HDD1": "1வது உள்ளூர் வட்டை துவக்கவும்", + "VTLANG_LB_SBOOT_HDD2": "2வது உள்ளூர் வட்டை துவக்கவும்", + "VTLANG_LB_SBOOT_HDD3": "3வது உள்ளூர் வட்டை துவக்கவும்", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI ஐத் தேடி துவக்கவும்", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI ஐத் தேடி துவக்கவும்", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI ஐத் தேடி துவக்கவும்", + "VTLANG_LB_SBOOT_XORBOOT": "xorboot ஐத் தேடி துவக்கவும்", + + "VTLANG_FILE_CHKSUM": "கோப்பு செக்சம்", + "VTLANG_CHKSUM_MD5_CALC": "md5sum ஐக் கணக்கிடவும்", + "VTLANG_CHKSUM_SHA1_CALC": "sha1sum ஐக் கணக்கிடவும்", + "VTLANG_CHKSUM_SHA256_CALC": "sha256sum ஐக் கணக்கிடவும்", + "VTLANG_CHKSUM_SHA512_CALC": "sha512sum ஐக் கணக்கிடவும்", + "VTLANG_CHKSUM_MD5_CALC_CHK": "md5sum ஐக் கணக்கிட்டு சரிபார்க்கவும்", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "sha1sum ஐக் கணக்கிட்டு சரிபார்க்கவும்", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "sha256sum ஐக் கணக்கிட்டு சரிபார்க்கவும்", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "sha512sum ஐக் கணக்கிட்டு சரிபார்க்கவும்", + + "VTLANG_POWER": "பவர்", + "VTLANG_POWER_REBOOT": "மறுதொடக்கம்", + "VTLANG_POWER_HALT": "நிறுத்து", + "VTLANG_POWER_BOOT_EFIFW": "EFI அமைப்பிற்கு மீண்டும் துவக்கவும்", + + "VTLANG_KEYBRD_LAYOUT": "விசைப்பலகை தளவமைப்புகள்", + "VTLANG_HWINFO": "வன்பொருள் தகவல்", + + "VTLANG_RESOLUTION_CFG": "தீர்மானம் கட்டமைப்பு", + "VTLANG_SCREEN_MODE": "திரை காட்சி பயன்முறை", + "VTLANG_SCREEN_TEXT_MODE": "கட்டாய உரை பயன்முறை", + "VTLANG_SCREEN_GUI_MODE": "கட்டாய கிராபிக்ஸ் பயன்முறை", + + "VTLANG_THEME_SELECT": "தீம் தேர்வு", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI பயன்பாடுகள்", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFI இயக்கிகளைக் காட்டு", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windows BlinitializeLibrary தோல்வியைச் சரிசெய்தல்", + + "VTLANG_JSON_CHK_JSON": "செருகுநிரல் json உள்ளமைவைச் சரிபார்க்கவும் (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "உலகளாவிய கட்டுப்பாட்டு செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_THEME": "தீம் செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_AUTOINS": "தானாக நிறுவும் செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_PERSIST": "நிலைத்தன்மை செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_MENU_ALIAS": "பட்டியலில் மாற்று செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_MENU_TIP": "பட்டியலில் முனை செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_MENU_CLASS": "பட்டியலில் வகுப்பு செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_INJECTION": "ஊசி செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "ஆட்டோ மெம்டிஸ்க் செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_IMG_LIST": "பட பட்டியல் செருகுநிரல் உள்ளமைவை சரிபார்க்கவும்", + "VTLANG_JSON_CHK_IMG_BLIST": "படத்தின் தடுப்புப்பட்டியல் செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + "VTLANG_JSON_CHK_CONF_REPLACE": "பூட் conf சொருகி உள்ளமைவை மாற்றுவதை சரிபார்க்கவும்", + "VTLANG_JSON_CHK_DUD": "dud செருகுநிரல் உள்ளமைவை சரிபார்க்கவும்", + "VTLANG_JSON_CHK_PASSWORD": "கடவுச்சொல் செருகுநிரல் உள்ளமைவைச் சரிபார்க்கவும்", + + "VTLANG_NORMAL_MODE": "சாதாரண பயன்முறையில் துவக்கவும்", + "VTLANG_WIMBOOT_MODE": "wimboot பயன்முறையில் துவக்கவும்", + "VTLANG_GRUB2_MODE": "grub2 பயன்முறையில் துவக்கவும்", + "VTLANG_MEMDISK_MODE": "memdisk பயன்முறையில் துவக்கவும்", + + "VTLANG_RET_TO_LISTVIEW": "பட்டியல்பார்வை பக்கத்துக்குத் திரும்பு", + "VTLANG_RET_TO_TREEVIEW": "மரப்பார்வை பக்கத்துக்குத் திரும்பு", + + "VTLANG_NO_AUTOINS_SCRIPT": "தானியங்கி நிறுவல் டெம்ப்ளேட் இல்லாமல் துவக்கவும்", + "VTLANG_AUTOINS_USE": "துவக்கவும் இத்துடன்", + + "VTLANG_NO_PERSIST": "விடாமுயற்சி இல்லாமல் துவக்கவும்", + "VTLANG_PERSIST_USE": "துவக்கவும் இத்துடன்", + + "VTLANG_BROWER_RETURN": "திரும்பு", + + "VTLANG_ENTER_EXIT": "வெளியேற Enter விசையை அழுத்தவும்", + "VTLANG_ENTER_REBOOT": "மறுதொடக்கம் செய்ய Enter விசையை அழுத்தவும்", + "VTLANG_ENTER_CONTINUE": "தொடர Enter விசையை அழுத்தவும்", + + "VTLANG_CTRL_TEMP_SET": "தற்காலிக கட்டுப்பாட்டு அமைப்புகள்", + "VTLANG_WIN11_BYPASS_CHECK": "விண்டோஸ் 11 ஐ நிறுவும் போது CPU/TPM/SecureBoot சரிபார்பை புறக்கணிக்கவும்", + "VTLANG_WIN11_BYPASS_NRO": "விண்டோஸ் 11 ஐ நிறுவும் போது ஆன்லைன் கணக்கின் தேவையை புறக்கணிக்கவும்", + "VTLANG_LINUX_REMOUNT": "லினக்ஸை துவக்கிய பிறகு Hiperiso பகிர்வை ஏற்றவும்", + "VTLANG_SECONDARY_BOOT_MENU": "இரண்டாம் நிலை துவக்க பட்டியலைக் காட்டு", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/tr_TR.json b/src/grub2/grub/menu/tr_TR.json new file mode 100644 index 0000000..a9f448d --- /dev/null +++ b/src/grub2/grub/menu/tr_TR.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Turkish (Türkçe)", + + "VTLANG_STR_HOTKEY_LIST": "L:Dil F1:Yardım F2:Gözat F3:Liste Görünümü F4:Önyükleme Seçenekleri F5:Araçlar F6:Grub2 Menü", + "VTLANG_STR_HOTKEY_TREE": "L:Dil F1:Yardım F2:Gözat F3:Ağaç Görünümü F4:Önyükleme Seçenekleri F5:Araçlar F6:Grub2 Menü", + "VTLANG_RETURN_PREVIOUS": "Önceki menüye geri dön [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Önceki menüye geri dön", + + "VTLANG_MENU_LANG": "Menü Dili Seçimi", + + "VTLANG_LB_SBOOT_WINDOWS": "Windows'u bul ve Önyükle", + "VTLANG_LB_SBOOT_G4D": "Grub4dos'u bul ve Önyükle", + "VTLANG_LB_SBOOT_HDD1": "1. Yerel diskten Önyükleme yap", + "VTLANG_LB_SBOOT_HDD2": "2. Yerel diskten Önyükleme yap", + "VTLANG_LB_SBOOT_HDD3": "3. Yerel diskten Önyükleme yap", + "VTLANG_LB_SBOOT_X64EFI": "BOOTX64.EFI'yi bul ve Önyükleme yap", + "VTLANG_LB_SBOOT_IA32EFI": "BOOTIA32.EFI'yi bul ve Önyükleme yap", + "VTLANG_LB_SBOOT_AA64EFI": "BOOTAA64.EFI'yi bul ve Önyükleme yap", + "VTLANG_LB_SBOOT_XORBOOT": "XORBOOT'u bul ve Önyükleme yap", + + "VTLANG_FILE_CHKSUM": "Dosya Doğrulama", + "VTLANG_CHKSUM_MD5_CALC": "md5sum değerini hesapla", + "VTLANG_CHKSUM_SHA1_CALC": "sha1sum değerini hesapla", + "VTLANG_CHKSUM_SHA256_CALC": "sha256sum değerini hesapla", + "VTLANG_CHKSUM_SHA512_CALC": "sha512sum değerini hesapla", + "VTLANG_CHKSUM_MD5_CALC_CHK": "md5sum hesapla ve kontrol et", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "sha1sum hesapla ve kontrol et", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "sha256sum hesapla ve kontrol et", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "sha512sum hesapla ve kontrol et", + + "VTLANG_POWER": "Güç Seçenekleri", + "VTLANG_POWER_REBOOT": "Yeniden Başlat", + "VTLANG_POWER_HALT": "Bilgisayarı Kapat", + "VTLANG_POWER_BOOT_EFIFW": "EFI BIOS Ayarları ile Yeniden Başlat", + + "VTLANG_KEYBRD_LAYOUT": "Klavye düzenleri", + "VTLANG_HWINFO": "Donanım Bilgisi", + + "VTLANG_RESOLUTION_CFG": "Çözünürlük Yapılandırması", + "VTLANG_SCREEN_MODE": "Ekran Görüntüleme Modu", + "VTLANG_SCREEN_TEXT_MODE": "Metin Modu'nu Dene", + "VTLANG_SCREEN_GUI_MODE": "Grafik Modu'nu Dene", + + "VTLANG_THEME_SELECT": "Tema Seçimi", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI Utilities", + "VTLANG_UTIL_SHOW_EFI_DRV": "EFI Sürücülerini Göster", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Windows BlinitializeLibrary Hatasını Düzelt", + + "VTLANG_JSON_CHK_JSON": "json (hiperiso.json) Yapılandırma Dosyası Ayarlarını kontrol et", + "VTLANG_JSON_CHK_CONTROL": "(Global Control Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_THEME": "(Theme Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_AUTOINS": "(Auto Install Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_PERSIST": "(Persistence Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_MENU_ALIAS": "(Menu Alias Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_MENU_TIP": "(Menu Tip Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_MENU_CLASS": "(Menu Class Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_INJECTION": "(Injection Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "(Auto Memdisk Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_IMG_LIST": "(Image List Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_IMG_BLIST": "(Image Blacklist Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_CONF_REPLACE": "(Check Boot Conf Replace Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_DUD": "(Dud Plugin) yapılandırma ayarları", + "VTLANG_JSON_CHK_PASSWORD": "(Password Plugin) yapılandırma ayarları", + + "VTLANG_NORMAL_MODE": "NORMAL(ISO) Mod'da ÖnYükleme Yap", + "VTLANG_WIMBOOT_MODE": "WIMBOOT(WIM) Mod'da Önyükleme Yap", + "VTLANG_GRUB2_MODE": "GRUB2 Mod'da Önyükleme Yap", + "VTLANG_MEMDISK_MODE": "MEMDISK Modunda ÖnYükleme Yap", + + "VTLANG_RET_TO_LISTVIEW": "Liste Görünümü Moduna Geri Dön", + "VTLANG_RET_TO_TREEVIEW": "Ağaç Görünümü Moduna Geri Dön", + + "VTLANG_NO_AUTOINS_SCRIPT": "Otomatik yükleme şablonu(autoinstalltemplate.xml) olmadan Önyükleme yap", + "VTLANG_AUTOINS_USE": "ile Önyükleme Yap", + + "VTLANG_NO_PERSIST": "Kalıcı ayar dosyası(persistence.dat) olmadan Önyükleme Yap", + "VTLANG_PERSIST_USE": "ile Önyükleme Yap", + + "VTLANG_BROWER_RETURN": "Geri Dön", + + "VTLANG_ENTER_EXIT": "çıkmak için ENTER tuşuna basın", + "VTLANG_ENTER_REBOOT": "yeniden başlatmak için ENTER'a basın", + "VTLANG_ENTER_CONTINUE": "devam etmek için ENTER'a basın", + + "VTLANG_CTRL_TEMP_SET": "Geçici Kontrol Ayarları", + "VTLANG_WIN11_BYPASS_CHECK": "Windows11'i yüklerken, TPM/CPU/RAM kontrollerini atla", + "VTLANG_WIN11_BYPASS_NRO": "Windows11'i yüklerken, çevrimiçi hesap gereksinimini(OOBE) atla", + "VTLANG_LINUX_REMOUNT": "Linux sistemi önyükledikten sonra, Hiperiso bölümünü bağla", + "VTLANG_SECONDARY_BOOT_MENU": "İkincil önyükleme menüsünü göster", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/uk_UA.json b/src/grub2/grub/menu/uk_UA.json new file mode 100644 index 0000000..c1b645d --- /dev/null +++ b/src/grub2/grub/menu/uk_UA.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Ukrainian (Українська)", + + "VTLANG_STR_HOTKEY_LIST": "L:Мова F1:Довідка F2:Перегляд F3:Вид списком F4:Локальне завантаження F5:Інструменти F6:Вийти з меню", + "VTLANG_STR_HOTKEY_TREE": "L:Мова F1:Довідка F2:Перегляд F3:Вид деревом F4:Локальне завантаження F5:Інструменти F6:Вийти з меню", + "VTLANG_RETURN_PREVIOUS": "Повернутись до попереднього меню [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Повернутись до попереднього меню", + + "VTLANG_MENU_LANG": "Мова меню", + + "VTLANG_LB_SBOOT_WINDOWS": "Знайти та завантажити Windows", + "VTLANG_LB_SBOOT_G4D": "Знайти та завантажити Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Завантажити 1-й локальний диск", + "VTLANG_LB_SBOOT_HDD2": "Завантажити 2-й локальний диск", + "VTLANG_LB_SBOOT_HDD3": "Завантажити 3-й локальний диск", + "VTLANG_LB_SBOOT_X64EFI": "Знайти та завантажити BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Знайти та завантажити BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Знайти та завантажити BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Знайти та завантажити xorboot", + + "VTLANG_FILE_CHKSUM": "Контрольна сума файлу", + "VTLANG_CHKSUM_MD5_CALC": "Розрахувати md5", + "VTLANG_CHKSUM_SHA1_CALC": "Розрахувати sha1", + "VTLANG_CHKSUM_SHA256_CALC": "Розрахувати sha256", + "VTLANG_CHKSUM_SHA512_CALC": "Розрахувати sha512", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Розрахувати та перевірити md5", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Розрахувати та перевірити sha1", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Розрахувати та перевірити sha256", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Розрахувати та перевірити sha512", + + "VTLANG_POWER": "Живлення", + "VTLANG_POWER_REBOOT": "Перезавантажити", + "VTLANG_POWER_HALT": "Завершити роботу", + "VTLANG_POWER_BOOT_EFIFW": "Перезавантажитись до налаштувань UEFI/BIOS", + + "VTLANG_KEYBRD_LAYOUT": "Розкладка клавіатури", + "VTLANG_HWINFO": "Відомості про пристрій", + + "VTLANG_RESOLUTION_CFG": "Налаштування роздільної здатності", + "VTLANG_SCREEN_MODE": "Інтерфейс користувача", + "VTLANG_SCREEN_TEXT_MODE": "Перейти до текстового інтерфейсу", + "VTLANG_SCREEN_GUI_MODE": "Перейти до графічного інтерфейсу", + + "VTLANG_THEME_SELECT": "Теми", + + "VTLANG_UEFI_UTIL": "Утиліти Hiperiso UEFI", + "VTLANG_UTIL_SHOW_EFI_DRV": "Показати драйвери EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Виправити помилку Windows 'BlinitializeLibrary Failure'", + + "VTLANG_JSON_CHK_JSON": "Перевірити налаштування плагіну 'json' (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Перевірити налаштування плагіну 'global control'", + "VTLANG_JSON_CHK_THEME": "Перевірити налаштування плагіну 'theme'", + "VTLANG_JSON_CHK_AUTOINS": "Перевірити налаштування плагіну 'auto install'", + "VTLANG_JSON_CHK_PERSIST": "Перевірити налаштування плагіну 'persistence'", + "VTLANG_JSON_CHK_MENU_ALIAS": "Перевірити налаштування плагіну 'menu alias'", + "VTLANG_JSON_CHK_MENU_TIP": "Перевірити налаштування плагіну 'menu tip'", + "VTLANG_JSON_CHK_MENU_CLASS": "Перевірити налаштування плагіну 'menu class'", + "VTLANG_JSON_CHK_INJECTION": "Перевірити налаштування плагіну 'injection'", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Перевірити налаштування плагіну 'auto memdisk'", + "VTLANG_JSON_CHK_IMG_LIST": "Перевірити налаштування плагіну 'image list'", + "VTLANG_JSON_CHK_IMG_BLIST": "Перевірити налаштування плагіну 'image blacklist plugin'", + "VTLANG_JSON_CHK_CONF_REPLACE": "Перевірити налаштування плагіну 'boot conf replace'", + "VTLANG_JSON_CHK_DUD": "Перевірити налаштування плагіну 'dud'", + "VTLANG_JSON_CHK_PASSWORD": "Перевірити налаштування плагіну 'password'", + + "VTLANG_NORMAL_MODE": "Завантажити в нормальному режимі", + "VTLANG_WIMBOOT_MODE": "Завантажити в режимі wimboot", + "VTLANG_GRUB2_MODE": "Завантажити в режимі GRUB2", + "VTLANG_MEMDISK_MODE": "Завантажити в режимі MEMDISK", + + "VTLANG_RET_TO_LISTVIEW": "Повернутись до перегляду списком", + "VTLANG_RET_TO_TREEVIEW": "Повернутись до деревовидного перегляду", + + "VTLANG_NO_AUTOINS_SCRIPT": "Завантажити без шаблону авто-інсталяції", + "VTLANG_AUTOINS_USE": "Завантажити з", + + "VTLANG_NO_PERSIST": "Завантажити без збереження", + "VTLANG_PERSIST_USE": "Завантажити з ", + + "VTLANG_BROWER_RETURN": "Повернутись", + + "VTLANG_ENTER_EXIT": "натисніть Enter для виходу", + "VTLANG_ENTER_REBOOT": "натисніть Enter для перезавантаження", + "VTLANG_ENTER_CONTINUE": "натисніть Enter для продовження", + + "VTLANG_CTRL_TEMP_SET": "Різні налаштування", + "VTLANG_WIN11_BYPASS_CHECK": "Обійти перевірку CPU/TPM/SecureBoot під час інсталяції Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Обійти вимогу онлайн-аккаунту під час інсталяції Windows 11", + "VTLANG_LINUX_REMOUNT": "Монтувати розділ Hiperiso після завантаження Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Показувати вторинне меню завантаження", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/vi_VN.json b/src/grub2/grub/menu/vi_VN.json new file mode 100644 index 0000000..e451f95 --- /dev/null +++ b/src/grub2/grub/menu/vi_VN.json @@ -0,0 +1,99 @@ +{ + "VTLANG_LANGUAGE_NAME": "Vietnamese (Tiếng Việt)", + + "VTLANG_STR_HOTKEY_LIST": "L:Ngôn ngữ F1:Trợ giúp F2:Duyệt F3:ListView F4:Khởi động cục bộ F5:Công cụ F6:ExMenu", + "VTLANG_STR_HOTKEY_TREE": "L:Ngôn ngữ F1:Trợ giúp F2:Duyệt F3:TreeView F4:Khởi động cục bộ F5:Công cụ F6:ExMenu", + "VTLANG_RETURN_PREVIOUS": "Trở về menu trước [Esc]", + "VTLANG_RETURN_PRV_NOESC": "Trở về menu trước", + + "VTLANG_MENU_LANG": "Chọn ngôn ngữ menu", + + "VTLANG_LB_SBOOT_WINDOWS": "Tìm kiếm và khởi động Windows", + "VTLANG_LB_SBOOT_G4D": "Tìm kiếm và khởi động Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "Khởi động từ ổ đĩa thứ 1 ở trên máy", + "VTLANG_LB_SBOOT_HDD2": "Khởi động từ ổ đĩa thứ 2 ở trên máy", + "VTLANG_LB_SBOOT_HDD3": "Khởi động từ ổ đĩa thứ 3 ở trên máy", + "VTLANG_LB_SBOOT_X64EFI": "Tìm kiếm và khởi động BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "Tìm kiếm và khởi động BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "Tìm kiếm và khởi động BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "Tìm kiếm và khởi động xorboot", + + "VTLANG_FILE_CHKSUM": "Checksum tệp", + "VTLANG_CHKSUM_MD5_CALC": "Tính md5sum", + "VTLANG_CHKSUM_SHA1_CALC": "Tính sha1sum", + "VTLANG_CHKSUM_SHA256_CALC": "Tính sha256sum", + "VTLANG_CHKSUM_SHA512_CALC": "Tính sha512sum", + "VTLANG_CHKSUM_MD5_CALC_CHK": "Tính và kiểm tra md5sum", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "Tính và kiểm tra sha1sum", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "Tính và kiểm tra sha256sum", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "Tính và kiểm tra sha512sum", + + "VTLANG_POWER": "Nguồn điện", + "VTLANG_POWER_REBOOT": "Khởi động lại", + "VTLANG_POWER_HALT": "Tắt máy", + "VTLANG_POWER_BOOT_EFIFW": "Khởi động lại vào cài đặt UEFI", + + "VTLANG_KEYBRD_LAYOUT": "Bố cục bàn phím", + "VTLANG_HWINFO": "Thông tin phần cứng", + + "VTLANG_RESOLUTION_CFG": "Cấu hình độ phân giải", + "VTLANG_SCREEN_MODE": "Chế độ hiển thị", + "VTLANG_SCREEN_TEXT_MODE": "Bắt buộc giao diện văn bản", + "VTLANG_SCREEN_GUI_MODE": "Bắt buộc giao diện đồ hoạ", + + "VTLANG_THEME_SELECT": "Chọn chủ đề", + + "VTLANG_UEFI_UTIL": "Các tiện ích UEFI Hiperiso", + "VTLANG_UTIL_SHOW_EFI_DRV": "Hiển thị các driver EFI", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "Sửa lỗi BlinitializeLibrary của Windows", + + "VTLANG_JSON_CHK_JSON": "Kiểm tra cấu hình plugin json (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "Kiểm tra cấu hình plugin điều khiển toàn cục", + "VTLANG_JSON_CHK_THEME": "Kiểm tra cấu hình plugin chủ đề", + "VTLANG_JSON_CHK_AUTOINS": "Kiểm tra cấu hình plugin tự động cài đặt", + "VTLANG_JSON_CHK_PERSIST": "Kiểm tra cấu hình plugin persistence", + "VTLANG_JSON_CHK_MENU_ALIAS": "Kiểm tra cấu hình plugin alias menu", + "VTLANG_JSON_CHK_MENU_TIP": "Kiểm tra cấu hình plugin tip menu", + "VTLANG_JSON_CHK_MENU_CLASS": "Kiểm tra cấu hình plugin lớp menu", + "VTLANG_JSON_CHK_INJECTION": "Kiểm tra cấu hình plugin injection", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "Kiểm tra cấu hình plugin auto memdisk", + "VTLANG_JSON_CHK_IMG_LIST": "Kiểm tra cấu hình plugin danh sách ảnh đĩa", + "VTLANG_JSON_CHK_IMG_BLIST": "Kiểm tra cấu hình plugin danh sách đen ảnh đĩa", + "VTLANG_JSON_CHK_CONF_REPLACE": "Kiểm tra cấu hình plugin boot replace conf", + "VTLANG_JSON_CHK_DUD": "Kiểm tra cấu hình plugin dud", + "VTLANG_JSON_CHK_PASSWORD": "Kiểm tra cấu hình plugin mật khẩu", + + "VTLANG_NORMAL_MODE": "Khởi động ở chế độ bình thường", + "VTLANG_WIMBOOT_MODE": "Khởi động ở chế độ wimboot", + "VTLANG_GRUB2_MODE": "Khởi động ở chế độ GRUB2", + "VTLANG_MEMDISK_MODE": "Khởi động ở chế độ memdisk", + + "VTLANG_RET_TO_LISTVIEW": "Trở về ListView", + "VTLANG_RET_TO_TREEVIEW": "Trở về TreeView", + + "VTLANG_NO_AUTOINS_SCRIPT": "Khởi động không dùng mẫu cài đặt", + "VTLANG_AUTOINS_USE": "Khởi động với", + + "VTLANG_NO_PERSIST": "Khởi động không có persistence", + "VTLANG_PERSIST_USE": "Khởi động với", + + "VTLANG_BROWER_RETURN": "Trở về", + + "VTLANG_ENTER_EXIT": "nhấn Enter để thoát", + "VTLANG_ENTER_REBOOT": "nhấn Enter để khởi động lại", + "VTLANG_ENTER_CONTINUE": "nhấn enter để tiếp tục", + + "VTLANG_CTRL_TEMP_SET": "Cài đặt điều khiển tạm", + "VTLANG_WIN11_BYPASS_CHECK": "Bỏ qua kiểm tra CPU/TPM/SecureBoot khi cài đặt Windows 11", + "VTLANG_WIN11_BYPASS_NRO": "Bỏ qua yêu cầu tài khoản trực tuyến khi cài đặt Windows 11", + "VTLANG_LINUX_REMOUNT": "Gắn phân vùng Hiperiso sau khi khởi động GNU/Linux", + "VTLANG_SECONDARY_BOOT_MENU": "Hiện menu khởi động thứ cấp`", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/zh_CN.json b/src/grub2/grub/menu/zh_CN.json new file mode 100644 index 0000000..8061f1b --- /dev/null +++ b/src/grub2/grub/menu/zh_CN.json @@ -0,0 +1,98 @@ +{ + "VTLANG_LANGUAGE_NAME": "Chinese Simplified (简体中文)", + + "VTLANG_STR_HOTKEY_LIST": "L:语言 F1:帮助 F2:本地浏览 F3:列表模式 F4:本地启动 F5:工具 F6:扩展菜单", + "VTLANG_STR_HOTKEY_TREE": "L:语言 F1:帮助 F2:本地浏览 F3:树形模式 F4:本地启动 F5:工具 F6:扩展菜单", + "VTLANG_RETURN_PREVIOUS": "返回上一级菜单 [Esc]", + "VTLANG_RETURN_PRV_NOESC": "返回上一级菜单", + + "VTLANG_MENU_LANG": "菜单语言", + + "VTLANG_LB_SBOOT_WINDOWS": "搜索并启动 Windows", + "VTLANG_LB_SBOOT_G4D": "搜索并启动 Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "启动本地硬盘1中的系统", + "VTLANG_LB_SBOOT_HDD2": "启动本地硬盘2中的系统", + "VTLANG_LB_SBOOT_HDD3": "启动本地硬盘3中的系统", + "VTLANG_LB_SBOOT_X64EFI": "搜索并启动 BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "搜索并启动 BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "搜索并启动 BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "搜索并启动 xorboot", + + "VTLANG_FILE_CHKSUM": "文件校验", + "VTLANG_CHKSUM_MD5_CALC": "计算 MD5 校验值", + "VTLANG_CHKSUM_SHA1_CALC": "计算 SHA1 校验值", + "VTLANG_CHKSUM_SHA256_CALC": "计算 SHA256 校验值", + "VTLANG_CHKSUM_SHA512_CALC": "计算 SHA512 校验值", + "VTLANG_CHKSUM_MD5_CALC_CHK": "计算并检查 MD5 校验值", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "计算并检查 SHA1 校验值", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "计算并检查 SHA256 校验值", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "计算并检查 SHA512 校验值", + + "VTLANG_POWER": "电源", + "VTLANG_POWER_REBOOT": "重启", + "VTLANG_POWER_HALT": "关机", + "VTLANG_POWER_BOOT_EFIFW": "重启进入 UEFI 设置菜单", + + "VTLANG_KEYBRD_LAYOUT": "键盘布局", + "VTLANG_HWINFO": "硬件信息", + + "VTLANG_RESOLUTION_CFG": "屏幕分辨率", + "VTLANG_SCREEN_MODE": "显示模式", + "VTLANG_SCREEN_TEXT_MODE": "文本模式", + "VTLANG_SCREEN_GUI_MODE": "图形模式", + + "VTLANG_THEME_SELECT": "主题选择", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI 工具", + "VTLANG_UTIL_SHOW_EFI_DRV": "显示 UEFI 驱动", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "修复 Windows BlinitializeLibrary 错误", + + "VTLANG_JSON_CHK_JSON": "检查插件配置文件 (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "配置检查 —— 全局控制插件", + "VTLANG_JSON_CHK_THEME": "配置检查 —— 主题插件", + "VTLANG_JSON_CHK_AUTOINS": "配置检查 —— 自动安装插件", + "VTLANG_JSON_CHK_PERSIST": "配置检查 —— 持久化插件", + "VTLANG_JSON_CHK_MENU_ALIAS": "配置检查 —— 菜单别名插件", + "VTLANG_JSON_CHK_MENU_TIP": "配置检查 —— 菜单提示插件", + "VTLANG_JSON_CHK_MENU_CLASS": "配置检查 —— 菜单类型插件", + "VTLANG_JSON_CHK_INJECTION": "配置检查 —— 文件注入插件", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "配置检查 —— 自动内存盘模式插件", + "VTLANG_JSON_CHK_IMG_LIST": "配置检查 —— 文件列表插件(白名单)", + "VTLANG_JSON_CHK_IMG_BLIST": "配置检查 —— 文件列表插件(黑名单)", + "VTLANG_JSON_CHK_CONF_REPLACE": "配置检查 —— 启动配置替换插件", + "VTLANG_JSON_CHK_DUD": "配置检查 —— Driver Update Disk插件", + "VTLANG_JSON_CHK_PASSWORD": "配置检查 —— 密码插件", + + "VTLANG_NORMAL_MODE": "以正常模式启动", + "VTLANG_WIMBOOT_MODE": "以 wimboot 模式启动", + "VTLANG_GRUB2_MODE": "以 grub2 模式启动", + "VTLANG_MEMDISK_MODE": "以内存盘模式启动", + + "VTLANG_RET_TO_LISTVIEW": "返回到列表模式", + "VTLANG_RET_TO_TREEVIEW": "返回到树形模式", + + "VTLANG_NO_AUTOINS_SCRIPT": "不使用自动安装脚本", + "VTLANG_AUTOINS_USE": "使用", + + "VTLANG_NO_PERSIST": "不使用持久化数据文件", + "VTLANG_PERSIST_USE": "使用", + + "VTLANG_BROWER_RETURN": "返回", + + "VTLANG_ENTER_EXIT": "按回车键退出", + "VTLANG_ENTER_REBOOT": "按回车键重启", + "VTLANG_ENTER_CONTINUE": "按回车键继续", + + "VTLANG_CTRL_TEMP_SET": "控制变量设置", + "VTLANG_WIN11_BYPASS_CHECK": "安装 Windows 11 时绕过 TPM/安全启动 等硬件检查", + "VTLANG_WIN11_BYPASS_NRO": "安装 Windows 11 时绕过在线账户的要求", + "VTLANG_LINUX_REMOUNT": "启动 Linux 系统后挂载 Hiperiso 分区", + "VTLANG_SECONDARY_BOOT_MENU": "显示二级启动菜单", + "VTLANG_WIN_UEFI_RES_LOCK": "UEFI启动 Windows/WinPE 时锁定分辨率", + "VTLANG_UEFI_RES_LOCK_NONE": "不锁定", + "VTLANG_UEFI_RES_LOCK_MAX": "锁定最高分辨率", + "VTLANG_UEFI_RES_LOCK_1024_768": "锁定 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "锁定 1024 x 768 及以上", + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menu/zh_TW.json b/src/grub2/grub/menu/zh_TW.json new file mode 100644 index 0000000..3343712 --- /dev/null +++ b/src/grub2/grub/menu/zh_TW.json @@ -0,0 +1,98 @@ +{ + "VTLANG_LANGUAGE_NAME": "Chinese Traditional (正體中文)", + + "VTLANG_STR_HOTKEY_LIST": "L:語言 F1:說明 F2:瀏覽 F3:清單檢視 F4:本機啟動 F5:工具 F6:附加選單", + "VTLANG_STR_HOTKEY_TREE": "L:語言 F1:說明 F2:瀏覽 F3:樹狀檢視 F4:本機啟動 F5:工具 F6:附加選單", + "VTLANG_RETURN_PREVIOUS": "返回上一層選單 [Esc]", + "VTLANG_RETURN_PRV_NOESC": "返回上一層選單", + + "VTLANG_MENU_LANG": "選單語言", + + "VTLANG_LB_SBOOT_WINDOWS": "搜尋並啟動 Windows", + "VTLANG_LB_SBOOT_G4D": "搜尋並啟動 Grub4dos", + "VTLANG_LB_SBOOT_HDD1": "啟動本機硬碟1中的系統", + "VTLANG_LB_SBOOT_HDD2": "啟動本機硬碟2中的系統", + "VTLANG_LB_SBOOT_HDD3": "啟動本機硬碟3中的系統", + "VTLANG_LB_SBOOT_X64EFI": "搜尋並啟動 BOOTX64.EFI", + "VTLANG_LB_SBOOT_IA32EFI": "搜尋並啟動 BOOTIA32.EFI", + "VTLANG_LB_SBOOT_AA64EFI": "搜尋並啟動 BOOTAA64.EFI", + "VTLANG_LB_SBOOT_XORBOOT": "搜尋並啟動 xorboot", + + "VTLANG_FILE_CHKSUM": "校驗檔案", + "VTLANG_CHKSUM_MD5_CALC": "計算 MD5 檢查碼", + "VTLANG_CHKSUM_SHA1_CALC": "計算 SHA1 檢查碼", + "VTLANG_CHKSUM_SHA256_CALC": "計算 SHA256 檢查碼", + "VTLANG_CHKSUM_SHA512_CALC": "計算 SHA512 檢查碼", + "VTLANG_CHKSUM_MD5_CALC_CHK": "計算並檢查 MD5 檢查碼", + "VTLANG_CHKSUM_SHA1_CALC_CHK": "計算並檢查 SHA1 檢查碼", + "VTLANG_CHKSUM_SHA256_CALC_CHK": "計算並檢查 SHA256 檢查碼", + "VTLANG_CHKSUM_SHA512_CALC_CHK": "計算並檢查 SHA512 檢查碼", + + "VTLANG_POWER": "電源", + "VTLANG_POWER_REBOOT": "重新開機", + "VTLANG_POWER_HALT": "關機", + "VTLANG_POWER_BOOT_EFIFW": "重新開機進入 UEFI 設定選單", + + "VTLANG_KEYBRD_LAYOUT": "鍵盤設定", + "VTLANG_HWINFO": "硬體資訊", + + "VTLANG_RESOLUTION_CFG": "螢幕解析度", + "VTLANG_SCREEN_MODE": "顯示模式", + "VTLANG_SCREEN_TEXT_MODE": "強制文字模式", + "VTLANG_SCREEN_GUI_MODE": "強制圖形模式", + + "VTLANG_THEME_SELECT": "主題風格選擇", + + "VTLANG_UEFI_UTIL": "Hiperiso UEFI 實用程式", + "VTLANG_UTIL_SHOW_EFI_DRV": "顯示 UEFI 驅動", + "VTLANG_UTIL_FIX_BLINIT_FAIL": "修復 Windows BlinitializeLibrary 錯誤", + + "VTLANG_JSON_CHK_JSON": "檢查外掛程式設定檔 (hiperiso.json)", + "VTLANG_JSON_CHK_CONTROL": "設定檢查 —— 全域控制外掛程式", + "VTLANG_JSON_CHK_THEME": "設定檢查 —— 主題風格外掛程式", + "VTLANG_JSON_CHK_AUTOINS": "設定檢查 —— 自動安裝外掛程式", + "VTLANG_JSON_CHK_PERSIST": "設定檢查 —— 永久性外掛程式", + "VTLANG_JSON_CHK_MENU_ALIAS": "設定檢查 —— 功能表別名外掛程式", + "VTLANG_JSON_CHK_MENU_TIP": "設定檢查 —— 功能表提示外掛程式", + "VTLANG_JSON_CHK_MENU_CLASS": "設定檢查 —— 功能表分類外掛程式", + "VTLANG_JSON_CHK_INJECTION": "設定檢查 —— 檔注入外掛程式", + "VTLANG_JSON_CHK_AUTO_MEMDISK": "設定檢查 —— 自動 memdisk 模式外掛程式", + "VTLANG_JSON_CHK_IMG_LIST": "設定檢查 —— 映像檔清單外掛程式(白名單)", + "VTLANG_JSON_CHK_IMG_BLIST": "設定檢查 —— 映像檔清單外掛程式(黑名單)", + "VTLANG_JSON_CHK_CONF_REPLACE": "設定檢查 —— 啟動設定替換外掛程式", + "VTLANG_JSON_CHK_DUD": "設定檢查 —— Driver Update Disk外掛程式", + "VTLANG_JSON_CHK_PASSWORD": "設定檢查 —— 密碼外掛程式", + + "VTLANG_NORMAL_MODE": "以正常模式啟動", + "VTLANG_WIMBOOT_MODE": "以 wimboot 模式啟動", + "VTLANG_GRUB2_MODE": "以 grub2 模式啟動", + "VTLANG_MEMDISK_MODE": "以 memdisk 模式啟動", + + "VTLANG_RET_TO_LISTVIEW": "返回到清單檢視", + "VTLANG_RET_TO_TREEVIEW": "返回到樹狀檢視", + + "VTLANG_NO_AUTOINS_SCRIPT": "不使用自動安裝腳本", + "VTLANG_AUTOINS_USE": "使用", + + "VTLANG_NO_PERSIST": "不使用永久性資料檔案", + "VTLANG_PERSIST_USE": "使用", + + "VTLANG_BROWER_RETURN": "返回", + + "VTLANG_ENTER_EXIT": "按 Enter 鍵退出", + "VTLANG_ENTER_REBOOT": "按 Enter 鍵重新開機", + "VTLANG_ENTER_CONTINUE": "按 Enter 鍵繼續", + + "VTLANG_CTRL_TEMP_SET": "控制變數設定", + "VTLANG_WIN11_BYPASS_CHECK": "安裝 Windows 11 時繞過TPM/安全啟動等硬體檢查", + "VTLANG_WIN11_BYPASS_NRO": "安裝 Windows 11 時繞過登入帳戶的需求", + "VTLANG_LINUX_REMOUNT": "啟動 Linux 系統後掛載 Hiperiso 分區", + "VTLANG_SECONDARY_BOOT_MENU": "顯示次要啟動選單", + "VTLANG_WIN_UEFI_RES_LOCK": "Lock the resolution when UEFI boot Windows/WinPE", + "VTLANG_UEFI_RES_LOCK_NONE": "None", + "VTLANG_UEFI_RES_LOCK_MAX": "Highest", + "VTLANG_UEFI_RES_LOCK_1024_768": "Fixed 1024 x 768", + "VTLANG_UEFI_RES_LOCK_BE1024_768": "At least 1024 x 768", + + "MENU_STR_XXX": "" +} diff --git a/src/grub2/grub/menulang.cfg b/src/grub2/grub/menulang.cfg new file mode 100644 index 0000000..9b47ea3 --- /dev/null +++ b/src/grub2/grub/menulang.cfg @@ -0,0 +1,149 @@ +menuentry "Arabic (العربية)" --id="ar_AR" { + vt_init_menu_lang ar_AR + configfile ${prefix}/grub.cfg +} + +menuentry "Bengali (বাংলা)" --id="bn_BN" { + vt_init_menu_lang bn_BN + configfile ${prefix}/grub.cfg +} + +menuentry "Czech (Čeština)" --id="cs_CZ" { + vt_init_menu_lang cs_CZ + configfile ${prefix}/grub.cfg +} + +menuentry "German (Deutsch)" --id="de_DE" { + vt_init_menu_lang de_DE + configfile ${prefix}/grub.cfg +} + +menuentry "Greek (Ελληνικά)" --id="el_GR" { + vt_init_menu_lang el_GR + configfile ${prefix}/grub.cfg +} + +menuentry "English (English)" --id="en_US" { + vt_init_menu_lang en_US + configfile ${prefix}/grub.cfg +} + +menuentry "Spanish (Español)" --id="es_ES" { + vt_init_menu_lang es_ES + configfile ${prefix}/grub.cfg +} + +menuentry "Persian (فارسی)" --id="fa_IR" { + vt_init_menu_lang fa_IR + configfile ${prefix}/grub.cfg +} + +menuentry "French (Français)" --id="fr_FR" { + vt_init_menu_lang fr_FR + configfile ${prefix}/grub.cfg +} + +menuentry "Hindi (हिन्दी)" --id="hi_HI" { + vt_init_menu_lang hi_HI + configfile ${prefix}/grub.cfg +} + +menuentry "Croatian (Hrvatski)" --id="hr_HR" { + vt_init_menu_lang hr_HR + configfile ${prefix}/grub.cfg +} + +menuentry "Magyar (Hungarian)" --id="hu_HU" { + vt_init_menu_lang hu_HU + configfile ${prefix}/grub.cfg +} + +menuentry "Indonesian (Bahasa Indonesia)" --id="id_ID" { + vt_init_menu_lang id_ID + configfile ${prefix}/grub.cfg +} + +menuentry "Italiano (Italian)" --id="it_IT" { + vt_init_menu_lang it_IT + configfile ${prefix}/grub.cfg +} + +menuentry "Japanese (日本語)" --id="ja_JP" { + vt_init_menu_lang ja_JP + configfile ${prefix}/grub.cfg +} + +menuentry "Georgian (ქართული)" --id="ka_GE" { + vt_init_menu_lang ka_GE + configfile ${prefix}/grub.cfg +} + +menuentry "Korean (한국어)" --id="ko_KR" { + vt_init_menu_lang ko_KR + configfile ${prefix}/grub.cfg +} + +menuentry "English (English)" --id="lg_UG" { + vt_init_menu_lang lg_UG + configfile ${prefix}/grub.cfg +} + +menuentry "Polish (Poland)" --id="pl_PL" { + vt_init_menu_lang pl_PL + configfile ${prefix}/grub.cfg +} + +menuentry "Brazilian Portuguese (Português Brasileiro)" --id="pt_BR" { + vt_init_menu_lang pt_BR + configfile ${prefix}/grub.cfg +} + +menuentry "Portuguese (Português de Portugal)" --id="pt_PT" { + vt_init_menu_lang pt_PT + configfile ${prefix}/grub.cfg +} + +menuentry "Russian (Русский)" --id="ru_RU" { + vt_init_menu_lang ru_RU + configfile ${prefix}/grub.cfg +} + +menuentry "Slovenija (Slovenski)" --id="sl_si" { + vt_init_menu_lang sl_si + configfile ${prefix}/grub.cfg +} + +menuentry "Serbian Latin (Srpski)" --id="sr_RS" { + vt_init_menu_lang sr_RS + configfile ${prefix}/grub.cfg +} + +menuentry "Tamil (தமிழ்)" --id="ta_IN" { + vt_init_menu_lang ta_IN + configfile ${prefix}/grub.cfg +} + +menuentry "Turkish (Türkçe)" --id="tr_TR" { + vt_init_menu_lang tr_TR + configfile ${prefix}/grub.cfg +} + +menuentry "Ukrainian (Українська)" --id="uk_UA" { + vt_init_menu_lang uk_UA + configfile ${prefix}/grub.cfg +} + +menuentry "Vietnamese (Tiếng Việt)" --id="vi_VN" { + vt_init_menu_lang vi_VN + configfile ${prefix}/grub.cfg +} + +menuentry "Chinese Simplified (简体中文)" --id="zh_CN" { + vt_init_menu_lang zh_CN + configfile ${prefix}/grub.cfg +} + +menuentry "Chinese Traditional (正體中文)" --id="zh_TW" { + vt_init_menu_lang zh_TW + configfile ${prefix}/grub.cfg +} diff --git a/src/grub2/grub/mips64el-efi/command.lst b/src/grub2/grub/mips64el-efi/command.lst new file mode 100644 index 0000000..1a5b7f8 Binary files /dev/null and b/src/grub2/grub/mips64el-efi/command.lst differ diff --git a/src/grub2/grub/mips64el-efi/crypto.lst b/src/grub2/grub/mips64el-efi/crypto.lst new file mode 100644 index 0000000..bd0a97c Binary files /dev/null and b/src/grub2/grub/mips64el-efi/crypto.lst differ diff --git a/src/grub2/grub/mips64el-efi/fdt.lst b/src/grub2/grub/mips64el-efi/fdt.lst new file mode 100644 index 0000000..ea28d9e Binary files /dev/null and b/src/grub2/grub/mips64el-efi/fdt.lst differ diff --git a/src/grub2/grub/mips64el-efi/fs.lst b/src/grub2/grub/mips64el-efi/fs.lst new file mode 100644 index 0000000..12c6c9d Binary files /dev/null and b/src/grub2/grub/mips64el-efi/fs.lst differ diff --git a/src/grub2/grub/mips64el-efi/moddep.lst b/src/grub2/grub/mips64el-efi/moddep.lst new file mode 100644 index 0000000..427a4b0 Binary files /dev/null and b/src/grub2/grub/mips64el-efi/moddep.lst differ diff --git a/src/grub2/grub/mips64el-efi/partmap.lst b/src/grub2/grub/mips64el-efi/partmap.lst new file mode 100644 index 0000000..720c55e Binary files /dev/null and b/src/grub2/grub/mips64el-efi/partmap.lst differ diff --git a/src/grub2/grub/mips64el-efi/parttool.lst b/src/grub2/grub/mips64el-efi/parttool.lst new file mode 100644 index 0000000..bfa2d4a Binary files /dev/null and b/src/grub2/grub/mips64el-efi/parttool.lst differ diff --git a/src/grub2/grub/mips64el-efi/terminal.lst b/src/grub2/grub/mips64el-efi/terminal.lst new file mode 100644 index 0000000..0f853df Binary files /dev/null and b/src/grub2/grub/mips64el-efi/terminal.lst differ diff --git a/src/grub2/grub/mips64el-efi/video.lst b/src/grub2/grub/mips64el-efi/video.lst new file mode 100644 index 0000000..ad1dbd0 Binary files /dev/null and b/src/grub2/grub/mips64el-efi/video.lst differ diff --git a/src/grub2/grub/power.cfg b/src/grub2/grub/power.cfg new file mode 100644 index 0000000..805f2cc --- /dev/null +++ b/src/grub2/grub/power.cfg @@ -0,0 +1,25 @@ +submenu "$VTLANG_POWER" --class=debug_power --class=F5tool { + menuentry "$VTLANG_POWER_REBOOT" --class=debug_reboot --class=debug_power --class=F5tool { + echo -e '\n\nSystem is rebooting ... \n' + sleep 1 + reboot + } + + menuentry "$VTLANG_POWER_HALT" --class=debug_halt --class=debug_power --class=F5tool { + echo -e '\n\nSystem is halting ... \n' + sleep 1 + halt + } + + if [ "$grub_platform" != "pc" ]; then + menuentry "$VTLANG_POWER_BOOT_EFIFW" --class=debug_efisetup --class=debug_power --class=F5tool { + echo -e '\n\nRebooting to enter UEFI firmware setup ... \n' + sleep 1 + fwsetup + } + fi + + menuentry "$VTLANG_RETURN_PREVIOUS" --class=hisoret HISO_RET { + echo "Return ..." + } +} diff --git a/src/grub2/grub/themes/hiperiso/background.png b/src/grub2/grub/themes/hiperiso/background.png new file mode 100644 index 0000000..8a4ac94 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/background.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_c.png b/src/grub2/grub/themes/hiperiso/menu_c.png new file mode 100644 index 0000000..75c165b Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_c.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_e.png b/src/grub2/grub/themes/hiperiso/menu_e.png new file mode 100644 index 0000000..d4c7421 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_e.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_n.png b/src/grub2/grub/themes/hiperiso/menu_n.png new file mode 100644 index 0000000..5af3469 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_n.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_ne.png b/src/grub2/grub/themes/hiperiso/menu_ne.png new file mode 100644 index 0000000..8757868 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_ne.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_nw.png b/src/grub2/grub/themes/hiperiso/menu_nw.png new file mode 100644 index 0000000..8757868 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_nw.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_s.png b/src/grub2/grub/themes/hiperiso/menu_s.png new file mode 100644 index 0000000..6ba2734 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_s.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_se.png b/src/grub2/grub/themes/hiperiso/menu_se.png new file mode 100644 index 0000000..959b609 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_se.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_sw.png b/src/grub2/grub/themes/hiperiso/menu_sw.png new file mode 100644 index 0000000..959b609 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_sw.png differ diff --git a/src/grub2/grub/themes/hiperiso/menu_w.png b/src/grub2/grub/themes/hiperiso/menu_w.png new file mode 100644 index 0000000..d4c7421 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/menu_w.png differ diff --git a/src/grub2/grub/themes/hiperiso/select_c.png b/src/grub2/grub/themes/hiperiso/select_c.png new file mode 100644 index 0000000..245259a Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/select_c.png differ diff --git a/src/grub2/grub/themes/hiperiso/slider_c.png b/src/grub2/grub/themes/hiperiso/slider_c.png new file mode 100644 index 0000000..7d630fd Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/slider_c.png differ diff --git a/src/grub2/grub/themes/hiperiso/slider_n.png b/src/grub2/grub/themes/hiperiso/slider_n.png new file mode 100644 index 0000000..41482c9 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/slider_n.png differ diff --git a/src/grub2/grub/themes/hiperiso/slider_s.png b/src/grub2/grub/themes/hiperiso/slider_s.png new file mode 100644 index 0000000..17adc2a Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/slider_s.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_c.png b/src/grub2/grub/themes/hiperiso/terminal_box_c.png new file mode 100644 index 0000000..d0dd52a Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_c.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_e.png b/src/grub2/grub/themes/hiperiso/terminal_box_e.png new file mode 100644 index 0000000..394cbe4 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_e.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_n.png b/src/grub2/grub/themes/hiperiso/terminal_box_n.png new file mode 100644 index 0000000..476f8bc Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_n.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_ne.png b/src/grub2/grub/themes/hiperiso/terminal_box_ne.png new file mode 100644 index 0000000..9e26959 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_ne.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_nw.png b/src/grub2/grub/themes/hiperiso/terminal_box_nw.png new file mode 100644 index 0000000..5c3cba8 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_nw.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_s.png b/src/grub2/grub/themes/hiperiso/terminal_box_s.png new file mode 100644 index 0000000..85a8901 Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_s.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_se.png b/src/grub2/grub/themes/hiperiso/terminal_box_se.png new file mode 100644 index 0000000..d8627ee Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_se.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_sw.png b/src/grub2/grub/themes/hiperiso/terminal_box_sw.png new file mode 100644 index 0000000..67c600c Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_sw.png differ diff --git a/src/grub2/grub/themes/hiperiso/terminal_box_w.png b/src/grub2/grub/themes/hiperiso/terminal_box_w.png new file mode 100644 index 0000000..d066e2d Binary files /dev/null and b/src/grub2/grub/themes/hiperiso/terminal_box_w.png differ diff --git a/src/grub2/grub/themes/hiperiso/theme.txt b/src/grub2/grub/themes/hiperiso/theme.txt new file mode 100644 index 0000000..492a159 --- /dev/null +++ b/src/grub2/grub/themes/hiperiso/theme.txt @@ -0,0 +1,97 @@ + +desktop-image: "background.png" +title-text: " " +title-color: "#ffffff" +message-color: "#f2f2f2" + +terminal-box: "terminal_box_*.png" + ++ boot_menu { + left = 10% + width = 80% + top = 30% + height = 50% + + menu_pixmap_style = "menu_*.png" + + item_color = "#ffffff" + item_height = 30 + + item_spacing = 1 + item_padding = 1 + + selected_item_color= "#f2f2f2" + selected_item_pixmap_style = "select_*.png" + + item_icon_space = 0 + + scrollbar = true + scrollbar_width = 10 + scrollbar_thumb = "slider_*.png" +} + + + ++ progress_bar { + id = "__timeout__" + text = "@TIMEOUT_NOTIFICATION_SHORT@" + + left = 90% + width = 10% + top = 90% + + text_color = "red" + bar_style = "*" + highlight_style = "*" +} + ++ hbox{ + left = 28% + top = 95% + width = 10% + height = 25 + + label {text = "@HISO_HOTKEY_TIP@" color = "blue" align = "left"} +} + + ++ hbox{ + left = 30% + top = 95%-25 + width = 10% + height = 25 + + label {text = "@HISO_MEM_DISK@" color = "red" align = "left"} +} + + ++ hbox{ + left = 30% + top = 95%-50 + width = 10% + height = 25 + + label {text = "@HISO_ISO_RAW@" color = "red" align = "left"} +} + + ++ hbox{ + left = 30%+200 + top = 95%-50 + width = 10% + height = 25 + + label {text = "@HISO_GRUB2_MODE@" color = "red" align = "left"} +} + ++ hbox{ + left = 30%+200 + top = 95%-25 + width = 10% + height = 25 + + label {text = "@HISO_WIMBOOT_MODE@" color = "red" align = "left"} +} + ++ hbox{ + left = 90% + top = 55 + width = 10% + height = 25 + + label {text = "@HISO_ISO_UEFI_DRV@" color = "red" align = "left"} +} diff --git a/src/grub2/grub/x86_64-efi/command.lst b/src/grub2/grub/x86_64-efi/command.lst new file mode 100644 index 0000000..96cba29 --- /dev/null +++ b/src/grub2/grub/x86_64-efi/command.lst @@ -0,0 +1,203 @@ +*acpi: acpi +*all_functional_test: functional_test +*background_image: gfxterm_background +*bls_import: blscfg +*blscfg: blscfg +*cat: cat +*cpuid: cpuid +*crc: hashsum +*cryptomount: cryptodisk +*echo: echo +*extract_syslinux_entries_configfile: syslinuxcfg +*extract_syslinux_entries_source: syslinuxcfg +*file: file +*functional_test: functional_test +*fwconnect: fwload +*fwload: fwload +*gettext: gettext +*hashsum: hashsum +*hdparm: hdparm +*hello: hello +*help: help +*hexdump: hexdump +*inb: iorw +*inl: iorw +*inw: iorw +*keystatus: keystatus +*kfreebsd: bsd +*knetbsd: bsd +*kopenbsd: bsd +*list_env: loadenv +*load_env: loadenv +*loopback: loopback +*ls: ls +*lsacpi: lsacpi +*lspci: lspci +*md5sum: hashsum +*menuentry: normal +*pcidump: pcidump +*probe: probe +*rdmsr: rdmsr +*read_byte: memrw +*read_dword: memrw +*read_word: memrw +*regexp: regexp +*save_env: loadenv +*search: search +*serial: serial +*set_keyboard_layout: setkey +*setkey: setkey +*setpci: setpci +*sha1sum: hashsum +*sha256sum: hashsum +*sha512sum: hashsum +*sleep: sleep +*smbios: smbios +*submenu: normal +*syslinux_configfile: syslinuxcfg +*syslinux_source: syslinuxcfg +*terminfo: terminfo +*test_blockarg: test_blockarg +*testspeed: testspeed +*tr: tr +*trust: pgp +*verify_detached: pgp +*xnu_splash: xnu +*zfskey: zfscrypt +.: configfile +[: test +appleloader: appleldr +authenticate: normal +background_color: gfxterm_background +backtrace: backtrace +badram: mmap +blocklist: blocklist +boot: boot +break: normal +cat: minicmd +cbmemc: cbmemc +chainloader: chain +clear: normal +cmp: cmp +configfile: configfile +continue: normal +coreboot_boottime: cbtime +cutmem: mmap +date: date +distrust: pgp +dump: minicmd +eval: eval +exit: minicmd +export: normal +extract_entries_configfile: configfile +extract_entries_source: configfile +extract_legacy_entries_configfile: legacycfg +extract_legacy_entries_source: legacycfg +fakebios: loadbios +false: true +fix_video: fixvideo +fwsetup: efifwsetup +gptsync: gptsync +halt: halt +help: minicmd +hexdump_random: random +initrd16: linux16 +initrd: linux +initrdefi: linux +keymap: keylayouts +kfreebsd_loadenv: bsd +kfreebsd_module: bsd +kfreebsd_module_elf: bsd +knetbsd_module: bsd +knetbsd_module_elf: bsd +kopenbsd_ramdisk: bsd +legacy_check_password: legacycfg +legacy_configfile: legacycfg +legacy_initrd: legacycfg +legacy_initrd_nounzip: legacycfg +legacy_kernel: legacycfg +legacy_password: legacycfg +legacy_source: legacycfg +linux16: linux16 +linux: linux +linuxefi: linux +list_trusted: pgp +loadbios: loadbios +loadfont: font +lscoreboot: cbls +lsefi: lsefi +lsefimmap: lsefimmap +lsefisystab: lsefisystab +lsfonts: font +lsmmap: lsmmap +lsmod: minicmd +lssal: lssal +macppcbless: macbless +mactelbless: macbless +module2: multiboot2 +module: multiboot +multiboot2: multiboot2 +multiboot: multiboot +nativedisk: nativedisk +net_add_addr: net +net_add_dns: net +net_add_route: net +net_bootp: net +net_del_addr: net +net_del_dns: net +net_del_route: net +net_dhcp: net +net_get_dhcp_option: net +net_ipv6_autoconf: net +net_ls_addr: net +net_ls_cards: net +net_ls_dns: net +net_ls_routes: net +net_nslookup: net +normal: normal +normal_exit: normal +outb: iorw +outl: iorw +outw: iorw +parttool: parttool +password: password +password_pbkdf2: password_pbkdf2 +play: play +read: read +reboot: reboot +return: normal +rmmod: minicmd +search.file: search_fs_file +search.fs_label: search_label +search.fs_uuid: search_fs_uuid +setparams: normal +shift: normal +source: configfile +terminal_input: terminal +terminal_output: terminal +test: test +testload: testload +time: time +true: true +usb: usbtest +videoinfo: videoinfo +videotest: videotest +vt_img_extra_initrd_append: linux +vt_img_extra_initrd_reset: linux +vt_set_boot_opt: linux +vt_unset_boot_opt: linux +write_byte: memrw +write_dword: memrw +write_word: memrw +wrmsr: wrmsr +xnu_devprop_load: xnu +xnu_kernel64: xnu +xnu_kernel: xnu +xnu_kext: xnu +xnu_kextdir: xnu +xnu_mkext: xnu +xnu_ramdisk: xnu +xnu_resume: xnu +xnu_uuid: xnu_uuid +zfs-bootfs: zfsinfo +zfsinfo: zfsinfo diff --git a/src/grub2/grub/x86_64-efi/crypto.lst b/src/grub2/grub/x86_64-efi/crypto.lst new file mode 100644 index 0000000..77d9efc --- /dev/null +++ b/src/grub2/grub/x86_64-efi/crypto.lst @@ -0,0 +1,45 @@ +RIJNDAEL: gcry_rijndael +RIJNDAEL192: gcry_rijndael +RIJNDAEL256: gcry_rijndael +AES128: gcry_rijndael +AES-128: gcry_rijndael +AES-192: gcry_rijndael +AES-256: gcry_rijndael +ADLER32: adler32 +CRC64: crc64 +ARCFOUR: gcry_arcfour +BLOWFISH: gcry_blowfish +CAMELLIA128: gcry_camellia +CAMELLIA192: gcry_camellia +CAMELLIA256: gcry_camellia +CAST5: gcry_cast5 +CRC32: gcry_crc +CRC32RFC1510: gcry_crc +CRC24RFC2440: gcry_crc +DES: gcry_des +3DES: gcry_des +DSA: gcry_dsa +IDEA: gcry_idea +MD4: gcry_md4 +MD5: gcry_md5 +RFC2268_40: gcry_rfc2268 +AES: gcry_rijndael +AES192: gcry_rijndael +AES256: gcry_rijndael +RIPEMD160: gcry_rmd160 +RSA: gcry_rsa +SEED: gcry_seed +SERPENT128: gcry_serpent +SERPENT192: gcry_serpent +SERPENT256: gcry_serpent +SHA1: gcry_sha1 +SHA224: gcry_sha256 +SHA256: gcry_sha256 +SHA512: gcry_sha512 +SHA384: gcry_sha512 +TIGER192: gcry_tiger +TIGER: gcry_tiger +TIGER2: gcry_tiger +TWOFISH: gcry_twofish +TWOFISH128: gcry_twofish +WHIRLPOOL: gcry_whirlpool diff --git a/src/grub2/grub/x86_64-efi/fdt.lst b/src/grub2/grub/x86_64-efi/fdt.lst new file mode 100644 index 0000000..e69de29 diff --git a/src/grub2/grub/x86_64-efi/fs.lst b/src/grub2/grub/x86_64-efi/fs.lst new file mode 100644 index 0000000..0acd240 --- /dev/null +++ b/src/grub2/grub/x86_64-efi/fs.lst @@ -0,0 +1,37 @@ +affs +afs +bfs +btrfs +cbfs +cpio +cpio_be +exfat +ext2 +f2fs +fat +hfs +hfsplus +iso9660 +jfs +minix +minix2 +minix2_be +minix3 +minix3_be +minix_be +newc +nilfs2 +ntfs +odc +procfs +reiserfs +romfs +sfs +squash4 +tar +udf +ufs1 +ufs1_be +ufs2 +xfs +zfs diff --git a/src/grub2/grub/x86_64-efi/moddep.lst b/src/grub2/grub/x86_64-efi/moddep.lst new file mode 100644 index 0000000..11eda45 --- /dev/null +++ b/src/grub2/grub/x86_64-efi/moddep.lst @@ -0,0 +1,270 @@ +videotest: font video gfxmenu +odc: archelp +loopback: extcmd +setkey: extcmd +macho: +gcry_des: crypto +memrw: extcmd +terminfo: extcmd +f2fs: fshelp +part_gpt: +romfs: fshelp +read: +lsefimmap: +aout: +gcry_arcfour: crypto +tftp: net priority_queue +newc: archelp +minix2_be: +elf: +videotest_checksum: font functional_test video_fb +password_pbkdf2: crypto gcry_sha512 pbkdf2 normal +gcry_seed: crypto +pcidump: extcmd +bsd: elf serial crypto gcry_md5 verifiers extcmd aout video boot cpuid relocator mmap +sfs: fshelp +reiserfs: fshelp +part_sunpc: +zstd: +gfxmenu: video_colors trig bitmap_scale gfxterm font normal video bitmap +backtrace: +jfs: +help: extcmd normal +configfile: normal +cbls: cbtable +gfxterm_menu: font functional_test procfs normal video_fb +gcry_idea: crypto +tr: extcmd +shift_test: functional_test +ohci: cs5536 usb boot +afs: fshelp +spkmodem: terminfo +usb_keyboard: keylayouts usb +xzio: crypto +syslinuxcfg: extcmd normal +search_fs_file: +wrmsr: +usbms: scsi usb +test_blockarg: extcmd normal +true: +affs: fshelp +iso9660: fshelp +smbios: extcmd +exfat: fshelp +setjmp_test: setjmp functional_test +gfxterm: font video +efinet: net +disk: +appleldr: boot +xfs: fshelp +testspeed: extcmd normal +cpio_be: archelp +functional_test: btrfs extcmd video video_fb +bswap_test: functional_test +sleep: extcmd normal +memdisk: +gcry_rijndael: crypto +mdraid09_be: diskfilter +gettext: +gcry_sha1: crypto +hfspluscomp: gzio hfsplus +cmp: +random: hexdump +offsetio: +file: elf macho extcmd offsetio +usbserial_usbdebug: serial usb usbserial_common +video_colors: +morse: +hashsum: crypto extcmd normal +usb: +halt: acpi +gfxterm_background: video_colors bitmap_scale gfxterm extcmd video bitmap +search_fs_uuid: +gcry_dsa: pgp mpi +keystatus: extcmd +linux: hiperiso verifiers video boot relocator mmap +geli: cryptodisk crypto gcry_sha512 pbkdf2 gcry_sha256 +cmdline_cat_test: font functional_test normal procfs video_fb +rdmsr: extcmd +part_sun: +cbtable: +pbkdf2_test: functional_test pbkdf2 gcry_sha1 +video_bochs: video video_fb +verifiers: +bufio: +usbserial_ftdi: serial usb usbserial_common +legacy_password_test: functional_test legacycfg +cpuid: extcmd +blscfg: extcmd normal +hdparm: extcmd hexdump +bfs: fshelp +gcry_blowfish: crypto +test: +nilfs2: fshelp +gcry_rsa: pgp mpi +cryptodisk: crypto extcmd procfs +nativedisk: +minicmd: +signature_test: functional_test procfs +ata: scsi +udf: fshelp +gzio: gcry_crc +xnu_uuid: gcry_md5 +uhci: usb +pata: ata +mul_test: functional_test +adler32: crypto +terminal: +shim_lock: verifiers +div: +ehci: cs5536 usb boot +crypto: +part_bsd: part_msdos +cs5536: +hiperiso: ext2 fshelp elf btrfs crypto font gcry_md5 exfat udf datetime div extcmd normal video gcry_sha1 mmap iso9660 +gcry_sha512: crypto +password: crypto normal +fshelp: +sleep_test: functional_test datetime +iorw: extcmd +xnu: macho bitmap_scale random verifiers extcmd boot video bitmap relocator mmap +mmap: +exfctest: functional_test +zfsinfo: zfs +ldm: part_gpt diskfilter part_msdos +eval: normal +part_dvh: +lssal: +blocklist: +ext2: fshelp +net: priority_queue bufio datetime boot +part_acorn: +videoinfo: video +btrfs: zstd lzopio raid6rec gzio +lsmmap: mmap +strtoull_test: functional_test +bitmap: +ntfs: fshelp +multiboot: net linux video boot relocator mmap +tpm: verifiers +gcry_crc: crypto +png: bufio bitmap +jpeg: bufio bitmap +macbless: disk +div_test: functional_test div +regexp: extcmd normal +parttool: normal +usbserial_pl2303: serial usb usbserial_common +cpio: archelp +gcry_rmd160: crypto +fat: fshelp +ufs1_be: +archelp: +http: net +zfs: gzio +raid6rec: diskfilter +lsefisystab: +minix2: +lsacpi: extcmd acpi +datehook: datetime normal +loadenv: disk extcmd +bitmap_scale: bitmap +probe: extcmd +minix3: +tar: archelp +loadbios: +hfs: fshelp +procfs: archelp +boot: +keylayouts: +progress: normal +kernel: +usbtest: usb +relocator: mmap +acpi: extcmd mmap +tga: bufio bitmap +reboot: +fwload: extcmd +serial: extcmd terminfo +zfscrypt: crypto pbkdf2 extcmd zfs gcry_sha1 gcry_rijndael +efi_uga: video video_fb +dm_nv: diskfilter +cmp_test: functional_test +luks: cryptodisk crypto pbkdf2 +font: bufio video +raid5rec: diskfilter +crc64: crypto +datetime: +efifwsetup: +ctz_test: functional_test +video: +cbmemc: cbtable normal terminfo +hfsplus: fshelp +gcry_cast5: crypto +extcmd: +squash4: fshelp zstd lzopio zfs xzio gzio +part_plan: +minix_be: +gcry_whirlpool: crypto +gcry_tiger: crypto +fixvideo: +search: search_fs_uuid search_fs_file extcmd search_label +lspci: extcmd +cbtime: cbtable +video_fb: +minix3_be: +trig: +msdospart: disk parttool +priority_queue: +gcry_twofish: crypto +part_dfly: +xnu_uuid_test: functional_test +diskfilter: +testload: +part_apple: +hexdump: extcmd +date: datetime normal +pbkdf2: crypto +gcry_sha256: crypto +ls: extcmd normal +usbserial_common: serial usb +ntfscomp: ntfs +mouse: +lzopio: crypto +video_cirrus: video video_fb +hello: extcmd +scsi: +linux16: linux boot video relocator mmap +cat: extcmd +ahci: ata boot +pgp: crypto verifiers extcmd mpi gcry_sha1 +normal: terminal crypto verifiers bufio extcmd boot gettext +ufs1: +mdraid09: diskfilter +lvm: diskfilter +chain: net efinet boot +cbfs: archelp +ufs2: +time: +setpci: extcmd +gptsync: disk +search_label: +setjmp: +multiboot2: linux net video boot relocator acpi mmap +gcry_rfc2268: crypto +mdraid1x: diskfilter +mpi: crypto +legacycfg: crypto password gcry_md5 normal +play: +part_amiga: +efi_gop: video video_fb +minix: +echo: extcmd +lsefi: +gcry_serpent: crypto +gcry_md4: crypto +gcry_md5: crypto +part_msdos: +gcry_camellia: crypto +at_keyboard: keylayouts boot +all_video: efi_gop efi_uga video_bochs video_cirrus diff --git a/src/grub2/grub/x86_64-efi/partmap.lst b/src/grub2/grub/x86_64-efi/partmap.lst new file mode 100644 index 0000000..761233a --- /dev/null +++ b/src/grub2/grub/x86_64-efi/partmap.lst @@ -0,0 +1,11 @@ +part_acorn +part_amiga +part_apple +part_bsd +part_dfly +part_dvh +part_gpt +part_msdos +part_plan +part_sun +part_sunpc diff --git a/src/grub2/grub/x86_64-efi/parttool.lst b/src/grub2/grub/x86_64-efi/parttool.lst new file mode 100644 index 0000000..68b4b5c --- /dev/null +++ b/src/grub2/grub/x86_64-efi/parttool.lst @@ -0,0 +1 @@ +msdos: msdospart diff --git a/src/grub2/grub/x86_64-efi/terminal.lst b/src/grub2/grub/x86_64-efi/terminal.lst new file mode 100644 index 0000000..9afb9bd --- /dev/null +++ b/src/grub2/grub/x86_64-efi/terminal.lst @@ -0,0 +1,10 @@ +iat_keyboard: at_keyboard +imouse: mouse +iserial: serial +iserial_*: serial +oaudio: morse +ocbmemc: cbmemc +ogfxterm: gfxterm +oserial: serial +oserial_*: serial +ospkmodem: spkmodem diff --git a/src/grub2/grub/x86_64-efi/video.lst b/src/grub2/grub/x86_64-efi/video.lst new file mode 100644 index 0000000..ae9ba23 --- /dev/null +++ b/src/grub2/grub/x86_64-efi/video.lst @@ -0,0 +1,4 @@ +efi_gop +efi_uga +video_bochs +video_cirrus diff --git a/src/grub2/hiperiso.c b/src/grub2/hiperiso.c new file mode 100644 index 0000000..3cb1a95 --- /dev/null +++ b/src/grub2/hiperiso.c @@ -0,0 +1,655 @@ +/****************************************************************************** + * hiperiso.c + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef GRUB_MACHINE_EFI +#include +#include +#endif +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +int g_hiperiso_debug = 0; +static int g_efi_os = 0xFF; +grub_uint32_t g_hiperiso_plat_data; + +#ifdef GRUB_MACHINE_EFI +static HISO_SHIM *g_hiso_shim = NULL; +#endif + +void hiperiso_debug(const char *fmt, ...) +{ + va_list args; + + va_start (args, fmt); + grub_vprintf (fmt, args); + va_end (args); +} + +void hiperiso_str_tolower(char *str) +{ + while (*str) + { + *str = grub_tolower(*str); + str++; + } +} + +void hiperiso_str_toupper(char *str) +{ + while (*str) + { + *str = grub_toupper(*str); + str++; + } +} + +char *hiperiso_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 hiperiso_str_all_digit(const char *str) +{ + if (NULL == str || 0 == *str) + { + return 0; + } + + while (*str) + { + if (*str < '0' || *str > '9') + { + return 0; + } + str++; + } + + return 1; +} + +int hiperiso_str_all_alnum(const char *str) +{ + if (NULL == str || 0 == *str) + { + return 0; + } + + while (*str) + { + if (!grub_isalnum(*str)) + { + return 0; + } + } + + return 1; +} + +int hiperiso_str_len_alnum(const char *str, int len) +{ + int i; + int slen; + + if (NULL == str || 0 == *str) + { + return 0; + } + + slen = grub_strlen(str); + if (slen <= len) + { + return 0; + } + + for (i = 0; i < len; i++) + { + if (!grub_isalnum(str[i])) + { + return 0; + } + } + + if (str[len] == 0 || grub_isspace(str[len])) + { + return 1; + } + + return 0; +} + +char * hiperiso_str_basename(char *path) +{ + char *pos = NULL; + + pos = grub_strrchr(path, '/'); + if (pos) + { + pos++; + } + else + { + pos = path; + } + + return pos; +} + +int hiperiso_str_chrcnt(const char *str, char c) +{ + int n = 0; + + if (str) + { + while (*str) + { + if (*str == c) + { + n++; + } + str++; + } + } + + return n; +} + +int hiperiso_strcmp(const char *pattern, const char *str) +{ + while (*pattern && *str) + { + if ((*pattern != *str) && (*pattern != '*')) + break; + + pattern++; + str++; + } + + return (int)(grub_uint8_t)*pattern - (int)(grub_uint8_t)*str; +} + +int hiperiso_strncmp (const char *pattern, const char *str, grub_size_t n) +{ + if (n == 0) + return 0; + + while (*pattern && *str && --n) + { + if ((*pattern != *str) && (*pattern != '*')) + break; + + pattern++; + str++; + } + + return (int)(grub_uint8_t)*pattern - (int)(grub_uint8_t)*str; +} + +grub_err_t hiperiso_env_int_set(const char *name, int value) +{ + char buf[16]; + + grub_snprintf(buf, sizeof(buf), "%d", value); + return grub_env_set(name, buf); +} + +void hiperiso_debug_dump_guid(const char *prefix, grub_uint8_t *guid) +{ + int i; + + if (!g_hiperiso_debug) + { + return; + } + + debug("%s", prefix); + for (i = 0; i < 16; i++) + { + grub_printf("%02x ", guid[i]); + } + grub_printf("\n"); +} + +int hiperiso_is_efi_os(void) +{ + if (g_efi_os > 1) + { + g_efi_os = (grub_strstr(GRUB_PLATFORM, "efi")) ? 1 : 0; + } + + return g_efi_os; +} + +void * hiperiso_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; +} + +void hiperiso_memfile_env_set(const char *prefix, const void *buf, unsigned long long len) +{ + char name[128]; + char val[64]; + + grub_snprintf(name, sizeof(name), "%s_addr", prefix); + grub_snprintf(val, sizeof(val), "0x%llx", (ulonglong)(ulong)buf); + grub_env_set(name, val); + + grub_snprintf(name, sizeof(name), "%s_size", prefix); + grub_snprintf(val, sizeof(val), "%llu", len); + grub_env_set(name, val); + + return; +} + +#ifdef GRUB_MACHINE_EFI +static void hiperiso_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); +} + +static void hiperiso_get_pi_version(char *str, grub_size_t len) +{ + grub_uint32_t data = 0; + grub_efi_uintn_t i = 0; + grub_efi_guid_t dxest = + { 0x05ad34ba, 0x6f02, 0x4214, {0x95, 0x2e, 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9 } }; + + for (i = 0; i < grub_efi_system_table->num_table_entries; i++) + { + if (grub_memcmp(&dxest, &grub_efi_system_table->configuration_table[i].vendor_guid, 16) == 0) + { + grub_memcpy(&data, (char *)grub_efi_system_table->configuration_table[i].vendor_table + 8, 4); + break; + } + } + + grub_snprintf(str, len, "%d.%d", (data >> 16) & 0xFFFF, (data & 0xFFFF) / 10); +} + +int hiperiso_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; + + /* HISO_SECURE_BOOT_POLICY only take affect once during init */ + env = grub_env_get("HISO_SECURE_BOOT_POLICY"); + if (env) + { + g_sb_policy = (grub_uint8_t)(env[0] - '0'); + } + + if (g_sb_policy == HISO_SB_POLICY_BYPASS) + { + if (g_hiso_shim && g_hiso_shim->ByPassSB) + { + g_hiso_shim->ByPassSB(); + } + } + else if (g_sb_policy == HISO_SB_POLICY_CHECK) + { + if (g_hiso_shim && g_hiso_shim->CheckSB) + { + g_hiso_shim->CheckSB(); + } + } + + return 0; +} + +static void hiperiso_get_uefi_sb(void) +{ + grub_uint8_t secure_boot = 0; + grub_uint8_t setup_mode = 0; + 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) + { + secure_boot = 1; + } + grub_check_free(var); + + size = 0; + var = grub_efi_get_variable("SetupMode", &global, &size); + if (var && size == 1 && *var == 1) + { + setup_mode = 1; + } + + if (secure_boot == 1 && setup_mode == 0) + { + g_sys_sb = 1; + } + + grub_check_free(var); +} + +static int hiperiso_secure_boot_init(void) +{ + grub_efi_guid_t ProtGuid = HISO_SHIM_POLICY_GUID; + + hiperiso_get_uefi_sb(); + + if (g_sys_sb == 0) + { + return 0; + } + + + /* + * When SecureBoot enabled, Hiperiso grub must be launched by Hiperiso Shim. + * Currently only x86_64 support this feature. + */ + if (g_hiperiso_plat_data == HISO_PLAT_X86_64_UEFI) + { + g_hiso_shim = grub_efi_locate_protocol(&ProtGuid, NULL); + if (g_hiso_shim == NULL || g_hiso_shim->ByPassSB == NULL || + g_hiso_shim->CheckSB == NULL || g_hiso_shim->Launched == NULL) + { + grub_cls(); + grub_printf(HISO_WARNING"\n"); + grub_printf(HISO_WARNING"\n"); + grub_printf(HISO_WARNING"\n\n\n"); + + grub_printf("Hiperiso grub is not launched by Hiperiso shim.\n\n"); + grub_refresh(); + + hiperiso_prompt_end(); + } + + g_hiso_shim->Launched(); + } + + return 0; +} + + +#endif + +static int hiperiso_arch_mode_init(void) +{ + #ifdef GRUB_MACHINE_EFI + + if (grub_strcmp(GRUB_TARGET_CPU, "i386") == 0) + { + g_hiperiso_plat_data = HISO_PLAT_I386_UEFI; + grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "ia32"); + } + else if (grub_strcmp(GRUB_TARGET_CPU, "arm64") == 0) + { + g_hiperiso_plat_data = HISO_PLAT_ARM64_UEFI; + grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "aa64"); + } + else if (grub_strcmp(GRUB_TARGET_CPU, "mips64el") == 0) + { + g_hiperiso_plat_data = HISO_PLAT_MIPS_UEFI; + grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "mips"); + } + else + { + g_hiperiso_plat_data = HISO_PLAT_X86_64_UEFI; + grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "uefi"); + } +#else + g_hiperiso_plat_data = HISO_PLAT_X86_LEGACY; + grub_snprintf(g_arch_mode_suffix, sizeof(g_arch_mode_suffix), "%s", "legacy"); +#endif + + return 0; +} + +static int hiperiso_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; + + (void)addr; + (void)type; + + *total_mem += size; + + return 0; +} + +static int hiperiso_hwinfo_init(void) +{ + char str[256]; + grub_uint64_t total_mem = 0; + + grub_machine_mmap_iterate(hiperiso_calc_totalmem, &total_mem); + + grub_snprintf(str, sizeof(str), "%ld", (long)(total_mem / HISO_SIZE_1MB)); + hiperiso_env_export("grub_total_ram", str); + +#ifdef GRUB_MACHINE_EFI + hiperiso_get_uefi_version(str, sizeof(str)); + hiperiso_env_export("grub_uefi_version", str); + + hiperiso_get_pi_version(str, sizeof(str)); + hiperiso_env_export("grub_pi_version", str); +#else + hiperiso_env_export("grub_uefi_version", "NA"); + hiperiso_env_export("grub_pi_version", "NA"); +#endif + + return 0; +} + +static global_var_cfg g_global_vars[] = +{ + { "gfxmode", "1024x768", NULL }, + { hiperiso_left_key, "5%", NULL }, + { hiperiso_top_key, "95%", NULL }, + { hiperiso_color_key, "#0000ff", NULL }, + { NULL, NULL, NULL } +}; + +static const char * hiperiso_global_var_read_hook(struct grub_env_var *var, const char *val) +{ + int i; + + for (i = 0; g_global_vars[i].name; i++) + { + if (grub_strcmp(g_global_vars[i].name, var->name) == 0) + { + return g_global_vars[i].value; + } + } + + return val; +} + +static char * hiperiso_global_var_write_hook(struct grub_env_var *var, const char *val) +{ + int i; + + for (i = 0; g_global_vars[i].name; i++) + { + if (grub_strcmp(g_global_vars[i].name, var->name) == 0) + { + grub_check_free(g_global_vars[i].value); + g_global_vars[i].value = grub_strdup(val); + break; + } + } + + return grub_strdup(val); +} + +int hiperiso_global_var_init(void) +{ + int i; + + for (i = 0; g_global_vars[i].name; i++) + { + g_global_vars[i].value = grub_strdup(g_global_vars[i].defval); + hiperiso_env_export(g_global_vars[i].name, g_global_vars[i].defval); + grub_register_variable_hook(g_global_vars[i].name, hiperiso_global_var_read_hook, hiperiso_global_var_write_hook); + } + + return 0; +} + +static ctrl_var_cfg g_ctrl_vars[] = +{ + { "HISO_WIN11_BYPASS_CHECK", "1" }, + { "HISO_WIN11_BYPASS_NRO", "1" }, + { "HISO_LINUX_REMOUNT", "0" }, + { "HISO_SECONDARY_BOOT_MENU", "1" }, + { "HISO_WIN_UEFI_RES_LOCK", "3" }, + { NULL, "" } +}; + +static const char * hiperiso_ctrl_var_read_hook(struct grub_env_var *var, const char *val) +{ + int i; + + for (i = 0; g_ctrl_vars[i].name; i++) + { + if (grub_strcmp(g_ctrl_vars[i].name, var->name) == 0) + { + return g_ctrl_vars[i].szval; + } + } + + return val; +} + +static char * hiperiso_ctrl_var_write_hook(struct grub_env_var *var, const char *val) +{ + int i; + + for (i = 0; g_ctrl_vars[i].name; i++) + { + if (grub_strcmp(g_ctrl_vars[i].name, var->name) == 0) + { + if (val && grub_isdigit(val[0]) && val[1] == 0) + { + g_ctrl_vars[i].szval[0] = val[0]; + return grub_strdup(val); + } + else + { + g_ctrl_vars[i].szval[0] = '0'; + return grub_strdup("0"); + } + } + } + + return grub_strdup(val); +} + +int hiperiso_ctrl_var_init(void) +{ + ctrl_var_cfg *cfg = g_ctrl_vars; + + while (cfg->name) + { + hiperiso_env_export(cfg->name, cfg->szval); + grub_register_variable_hook(cfg->name, hiperiso_ctrl_var_read_hook, hiperiso_ctrl_var_write_hook); + cfg++; + } + + return 0; +} + +GRUB_MOD_INIT(hiperiso) +{ + hiperiso_hwinfo_init(); + hiperiso_env_init(); + hiperiso_arch_mode_init(); + +#ifdef GRUB_MACHINE_EFI + hiperiso_secure_boot_init(); +#endif + + hiperiso_register_all_cmd(); +} + +GRUB_MOD_FINI(hiperiso) +{ + hiperiso_unregister_all_cmd(); +} + diff --git a/src/grub2/hiperiso.h b/src/grub2/hiperiso.h new file mode 100644 index 0000000..515169b --- /dev/null +++ b/src/grub2/hiperiso.h @@ -0,0 +1,331 @@ +/****************************************************************************** + * hiperiso.h + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ + +#ifndef __HIPERISO_H__ +#define __HIPERISO_H__ + +#define COMPILE_ASSERT(a, expr) extern char __compile_assert##a[(expr) ? 1 : -1] + +#define HIPERISO_COMPATIBLE_STR "HIPERISO COMPATIBLE" +#define HIPERISO_COMPATIBLE_STR_LEN 17 + +#define HIPERISO_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }} + +typedef enum hiperiso_fs_type +{ + hiperiso_fs_exfat = 0, /* 0: exfat */ + hiperiso_fs_ntfs, /* 1: NTFS */ + hiperiso_fs_ext, /* 2: ext2/ext3/ext4 */ + hiperiso_fs_xfs, /* 3: XFS */ + hiperiso_fs_udf, /* 4: UDF */ + hiperiso_fs_fat, /* 5: FAT */ + hiperiso_fs_btrfs, /* 6: BTRFS */ + + hiperiso_fs_max +}hiperiso_fs_type; + +typedef enum hiperiso_chain_type +{ + hiperiso_chain_linux = 0, /* 0: linux */ + hiperiso_chain_windows, /* 1: windows */ + hiperiso_chain_wim, /* 2: wim */ + + hiperiso_chain_max +}hiperiso_chain_type; + +#pragma pack(1) + +typedef struct hiperiso_guid +{ + grub_uint32_t data1; + grub_uint16_t data2; + grub_uint16_t data3; + grub_uint8_t data4[8]; +}hiperiso_guid; + + +typedef struct hiperiso_image_disk_region +{ + grub_uint32_t image_sector_count; /* image sectors contained in this region (in 2048) */ + grub_uint32_t image_start_sector; /* image sector start (in 2048) */ + grub_uint64_t disk_start_sector; /* disk sector start (in 512) */ +}hiperiso_image_disk_region; + +typedef struct hiperiso_image_location +{ + hiperiso_guid guid; + + /* image sector size, 2048/512 */ + grub_uint32_t image_sector_size; + + /* disk sector size, normally the value is 512 */ + grub_uint32_t disk_sector_size; + + grub_uint32_t region_count; + + /* + * disk region data (region_count) + * If the image file has more than one fragments in disk, + * there will be more than one region data here. + * + */ + hiperiso_image_disk_region regions[1]; + + /* hiperiso_image_disk_region regions[2~region_count-1] */ +}hiperiso_image_location; + + +typedef struct hiperiso_os_param +{ + hiperiso_guid guid; // HIPERISO_GUID + grub_uint8_t chksum; // checksum + + grub_uint8_t hiso_disk_guid[16]; + grub_uint64_t hiso_disk_size; // disk size in bytes + grub_uint16_t hiso_disk_part_id; // begin with 1 + grub_uint16_t hiso_disk_part_type; // 0:exfat 1:ntfs other: reserved + char hiso_img_path[384]; // It seems to be enough, utf-8 format + grub_uint64_t hiso_img_size; // image file size in bytes + + /* + * Hiperiso will write a copy of hiperiso_image_location data into runtime memory + * this is the physically address and length of that memory. + * Address 0 means no such data exist. + * Address will be aligned by 4KB. + * + */ + grub_uint64_t hiso_img_location_addr; + grub_uint32_t hiso_img_location_len; + + /* + * These 32 bytes are reserved by hiperiso. + * + * hiso_reserved[0]: hiso_break_level + * hiso_reserved[1]: hiso_debug_level + * hiso_reserved[2]: hiso_chain_type 0:Linux 1:Windows 2:wimfile + * hiso_reserved[3]: hiso_iso_format 0:iso9660 1:udf + * hiso_reserved[4]: hiso_windows_cd_prompt + * hiso_reserved[5]: hiso_linux_remount + * hiso_reserved[6]: hiso_vlnk + * hiso_reserved[7~10]: hiso_disk_sig[4] used for vlnk + * hiso_reserved[11]: hiso_win_uefi_max_res + * + */ + grub_uint8_t hiso_reserved[32]; // Internal use by hiperiso + + grub_uint8_t hiso_disk_signature[4]; + + grub_uint8_t reserved[27]; +}hiperiso_os_param; + + +typedef struct hiperiso_windows_data +{ + char auto_install_script[384]; + char injection_archive[384]; + grub_uint8_t windows11_bypass_check; + + grub_uint32_t auto_install_len; + + grub_uint8_t windows11_bypass_nro; + + grub_uint8_t reserved[255 - 5]; + + /* auto_intall file buf */ + /* ...... + auto_install_len */ +}hiperiso_windows_data; + + +typedef struct hiperiso_secure_data +{ + grub_uint8_t magic1[16]; /* HIPERISO_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]; /* HIPERISO_GUID */ +}hiperiso_secure_data; + + +typedef struct hiperiso_vlnk +{ + hiperiso_guid guid; // HIPERISO_GUID + grub_uint32_t crc32; // crc32 + grub_uint32_t disk_signature; + grub_uint64_t part_offset; // in bytes + char filepath[384]; + grub_uint8_t reserved[96]; +}hiperiso_vlnk; + +#pragma pack() + +// compile assert check : sizeof(hiperiso_os_param) must be 512 +COMPILE_ASSERT(1,sizeof(hiperiso_os_param) == 512); +COMPILE_ASSERT(2,sizeof(hiperiso_secure_data) == 4096); +COMPILE_ASSERT(3,sizeof(hiperiso_vlnk) == 512); + + + + + + + +#pragma pack(4) + +typedef struct hiperiso_chain_head +{ + hiperiso_os_param os_param; + + grub_uint32_t disk_drive; + grub_uint32_t drive_map; + grub_uint32_t disk_sector_size; + + grub_uint64_t real_img_size_in_bytes; + grub_uint64_t virt_img_size_in_bytes; + grub_uint32_t boot_catalog; + grub_uint8_t boot_catalog_sector[2048]; + + grub_uint32_t img_chunk_offset; + grub_uint32_t img_chunk_num; + + grub_uint32_t override_chunk_offset; + grub_uint32_t override_chunk_num; + + grub_uint32_t virt_chunk_offset; + grub_uint32_t virt_chunk_num; +}hiperiso_chain_head; + +typedef struct hiperiso_image_desc +{ + grub_uint64_t disk_size; + grub_uint64_t part1_size; + grub_uint8_t disk_uuid[16]; + grub_uint8_t disk_signature[4]; + grub_uint32_t img_chunk_count; + /* hiperiso_img_chunk list */ +}hiperiso_image_desc; + + + +typedef struct hiperiso_img_chunk +{ + grub_uint32_t img_start_sector; // sector size: 2KB + grub_uint32_t img_end_sector; // included + + grub_uint64_t disk_start_sector; // in disk_sector_size + grub_uint64_t disk_end_sector; // included +}hiperiso_img_chunk; + + +typedef struct hiperiso_override_chunk +{ + grub_uint64_t img_offset; + grub_uint32_t override_size; + grub_uint8_t override_data[512]; +}hiperiso_override_chunk; + +typedef struct hiperiso_virt_chunk +{ + grub_uint32_t mem_sector_start; + grub_uint32_t mem_sector_end; + grub_uint32_t mem_sector_offset; + grub_uint32_t remap_sector_start; + grub_uint32_t remap_sector_end; + grub_uint32_t org_sector_start; +}hiperiso_virt_chunk; + +#define DEFAULT_CHUNK_NUM 1024 +typedef struct hiperiso_img_chunk_list +{ + char *buf; + grub_uint32_t last_off; + grub_uint32_t err_code; + + grub_uint32_t max_chunk; + grub_uint32_t cur_chunk; + hiperiso_img_chunk *chunk; +}hiperiso_img_chunk_list; + +#pragma pack() + +#define hiperiso_filt_register grub_file_filter_register + +#pragma pack(1) + +#define HISO_MAX_CONF_REPLACE 2 +#define GRUB_FILE_REPLACE_MAGIC 0x1258BEEF +#define GRUB_IMG_REPLACE_MAGIC 0x1259BEEF + +typedef const char * (*grub_env_get_pf)(const char *name); +typedef int (*grub_env_set_pf)(const char *name, const char *val); +typedef int (*grub_env_printf_pf)(const char *fmt, ...); + +typedef struct hiperiso_grub_param_file_replace +{ + grub_uint32_t magic; + char old_file_name[4][256]; + grub_uint32_t old_name_cnt; + grub_uint32_t new_file_virtual_id; +}hiperiso_grub_param_file_replace; + +typedef struct hiperiso_grub_param +{ + grub_env_get_pf grub_env_get; + grub_env_set_pf grub_env_set; + hiperiso_grub_param_file_replace file_replace; + hiperiso_grub_param_file_replace img_replace[HISO_MAX_CONF_REPLACE]; + grub_env_printf_pf grub_env_printf; +}hiperiso_grub_param; + +#pragma pack() + +#define HISO_CHUNK_BUF_SIZE (4 * 1024 * 1024) + +typedef enum hiso_chunk_err +{ + HISO_CHUNK_ERR_NONE = 0, + HISO_CHUNK_ERR_MULTI_DEV, + HISO_CHUNK_ERR_RAID, + HISO_CHUNK_ERR_COMPRESS, + HISO_CHUNK_ERR_NOT_FLAT, + HISO_CHUNK_ERR_OVER_FLOW, + HISO_CHUNK_ERR_MAX +}hiso_chunk_err; + +int grub_ext_get_file_chunk(grub_uint64_t part_start, grub_file_t file, hiperiso_img_chunk_list *chunk_list); +int grub_btrfs_get_file_chunk(grub_uint64_t part_start, grub_file_t file, hiperiso_img_chunk_list *chunk_list); +int grub_fat_get_file_chunk(grub_uint64_t part_start, grub_file_t file, hiperiso_img_chunk_list *chunk_list); +void grub_iso9660_set_nojoliet(int nojoliet); +int grub_iso9660_is_joliet(void); +grub_uint64_t grub_iso9660_get_last_read_pos(grub_file_t file); +grub_uint64_t grub_iso9660_get_last_file_dirent_pos(grub_file_t file); +grub_uint64_t grub_udf_get_file_offset(grub_file_t file); +grub_uint64_t grub_udf_get_last_pd_size_offset(void); +grub_uint64_t grub_udf_get_last_file_attr_offset +( + grub_file_t file, + grub_uint32_t *startBlock, + grub_uint64_t *fe_entry_size_offset +); +int hiperiso_is_efi_os(void); +void hiperiso_memfile_env_set(const char *prefix, const void *buf, unsigned long long len); + +#endif /* __HIPERISO_H__ */ + diff --git a/src/grub2/hiperiso_browser.c b/src/grub2/hiperiso_browser.c new file mode 100644 index 0000000..a56fa1d --- /dev/null +++ b/src/grub2/hiperiso_browser.c @@ -0,0 +1,652 @@ +/****************************************************************************** + * hiperiso_browser.c + * + * Copyright (c) 2022, longpanda + * + * 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 . + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +#define BROWSER_MENU_BUF 65536 + +static const char *g_hiso_dev = NULL; +static grub_fs_t g_menu_fs = NULL; +static char *g_menu_device = NULL; +static grub_device_t g_menu_dev = NULL; +static char g_menu_path_buf[1024]; +static int g_menu_path_len = 0; +static browser_node *g_browser_list = NULL; + +static int hiperiso_browser_strcmp(char *str1, char *str2) +{ + char *s1, *s2; + int c1 = 0; + int c2 = 0; + + for (s1 = str1, s2 = str2; *s1 && *s2; s1++, s2++) + { + c1 = *s1; + c2 = *s2; + + if (0 == g_sort_case_sensitive) + { + if (grub_islower(c1)) + { + c1 = c1 - 'a' + 'A'; + } + + if (grub_islower(c2)) + { + c2 = c2 - 'a' + 'A'; + } + } + + if (c1 != c2) + { + break; + } + } + + return (c1 - c2); +} + +static int hiperiso_browser_mbuf_alloc(browser_mbuf *mbuf) +{ + grub_memset(mbuf, 0, sizeof(browser_mbuf)); + mbuf->buf = grub_malloc(BROWSER_MENU_BUF); + if (!mbuf->buf) + { + return 0; + } + + mbuf->pos = 0; + mbuf->max = BROWSER_MENU_BUF; + return 1; +} + +static inline void hiperiso_browser_mbuf_free(browser_mbuf *mbuf) +{ + if (mbuf) + grub_check_free(mbuf->buf) +} + +static inline int hiperiso_browser_mbuf_extend(browser_mbuf *mbuf) +{ + if (mbuf->max - mbuf->pos <= HISO_SIZE_1KB) + { + mbuf->max += BROWSER_MENU_BUF; + mbuf->buf = grub_realloc(mbuf->buf, mbuf->max); + } + + return 0; +} + +static browser_node * hiperiso_browser_find_top_node(int dir) +{ + browser_node *node = NULL; + browser_node *sel = NULL; + + for (node = g_browser_list; node; node = node->next) + { + if (node->dir == dir) + { + if (sel) + { + if (hiperiso_browser_strcmp(sel->filename, node->filename) > 0) + { + sel = node; + } + } + else + { + sel = node; + } + } + } + + return sel; +} + +static int hiperiso_browser_iterate_partition(struct grub_disk *disk, const grub_partition_t partition, void *data) +{ + char partname[64]; + char title[256]; + grub_device_t dev; + grub_fs_t fs; + char *Label = NULL; + browser_mbuf *mbuf = (browser_mbuf *)data; + + (void)data; + + if (partition->number == 1 && g_hiso_dev && grub_strcmp(disk->name, g_hiso_dev) == 0) + { + return 0; + } + + grub_snprintf(partname, sizeof(partname) - 1, "%s,%d", disk->name, partition->number + 1); + + dev = grub_device_open(partname); + if (!dev) + { + return 0; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + grub_device_close(dev); + return 0; + } + + fs->fs_label(dev, &Label); + + if (hiperiso_check_file_exist("(%s)/.hiperisoignore", partname)) + { + return 0; + } + + if (g_tree_view_menu_style == 0) + { + grub_snprintf(title, sizeof(title), "%-10s (%s,%s%d) [%s] %s %s", + "DISK", disk->name, partition->msdostype == 0xee ? "gpt" : "msdos", + partition->number + 1, (Label ? Label : ""), fs->name, + grub_get_human_size(partition->len << disk->log_sector_size, GRUB_HUMAN_SIZE_SHORT)); + } + else + { + grub_snprintf(title, sizeof(title), "(%s,%s%d) [%s] %s %s", + disk->name, partition->msdostype == 0xee ? "gpt" : "msdos", + partition->number + 1, (Label ? Label : ""), fs->name, + grub_get_human_size(partition->len << disk->log_sector_size, GRUB_HUMAN_SIZE_SHORT)); + } + + if (hiperiso_get_fs_type(fs->name) >= hiperiso_fs_max) + { + browser_ssprintf(mbuf, "menuentry \"%s\" --class=hisodisk {\n" + " echo \"unsupported file system type!\" \n" + " hiperiso_pause\n" + "}\n", + title); + } + else + { + browser_ssprintf(mbuf, "menuentry \"%s\" --class=hisodisk {\n" + " vt_browser_dir %s,%d 0x%lx /\n" + "}\n", + title, disk->name, partition->number + 1, (ulong)fs); + } + + hiperiso_browser_mbuf_extend(mbuf); + + return 0; +} + +static int hiperiso_browser_iterate_disk(const char *name, void *data) +{ + grub_disk_t disk; + + if (name[0] != 'h') + { + return 0; + } + + disk = grub_disk_open(name); + if (disk) + { + grub_partition_iterate(disk, hiperiso_browser_iterate_partition, data); + grub_disk_close(disk); + } + + return 0; +} + +static int hiperiso_browser_valid_dirname(const char *name, int len) +{ + if ((len == 1 && name[0] == '.') || + (len == 2 && name[0] == '.' && name[1] == '.')) + { + return 0; + } + + if (!hiperiso_img_name_valid(name, len)) + { + return 0; + } + + if (g_filt_trash_dir) + { + if (0 == grub_strncmp(name, ".trash-", 7) || + 0 == grub_strcmp(name, ".Trashes")) + { + return 0; + } + } + + if (name[0] == '$') + { + if (0 == grub_strncmp(name, "$RECYCLE.BIN", 12) || + 0 == grub_strncasecmp(name, "$Extend", 7)) + { + return 0; + } + } + + if (len == 25 && grub_strncmp(name, "System Volume Information", 25) == 0) + { + return 0; + } + + return 1; +} + +static int hiperiso_browser_valid_filename(const char *filename, int len, int *type) +{ + if (len < 4) + { + return 0; + } + + if (FILE_FLT(ISO) && 0 == grub_strcasecmp(filename + len - 4, ".iso")) + { + *type = img_type_iso; + } + else if (FILE_FLT(WIM) && g_wimboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".wim"))) + { + *type = img_type_wim; + } + else if (FILE_FLT(VHD) && g_vhdboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".vhd") || + (len >= 5 && 0 == grub_strcasecmp(filename + len - 5, ".vhdx")))) + { + *type = img_type_vhd; + } + #ifdef GRUB_MACHINE_EFI + else if (FILE_FLT(EFI) && 0 == grub_strcasecmp(filename + len - 4, ".efi")) + { + *type = img_type_efi; + } + #endif + else if (FILE_FLT(IMG) && 0 == grub_strcasecmp(filename + len - 4, ".img")) + { + if (len == 18 && grub_strncmp(filename, "hiperiso_", 7) == 0) + { + if (grub_strncmp(filename + 7, "wimboot", 7) == 0 || + grub_strncmp(filename + 7, "vhdboot", 7) == 0) + { + return 0; + } + } + *type = img_type_img; + } + else if (FILE_FLT(HISO) && len >= 5 && 0 == grub_strcasecmp(filename + len - 5, ".hiso")) + { + *type = img_type_hiso; + } + else + { + return 0; + } + + if (g_filt_dot_underscore_file && filename[0] == '.' && filename[1] == '_') + { + return 0; + } + + return 1; +} + +static int hiperiso_browser_check_ignore(const char *device, const char *root, const char *dir) +{ + grub_file_t file; + char fullpath[1024] = {0}; + + grub_snprintf(fullpath, 1023, "(%s)%s/%s/.hiperisoignore", device, root, dir); + file = grub_file_open(fullpath, GRUB_FILE_TYPE_NONE); + if (!file) + { + grub_errno = 0; + return 0; + } + else + { + grub_file_close(file); + return 1; + } +} + +static int hiperiso_browser_iterate_dir(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + int type; + int len; + browser_node *node; + + (void)data; + + len = grub_strlen(filename); + + if (info->dir) + { + if (!hiperiso_browser_valid_dirname(filename, len)) + { + return 0; + } + + if (hiperiso_browser_check_ignore(g_menu_device, g_menu_path_buf, filename)) + { + return 0; + } + + node = grub_zalloc(sizeof(browser_node)); + if (!node) + { + return 0; + } + + node->dir = 1; + grub_strncpy(node->filename, filename, sizeof(node->filename)); + + if (g_tree_view_menu_style == 0) + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"%-10s [%s]\" --class=hisodir {\n" + " vt_browser_dir %s 0x%lx \"%s/%s\"\n" + "}\n", + "DIR", filename, g_menu_device, (ulong)g_menu_fs, g_menu_path_buf, filename); + } + else + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"[%s]\" --class=hisodir {\n" + " vt_browser_dir %s 0x%lx \"%s/%s\"\n" + "}\n", + filename, g_menu_device, (ulong)g_menu_fs, g_menu_path_buf, filename); + } + } + else + { + grub_uint64_t fsize = info->size; + + if (!hiperiso_browser_valid_filename(filename, len, &type)) + { + return 0; + } + + if (grub_file_is_vlnk_suffix(filename, len)) + { + return 0; + } + + node = grub_zalloc(sizeof(browser_node)); + if (!node) + { + return 0; + } + + if (fsize == 0) + { + struct grub_file file; + + grub_memset(&file, 0, sizeof(file)); + file.device = g_menu_dev; + grub_snprintf(node->menuentry, sizeof(node->menuentry), "%s/%s", g_menu_path_buf, filename); + if (g_menu_fs->fs_open(&file, node->menuentry) == GRUB_ERR_NONE) + { + fsize = file.size; + g_menu_fs->fs_close(&file); + } + } + + node->dir = 0; + grub_strncpy(node->filename, filename, sizeof(node->filename)); + + if (g_tree_view_menu_style == 0) + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"%-10s %s\" --class=%s {\n" + " vt_set_fake_vlnk \"(%s)%s/%s\" %s %llu\n" + " %s_common_menuentry\n" + " vt_reset_fake_vlnk\n" + "}\n", + grub_get_human_size(fsize, GRUB_HUMAN_SIZE_SHORT), filename, g_menu_class[type], + g_menu_device, g_menu_path_buf, filename, g_menu_prefix[type], (ulonglong)fsize, + g_menu_prefix[type]); + } + else + { + grub_snprintf(node->menuentry, sizeof(node->menuentry), + "menuentry \"%s\" --class=%s {\n" + " vt_set_fake_vlnk \"(%s)%s/%s\" %s %llu\n" + " %s_common_menuentry\n" + " vt_reset_fake_vlnk\n" + "}\n", + filename, g_menu_class[type], + g_menu_device, g_menu_path_buf, filename, g_menu_prefix[type], (ulonglong)fsize, + g_menu_prefix[type]); + } + } + + node->prev = NULL; + node->next = g_browser_list; + if (g_browser_list) + { + g_browser_list->prev = node; + } + g_browser_list = node; + + return 0; +} + +static grub_err_t hiperiso_browser_iso_part(void) +{ + char cfgfile[64]; + char *buffer = NULL; + int pos = 0; + int buflen = 0; + int cfglen = 0; + + cfglen = g_tree_script_pos - g_tree_script_pre; + buflen = cfglen + 512; + buffer = grub_malloc(buflen); + if (!buffer) + { + return 1; + } + + if (g_tree_view_menu_style == 0) + { + pos = grub_snprintf(buffer, buflen, "menuentry \"%-10s [../]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n}\n", "<--"); + } + else + { + pos = grub_snprintf(buffer, buflen, "menuentry \"[../]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n}\n"); + } + + grub_memcpy(buffer + pos, g_tree_script_buf + g_tree_script_pre, cfglen); + pos += cfglen; + + grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%lx:size:%d", (ulong)buffer, pos); + grub_script_execute_sourcecode(cfgfile); + + grub_free(buffer); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + grub_fs_t fs; + grub_device_t dev; + char cfgfile[64]; + browser_node *node; + browser_mbuf mbuf; + + (void)ctxt; + (void)argc; + + if (args[2][0] == '/' && args[2][1] == 0) + { + grub_snprintf(cfgfile, sizeof(cfgfile), "(%s)", args[0]); + if (grub_strcmp(cfgfile, g_iso_path) == 0) + { + return hiperiso_browser_iso_part(); + } + } + + if (!hiperiso_browser_mbuf_alloc(&mbuf)) + { + return 1; + } + + fs = (grub_fs_t)grub_strtoul(args[1], NULL, 16); + if (!fs) + { + debug("Invalid fs %s\n", args[1]); + return 1; + } + + dev = grub_device_open(args[0]); + if (!dev) + { + debug("Failed to open device %s\n", args[0]); + return 1; + } + + g_menu_fs = fs; + g_menu_device = args[0]; + g_menu_dev = dev; + g_browser_list = NULL; + + if (args[2][0] == '/' && args[2][1] == 0) + { + g_menu_path_len = 0; + g_menu_path_buf[0] = 0; + fs->fs_dir(dev, "/", hiperiso_browser_iterate_dir, NULL); + } + else + { + g_menu_path_len = grub_snprintf(g_menu_path_buf, sizeof(g_menu_path_buf), "%s", args[2]); + fs->fs_dir(dev, g_menu_path_buf, hiperiso_browser_iterate_dir, NULL); + } + grub_device_close(dev); + + if (g_tree_view_menu_style == 0) + { + browser_ssprintf(&mbuf, "menuentry \"%-10s [(%s)%s/..]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n}\n", "<--", args[0], g_menu_path_buf); + } + else + { + browser_ssprintf(&mbuf, "menuentry \"[(%s)%s/..]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n}\n", args[0], g_menu_path_buf); + } + + for (i = 1; i >= 0; i--) + { + while (1) + { + node = hiperiso_browser_find_top_node(i); + if (node) + { + browser_ssprintf(&mbuf, "%s", node->menuentry); + hiperiso_browser_mbuf_extend(&mbuf); + + if (node->prev) + { + node->prev->next = node->next; + } + if (node->next) + { + node->next->prev = node->prev; + } + + if (node == g_browser_list) + { + g_browser_list = node->next; + } + grub_free(node); + } + else + { + break; + } + } + } + g_browser_list = NULL; + + grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%lx:size:%d", (ulong)mbuf.buf, mbuf.pos); + grub_script_execute_sourcecode(cfgfile); + + hiperiso_browser_mbuf_free(&mbuf); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_browser_disk(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char cfgfile[64]; + browser_mbuf mbuf; + + (void)ctxt; + (void)argc; + (void)args; + + if (!hiperiso_browser_mbuf_alloc(&mbuf)) + { + return 1; + } + + g_hiso_dev = grub_env_get("hisodev"); + + if (g_tree_view_menu_style == 0) + { + browser_ssprintf(&mbuf, "menuentry \"%-10s [%s]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n}\n", "<--", + hiperiso_get_vmenu_title("VTLANG_BROWER_RETURN")); + } + else + { + browser_ssprintf(&mbuf, "menuentry \"[%s]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n}\n", + hiperiso_get_vmenu_title("VTLANG_BROWER_RETURN")); + } + + grub_disk_dev_iterate(hiperiso_browser_iterate_disk, &mbuf); + + grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%lx:size:%d", (ulong)mbuf.buf, mbuf.pos); + grub_script_execute_sourcecode(cfgfile); + + hiperiso_browser_mbuf_free(&mbuf); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + diff --git a/src/grub2/hiperiso_cmd.c b/src/grub2/hiperiso_cmd.c new file mode 100644 index 0000000..b787655 --- /dev/null +++ b/src/grub2/hiperiso_cmd.c @@ -0,0 +1,7335 @@ +/****************************************************************************** + * hiperiso_cmd.c + * + * Copyright (c) 2021, longpanda + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef GRUB_MACHINE_EFI +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" +#include "miniz.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_uint8_t g_check_mbr_data[] = { + 0xEB, 0x63, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x56, 0x54, 0x00, 0x47, 0x65, 0x00, 0x48, 0x44, 0x00, 0x52, 0x64, 0x00, 0x20, 0x45, 0x72, 0x0D, +}; + +initrd_info *g_initrd_img_list = NULL; +initrd_info *g_initrd_img_tail = NULL; +int g_initrd_img_count = 0; +int g_valid_initrd_count = 0; +int g_default_menu_mode = 0; +int g_filt_dot_underscore_file = 0; +int g_filt_trash_dir = 1; +int g_sort_case_sensitive = 0; +int g_tree_view_menu_style = 0; +static grub_file_t g_old_file; +static int g_hiperiso_last_entry_back; + +char g_iso_path[256]; +char g_img_swap_tmp_buf[1024]; +img_info g_img_swap_tmp; +img_info *g_hiperiso_img_list = NULL; + +int g_hiperiso_img_count = 0; + +grub_device_t g_enum_dev = NULL; +grub_fs_t g_enum_fs = NULL; +int g_img_max_search_level = -1; +img_iterator_node g_img_iterator_head; +img_iterator_node *g_img_iterator_tail = NULL; + +grub_uint8_t g_hiperiso_break_level = 0; +grub_uint8_t g_hiperiso_debug_level = 0; +grub_uint8_t g_hiperiso_chain_type = 0; + +grub_uint8_t *g_hiperiso_cpio_buf = NULL; +grub_uint32_t g_hiperiso_cpio_size = 0; +cpio_newc_header *g_hiperiso_initrd_head = NULL; +grub_uint8_t *g_hiperiso_runtime_buf = NULL; + +int g_plugin_image_list = 0; + +hiperiso_grub_param *g_grub_param = NULL; + +hiperiso_guid g_hiperiso_guid = HIPERISO_GUID; + +hiperiso_img_chunk_list g_img_chunk_list; + +int g_wimboot_enable = 0; +hiperiso_img_chunk_list g_wimiso_chunk_list; +char *g_wimiso_path = NULL; +grub_uint32_t g_wimiso_size = 0; + +int g_vhdboot_enable = 0; + +grub_uint64_t g_svd_replace_offset = 0; + +int g_conf_replace_count = 0; +grub_uint64_t g_conf_replace_offset[HISO_MAX_CONF_REPLACE] = { 0 }; +conf_replace *g_conf_replace_node[HISO_MAX_CONF_REPLACE] = { NULL }; +grub_uint8_t *g_conf_replace_new_buf[HISO_MAX_CONF_REPLACE] = { NULL }; +int g_conf_replace_new_len[HISO_MAX_CONF_REPLACE] = { 0 }; +int g_conf_replace_new_len_align[HISO_MAX_CONF_REPLACE] = { 0 }; + +int g_hiperiso_disk_bios_id = 0; +hiperiso_gpt_info *g_hiperiso_part_info = NULL; +grub_uint64_t g_hiperiso_disk_size = 0; +grub_uint64_t g_hiperiso_disk_part_size[2]; + +char *g_tree_script_buf = NULL; +int g_tree_script_pos = 0; +int g_tree_script_pre = 0; + +static char *g_list_script_buf = NULL; +static int g_list_script_pos = 0; + +static char *g_part_list_buf = NULL; +static int g_part_list_pos = 0; +static grub_uint64_t g_part_end_max = 0; + +static int g_video_mode_max = 0; +static int g_video_mode_num = 0; +static hiperiso_video_mode *g_video_mode_list = NULL; + +static int g_enumerate_time_checked = 0; +static grub_uint64_t g_enumerate_start_time_ms; +static grub_uint64_t g_enumerate_finish_time_ms; +int g_hiso_file_flt[HISO_FILE_FLT_BUTT] = {0}; + +static char g_iso_vd_id_publisher[130]; +static char g_iso_vd_id_prepare[130]; +static char g_iso_vd_id_application[130]; + +static int g_pager_flag = 0; +static char g_old_pager[32]; + +const char *g_menu_class[img_type_max] = +{ + "hisoiso", "hisowim", "hisoefi", "hisoimg", "hisovhd", "hisohiso" +}; + +const char *g_menu_prefix[img_type_max] = +{ + "iso", "wim", "efi", "img", "vhd", "hiso" +}; + +static const char *g_lower_chksum_name[HISO_CHKSUM_NUM] = { "md5", "sha1", "sha256", "sha512" }; +static int g_lower_chksum_namelen[HISO_CHKSUM_NUM] = { 3, 4, 6, 6 }; +static int g_chksum_retlen[HISO_CHKSUM_NUM] = { 32, 40, 64, 128 }; + +static int g_hiso_secondary_need_recover = 0; + +static int g_hiso_load_prompt = 0; +static char g_hiso_prompt_msg[64]; + +static char g_json_case_mis_path[32]; + +static hiperiso_vlnk_part *g_vlnk_part_list = NULL; + +int hiperiso_get_fs_type(const char *fs) +{ + if (NULL == fs) + { + return hiperiso_fs_max; + } + else if (grub_strncmp(fs, "exfat", 5) == 0) + { + return hiperiso_fs_exfat; + } + else if (grub_strncmp(fs, "ntfs", 4) == 0) + { + return hiperiso_fs_ntfs; + } + else if (grub_strncmp(fs, "ext", 3) == 0) + { + return hiperiso_fs_ext; + } + else if (grub_strncmp(fs, "xfs", 3) == 0) + { + return hiperiso_fs_xfs; + } + else if (grub_strncmp(fs, "udf", 3) == 0) + { + return hiperiso_fs_udf; + } + else if (grub_strncmp(fs, "fat", 3) == 0) + { + return hiperiso_fs_fat; + } + else if (grub_strncmp(fs, "btrfs", 5) == 0) + { + return hiperiso_fs_btrfs; + } + + return hiperiso_fs_max; +} + +static int hiperiso_string_check(const char *str, grub_char_check_func check) +{ + if (!str) + { + return 0; + } + + for ( ; *str; str++) + { + if (!check(*str)) + { + return 0; + } + } + + return 1; +} + + +static grub_ssize_t hiperiso_fs_read(grub_file_t file, char *buf, grub_size_t len) +{ + grub_memcpy(buf, (char *)file->data + file->offset, len); + return len; +} + +static int hiperiso_control_get_flag(const char *key) +{ + const char *val = hiperiso_get_env(key); + + if (val && val[0] == '1' && val[1] == 0) + { + return 1; + } + return 0; +} + +static grub_err_t hiperiso_fs_close(grub_file_t file) +{ + grub_file_close(g_old_file); + grub_free(file->data); + + file->device = 0; + file->name = 0; + + return 0; +} + +static int hiperiso_video_hook(const struct grub_video_mode_info *info, void *hook_arg) +{ + int i; + + (void)hook_arg; + + if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT) + { + return 0; + } + + for (i = 0; i < g_video_mode_num; i++) + { + if (g_video_mode_list[i].width == info->width && + g_video_mode_list[i].height == info->height && + g_video_mode_list[i].bpp == info->bpp) + { + return 0; + } + } + + g_video_mode_list[g_video_mode_num].width = info->width; + g_video_mode_list[g_video_mode_num].height = info->height; + g_video_mode_list[g_video_mode_num].bpp = info->bpp; + g_video_mode_num++; + + if (g_video_mode_num == g_video_mode_max) + { + g_video_mode_max *= 2; + g_video_mode_list = grub_realloc(g_video_mode_list, g_video_mode_max * sizeof(hiperiso_video_mode)); + } + + return 0; +} + +static int hiperiso_video_mode_cmp(hiperiso_video_mode *v1, hiperiso_video_mode *v2) +{ + if (v1->bpp == v2->bpp) + { + if (v1->width == v2->width) + { + if (v1->height == v2->height) + { + return 0; + } + else + { + return (v1->height < v2->height) ? -1 : 1; + } + } + else + { + return (v1->width < v2->width) ? -1 : 1; + } + } + else + { + return (v1->bpp < v2->bpp) ? -1 : 1; + } +} + +static int hiperiso_enum_video_mode(void) +{ + int i, j; + grub_video_adapter_t adapter; + grub_video_driver_id_t id; + hiperiso_video_mode mode; + + g_video_mode_num = 0; + g_video_mode_max = 1024; + g_video_mode_list = grub_malloc(sizeof(hiperiso_video_mode) * g_video_mode_max); + if (!g_video_mode_list) + { + return 0; + } + + #ifdef GRUB_MACHINE_PCBIOS + grub_dl_load ("vbe"); + #endif + + id = grub_video_get_driver_id (); + + FOR_VIDEO_ADAPTERS (adapter) + { + if (!adapter->iterate || + (adapter->id != id && (id != GRUB_VIDEO_DRIVER_NONE || + adapter->init() != GRUB_ERR_NONE))) + { + continue; + } + + adapter->iterate(hiperiso_video_hook, NULL); + + if (adapter->id != id) + { + adapter->fini(); + } + } + + /* sort video mode */ + for (i = 0; i < g_video_mode_num; i++) + for (j = i + 1; j < g_video_mode_num; j++) + { + if (hiperiso_video_mode_cmp(g_video_mode_list + i, g_video_mode_list + j) < 0) + { + grub_memcpy(&mode, g_video_mode_list + i, sizeof(hiperiso_video_mode)); + grub_memcpy(g_video_mode_list + i, g_video_mode_list + j, sizeof(hiperiso_video_mode)); + grub_memcpy(g_video_mode_list + j, &mode, sizeof(hiperiso_video_mode)); + } + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_pre_parse_data(char *src, int size) +{ + char c; + char *pos = NULL; + char buf[256]; + + if (size < 20 || grub_strncmp(src, "hiperiso_left_top_color", 21)) + { + return 0; + } + + pos = src + 21; + while (*pos && *pos != '\r' && *pos != '\n') + { + pos++; + } + + c = *pos; + *pos = 0; + + if (grub_strlen(src) > 200) + { + goto end; + } + + grub_snprintf(buf, sizeof(buf), + "regexp -s 1:%s -s 2:%s -s 3:%s \"@([^@]*)@([^@]*)@([^@]*)@\" \"%s\"", + hiperiso_left_key, hiperiso_top_key, hiperiso_color_key, src); + + grub_script_execute_sourcecode(buf); + +end: + *pos = c; + return 0; +} + +static grub_file_t hiperiso_wrapper_open(grub_file_t rawFile, enum grub_file_type type) +{ + int len; + grub_file_t file; + static struct grub_fs hiso_fs = + { + .name = "hiso", + .fs_dir = 0, + .fs_open = 0, + .fs_read = hiperiso_fs_read, + .fs_close = hiperiso_fs_close, + .fs_label = 0, + .next = 0 + }; + + if (type != 52) + { + return rawFile; + } + + file = (grub_file_t)grub_zalloc(sizeof (*file)); + if (!file) + { + return 0; + } + + file->data = grub_malloc(rawFile->size + 4096); + if (!file->data) + { + return 0; + } + + grub_file_read(rawFile, file->data, rawFile->size); + hiperiso_pre_parse_data((char *)file->data, (int)rawFile->size); + len = hiperiso_fill_data(4096, (char *)file->data + rawFile->size); + + g_old_file = rawFile; + + file->size = rawFile->size + len; + file->device = rawFile->device; + file->fs = &hiso_fs; + file->not_easily_seekable = 1; + + return file; +} + +static int hiperiso_check_decimal_var(const char *name, long *value) +{ + const char *value_str = NULL; + + value_str = grub_env_get(name); + if (NULL == value_str) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Variable %s not found", name); + } + + if (!hiperiso_is_decimal(value_str)) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Variable %s value '%s' is not an integer", name, value_str); + } + + *value = grub_strtol(value_str, NULL, 10); + + return GRUB_ERR_NONE; +} + +grub_uint64_t hiperiso_get_hiso_partsize(int part) +{ + grub_uint64_t sectors; + + if (grub_strncmp(g_hiperiso_part_info->Head.Signature, "EFI PART", 8) == 0) + { + sectors = g_hiperiso_part_info->PartTbl[part].LastLBA + 1 - g_hiperiso_part_info->PartTbl[part].StartLBA; + } + else + { + sectors = g_hiperiso_part_info->MBR.PartTbl[part].SectorCount; + } + + return sectors * 512; +} + +static int hiperiso_load_efiboot_template(char **buf, int *datalen, int *direntoff) +{ + int len; + grub_file_t file; + char exec[128]; + char *data = NULL; + grub_uint32_t offset; + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/hiperiso/hiperiso_efiboot.img.xz", hiperiso_get_env("hiso_efi_part")); + if (file == NULL) + { + debug("failed to open file <%s>\n", "hiperiso_efiboot.img.xz"); + return 1; + } + + len = (int)file->size; + + data = (char *)grub_malloc(file->size); + if (!data) + { + return 1; + } + + grub_file_read(file, data, file->size); + grub_file_close(file); + + grub_snprintf(exec, sizeof(exec), "loopback efiboot mem:0x%llx:size:%d", (ulonglong)(ulong)data, len); + grub_script_execute_sourcecode(exec); + + file = grub_file_open("(efiboot)/EFI/BOOT/BOOTX64.EFI", GRUB_FILE_TYPE_LINUX_INITRD); + offset = (grub_uint32_t)grub_iso9660_get_last_file_dirent_pos(file); + grub_file_close(file); + + grub_script_execute_sourcecode("loopback -d efiboot"); + + *buf = data; + *datalen = len; + *direntoff = offset + 2; + + return 0; +} + +static int hiperiso_set_check_result(int ret, const char *msg) +{ + char buf[32]; + + grub_snprintf(buf, sizeof(buf), "%d", (ret & 0x7FFF)); + grub_env_set("HISO_CHKDEV_RESULT_STRING", buf); + grub_env_export("HISO_CHKDEV_RESULT_STRING"); + + if (ret) + { + grub_cls(); + grub_printf(HISO_WARNING"\n"); + grub_printf(HISO_WARNING"\n"); + grub_printf(HISO_WARNING"\n\n\n"); + + grub_printf("This is NOT a standard Hiperiso 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.hiperiso.net to use Hiperiso.\n"); + grub_refresh(); + } + + return ret; +} + +static int hiperiso_check_official_device(grub_device_t dev) +{ + int workaround = 0; + grub_file_t file; + grub_uint64_t offset; + char devname[64]; + grub_fs_t fs; + grub_uint8_t mbr[512]; + grub_disk_t disk; + grub_device_t dev2; + char *label = NULL; + struct grub_partition *partition; + + if (dev->disk == NULL || dev->disk->partition == NULL) + { + return hiperiso_set_check_result(1 | 0x1000, "Internal Error"); + } + + if (0 == hiperiso_check_file_exist("(%s,2)/EFI/hiperiso/initramfs.cpio.gz", dev->disk->name) || + 0 == hiperiso_check_file_exist("(%s,2)/grub/localboot.cfg", dev->disk->name) || + 0 == hiperiso_check_file_exist("(%s,2)/tool/mount.exfat-fuse_aarch64", dev->disk->name)) + { + #ifndef GRUB_MACHINE_EFI + if (0 == hiperiso_check_file_exist("(hiperisodisk)/EFI/hiperiso/initramfs.cpio.gz", dev->disk->name)) + { + return hiperiso_set_check_result(2 | 0x1000, "File EFI/hiperiso/initramfs.cpio.gz missing in HISOEFI partition"); + } + else if (0 == hiperiso_check_file_exist("(hiperisodisk)/grub/localboot.cfg", dev->disk->name)) + { + return hiperiso_set_check_result(2 | 0x1000, "File grub/localboot.cfg missing in HISOEFI partition"); + } + else if (0 == hiperiso_check_file_exist("(hiperisodisk)/tool/mount.exfat-fuse_aarch64", dev->disk->name)) + { + return hiperiso_set_check_result(2 | 0x1000, "File tool/mount.exfat-fuse_aarch64 missing in HISOEFI partition"); + } + else + { + workaround = 1; + } + #endif + } + + /* We must have partition 2 */ + if (workaround) + { + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", "(hiperisodisk)/EFI/hiperiso/initramfs.cpio.gz"); + } + else + { + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "(%s,2)/EFI/hiperiso/initramfs.cpio.gz", dev->disk->name); + } + if (!file) + { + return hiperiso_set_check_result(3 | 0x1000, "File EFI/hiperiso/initramfs.cpio.gz open failed in HISOEFI partition"); + } + + if (NULL == grub_strstr(file->fs->name, "fat")) + { + grub_file_close(file); + return hiperiso_set_check_result(4 | 0x1000, "HISOEFI partition is not FAT filesystem"); + } + + partition = dev->disk->partition; + if (partition->number != 0 || partition->start != 2048) + { + return hiperiso_set_check_result(5, "Hiperiso partition is not start at 1MB"); + } + + if (workaround) + { + if (grub_strncmp(g_hiperiso_part_info->Head.Signature, "EFI PART", 8) == 0) + { + hiperiso_gpt_part_tbl *PartTbl = g_hiperiso_part_info->PartTbl; + if (PartTbl[1].StartLBA != PartTbl[0].LastLBA + 1 || + (PartTbl[1].LastLBA + 1 - PartTbl[1].StartLBA) != 65536) + { + grub_file_close(file); + return hiperiso_set_check_result(6, "Disk partition layout check failed."); + } + } + else + { + hiperiso_part_table *PartTbl = g_hiperiso_part_info->MBR.PartTbl; + if (PartTbl[1].StartSectorId != PartTbl[0].StartSectorId + PartTbl[0].SectorCount || + PartTbl[1].SectorCount != 65536) + { + grub_file_close(file); + return hiperiso_set_check_result(6, "Disk partition layout check failed."); + } + } + } + else + { + offset = partition->start + partition->len; + partition = file->device->disk->partition; + if ((partition->number != 1) || (partition->len != 65536) || (offset != partition->start)) + { + grub_file_close(file); + return hiperiso_set_check_result(7, "Disk partition layout check failed."); + } + } + + grub_file_close(file); + + if (workaround == 0) + { + grub_snprintf(devname, sizeof(devname), "%s,2", dev->disk->name); + dev2 = grub_device_open(devname); + if (!dev2) + { + return hiperiso_set_check_result(8, "Disk open failed"); + } + + fs = grub_fs_probe(dev2); + if (!fs) + { + grub_device_close(dev2); + return hiperiso_set_check_result(9, "FS probe failed"); + } + + fs->fs_label(dev2, &label); + if ((!label) || grub_strncmp("HISOEFI", label, 7)) + { + grub_device_close(dev2); + return hiperiso_set_check_result(10, "Partition name is not HISOEFI"); + } + + grub_device_close(dev2); + } + + /* MBR check */ + disk = grub_disk_open(dev->disk->name); + if (!disk) + { + return hiperiso_set_check_result(11, "Disk open failed"); + } + + grub_memset(mbr, 0, 512); + grub_disk_read(disk, 0, 0, 512, mbr); + grub_disk_close(disk); + + if (grub_memcmp(g_check_mbr_data, mbr, 0x30) || grub_memcmp(g_check_mbr_data + 0x30, mbr + 0x190, 16)) + { + return hiperiso_set_check_result(12, "MBR check failed"); + } + + return hiperiso_set_check_result(0, NULL); +} + +static int hiperiso_check_ignore_flag(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + if (0 == info->dir) + { + if (filename && filename[0] == '.' && 0 == grub_strncmp(filename, ".hiperisoignore", 13)) + { + *((int *)data) = 1; + return 0; + } + } + + return 0; +} + +grub_uint64_t hiperiso_grub_get_file_size(const char *fmt, ...) +{ + grub_uint64_t size = 0; + grub_file_t file; + va_list ap; + char fullpath[256] = {0}; + + va_start (ap, fmt); + grub_vsnprintf(fullpath, 255, fmt, ap); + va_end (ap); + + file = grub_file_open(fullpath, HIPERISO_FILE_TYPE); + if (!file) + { + debug("grub_file_open failed <%s>\n", fullpath); + grub_errno = 0; + return 0; + } + + size = file->size; + grub_file_close(file); + return size; +} + +grub_file_t hiperiso_grub_file_open(enum grub_file_type type, const char *fmt, ...) +{ + va_list ap; + grub_file_t file; + char fullpath[512] = {0}; + + va_start (ap, fmt); + grub_vsnprintf(fullpath, 511, fmt, ap); + va_end (ap); + + file = grub_file_open(fullpath, type); + if (!file) + { + debug("grub_file_open failed <%s> %d\n", fullpath, grub_errno); + grub_errno = 0; + } + + return file; +} + +int hiperiso_is_dir_exist(const char *fmt, ...) +{ + va_list ap; + int len; + char *pos = NULL; + char buf[512] = {0}; + + grub_snprintf(buf, sizeof(buf), "%s", "[ -d \""); + pos = buf + 6; + + va_start (ap, fmt); + len = grub_vsnprintf(pos, 511, fmt, ap); + va_end (ap); + + grub_strncpy(pos + len, "\" ]", 3); + + debug("script exec %s\n", buf); + + if (0 == grub_script_execute_sourcecode(buf)) + { + return 1; + } + + return 0; +} + +int hiperiso_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len) +{ + mz_stream s; + grub_uint8_t *outbuf; + grub_uint8_t gzHdr[10] = + { + 0x1F, 0x8B, /* magic */ + 8, /* z method */ + 0, /* flags */ + 0,0,0,0, /* mtime */ + 4, /* xfl */ + 3, /* OS */ + }; + + grub_memset(&s, 0, sizeof(mz_stream)); + + mz_deflateInit2(&s, 1, MZ_DEFLATED, -MZ_DEFAULT_WINDOW_BITS, 6, MZ_DEFAULT_STRATEGY); + + outbuf = (grub_uint8_t *)mem_out; + + mem_out_len -= sizeof(gzHdr) + 8; + grub_memcpy(outbuf, gzHdr, sizeof(gzHdr)); + outbuf += sizeof(gzHdr); + + s.avail_in = mem_in_len; + s.next_in = mem_in; + + s.avail_out = mem_out_len; + s.next_out = outbuf; + + mz_deflate(&s, MZ_FINISH); + + mz_deflateEnd(&s); + + outbuf += s.total_out; + *(grub_uint32_t *)outbuf = grub_getcrc32c(0, outbuf, s.total_out); + *(grub_uint32_t *)(outbuf + 4) = (grub_uint32_t)(s.total_out); + + return s.total_out + sizeof(gzHdr) + 8; +} + + +#if 0 +hiperiso grub cmds +#endif + +static grub_err_t hiperiso_cmd_debug(grub_extcmd_context_t ctxt, int argc, char **args) +{ + if (argc != 1) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {on|off}", cmd_raw_name); + } + + if (0 == grub_strcmp(args[0], "on")) + { + g_hiperiso_debug = 1; + grub_env_set("vtdebug_flag", "debug"); + } + else + { + g_hiperiso_debug = 0; + grub_env_set("vtdebug_flag", ""); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_break(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + + if (argc < 1 || (args[0][0] != '0' && args[0][0] != '1')) + { + grub_printf("Usage: %s {level} [debug]\r\n", cmd_raw_name); + grub_printf(" level:\r\n"); + grub_printf(" 01/11: busybox / (+cat log)\r\n"); + grub_printf(" 02/12: initrd / (+cat log)\r\n"); + grub_printf(" 03/13: hook / (+cat log)\r\n"); + grub_printf("\r\n"); + grub_printf(" debug:\r\n"); + grub_printf(" 0: debug is off\r\n"); + grub_printf(" 1: debug is on\r\n"); + grub_printf("\r\n"); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); + } + + g_hiperiso_break_level = (grub_uint8_t)grub_strtoul(args[0], NULL, 16); + + if (argc > 1 && grub_strtoul(args[1], NULL, 10) > 0) + { + g_hiperiso_debug_level = 1; + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_strstr(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + + if (argc != 2) + { + return 1; + } + + return (grub_strstr(args[0], args[1])) ? 0 : 1; +} + +static grub_err_t hiperiso_cmd_istrstr(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_err_t ret = 1; + char *s1 = NULL; + char *s2 = NULL; + + (void)ctxt; + + if (argc != 2) + { + return 1; + } + + s1 = grub_strdup(args[0]); + s2 = grub_strdup(args[1]); + if (s1 == NULL || s2 == NULL) + { + goto end; + } + + hiperiso_str_toupper(s1); + hiperiso_str_toupper(s2); + ret = (grub_strstr(s1, s2)) ? 0 : 1; + +end: + grub_check_free(s1); + grub_check_free(s2); + return ret; +} + +static grub_err_t hiperiso_cmd_strbegin(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char *c0, *c1; + + (void)ctxt; + + if (argc != 2) + { + return 1; + } + + c0 = args[0]; + c1 = args[1]; + + while (*c0 && *c1) + { + if (*c0 != *c1) + { + return 1; + } + c0++; + c1++; + } + + if (*c1) + { + return 1; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_strcasebegin(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char *c0, *c1; + + (void)ctxt; + + if (argc != 2) + { + return 1; + } + + c0 = args[0]; + c1 = args[1]; + + while (*c0 && *c1) + { + if ((*c0 != *c1) && (*c0 != grub_toupper(*c1))) + { + return 1; + } + c0++; + c1++; + } + + if (*c1) + { + return 1; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_incr(grub_extcmd_context_t ctxt, int argc, char **args) +{ + long value_long = 0; + char buf[32]; + + if ((argc != 2) || (!hiperiso_is_decimal(args[1]))) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {Variable} {Int}", cmd_raw_name); + } + + if (GRUB_ERR_NONE != hiperiso_check_decimal_var(args[0], &value_long)) + { + return grub_errno; + } + + value_long += grub_strtol(args[1], NULL, 10); + + grub_snprintf(buf, sizeof(buf), "%ld", value_long); + grub_env_set(args[0], buf); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_mod(grub_extcmd_context_t ctxt, int argc, char **args) +{ + ulonglong value1 = 0; + ulonglong value2 = 0; + char buf[32]; + + if (argc != 3) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {Int} {Int} {Variable}", cmd_raw_name); + } + + value1 = grub_strtoull(args[0], NULL, 10); + value2 = grub_strtoull(args[1], NULL, 10); + + grub_snprintf(buf, sizeof(buf), "%llu", (value1 & (value2 - 1))); + grub_env_set(args[2], buf); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_file_size(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc = 1; + char buf[32]; + grub_file_t file; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 2) + { + return rc; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (file == NULL) + { + debug("failed to open file <%s> for udf check\n", args[0]); + return 1; + } + + grub_snprintf(buf, sizeof(buf), "%llu", (unsigned long long)file->size); + + grub_env_set(args[1], buf); + + grub_file_close(file); + rc = 0; + + return rc; +} + +static grub_err_t hiperiso_cmd_load_wimboot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_file_t file; + + (void)ctxt; + (void)argc; + (void)args; + + g_wimboot_enable = 0; + g_wimiso_size = 0; + grub_check_free(g_wimiso_path); + grub_check_free(g_wimiso_chunk_list.chunk); + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!file) + { + return 0; + } + + grub_memset(&g_wimiso_chunk_list, 0, sizeof(g_wimiso_chunk_list)); + g_wimiso_chunk_list.chunk = grub_malloc(sizeof(hiperiso_img_chunk) * DEFAULT_CHUNK_NUM); + if (NULL == g_wimiso_chunk_list.chunk) + { + return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Can't allocate image chunk memoty\n"); + } + + g_wimiso_chunk_list.max_chunk = DEFAULT_CHUNK_NUM; + g_wimiso_chunk_list.cur_chunk = 0; + + hiperiso_get_block_list(file, &g_wimiso_chunk_list, file->device->disk->partition->start); + + g_wimboot_enable = 1; + g_wimiso_path = grub_strdup(args[0]); + g_wimiso_size = (grub_uint32_t)(file->size); + grub_file_close(file); + + return 0; +} + +static grub_err_t hiperiso_cmd_concat_efi_iso(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len = 0; + int totlen = 0; + int offset = 0; + grub_file_t file; + char *buf = NULL; + char *data = NULL; + hiperiso_iso9660_override *dirent; + + (void)ctxt; + + if (argc != 2) + { + return 1; + } + + totlen = sizeof(hiperiso_chain_head); + + if (hiperiso_load_efiboot_template(&buf, &len, &offset)) + { + debug("failed to load efiboot template %d\n", len); + return 1; + } + + totlen += len; + + debug("efiboot template len:%d offset:%d\n", len, offset); + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s", args[0]); + if (file == NULL) + { + debug("failed to open file <%s>\n", args[0]); + return 1; + } + + if (grub_strncmp(args[0], g_iso_path, grub_strlen(g_iso_path))) + { + file->vlnk = 1; + } + + totlen += hiperiso_align_2k(file->size); + + dirent = (hiperiso_iso9660_override *)(buf + offset); + dirent->first_sector = len / 2048; + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size = (grub_uint32_t)file->size; + dirent->size_be = grub_swap_bytes32(dirent->size); + + debug("rawiso len:%d efilen:%d total:%d\n", len, (int)file->size, totlen); + +#ifdef GRUB_MACHINE_EFI + data = (char *)grub_efi_allocate_iso_buf(totlen); +#else + data = (char *)grub_malloc(totlen); +#endif + + hiperiso_fill_os_param(file, (hiperiso_os_param *)data); + + grub_memcpy(data + sizeof(hiperiso_chain_head), buf, len); + grub_check_free(buf); + + grub_file_read(file, data + sizeof(hiperiso_chain_head) + len, file->size); + grub_file_close(file); + + hiperiso_memfile_env_set(args[1], data, (ulonglong)totlen); + + return 0; +} + +grub_err_t hiperiso_cmd_set_wim_prompt(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_hiso_load_prompt = 0; + grub_memset(g_hiso_prompt_msg, 0, sizeof(g_hiso_prompt_msg)); + + if (argc == 2 && args[0][0] == '1') + { + g_hiso_load_prompt = 1; + grub_snprintf(g_hiso_prompt_msg, sizeof(g_hiso_prompt_msg), "%s", args[1]); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +int hiperiso_need_prompt_load_file(void) +{ + return g_hiso_load_prompt; +} + +grub_ssize_t hiperiso_load_file_with_prompt(grub_file_t file, void *buf, grub_ssize_t size) +{ + grub_uint64_t ro = 0; + grub_uint64_t div = 0; + grub_ssize_t left = size; + char *cur = (char *)buf; + + grub_printf("\r%s 1%% ", g_hiso_prompt_msg); + grub_refresh(); + + while (left >= HISO_SIZE_2MB) + { + grub_file_read(file, cur, HISO_SIZE_2MB); + cur += HISO_SIZE_2MB; + left -= HISO_SIZE_2MB; + + div = grub_divmod64((grub_uint64_t)((size - left) * 100), (grub_uint64_t)size, &ro); + if (div < 1) + { + div = 1; + } + grub_printf("\r%s %d%% ", g_hiso_prompt_msg, (int)div); + grub_refresh(); + } + + if (left > 0) + { + grub_file_read(file, cur, left); + } + + grub_printf("\r%s 100%% \n", g_hiso_prompt_msg); + grub_refresh(); + + return size; +} + +static grub_err_t hiperiso_cmd_load_file_to_mem(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc = 1; + char *buf = NULL; + grub_file_t file; + enum grub_file_type type; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 3) + { + return rc; + } + + if (grub_strcmp(args[0], "nodecompress") == 0) + { + type = HIPERISO_FILE_TYPE; + } + else + { + type = GRUB_FILE_TYPE_LINUX_INITRD; + } + + file = hiperiso_grub_file_open(type, "%s", args[1]); + if (file == NULL) + { + debug("failed to open file <%s>\n", args[1]); + return 1; + } + +#ifdef GRUB_MACHINE_EFI + buf = (char *)grub_efi_allocate_chain_buf(file->size); +#else + buf = (char *)grub_malloc(file->size); +#endif + + if (!buf) + { + grub_file_close(file); + return 1; + } + + if (g_hiso_load_prompt) + { + hiperiso_load_file_with_prompt(file, buf, file->size); + } + else + { + grub_file_read(file, buf, file->size); + } + + hiperiso_memfile_env_set(args[2], buf, (ulonglong)(file->size)); + + grub_file_close(file); + rc = 0; + + return rc; +} + +static grub_err_t hiperiso_cmd_load_img_memdisk(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc = 1; + int headlen; + char *buf = NULL; + grub_file_t file; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 2) + { + return rc; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (file == NULL) + { + debug("failed to open file <%s> for udf check\n", args[0]); + return 1; + } + + headlen = sizeof(hiperiso_chain_head); + +#ifdef GRUB_MACHINE_EFI + buf = (char *)grub_efi_allocate_iso_buf(headlen + file->size); +#else + buf = (char *)grub_malloc(headlen + file->size); +#endif + + hiperiso_fill_os_param(file, (hiperiso_os_param *)buf); + + grub_file_read(file, buf + headlen, file->size); + + hiperiso_memfile_env_set(args[1], buf, (ulonglong)(file->size)); + + grub_file_close(file); + rc = 0; + + return rc; +} + +static grub_err_t hiperiso_cmd_iso9660_is_joliet(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + if (grub_iso9660_is_joliet()) + { + debug("This time has joliet process\n"); + return 0; + } + else + { + return 1; + } +} + +static grub_err_t hiperiso_cmd_iso9660_nojoliet(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + + if (argc != 1) + { + return 1; + } + + if (args[0][0] == '1') + { + grub_iso9660_set_nojoliet(1); + } + else + { + grub_iso9660_set_nojoliet(0); + } + + return 0; +} + +static grub_err_t hiperiso_cmd_is_udf(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int rc = 1; + grub_file_t file; + grub_uint8_t buf[32]; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 1) + { + return rc; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (file == NULL) + { + debug("failed to open file <%s> for udf check\n", args[0]); + return 1; + } + + for (i = 16; i < 32; i++) + { + grub_file_seek(file, i * 2048); + grub_file_read(file, buf, sizeof(buf)); + if (buf[0] == 255) + { + break; + } + } + + i++; + grub_file_seek(file, i * 2048); + grub_file_read(file, buf, sizeof(buf)); + + if (grub_memcmp(buf + 1, "BEA01", 5) == 0) + { + i++; + grub_file_seek(file, i * 2048); + grub_file_read(file, buf, sizeof(buf)); + + if (grub_memcmp(buf + 1, "NSR02", 5) == 0 || + grub_memcmp(buf + 1, "NSR03", 5) == 0) + { + rc = 0; + } + } + + grub_file_close(file); + + debug("ISO UDF: %s\n", rc ? "NO" : "YES"); + + return rc; +} + +static grub_err_t hiperiso_cmd_cmp(grub_extcmd_context_t ctxt, int argc, char **args) +{ + long value_long1 = 0; + long value_long2 = 0; + + if ((argc != 3) || (!hiperiso_is_decimal(args[0])) || (!hiperiso_is_decimal(args[2]))) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {Int1} { eq|ne|gt|lt|ge|le } {Int2}", cmd_raw_name); + } + + value_long1 = grub_strtol(args[0], NULL, 10); + value_long2 = grub_strtol(args[2], NULL, 10); + + if (0 == grub_strcmp(args[1], "eq")) + { + grub_errno = (value_long1 == value_long2) ? GRUB_ERR_NONE : GRUB_ERR_TEST_FAILURE; + } + else if (0 == grub_strcmp(args[1], "ne")) + { + grub_errno = (value_long1 != value_long2) ? GRUB_ERR_NONE : GRUB_ERR_TEST_FAILURE; + } + else if (0 == grub_strcmp(args[1], "gt")) + { + grub_errno = (value_long1 > value_long2) ? GRUB_ERR_NONE : GRUB_ERR_TEST_FAILURE; + } + else if (0 == grub_strcmp(args[1], "lt")) + { + grub_errno = (value_long1 < value_long2) ? GRUB_ERR_NONE : GRUB_ERR_TEST_FAILURE; + } + else if (0 == grub_strcmp(args[1], "ge")) + { + grub_errno = (value_long1 >= value_long2) ? GRUB_ERR_NONE : GRUB_ERR_TEST_FAILURE; + } + else if (0 == grub_strcmp(args[1], "le")) + { + grub_errno = (value_long1 <= value_long2) ? GRUB_ERR_NONE : GRUB_ERR_TEST_FAILURE; + } + else + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {Int1} { eq ne gt lt ge le } {Int2}", cmd_raw_name); + } + + return grub_errno; +} + +static grub_err_t hiperiso_cmd_device(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char *pos = NULL; + char buf[128] = {0}; + + if (argc != 2) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s path var", cmd_raw_name); + } + + grub_strncpy(buf, (args[0][0] == '(') ? args[0] + 1 : args[0], sizeof(buf) - 1); + pos = grub_strstr(buf, ","); + if (pos) + { + *pos = 0; + } + + grub_env_set(args[1], buf); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_check_compatible(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + char buf[256]; + grub_disk_t disk; + char *pos = NULL; + const char *files[] = { "hiperiso.dat", "HIPERISO.DAT" }; + + (void)ctxt; + + if (argc != 1) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s (loop)", cmd_raw_name); + } + + for (i = 0; i < (int)ARRAY_SIZE(files); i++) + { + grub_snprintf(buf, sizeof(buf) - 1, "[ -e \"%s/%s\" ]", args[0], files[i]); + if (0 == grub_script_execute_sourcecode(buf)) + { + debug("file %s exist, hiperiso_compatible YES\n", buf); + grub_env_set("hiperiso_compatible", "YES"); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); + } + else + { + debug("file %s NOT exist\n", buf); + } + } + + grub_snprintf(buf, sizeof(buf) - 1, "%s", args[0][0] == '(' ? (args[0] + 1) : args[0]); + pos = grub_strstr(buf, ")"); + if (pos) + { + *pos = 0; + } + + disk = grub_disk_open(buf); + if (disk) + { + grub_disk_read(disk, 16 << 2, 0, 1024, g_img_swap_tmp_buf); + grub_disk_close(disk); + + g_img_swap_tmp_buf[703] = 0; + for (i = 318; i < 703; i++) + { + if (g_img_swap_tmp_buf[i] == 'V' && + 0 == grub_strncmp(g_img_swap_tmp_buf + i, HIPERISO_COMPATIBLE_STR, HIPERISO_COMPATIBLE_STR_LEN)) + { + debug("Hiperiso compatible string exist at %d, hiperiso_compatible YES\n", i); + grub_env_set("hiperiso_compatible", "YES"); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); + } + } + } + else + { + debug("failed to open disk <%s>\n", buf); + } + + grub_env_set("hiperiso_compatible", "NO"); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +int hiperiso_cmp_img(img_info *img1, img_info *img2) +{ + char *s1, *s2; + int c1 = 0; + int c2 = 0; + + if (g_plugin_image_list == HIPERISO_IMG_WHITE_LIST) + { + return (img1->plugin_list_index - img2->plugin_list_index); + } + + for (s1 = img1->name, s2 = img2->name; *s1 && *s2; s1++, s2++) + { + c1 = *s1; + c2 = *s2; + + if (0 == g_sort_case_sensitive) + { + if (grub_islower(c1)) + { + c1 = c1 - 'a' + 'A'; + } + + if (grub_islower(c2)) + { + c2 = c2 - 'a' + 'A'; + } + } + + if (c1 != c2) + { + break; + } + } + + return (c1 - c2); +} + +static int hiperiso_cmp_subdir(img_iterator_node *node1, img_iterator_node *node2) +{ + int i = 0; + int c1 = 0; + int c2 = 0; + int len = 0; + char *s1, *s2; + + if (g_plugin_image_list == HIPERISO_IMG_WHITE_LIST) + { + return (node1->plugin_list_index - node2->plugin_list_index); + } + + s1 = node1->dir; + s2 = node2->dir; + len = grub_min(node1->dirlen, node2->dirlen); + + for (i = 0; i < len - 1; i++) + { + c1 = *s1++; + c2 = *s2++; + + if (0 == g_sort_case_sensitive) + { + if (grub_islower(c1)) + { + c1 = c1 - 'a' + 'A'; + } + + if (grub_islower(c2)) + { + c2 = c2 - 'a' + 'A'; + } + } + + if (c1 != c2) + { + return (c1 - c2); + } + } + + if (len == node1->dirlen) + { + c1 = 0; + } + + if (len == node2->dirlen) + { + c2 = 0; + } + + return (c1 - c2); +} + +void hiperiso_swap_img(img_info *img1, img_info *img2) +{ + grub_memcpy(&g_img_swap_tmp, img1, sizeof(img_info)); + + grub_memcpy(img1, img2, sizeof(img_info)); + img1->next = g_img_swap_tmp.next; + img1->prev = g_img_swap_tmp.prev; + + g_img_swap_tmp.next = img2->next; + g_img_swap_tmp.prev = img2->prev; + grub_memcpy(img2, &g_img_swap_tmp, sizeof(img_info)); +} + +int hiperiso_img_name_valid(const char *filename, grub_size_t namelen) +{ + (void)namelen; + + if (g_filt_dot_underscore_file && filename[0] == '.' && filename[1] == '_') + { + return 0; + } + + return 1; +} + +static int hiperiso_vlnk_iterate_partition(struct grub_disk *disk, const grub_partition_t partition, void *data) +{ + hiperiso_vlnk_part *node = NULL; + grub_uint32_t SelfSig; + grub_uint32_t *pSig = (grub_uint32_t *)data; + + /* skip Hiperiso partition 1/2 */ + grub_memcpy(&SelfSig, g_hiperiso_part_info->MBR.BootCode + 0x1b8, 4); + if (partition->number < 2 && SelfSig == *pSig) + { + return 0; + } + + node = grub_zalloc(sizeof(hiperiso_vlnk_part)); + if (node) + { + node->disksig = *pSig; + node->partoffset = (partition->start << GRUB_DISK_SECTOR_BITS); + grub_snprintf(node->disk, sizeof(node->disk) - 1, "%s", disk->name); + grub_snprintf(node->device, sizeof(node->device) - 1, "%s,%d", disk->name, partition->number + 1); + + node->next = g_vlnk_part_list; + g_vlnk_part_list = node; + } + + return 0; +} + +static int hiperiso_vlnk_iterate_disk(const char *name, void *data) +{ + grub_disk_t disk; + grub_uint32_t sig; + + (void)data; + + disk = grub_disk_open(name); + if (disk) + { + grub_disk_read(disk, 0, 0x1b8, 4, &sig); + grub_partition_iterate(disk, hiperiso_vlnk_iterate_partition, &sig); + grub_disk_close(disk); + } + + return 0; +} + +static int hiperiso_vlnk_probe_fs(hiperiso_vlnk_part *cur) +{ + const char *fs[hiperiso_fs_max + 1] = + { + "exfat", "ntfs", "ext2", "xfs", "udf", "fat", "btrfs", NULL + }; + + if (!cur->dev) + { + cur->dev = grub_device_open(cur->device); + } + + if (cur->dev) + { + cur->fs = grub_fs_list_probe(cur->dev, fs); + } + + return 0; +} + +static int hiperiso_check_vlnk_data(hiperiso_vlnk *vlnk, int print, char *dst, int size) +{ + int diskfind = 0; + int partfind = 0; + int filefind = 0; + char *disk, *device; + grub_uint32_t readcrc, calccrc; + hiperiso_vlnk_part *cur; + grub_fs_t fs = NULL; + + if (grub_memcmp(&(vlnk->guid), &g_hiperiso_guid, sizeof(hiperiso_guid))) + { + if (print) + { + grub_printf("VLNK invalid guid\n"); + grub_refresh(); + } + return 1; + } + + readcrc = vlnk->crc32; + vlnk->crc32 = 0; + calccrc = grub_getcrc32c(0, vlnk, sizeof(hiperiso_vlnk)); + if (readcrc != calccrc) + { + if (print) + { + grub_printf("VLNK invalid crc 0x%08x 0x%08x\n", calccrc, readcrc); + grub_refresh(); + } + return 1; + } + + if (!g_vlnk_part_list) + { + grub_disk_dev_iterate(hiperiso_vlnk_iterate_disk, NULL); + } + + for (cur = g_vlnk_part_list; cur && filefind == 0; cur = cur->next) + { + if (cur->disksig == vlnk->disk_signature) + { + diskfind = 1; + disk = cur->disk; + if (cur->partoffset == vlnk->part_offset) + { + partfind = 1; + device = cur->device; + + if (cur->probe == 0) + { + cur->probe = 1; + hiperiso_vlnk_probe_fs(cur); + } + + if (!fs) + { + fs = cur->fs; + } + + if (cur->fs) + { + struct grub_file file; + + grub_memset(&file, 0, sizeof(file)); + file.device = cur->dev; + if (cur->fs->fs_open(&file, vlnk->filepath) == GRUB_ERR_NONE) + { + filefind = 1; + cur->fs->fs_close(&file); + grub_snprintf(dst, size - 1, "(%s)%s", cur->device, vlnk->filepath); + } + else + { + grub_errno = 0; + } + } + } + } + } + + if (print) + { + grub_printf("\n==== VLNK Information ====\n" + "Disk Signature: %08x\n" + "Partition Offset: %llu\n" + "File Path: <%s>\n\n", + vlnk->disk_signature, (ulonglong)vlnk->part_offset, vlnk->filepath); + + if (diskfind) + { + grub_printf("Disk Find: [ YES ] [ %s ]\n", disk); + } + else + { + grub_printf("Disk Find: [ NO ]\n"); + } + + if (partfind) + { + grub_printf("Part Find: [ YES ] [ %s ] [ %s ]\n", device, fs ? fs->name : "N/A"); + } + else + { + grub_printf("Part Find: [ NO ]\n"); + } + grub_printf("File Find: [ %s ]\n", filefind ? "YES" : "NO"); + if (filefind) + { + grub_printf("VLNK File: <%s>\n", dst); + } + + grub_printf("\n"); + grub_refresh(); + } + + return (1 - filefind); +} + +int hiperiso_add_vlnk_file(char *dir, const char *name) +{ + int rc = 1; + char src[512]; + char dst[512]; + grub_file_t file = NULL; + hiperiso_vlnk vlnk; + + if (!dir) + { + grub_snprintf(src, sizeof(src), "%s%s", g_iso_path, name); + } + else if (dir[0] == '/') + { + grub_snprintf(src, sizeof(src), "%s%s%s", g_iso_path, dir, name); + } + else + { + grub_snprintf(src, sizeof(src), "%s/%s%s", g_iso_path, dir, name); + } + + file = grub_file_open(src, HIPERISO_FILE_TYPE); + if (!file) + { + return 1; + } + + grub_memset(&vlnk, 0, sizeof(vlnk)); + grub_file_read(file, &vlnk, sizeof(vlnk)); + grub_file_close(file); + + if (hiperiso_check_vlnk_data(&vlnk, 0, dst, sizeof(dst)) == 0) + { + rc = grub_file_add_vlnk(src, dst); + } + + return rc; +} + +static int hiperiso_collect_img_files(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + //int i = 0; + int type = 0; + int ignore = 0; + int index = 0; + int vlnk = 0; + grub_size_t len; + img_info *img; + img_info *tail; + const menu_tip *tip; + img_iterator_node *tmp; + img_iterator_node *new_node; + img_iterator_node *node = (img_iterator_node *)data; + + if (g_enumerate_time_checked == 0) + { + g_enumerate_finish_time_ms = grub_get_time_ms(); + if ((g_enumerate_finish_time_ms - g_enumerate_start_time_ms) >= 3000) + { + grub_cls(); + grub_printf("\n\n Hiperiso scanning files, please wait...\n"); + grub_refresh(); + g_enumerate_time_checked = 1; + } + } + + len = grub_strlen(filename); + + if (info->dir) + { + if (node->level + 1 > g_img_max_search_level) + { + return 0; + } + + if ((len == 1 && filename[0] == '.') || + (len == 2 && filename[0] == '.' && filename[1] == '.')) + { + return 0; + } + + if (!hiperiso_img_name_valid(filename, len)) + { + return 0; + } + + if (g_filt_trash_dir) + { + if (0 == grub_strncmp(filename, ".trash-", 7) || + 0 == grub_strcmp(filename, ".Trashes") || + 0 == grub_strncmp(filename, "$RECYCLE.BIN", 12)) + { + return 0; + } + } + + if (g_plugin_image_list == HIPERISO_IMG_WHITE_LIST) + { + grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s/", node->dir, filename); + index = hiperiso_plugin_get_image_list_index(hiso_class_directory, g_img_swap_tmp_buf); + if (index == 0) + { + debug("Directory %s not found in image_list plugin config...\n", g_img_swap_tmp_buf); + return 0; + } + } + + new_node = grub_zalloc(sizeof(img_iterator_node)); + if (new_node) + { + new_node->level = node->level + 1; + new_node->plugin_list_index = index; + new_node->dirlen = grub_snprintf(new_node->dir, sizeof(new_node->dir), "%s%s/", node->dir, filename); + + g_enum_fs->fs_dir(g_enum_dev, new_node->dir, hiperiso_check_ignore_flag, &ignore); + if (ignore) + { + debug("Directory %s ignored...\n", new_node->dir); + grub_free(new_node); + return 0; + } + + new_node->tail = node->tail; + + new_node->parent = node; + if (!node->firstchild) + { + node->firstchild = new_node; + } + + if (g_img_iterator_tail) + { + g_img_iterator_tail->next = new_node; + g_img_iterator_tail = new_node; + } + else + { + g_img_iterator_head.next = new_node; + g_img_iterator_tail = new_node; + } + } + } + else + { + debug("Find a file %s\n", filename); + if (len < 4) + { + return 0; + } + + if (FILE_FLT(ISO) && 0 == grub_strcasecmp(filename + len - 4, ".iso")) + { + type = img_type_iso; + } + else if (FILE_FLT(WIM) && g_wimboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".wim"))) + { + type = img_type_wim; + } + else if (FILE_FLT(VHD) && g_vhdboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".vhd") || + (len >= 5 && 0 == grub_strcasecmp(filename + len - 5, ".vhdx")))) + { + type = img_type_vhd; + } + #ifdef GRUB_MACHINE_EFI + else if (FILE_FLT(EFI) && 0 == grub_strcasecmp(filename + len - 4, ".efi")) + { + type = img_type_efi; + } + #endif + else if (FILE_FLT(IMG) && 0 == grub_strcasecmp(filename + len - 4, ".img")) + { + if (len == 18 && grub_strncmp(filename, "hiperiso_", 7) == 0) + { + if (grub_strncmp(filename + 7, "wimboot", 7) == 0 || + grub_strncmp(filename + 7, "vhdboot", 7) == 0) + { + return 0; + } + } + type = img_type_img; + } + else if (FILE_FLT(HISO) && len >= 5 && 0 == grub_strcasecmp(filename + len - 5, ".hiso")) + { + type = img_type_hiso; + } + else if (len >= 9 && 0 == grub_strcasecmp(filename + len - 5, ".vcfg")) + { + if (filename[len - 9] == '.' || (len >= 10 && filename[len - 10] == '.')) + { + grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s", node->dir, filename); + hiperiso_plugin_add_custom_boot(g_img_swap_tmp_buf); + } + return 0; + } + else + { + return 0; + } + + if (g_filt_dot_underscore_file && filename[0] == '.' && filename[1] == '_') + { + return 0; + } + + if (g_plugin_image_list) + { + grub_snprintf(g_img_swap_tmp_buf, sizeof(g_img_swap_tmp_buf), "%s%s", node->dir, filename); + index = hiperiso_plugin_get_image_list_index(hiso_class_image_file, g_img_swap_tmp_buf); + if (HIPERISO_IMG_WHITE_LIST == g_plugin_image_list && index == 0) + { + debug("File %s not found in image_list plugin config...\n", g_img_swap_tmp_buf); + return 0; + } + else if (HIPERISO_IMG_BLACK_LIST == g_plugin_image_list && index > 0) + { + debug("File %s found in image_blacklist plugin config %d ...\n", g_img_swap_tmp_buf, index); + return 0; + } + } + + if (info->size == HISO_FILT_MIN_FILE_SIZE || info->size == 0) + { + if (grub_file_is_vlnk_suffix(filename, len)) + { + vlnk = 1; + if (hiperiso_add_vlnk_file(node->dir, filename) != 0) + { + return 0; + } + } + } + + img = grub_zalloc(sizeof(img_info)); + if (img) + { + img->type = type; + img->plugin_list_index = index; + grub_snprintf(img->name, sizeof(img->name), "%s", filename); + + img->pathlen = grub_snprintf(img->path, sizeof(img->path), "%s%s", node->dir, img->name); + + img->size = info->size; + if (vlnk || 0 == img->size) + { + if (node->dir[0] == '/') + { + img->size = hiperiso_grub_get_file_size("%s%s%s", g_iso_path, node->dir, filename); + } + else + { + img->size = hiperiso_grub_get_file_size("%s/%s%s", g_iso_path, node->dir, filename); + } + } + + if (img->size < HISO_FILT_MIN_FILE_SIZE) + { + debug("img <%s> size too small %llu\n", img->name, (ulonglong)img->size); + grub_free(img); + return 0; + } + + if (g_hiperiso_img_list) + { + tail = *(node->tail); + img->prev = tail; + tail->next = img; + } + else + { + g_hiperiso_img_list = img; + } + + img->id = g_hiperiso_img_count; + img->parent = node; + if (node && NULL == node->firstiso) + { + node->firstiso = img; + } + + node->isocnt++; + tmp = node->parent; + while (tmp) + { + tmp->isocnt++; + tmp = tmp->parent; + } + + *((img_info **)(node->tail)) = img; + g_hiperiso_img_count++; + + img->alias = hiperiso_plugin_get_menu_alias(hiso_alias_image_file, img->path); + + tip = hiperiso_plugin_get_menu_tip(hiso_tip_image_file, img->path); + if (tip) + { + img->tip1 = tip->tip1; + img->tip2 = tip->tip2; + } + + img->class = hiperiso_plugin_get_menu_class(hiso_class_image_file, img->name, img->path); + if (!img->class) + { + img->class = g_menu_class[type]; + } + img->menu_prefix = g_menu_prefix[type]; + + if (img_type_iso == type) + { + if (hiperiso_plugin_check_memdisk(img->path)) + { + img->menu_prefix = "miso"; + } + } + else if (img_type_img == type) + { + if (hiperiso_plugin_check_memdisk(img->path)) + { + img->menu_prefix = "mimg"; + } + } + + debug("Add %s%s to list %d\n", node->dir, filename, g_hiperiso_img_count); + } + } + + return 0; +} + +int hiperiso_fill_data(grub_uint32_t buflen, char *buffer) +{ + int len = GRUB_UINT_MAX; + const char *value = NULL; + char name[32] = {0}; + char plat[32] = {0}; + char guidstr[32] = {0}; + hiperiso_guid guid = HIPERISO_GUID; + const char *fmt1 = NULL; + const char *fmt2 = NULL; + const char *fmt3 = NULL; + grub_uint32_t *puint = (grub_uint32_t *)name; + grub_uint32_t *puint2 = (grub_uint32_t *)plat; + const char fmtdata[]={ 0x39, 0x35, 0x25, 0x00, 0x35, 0x00, 0x23, 0x30, 0x30, 0x30, 0x30, 0x66, 0x66, 0x00 }; + const char fmtcode[]={ + 0x22, 0x0A, 0x2B, 0x20, 0x68, 0x62, 0x6F, 0x78, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x74, 0x6F, 0x70, + 0x20, 0x3D, 0x20, 0x25, 0x73, 0x0A, 0x20, 0x20, 0x6C, 0x65, 0x66, 0x74, 0x20, 0x3D, 0x20, 0x25, + 0x73, 0x0A, 0x20, 0x20, 0x2B, 0x20, 0x6C, 0x61, 0x62, 0x65, 0x6C, 0x20, 0x7B, 0x74, 0x65, 0x78, + 0x74, 0x20, 0x3D, 0x20, 0x22, 0x25, 0x73, 0x20, 0x25, 0x73, 0x25, 0x73, 0x22, 0x20, 0x63, 0x6F, + 0x6C, 0x6F, 0x72, 0x20, 0x3D, 0x20, 0x22, 0x25, 0x73, 0x22, 0x20, 0x61, 0x6C, 0x69, 0x67, 0x6E, + 0x20, 0x3D, 0x20, 0x22, 0x6C, 0x65, 0x66, 0x74, 0x22, 0x7D, 0x0A, 0x7D, 0x0A, 0x22, 0x00 + }; + + grub_memset(name, 0, sizeof(name)); + puint[0] = grub_swap_bytes32(0x56454e54); + puint[3] = grub_swap_bytes32(0x4f4e0000); + puint[2] = grub_swap_bytes32(0x45525349); + puint[1] = grub_swap_bytes32(0x4f595f56); + value = hiperiso_get_env(name); + + grub_memset(name, 0, sizeof(name)); + puint[1] = grub_swap_bytes32(0x5f544f50); + puint[0] = grub_swap_bytes32(0x56544c45); + fmt1 = hiperiso_get_env(name); + if (!fmt1) + { + fmt1 = fmtdata; + } + + grub_memset(name, 0, sizeof(name)); + puint[1] = grub_swap_bytes32(0x5f4c4654); + puint[0] = grub_swap_bytes32(0x56544c45); + fmt2 = hiperiso_get_env(name); + + grub_memset(name, 0, sizeof(name)); + puint[1] = grub_swap_bytes32(0x5f434c52); + puint[0] = grub_swap_bytes32(0x56544c45); + fmt3 = hiperiso_get_env(name); + + grub_memcpy(guidstr, &guid, sizeof(guid)); + + puint2[0] = grub_swap_bytes32(g_hiperiso_plat_data); + + /* Easter egg :) It will be appreciated if you reserve it, but NOT mandatory. */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" + len = grub_snprintf(buffer, buflen, fmtcode, + fmt1 ? fmt1 : fmtdata, + fmt2 ? fmt2 : fmtdata + 4, + value ? value : "", plat, guidstr, + fmt3 ? fmt3 : fmtdata + 6); + #pragma GCC diagnostic pop + + grub_memset(name, 0, sizeof(name)); + puint[0] = grub_swap_bytes32(0x76746f79); + puint[2] = grub_swap_bytes32(0x656e7365); + puint[1] = grub_swap_bytes32(0x5f6c6963); + hiperiso_set_env(name, guidstr); + + return len; +} + +static int +hiperiso_password_get (char buf[], unsigned buf_size) +{ + unsigned i, cur_len = 0; + int key; + struct grub_term_coordinate *pos = grub_term_save_pos (); + + while (1) + { + key = grub_getkey (); + if (key == '\n' || key == '\r') + break; + + if (key == GRUB_TERM_ESC) + { + cur_len = 0; + break; + } + + if (key == '\b') + { + if (cur_len) + { + grub_term_restore_pos (pos); + for (i = 0; i < cur_len; i++) + grub_xputs (" "); + grub_term_restore_pos (pos); + cur_len--; + for (i = 0; i < cur_len; i++) + grub_xputs ("*"); + grub_refresh (); + } + continue; + } + + if (!grub_isprint (key)) + continue; + + if (cur_len + 2 < buf_size) + buf[cur_len++] = key; + grub_xputs ("*"); + grub_refresh (); + } + + grub_memset (buf + cur_len, 0, buf_size - cur_len); + + grub_xputs ("\n"); + grub_refresh (); + grub_free (pos); + + return (key != GRUB_TERM_ESC); +} + +static int hiperiso_get_password(char buf[], unsigned buf_size) +{ + const char *env = NULL; + + env = grub_env_get("HISO_SHOW_PASSWORD_ASTERISK"); + if (env && env[0] == '0' && env[1] == 0) + { + return grub_password_get(buf, buf_size); + } + else + { + return hiperiso_password_get(buf, buf_size); + } +} + +int hiperiso_check_password(const hiso_password *pwd, int retry) +{ + int offset; + char input[256]; + grub_uint8_t md5[16]; + + while (retry--) + { + grub_memset(input, 0, sizeof(input)); + + grub_printf("Enter password: "); + grub_refresh(); + + if (pwd->type == HISO_PASSWORD_TXT) + { + hiperiso_get_password(input, 128); + if (grub_strcmp(pwd->text, input) == 0) + { + return 0; + } + } + else if (pwd->type == HISO_PASSWORD_MD5) + { + hiperiso_get_password(input, 128); + grub_crypto_hash(GRUB_MD_MD5, md5, input, grub_strlen(input)); + if (grub_memcmp(pwd->md5, md5, 16) == 0) + { + return 0; + } + } + else if (pwd->type == HISO_PASSWORD_SALT_MD5) + { + offset = (int)grub_snprintf(input, 128, "%s", pwd->salt); + hiperiso_get_password(input + offset, 128); + + grub_crypto_hash(GRUB_MD_MD5, md5, input, grub_strlen(input)); + if (grub_memcmp(pwd->md5, md5, 16) == 0) + { + return 0; + } + } + + grub_printf("Invalid password!\n\n"); + grub_refresh(); + } + + return 1; +} + +static img_info * hiperiso_get_min_iso(img_iterator_node *node) +{ + img_info *minimg = NULL; + img_info *img = (img_info *)(node->firstiso); + + while (img && (img_iterator_node *)(img->parent) == node) + { + if (img->select == 0 && (NULL == minimg || hiperiso_cmp_img(img, minimg) < 0)) + { + minimg = img; + } + img = img->next; + } + + if (minimg) + { + minimg->select = 1; + } + + return minimg; +} + +static img_iterator_node * hiperiso_get_min_child(img_iterator_node *node) +{ + img_iterator_node *Minchild = NULL; + img_iterator_node *child = node->firstchild; + + while (child && child->parent == node) + { + if (child->select == 0 && (NULL == Minchild || hiperiso_cmp_subdir(child, Minchild) < 0)) + { + Minchild = child; + } + child = child->next; + } + + if (Minchild) + { + Minchild->select = 1; + } + + return Minchild; +} + +static int hiperiso_dynamic_tree_menu(img_iterator_node *node) +{ + int offset = 1; + img_info *img = NULL; + const char *dir_class = NULL; + const char *dir_alias = NULL; + img_iterator_node *child = NULL; + const menu_tip *tip = NULL; + + if (node->isocnt == 0 || node->done == 1) + { + return 0; + } + + if (node->parent && node->parent->dirlen < node->dirlen) + { + offset = node->parent->dirlen; + } + + if (node == &g_img_iterator_head) + { + if (g_default_menu_mode == 0) + { + if (g_tree_view_menu_style == 0) + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "menuentry \"%-10s [%s]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n" + "}\n", "<--", hiperiso_get_vmenu_title("VTLANG_RET_TO_LISTVIEW")); + } + else + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "menuentry \"[%s]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n" + "}\n", hiperiso_get_vmenu_title("VTLANG_RET_TO_LISTVIEW")); + } + } + + g_tree_script_pre = g_tree_script_pos; + } + else + { + node->dir[node->dirlen - 1] = 0; + dir_class = hiperiso_plugin_get_menu_class(hiso_class_directory, node->dir, node->dir); + if (!dir_class) + { + dir_class = "hisodir"; + } + + tip = hiperiso_plugin_get_menu_tip(hiso_tip_directory, node->dir); + + dir_alias = hiperiso_plugin_get_menu_alias(hiso_alias_directory, node->dir); + if (dir_alias) + { + if (g_tree_view_menu_style == 0) + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "submenu \"%-10s %s\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n", + "DIR", dir_alias, dir_class, node->dir + offset, tip); + } + else + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "submenu \"%s\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n", + dir_alias, dir_class, node->dir + offset, tip); + } + } + else + { + dir_alias = node->dir + offset; + + if (g_tree_view_menu_style == 0) + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "submenu \"%-10s [%s]\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n", + "DIR", dir_alias, dir_class, node->dir + offset, tip); + } + else + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "submenu \"[%s]\" --class=\"%s\" --id=\"DIR_%s\" _VTIP_%p {\n", + dir_alias, dir_class, node->dir + offset, tip); + } + } + + if (g_tree_view_menu_style == 0) + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "menuentry \"%-10s [%s/..]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n" + "}\n", "<--", node->dir); + } + else + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "menuentry \"[%s/..]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n" + "}\n", node->dir); + } + } + + while ((child = hiperiso_get_min_child(node)) != NULL) + { + hiperiso_dynamic_tree_menu(child); + } + + while ((img = hiperiso_get_min_iso(node)) != NULL) + { + if (g_tree_view_menu_style == 0) + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "menuentry \"%-10s %s%s\" --class=\"%s\" --id=\"VID_%p\" {\n" + " %s_%s \n" + "}\n", + grub_get_human_size(img->size, GRUB_HUMAN_SIZE_SHORT), + img->unsupport ? "[***********] " : "", + img->alias ? img->alias : img->name, img->class, img, + img->menu_prefix, + img->unsupport ? "unsupport_menuentry" : "common_menuentry"); + } + else + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, + "menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%p\" {\n" + " %s_%s \n" + "}\n", + img->unsupport ? "[***********] " : "", + img->alias ? img->alias : img->name, img->class, img, + img->menu_prefix, + img->unsupport ? "unsupport_menuentry" : "common_menuentry"); + } + } + + if (node != &g_img_iterator_head) + { + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, "}\n"); + } + + node->done = 1; + return 0; +} + +static int hiperiso_set_default_menu(void) +{ + int img_len = 0; + char *pos = NULL; + char *end = NULL; + char *def = NULL; + const char *strdata = NULL; + img_info *cur = NULL; + img_info *default_node = NULL; + const char *default_image = NULL; + + default_image = hiperiso_get_env("HISO_DEFAULT_IMAGE"); + if (default_image && default_image[0] == '/') + { + img_len = grub_strlen(default_image); + + for (cur = g_hiperiso_img_list; cur; cur = cur->next) + { + if (img_len == cur->pathlen && grub_strcmp(default_image, cur->path) == 0) + { + default_node = cur; + break; + } + } + + if (!default_node) + { + return 1; + } + + if (0 == g_default_menu_mode) + { + hiso_ssprintf(g_list_script_buf, g_list_script_pos, "set default='VID_%p'\n", default_node); + } + else + { + def = grub_strdup(default_image); + if (!def) + { + return 1; + } + + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, "set default=%c", '\''); + + strdata = hiperiso_get_env("HISO_DEFAULT_SEARCH_ROOT"); + if (strdata && strdata[0] == '/') + { + pos = def + grub_strlen(strdata); + if (*pos == '/') + { + pos++; + } + } + else + { + pos = def + 1; + } + + while ((end = grub_strchr(pos, '/')) != NULL) + { + *end = 0; + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, "DIR_%s>", pos); + pos = end + 1; + } + + hiso_ssprintf(g_tree_script_buf, g_tree_script_pos, "VID_%p'\n", default_node); + grub_free(def); + } + } + + return 0; +} + +static grub_err_t hiperiso_cmd_clear_img(grub_extcmd_context_t ctxt, int argc, char **args) +{ + img_info *next = NULL; + img_info *cur = g_hiperiso_img_list; + + (void)ctxt; + (void)argc; + (void)args; + + while (cur) + { + next = cur->next; + grub_free(cur); + cur = next; + } + + g_hiperiso_img_list = NULL; + g_hiperiso_img_count = 0; + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_img_name(grub_extcmd_context_t ctxt, int argc, char **args) +{ + long img_id = 0; + img_info *cur = g_hiperiso_img_list; + + (void)ctxt; + + if (argc != 2 || (!hiperiso_is_decimal(args[0]))) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {imageID} {var}", cmd_raw_name); + } + + img_id = grub_strtol(args[0], NULL, 10); + if (img_id >= g_hiperiso_img_count) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "No such many images %ld %ld", img_id, g_hiperiso_img_count); + } + + debug("Find image %ld name \n", img_id); + + while (cur && img_id > 0) + { + img_id--; + cur = cur->next; + } + + if (!cur) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "No such many images"); + } + + debug("image name is %s\n", cur->name); + + grub_env_set(args[1], cur->name); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_ext_select_img_path(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len = 0; + char id[32] = {0}; + img_info *cur = g_hiperiso_img_list; + + (void)ctxt; + + if (argc != 1) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {var}", cmd_raw_name); + } + + len = (int)grub_strlen(args[0]); + + while (cur) + { + if (len == cur->pathlen && 0 == grub_strcmp(args[0], cur->path)) + { + break; + } + cur = cur->next; + } + + if (!cur) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "No such image"); + } + + grub_snprintf(id, sizeof(id), "VID_%p", cur); + grub_env_set("chosen", id); + grub_env_export("chosen"); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static char g_fake_vlnk_src[512]; +static char g_fake_vlnk_dst[512]; +static grub_uint64_t g_fake_vlnk_size; +static grub_err_t hiperiso_cmd_set_fake_vlnk(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_fake_vlnk_size = (grub_uint64_t)grub_strtoull(args[2], NULL, 10); + + grub_strncpy(g_fake_vlnk_dst, args[0], sizeof(g_fake_vlnk_dst)); + grub_snprintf(g_fake_vlnk_src, sizeof(g_fake_vlnk_src), "%s/________HIPERISOVLNK.vlnk.%s", g_iso_path, args[1]); + + grub_file_hiso_vlnk(g_fake_vlnk_src, g_fake_vlnk_dst); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_reset_fake_vlnk(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_fake_vlnk_src[0] = 0; + g_fake_vlnk_dst[0] = 0; + g_fake_vlnk_size = 0; + grub_file_hiso_vlnk(NULL, NULL); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + + +static grub_err_t hiperiso_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char value[32]; + char *pos = NULL; + char *last = NULL; + const char *id = NULL; + img_info *cur = NULL; + + (void)ctxt; + + if (argc < 1 || argc > 3) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {var}", cmd_raw_name); + } + + if (g_fake_vlnk_src[0] && g_fake_vlnk_dst[0]) + { + pos = grub_strchr(g_fake_vlnk_src, '/'); + grub_env_set(args[0], pos); + if (argc > 1) + { + grub_snprintf(value, sizeof(value), "%llu", (ulonglong)(g_fake_vlnk_size)); + grub_env_set(args[1], value); + } + + if (argc > 2) + { + for (last = pos; *pos; pos++) + { + if (*pos == '/') + { + last = pos; + } + } + grub_env_set(args[2], last + 1); + } + + goto end; + } + + id = grub_env_get("chosen"); + + pos = grub_strstr(id, "VID_"); + if (pos) + { + cur = (img_info *)(void *)grub_strtoul(pos + 4, NULL, 16); + } + else + { + cur = g_hiperiso_img_list; + } + + if (!cur) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "No such image"); + } + + grub_env_set(args[0], cur->path); + + if (argc > 1) + { + grub_snprintf(value, sizeof(value), "%llu", (ulonglong)(cur->size)); + grub_env_set(args[1], value); + } + + if (argc > 2) + { + grub_snprintf(value, sizeof(value), "%llu", (ulonglong)(cur->size)); + grub_env_set(args[2], cur->name); + } + +end: + g_svd_replace_offset = 0; + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + + +static grub_err_t hiperiso_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len; + grub_fs_t fs; + grub_device_t dev = NULL; + img_info *cur = NULL; + img_info *tail = NULL; + img_info *min = NULL; + img_info *head = NULL; + const char *strdata = NULL; + char *device_name = NULL; + char buf[32]; + img_iterator_node *node = NULL; + img_iterator_node *tmp = NULL; + + (void)ctxt; + + if (argc != 2) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {device} {cntvar}", cmd_raw_name); + } + + if (g_hiperiso_img_list || g_hiperiso_img_count) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Must clear image before list"); + } + + HISO_CMD_CHECK(1); + + g_enumerate_time_checked = 0; + g_enumerate_start_time_ms = grub_get_time_ms(); + + strdata = hiperiso_get_env("HISO_FILT_DOT_UNDERSCORE_FILE"); + if (strdata && strdata[0] == '1' && strdata[1] == 0) + { + g_filt_dot_underscore_file = 1; + } + + strdata = hiperiso_get_env("HISO_FILT_TRASH_DIR"); + if (strdata && strdata[0] == '0' && strdata[1] == 0) + { + g_filt_trash_dir = 0; + } + + strdata = hiperiso_get_env("HISO_SORT_CASE_SENSITIVE"); + if (strdata && strdata[0] == '1' && strdata[1] == 0) + { + g_sort_case_sensitive = 1; + } + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + goto fail; + } + + g_enum_dev = dev = grub_device_open(device_name); + if (!dev) + { + goto fail; + } + + g_enum_fs = fs = grub_fs_probe(dev); + if (!fs) + { + goto fail; + } + + if (hiperiso_get_fs_type(fs->name) >= hiperiso_fs_max) + { + debug("unsupported fs:<%s>\n", fs->name); + hiperiso_set_env("HISO_NO_ISO_TIP", "unsupported file system"); + goto fail; + } + + hiperiso_set_env("hiso_iso_fs", fs->name); + + strdata = hiperiso_get_env("HISO_DEFAULT_MENU_MODE"); + if (strdata && strdata[0] == '1') + { + g_default_menu_mode = 1; + } + + grub_memset(&g_img_iterator_head, 0, sizeof(g_img_iterator_head)); + + grub_snprintf(g_iso_path, sizeof(g_iso_path), "%s", args[0]); + + strdata = hiperiso_get_env("HISO_DEFAULT_SEARCH_ROOT"); + if (strdata && strdata[0] == '/') + { + len = grub_snprintf(g_img_iterator_head.dir, sizeof(g_img_iterator_head.dir) - 1, "%s", strdata); + if (g_img_iterator_head.dir[len - 1] != '/') + { + g_img_iterator_head.dir[len++] = '/'; + } + g_img_iterator_head.dirlen = len; + } + else + { + g_img_iterator_head.dirlen = 1; + grub_strcpy(g_img_iterator_head.dir, "/"); + } + + g_img_iterator_head.tail = &tail; + + if (g_img_max_search_level < 0) + { + g_img_max_search_level = GRUB_INT_MAX; + strdata = hiperiso_get_env("HISO_MAX_SEARCH_LEVEL"); + if (strdata && hiperiso_is_decimal(strdata)) + { + g_img_max_search_level = (int)grub_strtoul(strdata, NULL, 10); + } + } + + g_hiso_file_flt[HISO_FILE_FLT_ISO] = hiperiso_control_get_flag("HISO_FILE_FLT_ISO"); + g_hiso_file_flt[HISO_FILE_FLT_WIM] = hiperiso_control_get_flag("HISO_FILE_FLT_WIM"); + g_hiso_file_flt[HISO_FILE_FLT_EFI] = hiperiso_control_get_flag("HISO_FILE_FLT_EFI"); + g_hiso_file_flt[HISO_FILE_FLT_IMG] = hiperiso_control_get_flag("HISO_FILE_FLT_IMG"); + g_hiso_file_flt[HISO_FILE_FLT_VHD] = hiperiso_control_get_flag("HISO_FILE_FLT_VHD"); + g_hiso_file_flt[HISO_FILE_FLT_HISO] = hiperiso_control_get_flag("HISO_FILE_FLT_HISO"); + + for (node = &g_img_iterator_head; node; node = node->next) + { + fs->fs_dir(dev, node->dir, hiperiso_collect_img_files, node); + } + + strdata = hiperiso_get_env("HISO_TREE_VIEW_MENU_STYLE"); + if (strdata && strdata[0] == '1' && strdata[1] == 0) + { + g_tree_view_menu_style = 1; + } + + hiperiso_set_default_menu(); + + for (node = &g_img_iterator_head; node; node = node->next) + { + hiperiso_dynamic_tree_menu(node); + } + + /* free node */ + node = g_img_iterator_head.next; + while (node) + { + tmp = node->next; + grub_free(node); + node = tmp; + } + + /* sort image list by image name */ + while (g_hiperiso_img_list) + { + min = g_hiperiso_img_list; + for (cur = g_hiperiso_img_list->next; cur; cur = cur->next) + { + if (hiperiso_cmp_img(min, cur) > 0) + { + min = cur; + } + } + + if (min->prev) + { + min->prev->next = min->next; + } + + if (min->next) + { + min->next->prev = min->prev; + } + + if (min == g_hiperiso_img_list) + { + g_hiperiso_img_list = min->next; + } + + if (head == NULL) + { + head = tail = min; + min->prev = NULL; + min->next = NULL; + } + else + { + tail->next = min; + min->prev = tail; + min->next = NULL; + tail = min; + } + } + + g_hiperiso_img_list = head; + + if (g_default_menu_mode == 1) + { + hiso_ssprintf(g_list_script_buf, g_list_script_pos, + "menuentry \"%s [%s]\" --class=\"hisoret\" HISO_RET {\n " + " echo 'return ...' \n" + "}\n", "<--", hiperiso_get_vmenu_title("VTLANG_RET_TO_TREEVIEW")); + } + + for (cur = g_hiperiso_img_list; cur; cur = cur->next) + { + hiso_ssprintf(g_list_script_buf, g_list_script_pos, + "menuentry \"%s%s\" --class=\"%s\" --id=\"VID_%p\" {\n" + " %s_%s \n" + "}\n", + cur->unsupport ? "[***********] " : "", + cur->alias ? cur->alias : cur->name, cur->class, cur, + cur->menu_prefix, + cur->unsupport ? "unsupport_menuentry" : "common_menuentry"); + } + + g_tree_script_buf[g_tree_script_pos] = 0; + g_list_script_buf[g_list_script_pos] = 0; + + grub_snprintf(buf, sizeof(buf), "%d", g_hiperiso_img_count); + grub_env_set(args[1], buf); + +fail: + + check_free(device_name, grub_free); + check_free(dev, grub_device_close); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +int hiperiso_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t *signature) +{ + grub_disk_t disk; + char *device_name; + char *pos; + char *pos2; + + device_name = grub_file_get_device_name(filename); + if (!device_name) + { + return 1; + } + + pos = device_name; + if (pos[0] == '(') + { + pos++; + } + + pos2 = grub_strstr(pos, ","); + if (!pos2) + { + pos2 = grub_strstr(pos, ")"); + } + + if (pos2) + { + *pos2 = 0; + } + + disk = grub_disk_open(pos); + if (disk) + { + grub_disk_read(disk, 0, 0x180, 16, guid); + grub_disk_read(disk, 0, 0x1b8, 4, signature); + grub_disk_close(disk); + } + else + { + return 1; + } + + grub_free(device_name); + return 0; +} + +grub_uint32_t hiperiso_get_iso_boot_catlog(grub_file_t file) +{ + eltorito_descriptor desc; + + grub_memset(&desc, 0, sizeof(desc)); + grub_file_seek(file, 17 * 2048); + grub_file_read(file, &desc, sizeof(desc)); + + if (desc.type != 0 || desc.version != 1) + { + return 0; + } + + if (grub_strncmp((char *)desc.id, "CD001", 5) != 0 || + grub_strncmp((char *)desc.system_id, "EL TORITO SPECIFICATION", 23) != 0) + { + return 0; + } + + return desc.sector; +} + +static grub_uint32_t hiperiso_get_bios_eltorito_rba(grub_file_t file, grub_uint32_t sector) +{ + grub_uint8_t buf[512]; + + grub_file_seek(file, sector * 2048); + grub_file_read(file, buf, sizeof(buf)); + + if (buf[0] == 0x01 && buf[1] == 0x00 && + buf[30] == 0x55 && buf[31] == 0xaa && buf[32] == 0x88) + { + return *((grub_uint32_t *)(buf + 40)); + } + + return 0; +} + +int hiperiso_has_efi_eltorito(grub_file_t file, grub_uint32_t sector) +{ + int i; + int x86count = 0; + grub_uint8_t buf[512]; + grub_uint8_t parttype[] = { 0x04, 0x06, 0x0B, 0x0C }; + + grub_file_seek(file, sector * 2048); + grub_file_read(file, buf, sizeof(buf)); + + if (buf[0] == 0x01 && buf[1] == 0xEF) + { + debug("%s efi eltorito in Validation Entry\n", file->name); + return 1; + } + + if (buf[0] == 0x01 && buf[1] == 0x00) + { + x86count++; + } + + for (i = 64; i < (int)sizeof(buf); i += 32) + { + if ((buf[i] == 0x90 || buf[i] == 0x91) && buf[i + 1] == 0xEF) + { + debug("%s efi eltorito offset %d 0x%02x\n", file->name, i, buf[i]); + return 1; + } + + if ((buf[i] == 0x90 || buf[i] == 0x91) && buf[i + 1] == 0x00 && x86count == 1) + { + debug("0x9100 assume %s efi eltorito offset %d 0x%02x\n", file->name, i, buf[i]); + return 1; + } + } + + if (x86count && buf[32] == 0x88 && buf[33] == 0x04) + { + for (i = 0; i < (int)(ARRAY_SIZE(parttype)); i++) + { + if (buf[36] == parttype[i]) + { + debug("hard disk image assume %s efi eltorito, part type 0x%x\n", file->name, buf[36]); + return 1; + } + } + } + + debug("%s does not contain efi eltorito\n", file->name); + return 0; +} + +void hiperiso_fill_os_param(grub_file_t file, hiperiso_os_param *param) +{ + char *pos; + const char *fs = NULL; + const char *val = NULL; + const char *cdprompt = NULL; + grub_uint32_t i; + grub_uint8_t chksum = 0; + grub_disk_t disk; + + disk = file->device->disk; + grub_memcpy(¶m->guid, &g_hiperiso_guid, sizeof(hiperiso_guid)); + + param->hiso_disk_size = disk->total_sectors * (1 << disk->log_sector_size); + param->hiso_disk_part_id = disk->partition->number + 1; + param->hiso_disk_part_type = hiperiso_get_fs_type(file->fs->name); + + pos = grub_strstr(file->name, "/"); + if (!pos) + { + pos = file->name; + } + + grub_snprintf(param->hiso_img_path, sizeof(param->hiso_img_path), "%s", pos); + + hiperiso_get_disk_guid(file->name, param->hiso_disk_guid, param->hiso_disk_signature); + + param->hiso_img_size = file->size; + + param->hiso_reserved[0] = g_hiperiso_break_level; + param->hiso_reserved[1] = g_hiperiso_debug_level; + + param->hiso_reserved[2] = g_hiperiso_chain_type; + + /* Windows CD/DVD prompt 0:suppress 1:reserved */ + param->hiso_reserved[4] = 0; + if (g_hiperiso_chain_type == 1) /* Windows */ + { + cdprompt = hiperiso_get_env("HISO_WINDOWS_CD_PROMPT"); + if (cdprompt && cdprompt[0] == '1' && cdprompt[1] == 0) + { + param->hiso_reserved[4] = 1; + } + } + + fs = hiperiso_get_env("hiperiso_fs_probe"); + if (fs && grub_strcmp(fs, "udf") == 0) + { + param->hiso_reserved[3] = 1; + } + + param->hiso_reserved[5] = 0; + val = hiperiso_get_env("HISO_LINUX_REMOUNT"); + if (val && val[0] == '1' && val[1] == 0) + { + param->hiso_reserved[5] = 1; + } + + /* hiperiso_disk_signature used for vlnk */ + param->hiso_reserved[6] = file->vlnk; + grub_memcpy(param->hiso_reserved + 7, g_hiperiso_part_info->MBR.BootCode + 0x1b8, 4); + + + /* Windows UEFI force resolution lock */ + if (g_hiperiso_chain_type == 1) /* Windows */ + { + val = hiperiso_get_env("HISO_WIN_UEFI_RES_LOCK"); + if (val && val[1] == 0) + { + if (val[0] == '1') + { + param->hiso_reserved[11] = 1; + } + else if (val[0] == '2') + { + param->hiso_reserved[11] = 2; + } + } + } + + + /* calculate checksum */ + for (i = 0; i < sizeof(hiperiso_os_param); i++) + { + chksum += *((grub_uint8_t *)param + i); + } + param->chksum = (grub_uint8_t)(0x100 - chksum); + + return; +} + +static const char* g_chunk_err_msg[HISO_CHUNK_ERR_MAX] = +{ + "success", + "File system use more than 1 disks! (maybe RAID)", + "File system enable RAID feature, this is NOT supported!", + "File is compressed in disk, this is not supported!", + "File not flat in disk! (maybe compressed)", + "Read buffer overflow!", +}; + +static const char * hiperiso_get_chunk_err_msg(grub_uint32_t err) +{ + if (err < HISO_CHUNK_ERR_MAX) + { + return g_chunk_err_msg[err]; + } + + return "XXXX"; +} + +int hiperiso_check_block_list(grub_file_t file, hiperiso_img_chunk_list *chunklist, +grub_disk_addr_t start, char *err, grub_uint32_t len) +{ + grub_uint32_t i = 0; + grub_uint64_t total = 0; + grub_uint64_t fileblk = 0; + hiperiso_img_chunk *chunk = NULL; + + if (chunklist->err_code) + { + if (err) + { + grub_snprintf(err, len, "%s", hiperiso_get_chunk_err_msg(chunklist->err_code)); + } + + return 1; + } + + if (err) + { + grub_snprintf(err, len, "Unsupported chunk list."); + } + + for (i = 0; i < chunklist->cur_chunk; i++) + { + chunk = chunklist->chunk + i; + + if (chunk->disk_start_sector <= start) + { + debug("%u disk start invalid %lu\n", i, (ulong)start); + return 1; + } + + total += chunk->disk_end_sector + 1 - chunk->disk_start_sector; + } + + fileblk = (file->size + 511) / 512; + + if (total != fileblk) + { + debug("Invalid total: %llu %llu\n", (ulonglong)total, (ulonglong)fileblk); + if ((file->size % 512) && (total + 1 == fileblk)) + { + debug("maybe img file to be processed.\n"); + return 0; + } + + return 1; + } + + return 0; +} + +int hiperiso_get_block_list(grub_file_t file, hiperiso_img_chunk_list *chunklist, grub_disk_addr_t start) +{ + int fs_type; + int len; + grub_uint32_t i = 0; + grub_uint32_t sector = 0; + grub_uint32_t count = 0; + grub_off_t size = 0; + grub_off_t read = 0; + + fs_type = hiperiso_get_fs_type(file->fs->name); + if (fs_type == hiperiso_fs_exfat) + { + grub_fat_get_file_chunk(start, file, chunklist); + } + else if (fs_type == hiperiso_fs_ext) + { + grub_ext_get_file_chunk(start, file, chunklist); + } + else if (fs_type == hiperiso_fs_btrfs) + { + grub_btrfs_get_file_chunk(start, file, chunklist); + } + else + { + file->read_hook = (grub_disk_read_hook_t)(void *)grub_disk_blocklist_read; + file->read_hook_data = chunklist; + + for (size = file->size; size > 0; size -= read) + { + read = (size > HISO_SIZE_1GB) ? HISO_SIZE_1GB : size; + grub_file_read(file, NULL, read); + } + + for (i = 0; start > 0 && i < chunklist->cur_chunk; i++) + { + chunklist->chunk[i].disk_start_sector += start; + chunklist->chunk[i].disk_end_sector += start; + } + + if (hiperiso_fs_udf == fs_type) + { + for (i = 0; i < chunklist->cur_chunk; i++) + { + count = (chunklist->chunk[i].disk_end_sector + 1 - chunklist->chunk[i].disk_start_sector) >> 2; + chunklist->chunk[i].img_start_sector = sector; + chunklist->chunk[i].img_end_sector = sector + count - 1; + sector += count; + } + } + } + + len = (int)grub_strlen(file->name); + if ((len > 4 && grub_strncasecmp(file->name + len - 4, ".img", 4) == 0) || + (len > 4 && grub_strncasecmp(file->name + len - 4, ".vhd", 4) == 0) || + (len > 5 && grub_strncasecmp(file->name + len - 5, ".vhdx", 5) == 0) || + (len > 5 && grub_strncasecmp(file->name + len - 5, ".hiso", 5) == 0)) + { + for (i = 0; i < chunklist->cur_chunk; i++) + { + count = chunklist->chunk[i].disk_end_sector + 1 - chunklist->chunk[i].disk_start_sector; + if (count < 4) + { + count = 1; + } + else + { + count >>= 2; + } + + chunklist->chunk[i].img_start_sector = sector; + chunklist->chunk[i].img_end_sector = sector + count - 1; + sector += count; + } + } + + return 0; +} + +static grub_err_t hiperiso_cmd_img_sector(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc; + int fs_type; + grub_file_t file; + grub_disk_addr_t start; + char errmsg[128]; + + (void)ctxt; + (void)argc; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]); + } + + g_conf_replace_count = 0; + grub_memset(g_conf_replace_node, 0, sizeof(g_conf_replace_node )); + grub_memset(g_conf_replace_offset, 0, sizeof(g_conf_replace_offset )); + + if (g_img_chunk_list.chunk) + { + grub_free(g_img_chunk_list.chunk); + } + + fs_type = hiperiso_get_fs_type(file->fs->name); + if (fs_type >= hiperiso_fs_max) + { + grub_file_close(file); + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Unsupported filesystem %s\n", file->fs->name); + } + + /* get image chunk data */ + grub_memset(&g_img_chunk_list, 0, sizeof(g_img_chunk_list)); + g_img_chunk_list.chunk = grub_malloc(sizeof(hiperiso_img_chunk) * DEFAULT_CHUNK_NUM); + if (NULL == g_img_chunk_list.chunk) + { + return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Can't allocate image chunk memoty\n"); + } + + g_img_chunk_list.max_chunk = DEFAULT_CHUNK_NUM; + g_img_chunk_list.cur_chunk = 0; + + start = file->device->disk->partition->start; + + hiperiso_get_block_list(file, &g_img_chunk_list, start); + + rc = hiperiso_check_block_list(file, &g_img_chunk_list, start, errmsg, sizeof(errmsg)); + grub_file_close(file); + + if (rc) + { + if (fs_type == hiperiso_fs_btrfs) + { + hiso_tip(10, "%s\n\nWill exit in 10 seconds...\n", errmsg); + grub_exit(); + } + return grub_error(GRUB_ERR_NOT_IMPLEMENTED_YET, "%s\n", errmsg); + } + + grub_memset(&g_grub_param->file_replace, 0, sizeof(g_grub_param->file_replace)); + grub_memset(&g_grub_param->img_replace, 0, sizeof(g_grub_param->img_replace)); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_select_conf_replace(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int n; + grub_uint64_t offset = 0; + grub_uint32_t align = 0; + grub_file_t file = NULL; + conf_replace *node = NULL; + conf_replace *nodes[HISO_MAX_CONF_REPLACE] = { NULL }; + hiperiso_grub_param_file_replace *replace = NULL; + + (void)ctxt; + (void)argc; + (void)args; + + debug("select conf replace argc:%d\n", argc); + + if (argc < 2) + { + return 0; + } + + n = hiperiso_plugin_find_conf_replace(args[1], nodes); + if (!n) + { + debug("Conf replace not found for %s\n", args[1]); + goto end; + } + + debug("Find %d conf replace for %s\n", n, args[1]); + + g_conf_replace_count = n; + for (i = 0; i < n; i++) + { + node = nodes[i]; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "(loop)%s", node->orgconf); + if (file) + { + offset = grub_iso9660_get_last_file_dirent_pos(file); + grub_file_close(file); + } + else if (node->img > 0) + { + offset = 0; + } + else + { + debug("<(loop)%s> NOT exist\n", node->orgconf); + continue; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", args[0], node->newconf); + if (!file) + { + debug("New config file <%s%s> NOT exist\n", args[0], node->newconf); + continue; + } + + align = ((int)file->size + 2047) / 2048 * 2048; + + if (align > hiso_max_replace_file_size) + { + debug("New config file <%s%s> too big\n", args[0], node->newconf); + grub_file_close(file); + continue; + } + + grub_file_read(file, g_conf_replace_new_buf[i], file->size); + grub_file_close(file); + g_conf_replace_new_len[i] = (int)file->size; + g_conf_replace_new_len_align[i] = align; + + g_conf_replace_node[i] = node; + g_conf_replace_offset[i] = offset + 2; + + if (node->img > 0) + { + replace = &(g_grub_param->img_replace[i]); + replace->magic = GRUB_IMG_REPLACE_MAGIC; + grub_snprintf(replace->old_file_name[replace->old_name_cnt], 256, "%s", node->orgconf); + replace->old_name_cnt++; + } + + debug("conf_replace OK: newlen[%d]: %d img:%d\n", i, g_conf_replace_new_len[i], node->img); + } + +end: + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_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 hiperiso_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 >= HISO_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, HISO_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 = hiperiso_get_line(curline); + + start = grub_strstr(curline, "$$"); + if (start) + { + end = grub_strstr(start + 2, "$$"); + } + + if (start && end) + { + *start = *end = 0; + HISO_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; + hiperiso_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; + } + } + } + + HISO_APPEND_NEWBUF(value); + + HISO_APPEND_NEWBUF(end + 2); + } + else + { + HISO_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 hiperiso_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; + + (void)ctxt; + (void)argc; + (void)args; + + debug("select auto installation argc:%d\n", argc); + + if (argc < 1) + { + return 0; + } + + node = hiperiso_plugin_find_install_template(args[0]); + if (!node) + { + debug("Auto install template not found for %s\n", args[0]); + return 0; + } + + if (node->autosel >= 0 && node->autosel <= node->templatenum) + { + defidx = node->autosel; + if (node->timeout < 0) + { + node->cursel = node->autosel - 1; + debug("Auto install template auto select %d\n", node->autosel); + goto load; + } + } + + buf = (char *)grub_malloc(HISO_MAX_SCRIPT_BUF); + if (!buf) + { + return 0; + } + + if (node->timeout > 0) + { + hiso_ssprintf(buf, pos, "set timeout=%d\n", node->timeout); + } + + hiso_ssprintf(buf, pos, "menuentry \"$VTLANG_NO_AUTOINS_SCRIPT\" --class=\"sel_auto_install\" {\n" + " echo %s\n}\n", ""); + + for (i = 0; i < node->templatenum; i++) + { + hiso_ssprintf(buf, pos, "menuentry \"%s %s\" --class=\"sel_auto_install\" {\n" + " echo \"\"\n}\n", + hiperiso_get_vmenu_title("VTLANG_AUTOINS_USE"), + node->templatepath[i].path); + } + + g_hiperiso_menu_esc = 1; + g_hiperiso_suppress_esc = 1; + g_hiperiso_suppress_esc_default = defidx; + g_hiperiso_secondary_menu_on = 1; + + grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos); + grub_script_execute_sourcecode(configfile); + + g_hiperiso_menu_esc = 0; + g_hiperiso_suppress_esc = 0; + g_hiperiso_suppress_esc_default = 1; + g_hiperiso_secondary_menu_on = 0; + + grub_free(buf); + + node->cursel = g_hiperiso_last_entry - 1; + +load: + grub_check_free(node->filebuf); + node->filelen = 0; + + if (node->cursel >= 0 && node->cursel < node->templatenum) + { + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", hiperiso_get_env("hiso_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; + + hiperiso_auto_install_var_expand(node); + } + } + else + { + debug("Failed to open auto install script <%s%s>\n", + hiperiso_get_env("hiso_iso_part"), node->templatepath[node->cursel].path); + } + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_sel_persistence(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i = 0; + int pos = 0; + int defidx = 1; + char *buf = NULL; + char configfile[128]; + persistence_config *node; + + (void)ctxt; + (void)argc; + (void)args; + + debug("select persistence argc:%d\n", argc); + + if (argc < 1) + { + return 0; + } + + node = hiperiso_plugin_find_persistent(args[0]); + if (!node) + { + debug("Persistence image not found for %s\n", args[0]); + return 0; + } + + if (node->autosel >= 0 && node->autosel <= node->backendnum) + { + defidx = node->autosel; + if (node->timeout < 0) + { + node->cursel = node->autosel - 1; + debug("Persistence image auto select %d\n", node->autosel); + return 0; + } + } + + buf = (char *)grub_malloc(HISO_MAX_SCRIPT_BUF); + if (!buf) + { + return 0; + } + + if (node->timeout > 0) + { + hiso_ssprintf(buf, pos, "set timeout=%d\n", node->timeout); + } + + hiso_ssprintf(buf, pos, "menuentry \"$VTLANG_NO_PERSIST\" --class=\"sel_persistence\" {\n" + " echo %s\n}\n", ""); + + for (i = 0; i < node->backendnum; i++) + { + hiso_ssprintf(buf, pos, "menuentry \"%s %s\" --class=\"sel_persistence\" {\n" + " echo \"\"\n}\n", + hiperiso_get_vmenu_title("VTLANG_PERSIST_USE"), + node->backendpath[i].path); + + } + + g_hiperiso_menu_esc = 1; + g_hiperiso_suppress_esc = 1; + g_hiperiso_suppress_esc_default = defidx; + g_hiperiso_secondary_menu_on = 1; + + grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, pos); + grub_script_execute_sourcecode(configfile); + + g_hiperiso_menu_esc = 0; + g_hiperiso_suppress_esc = 0; + g_hiperiso_suppress_esc_default = 1; + g_hiperiso_secondary_menu_on = 0; + + grub_free(buf); + + node->cursel = g_hiperiso_last_entry - 1; + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_dump_img_sector(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint32_t i; + hiperiso_img_chunk *cur; + + (void)ctxt; + (void)argc; + (void)args; + + for (i = 0; i < g_img_chunk_list.cur_chunk; i++) + { + cur = g_img_chunk_list.chunk + i; + grub_printf("image:[%u - %u] <==> disk:[%llu - %llu]\n", + cur->img_start_sector, cur->img_end_sector, + (unsigned long long)cur->disk_start_sector, (unsigned long long)cur->disk_end_sector + ); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_test_block_list(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint32_t i; + grub_file_t file; + hiperiso_img_chunk_list chunklist; + char errmsg[128]; + + (void)ctxt; + (void)argc; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s\n", args[0]); + } + + /* get image chunk data */ + grub_memset(&chunklist, 0, sizeof(chunklist)); + chunklist.chunk = grub_malloc(sizeof(hiperiso_img_chunk) * DEFAULT_CHUNK_NUM); + if (NULL == chunklist.chunk) + { + return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Can't allocate image chunk memoty\n"); + } + + chunklist.max_chunk = DEFAULT_CHUNK_NUM; + chunklist.cur_chunk = 0; + + hiperiso_get_block_list(file, &chunklist, 0); + + if (0 != hiperiso_check_block_list(file, &chunklist, 0, errmsg, sizeof(errmsg))) + { + grub_printf("%s\n", errmsg); + grub_printf("########## UNSUPPORTED ###############\n"); + } + + grub_printf("filesystem: <%s> entry number:<%u>\n", file->fs->name, chunklist.cur_chunk); + + for (i = 0; i < chunklist.cur_chunk; i++) + { + grub_printf("%llu+%llu,", (ulonglong)chunklist.chunk[i].disk_start_sector, + (ulonglong)(chunklist.chunk[i].disk_end_sector + 1 - chunklist.chunk[i].disk_start_sector)); + } + + grub_printf("\n==================================\n"); + + for (i = 0; i < chunklist.cur_chunk; i++) + { + grub_printf("%2u: [%llu %llu] - [%llu %llu]\n", i, + (ulonglong)chunklist.chunk[i].img_start_sector, + (ulonglong)chunklist.chunk[i].img_end_sector, + (ulonglong)chunklist.chunk[i].disk_start_sector, + (ulonglong)chunklist.chunk[i].disk_end_sector + ); + } + + grub_free(chunklist.chunk); + grub_file_close(file); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_add_replace_file(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + hiperiso_grub_param_file_replace *replace = NULL; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc >= 2) + { + replace = &(g_grub_param->file_replace); + replace->magic = GRUB_FILE_REPLACE_MAGIC; + + replace->old_name_cnt = 0; + for (i = 0; i < 4 && i + 1 < argc; i++) + { + replace->old_name_cnt++; + grub_snprintf(replace->old_file_name[i], sizeof(replace->old_file_name[i]), "%s", args[i + 1]); + } + + replace->new_file_virtual_id = (grub_uint32_t)grub_strtoul(args[0], NULL, 10); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_get_replace_file_cnt(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char buf[32]; + hiperiso_grub_param_file_replace *replace = &(g_grub_param->file_replace); + + (void)ctxt; + + if (argc >= 1) + { + grub_snprintf(buf, sizeof(buf), "%u", replace->old_name_cnt); + grub_env_set(args[0], buf); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_dump_menu(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + if (argc == 0) + { + grub_printf("List Mode: CurLen:%d MaxLen:%u\n", g_list_script_pos, HISO_MAX_SCRIPT_BUF); + grub_printf("%s", g_list_script_buf); + } + else + { + grub_printf("Tree Mode: CurLen:%d MaxLen:%u\n", g_tree_script_pos, HISO_MAX_SCRIPT_BUF); + grub_printf("%s", g_tree_script_buf); + } + + return 0; +} + +static grub_err_t hiperiso_cmd_dump_img_list(grub_extcmd_context_t ctxt, int argc, char **args) +{ + img_info *cur = g_hiperiso_img_list; + + (void)ctxt; + (void)argc; + (void)args; + + while (cur) + { + grub_printf("path:<%s> id=%d list_index=%d\n", cur->path, cur->id, cur->plugin_list_index); + grub_printf("name:<%s>\n\n", cur->name); + cur = cur->next; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_dump_injection(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + hiperiso_plugin_dump_injection(); + + return 0; +} + +static grub_err_t hiperiso_cmd_dump_auto_install(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + hiperiso_plugin_dump_auto_install(); + + return 0; +} + +static grub_err_t hiperiso_cmd_dump_persistence(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + hiperiso_plugin_dump_persistence(); + + return 0; +} + +static int hiperiso_check_mode_by_name(char *filename, const char *suffix) +{ + int i; + int len1; + int len2; + + len1 = (int)grub_strlen(filename); + len2 = (int)grub_strlen(suffix); + + if (len1 <= len2) + { + return 0; + } + + for (i = len1 - 1; i >= 0; i--) + { + if (filename[i] == '.') + { + break; + } + } + + if (i < len2 + 1) + { + return 0; + } + + if (filename[i - len2 - 1] != '_') + { + return 0; + } + + if (grub_strncasecmp(filename + (i - len2), suffix, len2) == 0) + { + return 1; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 1 && argc != 2) + { + return 1; + } + + if (args[0][0] == '0') + { + if (g_hiperiso_memdisk_mode) + { + return 0; + } + + if (argc == 2 && hiperiso_check_mode_by_name(args[1], "vtmemdisk")) + { + return 0; + } + + return 1; + } + else if (args[0][0] == '1') + { + return g_hiperiso_iso_raw ? 0 : 1; + } + else if (args[0][0] == '2') + { + return g_hiperiso_iso_uefi_drv ? 0 : 1; + } + else if (args[0][0] == '3') + { + if (g_hiperiso_grub2_mode) + { + return 0; + } + + if (argc == 2 && hiperiso_check_mode_by_name(args[1], "vtgrub2")) + { + return 0; + } + + return 1; + } + else if (args[0][0] == '4') + { + if (g_hiperiso_wimboot_mode) + { + return 0; + } + + if (argc == 2 && hiperiso_check_mode_by_name(args[1], "vtwimboot")) + { + return 0; + } + + return 1; + } + + return 1; +} + +static grub_err_t hiperiso_cmd_dynamic_menu(grub_extcmd_context_t ctxt, int argc, char **args) +{ + static int configfile_mode = 0; + char memfile[128] = {0}; + + (void)ctxt; + (void)argc; + (void)args; + + /* + * args[0]: 0:normal 1:configfile + * args[1]: 0:list_buf 1:tree_buf + */ + + if (argc != 2) + { + debug("Invalid argc %d\n", argc); + return 0; + } + + HISO_CMD_CHECK(1); + + if (args[0][0] == '0') + { + if (args[1][0] == '0') + { + grub_script_execute_sourcecode(g_list_script_buf); + } + else + { + grub_script_execute_sourcecode(g_tree_script_buf); + } + } + else + { + if (configfile_mode) + { + debug("Now already in F3 mode %d\n", configfile_mode); + return 0; + } + + if (args[1][0] == '0') + { + grub_snprintf(memfile, sizeof(memfile), "configfile mem:0x%llx:size:%d", + (ulonglong)(ulong)g_list_script_buf, g_list_script_pos); + } + else + { + g_hiperiso_last_entry = -1; + grub_snprintf(memfile, sizeof(memfile), "configfile mem:0x%llx:size:%d", + (ulonglong)(ulong)g_tree_script_buf, g_tree_script_pos); + } + + configfile_mode = 1; + grub_script_execute_sourcecode(memfile); + configfile_mode = 0; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_file_exist_nocase(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_file_t file; + + (void)ctxt; + + if (argc != 1) + { + return 1; + } + + g_hiperiso_case_insensitive = 1; + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + g_hiperiso_case_insensitive = 0; + + grub_errno = 0; + + if (file) + { + grub_file_close(file); + return 0; + } + return 1; +} + +static grub_err_t hiperiso_cmd_find_bootable_hdd(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int id = 0; + int find = 0; + grub_disk_t disk; + const char *isopath = NULL; + char hdname[32]; + hiperiso_mbr_head mbr; + + (void)ctxt; + (void)argc; + + if (argc != 1) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s variable\n", cmd_raw_name); + } + + isopath = grub_env_get("hiso_iso_part"); + if (!isopath) + { + debug("isopath is null %p\n", isopath); + return 0; + } + + debug("isopath is %s\n", isopath); + + for (id = 0; id < 30 && (find == 0); id++) + { + grub_snprintf(hdname, sizeof(hdname), "hd%d,", id); + if (grub_strstr(isopath, hdname)) + { + debug("skip %s ...\n", hdname); + continue; + } + + grub_snprintf(hdname, sizeof(hdname), "hd%d", id); + + disk = grub_disk_open(hdname); + if (!disk) + { + debug("%s not exist\n", hdname); + break; + } + + grub_memset(&mbr, 0, sizeof(mbr)); + if (0 == grub_disk_read(disk, 0, 0, 512, &mbr)) + { + if (mbr.Byte55 == 0x55 && mbr.ByteAA == 0xAA) + { + if (mbr.PartTbl[0].Active == 0x80 || mbr.PartTbl[1].Active == 0x80 || + mbr.PartTbl[2].Active == 0x80 || mbr.PartTbl[3].Active == 0x80) + { + + grub_env_set(args[0], hdname); + find = 1; + } + } + debug("%s is %s\n", hdname, find ? "bootable" : "NOT bootable"); + } + else + { + debug("read %s failed\n", hdname); + } + + grub_disk_close(disk); + } + + return 0; +} + +static grub_err_t hiperiso_cmd_read_1st_line(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len = 1024; + grub_file_t file; + char *buf = NULL; + + (void)ctxt; + (void)argc; + + if (argc != 2) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s file var \n", cmd_raw_name); + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + debug("failed to open file %s\n", args[0]); + return 0; + } + + buf = grub_malloc(len); + if (!buf) + { + goto end; + } + + buf[len - 1] = 0; + grub_file_read(file, buf, len - 1); + + hiperiso_get_line(buf); + hiperiso_set_env(args[1], buf); + +end: + + grub_check_free(buf); + grub_file_close(file); + + return 0; +} + +static int hiperiso_img_partition_callback (struct grub_disk *disk, const grub_partition_t partition, void *data) +{ + grub_uint64_t end_max = 0; + int *pCnt = (int *)data; + + (void)disk; + + (*pCnt)++; + g_part_list_pos += grub_snprintf(g_part_list_buf + g_part_list_pos, HISO_MAX_SCRIPT_BUF - g_part_list_pos, + "0 %llu linear /dev/hiperiso %llu\n", + (ulonglong)partition->len, (ulonglong)partition->start); + + end_max = (partition->len + partition->start) * 512; + if (end_max > g_part_end_max) + { + g_part_end_max = end_max; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_img_part_info(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int cnt = 0; + char *device_name = NULL; + grub_device_t dev = NULL; + char buf[64]; + + (void)ctxt; + + g_part_list_pos = 0; + g_part_end_max = 0; + grub_env_unset("hiso_img_part_file"); + + if (argc != 1) + { + return 1; + } + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + debug("hiperiso_cmd_img_part_info failed, %s\n", args[0]); + goto end; + } + + dev = grub_device_open(device_name); + if (!dev) + { + debug("grub_device_open failed, %s\n", device_name); + goto end; + } + + grub_partition_iterate(dev->disk, hiperiso_img_partition_callback, &cnt); + + grub_snprintf(buf, sizeof(buf), "newc:hiso_dm_table:mem:0x%llx:size:%d", (ulonglong)(ulong)g_part_list_buf, g_part_list_pos); + grub_env_set("hiso_img_part_file", buf); + + grub_snprintf(buf, sizeof(buf), "%d", cnt); + grub_env_set("hiso_img_part_cnt", buf); + + grub_snprintf(buf, sizeof(buf), "%llu", (ulonglong)g_part_end_max); + grub_env_set("hiso_img_max_part_end", buf); + +end: + + check_free(device_name, grub_free); + check_free(dev, grub_device_close); + + return 0; +} + + +static grub_err_t hiperiso_cmd_file_strstr(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc = 1; + grub_file_t file; + char *buf = NULL; + + (void)ctxt; + (void)argc; + + if (argc != 2) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s file str \n", cmd_raw_name); + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + debug("failed to open file %s\n", args[0]); + return 1; + } + + buf = grub_malloc(file->size + 1); + if (!buf) + { + goto end; + } + + buf[file->size] = 0; + grub_file_read(file, buf, file->size); + + if (grub_strstr(buf, args[1])) + { + rc = 0; + } + +end: + + grub_check_free(buf); + grub_file_close(file); + + return rc; +} + +static grub_err_t hiperiso_cmd_parse_volume(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len; + grub_file_t file; + char buf[64]; + grub_uint64_t size; + hiperiso_iso9660_vd pvd; + + (void)ctxt; + (void)argc; + + if (argc != 4) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s sysid volid space \n", cmd_raw_name); + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + debug("failed to open file %s\n", args[0]); + return 0; + } + + grub_file_seek(file, 16 * 2048); + len = (int)grub_file_read(file, &pvd, sizeof(pvd)); + if (len != sizeof(pvd)) + { + debug("failed to read pvd %d\n", len); + goto end; + } + + grub_memset(buf, 0, sizeof(buf)); + grub_memcpy(buf, pvd.sys, sizeof(pvd.sys)); + hiperiso_set_env(args[1], buf); + + grub_memset(buf, 0, sizeof(buf)); + grub_memcpy(buf, pvd.vol, sizeof(pvd.vol)); + hiperiso_set_env(args[2], buf); + + size = pvd.space; + size *= 2048; + grub_snprintf(buf, sizeof(buf), "%llu", (ulonglong)size); + hiperiso_set_env(args[3], buf); + +end: + grub_file_close(file); + + return 0; +} + +static grub_err_t hiperiso_cmd_parse_create_date(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len; + grub_file_t file; + char buf[64]; + + (void)ctxt; + (void)argc; + + if (argc != 2) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s var \n", cmd_raw_name); + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + debug("failed to open file %s\n", args[0]); + return 0; + } + + grub_memset(buf, 0, sizeof(buf)); + grub_file_seek(file, 16 * 2048 + 813); + len = (int)grub_file_read(file, buf, 17); + if (len != 17) + { + debug("failed to read create date %d\n", len); + goto end; + } + + hiperiso_set_env(args[1], buf); + +end: + grub_file_close(file); + + return 0; +} + +static grub_err_t hiperiso_cmd_img_hook_root(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + hiperiso_env_hook_root(1); + + return 0; +} + +static grub_err_t hiperiso_cmd_img_unhook_root(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + hiperiso_env_hook_root(0); + + return 0; +} + +#ifdef GRUB_MACHINE_EFI +static grub_err_t hiperiso_cmd_check_secureboot_var(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + return g_sys_sb ? 0 : 1; +} +#else +static grub_err_t hiperiso_cmd_check_secureboot_var(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + return 1; +} +#endif + +static grub_err_t hiperiso_cmd_img_check_range(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int ret = 1; + grub_file_t file; + grub_uint64_t FileSectors = 0; + hiperiso_gpt_info *gpt = NULL; + hiperiso_part_table *pt = NULL; + grub_uint8_t zeroguid[16] = {0}; + + (void)ctxt; + (void)argc; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + debug("failed to open file %s\n", args[0]); + return 1; + } + + if (file->size % 512) + { + debug("unaligned file size: %llu\n", (ulonglong)file->size); + goto out; + } + + gpt = grub_zalloc(sizeof(hiperiso_gpt_info)); + if (!gpt) + { + goto out; + } + + FileSectors = file->size / 512; + + grub_file_read(file, gpt, sizeof(hiperiso_gpt_info)); + if (grub_strncmp(gpt->Head.Signature, "EFI PART", 8) == 0) + { + debug("This is EFI partition table\n"); + + for (i = 0; i < 128; i++) + { + if (grub_memcmp(gpt->PartTbl[i].PartGuid, zeroguid, 16)) + { + if (FileSectors < gpt->PartTbl[i].LastLBA) + { + debug("out of range: part[%d] LastLBA:%llu FileSectors:%llu\n", i, + (ulonglong)gpt->PartTbl[i].LastLBA, (ulonglong)FileSectors); + goto out; + } + } + } + } + else + { + debug("This is MBR partition table\n"); + + for (i = 0; i < 4; i++) + { + pt = gpt->MBR.PartTbl + i; + if (FileSectors < pt->StartSectorId + pt->SectorCount) + { + debug("out of range: part[%d] LastLBA:%llu FileSectors:%llu\n", i, + (ulonglong)(pt->StartSectorId + pt->SectorCount), + (ulonglong)FileSectors); + goto out; + } + } + } + + ret = 0; + +out: + grub_file_close(file); + grub_check_free(gpt); + grub_errno = GRUB_ERR_NONE; + return ret; +} + +static grub_err_t hiperiso_cmd_clear_key(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int ret; + + (void)ctxt; + (void)argc; + (void)args; + + for (i = 0; i < 500; i++) + { + ret = grub_getkey_noblock(); + if (ret == GRUB_TERM_NO_KEY) + { + break; + } + } + + if (i >= 500) + { + grub_cls(); + grub_printf("\n\n Still have key input after clear.\n"); + grub_refresh(); + grub_sleep(5); + } + + return 0; +} + +static grub_err_t hiperiso_cmd_acpi_param(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int buflen; + int datalen; + int loclen; + int img_chunk_num; + int image_sector_size; + char cmd[64]; + hiperiso_chain_head *chain; + hiperiso_img_chunk *chunk; + hiperiso_os_param *osparam; + hiperiso_image_location *location; + hiperiso_image_disk_region *region; + struct grub_acpi_table_header *acpi; + + (void)ctxt; + + if (argc != 2) + { + return 1; + } + + debug("hiperiso_cmd_acpi_param %s %s\n", args[0], args[1]); + + chain = (hiperiso_chain_head *)(ulong)grub_strtoul(args[0], NULL, 16); + if (!chain) + { + return 1; + } + + image_sector_size = (int)grub_strtol(args[1], NULL, 10); + + if (grub_memcmp(&g_hiperiso_guid, &(chain->os_param.guid), 16)) + { + debug("Invalid hiperiso guid 0x%x\n", chain->os_param.guid.data1); + return 1; + } + + img_chunk_num = chain->img_chunk_num; + + loclen = sizeof(hiperiso_image_location) + (img_chunk_num - 1) * sizeof(hiperiso_image_disk_region); + datalen = sizeof(hiperiso_os_param) + loclen; + + buflen = sizeof(struct grub_acpi_table_header) + datalen; + acpi = grub_zalloc(buflen); + if (!acpi) + { + return 1; + } + + /* Step1: Fill acpi table header */ + grub_memcpy(acpi->signature, "HISO", 4); + acpi->length = buflen; + acpi->revision = 1; + grub_memcpy(acpi->oemid, "HIPERISO", 6); + grub_memcpy(acpi->oemtable, "OSPARAMS", 8); + acpi->oemrev = 1; + acpi->creator_id[0] = 1; + acpi->creator_rev = 1; + + /* Step2: Fill data */ + osparam = (hiperiso_os_param *)(acpi + 1); + grub_memcpy(osparam, &chain->os_param, sizeof(hiperiso_os_param)); + osparam->hiso_img_location_addr = 0; + osparam->hiso_img_location_len = loclen; + osparam->chksum = 0; + osparam->chksum = 0x100 - grub_byte_checksum(osparam, sizeof(hiperiso_os_param)); + + location = (hiperiso_image_location *)(osparam + 1); + grub_memcpy(&location->guid, &osparam->guid, sizeof(hiperiso_guid)); + location->image_sector_size = image_sector_size; + location->disk_sector_size = chain->disk_sector_size; + location->region_count = img_chunk_num; + + region = location->regions; + chunk = (hiperiso_img_chunk *)((char *)chain + chain->img_chunk_offset); + if (512 == image_sector_size) + { + for (i = 0; i < img_chunk_num; i++) + { + region->image_sector_count = chunk->disk_end_sector - chunk->disk_start_sector + 1; + region->image_start_sector = chunk->img_start_sector * 4; + region->disk_start_sector = chunk->disk_start_sector; + region++; + chunk++; + } + } + else + { + for (i = 0; i < img_chunk_num; i++) + { + region->image_sector_count = chunk->img_end_sector - chunk->img_start_sector + 1; + region->image_start_sector = chunk->img_start_sector; + region->disk_start_sector = chunk->disk_start_sector; + region++; + chunk++; + } + } + + /* Step3: Fill acpi checksum */ + acpi->checksum = 0; + acpi->checksum = 0x100 - grub_byte_checksum(acpi, acpi->length); + + /* load acpi table */ + grub_snprintf(cmd, sizeof(cmd), "acpi mem:0x%lx:size:%d", (ulong)acpi, acpi->length); + grub_script_execute_sourcecode(cmd); + + grub_free(acpi); + + HIPERISO_CMD_RETURN(0); +} + +static grub_err_t hiperiso_cmd_push_last_entry(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_hiperiso_last_entry_back = g_hiperiso_last_entry; + g_hiperiso_last_entry = -1; + + return 0; +} + +static grub_err_t hiperiso_cmd_pop_last_entry(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_hiperiso_last_entry = g_hiperiso_last_entry_back; + + return 0; +} + +static int hiperiso_lib_module_callback(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + const char *pos = filename + 1; + + if (info->dir) + { + while (*pos) + { + if (*pos == '.') + { + if ((*(pos - 1) >= '0' && *(pos - 1) <= '9') && (*(pos + 1) >= '0' && *(pos + 1) <= '9')) + { + grub_strncpy((char *)data, filename, 128); + return 1; + } + } + pos++; + } + } + + return 0; +} + +static grub_err_t hiperiso_cmd_lib_module_ver(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc = 1; + char *device_name = NULL; + grub_device_t dev = NULL; + grub_fs_t fs = NULL; + char buf[128] = {0}; + + (void)ctxt; + + if (argc != 3) + { + debug("hiperiso_cmd_lib_module_ver, invalid param num %d\n", argc); + return 1; + } + + debug("hiperiso_cmd_lib_module_ver %s %s %s\n", args[0], args[1], args[2]); + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + debug("grub_file_get_device_name failed, %s\n", args[0]); + goto end; + } + + dev = grub_device_open(device_name); + if (!dev) + { + debug("grub_device_open failed, %s\n", device_name); + goto end; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + debug("grub_fs_probe failed, %s\n", device_name); + goto end; + } + + fs->fs_dir(dev, args[1], hiperiso_lib_module_callback, buf); + + if (buf[0]) + { + hiperiso_set_env(args[2], buf); + } + + rc = 0; + +end: + + check_free(device_name, grub_free); + check_free(dev, grub_device_close); + + return rc; +} + +int hiperiso_load_part_table(const char *diskname) +{ + char name[64]; + int ret; + grub_disk_t disk; + grub_device_t dev; + + g_hiperiso_part_info = grub_zalloc(sizeof(hiperiso_gpt_info)); + if (!g_hiperiso_part_info) + { + return 1; + } + + disk = grub_disk_open(diskname); + if (!disk) + { + debug("Failed to open disk %s\n", diskname); + return 1; + } + + g_hiperiso_disk_size = disk->total_sectors * (1U << disk->log_sector_size); + + g_hiperiso_disk_bios_id = disk->id; + + grub_disk_read(disk, 0, 0, sizeof(hiperiso_gpt_info), g_hiperiso_part_info); + grub_disk_close(disk); + + grub_snprintf(name, sizeof(name), "%s,1", diskname); + dev = grub_device_open(name); + if (dev) + { + /* Check for official Hiperiso device */ + ret = hiperiso_check_official_device(dev); + grub_device_close(dev); + + if (ret) + { + return 1; + } + } + + g_hiperiso_disk_part_size[0] = hiperiso_get_hiso_partsize(0); + g_hiperiso_disk_part_size[1] = hiperiso_get_hiso_partsize(1); + + return 0; +} + +void hiperiso_prompt_end(void) +{ + int op = 0; + char c; + + grub_printf("\n\n\n"); + grub_printf(" 1 --- Exit grub\n"); + grub_printf(" 2 --- Reboot\n"); + grub_printf(" 3 --- Shut down\n"); + grub_printf("Please enter your choice: "); + grub_refresh(); + + while (1) + { + c = grub_getkey(); + if (c >= '1' && c <= '3') + { + if (op == 0) + { + op = c - '0'; + grub_printf("%c", c); + grub_refresh(); + } + } + else if (c == '\r' || c == '\n') + { + if (op) + { + if (op == 1) + { + grub_exit(); + } + else if (op == 2) + { + grub_reboot(); + } + else if (op == 3) + { + grub_script_execute_sourcecode("halt"); + } + } + } + else if (c == '\b') + { + if (op) + { + op = 0; + grub_printf("\rPlease enter your choice: "); + grub_printf("\rPlease enter your choice: "); + grub_refresh(); + } + } + } +} + +static grub_err_t hiperiso_cmd_load_part_table(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret; + + (void)argc; + (void)ctxt; + + ret = hiperiso_load_part_table(args[0]); + if (ret) + { + hiperiso_prompt_end(); + } + + g_hiperiso_disk_part_size[0] = hiperiso_get_hiso_partsize(0); + g_hiperiso_disk_part_size[1] = hiperiso_get_hiso_partsize(1); + + return 0; +} + +static grub_err_t hiperiso_cmd_check_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + const char *vcfg = NULL; + + (void)argc; + (void)ctxt; + + vcfg = hiperiso_plugin_get_custom_boot(args[0]); + if (vcfg) + { + debug("custom boot <%s>:<%s>\n", args[0], vcfg); + grub_env_set(args[1], vcfg); + ret = 0; + } + else + { + debug("custom boot <%s>:\n", args[0]); + } + + grub_errno = 0; + return ret; +} + + +static grub_err_t hiperiso_cmd_part_exist(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int id; + grub_uint8_t zeroguid[16] = {0}; + + (void)argc; + (void)ctxt; + + id = (int)grub_strtoul(args[0], NULL, 10); + grub_errno = 0; + + if (grub_memcmp(g_hiperiso_part_info->Head.Signature, "EFI PART", 8) == 0) + { + if (id >= 1 && id <= 128) + { + if (grub_memcmp(g_hiperiso_part_info->PartTbl[id - 1].PartGuid, zeroguid, 16)) + { + return 0; + } + } + } + else + { + if (id >= 1 && id <= 4) + { + if (g_hiperiso_part_info->MBR.PartTbl[id - 1].FsFlag) + { + return 0; + } + } + } + + return 1; +} + +static grub_err_t hiperiso_cmd_get_fs_label(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc = 1; + char *device_name = NULL; + grub_device_t dev = NULL; + grub_fs_t fs = NULL; + char *label = NULL; + + (void)ctxt; + + debug("get fs label for %s\n", args[0]); + + if (argc != 2) + { + debug("hiperiso_cmd_get_fs_label, invalid param num %d\n", argc); + return 1; + } + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + debug("grub_file_get_device_name failed, %s\n", args[0]); + goto end; + } + + dev = grub_device_open(device_name); + if (!dev) + { + debug("grub_device_open failed, %s\n", device_name); + goto end; + } + + fs = grub_fs_probe(dev); + if (NULL == fs || NULL == fs->fs_label) + { + debug("grub_fs_probe failed, %s %p %p\n", device_name, fs, fs->fs_label); + goto end; + } + + fs->fs_label(dev, &label); + if (label) + { + debug("label=<%s>\n", label); + hiperiso_set_env(args[1], label); + grub_free(label); + } + + rc = 0; + +end: + + check_free(device_name, grub_free); + check_free(dev, grub_device_close); + + return rc; +} + +static int hiperiso_fs_enum_1st_file(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + if (!info->dir) + { + grub_snprintf((char *)data, 256, "%s", filename); + return 1; + } + + return 0; +} + +static int hiperiso_fs_enum_1st_dir(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + if (info->dir && filename && filename[0] != '.') + { + grub_snprintf((char *)data, 256, "%s", filename); + return 1; + } + + return 0; +} + +static grub_err_t hiperiso_fs_enum_1st_child(int argc, char **args, grub_fs_dir_hook_t hook) +{ + int rc = 1; + char *device_name = NULL; + grub_device_t dev = NULL; + grub_fs_t fs = NULL; + char name[256] ={0}; + + if (argc != 3) + { + debug("hiperiso_fs_enum_1st_child, invalid param num %d\n", argc); + return 1; + } + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + debug("grub_file_get_device_name failed, %s\n", args[0]); + goto end; + } + + dev = grub_device_open(device_name); + if (!dev) + { + debug("grub_device_open failed, %s\n", device_name); + goto end; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + debug("grub_fs_probe failed, %s\n", device_name); + goto end; + } + + fs->fs_dir(dev, args[1], hook, name); + if (name[0]) + { + hiperiso_set_env(args[2], name); + } + + rc = 0; + +end: + + check_free(device_name, grub_free); + check_free(dev, grub_device_close); + + return rc; +} + +static grub_err_t hiperiso_cmd_fs_enum_1st_file(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + return hiperiso_fs_enum_1st_child(argc, args, hiperiso_fs_enum_1st_file); +} + +static grub_err_t hiperiso_cmd_fs_enum_1st_dir(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + return hiperiso_fs_enum_1st_child(argc, args, hiperiso_fs_enum_1st_dir); +} + +static grub_err_t hiperiso_cmd_basename(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char c; + char *pos = NULL; + char *end = NULL; + + (void)ctxt; + + if (argc != 2) + { + debug("hiperiso_cmd_basename, invalid param num %d\n", argc); + return 1; + } + + for (pos = args[0]; *pos; pos++) + { + if (*pos == '.') + { + end = pos; + } + } + + if (end) + { + c = *end; + *end = 0; + } + + grub_env_set(args[1], args[0]); + + if (end) + { + *end = c; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_basefile(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int len; + const char *buf; + + (void)ctxt; + + if (argc != 2) + { + debug("hiperiso_cmd_basefile, invalid param num %d\n", argc); + return 1; + } + + buf = args[0]; + len = (int)grub_strlen(buf); + for (i = len; i > 0; i--) + { + if (buf[i - 1] == '/') + { + grub_env_set(args[1], buf + i); + return 0; + } + } + + grub_env_set(args[1], buf); + + return 0; +} + +static grub_err_t hiperiso_cmd_enum_video_mode(grub_extcmd_context_t ctxt, int argc, char **args) +{ + struct grub_video_mode_info info; + char buf[32]; + + (void)ctxt; + (void)argc; + (void)args; + + if (!g_video_mode_list) + { + hiperiso_enum_video_mode(); + } + + if (grub_video_get_info(&info) == GRUB_ERR_NONE) + { + grub_snprintf(buf, sizeof(buf), "Resolution (%ux%u)", info.width, info.height); + } + else + { + grub_snprintf(buf, sizeof(buf), "Resolution (0x0)"); + } + + grub_env_set("HISO_CUR_VIDEO_MODE", buf); + + grub_snprintf(buf, sizeof(buf), "%d", g_video_mode_num); + grub_env_set("HISO_VIDEO_MODE_NUM", buf); + + HIPERISO_CMD_RETURN(0); +} + +static grub_err_t vt_cmd_update_cur_video_mode(grub_extcmd_context_t ctxt, int argc, char **args) +{ + struct grub_video_mode_info info; + char buf[32]; + + (void)ctxt; + (void)argc; + (void)args; + + if (grub_video_get_info(&info) == GRUB_ERR_NONE) + { + grub_snprintf(buf, sizeof(buf), "%ux%ux%u", info.width, info.height, info.bpp); + } + else + { + grub_snprintf(buf, sizeof(buf), "0x0x0"); + } + + grub_env_set(args[0], buf); + + HIPERISO_CMD_RETURN(0); +} + +static grub_err_t hiperiso_cmd_get_video_mode(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int id; + char buf[32]; + + (void)ctxt; + (void)argc; + + if (!g_video_mode_list) + { + return 0; + } + + id = (int)grub_strtoul(args[0], NULL, 10); + if (id < g_video_mode_num) + { + grub_snprintf(buf, sizeof(buf), "%ux%ux%u", + g_video_mode_list[id].width, g_video_mode_list[id].height, g_video_mode_list[id].bpp); + } + + grub_env_set(args[1], buf); + + HIPERISO_CMD_RETURN(0); +} + +static grub_err_t hiperiso_cmd_get_efivdisk_offset(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint32_t i; + grub_uint32_t loadsector = 0; + grub_file_t file; + char value[32]; + grub_uint32_t boot_catlog = 0; + grub_uint8_t buf[512]; + + (void)ctxt; + + if (argc != 2) + { + debug("hiperiso_cmd_get_efivdisk_offset, invalid param num %d\n", argc); + return 1; + } + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!file) + { + debug("failed to open %s\n", args[0]); + return 1; + } + + boot_catlog = hiperiso_get_iso_boot_catlog(file); + if (boot_catlog == 0) + { + debug("No bootcatlog found\n"); + grub_file_close(file); + return 1; + } + + grub_memset(buf, 0, sizeof(buf)); + grub_file_seek(file, boot_catlog * 2048); + grub_file_read(file, buf, sizeof(buf)); + grub_file_close(file); + + for (i = 0; i < sizeof(buf); i += 32) + { + if ((buf[i] == 0 || buf[i] == 0x90 || buf[i] == 0x91) && buf[i + 1] == 0xEF) + { + if (buf[i + 32] == 0x88) + { + loadsector = *(grub_uint32_t *)(buf + i + 32 + 8); + grub_snprintf(value, sizeof(value), "%u", loadsector * 4); //change to sector size 512 + break; + } + } + } + + if (loadsector == 0) + { + debug("No EFI eltorito info found\n"); + return 1; + } + + debug("hiperiso_cmd_get_efivdisk_offset <%s>\n", value); + grub_env_set(args[1], value); + HIPERISO_CMD_RETURN(0); +} + +static int hiperiso_collect_replace_initrd(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + int curpos; + int printlen; + grub_size_t len; + replace_fs_dir *pfsdir = (replace_fs_dir *)data; + + if (pfsdir->initrd[0]) + { + return 1; + } + + curpos = pfsdir->curpos; + len = grub_strlen(filename); + + if (info->dir) + { + if ((len == 1 && filename[0] == '.') || + (len == 2 && filename[0] == '.' && filename[1] == '.')) + { + return 0; + } + + //debug("#### [DIR] <%s> <%s>\n", pfsdir->fullpath, filename); + pfsdir->dircnt++; + + printlen = grub_snprintf(pfsdir->fullpath + curpos, 512 - curpos, "%s/", filename); + pfsdir->curpos = curpos + printlen; + pfsdir->fs->fs_dir(pfsdir->dev, pfsdir->fullpath, hiperiso_collect_replace_initrd, pfsdir); + pfsdir->curpos = curpos; + pfsdir->fullpath[curpos] = 0; + } + else + { + //debug("#### [FILE] <%s> <%s>\n", pfsdir->fullpath, filename); + pfsdir->filecnt++; + + /* We consider the xxx.img file bigger than 32MB is the initramfs file */ + if (len > 4 && grub_strncmp(filename + len - 4, ".img", 4) == 0) + { + if (info->size > 32 * HISO_SIZE_1MB) + { + grub_snprintf(pfsdir->initrd, sizeof(pfsdir->initrd), "%s%s", pfsdir->fullpath, filename); + return 1; + } + } + } + + return 0; +} + +static grub_err_t hiperiso_cmd_search_replace_initrd(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + char *pos = NULL; + char *device_name = NULL; + grub_device_t dev = NULL; + grub_fs_t fs = NULL; + replace_fs_dir *pfsdir = NULL; + + (void)ctxt; + + if (argc != 2) + { + debug("hiperiso_cmd_search_replace_initrd, invalid param num %d\n", argc); + return 1; + } + + pfsdir = grub_zalloc(sizeof(replace_fs_dir)); + if (!pfsdir) + { + return 1; + } + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + goto fail; + } + + dev = grub_device_open(device_name); + if (!dev) + { + goto fail; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + goto fail; + } + + pfsdir->dev = dev; + pfsdir->fs = fs; + pfsdir->curpos = 1; + pfsdir->fullpath[0] = '/'; + fs->fs_dir(dev, "/", hiperiso_collect_replace_initrd, pfsdir); + + if (pfsdir->initrd[0]) + { + debug("Replace initrd <%s> <%d %d>\n", pfsdir->initrd, pfsdir->dircnt, pfsdir->filecnt); + + for (i = 0; i < (int)sizeof(pfsdir->initrd) && pfsdir->initrd[i]; i++) + { + if (pfsdir->initrd[i] == '/') + { + pfsdir->initrd[i] = '\\'; + } + } + + pos = (pfsdir->initrd[0] == '\\') ? pfsdir->initrd + 1 : pfsdir->initrd; + grub_env_set(args[1], pos); + } + else + { + debug("Replace initrd NOT found <%s> <%d %d>\n", args[0], pfsdir->dircnt, pfsdir->filecnt); + } + +fail: + + grub_check_free(pfsdir); + grub_check_free(device_name); + check_free(dev, grub_device_close); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_push_pager(grub_extcmd_context_t ctxt, int argc, char **args) +{ + const char *pager = NULL; + + (void)ctxt; + (void)argc; + (void)args; + + pager = grub_env_get("pager"); + if (NULL == pager) + { + g_pager_flag = 1; + grub_env_set("pager", "1"); + } + else if (pager[0] == '1') + { + g_pager_flag = 0; + } + else + { + grub_snprintf(g_old_pager, sizeof(g_old_pager), "%s", pager); + g_pager_flag = 2; + grub_env_set("pager", "1"); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_pop_pager(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + if (g_pager_flag == 1) + { + grub_env_unset("pager"); + } + else if (g_pager_flag == 2) + { + grub_env_set("pager", g_old_pager); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_chk_case_file(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + if (g_json_case_mis_path[0]) + { + return 1; + } + + if (0 == info->dir && grub_strcasecmp(filename, "hiperiso.json") == 0) + { + grub_snprintf(g_json_case_mis_path, 32, "%s/%s", (char *)data, filename); + return 1; + } + return 0; +} + +static int hiperiso_chk_case_dir(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + char path[16]; + chk_case_fs_dir *fs_dir = (chk_case_fs_dir *)data; + + if (g_json_case_mis_path[0]) + { + return 1; + } + + if (info->dir && (filename[0] == 'v' || filename[0] == 'V')) + { + if (grub_strcasecmp(filename, "hiperiso") == 0) + { + grub_snprintf(path, sizeof(path), "/%s", filename); + fs_dir->fs->fs_dir(fs_dir->dev, path, hiperiso_chk_case_file, path); + if (g_json_case_mis_path[0]) + { + return 1; + } + } + } + + return 0; +} + +static grub_err_t hiperiso_cmd_chk_json_pathcase(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int fstype = 0; + char *device_name = NULL; + grub_device_t dev = NULL; + grub_fs_t fs = NULL; + chk_case_fs_dir fs_dir; + + (void)ctxt; + (void)argc; + (void)args; + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + goto out; + } + + dev = grub_device_open(device_name); + if (!dev) + { + goto out; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + goto out; + } + + fstype = hiperiso_get_fs_type(fs->name); + if (fstype == hiperiso_fs_fat || fstype == hiperiso_fs_exfat || fstype >= hiperiso_fs_max) + { + goto out; + } + + g_json_case_mis_path[0] = 0; + fs_dir.dev = dev; + fs_dir.fs = fs; + fs->fs_dir(dev, "/", hiperiso_chk_case_dir, &fs_dir); + + if (g_json_case_mis_path[0]) + { + grub_env_set("HISO_PLUGIN_PATH_CASE_MISMATCH", g_json_case_mis_path); + } + +out: + + grub_check_free(device_name); + check_free(dev, grub_device_close); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t grub_cmd_gptpriority(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_disk_t disk; + grub_partition_t part; + char priority_str[3]; /* Maximum value 15 */ + + (void)ctxt; + + if (argc < 2 || argc > 3) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "gptpriority DISKNAME PARTITIONNUM [VARNAME]"); + + /* Open the disk if it exists */ + disk = grub_disk_open (args[0]); + if (!disk) + { + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "Not a disk"); + } + + part = grub_partition_probe (disk, args[1]); + if (!part) + { + grub_disk_close (disk); + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "No such partition"); + } + + if (grub_strcmp (part->partmap->name, "gpt")) + { + grub_disk_close (disk); + return grub_error (GRUB_ERR_BAD_PART_TABLE, + "Not a GPT partition"); + } + + grub_snprintf (priority_str, sizeof(priority_str), "%u", + (grub_uint32_t)((part->gpt_attrib >> 48) & 0xfULL)); + + if (argc == 3) + { + grub_env_set (args[2], priority_str); + grub_env_export (args[2]); + } + else + { + grub_printf ("Priority is %s\n", priority_str); + } + + grub_disk_close (disk); + return GRUB_ERR_NONE; +} + + +static grub_err_t grub_cmd_syslinux_nojoliet(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + int joliet = 0; + grub_file_t file = NULL; + grub_uint32_t loadrba = 0; + grub_uint32_t boot_catlog = 0; + grub_uint8_t sector[512]; + boot_info_table *info = NULL; + + (void)ctxt; + (void)argc; + + /* This also trigger a iso9660 fs parse */ + if (hiperiso_check_file_exist("(loop)/isolinux/isolinux.cfg")) + { + return 0; + } + + joliet = grub_iso9660_is_joliet(); + if (joliet == 0) + { + return 1; + } + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!file) + { + debug("failed to open %s\n", args[0]); + return 1; + } + + boot_catlog = hiperiso_get_iso_boot_catlog(file); + if (boot_catlog == 0) + { + debug("no bootcatlog found %u\n", boot_catlog); + goto out; + } + + loadrba = hiperiso_get_bios_eltorito_rba(file, boot_catlog); + if (loadrba == 0) + { + debug("no bios eltorito rba found %u\n", loadrba); + goto out; + } + + grub_file_seek(file, loadrba * 2048); + grub_file_read(file, sector, 512); + + info = (boot_info_table *)sector; + if (info->bi_data0 == 0x7c6ceafa && + info->bi_data1 == 0x90900000 && + info->bi_PrimaryVolumeDescriptor == 16 && + info->bi_BootFileLocation == loadrba) + { + debug("bootloader is syslinux, %u.\n", loadrba); + ret = 0; + } + +out: + + grub_file_close(file); + grub_errno = GRUB_ERR_NONE; + return ret; +} + +static grub_err_t grub_cmd_vlnk_dump_part(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int n = 0; + hiperiso_vlnk_part *node; + + (void)ctxt; + (void)argc; + (void)args; + + for (node = g_vlnk_part_list; node; node = node->next) + { + grub_printf("[%d] %s disksig:%08x offset:%llu fs:%s\n", + ++n, node->device, node->disksig, + (ulonglong)node->partoffset, (node->fs ? node->fs->name : "N/A")); + } + + return 0; +} + +static grub_err_t grub_cmd_is_vlnk_name(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len = 0; + + (void)ctxt; + + if (argc == 1) + { + len = (int)grub_strlen(args[0]); + if (grub_file_is_vlnk_suffix(args[0], len)) + { + return 0; + } + } + + return 1; +} + +static grub_err_t grub_cmd_get_vlnk_dst(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int vlnk = 0; + const char *name = NULL; + + (void)ctxt; + + if (argc == 2) + { + grub_env_unset(args[1]); + name = grub_file_get_vlnk(args[0], &vlnk); + if (vlnk) + { + debug("VLNK SRC: <%s>\n", args[0]); + debug("VLNK DST: <%s>\n", name); + grub_env_set(args[1], name); + return 0; + } + } + + return 1; +} + +static grub_err_t grub_cmd_check_vlnk(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + int len = 0; + grub_file_t file = NULL; + hiperiso_vlnk vlnk; + char dst[512]; + + (void)ctxt; + + if (argc != 1) + { + goto out; + } + + len = (int)grub_strlen(args[0]); + if (!grub_file_is_vlnk_suffix(args[0], len)) + { + grub_printf("Invalid vlnk suffix\n"); + goto out; + } + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE | GRUB_FILE_TYPE_NO_VLNK); + if (!file) + { + grub_printf("Failed to open %s\n", args[0]); + goto out; + } + + if (file->size != 32768) + { + grub_printf("Invalid vlnk file (size=%llu).\n", (ulonglong)file->size); + goto out; + } + + grub_memset(&vlnk, 0, sizeof(vlnk)); + grub_file_read(file, &vlnk, sizeof(vlnk)); + + ret = hiperiso_check_vlnk_data(&vlnk, 1, dst, sizeof(dst)); + +out: + + grub_refresh(); + check_free(file, grub_file_close); + grub_errno = GRUB_ERR_NONE; + return ret; +} + +static grub_err_t hiperiso_iso_vd_id_clear(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_iso_vd_id_publisher[0] = 0; + g_iso_vd_id_prepare[0] = 0; + g_iso_vd_id_application[0] = 0; + + return 0; +} + +static grub_err_t hiperiso_cmd_iso_vd_id_parse(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + int offset = 318; + grub_file_t file = NULL; + + (void)ctxt; + (void)argc; + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!file) + { + grub_printf("Failed to open %s\n", args[0]); + goto out; + } + + grub_file_seek(file, 16 * 2048 + offset); + grub_file_read(file, g_iso_vd_id_publisher, 128); + + offset += 128; + grub_file_seek(file, 16 * 2048 + offset); + grub_file_read(file, g_iso_vd_id_prepare, 128); + + offset += 128; + grub_file_seek(file, 16 * 2048 + offset); + grub_file_read(file, g_iso_vd_id_application, 128); + +out: + + check_free(file, grub_file_close); + grub_errno = GRUB_ERR_NONE; + return ret; +} + +static grub_err_t hiperiso_cmd_iso_vd_id_begin(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + char *id = g_iso_vd_id_publisher; + + (void)ctxt; + (void)argc; + + if (args[0][0] == '1') + { + id = g_iso_vd_id_prepare; + } + else if (args[0][0] == '2') + { + id = g_iso_vd_id_application; + } + + if (args[1][0] == '0' && grub_strncasecmp(id, args[2], grub_strlen(args[2])) == 0) + { + ret = 0; + } + + if (args[1][0] == '1' && grub_strncmp(id, args[2], grub_strlen(args[2])) == 0) + { + ret = 0; + } + + grub_errno = GRUB_ERR_NONE; + return ret; +} + +static grub_err_t hiperiso_cmd_fn_mutex_lock(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + + g_hiperiso_fn_mutex = 0; + if (argc == 1 && args[0][0] == '1' && args[0][1] == 0) + { + g_hiperiso_fn_mutex = 1; + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_dump_rsv_page(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint64_t total; + grub_uint64_t org_required; + grub_uint64_t new_required; + + (void)ctxt; + (void)argc; + (void)args; + +#ifdef GRUB_MACHINE_EFI + grub_efi_get_reserved_page_num(&total, &org_required, &new_required); + grub_printf("Total pages: %llu\n", (unsigned long long)total); + grub_printf("OrgReq pages: %llu\n", (unsigned long long)org_required); + grub_printf("NewReq pages: %llu\n", (unsigned long long)new_required); +#else + (void)total; + (void)org_required; + (void)new_required; + grub_printf("Non EFI mode!\n"); +#endif + + grub_refresh(); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_need_secondary_menu(grub_extcmd_context_t ctxt, int argc, char **args) +{ + const char *env = NULL; + + (void)ctxt; + (void)argc; + + if (g_hiperiso_memdisk_mode || g_hiperiso_grub2_mode || g_hiperiso_wimboot_mode || g_hiperiso_iso_raw) + { + return 1; + } + + if (hiperiso_check_mode_by_name(args[0], "vtgrub2") || + hiperiso_check_mode_by_name(args[0], "vtwimboot") || + hiperiso_check_mode_by_name(args[0], "vtmemdisk") || + hiperiso_check_mode_by_name(args[0], "vtnormal") + ) + { + return 1; + } + + env = grub_env_get("HISO_SECONDARY_BOOT_MENU"); + if (env && env[0] == '0' && env[1] == 0) + { + return 1; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_show_secondary_menu(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int n = 0; + int pos = 0; + int len = 0; + int select = 0; + int timeout = 0; + char *cmd = NULL; + const char *env = NULL; + ulonglong fsize = 0; + char cfgfile[128]; + int seldata[16] = {0}; + + (void)ctxt; + (void)argc; + + len = 8 * HISO_SIZE_1KB; + cmd = (char *)grub_malloc(len); + if (!cmd) + { + return 1; + } + + g_hiso_secondary_need_recover = 0; + grub_env_unset("HISO_SECOND_EXIT"); + grub_env_unset("HISO_CHKSUM_FILE_PATH"); + + env = grub_env_get("HISO_SECONDARY_TIMEOUT"); + if (env) + { + timeout = (int)grub_strtol(env, NULL, 10); + } + + if (timeout > 0) + { + hiso_len_ssprintf(cmd, pos, len, "set timeout=%d\n", timeout); + } + + fsize = grub_strtoull(args[2], NULL, 10); + + hiso_dummy_menuentry(cmd, pos, len, "$VTLANG_NORMAL_MODE", "second_normal"); seldata[n++] = 1; + + if (grub_strcmp(args[1], "Unix") != 0) + { + if (grub_strcmp(args[1], "Windows") == 0) + { + hiso_dummy_menuentry(cmd, pos, len, "$VTLANG_WIMBOOT_MODE", "second_wimboot"); seldata[n++] = 2; + } + else + { + hiso_dummy_menuentry(cmd, pos, len, "$VTLANG_GRUB2_MODE", "second_grub2"); seldata[n++] = 3; + } + + if (fsize <= HISO_SIZE_1GB) + { + hiso_dummy_menuentry(cmd, pos, len, "$VTLANG_MEMDISK_MODE", "second_memdisk"); seldata[n++] = 4; + } + } + + hiso_dummy_menuentry(cmd, pos, len, "$VTLANG_FILE_CHKSUM", "second_checksum"); seldata[n++] = 5; + hiso_dummy_menuentry(cmd, pos, len, "$VTLANG_RETURN_PRV_NOESC", "second_return"); seldata[n++] = 6; + + do { + grub_errno = GRUB_ERR_NONE; + g_hiperiso_menu_esc = 1; + g_hiperiso_suppress_esc = 1; + g_hiperiso_suppress_esc_default = 0; + g_hiperiso_secondary_menu_on = 1; + grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)cmd, pos); + grub_script_execute_sourcecode(cfgfile); + g_hiperiso_menu_esc = 0; + g_hiperiso_suppress_esc = 0; + g_hiperiso_suppress_esc_default = 1; + g_hiperiso_secondary_menu_on = 0; + + select = seldata[g_hiperiso_last_entry]; + + if (select == 2) + { + g_hiperiso_wimboot_mode = 1; + g_hiso_secondary_need_recover = 1; + } + else if (select == 3) + { + g_hiperiso_grub2_mode = 1; + g_hiso_secondary_need_recover = 2; + } + else if (select == 4) + { + g_hiperiso_memdisk_mode = 1; + g_hiso_secondary_need_recover = 3; + } + else if (select == 5) + { + grub_env_set("HISO_CHKSUM_FILE_PATH", args[0]); + grub_script_execute_sourcecode("configfile $hiso_efi_part/grub/checksum.cfg"); + } + else if (select == 6) + { + grub_env_set("HISO_SECOND_EXIT", "1"); + } + }while (select == 5); + + grub_free(cmd); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_secondary_recover_mode(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + if (g_hiso_secondary_need_recover == 1) + { + g_hiperiso_wimboot_mode = 0; + } + else if (g_hiso_secondary_need_recover == 2) + { + g_hiperiso_grub2_mode = 0; + } + else if (g_hiso_secondary_need_recover == 3) + { + g_hiperiso_memdisk_mode = 0; + } + + g_hiso_secondary_need_recover = 0; + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_cmd_fs_ignore_case(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + + if (args[0][0] == '0') + { + g_hiperiso_case_insensitive = 0; + } + else + { + g_hiperiso_case_insensitive = 1; + } + + return 0; +} + +static grub_err_t hiperiso_cmd_init_menu_lang(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + + hiperiso_plugin_load_menu_lang(1, args[0]); + HIPERISO_CMD_RETURN(0); +} + +static grub_err_t hiperiso_cmd_load_menu_lang(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + + hiperiso_plugin_load_menu_lang(0, args[0]); + HIPERISO_CMD_RETURN(0); +} + +static grub_err_t hiperiso_cmd_update_sb_policy(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + +#ifdef GRUB_MACHINE_EFI + hiperiso_set_sb_policy(); +#endif + + HIPERISO_CMD_RETURN(0); +} + +static grub_err_t hiperiso_cmd_sb_info(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + +#ifdef GRUB_MACHINE_EFI + const char *policy = NULL; + grub_efi_guid_t security = + { 0xA46423E3, 0x4617, 0x49f1, {0xB9, 0xFF, 0xD1, 0xBF, 0xA9, 0x11, 0x58, 0x39 } }; + grub_efi_guid_t security2 = + { 0x94ab2f58, 0x1438, 0x4ef1, {0x91, 0x52, 0x18, 0x94, 0x1a, 0x3a, 0x0e, 0x68 } }; + + if (g_sb_policy == HISO_SB_POLICY_BYPASS) + { + policy = "ByPass"; + } + else if (g_sb_policy == HISO_SB_POLICY_CHECK) + { + policy = "Check"; + } + else + { + policy = "XXX"; + } + + grub_printf("UEFI Security %s\n", grub_efi_locate_protocol(&security, NULL) ? "Yes" : "No"); + grub_printf("UEFI Security2 %s\n", grub_efi_locate_protocol(&security2, NULL) ? "Yes" : "No"); + grub_printf("Hiperiso Secure Policy %s\n", policy); + +#else + grub_printf("Non EFI mode!\n"); +#endif + + grub_refresh(); + + HIPERISO_CMD_RETURN(0); +} + +static int hiperiso_chksum_pathcmp(int chktype, char *rlpath, char *rdpath) +{ + char *pos1 = NULL; + char *pos2 = NULL; + + if (chktype == 2) + { + pos1 = hiperiso_str_basename(rlpath); + pos2 = hiperiso_str_basename(rdpath); + return grub_strcmp(pos1, pos2); + } + else if (chktype == 3 || chktype == 4) + { + if (grub_strcmp(rlpath, rdpath) == 0 || grub_strcmp(rlpath + 1, rdpath) == 0) + { + return 0; + } + } + + return 1; +} + +static int hiperiso_find_checksum +( + grub_file_t file, + const char *uname, + int retlen, + char *path, + int chktype, + char *chksum +) +{ + int ulen; + char *pos = NULL; + char *pos1 = NULL; + char *pos2 = NULL; + char *buf = NULL; + char *currline = NULL; + char *nextline = NULL; + + ulen = (int)grub_strlen(uname); + + /* read file to buffer */ + buf = grub_malloc(file->size + 4); + if (!buf) + { + return 1; + } + grub_file_read(file, buf, file->size); + buf[file->size] = 0; + + /* parse each line */ + for (currline = buf; currline; currline = nextline) + { + nextline = hiperiso_get_line(currline); + HISO_SKIP_SPACE(currline); + + if (grub_strncasecmp(currline, uname, ulen) == 0) + { + pos = grub_strchr(currline, '='); + pos1 = grub_strchr(currline, '('); + pos2 = grub_strchr(currline, ')'); + + if (pos && pos1 && pos2) + { + *pos2 = 0; + if (hiperiso_chksum_pathcmp(chktype, path, pos1 + 1) == 0) + { + HISO_SKIP_SPACE_NEXT(pos, 1); + grub_memcpy(chksum, pos, retlen); + goto end; + } + } + } + else if (hiperiso_str_len_alnum(currline, retlen)) + { + HISO_SKIP_SPACE_NEXT_EX(pos, currline, retlen); + if (hiperiso_chksum_pathcmp(chktype, path, pos) == 0) + { + grub_memcpy(chksum, currline, retlen); + goto end; + } + } + } + +end: + grub_free(buf); + return 0; +} + +static int hiperiso_check_chkfile(const char *isopart, char *path, const char *lchkname, grub_file_t *pfile) +{ + int ret = 0; + int cnt = 0; + char c = 0; + char *pos = NULL; + grub_file_t file = NULL; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s.%s", isopart, path, lchkname); + if (file) + { + HISO_GOTO_END(1); + } + + cnt = hiperiso_str_chrcnt(path, '/'); + if (cnt > 1) + { + pos = grub_strrchr(path, '/'); + c = *pos; + *pos = 0; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s/HIPERISO_CHECKSUM", isopart, path); + if (file) + { + *pos = c; + HISO_GOTO_END(2); + } + *pos = c; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s/HIPERISO_CHECKSUM", isopart); + if (file) + { + ret = (cnt > 1) ? 3 : 4; + } + +end: + + if (pfile) + { + *pfile = file; + } + else + { + check_free(file, grub_file_close); + } + return ret; +} + +static grub_err_t hiperiso_cmd_cmp_checksum(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int index = 0; + int chktype = 0; + char *pos = NULL; + grub_file_t file = NULL; + const char *calc_value = NULL; + const char *isopart = NULL; + char fchksum[64]; + char readchk[256] = {0}; + char filebuf[512] = {0}; + char uchkname[16]; + + (void)ctxt; + + index = (int)grub_strtol(args[0], NULL, 10); + if (argc != 2 || index < 0 || index >= HISO_CHKSUM_NUM) + { + return 1; + } + + grub_strncpy(uchkname, g_lower_chksum_name[index], sizeof(uchkname)); + hiperiso_str_toupper(uchkname); + + isopart = grub_env_get("hiso_iso_part"); + calc_value = grub_env_get("VT_LAST_CHECK_SUM"); + + chktype = hiperiso_check_chkfile(isopart, args[1], g_lower_chksum_name[index], &file); + if (chktype <= 0) + { + grub_printf("\n\nNo checksum file found.\n"); + goto end; + } + + if (chktype == 1) + { + grub_snprintf(fchksum, sizeof(fchksum), ".%s", g_lower_chksum_name[index]); + grub_memset(filebuf, 0, sizeof(filebuf)); + grub_file_read(file, filebuf, 511); + + pos = grub_strchr(filebuf, '='); + if (pos) + { + HISO_SKIP_SPACE_NEXT(pos, 1); + grub_memcpy(readchk, pos, g_chksum_retlen[index]); + } + else + { + grub_memcpy(readchk, filebuf, g_chksum_retlen[index]); + } + } + else if (chktype == 3 || chktype == 4) + { + grub_snprintf(fchksum, sizeof(fchksum), "global HIPERISO_CHECKSUM"); + hiperiso_find_checksum(file, uchkname, g_chksum_retlen[index], args[1], chktype, readchk); + if (readchk[0] == 0) + { + grub_printf("\n\n%s value not found in %s.\n", uchkname, fchksum); + goto end; + } + } + else + { + grub_snprintf(fchksum, sizeof(fchksum), "local HIPERISO_CHECKSUM"); + hiperiso_find_checksum(file, uchkname, g_chksum_retlen[index], args[1], chktype, readchk); + if (readchk[0] == 0) + { + grub_file_close(file); + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s/HIPERISO_CHECKSUM", isopart); + if (file) + { + grub_snprintf(fchksum, sizeof(fchksum), "global HIPERISO_CHECKSUM"); + hiperiso_find_checksum(file, uchkname, g_chksum_retlen[index], args[1], 3, readchk); + if (readchk[0] == 0) + { + grub_printf("\n\n%s value not found in both local and global HIPERISO_CHECKSUM.\n", uchkname); + goto end; + } + } + } + } + + if (grub_strcasecmp(calc_value, readchk) == 0) + { + grub_printf("\n\nCheck %s value with %s file. [ SUCCESS ]\n", uchkname, fchksum); + } + else + { + grub_printf("\n\nCheck %s value with %s file. [ ERROR ]\n", uchkname, fchksum); + grub_printf("The %s value in %s file is:\n%s\n", uchkname, fchksum, readchk); + } + +end: + grub_refresh(); + check_free(file, grub_file_close); + HIPERISO_CMD_RETURN(0); +} + +static int hiperiso_find_all_checksum +( + grub_file_t file, + char *path, + int chktype, + int exists[HISO_CHKSUM_NUM], + int *ptotexist +) +{ + int i; + int ulen; + int tot = 0; + char c = 0; + char *pos = NULL; + char *pos1 = NULL; + char *pos2 = NULL; + char *buf = NULL; + char *currline = NULL; + char *nextline = NULL; + const char *uname = NULL; + + tot = *ptotexist; + + /* read file to buffer */ + buf = grub_malloc(file->size + 4); + if (!buf) + { + return 1; + } + grub_file_read(file, buf, file->size); + buf[file->size] = 0; + + /* parse each line */ + for (currline = buf; currline; currline = nextline) + { + nextline = hiperiso_get_line(currline); + HISO_SKIP_SPACE(currline); + + for (i = 0; i < HISO_CHKSUM_NUM; i++) + { + if (exists[i]) + { + continue; + } + + uname = g_lower_chksum_name[i]; + ulen = g_lower_chksum_namelen[i]; + + if (grub_strncasecmp(currline, uname, ulen) == 0) + { + pos = grub_strchr(currline, '='); + pos1 = grub_strchr(currline, '('); + pos2 = grub_strchr(currline, ')'); + + if (pos && pos1 && pos2) + { + c = *pos2; + *pos2 = 0; + if (hiperiso_chksum_pathcmp(chktype, path, pos1 + 1) == 0) + { + exists[i] = 1; + tot++; + } + *pos2 = c; + } + } + else if (hiperiso_str_len_alnum(currline, g_chksum_retlen[i])) + { + HISO_SKIP_SPACE_NEXT_EX(pos, currline, g_chksum_retlen[i]); + if (hiperiso_chksum_pathcmp(chktype, path, pos) == 0) + { + exists[i] = 1; + tot++; + } + } + + if (tot >= HISO_CHKSUM_NUM) + { + goto end; + } + } + } + +end: + + *ptotexist = tot; + grub_free(buf); + return 0; +} + +static grub_err_t hiperiso_cmd_hisochksum_exist(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i = 0; + int cnt = 0; + char c = 0; + int tip = 0; + char *pos = NULL; + grub_file_t file = NULL; + const char *isopart = NULL; + int exists[HISO_CHKSUM_NUM] = { 0, 0, 0, 0 }; + int totexist = 0; + + (void)argc; + (void)ctxt; + + isopart = grub_env_get("hiso_iso_part"); + + for (i = 0; i < HISO_CHKSUM_NUM; i++) + { + if (hiperiso_check_file_exist("%s%s.%s", isopart, args[0], g_lower_chksum_name[i])) + { + exists[i] = 1; + totexist++; + } + } + + if (totexist == HISO_CHKSUM_NUM) + { + goto end; + } + + cnt = hiperiso_str_chrcnt(args[0], '/'); + if (cnt > 1) + { + pos = grub_strrchr(args[0], '/'); + c = *pos; + *pos = 0; + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s/HIPERISO_CHECKSUM", isopart, args[0]); + *pos = c; + + if (file) + { + if (tip == 0 && file->size > (32 * HISO_SIZE_1KB)) + { + tip = 1; + grub_printf("Reading checksum file...\n"); + grub_refresh(); + } + + debug("parse local HIPERISO_CHECKSUM\n"); + hiperiso_find_all_checksum(file, args[0], 2, exists, &totexist); + grub_file_close(file); + } + } + + if (totexist == HISO_CHKSUM_NUM) + { + goto end; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s/HIPERISO_CHECKSUM", isopart); + if (file) + { + if (tip == 0 && file->size > (32 * HISO_SIZE_1KB)) + { + tip = 1; + grub_printf("Reading checksum file...\n"); + grub_refresh(); + } + + debug("parse global HIPERISO_CHECKSUM\n"); + hiperiso_find_all_checksum(file, args[0], (cnt > 1) ? 3 : 4, exists, &totexist); + grub_file_close(file); + } + +end: + + hiperiso_env_int_set("VT_EXIST_MD5", exists[0]); + hiperiso_env_int_set("VT_EXIST_SHA1", exists[1]); + hiperiso_env_int_set("VT_EXIST_SHA256", exists[2]); + hiperiso_env_int_set("VT_EXIST_SHA512", exists[3]); + + HIPERISO_CMD_RETURN(0); +} + + +static const char * hiperiso_menu_lang_read_hook(struct grub_env_var *var, const char *val) +{ + (void)var; + return hiperiso_get_vmenu_title(val); +} + +int hiperiso_env_init(void) +{ + int i; + char buf[64]; + + grub_env_set("vtdebug_flag", ""); + + grub_register_hiso_menu_lang_hook(hiperiso_menu_lang_read_hook); + hiperiso_ctrl_var_init(); + hiperiso_global_var_init(); + + g_part_list_buf = grub_malloc(HISO_PART_BUF_LEN); + g_tree_script_buf = grub_malloc(HISO_MAX_SCRIPT_BUF); + g_list_script_buf = grub_malloc(HISO_MAX_SCRIPT_BUF); + for (i = 0; i < HISO_MAX_CONF_REPLACE; i++) + { + g_conf_replace_new_buf[i] = grub_malloc(hiso_max_replace_file_size); + } + + hiperiso_filt_register(0, hiperiso_wrapper_open); + + g_grub_param = (hiperiso_grub_param *)grub_zalloc(sizeof(hiperiso_grub_param)); + if (g_grub_param) + { + g_grub_param->grub_env_get = grub_env_get; + g_grub_param->grub_env_set = (grub_env_set_pf)grub_env_set; + g_grub_param->grub_env_printf = (grub_env_printf_pf)grub_printf; + grub_snprintf(buf, sizeof(buf), "%p", g_grub_param); + grub_env_set("env_param", buf); + grub_env_set("hiperiso_env_param", buf); + + grub_env_export("env_param"); + grub_env_export("hiperiso_env_param"); + } + + grub_env_export("hiso_winpeshl_ini_addr"); + grub_env_export("hiso_winpeshl_ini_size"); + + grub_snprintf(buf, sizeof(buf), "0x%lx", (ulong)hiperiso_chain_file_size); + grub_env_set("hiso_chain_file_size", buf); + grub_env_export("hiso_chain_file_size"); + + grub_snprintf(buf, sizeof(buf), "0x%lx", (ulong)hiperiso_chain_file_read); + grub_env_set("hiso_chain_file_read", buf); + grub_env_export("hiso_chain_file_read"); + + grub_snprintf(buf, sizeof(buf), "0x%lx", (ulong)hiperiso_get_vmenu_title); + grub_env_set("HISO_VMENU_FUNC_ADDR", buf); + grub_env_export("HISO_VMENU_FUNC_ADDR"); + + grub_snprintf(buf, sizeof(buf), "%s-%s", GRUB_TARGET_CPU, GRUB_PLATFORM); + grub_env_set("grub_cpu_platform", buf); + grub_env_export("grub_cpu_platform"); + + return 0; +} + + + +static grub_err_t hiperiso_cmd_boot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char cmdline[2048]; + char log_dir[512]; + char linux_script[2048 + 256]; + char initrd_script[256]; + const char *iso_path; + const char *trace_level; + const char *fallback; + const char *display; + const char *vga; + const char *env_val; + int ram = 2048; + int cpus = 2; + int clen = 0; + const char *auto_install; + const char *persistence; + const char *dud; + const char *injection; + const char *conf_replace; + int secure_boot = 0; + int tpm = 0; + int net_dump = 0; + const char *cpu_features; + const char *boot_mode; + char *iso_clean; + + (void)ctxt; + + if (argc < 1 || !args[0][0]) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "usage: hiperiso_boot "); + } + + iso_path = args[0]; + + { + const char *base = grub_strrchr(iso_path, '/'); + base = base ? base + 1 : iso_path; + grub_snprintf(log_dir, sizeof(log_dir), "/hiperiso/logs/%s/", base); + } + + trace_level = hiperiso_get_env("HISO_TRACE_LEVEL"); + if (!trace_level || !trace_level[0]) + trace_level = "standard"; + + fallback = hiperiso_get_env("HISO_FALLBACK"); + if (!fallback || !fallback[0]) + fallback = "0"; + + display = hiperiso_get_env("HISO_DISPLAY"); + if (!display || !display[0]) + display = "none"; + vga = hiperiso_get_env("HISO_VGA"); + if (!vga || !vga[0]) + vga = "none"; + + env_val = hiperiso_get_env("HISO_GUEST_RAM"); + if (env_val && env_val[0]) + ram = (int)grub_strtoul(env_val, NULL, 10); + env_val = hiperiso_get_env("HISO_GUEST_CPUS"); + if (env_val && env_val[0]) + cpus = (int)grub_strtoul(env_val, NULL, 10); + + auto_install = hiperiso_get_env("HISO_AUTO_INSTALL"); + persistence = hiperiso_get_env("HISO_PERSISTENCE"); + dud = hiperiso_get_env("HISO_DUD"); + injection = hiperiso_get_env("HISO_INJECTION"); + conf_replace = hiperiso_get_env("HISO_CONF_REPLACE"); + + env_val = hiperiso_get_env("HISO_SECURE_BOOT"); + secure_boot = (env_val && env_val[0] && env_val[0] != '0') ? 1 : 0; + env_val = hiperiso_get_env("HISO_TPM"); + tpm = (env_val && env_val[0] && env_val[0] != '0') ? 1 : 0; + env_val = hiperiso_get_env("HISO_NET_DUMP"); + net_dump = (env_val && env_val[0] && env_val[0] != '0') ? 1 : 0; + cpu_features = hiperiso_get_env("HISO_CPU_FEATURES"); + boot_mode = "normal"; + if (argc >= 2 && args[1][0]) + boot_mode = args[1]; + + iso_clean = grub_strdup(iso_path); + if (iso_clean) + { + char *p; + for (p = iso_clean; *p; p++) + if (*p == '"') + *p = '\''; + } + + clen = grub_snprintf(cmdline, sizeof(cmdline), + "hiperiso_iso=\"%s\" hiperiso_log=\"%s\" hiperiso_trace_level=\"%s\" " + "hiperiso_ram=\"%d\" hiperiso_cpus=\"%d\" hiperiso_display=\"%s\" " + "hiperiso_vga=\"%s\" hiperiso_fallback=\"%s\"", + iso_clean ? iso_clean : iso_path, + log_dir, trace_level, ram, cpus, display, vga, fallback); + + if (auto_install && auto_install[0]) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_auto_install=\"%s\"", auto_install); + if (persistence && persistence[0]) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_persistence=\"%s\"", persistence); + if (dud && dud[0]) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_dud=\"%s\"", dud); + if (injection && injection[0]) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_injection=\"%s\"", injection); + if (conf_replace && conf_replace[0]) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_conf_replace=\"%s\"", conf_replace); + if (secure_boot) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_secure_boot=\"1\""); + if (tpm) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_tpm=\"1\""); + if (cpu_features && cpu_features[0]) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_cpu_features=\"%s\"", cpu_features); + if (boot_mode && boot_mode[0]) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_boot_mode=\"%s\"", boot_mode); + if (net_dump) + clen += grub_snprintf(cmdline + clen, sizeof(cmdline) - clen, + " hiperiso_net_dump=\"1\""); + + if (iso_clean) + grub_free(iso_clean); + + if (clen >= (int)sizeof(cmdline)) + { + debug("hiperiso_boot: cmdline too long, truncated\n"); + } + + grub_snprintf(linux_script, sizeof(linux_script), + "linux ($hiso_efi_part)/EFI/hiperiso/vmlinuz %s", cmdline); + grub_script_execute_sourcecode(linux_script); + if (grub_errno != GRUB_ERR_NONE) + { + debug("hiperiso_boot: Failed to load kernel\n"); + HIPERISO_CMD_RETURN(grub_errno); + } + + grub_snprintf(initrd_script, sizeof(initrd_script), + "initrd ($hiso_efi_part)/EFI/hiperiso/initramfs.cpio.gz"); + grub_script_execute_sourcecode(initrd_script); + if (grub_errno != GRUB_ERR_NONE) + { + debug("hiperiso_boot: Failed to load initramfs\n"); + HIPERISO_CMD_RETURN(grub_errno); + } + + debug("hiperiso_boot: Launching hypervisor for %s\n", iso_path); + + grub_script_execute_sourcecode("boot"); + + if (grub_errno != GRUB_ERR_NONE) + { + debug("hiperiso_boot: boot command failed\n"); + } + + HIPERISO_CMD_RETURN(grub_errno); +} + + +static cmd_para hiperiso_cmds[] = +{ + { "vt_browser_disk", hiperiso_cmd_browser_disk, 0, NULL, "", "", NULL }, + { "vt_browser_dir", hiperiso_cmd_browser_dir, 0, NULL, "", "", NULL }, + { "vt_incr", hiperiso_cmd_incr, 0, NULL, "{Var} {INT}", "Increase integer variable", NULL }, + { "vt_mod", hiperiso_cmd_mod, 0, NULL, "{Int} {Int} {Var}", "mod integer variable", NULL }, + { "vt_strstr", hiperiso_cmd_strstr, 0, NULL, "", "", NULL }, + { "vt_istrstr", hiperiso_cmd_istrstr, 0, NULL, "", "", NULL }, + { "vt_str_begin", hiperiso_cmd_strbegin, 0, NULL, "", "", NULL }, + { "vt_str_casebegin", hiperiso_cmd_strcasebegin, 0, NULL, "", "", NULL }, + { "vt_debug", hiperiso_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL }, + { "vtdebug", hiperiso_cmd_debug, 0, NULL, "{on|off}", "turn debug on/off", NULL }, + { "vtbreak", hiperiso_cmd_break, 0, NULL, "{level}", "set debug break", NULL }, + { "vt_cmp", hiperiso_cmd_cmp, 0, NULL, "{Int1} { eq|ne|gt|lt|ge|le } {Int2}", "Comare two integers", NULL }, + { "vt_device", hiperiso_cmd_device, 0, NULL, "path var", "", NULL }, + { "vt_check_compatible", hiperiso_cmd_check_compatible, 0, NULL, "", "", NULL }, + { "vt_list_img", hiperiso_cmd_list_img, 0, NULL, "{device} {cntvar}", "find all iso file in device", NULL }, + { "vt_clear_img", hiperiso_cmd_clear_img, 0, NULL, "", "clear image list", NULL }, + { "vt_img_name", hiperiso_cmd_img_name, 0, NULL, "{imageID} {var}", "get image name", NULL }, + { "vt_chosen_img_path", hiperiso_cmd_chosen_img_path, 0, NULL, "{var}", "get chosen img path", NULL }, + { "vt_ext_select_img_path", hiperiso_cmd_ext_select_img_path, 0, NULL, "{var}", "select chosen img path", NULL }, + { "vt_img_sector", hiperiso_cmd_img_sector, 0, NULL, "{imageName}", "", NULL }, + { "vt_dump_img_sector", hiperiso_cmd_dump_img_sector, 0, NULL, "", "", NULL }, + { "vt_load_wimboot", hiperiso_cmd_load_wimboot, 0, NULL, "", "", NULL }, + { "vt_load_vhdboot", hiperiso_cmd_load_vhdboot, 0, NULL, "", "", NULL }, + { "vt_patch_vhdboot", hiperiso_cmd_patch_vhdboot, 0, NULL, "", "", NULL }, + { "vt_raw_chain_data", hiperiso_cmd_raw_chain_data, 0, NULL, "", "", NULL }, + { "vt_get_hiso_type", hiperiso_cmd_get_hiso_type, 0, NULL, "", "", NULL }, + { "vt_check_custom_boot", hiperiso_cmd_check_custom_boot, 0, NULL, "", "", NULL }, + { "vt_dump_custom_boot", hiperiso_cmd_dump_custom_boot, 0, NULL, "", "", NULL }, + + { "vt_skip_svd", hiperiso_cmd_skip_svd, 0, NULL, "", "", NULL }, + { "vt_cpio_busybox64", hiperiso_cmd_cpio_busybox_64, 0, NULL, "", "", NULL }, + { "vt_load_cpio", hiperiso_cmd_load_cpio, 0, NULL, "", "", NULL }, + { "vt_trailer_cpio", hiperiso_cmd_trailer_cpio, 0, NULL, "", "", NULL }, + { "vt_push_last_entry", hiperiso_cmd_push_last_entry, 0, NULL, "", "", NULL }, + { "vt_pop_last_entry", hiperiso_cmd_pop_last_entry, 0, NULL, "", "", NULL }, + { "vt_get_lib_module_ver", hiperiso_cmd_lib_module_ver, 0, NULL, "", "", NULL }, + + { "vt_load_part_table", hiperiso_cmd_load_part_table, 0, NULL, "", "", NULL }, + { "vt_check_part_exist", hiperiso_cmd_part_exist, 0, NULL, "", "", NULL }, + { "vt_get_fs_label", hiperiso_cmd_get_fs_label, 0, NULL, "", "", NULL }, + { "vt_fs_enum_1st_file", hiperiso_cmd_fs_enum_1st_file, 0, NULL, "", "", NULL }, + { "vt_fs_enum_1st_dir", hiperiso_cmd_fs_enum_1st_dir, 0, NULL, "", "", NULL }, + { "vt_file_basename", hiperiso_cmd_basename, 0, NULL, "", "", NULL }, + { "vt_file_basefile", hiperiso_cmd_basefile, 0, NULL, "", "", NULL }, + { "vt_enum_video_mode", hiperiso_cmd_enum_video_mode, 0, NULL, "", "", NULL }, + { "vt_get_video_mode", hiperiso_cmd_get_video_mode, 0, NULL, "", "", NULL }, + { "vt_update_cur_video_mode", vt_cmd_update_cur_video_mode, 0, NULL, "", "", NULL }, + + + { "vt_find_first_bootable_hd", hiperiso_cmd_find_bootable_hdd, 0, NULL, "", "", NULL }, + { "vt_dump_menu", hiperiso_cmd_dump_menu, 0, NULL, "", "", NULL }, + { "vt_dynamic_menu", hiperiso_cmd_dynamic_menu, 0, NULL, "", "", NULL }, + { "vt_check_mode", hiperiso_cmd_check_mode, 0, NULL, "", "", NULL }, + { "vt_dump_img_list", hiperiso_cmd_dump_img_list, 0, NULL, "", "", NULL }, + { "vt_dump_injection", hiperiso_cmd_dump_injection, 0, NULL, "", "", NULL }, + { "vt_dump_auto_install", hiperiso_cmd_dump_auto_install, 0, NULL, "", "", NULL }, + { "vt_dump_persistence", hiperiso_cmd_dump_persistence, 0, NULL, "", "", NULL }, + { "vt_select_auto_install", hiperiso_cmd_sel_auto_install, 0, NULL, "", "", NULL }, + { "vt_select_persistence", hiperiso_cmd_sel_persistence, 0, NULL, "", "", NULL }, + { "vt_select_conf_replace", hiperiso_select_conf_replace, 0, NULL, "", "", NULL }, + + { "vt_iso9660_nojoliet", hiperiso_cmd_iso9660_nojoliet, 0, NULL, "", "", NULL }, + { "vt_iso9660_isjoliet", hiperiso_cmd_iso9660_is_joliet, 0, NULL, "", "", NULL }, + { "vt_is_udf", hiperiso_cmd_is_udf, 0, NULL, "", "", NULL }, + { "vt_file_size", hiperiso_cmd_file_size, 0, NULL, "", "", NULL }, + { "vt_load_file_to_mem", hiperiso_cmd_load_file_to_mem, 0, NULL, "", "", NULL }, + { "vt_load_img_memdisk", hiperiso_cmd_load_img_memdisk, 0, NULL, "", "", NULL }, + { "vt_concat_efi_iso", hiperiso_cmd_concat_efi_iso, 0, NULL, "", "", NULL }, + + { "vt_linux_parse_initrd_isolinux", hiperiso_cmd_isolinux_initrd_collect, 0, NULL, "{cfgfile}", "", NULL }, + { "vt_linux_parse_initrd_grub", hiperiso_cmd_grub_initrd_collect, 0, NULL, "{cfgfile}", "", NULL }, + { "vt_linux_specify_initrd_file", hiperiso_cmd_specify_initrd_file, 0, NULL, "", "", NULL }, + { "vt_linux_clear_initrd", hiperiso_cmd_clear_initrd_list, 0, NULL, "", "", NULL }, + { "vt_linux_dump_initrd", hiperiso_cmd_dump_initrd_list, 0, NULL, "", "", NULL }, + { "vt_linux_initrd_count", hiperiso_cmd_initrd_count, 0, NULL, "", "", NULL }, + { "vt_linux_valid_initrd_count", hiperiso_cmd_valid_initrd_count, 0, NULL, "", "", NULL }, + { "vt_linux_locate_initrd", hiperiso_cmd_linux_locate_initrd, 0, NULL, "", "", NULL }, + { "vt_linux_chain_data", hiperiso_cmd_linux_chain_data, 0, NULL, "", "", NULL }, + { "vt_linux_get_main_initrd_index", hiperiso_cmd_linux_get_main_initrd_index, 0, NULL, "", "", NULL }, + + { "vt_windows_reset", hiperiso_cmd_wimdows_reset, 0, NULL, "", "", NULL }, + { "vt_windows_chain_data", hiperiso_cmd_windows_chain_data, 0, NULL, "", "", NULL }, + { "vt_windows_wimboot_data", hiperiso_cmd_windows_wimboot_data, 0, NULL, "", "", NULL }, + { "vt_windows_collect_wim_patch", hiperiso_cmd_collect_wim_patch, 0, NULL, "", "", NULL }, + { "vt_windows_locate_wim_patch", hiperiso_cmd_locate_wim_patch, 0, NULL, "", "", NULL }, + { "vt_windows_count_wim_patch", hiperiso_cmd_wim_patch_count, 0, NULL, "", "", NULL }, + { "vt_dump_wim_patch", hiperiso_cmd_dump_wim_patch, 0, NULL, "", "", NULL }, + { "vt_wim_check_bootable", hiperiso_cmd_wim_check_bootable, 0, NULL, "", "", NULL }, + { "vt_wim_chain_data", hiperiso_cmd_wim_chain_data, 0, NULL, "", "", NULL }, + + { "vt_add_replace_file", hiperiso_cmd_add_replace_file, 0, NULL, "", "", NULL }, + { "vt_get_replace_file_cnt", hiperiso_cmd_get_replace_file_cnt, 0, NULL, "", "", NULL }, + { "vt_test_block_list", hiperiso_cmd_test_block_list, 0, NULL, "", "", NULL }, + { "vt_file_exist_nocase", hiperiso_cmd_file_exist_nocase, 0, NULL, "", "", NULL }, + + + { "vt_load_plugin", hiperiso_cmd_load_plugin, 0, NULL, "", "", NULL }, + { "vt_check_plugin_json", hiperiso_cmd_plugin_check_json, 0, NULL, "", "", NULL }, + { "vt_check_password", hiperiso_cmd_check_password, 0, NULL, "", "", NULL }, + + { "vt_1st_line", hiperiso_cmd_read_1st_line, 0, NULL, "", "", NULL }, + { "vt_file_strstr", hiperiso_cmd_file_strstr, 0, NULL, "", "", NULL }, + { "vt_img_part_info", hiperiso_cmd_img_part_info, 0, NULL, "", "", NULL }, + + + { "vt_parse_iso_volume", hiperiso_cmd_parse_volume, 0, NULL, "", "", NULL }, + { "vt_parse_iso_create_date", hiperiso_cmd_parse_create_date, 0, NULL, "", "", NULL }, + { "vt_parse_freenas_ver", hiperiso_cmd_parse_freenas_ver, 0, NULL, "", "", NULL }, + { "vt_unix_parse_freebsd_ver", hiperiso_cmd_unix_freebsd_ver, 0, NULL, "", "", NULL }, + { "vt_unix_parse_freebsd_ver_elf", hiperiso_cmd_unix_freebsd_ver_elf, 0, NULL, "", "", NULL }, + { "vt_unix_reset", hiperiso_cmd_unix_reset, 0, NULL, "", "", NULL }, + { "vt_unix_check_vlnk", hiperiso_cmd_unix_check_vlnk, 0, NULL, "", "", NULL }, + { "vt_unix_replace_conf", hiperiso_cmd_unix_replace_conf, 0, NULL, "", "", NULL }, + { "vt_unix_replace_grub_conf", hiperiso_cmd_unix_replace_grub_conf, 0, NULL, "", "", NULL }, + { "vt_unix_replace_ko", hiperiso_cmd_unix_replace_ko, 0, NULL, "", "", NULL }, + { "vt_unix_ko_fillmap", hiperiso_cmd_unix_ko_fillmap, 0, NULL, "", "", NULL }, + { "vt_unix_fill_image_desc", hiperiso_cmd_unix_fill_image_desc, 0, NULL, "", "", NULL }, + { "vt_unix_gzip_new_ko", hiperiso_cmd_unix_gzip_newko, 0, NULL, "", "", NULL }, + { "vt_unix_chain_data", hiperiso_cmd_unix_chain_data, 0, NULL, "", "", NULL }, + + { "vt_img_hook_root", hiperiso_cmd_img_hook_root, 0, NULL, "", "", NULL }, + { "vt_img_unhook_root", hiperiso_cmd_img_unhook_root, 0, NULL, "", "", NULL }, + { "vt_acpi_param", hiperiso_cmd_acpi_param, 0, NULL, "", "", NULL }, + { "vt_check_secureboot_var", hiperiso_cmd_check_secureboot_var, 0, NULL, "", "", NULL }, + { "vt_clear_key", hiperiso_cmd_clear_key, 0, NULL, "", "", NULL }, + { "vt_img_check_range", hiperiso_cmd_img_check_range, 0, NULL, "", "", NULL }, + { "vt_is_pe64", hiperiso_cmd_is_pe64, 0, NULL, "", "", NULL }, + { "vt_sel_wimboot", hiperiso_cmd_sel_wimboot, 0, NULL, "", "", NULL }, + { "vt_set_wim_load_prompt", hiperiso_cmd_set_wim_prompt, 0, NULL, "", "", NULL }, + { "vt_set_theme", hiperiso_cmd_set_theme, 0, NULL, "", "", NULL }, + { "vt_set_theme_path", hiperiso_cmd_set_theme_path, 0, NULL, "", "", NULL }, + { "vt_select_theme_cfg", hiperiso_cmd_select_theme_cfg, 0, NULL, "", "", NULL }, + + { "vt_get_efi_vdisk_offset", hiperiso_cmd_get_efivdisk_offset, 0, NULL, "", "", NULL }, + { "vt_search_replace_initrd", hiperiso_cmd_search_replace_initrd, 0, NULL, "", "", NULL }, + { "vt_push_pager", hiperiso_cmd_push_pager, 0, NULL, "", "", NULL }, + { "vt_pop_pager", hiperiso_cmd_pop_pager, 0, NULL, "", "", NULL }, + { "vt_check_json_path_case", hiperiso_cmd_chk_json_pathcase, 0, NULL, "", "", NULL }, + { "vt_append_extra_sector", hiperiso_cmd_append_ext_sector, 0, NULL, "", "", NULL }, + { "gptpriority", grub_cmd_gptpriority, 0, NULL, "", "", NULL }, + { "vt_syslinux_need_nojoliet", grub_cmd_syslinux_nojoliet, 0, NULL, "", "", NULL }, + { "vt_vlnk_check", grub_cmd_check_vlnk, 0, NULL, "", "", NULL }, + { "vt_vlnk_dump_part", grub_cmd_vlnk_dump_part, 0, NULL, "", "", NULL }, + { "vt_is_vlnk_name", grub_cmd_is_vlnk_name, 0, NULL, "", "", NULL }, + { "vt_get_vlnk_dst", grub_cmd_get_vlnk_dst, 0, NULL, "", "", NULL }, + { "vt_set_fake_vlnk", hiperiso_cmd_set_fake_vlnk, 0, NULL, "", "", NULL }, + { "vt_reset_fake_vlnk", hiperiso_cmd_reset_fake_vlnk, 0, NULL, "", "", NULL }, + { "vt_iso_vd_id_parse", hiperiso_cmd_iso_vd_id_parse, 0, NULL, "", "", NULL }, + { "vt_iso_vd_id_clear", hiperiso_iso_vd_id_clear, 0, NULL, "", "", NULL }, + { "vt_iso_vd_id_begin", hiperiso_cmd_iso_vd_id_begin, 0, NULL, "", "", NULL }, + { "vt_fn_mutex_lock", hiperiso_cmd_fn_mutex_lock, 0, NULL, "", "", NULL }, + { "vt_efi_dump_rsv_page", hiperiso_cmd_dump_rsv_page, 0, NULL, "", "", NULL }, + { "vt_is_standard_winiso", hiperiso_cmd_is_standard_winiso, 0, NULL, "", "", NULL }, + { "vt_sel_winpe_wim", hiperiso_cmd_sel_winpe_wim, 0, NULL, "", "", NULL }, + { "vt_need_secondary_menu", hiperiso_cmd_need_secondary_menu, 0, NULL, "", "", NULL }, + { "vt_show_secondary_menu", hiperiso_cmd_show_secondary_menu, 0, NULL, "", "", NULL }, + { "vt_fs_ignore_case", hiperiso_cmd_fs_ignore_case, 0, NULL, "", "", NULL }, + { "vt_systemd_menu", hiperiso_cmd_linux_systemd_menu, 0, NULL, "", "", NULL }, + { "vt_limine_menu", hiperiso_cmd_linux_limine_menu, 0, NULL, "", "", NULL }, + { "vt_secondary_recover_mode", hiperiso_cmd_secondary_recover_mode, 0, NULL, "", "", NULL }, + { "vt_load_menu_lang", hiperiso_cmd_load_menu_lang, 0, NULL, "", "", NULL }, + { "vt_init_menu_lang", hiperiso_cmd_init_menu_lang, 0, NULL, "", "", NULL }, + { "vt_cur_menu_lang", hiperiso_cmd_cur_menu_lang, 0, NULL, "", "", NULL }, + { "vt_hisochksum_exist", hiperiso_cmd_hisochksum_exist, 0, NULL, "", "", NULL }, + { "vt_cmp_checksum", hiperiso_cmd_cmp_checksum, 0, NULL, "", "", NULL }, + { "vt_push_menu_lang", hiperiso_cmd_push_menulang, 0, NULL, "", "", NULL }, + { "vt_pop_menu_lang", hiperiso_cmd_pop_menulang, 0, NULL, "", "", NULL }, + { "vt_linux_initrd", hiperiso_cmd_linux_initrd, 0, NULL, "", "", NULL }, + + { "vt_sbinfo", hiperiso_cmd_sb_info, 0, NULL, "", "", NULL }, + { "vt_update_sb_policy", hiperiso_cmd_update_sb_policy, 0, NULL, "", "", NULL }, + + { "hiperiso_boot", hiperiso_cmd_boot, 0, NULL, "{iso_path}", "Boot ISO via KVM/QEMU hypervisor", NULL }, + +}; + +int hiperiso_register_all_cmd(void) +{ + grub_uint32_t i; + cmd_para *cur = NULL; + + for (i = 0; i < ARRAY_SIZE(hiperiso_cmds); i++) + { + cur = hiperiso_cmds + i; + cur->cmd = grub_register_extcmd(cur->name, cur->func, cur->flags, + cur->summary, cur->description, cur->parser); + } + + return 0; +} + +int hiperiso_unregister_all_cmd(void) +{ + grub_uint32_t i; + + for (i = 0; i < ARRAY_SIZE(hiperiso_cmds); i++) + { + grub_unregister_extcmd(hiperiso_cmds[i].cmd); + } + + return 0; +} + + diff --git a/src/grub2/hiperiso_def.h b/src/grub2/hiperiso_def.h new file mode 100644 index 0000000..64e343e --- /dev/null +++ b/src/grub2/hiperiso_def.h @@ -0,0 +1,1345 @@ +/****************************************************************************** + * hiperiso_def.h + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ + +#ifndef __HIPERISO_DEF_H__ +#define __HIPERISO_DEF_H__ + +#define HISO_MAX_DIR_DEPTH 32 + +#define HISO_MAX_SCRIPT_BUF (4 * 1024 * 1024) + +#define HISO_PART_BUF_LEN (128 * 1024) + +#define HISO_FILT_MIN_FILE_SIZE 32768 + +#define HISO_LINUX_SYSTEMD_MENU_MAX_BUF 16384 + +#define HISO_SIZE_1GB 1073741824 +#define HISO_SIZE_1MB (1024 * 1024) +#define HISO_SIZE_2MB (2 * 1024 * 1024) +#define HISO_SIZE_4MB (4 * 1024 * 1024) +#define HISO_SIZE_512KB (512 * 1024) +#define HISO_SIZE_1KB 1024 +#define HISO_SIZE_4KB 4096 +#define HISO_SIZE_32KB (32 * 1024) +#define HISO_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 + +#define hiso_to_upper(c) (((char)(c) >= 'a' && (char)(c) <= 'z') ? ((char)(c) - 'a' + 'A') : (char)(c)) + +#define HIPERISO_CMD_RETURN(err) grub_errno = (err); return (err) +#define HIPERISO_FILE_TYPE (GRUB_FILE_TYPE_NO_DECOMPRESS | GRUB_FILE_TYPE_LINUX_INITRD) + +#define hiperiso_env_op1(op, a) grub_env_##op(a) +#define hiperiso_env_op2(op, a, b) grub_env_##op((a), (b)) + +#define hiperiso_get_env(key) hiperiso_env_op1(get, key) +#define hiperiso_set_env(key, val) hiperiso_env_op2(set, key, val) + +#define HISO_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!" + +#define HISO_CHKSUM_NUM 4 + +#define HISO_PLAT_I386_UEFI 0x49413332 +#define HISO_PLAT_ARM64_UEFI 0x41413634 +#define HISO_PLAT_X86_64_UEFI 0x55454649 +#define HISO_PLAT_X86_LEGACY 0x42494f53 +#define HISO_PLAT_MIPS_UEFI 0x4D495053 + +#define HISO_COMM_CPIO "hiperiso.cpio" +#if defined(__arm__) || defined(__aarch64__) +#define HISO_ARCH_CPIO "hiperiso_arm64.cpio" +#elif defined(__mips__) +#define HISO_ARCH_CPIO "hiperiso_mips64.cpio" +#else +#define HISO_ARCH_CPIO "hiperiso_x86.cpio" +#endif + +#define hiperiso_left_key "VTLE_LFT" +#define hiperiso_top_key "VTLE_TOP" +#define hiperiso_color_key "VTLE_CLR" + +#define hiperiso_varg_4(arg) arg[0], arg[1], arg[2], arg[3] +#define hiperiso_varg_8(arg) arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7] + +#define HISO_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);\ +} + +#define hiso_tip(wait_seconds, fmt, ...) \ + grub_printf(fmt, __VA_ARGS__); \ + grub_refresh(); \ + grub_sleep(wait_seconds) + + +#define HISO_APPEND_NEWBUF(buf) \ +{\ + char *__c = buf;\ + while (*__c)\ + {\ + newbuf[pos++] = *__c;\ + __c++;\ + }\ +} + +#define HISO_SKIP_SPACE(s) \ + while (hiperiso_isspace(*s)) \ + {\ + s++;\ + } + +#define HISO_SKIP_SPACE_NEXT(s, initial) \ + s += initial;\ + while (hiperiso_isspace(*s)) \ + {\ + s++;\ + } + +#define HISO_SKIP_SPACE_NEXT_EX(s, base, initial) \ + s = base + initial;\ + while (hiperiso_isspace(*s)) \ + {\ + s++;\ + } + +#define HISO_GOTO_END(v) ret = v; goto end + +typedef enum HISO_FILE_FLT +{ + HISO_FILE_FLT_ISO = 0, /* .iso */ + HISO_FILE_FLT_WIM, /* .wim */ + HISO_FILE_FLT_EFI, /* .efi */ + HISO_FILE_FLT_IMG, /* .img */ + HISO_FILE_FLT_VHD, /* .vhd(x) */ + HISO_FILE_FLT_HISO, /* .hiso */ + + HISO_FILE_FLT_BUTT +}HISO_FILE_FLT; + +#define FILE_FLT(type) (0 == g_hiso_file_flt[HISO_FILE_FLT_##type]) + +typedef struct hiperiso_initrd_ctx +{ + const char *path_prefix; + const char *dir_prefix; +}hiperiso_initrd_ctx; + +typedef struct cmd_para +{ + const char *name; + grub_extcmd_func_t func; + grub_command_flags_t flags; + const struct grub_arg_option *parser; + + const char *summary; + const char *description; + + grub_extcmd_t cmd; +}cmd_para; + +#define hiperiso_align_2k(value) ((value + 2047) / 2048 * 2048) +#define hiperiso_align(value, align) (((value) + ((align) - 1)) & (~((align) - 1))) + +#pragma pack(1) +typedef struct cpio_newc_header +{ + char c_magic[6]; + char c_ino[8]; + char c_mode[8]; + char c_uid[8]; + char c_gid[8]; + char c_nlink[8]; + char c_mtime[8]; + char c_filesize[8]; + char c_devmajor[8]; + char c_devminor[8]; + char c_rdevmajor[8]; + char c_rdevminor[8]; + char c_namesize[8]; + char c_check[8]; +}cpio_newc_header; +#pragma pack() + + +#define cmd_raw_name ctxt->extcmd->cmd->name +#define check_free(p, func) if (p) { func(p); p = NULL; } +#define grub_check_free(p) if (p) { grub_free(p); p = NULL; } + +#define HISO_SHIM_POLICY_GUID {0x90a29d14, 0x3968, 0x48fe, { 0x85, 0x81, 0x6b, 0x7f, 0x7d, 0xc4, 0x70, 0x55 }}; + +typedef void (*HISO_BYPASS_SB)(void); +typedef void (*HISO_CHECK_SB)(void); +typedef void (*HISO_LAUNCHED)(void); +typedef struct _HISO_SHIM{ + HISO_BYPASS_SB ByPassSB; + HISO_CHECK_SB CheckSB; + HISO_LAUNCHED Launched; +} HISO_SHIM; + + +typedef int (*grub_char_check_func)(int c); +#define hiperiso_is_decimal(str) hiperiso_string_check(str, grub_isdigit) + +#define OFFSET_OF(TYPE, MEMBER) ((grub_size_t) &((TYPE *)0)->MEMBER) + +#pragma pack(1) +typedef struct hiperiso_patch_vhd +{ + grub_uint8_t part_offset_or_guid[16]; + grub_uint32_t reserved1; + grub_uint32_t part_type; + grub_uint8_t disk_signature_or_guid[16]; + grub_uint8_t reserved2[16]; + grub_uint8_t vhd_file_path[1]; +}hiperiso_patch_vhd; +#pragma pack() + +// El Torito Boot Record Volume Descriptor +#pragma pack(1) +typedef struct eltorito_descriptor +{ + grub_uint8_t type; + grub_uint8_t id[5]; + grub_uint8_t version; + grub_uint8_t system_id[32]; + grub_uint8_t reserved[32]; + grub_uint32_t sector; +}eltorito_descriptor; + +typedef struct hiperiso_iso9660_override +{ + grub_uint32_t first_sector; + grub_uint32_t first_sector_be; + grub_uint32_t size; + grub_uint32_t size_be; +}hiperiso_iso9660_override; + +typedef struct hiperiso_udf_override +{ + grub_uint32_t length; + grub_uint32_t position; +}hiperiso_udf_override; + +typedef struct hiperiso_iso9660_vd +{ + grub_uint8_t type; + grub_uint8_t id[5]; + grub_uint8_t ver; + grub_uint8_t res; + char sys[32]; + char vol[32]; + grub_uint8_t res2[8]; + grub_uint32_t space; +}hiperiso_iso9660_vd; + +/* https://wiki.osdev.org/El-Torito */ +typedef struct boot_info_table +{ + grub_uint32_t bi_data0; + grub_uint32_t bi_data1; + grub_uint32_t bi_PrimaryVolumeDescriptor; + grub_uint32_t bi_BootFileLocation; + grub_uint32_t bi_BootFileLength; + grub_uint32_t bi_Checksum; + grub_uint8_t bi_Reserved[40]; +}boot_info_table; + +#pragma pack() + +#define img_type_start 0 +#define img_type_iso 0 +#define img_type_wim 1 +#define img_type_efi 2 +#define img_type_img 3 +#define img_type_vhd 4 +#define img_type_hiso 5 +#define img_type_max 6 + +typedef struct img_info +{ + int pathlen; + char path[512]; + char name[256]; + + const char *alias; + const char *tip1; + const char *tip2; + const char *class; + const char *menu_prefix; + + int id; + int type; + int plugin_list_index; + grub_uint64_t size; + int select; + int unsupport; + + void *parent; + + struct img_info *next; + struct img_info *prev; +}img_info; + +typedef struct img_iterator_node +{ + struct img_iterator_node *next; + img_info **tail; + char dir[400]; + int dirlen; + int level; + int isocnt; + int done; + int select; + + int plugin_list_index; + + struct img_iterator_node *parent; + struct img_iterator_node *firstchild; + + void *firstiso; +}img_iterator_node; + + + +typedef struct initrd_info +{ + char name[256]; + + grub_uint64_t offset; + grub_uint64_t size; + + grub_uint8_t iso_type; // 0: iso9660 1:udf + grub_uint32_t udf_start_block; + + grub_uint64_t override_offset; + grub_uint32_t override_length; + char override_data[32]; + + struct initrd_info *next; + struct initrd_info *prev; +}initrd_info; + +extern initrd_info *g_initrd_img_list; +extern initrd_info *g_initrd_img_tail; +extern int g_initrd_img_count; +extern int g_valid_initrd_count; + +extern img_info *g_hiperiso_img_list; +extern int g_hiperiso_img_count; + +extern grub_uint8_t *g_hiperiso_cpio_buf; +extern grub_uint32_t g_hiperiso_cpio_size; +extern cpio_newc_header *g_hiperiso_initrd_head; +extern grub_uint8_t *g_hiperiso_runtime_buf; + +extern hiperiso_guid g_hiperiso_guid; + +extern hiperiso_img_chunk_list g_img_chunk_list; +extern hiperiso_img_chunk_list g_wimiso_chunk_list; +extern char *g_wimiso_path; +extern grub_uint32_t g_wimiso_size; +extern char g_arch_mode_suffix[64]; +extern const char *g_menu_prefix[img_type_max]; + +extern int g_hiperiso_debug; +void hiperiso_debug(const char *fmt, ...); +#define debug(fmt, args...) if (g_hiperiso_debug) hiperiso_debug("[HISO]: "fmt, ##args) + +#define hiso_ssprintf(buf, pos, fmt, args...) \ + pos += grub_snprintf(buf + pos, HISO_MAX_SCRIPT_BUF - pos, fmt, ##args) + +#define hiso_len_ssprintf(buf, pos, len, fmt, args...) \ + pos += grub_snprintf(buf + pos, len - pos, fmt, ##args) + +#define browser_ssprintf(mbuf, fmt, args...) \ + (mbuf)->pos += grub_snprintf((mbuf)->buf + (mbuf)->pos, (mbuf)->max - (mbuf)->pos, fmt, ##args) + +#define hiso_dummy_menuentry(buf, pos, len, title, class) \ + hiso_len_ssprintf(buf, pos, len, "menuentry \"%s\" --class=\"%s\" {\n echo \"\"\n}\n", title, class) + + +#define FLAG_HEADER_RESERVED 0x00000001 +#define FLAG_HEADER_COMPRESSION 0x00000002 +#define FLAG_HEADER_READONLY 0x00000004 +#define FLAG_HEADER_SPANNED 0x00000008 +#define FLAG_HEADER_RESOURCE_ONLY 0x00000010 +#define FLAG_HEADER_METADATA_ONLY 0x00000020 +#define FLAG_HEADER_WRITE_IN_PROGRESS 0x00000040 +#define FLAG_HEADER_RP_FIX 0x00000080 // reparse point fixup +#define FLAG_HEADER_COMPRESS_RESERVED 0x00010000 +#define FLAG_HEADER_COMPRESS_XPRESS 0x00020000 +#define FLAG_HEADER_COMPRESS_LZX 0x00040000 +#define FLAG_HEADER_COMPRESS_LZMS 0x00080000 + +#define RESHDR_FLAG_FREE 0x01 +#define RESHDR_FLAG_METADATA 0x02 +#define RESHDR_FLAG_COMPRESSED 0x04 +#define RESHDR_FLAG_SPANNED 0x08 + +#pragma pack(1) + +/* A WIM resource header */ +typedef struct wim_resource_header +{ + grub_uint64_t size_in_wim:56; /* Compressed length */ + grub_uint64_t flags:8; /* flags */ + grub_uint64_t offset; /* Offset */ + grub_uint64_t raw_size; /* Uncompressed length */ +}wim_resource_header; + +/* WIM resource header length mask */ +#define WIM_RESHDR_ZLEN_MASK 0x00ffffffffffffffULL + +/* WIM resource header flags */ +typedef enum wim_resource_header_flags +{ + WIM_RESHDR_METADATA = ( 0x02ULL << 56 ), /* Resource contains metadata */ + WIM_RESHDR_COMPRESSED = ( 0x04ULL << 56 ), /* Resource is compressed */ + WIM_RESHDR_PACKED_STREAMS = ( 0x10ULL << 56 ), /* Resource is compressed using packed streams */ +}wim_resource_header_flags; + +#define WIM_HEAD_SIGNATURE "MSWIM\0\0" + +/* WIM header */ +typedef struct wim_header +{ + grub_uint8_t signature[8]; /* Signature */ + grub_uint32_t header_len; /* Header length */ + grub_uint32_t version; /* Verson */ + grub_uint32_t flags; /* Flags */ + grub_uint32_t chunk_len; /* Chunk length */ + grub_uint8_t guid[16]; /* GUID */ + grub_uint16_t part; /* Part number */ + grub_uint16_t parts; /* Total number of parts */ + grub_uint32_t images; /* number of images */ + wim_resource_header lookup; /* Lookup table */ + wim_resource_header xml; /* XML data */ + wim_resource_header metadata; /* Boot metadata */ + grub_uint32_t boot_index; /* Boot index */ + wim_resource_header integrity; /* Integrity table */ + grub_uint8_t reserved[60]; /* Reserved */ +} wim_header; + +/* WIM header flags */ +typedef enum wim_header_flags +{ + WIM_HDR_XPRESS = 0x00020000, /* WIM uses Xpress compresson */ + WIM_HDR_LZX = 0x00040000, /* WIM uses LZX compression */ +}wim_header_flags; + +/* A WIM file hash */ +typedef struct wim_hash +{ + /* SHA-1 hash */ + grub_uint8_t sha1[20]; +}wim_hash; + +/* A WIM lookup table entry */ +typedef struct wim_lookup_entry +{ + wim_resource_header resource; /* Resource header */ + grub_uint16_t part; /* Part number */ + grub_uint32_t refcnt; /* Reference count */ + wim_hash hash; /* Hash */ +}wim_lookup_entry; + +/* WIM chunk length */ +#define WIM_CHUNK_LEN 32768 + +/* A WIM chunk buffer */ +typedef struct wim_chunk_buffer +{ + grub_uint8_t data[WIM_CHUNK_LEN]; /*Data */ +}wim_chunk_buffer; + +/* Security data */ +typedef struct wim_security_header +{ + grub_uint32_t len; /* Length */ + grub_uint32_t count; /* Number of entries */ +}wim_security_header; + +typedef struct wim_stream_entry +{ + grub_uint64_t len; + grub_uint64_t unused1; + wim_hash hash; + grub_uint16_t name_len; + /* name */ +}wim_stream_entry; + +/* Directory entry */ +typedef struct wim_directory_entry +{ + grub_uint64_t len; /* Length */ + grub_uint32_t attributes; /* Attributes */ + grub_uint32_t security; /* Security ID */ + grub_uint64_t subdir; /* Subdirectory offset */ + grub_uint8_t reserved1[16]; /* Reserved */ + grub_uint64_t created; /* Creation time */ + grub_uint64_t accessed; /* Last access time */ + grub_uint64_t written; /* Last written time */ + wim_hash hash; /* Hash */ + grub_uint8_t reserved2[12]; /* Reserved */ + grub_uint16_t streams; /* Streams */ + grub_uint16_t short_name_len; /* Short name length */ + grub_uint16_t name_len; /* Name length */ +}wim_directory_entry; + +/** Normal file */ +#define WIM_ATTR_NORMAL 0x00000080UL + +/** No security information exists for this file */ +#define WIM_NO_SECURITY 0xffffffffUL + +typedef struct reg_vk +{ + grub_uint32_t res1; + grub_uint16_t sig; + grub_uint16_t namesize; + grub_uint32_t datasize; + grub_uint32_t dataoffset; + grub_uint32_t datatype; + grub_uint16_t flag; + grub_uint16_t res2; +}reg_vk; + +#pragma pack() + + +typedef struct wim_tail +{ + grub_uint32_t wim_raw_size; + grub_uint32_t wim_align_size; + + grub_uint8_t iso_type; + grub_uint64_t file_offset; + grub_uint32_t udf_start_block; + grub_uint64_t fe_entry_size_offset; + grub_uint64_t override_offset; + grub_uint32_t override_len; + grub_uint8_t override_data[32]; + + wim_header wim_header; + + wim_hash bin_hash; + grub_uint32_t jump_exe_len; + grub_uint8_t *jump_bin_data; + grub_uint32_t bin_raw_len; + grub_uint32_t bin_align_len; + grub_uint32_t windata_flag; + + grub_uint8_t *new_meta_data; + grub_uint32_t new_meta_len; + grub_uint32_t new_meta_align_len; + + grub_uint8_t *new_lookup_data; + grub_uint32_t new_lookup_len; + grub_uint32_t new_lookup_align_len; +}wim_tail; + +typedef struct wim_patch +{ + int pathlen; + char path[256]; + + wim_hash old_hash; + wim_tail wim_data; + wim_lookup_entry *replace_look; + + int valid; + + struct wim_patch *next; +}wim_patch; + + +typedef enum _JSON_TYPE +{ + JSON_TYPE_NUMBER = 0, + JSON_TYPE_STRING, + JSON_TYPE_BOOL, + JSON_TYPE_ARRAY, + JSON_TYPE_OBJECT, + JSON_TYPE_NULL, + JSON_TYPE_BUTT +}JSON_TYPE; + + +typedef struct _HISO_JSON +{ + struct _HISO_JSON *pstPrev; + struct _HISO_JSON *pstNext; + struct _HISO_JSON *pstChild; + + JSON_TYPE enDataType; + union + { + char *pcStrVal; + int iNumVal; + grub_uint64_t lValue; + }unData; + + char *pcName; +}HISO_JSON; + +typedef struct _JSON_PARSE +{ + char *pcKey; + void *pDataBuf; + grub_uint32_t uiBufSize; +}JSON_PARSE; + +#define JSON_NEW_ITEM(pstJson, ret) \ +{ \ + (pstJson) = (HISO_JSON *)grub_zalloc(sizeof(HISO_JSON)); \ + if (NULL == (pstJson)) \ + { \ + json_debug("Failed to alloc memory for json.\n"); \ + return (ret); \ + } \ +} + +typedef int (*hiperiso_plugin_entry_pf)(HISO_JSON *json, const char *isodisk); +typedef int (*hiperiso_plugin_check_pf)(HISO_JSON *json, const char *isodisk); + +typedef struct plugin_entry +{ + const char *key; + hiperiso_plugin_entry_pf entryfunc; + hiperiso_plugin_check_pf checkfunc; + int flag; +}plugin_entry; + +typedef struct replace_fs_dir +{ + grub_device_t dev; + grub_fs_t fs; + char fullpath[512]; + char initrd[512]; + int curpos; + int dircnt; + int filecnt; +}replace_fs_dir; + +typedef struct chk_case_fs_dir +{ + grub_device_t dev; + grub_fs_t fs; +}chk_case_fs_dir; + +int hiperiso_str_all_digit(const char *str); +int hiperiso_str_all_alnum(const char *str); +int hiperiso_str_len_alnum(const char *str, int len); +char * hiperiso_str_basename(char *path); +grub_err_t hiperiso_env_int_set(const char *name, int value); +int hiperiso_str_chrcnt(const char *str, char c); +int hiperiso_strcmp(const char *pattern, const char *str); +int hiperiso_strncmp (const char *pattern, const char *str, grub_size_t n); +void hiperiso_fill_os_param(grub_file_t file, hiperiso_os_param *param); +grub_err_t hiperiso_cmd_isolinux_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_grub_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_specify_initrd_file(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_dump_initrd_list(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_clear_initrd_list(grub_extcmd_context_t ctxt, int argc, char **args); +grub_uint32_t hiperiso_get_iso_boot_catlog(grub_file_t file); +int hiperiso_has_efi_eltorito(grub_file_t file, grub_uint32_t sector); +grub_err_t hiperiso_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_linux_systemd_menu(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_linux_initrd(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_linux_limine_menu(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args); +int hiperiso_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name); +grub_file_t hiperiso_grub_file_open(enum grub_file_type type, const char *fmt, ...); +grub_uint64_t hiperiso_grub_get_file_size(const char *fmt, ...); +int hiperiso_is_dir_exist(const char *fmt, ...); +int hiperiso_fill_data(grub_uint32_t buflen, char *buffer); +grub_err_t hiperiso_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_is_pe64(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_is_standard_winiso(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_set_wim_prompt(grub_extcmd_context_t ctxt, int argc, char **args); +grub_ssize_t hiperiso_load_file_with_prompt(grub_file_t file, void *buf, grub_ssize_t size); +int hiperiso_need_prompt_load_file(void); + +HISO_JSON *hiso_json_find_item +( + HISO_JSON *pstJson, + JSON_TYPE enDataType, + const char *szKey +); +int hiso_json_parse_value +( + char *pcNewStart, + char *pcRawStart, + HISO_JSON *pstJson, + const char *pcData, + const char **ppcEnd +); +HISO_JSON * hiso_json_create(void); +int hiso_json_parse(HISO_JSON *pstJson, const char *szJsonData); + +int hiso_json_scan_parse +( + const HISO_JSON *pstJson, + grub_uint32_t uiParseNum, + JSON_PARSE *pstJsonParse +); + +int hiso_json_scan_array +( + HISO_JSON *pstJson, + const char *szKey, + HISO_JSON **ppstArrayItem +); + +int hiso_json_scan_array_ex +( + HISO_JSON *pstJson, + const char *szKey, + HISO_JSON **ppstArrayItem +); +int hiso_json_scan_object +( + HISO_JSON *pstJson, + const char *szKey, + HISO_JSON **ppstObjectItem +); +int hiso_json_get_int +( + HISO_JSON *pstJson, + const char *szKey, + int *piValue +); +int hiso_json_get_uint +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint32_t *puiValue +); +int hiso_json_get_uint64 +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint64_t *pui64Value +); +int hiso_json_get_bool +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint8_t *pbValue +); +int hiso_json_get_string +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint32_t uiBufLen, + char *pcBuf +); +const char * hiso_json_get_string_ex(HISO_JSON *pstJson, const char *szKey); +int hiso_json_destroy(HISO_JSON *pstJson); + + +grub_uint32_t CalculateCrc32 +( + const void *Buffer, + grub_uint32_t Length, + grub_uint32_t InitValue +); + +static inline int hiperiso_isspace (int c) +{ + return (c == '\n' || c == '\r' || c == ' ' || c == '\t'); +} + +static inline int hiperiso_is_word_end(int c) +{ + return (c == 0 || c == ',' || hiperiso_isspace(c)); +} + +#pragma pack(1) +typedef struct hiperiso_part_table +{ + grub_uint8_t Active; // 0x00 0x80 + + grub_uint8_t StartHead; + grub_uint16_t StartSector : 6; + grub_uint16_t StartCylinder : 10; + + grub_uint8_t FsFlag; + + grub_uint8_t EndHead; + grub_uint16_t EndSector : 6; + grub_uint16_t EndCylinder : 10; + + grub_uint32_t StartSectorId; + grub_uint32_t SectorCount; +}hiperiso_part_table; + +typedef struct hiperiso_mbr_head +{ + grub_uint8_t BootCode[446]; + hiperiso_part_table PartTbl[4]; + grub_uint8_t Byte55; + grub_uint8_t ByteAA; +}hiperiso_mbr_head; + +typedef struct hiperiso_gpt_head +{ + char Signature[8]; /* EFI PART */ + grub_uint8_t Version[4]; + grub_uint32_t Length; + grub_uint32_t Crc; + grub_uint8_t Reserved1[4]; + grub_uint64_t EfiStartLBA; + grub_uint64_t EfiBackupLBA; + grub_uint64_t PartAreaStartLBA; + grub_uint64_t PartAreaEndLBA; + grub_uint8_t DiskGuid[16]; + grub_uint64_t PartTblStartLBA; + grub_uint32_t PartTblTotNum; + grub_uint32_t PartTblEntryLen; + grub_uint32_t PartTblCrc; + grub_uint8_t Reserved2[420]; +}hiperiso_gpt_head; + +typedef struct hiperiso_gpt_part_tbl +{ + grub_uint8_t PartType[16]; + grub_uint8_t PartGuid[16]; + grub_uint64_t StartLBA; + grub_uint64_t LastLBA; + grub_uint64_t Attr; + grub_uint16_t Name[36]; +}hiperiso_gpt_part_tbl; + +typedef struct hiperiso_gpt_info +{ + hiperiso_mbr_head MBR; + hiperiso_gpt_head Head; + hiperiso_gpt_part_tbl PartTbl[128]; +}hiperiso_gpt_info; + +typedef struct vhd_footer_t +{ + char cookie[8]; // Cookie + grub_uint32_t features; // Features + grub_uint32_t ffversion; // File format version + grub_uint32_t dataoffset; // Data offset + grub_uint32_t timestamp; // Timestamp + grub_uint32_t creatorapp; // Creator application + grub_uint32_t creatorver; // Creator version + grub_uint32_t creatorhos; // Creator host OS + grub_uint32_t origsize; // Original size + grub_uint32_t currsize; // Current size + grub_uint32_t diskgeom; // Disk geometry + grub_uint32_t disktype; // Disk type + grub_uint32_t checksum; // Checksum + grub_uint8_t uniqueid[16]; // Unique ID + grub_uint8_t savedst; // Saved state +}vhd_footer_t; + +#define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n" +#define VDI_IMAGE_FILE_INFO2 "<<< Oracle VirtualBox Disk Image >>>\n" + +/** Image signature. */ +#define VDI_IMAGE_SIGNATURE (0xbeda107f) + +typedef struct VDIPREHEADER +{ + /** Just text info about image type, for eyes only. */ + char szFileInfo[64]; + /** The image signature (VDI_IMAGE_SIGNATURE). */ + grub_uint32_t u32Signature; + /** The image version (VDI_IMAGE_VERSION). */ + grub_uint32_t u32Version; +} VDIPREHEADER, *PVDIPREHEADER; + +#pragma pack() + +typedef struct hiperiso_video_mode +{ + grub_uint32_t width; + grub_uint32_t height; + grub_uint32_t bpp; +}hiperiso_video_mode; + + + +typedef struct file_fullpath +{ + char path[256]; + int vlnk_add; +}file_fullpath; + +typedef struct theme_list +{ + file_fullpath theme; + struct theme_list *next; +}theme_list; + +#define auto_install_type_file 0 +#define auto_install_type_parent 1 +typedef struct install_template +{ + int type; + int pathlen; + char isopath[256]; + + int timeout; + int autosel; + int cursel; + int templatenum; + file_fullpath *templatepath; + + char *filebuf; + int filelen; + + struct install_template *next; +}install_template; + +typedef struct dudfile +{ + int size; + char *buf; +}dudfile; + +typedef struct dud +{ + int pathlen; + char isopath[256]; + + int dudnum; + file_fullpath *dudpath; + dudfile *files; + + struct dud *next; +}dud; + +typedef struct persistence_config +{ + int pathlen; + char isopath[256]; + + int timeout; + int autosel; + int cursel; + int backendnum; + file_fullpath *backendpath; + + struct persistence_config *next; +}persistence_config; + +#define hiso_alias_image_file 0 +#define hiso_alias_directory 1 + +typedef struct menu_alias +{ + int type; + int pathlen; + char isopath[256]; + char alias[256]; + + struct menu_alias *next; +}menu_alias; + +#define hiso_tip_image_file 0 +#define hiso_tip_directory 1 +typedef struct menu_tip +{ + int type; + int pathlen; + char isopath[256]; + char tip1[1024]; + char tip2[1024]; + + struct menu_tip *next; +}menu_tip; + + +#define hiso_class_image_file 0 +#define hiso_class_directory 1 + +typedef struct menu_class +{ + int type; + int patlen; + int parent; + char pattern[256]; + char class[64]; + + struct menu_class *next; +}menu_class; + +#define hiso_custom_boot_image_file 0 +#define hiso_custom_boot_directory 1 + +typedef struct custom_boot +{ + int type; + int pathlen; + char path[256]; + char cfg[256]; + + struct custom_boot *next; +}custom_boot; + +#define hiso_max_replace_file_size (1024 * 1024) +typedef struct conf_replace +{ + int pathlen; + int img; + char isopath[256]; + char orgconf[256]; + char newconf[256]; + + struct conf_replace *next; +}conf_replace; + +#define injection_type_file 0 +#define injection_type_parent 1 +typedef struct injection_config +{ + int type; + int pathlen; + char isopath[256]; + char archive[256]; + + struct injection_config *next; +}injection_config; + +typedef struct auto_memdisk +{ + int pathlen; + char isopath[256]; + + struct auto_memdisk *next; +}auto_memdisk; + +typedef struct image_list +{ + int pathlen; + char isopath[256]; + + struct image_list *next; +}image_list; + +#define HISO_PASSWORD_NONE 0 +#define HISO_PASSWORD_TXT 1 +#define HISO_PASSWORD_MD5 2 +#define HISO_PASSWORD_SALT_MD5 3 + +typedef struct hiso_password +{ + int type; + char text[128]; + char salt[64]; + grub_uint8_t md5[16]; +}hiso_password; + +#define hiso_menu_pwd_file 0 +#define hiso_menu_pwd_parent 1 + +typedef struct menu_password +{ + int type; + int pathlen; + char isopath[256]; + + hiso_password password; + + struct menu_password *next; +}menu_password; + +extern int g_hiperiso_menu_esc; +extern int g_hiperiso_secondary_menu_on; +extern int g_hiperiso_suppress_esc; +extern int g_hiperiso_suppress_esc_default; +extern int g_hiperiso_last_entry; +extern int g_hiperiso_memdisk_mode; +extern int g_hiperiso_iso_raw; +extern int g_hiperiso_grub2_mode; +extern int g_hiperiso_wimboot_mode; +extern int g_hiperiso_iso_uefi_drv; +extern int g_hiperiso_case_insensitive; +extern int g_hiperiso_fn_mutex; +extern grub_uint8_t g_hiperiso_chain_type; +extern int g_vhdboot_enable; +extern int g_default_menu_mode; +extern char g_hiperiso_hotkey_tip[256]; +extern int g_hiperiso_menu_refresh; + +#define HIPERISO_IMG_WHITE_LIST 1 +#define HIPERISO_IMG_BLACK_LIST 2 +extern int g_plugin_image_list; + +extern hiperiso_gpt_info *g_hiperiso_part_info; +extern int g_conf_replace_count; +extern grub_uint64_t g_conf_replace_offset[HISO_MAX_CONF_REPLACE]; +extern grub_uint64_t g_svd_replace_offset; +extern conf_replace *g_conf_replace_node[HISO_MAX_CONF_REPLACE]; +extern grub_uint8_t *g_conf_replace_new_buf[HISO_MAX_CONF_REPLACE]; +extern int g_conf_replace_new_len[HISO_MAX_CONF_REPLACE]; +extern int g_conf_replace_new_len_align[HISO_MAX_CONF_REPLACE]; +extern int g_hiperiso_disk_bios_id; +extern grub_uint64_t g_hiperiso_disk_size; +extern grub_uint64_t g_hiperiso_disk_part_size[2]; +extern grub_uint32_t g_hiperiso_plat_data; + +#define hiperiso_unix_fill_virt(new_data, new_len) \ +{ \ + data_secs = (new_len + 2047) / 2048; \ + cur->mem_sector_start = sector; \ + cur->mem_sector_end = cur->mem_sector_start + data_secs; \ + cur->mem_sector_offset = offset; \ + cur->remap_sector_start = 0; \ + cur->remap_sector_end = 0; \ + cur->org_sector_start = 0; \ + grub_memcpy(override + offset, new_data, new_len); \ + cur++; \ + sector += data_secs; \ + offset += new_len; \ + chain->virt_img_size_in_bytes += data_secs * 2048; \ +} + +#define hiperiso_syscall0(name) grub_##name() +#define hiperiso_syscall1(name, a) grub_##name(a) + +void hiperiso_str_tolower(char *str); +void hiperiso_str_toupper(char *str); +char * hiperiso_get_line(char *start); +char *hiperiso_str_last(char *str, char ch); +int hiperiso_cmp_img(img_info *img1, img_info *img2); +void hiperiso_swap_img(img_info *img1, img_info *img2); +char * hiperiso_plugin_get_cur_install_template(const char *isopath, install_template **cur); +install_template * hiperiso_plugin_find_install_template(const char *isopath); +persistence_config * hiperiso_plugin_find_persistent(const char *isopath); +grub_uint64_t hiperiso_get_hiso_partsize(int part); +void hiperiso_plugin_dump_injection(void); +void hiperiso_plugin_dump_auto_install(void); +int hiperiso_plugin_get_persistent_chunklist(const char *isopath, int index, hiperiso_img_chunk_list *chunk_list); +const char * hiperiso_plugin_get_injection(const char *isopath); +const char * hiperiso_plugin_get_menu_alias(int type, const char *isopath); +const menu_tip * hiperiso_plugin_get_menu_tip(int type, const char *isopath); +const char * hiperiso_plugin_get_menu_class(int type, const char *name, const char *path); +int hiperiso_plugin_check_memdisk(const char *isopath); +int hiperiso_plugin_get_image_list_index(int type, const char *name); +int hiperiso_plugin_find_conf_replace(const char *iso, conf_replace *nodes[HISO_MAX_CONF_REPLACE]); +dud * hiperiso_plugin_find_dud(const char *iso); +int hiperiso_plugin_load_dud(dud *node, const char *isopart); +int hiperiso_get_block_list(grub_file_t file, hiperiso_img_chunk_list *chunklist, grub_disk_addr_t start); +int hiperiso_check_block_list(grub_file_t file, hiperiso_img_chunk_list *chunklist, grub_disk_addr_t start, char *err, grub_uint32_t len); +void hiperiso_plugin_dump_persistence(void); +grub_err_t hiperiso_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_set_theme_path(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_locate_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_sel_winpe_wim(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); +int hiperiso_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t *signature); +grub_err_t hiperiso_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_check_vlnk(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_replace_grub_conf(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_ko_fillmap(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc, char **args); +int hiperiso_check_device_result(int ret); +int hiperiso_check_device(grub_device_t dev); +void hiperiso_debug_dump_guid(const char *prefix, grub_uint8_t *guid); +grub_err_t hiperiso_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_get_hiso_type(grub_extcmd_context_t ctxt, int argc, char **args); +int hiperiso_check_password(const hiso_password *pwd, int retry); +int hiperiso_plugin_add_custom_boot(const char *vcfgpath); +const char * hiperiso_plugin_get_custom_boot(const char *isopath); +grub_err_t hiperiso_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args); +int hiperiso_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len); +int hiperiso_load_part_table(const char *diskname); +int hiperiso_env_init(void); +int hiperiso_register_all_cmd(void); +int hiperiso_unregister_all_cmd(void); +int hiperiso_chain_file_size(const char *path); +int hiperiso_chain_file_read(const char *path, int offset, int len, void *buf); + +#define HISO_CMD_CHECK(a) if (33554432 != g_hiperiso_disk_part_size[a]) hiperiso_syscall0(exit) + +#define hiso_theme_random_boot_second 0 +#define hiso_theme_random_boot_day 1 +#define hiso_theme_random_boot_month 2 + +#define hiperiso_env_export(env, name) \ +{\ + grub_env_set((env), (name));\ + grub_env_export(env);\ +} + +#define ret_goto_end(a) ret = a; goto end; + +extern hiperiso_grub_param *g_grub_param; + +#pragma pack(1) +#define HIPERISO_UNIX_SEG_MAGIC0 0x11223344 +#define HIPERISO_UNIX_SEG_MAGIC1 0x55667788 +#define HIPERISO_UNIX_SEG_MAGIC2 0x99aabbcc +#define HIPERISO_UNIX_SEG_MAGIC3 0xddeeff00 +#define HIPERISO_UNIX_MAX_SEGNUM 40960 +struct g_hiperiso_seg { + grub_uint64_t seg_start_bytes; + grub_uint64_t seg_end_bytes; +}; + +struct g_hiperiso_map{ + grub_uint32_t magic1[4]; + grub_uint32_t magic2[4]; + grub_uint64_t segnum; + grub_uint64_t disksize; + grub_uint8_t diskuuid[16]; + struct g_hiperiso_seg seglist[HIPERISO_UNIX_MAX_SEGNUM]; + grub_uint32_t magic3[4]; +}; +#pragma pack() + +typedef struct hiperiso_vlnk_part +{ + grub_uint32_t disksig; + grub_uint64_t partoffset; + char disk[64]; + char device[64]; + grub_device_t dev; + grub_fs_t fs; + int probe; + struct hiperiso_vlnk_part *next; +}hiperiso_vlnk_part; + + +typedef struct browser_mbuf +{ + int max; + int pos; + char *buf; +}browser_mbuf; + +typedef struct browser_node +{ + int dir; + char menuentry[1024]; + char filename[512]; + struct browser_node *prev; + struct browser_node *next; +}browser_node; + +typedef struct var_node +{ + char var[128]; + char val[256]; + + struct var_node *next; +}var_node; + +typedef struct systemd_menu_ctx +{ + char *dev; + char *buf; + const char *initrd_cmd; + int pos; + int len; +}systemd_menu_ctx; + +typedef struct global_var_cfg +{ + const char *name; + const char *defval; + char *value; +}global_var_cfg; + +typedef struct ctrl_var_cfg +{ + const char *name; + char szval[2]; +}ctrl_var_cfg; + +#define hiso_check_goto_out(p) if (!p) goto out + +extern char *g_tree_script_buf; +extern int g_tree_script_pos; +extern int g_tree_script_pre; +extern int g_tree_view_menu_style; +extern int g_sort_case_sensitive; +extern int g_wimboot_enable; +extern int g_filt_dot_underscore_file; +extern int g_filt_trash_dir; +extern int g_hiso_file_flt[HISO_FILE_FLT_BUTT]; +extern const char *g_menu_class[img_type_max]; +extern char g_iso_path[256]; +int hiperiso_add_vlnk_file(char *dir, const char *name); +grub_err_t hiperiso_cmd_browser_dir(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_browser_disk(grub_extcmd_context_t ctxt, int argc, char **args); +int hiperiso_get_fs_type(const char *fs); +int hiperiso_img_name_valid(const char *filename, grub_size_t namelen); +void * hiperiso_alloc_chain(grub_size_t size); +int hiperiso_plugin_load_menu_lang(int init, const char *lang); +const char *hiperiso_get_vmenu_title(const char *vMenu); +grub_err_t hiperiso_cmd_cur_menu_lang(grub_extcmd_context_t ctxt, int argc, char **args); +extern int hiperiso_menu_push_key(int code); +int hiperiso_ctrl_var_init(void); +int hiperiso_global_var_init(void); +grub_err_t hiperiso_cmd_push_menulang(grub_extcmd_context_t ctxt, int argc, char **args); +grub_err_t hiperiso_cmd_pop_menulang(grub_extcmd_context_t ctxt, int argc, char **args); +void hiperiso_prompt_end(void); +int hiperiso_set_sb_policy(void); + +#endif /* __HIPERISO_DEF_H__ */ + diff --git a/src/grub2/hiperiso_json.c b/src/grub2/hiperiso_json.c new file mode 100644 index 0000000..04771d2 --- /dev/null +++ b/src/grub2/hiperiso_json.c @@ -0,0 +1,758 @@ +/****************************************************************************** + * hiperiso_json.c + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +static void json_debug(const char *fmt, ...) +{ + va_list args; + + if (g_hiperiso_debug == 0) + { + return; + } + + va_start (args, fmt); + grub_vprintf (fmt, args); + va_end (args); + + grub_printf("\n"); +} + +static void hiso_json_free(HISO_JSON *pstJsonHead) +{ + HISO_JSON *pstNext = NULL; + + while (NULL != pstJsonHead) + { + pstNext = pstJsonHead->pstNext; + if ((pstJsonHead->enDataType < JSON_TYPE_BUTT) && (NULL != pstJsonHead->pstChild)) + { + hiso_json_free(pstJsonHead->pstChild); + } + + grub_free(pstJsonHead); + pstJsonHead = pstNext; + } + + return; +} + +static char *hiso_json_skip(const char *pcData) +{ + while ((NULL != pcData) && ('\0' != *pcData) && (*pcData <= 32)) + { + pcData++; + } + + return (char *)pcData; +} + +HISO_JSON *hiso_json_find_item +( + HISO_JSON *pstJson, + JSON_TYPE enDataType, + const char *szKey +) +{ + while (NULL != pstJson) + { + if ((enDataType == pstJson->enDataType) && + (0 == grub_strcmp(szKey, pstJson->pcName))) + { + return pstJson; + } + pstJson = pstJson->pstNext; + } + + return NULL; +} + +static int hiso_json_parse_number +( + HISO_JSON *pstJson, + const char *pcData, + const char **ppcEnd +) +{ + unsigned long Value; + + Value = grub_strtoul(pcData, (char **)ppcEnd, 10); + if (*ppcEnd == pcData) + { + json_debug("Failed to parse json number %s.", pcData); + return JSON_FAILED; + } + + pstJson->enDataType = JSON_TYPE_NUMBER; + pstJson->unData.lValue = Value; + + return JSON_SUCCESS; +} + +static int hiso_json_parse_string +( + char *pcNewStart, + char *pcRawStart, + HISO_JSON *pstJson, + const char *pcData, + const char **ppcEnd +) +{ + grub_uint32_t uiLen = 0; + const char *pcPos = NULL; + const char *pcTmp = pcData + 1; + + *ppcEnd = pcData; + + if ('\"' != *pcData) + { + return JSON_FAILED; + } + + pcPos = grub_strchr(pcTmp, '\"'); + if ((NULL == pcPos) || (pcPos < pcTmp)) + { + json_debug("Invalid string %s.", pcData); + return JSON_FAILED; + } + + if (*(pcPos - 1) == '\\') + { + for (pcPos++; *pcPos; pcPos++) + { + if (*pcPos == '"' && *(pcPos - 1) != '\\') + { + break; + } + } + + if (*pcPos == 0 || pcPos < pcTmp) + { + json_debug("Invalid quotes string %s.", pcData); + return JSON_FAILED; + } + } + + *ppcEnd = pcPos + 1; + uiLen = (grub_uint32_t)(unsigned long)(pcPos - pcTmp); + + pstJson->enDataType = JSON_TYPE_STRING; + pstJson->unData.pcStrVal = pcNewStart + (pcTmp - pcRawStart); + pstJson->unData.pcStrVal[uiLen] = '\0'; + + return JSON_SUCCESS; +} + +static int hiso_json_parse_array +( + char *pcNewStart, + char *pcRawStart, + HISO_JSON *pstJson, + const char *pcData, + const char **ppcEnd +) +{ + int Ret = JSON_SUCCESS; + HISO_JSON *pstJsonChild = NULL; + HISO_JSON *pstJsonItem = NULL; + const char *pcTmp = pcData + 1; + + *ppcEnd = pcData; + pstJson->enDataType = JSON_TYPE_ARRAY; + + if ('[' != *pcData) + { + return JSON_FAILED; + } + + pcTmp = hiso_json_skip(pcTmp); + + if (']' == *pcTmp) + { + *ppcEnd = pcTmp + 1; + return JSON_SUCCESS; + } + + JSON_NEW_ITEM(pstJson->pstChild, JSON_FAILED); + + Ret = hiso_json_parse_value(pcNewStart, pcRawStart, pstJson->pstChild, pcTmp, ppcEnd); + if (JSON_SUCCESS != Ret) + { + json_debug("Failed to parse array child."); + return JSON_FAILED; + } + + pstJsonChild = pstJson->pstChild; + pcTmp = hiso_json_skip(*ppcEnd); + while ((NULL != pcTmp) && (',' == *pcTmp)) + { + JSON_NEW_ITEM(pstJsonItem, JSON_FAILED); + pstJsonChild->pstNext = pstJsonItem; + pstJsonItem->pstPrev = pstJsonChild; + pstJsonChild = pstJsonItem; + + Ret = hiso_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, hiso_json_skip(pcTmp + 1), ppcEnd); + if (JSON_SUCCESS != Ret) + { + json_debug("Failed to parse array child."); + return JSON_FAILED; + } + pcTmp = hiso_json_skip(*ppcEnd); + } + + if ((NULL != pcTmp) && (']' == *pcTmp)) + { + *ppcEnd = pcTmp + 1; + return JSON_SUCCESS; + } + else + { + *ppcEnd = pcTmp; + return JSON_FAILED; + } +} + +static int hiso_json_parse_object +( + char *pcNewStart, + char *pcRawStart, + HISO_JSON *pstJson, + const char *pcData, + const char **ppcEnd +) +{ + int Ret = JSON_SUCCESS; + HISO_JSON *pstJsonChild = NULL; + HISO_JSON *pstJsonItem = NULL; + const char *pcTmp = pcData + 1; + + *ppcEnd = pcData; + pstJson->enDataType = JSON_TYPE_OBJECT; + + if ('{' != *pcData) + { + return JSON_FAILED; + } + + pcTmp = hiso_json_skip(pcTmp); + if ('}' == *pcTmp) + { + *ppcEnd = pcTmp + 1; + return JSON_SUCCESS; + } + + JSON_NEW_ITEM(pstJson->pstChild, JSON_FAILED); + + Ret = hiso_json_parse_string(pcNewStart, pcRawStart, pstJson->pstChild, pcTmp, ppcEnd); + if (JSON_SUCCESS != Ret) + { + json_debug("Failed to parse array child."); + return JSON_FAILED; + } + + pstJsonChild = pstJson->pstChild; + pstJsonChild->pcName = pstJsonChild->unData.pcStrVal; + pstJsonChild->unData.pcStrVal = NULL; + + pcTmp = hiso_json_skip(*ppcEnd); + if ((NULL == pcTmp) || (':' != *pcTmp)) + { + *ppcEnd = pcTmp; + return JSON_FAILED; + } + + Ret = hiso_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, hiso_json_skip(pcTmp + 1), ppcEnd); + if (JSON_SUCCESS != Ret) + { + json_debug("Failed to parse array child."); + return JSON_FAILED; + } + + pcTmp = hiso_json_skip(*ppcEnd); + while ((NULL != pcTmp) && (',' == *pcTmp)) + { + JSON_NEW_ITEM(pstJsonItem, JSON_FAILED); + pstJsonChild->pstNext = pstJsonItem; + pstJsonItem->pstPrev = pstJsonChild; + pstJsonChild = pstJsonItem; + + Ret = hiso_json_parse_string(pcNewStart, pcRawStart, pstJsonChild, hiso_json_skip(pcTmp + 1), ppcEnd); + if (JSON_SUCCESS != Ret) + { + json_debug("Failed to parse array child."); + return JSON_FAILED; + } + + pcTmp = hiso_json_skip(*ppcEnd); + pstJsonChild->pcName = pstJsonChild->unData.pcStrVal; + pstJsonChild->unData.pcStrVal = NULL; + if ((NULL == pcTmp) || (':' != *pcTmp)) + { + *ppcEnd = pcTmp; + return JSON_FAILED; + } + + Ret = hiso_json_parse_value(pcNewStart, pcRawStart, pstJsonChild, hiso_json_skip(pcTmp + 1), ppcEnd); + if (JSON_SUCCESS != Ret) + { + json_debug("Failed to parse array child."); + return JSON_FAILED; + } + + pcTmp = hiso_json_skip(*ppcEnd); + } + + if ((NULL != pcTmp) && ('}' == *pcTmp)) + { + *ppcEnd = pcTmp + 1; + return JSON_SUCCESS; + } + else + { + *ppcEnd = pcTmp; + return JSON_FAILED; + } +} + +int hiso_json_parse_value +( + char *pcNewStart, + char *pcRawStart, + HISO_JSON *pstJson, + const char *pcData, + const char **ppcEnd +) +{ + pcData = hiso_json_skip(pcData); + + switch (*pcData) + { + case 'n': + { + if (0 == grub_strncmp(pcData, "null", 4)) + { + pstJson->enDataType = JSON_TYPE_NULL; + *ppcEnd = pcData + 4; + return JSON_SUCCESS; + } + break; + } + case 'f': + { + if (0 == grub_strncmp(pcData, "false", 5)) + { + pstJson->enDataType = JSON_TYPE_BOOL; + pstJson->unData.lValue = 0; + *ppcEnd = pcData + 5; + return JSON_SUCCESS; + } + break; + } + case 't': + { + if (0 == grub_strncmp(pcData, "true", 4)) + { + pstJson->enDataType = JSON_TYPE_BOOL; + pstJson->unData.lValue = 1; + *ppcEnd = pcData + 4; + return JSON_SUCCESS; + } + break; + } + case '\"': + { + return hiso_json_parse_string(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd); + } + case '[': + { + return hiso_json_parse_array(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd); + } + case '{': + { + return hiso_json_parse_object(pcNewStart, pcRawStart, pstJson, pcData, ppcEnd); + } + case '-': + { + return hiso_json_parse_number(pstJson, pcData, ppcEnd); + } + default : + { + if (*pcData >= '0' && *pcData <= '9') + { + return hiso_json_parse_number(pstJson, pcData, ppcEnd); + } + } + } + + *ppcEnd = pcData; + json_debug("Invalid json data %u.", (grub_uint8_t)(*pcData)); + return JSON_FAILED; +} + +HISO_JSON * hiso_json_create(void) +{ + HISO_JSON *pstJson = NULL; + + pstJson = (HISO_JSON *)grub_zalloc(sizeof(HISO_JSON)); + if (NULL == pstJson) + { + return NULL; + } + + return pstJson; +} + +int hiso_json_parse(HISO_JSON *pstJson, const char *szJsonData) +{ + grub_uint32_t uiMemSize = 0; + int Ret = JSON_SUCCESS; + char *pcNewBuf = NULL; + const char *pcEnd = NULL; + + uiMemSize = grub_strlen(szJsonData) + 1; + pcNewBuf = (char *)grub_malloc(uiMemSize); + if (NULL == pcNewBuf) + { + json_debug("Failed to alloc new buf."); + return JSON_FAILED; + } + grub_memcpy(pcNewBuf, szJsonData, uiMemSize); + pcNewBuf[uiMemSize - 1] = 0; + + Ret = hiso_json_parse_value(pcNewBuf, (char *)szJsonData, pstJson, szJsonData, &pcEnd); + if (JSON_SUCCESS != Ret) + { + json_debug("Failed to parse json data %s start=%p, end=%p:%s.", + szJsonData, szJsonData, pcEnd, pcEnd); + return JSON_FAILED; + } + + return JSON_SUCCESS; +} + +int hiso_json_scan_parse +( + const HISO_JSON *pstJson, + grub_uint32_t uiParseNum, + JSON_PARSE *pstJsonParse +) +{ + grub_uint32_t i = 0; + const HISO_JSON *pstJsonCur = NULL; + JSON_PARSE *pstCurParse = NULL; + + for (pstJsonCur = pstJson; NULL != pstJsonCur; pstJsonCur = pstJsonCur->pstNext) + { + if ((JSON_TYPE_OBJECT == pstJsonCur->enDataType) || + (JSON_TYPE_ARRAY == pstJsonCur->enDataType)) + { + continue; + } + + for (i = 0, pstCurParse = NULL; i < uiParseNum; i++) + { + if (0 == grub_strcmp(pstJsonParse[i].pcKey, pstJsonCur->pcName)) + { + pstCurParse = pstJsonParse + i; + break; + } + } + + if (NULL == pstCurParse) + { + continue; + } + + switch (pstJsonCur->enDataType) + { + case JSON_TYPE_NUMBER: + { + if (sizeof(grub_uint32_t) == pstCurParse->uiBufSize) + { + *(grub_uint32_t *)(pstCurParse->pDataBuf) = (grub_uint32_t)pstJsonCur->unData.lValue; + } + else if (sizeof(grub_uint16_t) == pstCurParse->uiBufSize) + { + *(grub_uint16_t *)(pstCurParse->pDataBuf) = (grub_uint16_t)pstJsonCur->unData.lValue; + } + else if (sizeof(grub_uint8_t) == pstCurParse->uiBufSize) + { + *(grub_uint8_t *)(pstCurParse->pDataBuf) = (grub_uint8_t)pstJsonCur->unData.lValue; + } + else if ((pstCurParse->uiBufSize > sizeof(grub_uint64_t))) + { + grub_snprintf((char *)pstCurParse->pDataBuf, pstCurParse->uiBufSize, "%llu", + (unsigned long long)(pstJsonCur->unData.lValue)); + } + else + { + json_debug("Invalid number data buf size %u.", pstCurParse->uiBufSize); + } + break; + } + case JSON_TYPE_STRING: + { + grub_strncpy((char *)pstCurParse->pDataBuf, pstJsonCur->unData.pcStrVal, pstCurParse->uiBufSize); + break; + } + case JSON_TYPE_BOOL: + { + *(grub_uint8_t *)(pstCurParse->pDataBuf) = (pstJsonCur->unData.lValue) > 0 ? 1 : 0; + break; + } + default : + { + break; + } + } + } + + return JSON_SUCCESS; +} + +int hiso_json_scan_array +( + HISO_JSON *pstJson, + const char *szKey, + HISO_JSON **ppstArrayItem +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_ARRAY, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + *ppstArrayItem = pstJsonItem; + + return JSON_SUCCESS; +} + +int hiso_json_scan_array_ex +( + HISO_JSON *pstJson, + const char *szKey, + HISO_JSON **ppstArrayItem +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_ARRAY, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + *ppstArrayItem = pstJsonItem->pstChild; + + return JSON_SUCCESS; +} + +int hiso_json_scan_object +( + HISO_JSON *pstJson, + const char *szKey, + HISO_JSON **ppstObjectItem +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_OBJECT, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + *ppstObjectItem = pstJsonItem; + + return JSON_SUCCESS; +} + +int hiso_json_get_int +( + HISO_JSON *pstJson, + const char *szKey, + int *piValue +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + *piValue = (int)pstJsonItem->unData.lValue; + + return JSON_SUCCESS; +} + +int hiso_json_get_uint +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint32_t *puiValue +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + *puiValue = (grub_uint32_t)pstJsonItem->unData.lValue; + + return JSON_SUCCESS; +} + +int hiso_json_get_uint64 +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint64_t *pui64Value +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_NUMBER, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + *pui64Value = (grub_uint64_t)pstJsonItem->unData.lValue; + + return JSON_SUCCESS; +} + +int hiso_json_get_bool +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint8_t *pbValue +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_BOOL, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + *pbValue = pstJsonItem->unData.lValue > 0 ? 1 : 0; + + return JSON_SUCCESS; +} + +int hiso_json_get_string +( + HISO_JSON *pstJson, + const char *szKey, + grub_uint32_t uiBufLen, + char *pcBuf +) +{ + HISO_JSON *pstJsonItem = NULL; + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_STRING, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return JSON_NOT_FOUND; + } + + grub_strncpy(pcBuf, pstJsonItem->unData.pcStrVal, uiBufLen); + + return JSON_SUCCESS; +} + +const char * hiso_json_get_string_ex(HISO_JSON *pstJson, const char *szKey) +{ + HISO_JSON *pstJsonItem = NULL; + + if ((NULL == pstJson) || (NULL == szKey)) + { + return NULL; + } + + pstJsonItem = hiso_json_find_item(pstJson, JSON_TYPE_STRING, szKey); + if (NULL == pstJsonItem) + { + json_debug("Key %s is not found in json data.", szKey); + return NULL; + } + + return pstJsonItem->unData.pcStrVal; +} + +int hiso_json_destroy(HISO_JSON *pstJson) +{ + if (NULL == pstJson) + { + return JSON_SUCCESS; + } + + if (NULL != pstJson->pstChild) + { + hiso_json_free(pstJson->pstChild); + } + + if (NULL != pstJson->pstNext) + { + hiso_json_free(pstJson->pstNext); + } + + grub_free(pstJson); + + return JSON_SUCCESS; +} + diff --git a/src/grub2/hiperiso_linux.c b/src/grub2/hiperiso_linux.c new file mode 100644 index 0000000..bf55ff4 --- /dev/null +++ b/src/grub2/hiperiso_linux.c @@ -0,0 +1,2120 @@ +/****************************************************************************** + * hiperiso_linux.c + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +#define HISO_APPEND_EXT_SIZE 4096 +static int g_append_ext_sector = 0; + +char * hiperiso_get_line(char *start) +{ + if (start == NULL) + { + return NULL; + } + + while (*start && *start != '\n') + { + start++; + } + + if (*start == 0) + { + return NULL; + } + else + { + *start = 0; + return start + 1; + } +} + +static initrd_info * hiperiso_find_initrd_by_name(initrd_info *list, const char *name) +{ + initrd_info *node = list; + + while (node) + { + if (grub_strcmp(node->name, name) == 0) + { + return node; + } + node = node->next; + } + + return NULL; +} + +grub_err_t hiperiso_cmd_clear_initrd_list(grub_extcmd_context_t ctxt, int argc, char **args) +{ + initrd_info *node = g_initrd_img_list; + initrd_info *next; + + (void)ctxt; + (void)argc; + (void)args; + + while (node) + { + next = node->next; + grub_free(node); + node = next; + } + + g_initrd_img_list = NULL; + g_initrd_img_tail = NULL; + g_initrd_img_count = 0; + g_valid_initrd_count = 0; + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_dump_initrd_list(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i = 0; + initrd_info *node = g_initrd_img_list; + + (void)ctxt; + (void)argc; + (void)args; + + grub_printf("###################\n"); + grub_printf("initrd info list: valid count:%d\n", g_valid_initrd_count); + + while (node) + { + grub_printf("%s ", node->size > 0 ? "*" : " "); + grub_printf("%02u %s offset:%llu size:%llu \n", i++, node->name, (unsigned long long)node->offset, + (unsigned long long)node->size); + node = node->next; + } + + grub_printf("###################\n"); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static void hiperiso_parse_directory(char *path, char *dir, int buflen) +{ + int end; + char *pos; + + pos = grub_strstr(path, ")"); + if (!pos) + { + pos = path; + } + + end = grub_snprintf(dir, buflen, "%s", pos + 1); + while (end > 0) + { + if (dir[end] == '/') + { + dir[end + 1] = 0; + break; + } + end--; + } +} + +static grub_err_t hiperiso_isolinux_initrd_collect(grub_file_t file, const char *prefix) +{ + int i = 0; + int offset; + int prefixlen = 0; + char *buf = NULL; + char *pos = NULL; + char *start = NULL; + char *nextline = NULL; + initrd_info *img = NULL; + + prefixlen = grub_strlen(prefix); + + buf = grub_zalloc(file->size + 2); + if (!buf) + { + return 0; + } + + grub_file_read(file, buf, file->size); + + for (start = buf; start; start = nextline) + { + nextline = hiperiso_get_line(start); + + HISO_SKIP_SPACE(start); + + offset = 7; // strlen("initrd=") or "INITRD " or "initrd " + pos = grub_strstr(start, "initrd="); + if (pos == NULL) + { + pos = start; + + if (grub_strncmp(start, "INITRD", 6) != 0 && grub_strncmp(start, "initrd", 6) != 0) + { + if (grub_strstr(start, "xen") && + ((pos = grub_strstr(start, "--- /install.img")) != NULL || + (pos = grub_strstr(start, "--- initrd.img")) != NULL + )) + { + offset = 4; // "--- " + } + else + { + continue; + } + } + } + + pos += offset; + + while (1) + { + i = 0; + img = grub_zalloc(sizeof(initrd_info)); + if (!img) + { + break; + } + + if (*pos != '/') + { + grub_strcpy(img->name, prefix); + i = prefixlen; + } + + while (i < 255 && (0 == hiperiso_is_word_end(*pos))) + { + img->name[i++] = *pos++; + } + + if (hiperiso_find_initrd_by_name(g_initrd_img_list, img->name)) + { + grub_free(img); + } + else + { + if (g_initrd_img_list) + { + img->prev = g_initrd_img_tail; + g_initrd_img_tail->next = img; + } + else + { + g_initrd_img_list = img; + } + + g_initrd_img_tail = img; + g_initrd_img_count++; + } + + if (*pos == ',') + { + pos++; + } + else + { + break; + } + } + } + + grub_free(buf); + return GRUB_ERR_NONE; +} + +static int hiperiso_isolinux_initrd_hook(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + grub_file_t file = NULL; + hiperiso_initrd_ctx *ctx = (hiperiso_initrd_ctx *)data; + + (void)info; + + if (NULL == grub_strstr(filename, ".cfg") && NULL == grub_strstr(filename, ".CFG")) + { + return 0; + } + + debug("init hook dir <%s%s>\n", ctx->path_prefix, filename); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", ctx->path_prefix, filename); + if (!file) + { + return 0; + } + + hiperiso_isolinux_initrd_collect(file, ctx->dir_prefix); + grub_file_close(file); + + return 0; +} + +grub_err_t hiperiso_cmd_isolinux_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_fs_t fs; + grub_device_t dev = NULL; + char *device_name = NULL; + hiperiso_initrd_ctx ctx; + char directory[256]; + + (void)ctxt; + (void)argc; + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + goto end; + } + + dev = grub_device_open(device_name); + if (!dev) + { + goto end; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + goto end; + } + + debug("isolinux initrd collect %s\n", args[0]); + + hiperiso_parse_directory(args[0], directory, sizeof(directory) - 1); + ctx.path_prefix = args[0]; + ctx.dir_prefix = (argc > 1) ? args[1] : directory; + + debug("path_prefix=<%s> dir_prefix=<%s>\n", ctx.path_prefix, ctx.dir_prefix); + + fs->fs_dir(dev, directory, hiperiso_isolinux_initrd_hook, &ctx); + +end: + check_free(device_name, grub_free); + check_free(dev, grub_device_close); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_linux_initrd_collect_hook(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + int len; + initrd_info *img = NULL; + + (void)data; + + if (0 == info->dir) + { + if (grub_strncmp(filename, "initrd", 6) == 0) + { + len = (int)grub_strlen(filename); + if (grub_strcmp(filename + len - 4, ".img") == 0) + { + img = grub_zalloc(sizeof(initrd_info)); + if (img) + { + grub_snprintf(img->name, sizeof(img->name), "/boot/%s", filename); + + if (hiperiso_find_initrd_by_name(g_initrd_img_list, img->name)) + { + grub_free(img); + } + else + { + if (g_initrd_img_list) + { + img->prev = g_initrd_img_tail; + g_initrd_img_tail->next = img; + } + else + { + g_initrd_img_list = img; + } + + g_initrd_img_tail = img; + g_initrd_img_count++; + } + } + } + } + } + + return 0; +} + +static int hiperiso_linux_collect_boot_initrds(void) +{ + grub_fs_t fs; + grub_device_t dev = NULL; + + dev = grub_device_open("loop"); + if (!dev) + { + debug("failed to open device loop\n"); + goto end; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + debug("failed to probe fs %d\n", grub_errno); + goto end; + } + + fs->fs_dir(dev, "/boot", hiperiso_linux_initrd_collect_hook, NULL); + +end: + return 0; +} + +static grub_err_t hiperiso_grub_cfg_initrd_collect(const char *fileName) +{ + int i = 0; + int len = 0; + int dollar = 0; + int quotation = 0; + int initrd_dollar = 0; + grub_file_t file = NULL; + char *buf = NULL; + char *start = NULL; + char *nextline = NULL; + initrd_info *img = NULL; + + debug("grub initrd collect %s\n", fileName); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", fileName); + if (!file) + { + return 0; + } + + buf = grub_zalloc(file->size + 2); + if (!buf) + { + grub_file_close(file); + return 0; + } + + grub_file_read(file, buf, file->size); + + for (start = buf; start; start = nextline) + { + nextline = hiperiso_get_line(start); + + HISO_SKIP_SPACE(start); + + if (grub_strncmp(start, "initrd", 6) != 0) + { + continue; + } + + start += 6; + while (*start && (!hiperiso_isspace(*start))) + { + start++; + } + + HISO_SKIP_SPACE(start); + + if (*start == '"') + { + quotation = 1; + start++; + } + + while (*start) + { + img = grub_zalloc(sizeof(initrd_info)); + if (!img) + { + break; + } + + dollar = 0; + for (i = 0; i < 255 && (0 == hiperiso_is_word_end(*start)); i++) + { + img->name[i] = *start++; + if (img->name[i] == '$') + { + dollar = 1; + } + } + + if (quotation) + { + len = (int)grub_strlen(img->name); + if (len > 2 && img->name[len - 1] == '"') + { + img->name[len - 1] = 0; + } + debug("Remove quotation <%s>\n", img->name); + } + + /* special process for /boot/initrd$XXX.img */ + if (dollar == 1) + { + if (grub_strncmp(img->name, "/boot/initrd$", 13) == 0) + { + len = (int)grub_strlen(img->name); + if (grub_strcmp(img->name + len - 4, ".img") == 0) + { + initrd_dollar++; + } + } + } + + if (dollar == 1 || hiperiso_find_initrd_by_name(g_initrd_img_list, img->name)) + { + grub_free(img); + } + else + { + if (g_initrd_img_list) + { + img->prev = g_initrd_img_tail; + g_initrd_img_tail->next = img; + } + else + { + g_initrd_img_list = img; + } + + g_initrd_img_tail = img; + g_initrd_img_count++; + } + + if (*start == ' ' || *start == '\t') + { + HISO_SKIP_SPACE(start); + } + else + { + break; + } + } + } + + grub_free(buf); + grub_file_close(file); + + if (initrd_dollar > 0 && grub_strncmp(fileName, "(loop)/", 7) == 0) + { + debug("collect initrd variable %d\n", initrd_dollar); + hiperiso_linux_collect_boot_initrds(); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_grub_initrd_hook(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + char filePath[256]; + hiperiso_initrd_ctx *ctx = (hiperiso_initrd_ctx *)data; + + (void)info; + + debug("hiperiso_grub_initrd_hook %s\n", filename); + + if (NULL == grub_strstr(filename, ".cfg") && + NULL == grub_strstr(filename, ".CFG") && + NULL == grub_strstr(filename, ".conf")) + { + return 0; + } + + debug("init hook dir <%s%s>\n", ctx->path_prefix, filename); + + grub_snprintf(filePath, sizeof(filePath) - 1, "%s%s", ctx->dir_prefix, filename); + hiperiso_grub_cfg_initrd_collect(filePath); + + return 0; +} + +grub_err_t hiperiso_cmd_grub_initrd_collect(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_fs_t fs; + grub_device_t dev = NULL; + char *device_name = NULL; + hiperiso_initrd_ctx ctx; + + (void)ctxt; + (void)argc; + + if (argc != 2) + { + return 0; + } + + debug("grub initrd collect %s %s\n", args[0], args[1]); + + if (grub_strcmp(args[0], "file") == 0) + { + return hiperiso_grub_cfg_initrd_collect(args[1]); + } + + device_name = grub_file_get_device_name(args[1]); + if (!device_name) + { + debug("failed to get device name %s\n", args[1]); + goto end; + } + + dev = grub_device_open(device_name); + if (!dev) + { + debug("failed to open device %s\n", device_name); + goto end; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + debug("failed to probe fs %d\n", grub_errno); + goto end; + } + + ctx.dir_prefix = args[1]; + ctx.path_prefix = grub_strstr(args[1], device_name); + if (ctx.path_prefix) + { + ctx.path_prefix += grub_strlen(device_name) + 1; + } + else + { + ctx.path_prefix = args[1]; + } + + debug("ctx.path_prefix:<%s>\n", ctx.path_prefix); + + fs->fs_dir(dev, ctx.path_prefix, hiperiso_grub_initrd_hook, &ctx); + +end: + check_free(device_name, grub_free); + check_free(dev, grub_device_close); + + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_specify_initrd_file(grub_extcmd_context_t ctxt, int argc, char **args) +{ + initrd_info *img = NULL; + + (void)ctxt; + (void)argc; + + debug("hiperiso_cmd_specify_initrd_file %s\n", args[0]); + + img = grub_zalloc(sizeof(initrd_info)); + if (!img) + { + return 1; + } + + grub_strncpy(img->name, args[0], sizeof(img->name)); + if (hiperiso_find_initrd_by_name(g_initrd_img_list, img->name)) + { + debug("%s is already exist\n", args[0]); + grub_free(img); + } + else + { + if (g_initrd_img_list) + { + img->prev = g_initrd_img_tail; + g_initrd_img_tail->next = img; + } + else + { + g_initrd_img_list = img; + } + + g_initrd_img_tail = img; + g_initrd_img_count++; + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_cpio_newc_get_int(char *value) +{ + char buf[16] = {0}; + + grub_memcpy(buf, value, 8); + return (int)grub_strtoul(buf, NULL, 16); +} + +static void hiperiso_cpio_newc_fill_int(grub_uint32_t value, char *buf, int buflen) +{ + int i; + int len; + char intbuf[32]; + + len = grub_snprintf(intbuf, sizeof(intbuf), "%x", value); + + for (i = 0; i < buflen; i++) + { + buf[i] = '0'; + } + + if (len > buflen) + { + grub_printf("int buf len overflow %d %d\n", len, buflen); + } + else + { + grub_memcpy(buf + buflen - len, intbuf, len); + } +} + +int hiperiso_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name) +{ + int namelen = 0; + int headlen = 0; + static grub_uint32_t cpio_ino = 0xFFFFFFF0; + cpio_newc_header *cpio = (cpio_newc_header *)buf; + + namelen = grub_strlen(name) + 1; + headlen = sizeof(cpio_newc_header) + namelen; + headlen = hiperiso_align(headlen, 4); + + grub_memset(cpio, '0', sizeof(cpio_newc_header)); + grub_memset(cpio + 1, 0, headlen - sizeof(cpio_newc_header)); + + grub_memcpy(cpio->c_magic, "070701", 6); + hiperiso_cpio_newc_fill_int(cpio_ino--, cpio->c_ino, 8); + hiperiso_cpio_newc_fill_int(0100777, cpio->c_mode, 8); + hiperiso_cpio_newc_fill_int(1, cpio->c_nlink, 8); + hiperiso_cpio_newc_fill_int(filesize, cpio->c_filesize, 8); + hiperiso_cpio_newc_fill_int(namelen, cpio->c_namesize, 8); + grub_memcpy(cpio + 1, name, namelen); + + if (filedata) + { + grub_memcpy((char *)cpio + headlen, filedata, filesize); + } + + return headlen; +} + +static grub_uint32_t hiperiso_linux_get_virt_chunk_count(void) +{ + int i; + grub_uint32_t count = g_valid_initrd_count; + + if (g_conf_replace_count > 0) + { + for (i = 0; i < g_conf_replace_count; i++) + { + if (g_conf_replace_offset[i] > 0) + { + count++; + } + } + } + + if (g_append_ext_sector > 0) + { + count++; + } + + return count; +} + +static grub_uint32_t hiperiso_linux_get_virt_chunk_size(void) +{ + int i; + grub_uint32_t size; + + size = (sizeof(hiperiso_virt_chunk) + g_hiperiso_cpio_size) * g_valid_initrd_count; + + if (g_conf_replace_count > 0) + { + for (i = 0; i < g_conf_replace_count; i++) + { + if (g_conf_replace_offset[i] > 0) + { + size += sizeof(hiperiso_virt_chunk) + g_conf_replace_new_len_align[i]; + } + } + } + + if (g_append_ext_sector > 0) + { + size += sizeof(hiperiso_virt_chunk) + HISO_APPEND_EXT_SIZE; + } + + return size; +} + +static void hiperiso_linux_fill_virt_data( grub_uint64_t isosize, hiperiso_chain_head *chain) +{ + int i = 0; + int id = 0; + int virtid = 0; + initrd_info *node; + grub_uint64_t sector; + grub_uint32_t offset; + grub_uint32_t cpio_secs; + grub_uint32_t initrd_secs; + char *override; + hiperiso_virt_chunk *cur; + hiperiso_grub_param_file_replace *replace = NULL; + char name[32]; + + override = (char *)chain + chain->virt_chunk_offset; + sector = (isosize + 2047) / 2048; + cpio_secs = g_hiperiso_cpio_size / 2048; + + offset = hiperiso_linux_get_virt_chunk_count() * sizeof(hiperiso_virt_chunk); + cur = (hiperiso_virt_chunk *)override; + + for (node = g_initrd_img_list; node; node = node->next) + { + if (node->size == 0) + { + continue; + } + + initrd_secs = (grub_uint32_t)((node->size + 2047) / 2048); + + cur->mem_sector_start = sector; + cur->mem_sector_end = cur->mem_sector_start + cpio_secs; + cur->mem_sector_offset = offset; + cur->remap_sector_start = cur->mem_sector_end; + cur->remap_sector_end = cur->remap_sector_start + initrd_secs; + cur->org_sector_start = (grub_uint32_t)(node->offset / 2048); + + grub_memcpy(g_hiperiso_runtime_buf, &chain->os_param, sizeof(hiperiso_os_param)); + + grub_memset(name, 0, 16); + grub_snprintf(name, sizeof(name), "initrd%03d", ++id); + + grub_memcpy(g_hiperiso_initrd_head + 1, name, 16); + hiperiso_cpio_newc_fill_int((grub_uint32_t)node->size, g_hiperiso_initrd_head->c_filesize, 8); + + grub_memcpy(override + offset, g_hiperiso_cpio_buf, g_hiperiso_cpio_size); + + chain->virt_img_size_in_bytes += g_hiperiso_cpio_size + initrd_secs * 2048; + + offset += g_hiperiso_cpio_size; + sector += cpio_secs + initrd_secs; + cur++; + virtid++; + } + + /* Lenovo EasyStartup need an addional sector for boundary check */ + if (g_append_ext_sector > 0) + { + cpio_secs = HISO_APPEND_EXT_SIZE / 2048; + + cur->mem_sector_start = sector; + cur->mem_sector_end = cur->mem_sector_start + cpio_secs; + cur->mem_sector_offset = offset; + cur->remap_sector_start = 0; + cur->remap_sector_end = 0; + cur->org_sector_start = 0; + + grub_memset(override + offset, 0, HISO_APPEND_EXT_SIZE); + + chain->virt_img_size_in_bytes += HISO_APPEND_EXT_SIZE; + + offset += HISO_APPEND_EXT_SIZE; + sector += cpio_secs; + cur++; + virtid++; + } + + if (g_conf_replace_count > 0) + { + for (i = 0; i < g_conf_replace_count; i++) + { + if (g_conf_replace_offset[i] > 0) + { + cpio_secs = g_conf_replace_new_len_align[i] / 2048; + + cur->mem_sector_start = sector; + cur->mem_sector_end = cur->mem_sector_start + cpio_secs; + cur->mem_sector_offset = offset; + cur->remap_sector_start = 0; + cur->remap_sector_end = 0; + cur->org_sector_start = 0; + + grub_memcpy(override + offset, g_conf_replace_new_buf[i], g_conf_replace_new_len[i]); + + chain->virt_img_size_in_bytes += g_conf_replace_new_len_align[i]; + + replace = g_grub_param->img_replace + i; + if (replace->magic == GRUB_IMG_REPLACE_MAGIC) + { + replace->new_file_virtual_id = virtid; + } + + offset += g_conf_replace_new_len_align[i]; + sector += cpio_secs; + cur++; + virtid++; + } + } + } + + return; +} + +static grub_uint32_t hiperiso_linux_get_override_chunk_count(void) +{ + int i; + grub_uint32_t count = g_valid_initrd_count; + + if (g_conf_replace_count > 0) + { + for (i = 0; i < g_conf_replace_count; i++) + { + if (g_conf_replace_offset[i] > 0) + { + count++; + } + } + } + + if (g_svd_replace_offset > 0) + { + count++; + } + + return count; +} + +static grub_uint32_t hiperiso_linux_get_override_chunk_size(void) +{ + int i; + int count = g_valid_initrd_count; + + if (g_conf_replace_count > 0) + { + for (i = 0; i < g_conf_replace_count; i++) + { + if (g_conf_replace_offset[i] > 0) + { + count++; + } + } + } + + if (g_svd_replace_offset > 0) + { + count++; + } + + return sizeof(hiperiso_override_chunk) * count; +} + +static void hiperiso_linux_fill_override_data( grub_uint64_t isosize, void *override) +{ + int i; + initrd_info *node; + grub_uint32_t mod; + grub_uint32_t newlen; + grub_uint64_t sector; + hiperiso_override_chunk *cur; + hiperiso_iso9660_override *dirent; + hiperiso_udf_override *udf; + + sector = (isosize + 2047) / 2048; + + cur = (hiperiso_override_chunk *)override; + for (node = g_initrd_img_list; node; node = node->next) + { + if (node->size == 0) + { + continue; + } + + newlen = (grub_uint32_t)(node->size + g_hiperiso_cpio_size); + mod = newlen % 4; + if (mod > 0) + { + newlen += 4 - mod; /* cpio must align with 4 */ + } + + if (node->iso_type == 0) + { + dirent = (hiperiso_iso9660_override *)node->override_data; + + node->override_length = sizeof(hiperiso_iso9660_override); + dirent->first_sector = (grub_uint32_t)sector; + dirent->size = newlen; + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size_be = grub_swap_bytes32(dirent->size); + + sector += (dirent->size + 2047) / 2048; + } + else + { + udf = (hiperiso_udf_override *)node->override_data; + + node->override_length = sizeof(hiperiso_udf_override); + udf->length = newlen; + udf->position = (grub_uint32_t)sector - node->udf_start_block; + + sector += (udf->length + 2047) / 2048; + } + + cur->img_offset = node->override_offset; + cur->override_size = node->override_length; + grub_memcpy(cur->override_data, node->override_data, cur->override_size); + cur++; + } + + if (g_conf_replace_count > 0) + { + for (i = 0; i < g_conf_replace_count; i++) + { + if (g_conf_replace_offset[i] > 0) + { + cur->img_offset = g_conf_replace_offset[i]; + cur->override_size = sizeof(hiperiso_iso9660_override); + + newlen = (grub_uint32_t)(g_conf_replace_new_len[i]); + + dirent = (hiperiso_iso9660_override *)cur->override_data; + dirent->first_sector = (grub_uint32_t)sector; + dirent->size = newlen; + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size_be = grub_swap_bytes32(dirent->size); + + sector += (dirent->size + 2047) / 2048; + 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; +} + +grub_err_t hiperiso_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char buf[32] = {0}; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc == 1) + { + grub_snprintf(buf, sizeof(buf), "%d", g_initrd_img_count); + grub_env_set(args[0], buf); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char buf[32] = {0}; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc == 1) + { + grub_snprintf(buf, sizeof(buf), "%d", g_valid_initrd_count); + grub_env_set(args[0], buf); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_linux_locate_initrd(int filt, int *filtcnt) +{ + int data; + int filtbysize = 1; + int sizefilt = 0; + grub_file_t file; + initrd_info *node; + + debug("hiperiso_linux_locate_initrd %d\n", filt); + + g_valid_initrd_count = 0; + + if (grub_env_get("INITRD_NO_SIZE_FILT")) + { + filtbysize = 0; + } + + for (node = g_initrd_img_list; node; node = node->next) + { + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "(loop)%s", node->name); + if (!file) + { + continue; + } + + debug("file <%s> size:%d\n", node->name, (int)file->size); + + /* initrd file too small */ + if (filtbysize + && (NULL == grub_strstr(node->name, "minirt.gz")) + && (NULL == grub_strstr(node->name, "initrd.xz")) + && (NULL == grub_strstr(node->name, "initrd.gz")) + ) + { + if (filt > 0 && file->size <= g_hiperiso_cpio_size + 2048) + { + debug("file size too small %d\n", (int)g_hiperiso_cpio_size); + grub_file_close(file); + sizefilt++; + continue; + } + } + + /* skip hdt.img */ + if (file->size <= HISO_SIZE_1MB && grub_strcmp(node->name, "/boot/hdt.img") == 0) + { + continue; + } + + if (grub_strcmp(file->fs->name, "iso9660") == 0) + { + node->iso_type = 0; + node->override_offset = grub_iso9660_get_last_file_dirent_pos(file) + 2; + + grub_file_read(file, &data, 1); // just read for hook trigger + node->offset = grub_iso9660_get_last_read_pos(file); + } + else + { + /* TBD */ + } + + node->size = file->size; + g_valid_initrd_count++; + + grub_file_close(file); + } + + *filtcnt = sizefilt; + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + + +grub_err_t hiperiso_cmd_linux_get_main_initrd_index(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int index = 0; + char buf[32]; + initrd_info *node = NULL; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 1) + { + return 1; + } + + if (g_initrd_img_count == 1) + { + hiperiso_set_env(args[0], "0"); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); + } + + for (node = g_initrd_img_list; node; node = node->next) + { + if (node->size <= 0) + { + continue; + } + + if (grub_strstr(node->name, "ucode") || grub_strstr(node->name, "-firmware")) + { + index++; + continue; + } + + grub_snprintf(buf, sizeof(buf), "%d", index); + hiperiso_set_env(args[0], buf); + break; + } + + debug("main initrd index:%d\n", index); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int sizefilt = 0; + + (void)ctxt; + (void)argc; + (void)args; + + hiperiso_linux_locate_initrd(1, &sizefilt); + + if (g_valid_initrd_count == 0 && sizefilt > 0) + { + hiperiso_linux_locate_initrd(0, &sizefilt); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_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), "hiperiso/busybox/%s", file); + + name = (char *)(head + 1); + while (name[0] && count < 2) + { + if (grub_strcmp(name, "hiperiso/busybox/ash") == 0) + { + grub_memcpy(name, "hiperiso/busybox/32h", 18); + count++; + } + else if (grub_strcmp(name, filepath) == 0) + { + grub_memcpy(name, "hiperiso/busybox/ash", 18); + count++; + } + + namelen = hiperiso_cpio_newc_get_int(head->c_namesize); + offset = sizeof(cpio_newc_header) + namelen; + offset = hiperiso_align(offset, 4); + offset += hiperiso_cpio_newc_get_int(head->c_filesize); + offset = hiperiso_align(offset, 4); + + head = (cpio_newc_header *)((char *)head + offset); + name = (char *)(head + 1); + } + + return 0; +} + + +grub_err_t hiperiso_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + debug("hiperiso_cmd_busybox_64 %d\n", argc); + hiperiso_cpio_busybox64((cpio_newc_header *)g_hiperiso_cpio_buf, args[0]); + return 0; +} + +grub_err_t hiperiso_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 = hiperiso_grub_file_open(HIPERISO_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); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + if (args[0][0] == '1') + { + g_append_ext_sector = 1; + } + else + { + g_append_ext_sector = 0; + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int rc; + char *pos = NULL; + char *template_file = NULL; + char *template_buf = NULL; + char *persistent_buf = NULL; + char *injection_buf = NULL; + dud *dudnode = NULL; + char tmpname[128]; + const char *injection_file = NULL; + grub_uint8_t *buf = NULL; + grub_uint32_t mod; + grub_uint32_t headlen; + grub_uint32_t initrd_head_len; + grub_uint32_t padlen; + grub_uint32_t img_chunk_size; + grub_uint32_t template_size = 0; + grub_uint32_t persistent_size = 0; + grub_uint32_t injection_size = 0; + grub_uint32_t dud_size = 0; + grub_file_t file; + grub_file_t archfile; + grub_file_t tmpfile; + install_template *template_node = NULL; + hiperiso_img_chunk_list chunk_list; + + (void)ctxt; + (void)argc; + + if (argc != 4) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s cpiofile\n", cmd_raw_name); + } + + if (g_img_chunk_list.chunk == NULL || g_img_chunk_list.cur_chunk == 0) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "image chunk is null\n"); + } + + img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s/%s", args[0], HISO_COMM_CPIO); + if (!file) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], HISO_COMM_CPIO); + } + + archfile = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s/%s", args[0], HISO_ARCH_CPIO); + if (!archfile) + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't open file %s/%s\n", args[0], HISO_ARCH_CPIO); + grub_file_close(file); + } + + debug("load %s %s success\n", HISO_COMM_CPIO, HISO_ARCH_CPIO); + + if (g_hiperiso_cpio_buf) + { + grub_free(g_hiperiso_cpio_buf); + g_hiperiso_cpio_buf = NULL; + g_hiperiso_cpio_size = 0; + } + + rc = hiperiso_plugin_get_persistent_chunklist(args[1], -1, &chunk_list); + if (rc == 0 && chunk_list.cur_chunk > 0 && chunk_list.chunk) + { + persistent_size = chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + persistent_buf = (char *)(chunk_list.chunk); + } + + template_file = hiperiso_plugin_get_cur_install_template(args[1], &template_node); + if (template_file) + { + debug("auto install template: <%s> \n", + template_file, template_node->filebuf, template_node->filelen); + + template_size = template_node->filelen; + template_buf = grub_malloc(template_size); + if (template_buf) + { + grub_memcpy(template_buf, template_node->filebuf, template_size); + } + } + else + { + debug("auto install script skipped or not configed %s\n", args[1]); + } + + injection_file = hiperiso_plugin_get_injection(args[1]); + if (injection_file) + { + debug("injection archive: <%s>\n", injection_file); + tmpfile = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", args[2], injection_file); + if (tmpfile) + { + debug("injection archive size:%d\n", (int)tmpfile->size); + injection_size = tmpfile->size; + injection_buf = grub_malloc(injection_size); + if (injection_buf) + { + grub_file_read(tmpfile, injection_buf, injection_size); + } + + grub_file_close(tmpfile); + } + else + { + debug("Failed to open injection archive %s%s\n", args[2], injection_file); + } + } + else + { + debug("injection not configed %s\n", args[1]); + } + + dudnode = hiperiso_plugin_find_dud(args[1]); + if (dudnode) + { + debug("dud file: <%d>\n", dudnode->dudnum); + hiperiso_plugin_load_dud(dudnode, args[2]); + for (i = 0; i < dudnode->dudnum; i++) + { + if (dudnode->files[i].size > 0) + { + dud_size += dudnode->files[i].size + sizeof(cpio_newc_header); + } + } + } + else + { + debug("dud not configed %s\n", args[1]); + } + + g_hiperiso_cpio_buf = grub_malloc(file->size + archfile->size + 40960 + template_size + + persistent_size + injection_size + dud_size + img_chunk_size); + if (NULL == g_hiperiso_cpio_buf) + { + grub_file_close(file); + grub_file_close(archfile); + return grub_error(GRUB_ERR_BAD_ARGUMENT, "Can't alloc memory %llu\n", file->size); + } + + grub_file_read(file, g_hiperiso_cpio_buf, file->size); + buf = (grub_uint8_t *)(g_hiperiso_cpio_buf + file->size - 4); + while (*((grub_uint32_t *)buf) != 0x37303730) + { + buf -= 4; + } + + grub_file_read(archfile, buf, archfile->size); + buf += (archfile->size - 4); + while (*((grub_uint32_t *)buf) != 0x37303730) + { + buf -= 4; + } + + /* get initrd head len */ + initrd_head_len = hiperiso_cpio_newc_fill_head(buf, 0, NULL, "initrd000.xx"); + + /* step1: insert image chunk data to cpio */ + headlen = hiperiso_cpio_newc_fill_head(buf, img_chunk_size, g_img_chunk_list.chunk, "hiperiso/hiperiso_image_map"); + buf += headlen + hiperiso_align(img_chunk_size, 4); + + if (template_buf) + { + headlen = hiperiso_cpio_newc_fill_head(buf, template_size, template_buf, "hiperiso/autoinstall"); + buf += headlen + hiperiso_align(template_size, 4); + grub_check_free(template_buf); + } + + if (persistent_size > 0 && persistent_buf) + { + headlen = hiperiso_cpio_newc_fill_head(buf, persistent_size, persistent_buf, "hiperiso/hiperiso_persistent_map"); + buf += headlen + hiperiso_align(persistent_size, 4); + grub_check_free(persistent_buf); + } + + if (injection_size > 0 && injection_buf) + { + headlen = hiperiso_cpio_newc_fill_head(buf, injection_size, injection_buf, "hiperiso/hiperiso_injection"); + buf += headlen + hiperiso_align(injection_size, 4); + + grub_free(injection_buf); + injection_buf = NULL; + } + + if (dud_size > 0) + { + for (i = 0; i < dudnode->dudnum; i++) + { + pos = grub_strrchr(dudnode->dudpath[i].path, '.'); + grub_snprintf(tmpname, sizeof(tmpname), "hiperiso/hiperiso_dud%d%s", i, (pos ? pos : ".iso")); + dud_size = dudnode->files[i].size; + headlen = hiperiso_cpio_newc_fill_head(buf, dud_size, dudnode->files[i].buf, tmpname); + buf += headlen + hiperiso_align(dud_size, 4); + } + } + + /* step2: insert os param to cpio */ + headlen = hiperiso_cpio_newc_fill_head(buf, 0, NULL, "hiperiso/hiperiso_os_param"); + padlen = sizeof(hiperiso_os_param); + g_hiperiso_cpio_size = (grub_uint32_t)(buf - g_hiperiso_cpio_buf) + headlen + padlen + initrd_head_len; + mod = g_hiperiso_cpio_size % 2048; + if (mod) + { + g_hiperiso_cpio_size += 2048 - mod; + padlen += 2048 - mod; + } + + /* update os param data size, the data will be updated before chain boot */ + hiperiso_cpio_newc_fill_int(padlen, ((cpio_newc_header *)buf)->c_filesize, 8); + g_hiperiso_runtime_buf = (grub_uint8_t *)buf + headlen; + + /* step3: fill initrd cpio head, the file size will be updated before chain boot */ + g_hiperiso_initrd_head = (cpio_newc_header *)(g_hiperiso_runtime_buf + padlen); + hiperiso_cpio_newc_fill_head(g_hiperiso_initrd_head, 0, NULL, "initrd000.xx"); + + grub_file_close(file); + grub_file_close(archfile); + + if (grub_strcmp(args[3], "busybox=64") == 0) + { + debug("cpio busybox proc %s\n", args[3]); + hiperiso_cpio_busybox64((cpio_newc_header *)g_hiperiso_cpio_buf, "64h"); + } + else if (grub_strcmp(args[3], "busybox=a64") == 0) + { + debug("cpio busybox proc %s\n", args[3]); + hiperiso_cpio_busybox64((cpio_newc_header *)g_hiperiso_cpio_buf, "a64"); + } + else if (grub_strcmp(args[3], "busybox=m64") == 0) + { + debug("cpio busybox proc %s\n", args[3]); + hiperiso_cpio_busybox64((cpio_newc_header *)g_hiperiso_cpio_buf, "m64"); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int mod; + int bufsize; + int namelen; + int offset; + char *name; + grub_uint8_t *bufend; + cpio_newc_header *head; + grub_file_t file; + const grub_uint8_t trailler[124] = { + 0x30, 0x37, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x54, 0x52, + 0x41, 0x49, 0x4C, 0x45, 0x52, 0x21, 0x21, 0x21, 0x00, 0x00, 0x00, 0x00 + }; + + (void)ctxt; + (void)argc; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", args[0], args[1]); + if (!file) + { + return 1; + } + + grub_memset(g_hiperiso_runtime_buf, 0, sizeof(hiperiso_os_param)); + hiperiso_fill_os_param(file, (hiperiso_os_param *)g_hiperiso_runtime_buf); + + grub_file_close(file); + + grub_memcpy(g_hiperiso_initrd_head, trailler, sizeof(trailler)); + bufend = (grub_uint8_t *)g_hiperiso_initrd_head + sizeof(trailler); + + bufsize = (int)(bufend - g_hiperiso_cpio_buf); + mod = bufsize % 512; + if (mod) + { + grub_memset(bufend, 0, 512 - mod); + bufsize += 512 - mod; + } + + if (argc > 1 && grub_strcmp(args[2], "noinit") == 0) + { + head = (cpio_newc_header *)g_hiperiso_cpio_buf; + name = (char *)(head + 1); + + while (grub_strcmp(name, "TRAILER!!!")) + { + if (grub_strcmp(name, "init") == 0) + { + grub_memcpy(name, "xxxx", 4); + } + else if (grub_strcmp(name, "linuxrc") == 0) + { + grub_memcpy(name, "hisoxrc", 7); + } + else if (grub_strcmp(name, "sbin") == 0) + { + grub_memcpy(name, "hiso", 4); + } + else if (grub_strcmp(name, "sbin/init") == 0) + { + grub_memcpy(name, "hiso/hiso", 9); + } + + namelen = hiperiso_cpio_newc_get_int(head->c_namesize); + offset = sizeof(cpio_newc_header) + namelen; + offset = hiperiso_align(offset, 4); + offset += hiperiso_cpio_newc_get_int(head->c_filesize); + offset = hiperiso_align(offset, 4); + + head = (cpio_newc_header *)((char *)head + offset); + name = (char *)(head + 1); + } + } + + hiperiso_memfile_env_set("hiperiso_cpio", g_hiperiso_cpio_buf, (ulonglong)bufsize); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len = 0; + int hiperiso_compatible = 0; + grub_uint32_t size = 0; + grub_uint64_t isosize = 0; + grub_uint32_t boot_catlog = 0; + grub_uint32_t img_chunk_size = 0; + grub_uint32_t override_count = 0; + grub_uint32_t override_size = 0; + grub_uint32_t virt_chunk_count = 0; + grub_uint32_t virt_chunk_size = 0; + grub_file_t file; + grub_disk_t disk; + const char *pLastChain = NULL; + const char *compatible; + hiperiso_chain_head *chain; + + (void)ctxt; + (void)argc; + + compatible = grub_env_get("hiperiso_compatible"); + if (compatible && compatible[0] == 'Y') + { + hiperiso_compatible = 1; + } + + if ((NULL == g_img_chunk_list.chunk) || (0 == hiperiso_compatible && g_hiperiso_cpio_buf == NULL)) + { + grub_printf("hiperiso not ready\n"); + return 1; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + return 1; + } + + isosize = file->size; + + len = (int)grub_strlen(args[0]); + if (len >= 4 && 0 == grub_strcasecmp(args[0] + len - 4, ".img")) + { + debug("boot catlog %u for img file\n", boot_catlog); + } + else + { + boot_catlog = hiperiso_get_iso_boot_catlog(file); + if (boot_catlog) + { + if (hiperiso_is_efi_os() && (!hiperiso_has_efi_eltorito(file, boot_catlog))) + { + grub_env_set("LoadIsoEfiDriver", "on"); + } + } + else + { + if (hiperiso_is_efi_os()) + { + grub_env_set("LoadIsoEfiDriver", "on"); + } + else + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "File %s is not bootable", args[0]); + } + } + } + + img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + + override_count = hiperiso_linux_get_override_chunk_count(); + virt_chunk_count = hiperiso_linux_get_virt_chunk_count(); + + if (hiperiso_compatible) + { + size = sizeof(hiperiso_chain_head) + img_chunk_size; + } + else + { + override_size = hiperiso_linux_get_override_chunk_size(); + virt_chunk_size = hiperiso_linux_get_virt_chunk_size(); + size = sizeof(hiperiso_chain_head) + img_chunk_size + override_size + virt_chunk_size; + } + + pLastChain = grub_env_get("hiso_chain_mem_addr"); + if (pLastChain) + { + chain = (hiperiso_chain_head *)grub_strtoul(pLastChain, NULL, 16); + if (chain) + { + debug("free last chain memory %p\n", chain); + grub_free(chain); + } + } + + chain = hiperiso_alloc_chain(size); + if (!chain) + { + grub_printf("Failed to alloc chain linux memory size %u\n", size); + grub_file_close(file); + return 1; + } + + hiperiso_memfile_env_set("hiso_chain_mem", chain, (ulonglong)size); + + grub_memset(chain, 0, sizeof(hiperiso_chain_head)); + + /* part 1: os parameter */ + g_hiperiso_chain_type = hiperiso_chain_linux; + hiperiso_fill_os_param(file, &(chain->os_param)); + + /* part 2: chain head */ + disk = file->device->disk; + chain->disk_drive = disk->id; + chain->disk_sector_size = (1 << disk->log_sector_size); + chain->real_img_size_in_bytes = file->size; + chain->virt_img_size_in_bytes = (file->size + 2047) / 2048 * 2048; + chain->boot_catalog = boot_catlog; + + if (!hiperiso_is_efi_os()) + { + grub_file_seek(file, boot_catlog * 2048); + grub_file_read(file, chain->boot_catalog_sector, sizeof(chain->boot_catalog_sector)); + } + + /* part 3: image chunk */ + chain->img_chunk_offset = sizeof(hiperiso_chain_head); + chain->img_chunk_num = g_img_chunk_list.cur_chunk; + grub_memcpy((char *)chain + chain->img_chunk_offset, g_img_chunk_list.chunk, img_chunk_size); + + if (hiperiso_compatible) + { + return 0; + } + + /* part 4: override chunk */ + if (override_count > 0) + { + chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size; + chain->override_chunk_num = override_count; + hiperiso_linux_fill_override_data(isosize, (char *)chain + chain->override_chunk_offset); + } + + /* part 5: virt chunk */ + if (virt_chunk_count > 0) + { + chain->virt_chunk_offset = chain->override_chunk_offset + override_size; + chain->virt_chunk_num = virt_chunk_count; + hiperiso_linux_fill_virt_data(isosize, chain); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static char *hiperiso_systemd_conf_tag(char *buf, const char *tag, int optional) +{ + int taglen = 0; + char *start = NULL; + char *nextline = NULL; + + taglen = grub_strlen(tag); + for (start = buf; start; start = nextline) + { + nextline = hiperiso_get_line(start); + HISO_SKIP_SPACE(start); + + if (grub_strncmp(start, tag, taglen) == 0 && (start[taglen] == ' ' || start[taglen] == '\t')) + { + start += taglen; + HISO_SKIP_SPACE(start); + return start; + } + } + + if (optional == 0) + { + debug("tag<%s> NOT found\n", tag); + } + return NULL; +} + +static int hiperiso_systemd_conf_hook(const char *filename, const struct grub_dirhook_info *info, void *data) +{ + int oldpos = 0; + char *tag = NULL; + char *bkbuf = NULL; + char *filebuf = NULL; + grub_file_t file = NULL; + systemd_menu_ctx *ctx = (systemd_menu_ctx *)data; + + debug("hiperiso_systemd_conf_hook %s\n", filename); + + if (info->dir || NULL == grub_strstr(filename, ".conf")) + { + return 0; + } + + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s/loader/entries/%s", ctx->dev, filename); + if (!file) + { + return 0; + } + + filebuf = grub_zalloc(2 * file->size + 8); + if (!filebuf) + { + goto out; + } + + bkbuf = filebuf + file->size + 4; + grub_file_read(file, bkbuf, file->size); + + oldpos = ctx->pos; + + /* title --> menuentry */ + grub_memcpy(filebuf, bkbuf, file->size); + tag = hiperiso_systemd_conf_tag(filebuf, "title", 0); + hiso_check_goto_out(tag); + hiso_len_ssprintf(ctx->buf, ctx->pos, ctx->len, "menuentry \"%s\" {\n", tag); + + /* linux xxx */ + grub_memcpy(filebuf, bkbuf, file->size); + tag = hiperiso_systemd_conf_tag(filebuf, "linux", 0); + if (!tag) + { + ctx->pos = oldpos; + goto out; + } + hiso_len_ssprintf(ctx->buf, ctx->pos, ctx->len, " echo \"Loading kernel ...\"\n linux %s ", tag); + + /* kernel options */ + grub_memcpy(filebuf, bkbuf, file->size); + tag = hiperiso_systemd_conf_tag(filebuf, "options", 0); + hiso_len_ssprintf(ctx->buf, ctx->pos, ctx->len, "%s \n", tag ? tag : ""); + + + /* initrd xxx xxx xxx */ + hiso_len_ssprintf(ctx->buf, ctx->pos, ctx->len, " echo \"Loading initrd ...\"\n %s ", ctx->initrd_cmd); + grub_memcpy(filebuf, bkbuf, file->size); + tag = hiperiso_systemd_conf_tag(filebuf, "initrd", 1); + while (tag) + { + hiso_len_ssprintf(ctx->buf, ctx->pos, ctx->len, "%s ", tag); + tag = hiperiso_systemd_conf_tag(tag + grub_strlen(tag) + 1, "initrd", 1); + } + + hiso_len_ssprintf(ctx->buf, ctx->pos, ctx->len, "\n boot\n}\n"); + +out: + grub_check_free(filebuf); + grub_file_close(file); + return 0; +} + +grub_err_t hiperiso_cmd_linux_initrd(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int pos = 0; + char *buf = NULL; + + (void)ctxt; + + buf = (char *)grub_malloc(HISO_SIZE_4KB); + if (!buf) + { + return 1; + } + + pos += grub_snprintf(buf + pos, HISO_SIZE_4KB - pos, "initrd mem:%s:size:%s", + grub_env_get("hiperiso_cpio_addr"), grub_env_get("hiperiso_cpio_size")); + + for (i = 0; i < argc; i++) + { + pos += grub_snprintf(buf + pos, HISO_SIZE_4KB - pos, " newc:initrd%03d:%s", i + 1, args[i]); + } + + grub_script_execute_sourcecode(buf); + grub_free(buf); + + return 0; +} + +grub_err_t hiperiso_cmd_linux_systemd_menu(grub_extcmd_context_t ctxt, int argc, char **args) +{ + static char *buf = NULL; + grub_fs_t fs; + char *device_name = NULL; + grub_device_t dev = NULL; + systemd_menu_ctx ctx; + + (void)ctxt; + (void)argc; + + if (!buf) + { + buf = grub_malloc(HISO_LINUX_SYSTEMD_MENU_MAX_BUF); + if (!buf) + { + goto end; + } + } + + device_name = grub_file_get_device_name(args[0]); + if (!device_name) + { + debug("failed to get device name %s\n", args[0]); + goto end; + } + + dev = grub_device_open(device_name); + if (!dev) + { + debug("failed to open device %s\n", device_name); + goto end; + } + + fs = grub_fs_probe(dev); + if (!fs) + { + debug("failed to probe fs %d\n", grub_errno); + goto end; + } + + ctx.dev = args[0]; + ctx.buf = buf; + ctx.initrd_cmd = args[2] ? args[2] : "initrd"; + ctx.pos = 0; + ctx.len = HISO_LINUX_SYSTEMD_MENU_MAX_BUF; + fs->fs_dir(dev, "/loader/entries", hiperiso_systemd_conf_hook, &ctx); + + hiperiso_memfile_env_set(args[1], buf, (ulonglong)(ctx.pos)); + +end: + grub_check_free(device_name); + check_free(dev, grub_device_close); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_limine_path_convert(char *path) +{ + char newpath[256] = {0}; + + if (grub_strncmp(path, "boot://2/", 9) == 0) + { + grub_snprintf(newpath, sizeof(newpath), "(vtimghd,2)/%s", path + 9); + } + else if (grub_strncmp(path, "boot://1/", 9) == 0) + { + grub_snprintf(newpath, sizeof(newpath), "(vtimghd,1)/%s", path + 9); + } + + if (newpath[0]) + { + grub_snprintf(path, 1024, "%s", newpath); + } + + return 0; +} + +grub_err_t hiperiso_cmd_linux_limine_menu(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int pos = 0; + int sub = 0; + int len = HISO_LINUX_SYSTEMD_MENU_MAX_BUF; + char *filebuf = NULL; + char *start = NULL; + char *nextline = NULL; + grub_file_t file = NULL; + char *title = NULL; + char *kernel = NULL; + char *initrd = NULL; + char *param = NULL; + static char *buf = NULL; + + (void)ctxt; + (void)argc; + + if (!buf) + { + buf = grub_malloc(len + 4 * 1024); + if (!buf) + { + goto end; + } + } + + title = buf + len; + kernel = title + 1024; + initrd = kernel + 1024; + param = initrd + 1024; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, args[0]); + if (!file) + { + return 0; + } + + filebuf = grub_zalloc(file->size + 8); + if (!filebuf) + { + goto end; + } + + grub_file_read(file, filebuf, file->size); + grub_file_close(file); + + + title[0] = kernel[0] = initrd[0] = param[0] = 0; + for (start = filebuf; start; start = nextline) + { + nextline = hiperiso_get_line(start); + HISO_SKIP_SPACE(start); + + if (start[0] == ':') + { + if (start[1] == ':') + { + grub_snprintf(title, 1024, "%s", start + 2); + } + else + { + if (sub) + { + hiso_len_ssprintf(buf, pos, len, "}\n"); + sub = 0; + } + + if (nextline && nextline[0] == ':' && nextline[1] == ':') + { + hiso_len_ssprintf(buf, pos, len, "submenu \"[+] %s\" {\n", start + 2); + sub = 1; + title[0] = 0; + } + else + { + grub_snprintf(title, 1024, "%s", start + 1); + } + } + } + else if (grub_strncmp(start, "KERNEL_PATH=", 12) == 0) + { + grub_snprintf(kernel, 1024, "%s", start + 12); + } + else if (grub_strncmp(start, "MODULE_PATH=", 12) == 0) + { + grub_snprintf(initrd, 1024, "%s", start + 12); + } + else if (grub_strncmp(start, "KERNEL_CMDLINE=", 15) == 0) + { + grub_snprintf(param, 1024, "%s", start + 15); + } + + if (title[0] && kernel[0] && initrd[0] && param[0]) + { + hiperiso_limine_path_convert(kernel); + hiperiso_limine_path_convert(initrd); + + hiso_len_ssprintf(buf, pos, len, "menuentry \"%s\" {\n", title); + hiso_len_ssprintf(buf, pos, len, " echo \"Downloading kernel ...\"\n linux %s %s\n", kernel, param); + hiso_len_ssprintf(buf, pos, len, " echo \"Downloading initrd ...\"\n initrd %s\n", initrd); + hiso_len_ssprintf(buf, pos, len, "}\n"); + + title[0] = kernel[0] = initrd[0] = param[0] = 0; + } + } + + if (sub) + { + hiso_len_ssprintf(buf, pos, len, "}\n"); + sub = 0; + } + + hiperiso_memfile_env_set(args[1], buf, (ulonglong)pos); + +end: + grub_check_free(filebuf); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + diff --git a/src/grub2/hiperiso_plugin.c b/src/grub2/hiperiso_plugin.c new file mode 100644 index 0000000..665d745 --- /dev/null +++ b/src/grub2/hiperiso_plugin.c @@ -0,0 +1,3657 @@ +/****************************************************************************** + * hiperiso_plugin.c + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +char g_arch_mode_suffix[64]; +static char g_iso_disk_name[128]; +static hiso_password g_boot_pwd; +static hiso_password g_file_type_pwd[img_type_max]; +static install_template *g_install_template_head = NULL; +static dud *g_dud_head = NULL; +static menu_password *g_pwd_head = NULL; +static persistence_config *g_persistence_head = NULL; +static menu_tip *g_menu_tip_head = NULL; +static menu_alias *g_menu_alias_head = NULL; +static menu_class *g_menu_class_head = NULL; +static custom_boot *g_custom_boot_head = NULL; +static injection_config *g_injection_head = NULL; +static auto_memdisk *g_auto_memdisk_head = NULL; +static image_list *g_image_list_head = NULL; +static conf_replace *g_conf_replace_head = NULL; +static HISO_JSON *g_menu_lang_json = NULL; + +static int g_theme_id = 0; +static int g_theme_res_fit = 0; +static int g_theme_num = 0; +static theme_list *g_theme_head = NULL; +static int g_theme_random = hiso_theme_random_boot_second; +static char g_theme_single_file[256]; +static char g_cur_menu_language[32] = {0}; +static char g_push_menu_language[32] = {0}; + +static int hiperiso_plugin_is_parent(const char *pat, int patlen, const char *isopath) +{ + if (patlen > 1) + { + if (isopath[patlen] == '/' && hiperiso_strncmp(pat, isopath, patlen) == 0 && + grub_strchr(isopath + patlen + 1, '/') == NULL) + { + return 1; + } + } + else + { + if (pat[0] == '/' && grub_strchr(isopath + 1, '/') == NULL) + { + return 1; + } + } + + return 0; +} + +static int hiperiso_plugin_control_check(HISO_JSON *json, const char *isodisk) +{ + int rc = 0; + HISO_JSON *pNode = NULL; + HISO_JSON *pChild = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array type %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType == JSON_TYPE_OBJECT) + { + pChild = pNode->pstChild; + if (pChild->enDataType == JSON_TYPE_STRING) + { + if (grub_strcmp(pChild->pcName, "HISO_DEFAULT_IMAGE") == 0) + { + grub_printf("%s: %s [%s]\n", pChild->pcName, pChild->unData.pcStrVal, + hiperiso_check_file_exist("%s%s", isodisk, pChild->unData.pcStrVal) ? "OK" : "NOT EXIST"); + } + else + { + grub_printf("%s: %s\n", pChild->pcName, pChild->unData.pcStrVal); + } + } + else + { + grub_printf("%s is NOT string type\n", pChild->pcName); + rc = 1; + } + } + else + { + grub_printf("%s is not an object\n", pNode->pcName); + rc = 1; + } + } + + return rc; +} + +static int hiperiso_plugin_control_entry(HISO_JSON *json, const char *isodisk) +{ + HISO_JSON *pNode = NULL; + HISO_JSON *pChild = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType == JSON_TYPE_OBJECT) + { + pChild = pNode->pstChild; + if (pChild->enDataType == JSON_TYPE_STRING && pChild->pcName && pChild->unData.pcStrVal) + { + hiperiso_set_env(pChild->pcName, pChild->unData.pcStrVal); + } + } + } + + return 0; +} + +static int hiperiso_plugin_theme_check(HISO_JSON *json, const char *isodisk) +{ + int exist = 0; + const char *value; + HISO_JSON *node; + + value = hiso_json_get_string_ex(json->pstChild, "file"); + if (value) + { + grub_printf("file: %s\n", value); + if (value[0] == '/') + { + exist = hiperiso_check_file_exist("%s%s", isodisk, value); + } + else + { + exist = hiperiso_check_file_exist("%s/hiperiso/%s", isodisk, value); + } + + if (exist == 0) + { + grub_printf("Theme file %s does NOT exist\n", value); + return 1; + } + } + else + { + node = hiso_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "file"); + if (node) + { + for (node = node->pstChild; node; node = node->pstNext) + { + value = node->unData.pcStrVal; + grub_printf("file: %s\n", value); + if (value[0] == '/') + { + exist = hiperiso_check_file_exist("%s%s", isodisk, value); + } + else + { + exist = hiperiso_check_file_exist("%s/hiperiso/%s", isodisk, value); + } + + if (exist == 0) + { + grub_printf("Theme file %s does NOT exist\n", value); + return 1; + } + } + + value = hiso_json_get_string_ex(json->pstChild, "random"); + if (value) + { + grub_printf("random: %s\n", value); + } + } + } + + value = hiso_json_get_string_ex(json->pstChild, "gfxmode"); + if (value) + { + grub_printf("gfxmode: %s\n", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "display_mode"); + if (value) + { + grub_printf("display_mode: %s\n", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "serial_param"); + if (value) + { + grub_printf("serial_param %s\n", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "hiperiso_left"); + if (value) + { + grub_printf("hiperiso_left: %s\n", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "hiperiso_top"); + if (value) + { + grub_printf("hiperiso_top: %s\n", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "hiperiso_color"); + if (value) + { + grub_printf("hiperiso_color: %s\n", value); + } + + node = hiso_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "fonts"); + if (node) + { + for (node = node->pstChild; node; node = node->pstNext) + { + if (node->enDataType == JSON_TYPE_STRING) + { + if (hiperiso_check_file_exist("%s%s", isodisk, node->unData.pcStrVal)) + { + grub_printf("%s [OK]\n", node->unData.pcStrVal); + } + else + { + grub_printf("%s [NOT EXIST]\n", node->unData.pcStrVal); + } + } + } + } + else + { + grub_printf("fonts NOT found\n"); + } + + return 0; +} + +static int hiperiso_plugin_theme_entry(HISO_JSON *json, const char *isodisk) +{ + const char *value; + char val[64]; + char filepath[256]; + HISO_JSON *node = NULL; + theme_list *tail = NULL; + theme_list *themenode = NULL; + + value = hiso_json_get_string_ex(json->pstChild, "file"); + if (value) + { + if (value[0] == '/') + { + grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, value); + } + else + { + grub_snprintf(filepath, sizeof(filepath), "%s/hiperiso/%s", isodisk, value); + } + + if (hiperiso_check_file_exist(filepath) == 0) + { + debug("Theme file %s does not exist\n", filepath); + return 0; + } + + debug("hiso_theme %s\n", filepath); + hiperiso_env_export("hiso_theme", filepath); + grub_snprintf(g_theme_single_file, sizeof(g_theme_single_file), "%s", filepath); + } + else + { + node = hiso_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "file"); + if (node) + { + for (node = node->pstChild; node; node = node->pstNext) + { + value = node->unData.pcStrVal; + if (value[0] == '/') + { + grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, value); + } + else + { + grub_snprintf(filepath, sizeof(filepath), "%s/hiperiso/%s", isodisk, value); + } + + if (hiperiso_check_file_exist(filepath) == 0) + { + continue; + } + + themenode = grub_zalloc(sizeof(theme_list)); + if (themenode) + { + grub_snprintf(themenode->theme.path, sizeof(themenode->theme.path), "%s", filepath); + if (g_theme_head) + { + tail->next = themenode; + } + else + { + g_theme_head = themenode; + } + tail = themenode; + g_theme_num++; + } + } + + hiperiso_env_export("hiso_theme", "random"); + value = hiso_json_get_string_ex(json->pstChild, "random"); + if (value) + { + if (grub_strcmp(value, "boot_second") == 0) + { + g_theme_random = hiso_theme_random_boot_second; + } + else if (grub_strcmp(value, "boot_day") == 0) + { + g_theme_random = hiso_theme_random_boot_day; + } + else if (grub_strcmp(value, "boot_month") == 0) + { + g_theme_random = hiso_theme_random_boot_month; + } + } + } + } + + grub_snprintf(val, sizeof(val), "%d", g_theme_num); + grub_env_set("HISO_THEME_COUNT", val); + grub_env_export("HISO_THEME_COUNT"); + if (g_theme_num > 0) + { + hiso_json_get_int(json->pstChild, "default_file", &g_theme_id); + if (g_theme_id == 0) + { + hiso_json_get_int(json->pstChild, "resolution_fit", &g_theme_res_fit); + if (g_theme_res_fit != 1) + { + g_theme_res_fit = 0; + } + + grub_snprintf(val, sizeof(val), "%d", g_theme_res_fit); + hiperiso_env_export("hiso_res_fit", val); + } + + if (g_theme_id > g_theme_num || g_theme_id < 0) + { + g_theme_id = 0; + } + } + + value = hiso_json_get_string_ex(json->pstChild, "gfxmode"); + if (value) + { + debug("hiso_gfxmode %s\n", value); + hiperiso_env_export("hiso_gfxmode", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "display_mode"); + if (value) + { + debug("display_mode %s\n", value); + hiperiso_env_export("hiso_display_mode", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "serial_param"); + if (value) + { + debug("serial_param %s\n", value); + hiperiso_env_export("hiso_serial_param", value); + } + + value = hiso_json_get_string_ex(json->pstChild, "hiperiso_left"); + if (value) + { + hiperiso_env_export(hiperiso_left_key, value); + } + + value = hiso_json_get_string_ex(json->pstChild, "hiperiso_top"); + if (value) + { + hiperiso_env_export(hiperiso_top_key, value); + } + + value = hiso_json_get_string_ex(json->pstChild, "hiperiso_color"); + if (value) + { + hiperiso_env_export(hiperiso_color_key, value); + } + + node = hiso_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "fonts"); + if (node) + { + for (node = node->pstChild; node; node = node->pstNext) + { + if (node->enDataType == JSON_TYPE_STRING && + hiperiso_check_file_exist("%s%s", isodisk, node->unData.pcStrVal)) + { + grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, node->unData.pcStrVal); + grub_font_load(filepath); + } + } + } + + return 0; +} + +static int hiperiso_plugin_check_path(const char *path, const char *file) +{ + if (file[0] != '/') + { + grub_printf("%s is NOT begin with '/' \n", file); + return 1; + } + + if (grub_strchr(file, '\\')) + { + grub_printf("%s contains invalid '\\' \n", file); + return 1; + } + + if (grub_strstr(file, "//")) + { + grub_printf("%s contains invalid double slash\n", file); + return 1; + } + + if (grub_strstr(file, "../")) + { + grub_printf("%s contains invalid '../' \n", file); + return 1; + } + + if (!hiperiso_check_file_exist("%s%s", path, file)) + { + grub_printf("%s%s does NOT exist\n", path, file); + return 1; + } + + return 0; +} + +static int hiperiso_plugin_check_fullpath +( + HISO_JSON *json, + const char *isodisk, + const char *key, + int *pathnum +) +{ + int rc = 0; + int ret = 0; + int cnt = 0; + HISO_JSON *node = json; + HISO_JSON *child = NULL; + + while (node) + { + if (0 == grub_strcmp(key, node->pcName)) + { + break; + } + node = node->pstNext; + } + + if (!node) + { + return 1; + } + + if (JSON_TYPE_STRING == node->enDataType) + { + cnt = 1; + ret = hiperiso_plugin_check_path(isodisk, node->unData.pcStrVal); + grub_printf("%s: %s [%s]\n", key, node->unData.pcStrVal, ret ? "FAIL" : "OK"); + } + else if (JSON_TYPE_ARRAY == node->enDataType) + { + for (child = node->pstChild; child; child = child->pstNext) + { + if (JSON_TYPE_STRING != child->enDataType) + { + grub_printf("Non string json type\n"); + } + else + { + rc = hiperiso_plugin_check_path(isodisk, child->unData.pcStrVal); + grub_printf("%s: %s [%s]\n", key, child->unData.pcStrVal, rc ? "FAIL" : "OK"); + ret += rc; + cnt++; + } + } + } + + *pathnum = cnt; + return ret; +} + +static int hiperiso_plugin_parse_fullpath +( + HISO_JSON *json, + const char *isodisk, + const char *key, + file_fullpath **fullpath, + int *pathnum +) +{ + int rc = 1; + int count = 0; + HISO_JSON *node = json; + HISO_JSON *child = NULL; + file_fullpath *path = NULL; + + while (node) + { + if (0 == grub_strcmp(key, node->pcName)) + { + break; + } + node = node->pstNext; + } + + if (!node) + { + return 1; + } + + if (JSON_TYPE_STRING == node->enDataType) + { + debug("%s is string type data\n", node->pcName); + + if ((node->unData.pcStrVal[0] != '/') || (!hiperiso_check_file_exist("%s%s", isodisk, node->unData.pcStrVal))) + { + debug("%s%s file not found\n", isodisk, node->unData.pcStrVal); + return 1; + } + + path = (file_fullpath *)grub_zalloc(sizeof(file_fullpath)); + if (path) + { + grub_snprintf(path->path, sizeof(path->path), "%s", node->unData.pcStrVal); + *fullpath = path; + *pathnum = 1; + rc = 0; + } + } + else if (JSON_TYPE_ARRAY == node->enDataType) + { + for (child = node->pstChild; child; child = child->pstNext) + { + if ((JSON_TYPE_STRING != child->enDataType) || (child->unData.pcStrVal[0] != '/')) + { + debug("Invalid data type:%d\n", child->enDataType); + return 1; + } + 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 (hiperiso_check_file_exist("%s%s", isodisk, child->unData.pcStrVal)) + { + grub_snprintf(path->path, sizeof(path->path), "%s", child->unData.pcStrVal); + path++; + count++; + } + } + + *pathnum = count; + rc = 0; + } + } + + return rc; +} + +static int hiperiso_plugin_auto_install_check(HISO_JSON *json, const char *isodisk) +{ + int pathnum = 0; + int autosel = 0; + int timeout = 0; + char *pos = NULL; + const char *iso = NULL; + HISO_JSON *pNode = NULL; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array type %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType != JSON_TYPE_OBJECT) + { + grub_printf("NOT object type\n"); + } + + if ((iso = hiso_json_get_string_ex(pNode->pstChild, "image")) != NULL) + { + pos = grub_strchr(iso, '*'); + if (pos || 0 == hiperiso_plugin_check_path(isodisk, iso)) + { + grub_printf("image: %s [%s]\n", iso, (pos ? "*" : "OK")); + hiperiso_plugin_check_fullpath(pNode->pstChild, isodisk, "template", &pathnum); + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "autosel", &autosel)) + { + if (autosel >= 0 && autosel <= pathnum) + { + grub_printf("autosel: %d [OK]\n", autosel); + } + else + { + grub_printf("autosel: %d [FAIL]\n", autosel); + } + } + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "timeout", &timeout)) + { + if (timeout >= 0) + { + grub_printf("timeout: %d [OK]\n", timeout); + } + else + { + grub_printf("timeout: %d [FAIL]\n", timeout); + } + } + } + else + { + grub_printf("image: %s [FAIL]\n", iso); + } + } + else if ((iso = hiso_json_get_string_ex(pNode->pstChild, "parent")) != NULL) + { + if (hiperiso_is_dir_exist("%s%s", isodisk, iso)) + { + grub_printf("parent: %s [OK]\n", iso); + hiperiso_plugin_check_fullpath(pNode->pstChild, isodisk, "template", &pathnum); + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "autosel", &autosel)) + { + if (autosel >= 0 && autosel <= pathnum) + { + grub_printf("autosel: %d [OK]\n", autosel); + } + else + { + grub_printf("autosel: %d [FAIL]\n", autosel); + } + } + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "timeout", &timeout)) + { + if (timeout >= 0) + { + grub_printf("timeout: %d [OK]\n", timeout); + } + else + { + grub_printf("timeout: %d [FAIL]\n", timeout); + } + } + } + else + { + grub_printf("parent: %s [FAIL]\n", iso); + } + } + else + { + grub_printf("image not found\n"); + } + } + + return 0; +} + +static int hiperiso_plugin_auto_install_entry(HISO_JSON *json, const char *isodisk) +{ + int type = 0; + int pathnum = 0; + int autosel = 0; + int timeout = 0; + const char *iso = NULL; + HISO_JSON *pNode = NULL; + install_template *node = NULL; + install_template *next = NULL; + file_fullpath *templatepath = NULL; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_install_template_head) + { + for (node = g_install_template_head; node; node = next) + { + next = node->next; + grub_check_free(node->templatepath); + grub_free(node); + } + + g_install_template_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = auto_install_type_file; + iso = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (!iso) + { + type = auto_install_type_parent; + iso = hiso_json_get_string_ex(pNode->pstChild, "parent"); + } + + if (iso && iso[0] == '/') + { + if (0 == hiperiso_plugin_parse_fullpath(pNode->pstChild, isodisk, "template", &templatepath, &pathnum)) + { + node = grub_zalloc(sizeof(install_template)); + if (node) + { + node->type = type; + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso); + node->templatepath = templatepath; + node->templatenum = pathnum; + + node->autosel = -1; + node->timeout = -1; + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "autosel", &autosel)) + { + if (autosel >= 0 && autosel <= pathnum) + { + node->autosel = autosel; + } + } + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "timeout", &timeout)) + { + if (timeout >= 0) + { + node->timeout = timeout; + } + } + + if (g_install_template_head) + { + node->next = g_install_template_head; + } + + g_install_template_head = node; + } + } + } + } + + return 0; +} + +static int hiperiso_plugin_dud_check(HISO_JSON *json, const char *isodisk) +{ + int pathnum = 0; + char *pos = NULL; + const char *iso = NULL; + HISO_JSON *pNode = NULL; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array type %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType != JSON_TYPE_OBJECT) + { + grub_printf("NOT object type\n"); + } + + iso = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (iso) + { + pos = grub_strchr(iso, '*'); + if (pos || 0 == hiperiso_plugin_check_path(isodisk, iso)) + { + grub_printf("image: %s [%s]\n", iso, (pos ? "*" : "OK")); + hiperiso_plugin_check_fullpath(pNode->pstChild, isodisk, "dud", &pathnum); + } + else + { + grub_printf("image: %s [FAIL]\n", iso); + } + } + else + { + grub_printf("image not found\n"); + } + } + + return 0; +} + +static int hiperiso_plugin_dud_entry(HISO_JSON *json, const char *isodisk) +{ + int pathnum = 0; + const char *iso = NULL; + HISO_JSON *pNode = NULL; + dud *node = NULL; + dud *next = NULL; + file_fullpath *dudpath = NULL; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_dud_head) + { + for (node = g_dud_head; node; node = next) + { + next = node->next; + grub_check_free(node->dudpath); + grub_free(node); + } + + g_dud_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + iso = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (iso && iso[0] == '/') + { + if (0 == hiperiso_plugin_parse_fullpath(pNode->pstChild, isodisk, "dud", &dudpath, &pathnum)) + { + node = grub_zalloc(sizeof(dud)); + if (node) + { + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso); + node->dudpath = dudpath; + node->dudnum = pathnum; + node->files = grub_zalloc(sizeof(dudfile) * pathnum); + + if (node->files) + { + if (g_dud_head) + { + node->next = g_dud_head; + } + + g_dud_head = node; + } + else + { + grub_free(node); + } + } + } + } + } + + return 0; +} + +static int hiperiso_plugin_parse_pwdstr(char *pwdstr, hiso_password *pwd) +{ + int i; + int len; + char ch; + char *pos; + char bytes[3]; + hiso_password tmpPwd; + + len = (int)grub_strlen(pwdstr); + if (len > 64) + { + if (NULL == pwd) grub_printf("Password too long %d\n", len); + return 1; + } + + grub_memset(&tmpPwd, 0, sizeof(tmpPwd)); + + if (grub_strncmp(pwdstr, "txt#", 4) == 0) + { + tmpPwd.type = HISO_PASSWORD_TXT; + grub_snprintf(tmpPwd.text, sizeof(tmpPwd.text), "%s", pwdstr + 4); + } + else if (grub_strncmp(pwdstr, "md5#", 4) == 0) + { + if ((len - 4) == 32) + { + for (i = 0; i < 16; i++) + { + 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); + } + else + { + if (NULL == pwd) grub_printf("Invalid md5 hex format %s %d\n", pwdstr, i); + return 1; + } + } + tmpPwd.type = HISO_PASSWORD_MD5; + } + else if ((len - 4) > 32) + { + pos = grub_strchr(pwdstr + 4, '#'); + if (!pos) + { + if (NULL == pwd) grub_printf("Invalid md5 password format %s\n", pwdstr); + return 1; + } + + if (len - 1 - ((long)pos - (long)pwdstr) != 32) + { + 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); + *pos = ch; + + pos++; + for (i = 0; i < 16; i++) + { + 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); + } + else + { + if (NULL == pwd) grub_printf("Invalid md5 hex format %s %d\n", pwdstr, i); + return 1; + } + } + + tmpPwd.type = HISO_PASSWORD_SALT_MD5; + } + else + { + if (NULL == pwd) grub_printf("Invalid md5 password format %s\n", pwdstr); + return 1; + } + } + else + { + if (NULL == pwd) grub_printf("Invalid password format %s\n", pwdstr); + return 1; + } + + if (pwd) + { + grub_memcpy(pwd, &tmpPwd, sizeof(tmpPwd)); + } + + return 0; +} + +static int hiperiso_plugin_get_pwd_type(const char *pwd) +{ + int i; + char pwdtype[64]; + + for (i = 0; pwd && i < (int)ARRAY_SIZE(g_menu_prefix); i++) + { + grub_snprintf(pwdtype, sizeof(pwdtype), "%spwd", g_menu_prefix[i]); + if (grub_strcmp(pwdtype, pwd) == 0) + { + return img_type_start + i; + } + } + + return -1; +} + +static int hiperiso_plugin_pwd_entry(HISO_JSON *json, const char *isodisk) +{ + int type = -1; + const char *iso = NULL; + const char *pwd = NULL; + HISO_JSON *pNode = NULL; + HISO_JSON *pCNode = NULL; + menu_password *node = NULL; + menu_password *tail = NULL; + menu_password *next = NULL; + + (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) + { + hiperiso_plugin_parse_pwdstr(pNode->unData.pcStrVal, &g_boot_pwd); + } + else if ((type = hiperiso_plugin_get_pwd_type(pNode->pcName)) >= 0) + { + hiperiso_plugin_parse_pwdstr(pNode->unData.pcStrVal, g_file_type_pwd + type); + } + 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; + } + + type = hiso_menu_pwd_file; + iso = hiso_json_get_string_ex(pCNode->pstChild, "file"); + if (!iso) + { + type = hiso_menu_pwd_parent; + iso = hiso_json_get_string_ex(pCNode->pstChild, "parent"); + } + + pwd = hiso_json_get_string_ex(pCNode->pstChild, "pwd"); + if (iso && pwd && iso[0] == '/') + { + node = grub_zalloc(sizeof(menu_password)); + if (node) + { + node->type = type; + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso); + + if (hiperiso_plugin_parse_pwdstr((char *)pwd, &(node->password))) + { + grub_free(node); + continue; + } + + if (g_pwd_head) + { + tail->next = node; + } + else + { + g_pwd_head = node; + } + tail = node; + } + } + } + } + } + + return 0; +} + +static int hiperiso_plugin_pwd_check(HISO_JSON *json, const char *isodisk) +{ + int type = -1; + char *pos = NULL; + const char *iso = NULL; + const char *pwd = NULL; + HISO_JSON *pNode = NULL; + HISO_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) + { + if (0 == hiperiso_plugin_parse_pwdstr(pNode->unData.pcStrVal, NULL)) + { + grub_printf("bootpwd:<%s>\n", pNode->unData.pcStrVal); + } + else + { + grub_printf("Invalid bootpwd.\n"); + } + } + else if ((type = hiperiso_plugin_get_pwd_type(pNode->pcName)) >= 0) + { + if (0 == hiperiso_plugin_parse_pwdstr(pNode->unData.pcStrVal, NULL)) + { + grub_printf("%s:<%s>\n", pNode->pcName, pNode->unData.pcStrVal); + } + else + { + grub_printf("Invalid pwd <%s>\n", pNode->unData.pcStrVal); + } + } + else if (pNode->pcName && grub_strcmp("menupwd", pNode->pcName) == 0) + { + grub_printf("\n"); + for (pCNode = pNode->pstChild; pCNode; pCNode = pCNode->pstNext) + { + if (pCNode->enDataType != JSON_TYPE_OBJECT) + { + grub_printf("Not object %d\n", pCNode->enDataType); + continue; + } + + if ((iso = hiso_json_get_string_ex(pCNode->pstChild, "file")) != NULL) + { + pos = grub_strchr(iso, '*'); + if (pos || 0 == hiperiso_plugin_check_path(isodisk, iso)) + { + pwd = hiso_json_get_string_ex(pCNode->pstChild, "pwd"); + + if (0 == hiperiso_plugin_parse_pwdstr((char *)pwd, NULL)) + { + grub_printf("file:<%s> [%s]\n", iso, (pos ? "*" : "OK")); + grub_printf("pwd:<%s>\n\n", pwd); + } + else + { + grub_printf("Invalid password for <%s>\n", iso); + } + } + else + { + grub_printf("<%s%s> not found\n", isodisk, iso); + } + } + else if ((iso = hiso_json_get_string_ex(pCNode->pstChild, "parent")) != NULL) + { + if (hiperiso_is_dir_exist("%s%s", isodisk, iso)) + { + pwd = hiso_json_get_string_ex(pCNode->pstChild, "pwd"); + if (0 == hiperiso_plugin_parse_pwdstr((char *)pwd, NULL)) + { + grub_printf("dir:<%s> [%s]\n", iso, (pos ? "*" : "OK")); + grub_printf("pwd:<%s>\n\n", pwd); + } + else + { + grub_printf("Invalid password for <%s>\n", iso); + } + } + else + { + grub_printf("<%s%s> not found\n", isodisk, iso); + } + } + else + { + grub_printf("No file item found in json.\n"); + } + } + } + } + + return 0; +} + +static int hiperiso_plugin_persistence_check(HISO_JSON *json, const char *isodisk) +{ + int autosel = 0; + int timeout = 0; + int pathnum = 0; + char *pos = NULL; + const char *iso = NULL; + HISO_JSON *pNode = NULL; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array type %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType != JSON_TYPE_OBJECT) + { + grub_printf("NOT object type\n"); + } + + iso = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (iso) + { + pos = grub_strchr(iso, '*'); + if (pos || 0 == hiperiso_plugin_check_path(isodisk, iso)) + { + grub_printf("image: %s [%s]\n", iso, (pos ? "*" : "OK")); + hiperiso_plugin_check_fullpath(pNode->pstChild, isodisk, "backend", &pathnum); + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "autosel", &autosel)) + { + if (autosel >= 0 && autosel <= pathnum) + { + grub_printf("autosel: %d [OK]\n", autosel); + } + else + { + grub_printf("autosel: %d [FAIL]\n", autosel); + } + } + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "timeout", &timeout)) + { + if (timeout >= 0) + { + grub_printf("timeout: %d [OK]\n", timeout); + } + else + { + grub_printf("timeout: %d [FAIL]\n", timeout); + } + } + } + else + { + grub_printf("image: %s [FAIL]\n", iso); + } + } + else + { + grub_printf("image not found\n"); + } + } + + return 0; +} + +static int hiperiso_plugin_persistence_entry(HISO_JSON *json, const char *isodisk) +{ + int autosel = 0; + int timeout = 0; + int pathnum = 0; + const char *iso = NULL; + HISO_JSON *pNode = NULL; + persistence_config *node = NULL; + persistence_config *next = NULL; + file_fullpath *backendpath = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_persistence_head) + { + for (node = g_persistence_head; node; node = next) + { + next = node->next; + grub_check_free(node->backendpath); + grub_free(node); + } + + g_persistence_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + iso = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (iso && iso[0] == '/') + { + if (0 == hiperiso_plugin_parse_fullpath(pNode->pstChild, isodisk, "backend", &backendpath, &pathnum)) + { + node = grub_zalloc(sizeof(persistence_config)); + if (node) + { + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso); + node->backendpath = backendpath; + node->backendnum = pathnum; + + node->autosel = -1; + node->timeout = -1; + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "autosel", &autosel)) + { + if (autosel >= 0 && autosel <= pathnum) + { + node->autosel = autosel; + } + } + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "timeout", &timeout)) + { + if (timeout >= 0) + { + node->timeout = timeout; + } + } + + if (g_persistence_head) + { + node->next = g_persistence_head; + } + + g_persistence_head = node; + } + } + } + } + + return 0; +} + +static int hiperiso_plugin_menualias_check(HISO_JSON *json, const char *isodisk) +{ + int type; + const char *path = NULL; + const char *alias = NULL; + HISO_JSON *pNode = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = hiso_alias_image_file; + path = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (!path) + { + path = hiso_json_get_string_ex(pNode->pstChild, "dir"); + type = hiso_alias_directory; + } + + alias = hiso_json_get_string_ex(pNode->pstChild, "alias"); + if (path && path[0] == '/' && alias) + { + if (hiso_alias_image_file == type) + { + if (grub_strchr(path, '*')) + { + grub_printf("image: <%s> [ * ]\n", path); + } + else if (hiperiso_check_file_exist("%s%s", isodisk, path)) + { + grub_printf("image: <%s> [ OK ]\n", path); + } + else + { + grub_printf("image: <%s> [ NOT EXIST ]\n", path); + } + } + else + { + if (hiperiso_is_dir_exist("%s%s", isodisk, path)) + { + grub_printf("dir: <%s> [ OK ]\n", path); + } + else + { + grub_printf("dir: <%s> [ NOT EXIST ]\n", path); + } + } + + grub_printf("alias: <%s>\n\n", alias); + } + } + + return 0; +} + +static int hiperiso_plugin_menualias_entry(HISO_JSON *json, const char *isodisk) +{ + int type; + const char *path = NULL; + const char *alias = NULL; + HISO_JSON *pNode = NULL; + menu_alias *node = NULL; + menu_alias *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_menu_alias_head) + { + for (node = g_menu_alias_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_menu_alias_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = hiso_alias_image_file; + path = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (!path) + { + path = hiso_json_get_string_ex(pNode->pstChild, "dir"); + type = hiso_alias_directory; + } + + alias = hiso_json_get_string_ex(pNode->pstChild, "alias"); + if (path && path[0] == '/' && alias) + { + node = grub_zalloc(sizeof(menu_alias)); + if (node) + { + node->type = type; + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", path); + grub_snprintf(node->alias, sizeof(node->alias), "%s", alias); + + if (g_menu_alias_head) + { + node->next = g_menu_alias_head; + } + + g_menu_alias_head = node; + } + } + } + + return 0; +} + +static int hiperiso_plugin_menutip_check(HISO_JSON *json, const char *isodisk) +{ + int type; + const char *path = NULL; + const char *tip = NULL; + HISO_JSON *pNode = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_OBJECT) + { + grub_printf("Not object %d\n", json->enDataType); + return 1; + } + + tip = hiso_json_get_string_ex(json->pstChild, "left"); + if (tip) + { + grub_printf("left: <%s>\n", tip); + } + + tip = hiso_json_get_string_ex(json->pstChild, "top"); + if (tip) + { + grub_printf("top: <%s>\n", tip); + } + + tip = hiso_json_get_string_ex(json->pstChild, "color"); + if (tip) + { + grub_printf("color: <%s>\n", tip); + } + + pNode = hiso_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "tips"); + for (pNode = pNode->pstChild; pNode; pNode = pNode->pstNext) + { + type = hiso_tip_image_file; + path = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (!path) + { + path = hiso_json_get_string_ex(pNode->pstChild, "dir"); + type = hiso_tip_directory; + } + + if (path && path[0] == '/') + { + if (hiso_tip_image_file == type) + { + if (grub_strchr(path, '*')) + { + grub_printf("image: <%s> [ * ]\n", path); + } + else if (hiperiso_check_file_exist("%s%s", isodisk, path)) + { + grub_printf("image: <%s> [ OK ]\n", path); + } + else + { + grub_printf("image: <%s> [ NOT EXIST ]\n", path); + } + } + else + { + if (hiperiso_is_dir_exist("%s%s", isodisk, path)) + { + grub_printf("dir: <%s> [ OK ]\n", path); + } + else + { + grub_printf("dir: <%s> [ NOT EXIST ]\n", path); + } + } + + tip = hiso_json_get_string_ex(pNode->pstChild, "tip"); + if (tip) + { + grub_printf("tip: <%s>\n", tip); + } + else + { + tip = hiso_json_get_string_ex(pNode->pstChild, "tip1"); + if (tip) + grub_printf("tip1: <%s>\n", tip); + else + grub_printf("tip1: \n"); + + tip = hiso_json_get_string_ex(pNode->pstChild, "tip2"); + if (tip) + grub_printf("tip2: <%s>\n", tip); + else + grub_printf("tip2: \n"); + } + } + else + { + grub_printf("image: <%s> [ INVALID ]\n", path); + } + } + + return 0; +} + +static int hiperiso_plugin_menutip_entry(HISO_JSON *json, const char *isodisk) +{ + int type; + const char *path = NULL; + const char *tip = NULL; + HISO_JSON *pNode = NULL; + menu_tip *node = NULL; + menu_tip *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_OBJECT) + { + debug("Not object %d\n", json->enDataType); + return 0; + } + + pNode = hiso_json_find_item(json->pstChild, JSON_TYPE_ARRAY, "tips"); + if (pNode == NULL) + { + debug("Not tips found\n"); + return 0; + } + + if (g_menu_tip_head) + { + for (node = g_menu_tip_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_menu_tip_head = NULL; + } + + tip = hiso_json_get_string_ex(json->pstChild, "left"); + if (tip) + { + grub_env_set("HISO_TIP_LEFT", tip); + } + + tip = hiso_json_get_string_ex(json->pstChild, "top"); + if (tip) + { + grub_env_set("HISO_TIP_TOP", tip); + } + + tip = hiso_json_get_string_ex(json->pstChild, "color"); + if (tip) + { + grub_env_set("HISO_TIP_COLOR", tip); + } + + for (pNode = pNode->pstChild; pNode; pNode = pNode->pstNext) + { + type = hiso_tip_image_file; + path = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (!path) + { + path = hiso_json_get_string_ex(pNode->pstChild, "dir"); + type = hiso_tip_directory; + } + + if (path && path[0] == '/') + { + node = grub_zalloc(sizeof(menu_tip)); + if (node) + { + node->type = type; + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", path); + + tip = hiso_json_get_string_ex(pNode->pstChild, "tip"); + if (tip) + { + grub_snprintf(node->tip1, 1000, "%s", tip); + } + else + { + tip = hiso_json_get_string_ex(pNode->pstChild, "tip1"); + if (tip) + grub_snprintf(node->tip1, 1000, "%s", tip); + + tip = hiso_json_get_string_ex(pNode->pstChild, "tip2"); + if (tip) + grub_snprintf(node->tip2, 1000, "%s", tip); + } + + if (g_menu_tip_head) + { + node->next = g_menu_tip_head; + } + + g_menu_tip_head = node; + } + } + } + + return 0; +} + +static int hiperiso_plugin_injection_check(HISO_JSON *json, const char *isodisk) +{ + int type = 0; + const char *path = NULL; + const char *archive = NULL; + HISO_JSON *pNode = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 0; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = injection_type_file; + path = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (!path) + { + type = injection_type_parent; + path = hiso_json_get_string_ex(pNode->pstChild, "parent"); + if (!path) + { + grub_printf("image/parent not found\n"); + continue; + } + } + + archive = hiso_json_get_string_ex(pNode->pstChild, "archive"); + if (!archive) + { + grub_printf("archive not found\n"); + continue; + } + + if (type == injection_type_file) + { + if (grub_strchr(path, '*')) + { + grub_printf("image: <%s> [*]\n", path); + } + else + { + grub_printf("image: <%s> [%s]\n", path, hiperiso_check_file_exist("%s%s", isodisk, path) ? "OK" : "NOT EXIST"); + } + } + else + { + grub_printf("parent: <%s> [%s]\n", path, + hiperiso_is_dir_exist("%s%s", isodisk, path) ? "OK" : "NOT EXIST"); + } + + grub_printf("archive: <%s> [%s]\n\n", archive, hiperiso_check_file_exist("%s%s", isodisk, archive) ? "OK" : "NOT EXIST"); + } + + return 0; +} + +static int hiperiso_plugin_injection_entry(HISO_JSON *json, const char *isodisk) +{ + int type = 0; + const char *path = NULL; + const char *archive = NULL; + HISO_JSON *pNode = NULL; + injection_config *node = NULL; + injection_config *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_injection_head) + { + for (node = g_injection_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_injection_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = injection_type_file; + path = hiso_json_get_string_ex(pNode->pstChild, "image"); + if (!path) + { + type = injection_type_parent; + path = hiso_json_get_string_ex(pNode->pstChild, "parent"); + } + + archive = hiso_json_get_string_ex(pNode->pstChild, "archive"); + if (path && path[0] == '/' && archive && archive[0] == '/') + { + node = grub_zalloc(sizeof(injection_config)); + if (node) + { + node->type = type; + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", path); + grub_snprintf(node->archive, sizeof(node->archive), "%s", archive); + + if (g_injection_head) + { + node->next = g_injection_head; + } + + g_injection_head = node; + } + } + } + + return 0; +} + +static int hiperiso_plugin_menuclass_entry(HISO_JSON *json, const char *isodisk) +{ + int type; + int parent = 0; + const char *key = NULL; + const char *class = NULL; + HISO_JSON *pNode = NULL; + menu_class *tail = NULL; + menu_class *node = NULL; + menu_class *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_menu_class_head) + { + for (node = g_menu_class_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_menu_class_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + parent = 0; + type = hiso_class_image_file; + key = hiso_json_get_string_ex(pNode->pstChild, "key"); + if (!key) + { + key = hiso_json_get_string_ex(pNode->pstChild, "parent"); + if (key) + { + parent = 1; + } + else + { + key = hiso_json_get_string_ex(pNode->pstChild, "dir"); + type = hiso_class_directory; + } + } + + class = hiso_json_get_string_ex(pNode->pstChild, "class"); + if (key && class) + { + node = grub_zalloc(sizeof(menu_class)); + if (node) + { + node->type = type; + node->parent = parent; + node->patlen = grub_snprintf(node->pattern, sizeof(node->pattern), "%s", key); + grub_snprintf(node->class, sizeof(node->class), "%s", class); + + if (g_menu_class_head) + { + tail->next = node; + } + else + { + g_menu_class_head = node; + } + tail = node; + } + } + } + + return 0; +} + +static int hiperiso_plugin_menuclass_check(HISO_JSON *json, const char *isodisk) +{ + const char *name = NULL; + const char *key = NULL; + const char *class = NULL; + HISO_JSON *pNode = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + name = "key"; + key = hiso_json_get_string_ex(pNode->pstChild, "key"); + if (!key) + { + name = "parent"; + key = hiso_json_get_string_ex(pNode->pstChild, "parent"); + if (!key) + { + name = "dir"; + key = hiso_json_get_string_ex(pNode->pstChild, "dir"); + } + } + + class = hiso_json_get_string_ex(pNode->pstChild, "class"); + if (key && class) + { + grub_printf("%s: <%s>\n", name, key); + grub_printf("class: <%s>\n\n", class); + } + } + + return 0; +} + +static int hiperiso_plugin_custom_boot_entry(HISO_JSON *json, const char *isodisk) +{ + int type; + int len; + const char *key = NULL; + const char *cfg = NULL; + HISO_JSON *pNode = NULL; + custom_boot *tail = NULL; + custom_boot *node = NULL; + custom_boot *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_custom_boot_head) + { + for (node = g_custom_boot_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_custom_boot_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = hiso_custom_boot_image_file; + key = hiso_json_get_string_ex(pNode->pstChild, "file"); + if (!key) + { + key = hiso_json_get_string_ex(pNode->pstChild, "dir"); + type = hiso_custom_boot_directory; + } + + cfg = hiso_json_get_string_ex(pNode->pstChild, "vcfg"); + if (key && cfg) + { + node = grub_zalloc(sizeof(custom_boot)); + if (node) + { + node->type = type; + node->pathlen = grub_snprintf(node->path, sizeof(node->path), "%s", key); + len = (int)grub_snprintf(node->cfg, sizeof(node->cfg), "%s", cfg); + + if (len >= 5 && grub_strncmp(node->cfg + len - 5, ".vcfg", 5) == 0) + { + if (g_custom_boot_head) + { + tail->next = node; + } + else + { + g_custom_boot_head = node; + } + tail = node; + } + else + { + grub_free(node); + } + } + } + } + + return 0; +} + +static int hiperiso_plugin_custom_boot_check(HISO_JSON *json, const char *isodisk) +{ + int type; + int len; + const char *key = NULL; + const char *cfg = NULL; + HISO_JSON *pNode = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + type = hiso_custom_boot_image_file; + key = hiso_json_get_string_ex(pNode->pstChild, "file"); + if (!key) + { + key = hiso_json_get_string_ex(pNode->pstChild, "dir"); + type = hiso_custom_boot_directory; + } + + cfg = hiso_json_get_string_ex(pNode->pstChild, "vcfg"); + len = (int)grub_strlen(cfg); + if (key && cfg) + { + if (len < 5 || grub_strncmp(cfg + len - 5, ".vcfg", 5)) + { + grub_printf("<%s> does not have \".vcfg\" suffix\n\n", cfg); + } + else + { + grub_printf("%s: <%s>\n", (type == hiso_custom_boot_directory) ? "dir" : "file", key); + grub_printf("vcfg: <%s>\n\n", cfg); + } + } + } + + return 0; +} + +static int hiperiso_plugin_conf_replace_entry(HISO_JSON *json, const char *isodisk) +{ + int img = 0; + const char *isof = NULL; + const char *orgf = NULL; + const char *newf = NULL; + HISO_JSON *pNode = NULL; + conf_replace *tail = NULL; + conf_replace *node = NULL; + conf_replace *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_conf_replace_head) + { + for (node = g_conf_replace_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_conf_replace_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + isof = hiso_json_get_string_ex(pNode->pstChild, "iso"); + orgf = hiso_json_get_string_ex(pNode->pstChild, "org"); + newf = hiso_json_get_string_ex(pNode->pstChild, "new"); + if (isof && orgf && newf && isof[0] == '/' && orgf[0] == '/' && newf[0] == '/') + { + node = grub_zalloc(sizeof(conf_replace)); + if (node) + { + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "img", &img)) + { + node->img = img; + } + + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", isof); + grub_snprintf(node->orgconf, sizeof(node->orgconf), "%s", orgf); + grub_snprintf(node->newconf, sizeof(node->newconf), "%s", newf); + + if (g_conf_replace_head) + { + tail->next = node; + } + else + { + g_conf_replace_head = node; + } + tail = node; + } + } + } + + return 0; +} + +static int hiperiso_plugin_conf_replace_check(HISO_JSON *json, const char *isodisk) +{ + int img = 0; + const char *isof = NULL; + const char *orgf = NULL; + const char *newf = NULL; + HISO_JSON *pNode = NULL; + grub_file_t file = NULL; + char cmd[256]; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + isof = hiso_json_get_string_ex(pNode->pstChild, "iso"); + orgf = hiso_json_get_string_ex(pNode->pstChild, "org"); + newf = hiso_json_get_string_ex(pNode->pstChild, "new"); + if (isof && orgf && newf && isof[0] == '/' && orgf[0] == '/' && newf[0] == '/') + { + if (hiperiso_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); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "(vtisocheck)/%s", orgf); + if (file) + { + if (grub_strcmp(file->fs->name, "iso9660") == 0) + { + grub_printf("org:<%s> [OK]\n", orgf); + } + else + { + grub_printf("org:<%s> [Exist But NOT ISO9660]\n", orgf); + } + grub_file_close(file); + } + else + { + grub_printf("org:<%s> [NOT Exist]\n", orgf); + } + + grub_script_execute_sourcecode("loopback -d vtisocheck"); + } + else if (grub_strchr(isof, '*')) + { + grub_printf("iso:<%s> [*]\n", isof); + grub_printf("org:<%s>\n", orgf); + } + else + { + grub_printf("iso:<%s> [NOT Exist]\n", isof); + grub_printf("org:<%s>\n", orgf); + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", isodisk, newf); + if (file) + { + if (file->size > hiso_max_replace_file_size) + { + grub_printf("new:<%s> [Too Big %lu] \n", newf, (ulong)file->size); + } + else + { + grub_printf("new1:<%s> [OK]\n", newf); + } + grub_file_close(file); + } + else + { + grub_printf("new:<%s> [NOT Exist]\n", newf); + } + + if (JSON_SUCCESS == hiso_json_get_int(pNode->pstChild, "img", &img)) + { + grub_printf("img:<%d>\n", img); + } + + grub_printf("\n"); + } + } + + return 0; +} + +static int hiperiso_plugin_auto_memdisk_entry(HISO_JSON *json, const char *isodisk) +{ + HISO_JSON *pNode = NULL; + auto_memdisk *node = NULL; + auto_memdisk *next = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_auto_memdisk_head) + { + for (node = g_auto_memdisk_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_auto_memdisk_head = NULL; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType == JSON_TYPE_STRING) + { + node = grub_zalloc(sizeof(auto_memdisk)); + if (node) + { + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", pNode->unData.pcStrVal); + + if (g_auto_memdisk_head) + { + node->next = g_auto_memdisk_head; + } + + g_auto_memdisk_head = node; + } + } + } + + return 0; +} + +static int hiperiso_plugin_auto_memdisk_check(HISO_JSON *json, const char *isodisk) +{ + HISO_JSON *pNode = NULL; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType == JSON_TYPE_STRING) + { + grub_printf("<%s> ", pNode->unData.pcStrVal); + + if (grub_strchr(pNode->unData.pcStrVal, '*')) + { + grub_printf(" [*]\n"); + } + else if (hiperiso_check_file_exist("%s%s", isodisk, pNode->unData.pcStrVal)) + { + grub_printf(" [OK]\n"); + } + else + { + grub_printf(" [NOT EXIST]\n"); + } + } + } + + return 0; +} + +static int hiperiso_plugin_image_list_entry(HISO_JSON *json, const char *isodisk) +{ + HISO_JSON *pNode = NULL; + image_list *node = NULL; + image_list *next = NULL; + image_list *tail = NULL; + + (void)isodisk; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + debug("Not array %d\n", json->enDataType); + return 0; + } + + if (g_image_list_head) + { + for (node = g_image_list_head; node; node = next) + { + next = node->next; + grub_free(node); + } + + g_image_list_head = NULL; + } + + if (grub_strncmp(json->pcName, "image_blacklist", 15) == 0) + { + g_plugin_image_list = HIPERISO_IMG_BLACK_LIST; + } + else + { + g_plugin_image_list = HIPERISO_IMG_WHITE_LIST; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType == JSON_TYPE_STRING) + { + node = grub_zalloc(sizeof(image_list)); + if (node) + { + node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", pNode->unData.pcStrVal); + + if (g_image_list_head) + { + tail->next = node; + } + else + { + g_image_list_head = node; + } + tail = node; + } + } + } + + return 0; +} + +static int hiperiso_plugin_image_list_check(HISO_JSON *json, const char *isodisk) +{ + HISO_JSON *pNode = NULL; + + if (json->enDataType != JSON_TYPE_ARRAY) + { + grub_printf("Not array %d\n", json->enDataType); + return 1; + } + + for (pNode = json->pstChild; pNode; pNode = pNode->pstNext) + { + if (pNode->enDataType == JSON_TYPE_STRING) + { + grub_printf("<%s> ", pNode->unData.pcStrVal); + + if (grub_strchr(pNode->unData.pcStrVal, '*')) + { + grub_printf(" [*]\n"); + } + else if (hiperiso_check_file_exist("%s%s", isodisk, pNode->unData.pcStrVal)) + { + grub_printf(" [OK]\n"); + } + else + { + grub_printf(" [NOT EXIST]\n"); + } + } + } + + return 0; +} + +static plugin_entry g_plugin_entries[] = +{ + { "control", hiperiso_plugin_control_entry, hiperiso_plugin_control_check, 0 }, + { "theme", hiperiso_plugin_theme_entry, hiperiso_plugin_theme_check, 0 }, + { "auto_install", hiperiso_plugin_auto_install_entry, hiperiso_plugin_auto_install_check, 0 }, + { "persistence", hiperiso_plugin_persistence_entry, hiperiso_plugin_persistence_check, 0 }, + { "menu_alias", hiperiso_plugin_menualias_entry, hiperiso_plugin_menualias_check, 0 }, + { "menu_tip", hiperiso_plugin_menutip_entry, hiperiso_plugin_menutip_check, 0 }, + { "menu_class", hiperiso_plugin_menuclass_entry, hiperiso_plugin_menuclass_check, 0 }, + { "injection", hiperiso_plugin_injection_entry, hiperiso_plugin_injection_check, 0 }, + { "auto_memdisk", hiperiso_plugin_auto_memdisk_entry, hiperiso_plugin_auto_memdisk_check, 0 }, + { "image_list", hiperiso_plugin_image_list_entry, hiperiso_plugin_image_list_check, 0 }, + { "image_blacklist", hiperiso_plugin_image_list_entry, hiperiso_plugin_image_list_check, 0 }, + { "conf_replace", hiperiso_plugin_conf_replace_entry, hiperiso_plugin_conf_replace_check, 0 }, + { "dud", hiperiso_plugin_dud_entry, hiperiso_plugin_dud_check, 0 }, + { "password", hiperiso_plugin_pwd_entry, hiperiso_plugin_pwd_check, 0 }, + { "custom_boot", hiperiso_plugin_custom_boot_entry, hiperiso_plugin_custom_boot_check, 0 }, +}; + +static int hiperiso_parse_plugin_config(HISO_JSON *json, const char *isodisk) +{ + int i; + char key[128]; + HISO_JSON *cur = NULL; + + grub_snprintf(g_iso_disk_name, sizeof(g_iso_disk_name), "%s", isodisk); + + for (cur = json; cur; cur = cur->pstNext) + { + for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++) + { + grub_snprintf(key, sizeof(key), "%s_%s", g_plugin_entries[i].key, g_arch_mode_suffix); + if (g_plugin_entries[i].flag == 0 && grub_strcmp(key, cur->pcName) == 0) + { + debug("Plugin entry for %s\n", g_plugin_entries[i].key); + g_plugin_entries[i].entryfunc(cur, isodisk); + g_plugin_entries[i].flag = 1; + break; + } + } + } + + + for (cur = json; cur; cur = cur->pstNext) + { + for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++) + { + if (g_plugin_entries[i].flag == 0 && grub_strcmp(g_plugin_entries[i].key, cur->pcName) == 0) + { + debug("Plugin entry for %s\n", g_plugin_entries[i].key); + g_plugin_entries[i].entryfunc(cur, isodisk); + g_plugin_entries[i].flag = 1; + break; + } + } + } + + return 0; +} + +grub_err_t hiperiso_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 0; + int offset = 0; + char *buf = NULL; + grub_uint8_t *code = NULL; + grub_file_t file; + HISO_JSON *json = NULL; + + (void)ctxt; + (void)argc; + + grub_env_set("HISO_TIP_LEFT", "10%"); + grub_env_set("HISO_TIP_TOP", "80%+5"); + grub_env_set("HISO_TIP_COLOR", "blue"); + grub_env_set("HISO_TIP_ALIGN", "left"); + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/hiperiso/hiperiso.json", args[0]); + if (!file) + { + return GRUB_ERR_NONE; + } + + debug("json configuration file size %d\n", (int)file->size); + + buf = grub_malloc(file->size + 1); + if (!buf) + { + grub_file_close(file); + return 1; + } + + buf[file->size] = 0; + grub_file_read(file, buf, file->size); + grub_file_close(file); + + json = hiso_json_create(); + if (!json) + { + return 1; + } + + code = (grub_uint8_t *)buf; + if (code[0] == 0xef && code[1] == 0xbb && code[2] == 0xbf) + { + offset = 3; /* Skip UTF-8 BOM */ + } + else if ((code[0] == 0xff && code[1] == 0xfe) || (code[0] == 0xfe && code[1] == 0xff)) + { + grub_env_set("HISO_PLUGIN_SYNTAX_ERROR", "1"); + grub_env_export("HISO_PLUGIN_SYNTAX_ERROR"); + + grub_env_set("HISO_PLUGIN_ENCODE_ERROR", "1"); + grub_env_export("HISO_PLUGIN_ENCODE_ERROR"); + + debug("Failed to parse json string %d\n", ret); + grub_free(buf); + return 1; + } + + ret = hiso_json_parse(json, buf + offset); + if (ret) + { + grub_env_set("HISO_PLUGIN_SYNTAX_ERROR", "1"); + grub_env_export("HISO_PLUGIN_SYNTAX_ERROR"); + + debug("Failed to parse json string %d\n", ret); + grub_free(buf); + return 1; + } + + hiperiso_parse_plugin_config(json->pstChild, args[0]); + + hiso_json_destroy(json); + + grub_free(buf); + + if (g_boot_pwd.type) + { + grub_printf("\n\n======= %s ======\n\n", grub_env_get("HISO_TEXT_MENU_VER")); + if (hiperiso_check_password(&g_boot_pwd, 3)) + { + grub_printf("\n!!! Password check failed, will exit after 5 seconds. !!!\n"); + grub_refresh(); + grub_sleep(5); + grub_exit(); + } + } + + if (g_menu_tip_head) + { + grub_env_set("HISO_MENU_TIP_ENABLE", "1"); + } + else + { + grub_env_unset("HISO_MENU_TIP_ENABLE"); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +void hiperiso_plugin_dump_injection(void) +{ + injection_config *node = NULL; + + for (node = g_injection_head; node; node = node->next) + { + grub_printf("\n%s:<%s>\n", (node->type == injection_type_file) ? "IMAGE" : "PARENT", node->isopath); + grub_printf("ARCHIVE:<%s>\n", node->archive); + } + + return; +} + + +void hiperiso_plugin_dump_auto_install(void) +{ + int i; + install_template *node = NULL; + + for (node = g_install_template_head; node; node = node->next) + { + 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); + } + } + + return; +} + +void hiperiso_plugin_dump_persistence(void) +{ + int rc; + int i = 0; + persistence_config *node = NULL; + hiperiso_img_chunk_list chunk_list; + + for (node = g_persistence_head; node; node = node->next) + { + grub_printf("\nIMAGE:<%s> <%d>\n", node->isopath, node->backendnum); + + for (i = 0; i < node->backendnum; i++) + { + grub_printf("PERSIST %d:<%s>", i, node->backendpath[i].path); + rc = hiperiso_plugin_get_persistent_chunklist(node->isopath, i, &chunk_list); + if (rc == 0) + { + grub_printf(" [ SUCCESS ]\n"); + grub_free(chunk_list.chunk); + } + else + { + grub_printf(" [ FAILED ]\n"); + } + } + } + + return; +} + +install_template * hiperiso_plugin_find_install_template(const char *isopath) +{ + int len; + install_template *node = NULL; + + if (!g_install_template_head) + { + return NULL; + } + + len = (int)grub_strlen(isopath); + for (node = g_install_template_head; node; node = node->next) + { + if (node->type == auto_install_type_file) + { + if (node->pathlen == len && hiperiso_strcmp(node->isopath, isopath) == 0) + { + return node; + } + } + } + + for (node = g_install_template_head; node; node = node->next) + { + if (node->type == auto_install_type_parent) + { + if (node->pathlen < len && hiperiso_plugin_is_parent(node->isopath, node->pathlen, isopath)) + { + return node; + } + } + } + + return NULL; +} + +char * hiperiso_plugin_get_cur_install_template(const char *isopath, install_template **cur) +{ + install_template *node = NULL; + + if (cur) + { + *cur = NULL; + } + + node = hiperiso_plugin_find_install_template(isopath); + if ((!node) || (!node->templatepath)) + { + return NULL; + } + + if (node->cursel < 0 || node->cursel >= node->templatenum) + { + return NULL; + } + + if (cur) + { + *cur = node; + } + + return node->templatepath[node->cursel].path; +} + +persistence_config * hiperiso_plugin_find_persistent(const char *isopath) +{ + int len; + persistence_config *node = NULL; + + if (!g_persistence_head) + { + return NULL; + } + + len = (int)grub_strlen(isopath); + for (node = g_persistence_head; node; node = node->next) + { + if ((len == node->pathlen) && (hiperiso_strcmp(node->isopath, isopath) == 0)) + { + return node; + } + } + + return NULL; +} + +int hiperiso_plugin_get_persistent_chunklist(const char *isopath, int index, hiperiso_img_chunk_list *chunk_list) +{ + int rc = 1; + int len = 0; + char *path = NULL; + grub_uint64_t start = 0; + grub_file_t file = NULL; + persistence_config *node = NULL; + + node = hiperiso_plugin_find_persistent(isopath); + if ((!node) || (!node->backendpath)) + { + return 1; + } + + if (index < 0) + { + index = node->cursel; + } + + if (index < 0 || index >= node->backendnum) + { + return 1; + } + + path = node->backendpath[index].path; + + if (node->backendpath[index].vlnk_add == 0) + { + len = grub_strlen(path); + if (len > 9 && grub_strncmp(path + len - 9, ".vlnk.dat", 9) == 0) + { + hiperiso_add_vlnk_file(NULL, path); + node->backendpath[index].vlnk_add = 1; + } + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", g_iso_disk_name, path); + if (!file) + { + debug("Failed to open file %s%s\n", g_iso_disk_name, path); + goto end; + } + + grub_memset(chunk_list, 0, sizeof(hiperiso_img_chunk_list)); + chunk_list->chunk = grub_malloc(sizeof(hiperiso_img_chunk) * DEFAULT_CHUNK_NUM); + if (NULL == chunk_list->chunk) + { + goto end; + } + + chunk_list->max_chunk = DEFAULT_CHUNK_NUM; + chunk_list->cur_chunk = 0; + + start = file->device->disk->partition->start; + hiperiso_get_block_list(file, chunk_list, start); + + if (0 != hiperiso_check_block_list(file, chunk_list, start, NULL, 0)) + { + grub_free(chunk_list->chunk); + chunk_list->chunk = NULL; + goto end; + } + + rc = 0; + +end: + if (file) + grub_file_close(file); + + return rc; +} + +const char * hiperiso_plugin_get_injection(const char *isopath) +{ + int len; + injection_config *node = NULL; + + if (!g_injection_head) + { + return NULL; + } + + len = (int)grub_strlen(isopath); + for (node = g_injection_head; node; node = node->next) + { + if (node->type == injection_type_file) + { + if (node->pathlen == len && hiperiso_strcmp(node->isopath, isopath) == 0) + { + return node->archive; + } + } + } + + for (node = g_injection_head; node; node = node->next) + { + if (node->type == injection_type_parent) + { + if (node->pathlen < len && hiperiso_plugin_is_parent(node->isopath, node->pathlen, isopath)) + { + return node->archive; + } + } + } + + return NULL; +} + +const char * hiperiso_plugin_get_menu_alias(int type, const char *isopath) +{ + int len; + menu_alias *node = NULL; + + if (!g_menu_alias_head) + { + return NULL; + } + + len = (int)grub_strlen(isopath); + for (node = g_menu_alias_head; node; node = node->next) + { + if (node->type == type && node->pathlen && + node->pathlen == len && hiperiso_strcmp(node->isopath, isopath) == 0) + { + return node->alias; + } + } + + return NULL; +} + +const menu_tip * hiperiso_plugin_get_menu_tip(int type, const char *isopath) +{ + int len; + menu_tip *node = NULL; + + if (!g_menu_tip_head) + { + return NULL; + } + + len = (int)grub_strlen(isopath); + for (node = g_menu_tip_head; node; node = node->next) + { + if (node->type == type && node->pathlen && + node->pathlen == len && hiperiso_strcmp(node->isopath, isopath) == 0) + { + return node; + } + } + + return NULL; +} + +const char * hiperiso_plugin_get_menu_class(int type, const char *name, const char *path) +{ + int namelen; + int pathlen; + menu_class *node = NULL; + + if (!g_menu_class_head) + { + return NULL; + } + + namelen = (int)grub_strlen(name); + pathlen = (int)grub_strlen(path); + + if (hiso_class_image_file == type) + { + for (node = g_menu_class_head; node; node = node->next) + { + if (node->type != type) + { + continue; + } + + if (node->parent == 0) + { + if ((node->patlen < namelen) && grub_strstr(name, node->pattern)) + { + return node->class; + } + } + } + + for (node = g_menu_class_head; node; node = node->next) + { + if (node->type != type) + { + continue; + } + + if (node->parent) + { + if ((node->patlen < pathlen) && hiperiso_plugin_is_parent(node->pattern, node->patlen, path)) + { + return node->class; + } + } + } + } + else + { + for (node = g_menu_class_head; node; node = node->next) + { + if (node->type == type && node->patlen == namelen && grub_strncmp(name, node->pattern, namelen) == 0) + { + return node->class; + } + } + } + + return NULL; +} + +int hiperiso_plugin_add_custom_boot(const char *vcfgpath) +{ + int len; + custom_boot *node = NULL; + + node = grub_zalloc(sizeof(custom_boot)); + if (node) + { + node->type = hiso_custom_boot_image_file; + node->pathlen = grub_snprintf(node->path, sizeof(node->path), "%s", vcfgpath); + grub_snprintf(node->cfg, sizeof(node->cfg), "%s", vcfgpath); + + /* .vcfg */ + len = node->pathlen - 5; + node->path[len] = 0; + node->pathlen = len; + + if (g_custom_boot_head) + { + node->next = g_custom_boot_head; + } + g_custom_boot_head = node; + } + + return 0; +} + +const char * hiperiso_plugin_get_custom_boot(const char *isopath) +{ + int i; + int len; + custom_boot *node = NULL; + + if (!g_custom_boot_head) + { + return NULL; + } + + len = (int)grub_strlen(isopath); + + for (node = g_custom_boot_head; node; node = node->next) + { + if (node->type == hiso_custom_boot_image_file) + { + if (node->pathlen == len && grub_strncmp(isopath, node->path, len) == 0) + { + return node->cfg; + } + } + else + { + if (node->pathlen < len && isopath[node->pathlen] == '/' && + grub_strncmp(isopath, node->path, node->pathlen) == 0) + { + for (i = node->pathlen + 1; i < len; i++) + { + if (isopath[i] == '/') + { + break; + } + } + + if (i >= len) + { + return node->cfg; + } + } + } + } + + return NULL; +} + +grub_err_t hiperiso_cmd_dump_custom_boot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + custom_boot *node = NULL; + + (void)argc; + (void)ctxt; + (void)args; + + for (node = g_custom_boot_head; node; node = node->next) + { + grub_printf("[%s] <%s>:<%s>\n", (node->type == hiso_custom_boot_directory) ? "dir" : "file", + node->path, node->cfg); + } + + return 0; +} + +int hiperiso_plugin_check_memdisk(const char *isopath) +{ + int len; + auto_memdisk *node = NULL; + + if (!g_auto_memdisk_head) + { + return 0; + } + + len = (int)grub_strlen(isopath); + for (node = g_auto_memdisk_head; node; node = node->next) + { + if (node->pathlen == len && hiperiso_strncmp(node->isopath, isopath, len) == 0) + { + return 1; + } + } + + return 0; +} + +int hiperiso_plugin_get_image_list_index(int type, const char *name) +{ + int len; + int index = 1; + image_list *node = NULL; + + if (!g_image_list_head) + { + return 0; + } + + len = (int)grub_strlen(name); + + for (node = g_image_list_head; node; node = node->next, index++) + { + if (hiso_class_directory == type) + { + if (len < node->pathlen && hiperiso_strncmp(node->isopath, name, len) == 0) + { + return index; + } + } + else + { + if (len == node->pathlen && hiperiso_strncmp(node->isopath, name, len) == 0) + { + return index; + } + } + } + + return 0; +} + +int hiperiso_plugin_find_conf_replace(const char *iso, conf_replace *nodes[HISO_MAX_CONF_REPLACE]) +{ + int n = 0; + int len; + conf_replace *node; + + if (!g_conf_replace_head) + { + return 0; + } + + len = (int)grub_strlen(iso); + + for (node = g_conf_replace_head; node; node = node->next) + { + if (node->pathlen == len && hiperiso_strncmp(node->isopath, iso, len) == 0) + { + nodes[n++] = node; + if (n >= HISO_MAX_CONF_REPLACE) + { + return n; + } + } + } + + return n; +} + +dud * hiperiso_plugin_find_dud(const char *iso) +{ + int len; + dud *node; + + if (!g_dud_head) + { + return NULL; + } + + len = (int)grub_strlen(iso); + for (node = g_dud_head; node; node = node->next) + { + if (node->pathlen == len && hiperiso_strncmp(node->isopath, iso, len) == 0) + { + return node; + } + } + + return NULL; +} + +int hiperiso_plugin_load_dud(dud *node, const char *isopart) +{ + int i; + char *buf; + grub_file_t file; + + for (i = 0; i < node->dudnum; i++) + { + if (node->files[i].size > 0) + { + debug("file %d has been loaded\n", i); + continue; + } + + file = hiperiso_grub_file_open(HIPERISO_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); + node->files[i].size = (int)file->size; + node->files[i].buf = buf; + } + grub_file_close(file); + } + } + + return 0; +} + +static const hiso_password * hiperiso_plugin_get_password(const char *isopath) +{ + int i; + int len; + const char *pos = NULL; + menu_password *node = NULL; + + if (!isopath) + { + return NULL; + } + + if (g_pwd_head) + { + len = (int)grub_strlen(isopath); + for (node = g_pwd_head; node; node = node->next) + { + if (node->type == hiso_menu_pwd_file) + { + if (node->pathlen == len && hiperiso_strncmp(node->isopath, isopath, len) == 0) + { + return &(node->password); + } + } + } + + for (node = g_pwd_head; node; node = node->next) + { + if (node->type == hiso_menu_pwd_parent) + { + if (node->pathlen < len && hiperiso_plugin_is_parent(node->isopath, node->pathlen, isopath)) + { + return &(node->password); + } + } + } + } + + while (*isopath) + { + if (*isopath == '.') + { + pos = isopath; + } + isopath++; + } + + if (pos) + { + for (i = 0; i < (int)ARRAY_SIZE(g_menu_prefix); i++) + { + if (g_file_type_pwd[i].type && 0 == grub_strcasecmp(pos + 1, g_menu_prefix[i])) + { + return g_file_type_pwd + i; + } + } + } + + return NULL; +} + +grub_err_t hiperiso_cmd_check_password(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret; + const hiso_password *pwd = NULL; + + (void)ctxt; + (void)argc; + + pwd = hiperiso_plugin_get_password(args[0]); + if (pwd) + { + if (0 == hiperiso_check_password(pwd, 1)) + { + ret = 1; + } + else + { + ret = 0; + } + } + else + { + ret = 1; + } + + grub_errno = 0; + return ret; +} + +grub_err_t hiperiso_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i = 0; + int ret = 0; + char *buf = NULL; + char key[128]; + grub_file_t file; + HISO_JSON *node = NULL; + HISO_JSON *json = NULL; + + (void)ctxt; + + if (argc != 3) + { + return 0; + } + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s/hiperiso/hiperiso.json", args[0]); + if (!file) + { + grub_printf("Plugin json file /hiperiso/hiperiso.json does NOT exist.\n"); + grub_printf("Attention: directory name and filename are both case-sensitive.\n"); + goto end; + } + + buf = grub_malloc(file->size + 1); + if (!buf) + { + 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); + + json = hiso_json_create(); + if (!json) + { + grub_printf("Failed to create json\n"); + goto end; + } + + ret = hiso_json_parse(json, buf); + if (ret) + { + grub_printf("Syntax error detected in hiperiso.json, please check it.\n"); + goto end; + } + + 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, key) == 0) + { + break; + } + } + + if (!node) + { + for (node = json->pstChild; node; node = node->pstNext) + { + if (grub_strcmp(node->pcName, args[1]) == 0) + { + break; + } + } + + if (!node) + { + grub_printf("%s is NOT found in hiperiso.json\n", args[1]); + goto end; + } + } + + for (i = 0; i < (int)ARRAY_SIZE(g_plugin_entries); i++) + { + if (grub_strcmp(g_plugin_entries[i].key, args[1]) == 0) + { + if (g_plugin_entries[i].checkfunc) + { + ret = g_plugin_entries[i].checkfunc(node, args[2]); + } + break; + } + } + +end: + check_free(file, grub_file_close); + check_free(json, hiso_json_destroy); + grub_check_free(buf); + + return 0; +} + +grub_err_t hiperiso_cmd_select_theme_cfg(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int pos = 0; + int bufsize = 0; + char *name = NULL; + char *buf = NULL; + theme_list *node = NULL; + + (void)argc; + (void)args; + (void)ctxt; + + if (g_theme_single_file[0]) + { + return 0; + } + + if (g_theme_num < 2) + { + return 0; + } + + bufsize = (g_theme_num + 1) * 1024; + buf = grub_malloc(bufsize); + if (!buf) + { + return 0; + } + + for (node = g_theme_head; node; node = node->next) + { + name = grub_strstr(node->theme.path, ")/"); + if (name) + { + name++; + } + else + { + name = node->theme.path; + } + + 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, + "menuentry \"$VTLANG_RETURN_PREVIOUS\" --class=hisoret HISO_RET {\n" + "echo 'Return ...'\n" + "}\n"); + + grub_script_execute_sourcecode(buf); + grub_free(buf); + + return 0; +} + +extern char g_hiperiso_theme_path[256]; + +grub_err_t hiperiso_cmd_set_theme(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint32_t i = 0; + grub_uint32_t mod = 0; + grub_uint32_t theme_num = 0; + theme_list *node = g_theme_head; + struct grub_datetime datetime; + struct grub_video_mode_info info; + char buf[64]; + char **pThemePath = NULL; + + (void)argc; + (void)args; + (void)ctxt; + + if (g_theme_single_file[0]) + { + debug("single theme %s\n", g_theme_single_file); + grub_env_set("theme", g_theme_single_file); + goto end; + } + + 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++) + { + node = node->next; + } + + grub_env_set("theme", node->theme.path); + goto end; + } + + pThemePath = (char **)grub_zalloc(sizeof(char *) * g_theme_num); + if (!pThemePath) + { + goto end; + } + + if (g_theme_res_fit) + { + if (grub_video_get_info(&info) == GRUB_ERR_NONE) + { + debug("get video info success %ux%u\n", info.width, info.height); + grub_snprintf(buf, sizeof(buf), "%ux%u", info.width, info.height); + for (node = g_theme_head; node; node = node->next) + { + if (grub_strstr(node->theme.path, buf)) + { + pThemePath[theme_num++] = node->theme.path; + } + } + } + } + + if (theme_num == 0) + { + for (node = g_theme_head; node; node = node->next) + { + pThemePath[theme_num++] = node->theme.path; + } + } + + if (theme_num == 1) + { + mod = 0; + debug("Only 1 theme match, no need to random.\n"); + } + else + { + grub_memset(&datetime, 0, sizeof(datetime)); + grub_get_datetime(&datetime); + + if (g_theme_random == hiso_theme_random_boot_second) + { + grub_divmod32((grub_uint32_t)datetime.second, theme_num, &mod); + } + else if (g_theme_random == hiso_theme_random_boot_day) + { + grub_divmod32((grub_uint32_t)datetime.day, theme_num, &mod); + } + else if (g_theme_random == hiso_theme_random_boot_month) + { + grub_divmod32((grub_uint32_t)datetime.month, theme_num, &mod); + } + + debug("%04d/%02d/%02d %02d:%02d:%02d theme_num:%d mod:%d\n", + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, + theme_num, mod); + } + + if (argc > 0 && grub_strcmp(args[0], "switch") == 0) + { + grub_snprintf(g_hiperiso_theme_path, sizeof(g_hiperiso_theme_path), "%s", pThemePath[mod]); + } + else + { + debug("random theme %s\n", pThemePath[mod]); + grub_env_set("theme", pThemePath[mod]); + } + g_hiperiso_menu_refresh = 1; + +end: + + grub_check_free(pThemePath); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_set_theme_path(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)argc; + (void)ctxt; + + if (argc == 0) + { + g_hiperiso_theme_path[0] = 0; + } + else + { + grub_snprintf(g_hiperiso_theme_path, sizeof(g_hiperiso_theme_path), "%s", args[0]); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +const char *hiperiso_get_vmenu_title(const char *vMenu) +{ + return hiso_json_get_string_ex(g_menu_lang_json->pstChild, vMenu); +} + +int hiperiso_plugin_load_menu_lang(int init, const char *lang) +{ + int ret = 1; + grub_file_t file = NULL; + char *buf = NULL; + + if (grub_strcmp(lang, g_cur_menu_language) == 0) + { + debug("Same menu lang %s\n", lang); + return 0; + } + grub_snprintf(g_cur_menu_language, sizeof(g_cur_menu_language), "%s", lang); + + debug("Load menu lang %s\n", g_cur_menu_language); + + if (g_menu_lang_json) + { + hiso_json_destroy(g_menu_lang_json); + g_menu_lang_json = NULL; + } + + g_menu_lang_json = hiso_json_create(); + if (!g_menu_lang_json) + { + goto end; + } + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "(vt_menu_tarfs)/menu/%s.json", lang); + if (!file) + { + goto end; + } + + buf = grub_malloc(file->size + 1); + if (!buf) + { + 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); + + hiso_json_parse(g_menu_lang_json, buf); + + if (g_default_menu_mode == 0) + { + grub_snprintf(g_hiperiso_hotkey_tip, sizeof(g_hiperiso_hotkey_tip), "%s", hiperiso_get_vmenu_title("VTLANG_STR_HOTKEY_TREE")); + } + else + { + grub_snprintf(g_hiperiso_hotkey_tip, sizeof(g_hiperiso_hotkey_tip), "%s", hiperiso_get_vmenu_title("VTLANG_STR_HOTKEY_LIST")); + } + + if (init == 0) + { + hiperiso_menu_push_key(GRUB_TERM_ESC); + hiperiso_menu_push_key(GRUB_TERM_ESC); + g_hiperiso_menu_refresh = 1; + } + ret = 0; + +end: + + check_free(file, grub_file_close); + grub_check_free(buf); + + return ret; +} + +grub_err_t hiperiso_cmd_cur_menu_lang(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + + if (argc > 0) + { + grub_env_set(args[0], g_cur_menu_language); + } + else + { + grub_printf("%s\n", g_cur_menu_language); + grub_printf("%s\n", g_hiperiso_hotkey_tip); + grub_refresh(); + } + + HIPERISO_CMD_RETURN(0); +} + +grub_err_t hiperiso_cmd_push_menulang(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)argc; + (void)ctxt; + + if (g_push_menu_language[0] == 0) + { + grub_memcpy(g_push_menu_language, g_cur_menu_language, sizeof(g_push_menu_language)); + hiperiso_plugin_load_menu_lang(0, args[0]); + } + + HIPERISO_CMD_RETURN(0); +} + +grub_err_t hiperiso_cmd_pop_menulang(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)argc; + (void)ctxt; + (void)args; + + if (g_push_menu_language[0]) + { + hiperiso_plugin_load_menu_lang(0, g_push_menu_language); + g_push_menu_language[0] = 0; + } + + HIPERISO_CMD_RETURN(0); +} + + diff --git a/src/grub2/hiperiso_unix.c b/src/grub2/hiperiso_unix.c new file mode 100644 index 0000000..e8209be --- /dev/null +++ b/src/grub2/hiperiso_unix.c @@ -0,0 +1,1245 @@ +/****************************************************************************** + * hiperiso_unix.c + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +char g_ko_mod_path[256]; +int g_conf_new_len = 0; +char *g_conf_new_data = NULL; + +int g_mod_new_len = 0; +char *g_mod_new_data = NULL; + +int g_mod_search_magic = 0; +int g_unix_vlnk_boot = 0; + +int g_ko_fillmap_len = 0; +char *g_ko_fillmap_data = NULL; + +grub_uint64_t g_mod_override_offset = 0; +grub_uint64_t g_conf_override_offset = 0; + +static int hiperiso_get_file_override(const char *filename, grub_uint64_t *offset) +{ + grub_file_t file; + + *offset = 0; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "(loop)%s", filename); + if (!file) + { + return 1; + } + + *offset = grub_iso9660_get_last_file_dirent_pos(file) + 2; + + grub_file_close(file); + + return 0; +} + +static grub_uint32_t hiperiso_unix_get_override_chunk_count(void) +{ + grub_uint32_t count = 0; + + if (g_conf_new_len > 0) + { + count++; + } + + if (g_mod_new_len > 0) + { + count++; + } + + if (g_ko_fillmap_len > 0) + { + count += (g_ko_fillmap_len / 512); + if ((g_ko_fillmap_len % 512) > 0) + { + count++; + } + } + + return count; +} + +static grub_uint32_t hiperiso_unix_get_virt_chunk_count(void) +{ + grub_uint32_t count = 0; + + if (g_conf_new_len > 0) + { + count++; + } + + if (g_mod_new_len > 0) + { + count++; + } + + return count; +} +static grub_uint32_t hiperiso_unix_get_virt_chunk_size(void) +{ + grub_uint32_t size; + + size = sizeof(hiperiso_virt_chunk) * hiperiso_unix_get_virt_chunk_count(); + + if (g_conf_new_len > 0) + { + size += hiperiso_align_2k(g_conf_new_len); + } + + if (g_mod_new_len > 0) + { + size += hiperiso_align_2k(g_mod_new_len); + } + + return size; +} + +static void hiperiso_unix_fill_map_data(hiperiso_chain_head *chain, struct g_hiperiso_map *map) +{ + grub_uint32_t i; + hiperiso_img_chunk *chunk = NULL; + + debug("Fill unix map data: <%llu> <%u> %p\n", + (unsigned long long)chain->os_param.hiso_disk_size, g_img_chunk_list.cur_chunk, map); + + map->magic1[0] = map->magic2[0] = HIPERISO_UNIX_SEG_MAGIC0; + map->magic1[1] = map->magic2[1] = HIPERISO_UNIX_SEG_MAGIC1; + map->magic1[2] = map->magic2[2] = HIPERISO_UNIX_SEG_MAGIC2; + map->magic1[3] = map->magic2[3] = HIPERISO_UNIX_SEG_MAGIC3; + + map->disksize = chain->os_param.hiso_disk_size; + grub_memcpy(map->diskuuid, chain->os_param.hiso_disk_guid, 16); + + map->segnum = g_img_chunk_list.cur_chunk; + if (g_img_chunk_list.cur_chunk > HIPERISO_UNIX_MAX_SEGNUM) + { + debug("####[FAIL] Too many segments for the ISO file %u\n", g_img_chunk_list.cur_chunk); + map->segnum = HIPERISO_UNIX_MAX_SEGNUM; + } + + for (i = 0; i < (grub_uint32_t)(map->segnum); i++) + { + chunk = g_img_chunk_list.chunk + i; + map->seglist[i].seg_start_bytes = chunk->disk_start_sector * 512ULL; + map->seglist[i].seg_end_bytes = (chunk->disk_end_sector + 1) * 512ULL; + } +} + +static void hiperiso_unix_fill_override_data( grub_uint64_t isosize, hiperiso_chain_head *chain) +{ + int i; + int left; + char *data = NULL; + grub_uint64_t offset; + grub_uint64_t sector; + hiperiso_override_chunk *cur; + hiperiso_iso9660_override *dirent; + + sector = (isosize + 2047) / 2048; + + cur = (hiperiso_override_chunk *)((char *)chain + chain->override_chunk_offset); + + if (g_conf_new_len > 0) + { + /* loader.conf */ + cur->img_offset = g_conf_override_offset; + cur->override_size = sizeof(hiperiso_iso9660_override); + dirent = (hiperiso_iso9660_override *)cur->override_data; + dirent->first_sector = (grub_uint32_t)sector; + dirent->size = (grub_uint32_t)g_conf_new_len; + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size_be = grub_swap_bytes32(dirent->size); + sector += (dirent->size + 2047) / 2048; + cur++; + } + + if (g_mod_new_len > 0) + { + /* mod.ko */ + cur->img_offset = g_mod_override_offset; + cur->override_size = sizeof(hiperiso_iso9660_override); + dirent = (hiperiso_iso9660_override *)cur->override_data; + dirent->first_sector = (grub_uint32_t)sector; + dirent->size = (grub_uint32_t)g_mod_new_len; + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size_be = grub_swap_bytes32(dirent->size); + sector += (dirent->size + 2047) / 2048; + cur++; + } + + if (g_ko_fillmap_len > 0) + { + data = g_ko_fillmap_data; + offset = g_mod_override_offset; + + hiperiso_unix_fill_map_data(chain, (struct g_hiperiso_map *)data); + + for (i = 0; i < g_ko_fillmap_len / 512; i++) + { + cur->img_offset = offset; + cur->override_size = 512; + grub_memcpy(cur->override_data, data, 512); + + offset += 512; + data += 512; + cur++; + } + + left = (g_ko_fillmap_len % 512); + if (left > 0) + { + cur->img_offset = offset; + cur->override_size = left; + grub_memcpy(cur->override_data, data, left); + + offset += left; + cur++; + } + } + + return; +} + +static void hiperiso_unix_fill_virt_data( grub_uint64_t isosize, hiperiso_chain_head *chain) +{ + grub_uint64_t sector; + grub_uint32_t offset; + grub_uint32_t data_secs; + char *override; + hiperiso_virt_chunk *cur; + + override = (char *)chain + chain->virt_chunk_offset; + cur = (hiperiso_virt_chunk *)override; + + sector = (isosize + 2047) / 2048; + offset = 2 * sizeof(hiperiso_virt_chunk); + + if (g_conf_new_len > 0) + { + hiperiso_unix_fill_virt(g_conf_new_data, g_conf_new_len); + } + + if (g_mod_new_len > 0) + { + if (g_mod_search_magic > 0) + { + hiperiso_unix_fill_map_data(chain, (struct g_hiperiso_map *)(g_mod_new_data + g_mod_search_magic)); + } + + hiperiso_unix_fill_virt(g_mod_new_data, g_mod_new_len); + } + + return; +} + +static int hiperiso_freebsd_append_conf(char *buf, const char *isopath, const char *alias) +{ + int pos = 0; + grub_uint32_t i; + grub_disk_t disk; + grub_file_t isofile; + char uuid[64] = {0}; + const char *val = NULL; + hiperiso_img_chunk *chunk; + grub_uint8_t disk_sig[4]; + grub_uint8_t disk_guid[16]; + + debug("hiperiso_freebsd_append_conf %s\n", isopath); + + isofile = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", isopath); + if (!isofile) + { + return 1; + } + + hiso_ssprintf(buf, pos, "hiperiso_load=\"%s\"\n", "YES"); + hiso_ssprintf(buf, pos, "hiperiso_name=\"%s\"\n", g_ko_mod_path); + + if (alias) + { + hiso_ssprintf(buf, pos, "hint.hiperiso.0.alias=\"%s\"\n", alias); + } + + if (g_unix_vlnk_boot) + { + hiso_ssprintf(buf, pos, "hint.hiperiso.0.vlnk=%d\n", 1); + } + + val = hiperiso_get_env("HISO_UNIX_REMOUNT"); + if (val && val[0] == '1' && val[1] == 0) + { + hiso_ssprintf(buf, pos, "hint.hiperiso.0.remount=%d\n", 1); + } + + if (g_mod_search_magic) + { + debug("hint.hiperiso NO need\n"); + goto out; + } + + debug("Fill hint.hiperiso info\n"); + + disk = isofile->device->disk; + + hiperiso_get_disk_guid(isofile->name, disk_guid, disk_sig); + + for (i = 0; i < 16; i++) + { + grub_snprintf(uuid + i * 2, sizeof(uuid), "%02x", disk_guid[i]); + } + + hiso_ssprintf(buf, pos, "hint.hiperiso.0.disksize=%llu\n", (ulonglong)(disk->total_sectors * (1 << disk->log_sector_size))); + hiso_ssprintf(buf, pos, "hint.hiperiso.0.diskuuid=\"%s\"\n", uuid); + hiso_ssprintf(buf, pos, "hint.hiperiso.0.disksignature=%02x%02x%02x%02x\n", disk_sig[0], disk_sig[1], disk_sig[2], disk_sig[3]); + hiso_ssprintf(buf, pos, "hint.hiperiso.0.segnum=%u\n", g_img_chunk_list.cur_chunk); + + for (i = 0; i < g_img_chunk_list.cur_chunk; i++) + { + chunk = g_img_chunk_list.chunk + i; + hiso_ssprintf(buf, pos, "hint.hiperiso.%u.seg=\"0x%llx@0x%llx\"\n", + i, (ulonglong)(chunk->disk_start_sector * 512), + (ulonglong)((chunk->disk_end_sector + 1) * 512)); + } + +out: + grub_file_close(isofile); + return pos; +} + +static int hiperiso_dragonfly_append_conf(char *buf, const char *isopath) +{ + int pos = 0; + + debug("hiperiso_dragonfly_append_conf %s\n", isopath); + + hiso_ssprintf(buf, pos, "tmpfs_load=\"%s\"\n", "YES"); + hiso_ssprintf(buf, pos, "dm_target_linear_load=\"%s\"\n", "YES"); + hiso_ssprintf(buf, pos, "initrd.img_load=\"%s\"\n", "YES"); + hiso_ssprintf(buf, pos, "initrd.img_type=\"%s\"\n", "md_image"); + hiso_ssprintf(buf, pos, "vfs.root.mountfrom=\"%s\"\n", "ufs:md0s0"); + + return pos; +} + +grub_err_t hiperiso_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args) +{ + (void)ctxt; + (void)argc; + (void)args; + + g_unix_vlnk_boot = 0; + g_mod_search_magic = 0; + g_conf_new_len = 0; + g_mod_new_len = 0; + g_mod_override_offset = 0; + g_conf_override_offset = 0; + g_ko_fillmap_len = 0; + + check_free(g_mod_new_data, grub_free); + check_free(g_conf_new_data, grub_free); + check_free(g_ko_fillmap_data, grub_free); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_check_vlnk(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_file_t file; + + (void)ctxt; + + if (argc != 1) + { + return 1; + } + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (file) + { + g_unix_vlnk_boot = file->vlnk; + grub_file_close(file); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_file_t file; + const char *ver = NULL; + char *buf = NULL; + HISO_JSON *json = NULL; + + (void)ctxt; + (void)argc; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + debug("Failed to open file %s\n", args[0]); + return 1; + } + + buf = grub_malloc(file->size + 2); + if (!buf) + { + grub_file_close(file); + return 0; + } + grub_file_read(file, buf, file->size); + buf[file->size] = 0; + + json = hiso_json_create(); + if (!json) + { + goto end; + } + + if (hiso_json_parse(json, buf)) + { + goto end; + } + + ver = hiso_json_get_string_ex(json->pstChild, "Version"); + if (ver) + { + debug("NAS version:<%s>\n", ver); + if (grub_strncmp(ver, "TrueNAS-", 8) == 0) + { + ver += 8; + } + hiperiso_set_env(args[1], ver); + } + else + { + debug("NAS version:<%s>\n", "NOT FOUND"); + grub_env_unset(args[1]); + } + +end: + grub_check_free(buf); + check_free(json, hiso_json_destroy); + grub_file_close(file); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_file_t file; + char *buf; + char *start = NULL; + char *nextline = NULL; + + (void)ctxt; + (void)argc; + (void)args; + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s", args[0]); + if (!file) + { + debug("Failed to open file %s\n", args[0]); + return 1; + } + + buf = grub_zalloc(file->size + 2); + if (!buf) + { + grub_file_close(file); + return 0; + } + grub_file_read(file, buf, file->size); + + for (start = buf; start; start = nextline) + { + if (grub_strncmp(start, "USERLAND_VERSION", 16) == 0) + { + nextline = start; + while (*nextline && *nextline != '\r' && *nextline != '\n') + { + nextline++; + } + + *nextline = 0; + break; + } + nextline = hiperiso_get_line(start); + } + + if (start) + { + debug("freebsd version:<%s>\n", start); + hiperiso_set_env(args[1], start); + } + else + { + debug("freebsd version:<%s>\n", "NOT FOUND"); + grub_env_unset(args[1]); + } + + grub_free(buf); + grub_file_close(file); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_freebsd_ver_elf(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int j; + int k; + grub_elf_t elf = NULL; + grub_off_t offset = 0; + grub_uint32_t len = 0; + char *str = NULL; + char *data = NULL; + void *hdr = NULL; + char ver[64] = {0}; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 3) + { + debug("Invalid argc %d\n", argc); + return 1; + } + + data = grub_zalloc(8192); + if (!data) + { + goto out; + } + + elf = grub_elf_open(args[0], GRUB_FILE_TYPE_LINUX_INITRD); + if (!elf) + { + debug("Failed to open file %s\n", args[0]); + goto out; + } + + if (args[1][0] == '6') + { + Elf64_Ehdr *e = &(elf->ehdr.ehdr64); + Elf64_Shdr *h; + Elf64_Shdr *s; + Elf64_Shdr *t; + Elf64_Half i; + + h = hdr = grub_zalloc(e->e_shnum * e->e_shentsize); + if (!h) + { + goto out; + } + + debug("read section header %u %u %u\n", e->e_shnum, e->e_shentsize, e->e_shstrndx); + grub_file_seek(elf->file, e->e_shoff); + grub_file_read(elf->file, h, e->e_shnum * e->e_shentsize); + + s = (Elf64_Shdr *)((char *)h + e->e_shstrndx * e->e_shentsize); + str = grub_malloc(s->sh_size + 1); + if (!str) + { + goto out; + } + str[s->sh_size] = 0; + + debug("read string table %u %u\n", (grub_uint32_t)s->sh_offset, (grub_uint32_t)s->sh_size); + grub_file_seek(elf->file, s->sh_offset); + grub_file_read(elf->file, str, s->sh_size); + + for (t = h, i = 0; i < e->e_shnum; i++) + { + if (grub_strcmp(str + t->sh_name, ".data") == 0) + { + offset = t->sh_offset; + len = t->sh_size; + debug("find .data section at %u %u\n", (grub_uint32_t)offset, len); + break; + } + t = (Elf64_Shdr *)((char *)t + e->e_shentsize); + } + } + else + { + Elf32_Ehdr *e = &(elf->ehdr.ehdr32); + Elf32_Shdr *h; + Elf32_Shdr *s; + Elf32_Shdr *t; + Elf32_Half i; + + h = hdr = grub_zalloc(e->e_shnum * e->e_shentsize); + if (!h) + { + goto out; + } + + debug("read section header %u %u %u\n", e->e_shnum, e->e_shentsize, e->e_shstrndx); + grub_file_seek(elf->file, e->e_shoff); + grub_file_read(elf->file, h, e->e_shnum * e->e_shentsize); + + s = (Elf32_Shdr *)((char *)h + e->e_shstrndx * e->e_shentsize); + str = grub_malloc(s->sh_size + 1); + if (!str) + { + goto out; + } + str[s->sh_size] = 0; + + debug("read string table %u %u\n", (grub_uint32_t)s->sh_offset, (grub_uint32_t)s->sh_size); + grub_file_seek(elf->file, s->sh_offset); + grub_file_read(elf->file, str, s->sh_size); + + for (t = h, i = 0; i < e->e_shnum; i++) + { + if (grub_strcmp(str + t->sh_name, ".data") == 0) + { + offset = t->sh_offset; + len = t->sh_size; + debug("find .data section at %u %u\n", (grub_uint32_t)offset, len); + break; + } + t = (Elf32_Shdr *)((char *)t + e->e_shentsize); + } + } + + if (offset == 0 || len == 0) + { + debug(".data section not found %s\n", args[0]); + goto out; + } + + grub_file_seek(elf->file, offset + len - 8192); + grub_file_read(elf->file, data, 8192); + + for (j = 0; j < 8192 - 12; j++) + { + if (grub_strncmp(data + j, "@(#)FreeBSD ", 12) == 0) + { + for (k = j + 12; k < 8192; k++) + { + if (0 == grub_isdigit(data[k]) && data[k] != '.') + { + data[k] = 0; + break; + } + } + + grub_snprintf(ver, sizeof(ver), "%s", data + j + 12); + break; + } + } + + if (ver[0]) + { + k = (int)grub_strtoul(ver, NULL, 10); + debug("freebsd version:<%s> <%d.x>\n", ver, k); + grub_snprintf(ver, sizeof(ver), "%d.x", k); + hiperiso_set_env(args[2], ver); + } + else + { + debug("freebsd version:<%s>\n", "NOT FOUND"); + } + +out: + grub_check_free(str); + grub_check_free(hdr); + grub_check_free(data); + check_free(elf, grub_elf_close); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_replace_grub_conf(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int len = 0; + grub_uint32_t i; + char *data; + char *pos; + const char *val = NULL; + grub_uint64_t offset; + grub_file_t file; + char extcfg[512]; + const char *confile = NULL; + const char * loader_conf[] = + { + "/boot/grub/grub.cfg", + }; + + (void)ctxt; + + if (argc != 1 && argc != 2) + { + debug("Replace conf invalid argc %d\n", argc); + return 1; + } + + for (i = 0; i < sizeof(loader_conf) / sizeof(loader_conf[0]); i++) + { + if (hiperiso_get_file_override(loader_conf[i], &offset) == 0) + { + confile = loader_conf[i]; + g_conf_override_offset = offset; + break; + } + } + + if (confile == NULL) + { + debug("Can't find grub.cfg file from %u locations\n", i); + return 1; + } + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "(loop)/%s", confile); + if (!file) + { + debug("Failed to open %s \n", confile); + return 1; + } + + debug("old grub2 conf file size:%d\n", (int)file->size); + + data = grub_malloc(HISO_MAX_SCRIPT_BUF); + if (!data) + { + grub_file_close(file); + return 1; + } + + grub_file_read(file, data, file->size); + grub_file_close(file); + + g_conf_new_data = data; + g_conf_new_len = (int)file->size; + + pos = grub_strstr(data, "kfreebsd /boot/kernel/kernel"); + if (pos) + { + pos += grub_strlen("kfreebsd /boot/kernel/kernel"); + if (grub_strncmp(pos, ".gz", 3) == 0) + { + pos += 3; + } + + if (argc == 2) + { + hiso_ssprintf(extcfg, len, ";kfreebsd_module_elf %s; set kFreeBSD.hint.hiperiso.0.alias=\"%s\"", args[0], args[1]); + } + else + { + hiso_ssprintf(extcfg, len, ";kfreebsd_module_elf %s", args[0]); + } + + if (g_unix_vlnk_boot) + { + hiso_ssprintf(extcfg, len, ";set kFreeBSD.hint.hiperiso.0.vlnk=%d", 1); + } + + val = hiperiso_get_env("HISO_UNIX_REMOUNT"); + if (val && val[0] == '1' && val[1] == 0) + { + hiso_ssprintf(extcfg, len, ";set kFreeBSD.hint.hiperiso.0.remount=%d", 1); + } + + grub_memmove(pos + len, pos, (int)(file->size - (pos - data))); + grub_memcpy(pos, extcfg, len); + g_conf_new_len += len; + } + else + { + debug("no kfreebsd found\n"); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint32_t i; + char *data; + grub_uint64_t offset; + grub_file_t file; + const char *confile = NULL; + const char * loader_conf[] = + { + "/boot/loader.conf", + "/boot/defaults/loader.conf", + }; + + (void)ctxt; + + if (argc != 2 && argc != 3) + { + debug("Replace conf invalid argc %d\n", argc); + return 1; + } + + for (i = 0; i < sizeof(loader_conf) / sizeof(loader_conf[0]); i++) + { + if (hiperiso_get_file_override(loader_conf[i], &offset) == 0) + { + confile = loader_conf[i]; + g_conf_override_offset = offset; + break; + } + } + + if (confile == NULL) + { + debug("Can't find loader.conf file from %u locations\n", i); + return 1; + } + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "(loop)/%s", confile); + if (!file) + { + debug("Failed to open %s \n", confile); + return 1; + } + + debug("old conf file <%s> size:%d\n", confile, (int)file->size); + + data = grub_malloc(HISO_MAX_SCRIPT_BUF); + if (!data) + { + grub_file_close(file); + return 1; + } + + grub_file_read(file, data, file->size); + grub_file_close(file); + + g_conf_new_data = data; + g_conf_new_len = (int)file->size; + + if (grub_strcmp(args[0], "FreeBSD") == 0) + { + g_conf_new_len += hiperiso_freebsd_append_conf(data + file->size, args[1], (argc > 2) ? args[2] : NULL); + } + else if (grub_strcmp(args[0], "DragonFly") == 0) + { + g_conf_new_len += hiperiso_dragonfly_append_conf(data + file->size, args[1]); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static int hiperiso_unix_search_magic(char *data, int len) +{ + int i; + grub_uint32_t *magic = NULL; + + for (i = 0; i < len; i += 4096) + { + magic = (grub_uint32_t *)(data + i); + if (magic[0] == HIPERISO_UNIX_SEG_MAGIC0 && magic[1] == HIPERISO_UNIX_SEG_MAGIC1 && + magic[2] == HIPERISO_UNIX_SEG_MAGIC2 && magic[3] == HIPERISO_UNIX_SEG_MAGIC3) + { + debug("unix find search magic at 0x%x loop:%d\n", i, (i >> 12)); + g_mod_search_magic = i; + return 0; + } + } + + debug("unix can not find search magic\n"); + return 1; +} + +grub_err_t hiperiso_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char *data; + grub_uint64_t offset; + grub_file_t file; + + (void)ctxt; + + if (argc != 2) + { + debug("Replace ko invalid argc %d\n", argc); + return 1; + } + + debug("replace ko %s\n", args[0]); + + if (hiperiso_get_file_override(args[0], &offset) == 0) + { + grub_snprintf(g_ko_mod_path, sizeof(g_ko_mod_path), "%s", args[0]); + g_mod_override_offset = offset; + } + else + { + debug("Can't find replace ko file from %s\n", args[0]); + return 1; + } + + file = hiperiso_grub_file_open(GRUB_FILE_TYPE_LINUX_INITRD, "%s", args[1]); + if (!file) + { + debug("Failed to open %s \n", args[1]); + return 1; + } + + debug("new ko file size:%d\n", (int)file->size); + + data = grub_malloc(file->size); + if (!data) + { + debug("Failed to alloc memory for new ko %d\n", (int)file->size); + grub_file_close(file); + return 1; + } + + grub_file_read(file, data, file->size); + grub_file_close(file); + + g_mod_new_data = data; + g_mod_new_len = (int)file->size; + + hiperiso_unix_search_magic(g_mod_new_data, g_mod_new_len); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_ko_fillmap(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + grub_file_t file; + grub_uint32_t magic[4]; + grub_uint32_t len; + + (void)ctxt; + + if (argc != 1) + { + debug("Fillmap ko invalid argc %d\n", argc); + return 1; + } + + debug("Fillmap ko %s\n", args[0]); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "(loop)%s", args[0]); + if (file) + { + grub_file_read(file, magic, 4); /* read for trigger */ + g_mod_override_offset = grub_iso9660_get_last_read_pos(file); + } + else + { + debug("Can't find replace ko file from %s\n", args[0]); + return 1; + } + + for (i = 0; i < (int)(file->size); i += 65536) + { + magic[0] = 0; + grub_file_seek(file, i); + grub_file_read(file, magic, sizeof(magic)); + + if (magic[0] == HIPERISO_UNIX_SEG_MAGIC0 && magic[1] == HIPERISO_UNIX_SEG_MAGIC1 && + magic[2] == HIPERISO_UNIX_SEG_MAGIC2 && magic[3] == HIPERISO_UNIX_SEG_MAGIC3) + { + debug("unix find search magic at 0x%x loop:%d\n", i, (i >> 16)); + g_mod_override_offset += i; + break; + } + } + + len = (grub_uint32_t)OFFSET_OF(struct g_hiperiso_map, seglist) + + (sizeof(struct g_hiperiso_seg) * g_img_chunk_list.cur_chunk); + + g_ko_fillmap_len = (int)len; + g_ko_fillmap_data = grub_malloc(len); + if (!g_ko_fillmap_data) + { + g_ko_fillmap_len = 0; + debug("Failed to malloc fillmap data\n"); + } + + debug("Fillmap ko segnum:%u, override len:%u data:%p\n", g_img_chunk_list.cur_chunk, len, g_ko_fillmap_data); + + grub_file_close(file); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + grub_uint8_t *byte; + grub_uint32_t memsize; + hiperiso_image_desc *desc; + grub_uint8_t flag[32] = { + 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF + }; + + (void)ctxt; + (void)argc; + (void)args; + + debug("hiperiso_cmd_unix_fill_image_desc %p\n", g_mod_new_data); + + if (!g_mod_new_data) + { + goto end; + } + + byte = (grub_uint8_t *)g_mod_new_data; + for (i = 0; i < g_mod_new_len - 32; i += 16) + { + if (byte[i] == 0xFF && byte[i + 1] == 0xEE) + { + if (grub_memcmp(flag, byte + i, 32) == 0) + { + debug("Find position flag at %d(0x%x)\n", i, i); + break; + } + } + } + + if (i >= g_mod_new_len - 32) + { + debug("Failed to find position flag %d\n", i); + goto end; + } + + desc = (hiperiso_image_desc *)(byte + i); + desc->disk_size = g_hiperiso_disk_size; + desc->part1_size = g_hiperiso_disk_part_size[0]; + grub_memcpy(desc->disk_uuid, g_hiperiso_part_info->MBR.BootCode + 0x180, 16); + grub_memcpy(desc->disk_signature, g_hiperiso_part_info->MBR.BootCode + 0x1B8, 4); + + desc->img_chunk_count = g_img_chunk_list.cur_chunk; + memsize = g_img_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + + debug("image chunk count:%u memsize:%u\n", desc->img_chunk_count, memsize); + + if (memsize >= HISO_SIZE_1MB * 8) + { + grub_printf("image chunk count:%u memsize:%u too big\n", desc->img_chunk_count, memsize); + goto end; + } + + grub_memcpy(desc + 1, g_img_chunk_list.chunk, memsize); + +end: + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int newlen; + grub_uint8_t *buf; + + (void)ctxt; + (void)argc; + (void)args; + + debug("hiperiso_cmd_unix_gzip_newko %p\n", g_mod_new_data); + + if (!g_mod_new_data) + { + goto end; + } + + buf = grub_malloc(g_mod_new_len); + if (!buf) + { + goto end; + } + + newlen = hiperiso_gzip_compress(g_mod_new_data, g_mod_new_len, buf, g_mod_new_len); + + grub_free(g_mod_new_data); + + debug("gzip org len:%d newlen:%d\n", g_mod_new_len, newlen); + + g_mod_new_data = (char *)buf; + g_mod_new_len = newlen; + +end: + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int hiperiso_compatible = 0; + grub_uint32_t size = 0; + grub_uint64_t isosize = 0; + grub_uint32_t boot_catlog = 0; + grub_uint32_t img_chunk_size = 0; + grub_uint32_t override_count = 0; + grub_uint32_t override_size = 0; + grub_uint32_t virt_chunk_size = 0; + grub_file_t file; + grub_disk_t disk; + const char *pLastChain = NULL; + const char *compatible; + hiperiso_chain_head *chain; + + (void)ctxt; + (void)argc; + + compatible = grub_env_get("hiperiso_compatible"); + if (compatible && compatible[0] == 'Y') + { + hiperiso_compatible = 1; + } + + if (NULL == g_img_chunk_list.chunk) + { + grub_printf("hiperiso not ready\n"); + return 1; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + return 1; + } + + isosize = file->size; + + boot_catlog = hiperiso_get_iso_boot_catlog(file); + if (boot_catlog) + { + if (hiperiso_is_efi_os() && (!hiperiso_has_efi_eltorito(file, boot_catlog))) + { + grub_env_set("LoadIsoEfiDriver", "on"); + } + } + else + { + if (hiperiso_is_efi_os()) + { + grub_env_set("LoadIsoEfiDriver", "on"); + } + else + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "File %s is not bootable", args[0]); + } + } + + img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + + if (hiperiso_compatible) + { + size = sizeof(hiperiso_chain_head) + img_chunk_size; + } + else + { + override_count = hiperiso_unix_get_override_chunk_count(); + override_size = override_count * sizeof(hiperiso_override_chunk); + + virt_chunk_size = hiperiso_unix_get_virt_chunk_size(); + size = sizeof(hiperiso_chain_head) + img_chunk_size + override_size + virt_chunk_size; + } + + pLastChain = grub_env_get("hiso_chain_mem_addr"); + if (pLastChain) + { + chain = (hiperiso_chain_head *)grub_strtoul(pLastChain, NULL, 16); + if (chain) + { + debug("free last chain memory %p\n", chain); + grub_free(chain); + } + } + + chain = hiperiso_alloc_chain(size); + if (!chain) + { + grub_printf("Failed to alloc chain unix memory size %u\n", size); + grub_file_close(file); + return 1; + } + + hiperiso_memfile_env_set("hiso_chain_mem", chain, (ulonglong)size); + + grub_memset(chain, 0, sizeof(hiperiso_chain_head)); + + /* part 1: os parameter */ + g_hiperiso_chain_type = hiperiso_chain_linux; + hiperiso_fill_os_param(file, &(chain->os_param)); + + /* part 2: chain head */ + disk = file->device->disk; + chain->disk_drive = disk->id; + chain->disk_sector_size = (1 << disk->log_sector_size); + chain->real_img_size_in_bytes = file->size; + chain->virt_img_size_in_bytes = (file->size + 2047) / 2048 * 2048; + chain->boot_catalog = boot_catlog; + + if (!hiperiso_is_efi_os()) + { + grub_file_seek(file, boot_catlog * 2048); + grub_file_read(file, chain->boot_catalog_sector, sizeof(chain->boot_catalog_sector)); + } + + /* part 3: image chunk */ + chain->img_chunk_offset = sizeof(hiperiso_chain_head); + chain->img_chunk_num = g_img_chunk_list.cur_chunk; + grub_memcpy((char *)chain + chain->img_chunk_offset, g_img_chunk_list.chunk, img_chunk_size); + + if (hiperiso_compatible) + { + return 0; + } + + /* part 4: override chunk */ + chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size; + chain->override_chunk_num = override_count; + hiperiso_unix_fill_override_data(isosize, chain); + + /* part 5: virt chunk */ + chain->virt_chunk_offset = chain->override_chunk_offset + override_size; + chain->virt_chunk_num = hiperiso_unix_get_virt_chunk_count(); + hiperiso_unix_fill_virt_data(isosize, chain); + + grub_file_close(file); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + diff --git a/src/grub2/hiperiso_vhd.c b/src/grub2/hiperiso_vhd.c new file mode 100644 index 0000000..15f0d97 --- /dev/null +++ b/src/grub2/hiperiso_vhd.c @@ -0,0 +1,754 @@ +/****************************************************************************** + * hiperiso_vhd.c + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef GRUB_MACHINE_EFI +#include +#endif +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +static int g_vhdboot_isolen = 0; +static char *g_vhdboot_totbuf = NULL; +static char *g_vhdboot_isobuf = NULL; +static grub_uint64_t g_img_trim_head_secnum = 0; + +static int hiperiso_vhd_find_bcd(int *bcdoffset, int *bcdlen, const char *path) +{ + grub_uint32_t offset; + grub_file_t file; + char cmdbuf[128]; + + grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback vhdiso mem:0x%lx:size:%d", (ulong)g_vhdboot_isobuf, g_vhdboot_isolen); + + grub_script_execute_sourcecode(cmdbuf); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "(vhdiso)%s", path); + if (!file) + { + return 1; + } + + grub_file_read(file, &offset, 4); + offset = (grub_uint32_t)grub_iso9660_get_last_read_pos(file); + + *bcdoffset = (int)offset; + *bcdlen = (int)file->size; + + debug("vhdiso bcd file offset:%d len:%d\n", *bcdoffset, *bcdlen); + + grub_file_close(file); + + grub_script_execute_sourcecode("loopback -d vhdiso"); + + return 0; +} + +static int hiperiso_vhd_patch_path(char *vhdpath, hiperiso_patch_vhd *patch1, hiperiso_patch_vhd *patch2, + int bcdoffset, int bcdlen) +{ + int i; + int cnt = 0; + char *pos; + grub_size_t pathlen; + const char *plat; + char *newpath = NULL; + grub_uint16_t *unicode_path; + const grub_uint8_t winloadexe[] = + { + 0x77, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x61, 0x00, 0x64, 0x00, 0x2E, 0x00, + 0x65, 0x00, 0x78, 0x00, 0x65, 0x00 + }; + + while ((*vhdpath) != '/') + { + vhdpath++; + } + + pathlen = sizeof(grub_uint16_t) * (grub_strlen(vhdpath) + 1); + debug("unicode path for <%s> len:%d\n", vhdpath, (int)pathlen); + + unicode_path = grub_zalloc(pathlen); + if (!unicode_path) + { + return 0; + } + + plat = grub_env_get("grub_platform"); + + if (plat && (plat[0] == 'e')) /* UEFI */ + { + pos = g_vhdboot_isobuf + bcdoffset; + + /* winload.exe ==> winload.efi */ + for (i = 0; i + (int)sizeof(winloadexe) < bcdlen; i++) + { + if (*((grub_uint32_t *)(pos + i)) == 0x00690077 && + grub_memcmp(pos + i, winloadexe, sizeof(winloadexe)) == 0) + { + pos[i + sizeof(winloadexe) - 4] = 0x66; + pos[i + sizeof(winloadexe) - 2] = 0x69; + cnt++; + } + } + + debug("winload patch %d times\n", cnt); + } + + newpath = grub_strdup(vhdpath); + for (pos = newpath; *pos; pos++) + { + if (*pos == '/') + { + *pos = '\\'; + } + } + + grub_utf8_to_utf16(unicode_path, pathlen, (grub_uint8_t *)newpath, -1, NULL); + grub_memcpy(patch1->vhd_file_path, unicode_path, pathlen); + grub_memcpy(patch2->vhd_file_path, unicode_path, pathlen); + + grub_free(newpath); + return 0; +} + +static int hiperiso_vhd_read_parttbl(const char *filename, hiperiso_gpt_info *gpt, int *index, grub_uint64_t *poffset) +{ + int i; + int find = 0; + int ret = 1; + grub_uint64_t start; + grub_file_t file = NULL; + grub_disk_t disk = NULL; + grub_uint8_t zeroguid[16] = {0}; + + file = grub_file_open(filename, HIPERISO_FILE_TYPE); + if (!file) + { + goto end; + } + + disk = grub_disk_open(file->device->disk->name); + if (!disk) + { + goto end; + } + + grub_disk_read(disk, 0, 0, sizeof(hiperiso_gpt_info), gpt); + + start = file->device->disk->partition->start; + + if (grub_memcmp(gpt->Head.Signature, "EFI PART", 8) == 0) + { + debug("GPT part start: %llu\n", (ulonglong)start); + for (i = 0; i < 128; i++) + { + if (grub_memcmp(gpt->PartTbl[i].PartGuid, zeroguid, 16)) + { + if (start == gpt->PartTbl[i].StartLBA) + { + *index = i; + find = 1; + break; + } + } + } + } + else + { + debug("MBR part start: %llu\n", (ulonglong)start); + for (i = 0; i < 4; i++) + { + if ((grub_uint32_t)start == gpt->MBR.PartTbl[i].StartSectorId) + { + *index = i; + find = 1; + break; + } + } + } + + if (find == 0) // MBR Logical partition + { + if (file->device->disk->partition->number > 0) + { + *index = file->device->disk->partition->number; + debug("Fall back part number: %d\n", *index); + } + } + + *poffset = start; + ret = 0; + +end: + check_free(file, grub_file_close); + check_free(disk, grub_disk_close); + + return ret; +} + +static int hiperiso_vhd_patch_disk(const char *vhdpath, hiperiso_patch_vhd *patch1, hiperiso_patch_vhd *patch2) +{ + int partIndex = 0; + grub_uint64_t offset = 0; + char efipart[16] = {0}; + hiperiso_gpt_info *gpt = NULL; + + if (vhdpath[0] == '/') + { + gpt = g_hiperiso_part_info; + partIndex = 0; + debug("This is Hiperiso ISO partIndex %d %s\n", partIndex, vhdpath); + } + else + { + gpt = grub_zalloc(sizeof(hiperiso_gpt_info)); + hiperiso_vhd_read_parttbl(vhdpath, gpt, &partIndex, &offset); + debug("This is HDD partIndex %d %s\n", partIndex, vhdpath); + } + + grub_memcpy(efipart, gpt->Head.Signature, sizeof(gpt->Head.Signature)); + + grub_memset(patch1, 0, OFFSET_OF(hiperiso_patch_vhd, vhd_file_path)); + grub_memset(patch2, 0, OFFSET_OF(hiperiso_patch_vhd, vhd_file_path)); + + if (grub_strncmp(efipart, "EFI PART", 8) == 0) + { + hiperiso_debug_dump_guid("GPT disk GUID: ", gpt->Head.DiskGuid); + hiperiso_debug_dump_guid("GPT partIndex GUID: ", gpt->PartTbl[partIndex].PartGuid); + + grub_memcpy(patch1->disk_signature_or_guid, gpt->Head.DiskGuid, 16); + grub_memcpy(patch1->part_offset_or_guid, gpt->PartTbl[partIndex].PartGuid, 16); + grub_memcpy(patch2->disk_signature_or_guid, gpt->Head.DiskGuid, 16); + grub_memcpy(patch2->part_offset_or_guid, gpt->PartTbl[partIndex].PartGuid, 16); + + patch1->part_type = patch2->part_type = 0; + } + else + { + if (offset == 0) + { + offset = gpt->MBR.PartTbl[partIndex].StartSectorId; + } + offset *= 512; + debug("MBR disk signature: %02x%02x%02x%02x Part(%d) offset:%llu\n", + gpt->MBR.BootCode[0x1b8 + 0], gpt->MBR.BootCode[0x1b8 + 1], + gpt->MBR.BootCode[0x1b8 + 2], gpt->MBR.BootCode[0x1b8 + 3], + partIndex + 1, offset); + + grub_memcpy(patch1->part_offset_or_guid, &offset, 8); + grub_memcpy(patch2->part_offset_or_guid, &offset, 8); + + grub_memcpy(patch1->disk_signature_or_guid, gpt->MBR.BootCode + 0x1b8, 4); + grub_memcpy(patch2->disk_signature_or_guid, gpt->MBR.BootCode + 0x1b8, 4); + + patch1->part_type = patch2->part_type = 1; + } + + if (gpt != g_hiperiso_part_info) + { + grub_free(gpt); + } + + return 0; +} + +static int hiperiso_find_vhdpatch_offset(int bcdoffset, int bcdlen, int *offset) +{ + int i; + int cnt = 0; + grub_uint8_t *buf = (grub_uint8_t *)(g_vhdboot_isobuf + bcdoffset); + grub_uint8_t magic[16] = { + 0x5C, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00, 0x58, 0x00 + }; + + for (i = 0; i < bcdlen - 16 && cnt < 2; i++) + { + if (*(grub_uint32_t *)(buf + i) == 0x0058005C) + { + if (grub_memcmp(magic, buf + i, 16) == 0) + { + *offset++ = i - (int)OFFSET_OF(hiperiso_patch_vhd, vhd_file_path); + cnt++; + } + } + } + + return 0; +} + +grub_err_t hiperiso_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc; + int bcdoffset, bcdlen; + int patchoffset[2]; + hiperiso_patch_vhd *patch1; + hiperiso_patch_vhd *patch2; + + (void)ctxt; + (void)argc; + + grub_env_unset("hiso_vhd_buf_addr"); + + debug("patch vhd <%s>\n", args[0]); + + if ((!g_vhdboot_enable) || (!g_vhdboot_totbuf)) + { + debug("vhd boot not ready %d %p\n", g_vhdboot_enable, g_vhdboot_totbuf); + return 0; + } + + rc = hiperiso_vhd_find_bcd(&bcdoffset, &bcdlen, "/boot/bcd"); + if (rc) + { + debug("failed to get bcd location %d\n", rc); + } + else + { + hiperiso_find_vhdpatch_offset(bcdoffset, bcdlen, patchoffset); + patch1 = (hiperiso_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[0]); + patch2 = (hiperiso_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[1]); + + debug("Find /boot/bcd (%d %d) now patch it (offset: 0x%x 0x%x) ...\n", + bcdoffset, bcdlen, patchoffset[0], patchoffset[1]); + hiperiso_vhd_patch_disk(args[0], patch1, patch2); + hiperiso_vhd_patch_path(args[0], patch1, patch2, bcdoffset, bcdlen); + } + + rc = hiperiso_vhd_find_bcd(&bcdoffset, &bcdlen, "/boot/BCD"); + if (rc) + { + debug("No file /boot/BCD \n"); + } + else + { + hiperiso_find_vhdpatch_offset(bcdoffset, bcdlen, patchoffset); + patch1 = (hiperiso_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[0]); + patch2 = (hiperiso_patch_vhd *)(g_vhdboot_isobuf + bcdoffset + patchoffset[1]); + + debug("Find /boot/BCD (%d %d) now patch it (offset: 0x%x 0x%x) ...\n", + bcdoffset, bcdlen, patchoffset[0], patchoffset[1]); + hiperiso_vhd_patch_disk(args[0], patch1, patch2); + hiperiso_vhd_patch_path(args[0], patch1, patch2, bcdoffset, bcdlen); + } + + /* set buffer and size */ +#ifdef GRUB_MACHINE_EFI + hiperiso_memfile_env_set("hiso_vhd_buf", g_vhdboot_totbuf, (ulonglong)(g_vhdboot_isolen + sizeof(hiperiso_chain_head))); +#else + hiperiso_memfile_env_set("hiso_vhd_buf", g_vhdboot_isobuf, (ulonglong)g_vhdboot_isolen); +#endif + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int buflen; + grub_file_t file; + + (void)ctxt; + (void)argc; + + g_vhdboot_enable = 0; + grub_check_free(g_vhdboot_totbuf); + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!file) + { + return 0; + } + + debug("load vhd boot: <%s> <%lu>\n", args[0], (ulong)file->size); + + if (file->size < HISO_SIZE_1KB * 32) + { + grub_file_close(file); + return 0; + } + + g_vhdboot_isolen = (int)file->size; + + buflen = (int)(file->size + sizeof(hiperiso_chain_head)); + +#ifdef GRUB_MACHINE_EFI + g_vhdboot_totbuf = (char *)grub_efi_allocate_iso_buf(buflen); +#else + g_vhdboot_totbuf = (char *)grub_malloc(buflen); +#endif + + if (!g_vhdboot_totbuf) + { + grub_file_close(file); + return 0; + } + + g_vhdboot_isobuf = g_vhdboot_totbuf + sizeof(hiperiso_chain_head); + + grub_file_read(file, g_vhdboot_isobuf, file->size); + grub_file_close(file); + + g_vhdboot_enable = 1; + + return 0; +} + +static int hiperiso_raw_trim_head(grub_uint64_t offset) +{ + grub_uint32_t i; + grub_uint32_t memsize; + grub_uint32_t imgstart = 0; + grub_uint32_t imgsecs = 0; + grub_uint64_t sectors = 0; + grub_uint64_t cursecs = 0; + grub_uint64_t delta = 0; + + if ((!g_img_chunk_list.chunk) || (!offset)) + { + debug("image chunk not ready %p %lu\n", g_img_chunk_list.chunk, (ulong)offset); + return 0; + } + + debug("image trim head %lu\n", (ulong)offset); + + for (i = 0; i < g_img_chunk_list.cur_chunk; i++) + { + cursecs = g_img_chunk_list.chunk[i].disk_end_sector + 1 - g_img_chunk_list.chunk[i].disk_start_sector; + sectors += cursecs; + if (sectors >= offset) + { + delta = cursecs - (sectors - offset); + break; + } + } + + if (sectors < offset || i >= g_img_chunk_list.cur_chunk) + { + debug("Invalid size %lu %lu\n", (ulong)sectors, (ulong)offset); + return 0; + } + + if (sectors == offset) + { + memsize = (g_img_chunk_list.cur_chunk - (i + 1)) * sizeof(hiperiso_img_chunk); + grub_memmove(g_img_chunk_list.chunk, g_img_chunk_list.chunk + i + 1, memsize); + g_img_chunk_list.cur_chunk -= (i + 1); + } + else + { + g_img_chunk_list.chunk[i].disk_start_sector += delta; + g_img_chunk_list.chunk[i].img_start_sector += (grub_uint32_t)(delta / 4); + + if (i > 0) + { + memsize = (g_img_chunk_list.cur_chunk - i) * sizeof(hiperiso_img_chunk); + grub_memmove(g_img_chunk_list.chunk, g_img_chunk_list.chunk + i, memsize); + g_img_chunk_list.cur_chunk -= i; + } + } + + for (i = 0; i < g_img_chunk_list.cur_chunk; i++) + { + imgsecs = g_img_chunk_list.chunk[i].img_end_sector + 1 - g_img_chunk_list.chunk[i].img_start_sector; + g_img_chunk_list.chunk[i].img_start_sector = imgstart; + g_img_chunk_list.chunk[i].img_end_sector = imgstart + (imgsecs - 1); + imgstart += imgsecs; + } + + return 0; +} + +grub_err_t hiperiso_cmd_get_hiso_type(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int altboot = 0; + int offset = -1; + grub_file_t file; + grub_uint8_t data = 0; + vhd_footer_t vhdfoot; + VDIPREHEADER vdihdr; + char type[16] = {0}; + hiperiso_gpt_info *gpt = NULL; + + (void)ctxt; + + g_img_trim_head_secnum = 0; + + if (argc != 4) + { + return 0; + } + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!file) + { + debug("Failed to open file %s\n", args[0]); + return 0; + } + + grub_snprintf(type, sizeof(type), "unknown"); + + grub_file_seek(file, file->size - 512); + grub_file_read(file, &vhdfoot, sizeof(vhdfoot)); + + if (grub_strncmp(vhdfoot.cookie, "conectix", 8) == 0) + { + offset = 0; + grub_snprintf(type, sizeof(type), "vhd%u", grub_swap_bytes32(vhdfoot.disktype)); + } + else + { + grub_file_seek(file, 0); + grub_file_read(file, &vdihdr, sizeof(vdihdr)); + if (vdihdr.u32Signature == VDI_IMAGE_SIGNATURE) + { + grub_snprintf(type, sizeof(type), "vdi"); + if (grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO, grub_strlen(VDI_IMAGE_FILE_INFO)) == 0) + { + offset = 2 * 1048576; + g_img_trim_head_secnum = offset / 512; + debug("VDI V1\n"); + } + else if (grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO2, grub_strlen(VDI_IMAGE_FILE_INFO2)) == 0) + { + offset = 2 * 1048576; + g_img_trim_head_secnum = offset / 512; + debug("VDI V2\n"); + } + else + { + debug("invalid file info <%s>\n", vdihdr.szFileInfo); + } + } + else + { + offset = 0; + grub_snprintf(type, sizeof(type), "raw"); + } + } + + grub_env_set(args[1], type); + debug("<%s> hiso type: <%s> offset:%d\n", args[0], type, offset); + + if (offset >= 0) + { + gpt = grub_zalloc(sizeof(hiperiso_gpt_info)); + if (!gpt) + { + grub_env_set(args[1], "unknown"); + goto end; + } + + grub_file_seek(file, offset); + grub_file_read(file, gpt, sizeof(hiperiso_gpt_info)); + + if (gpt->MBR.Byte55 != 0x55 || gpt->MBR.ByteAA != 0xAA) + { + grub_env_set(args[1], "unknown"); + debug("invalid mbr signature: 0x%x 0x%x offset=%d\n", gpt->MBR.Byte55, gpt->MBR.ByteAA, offset); + goto end; + } + + if (grub_memcmp(gpt->Head.Signature, "EFI PART", 8) == 0) + { + grub_env_set(args[2], "gpt"); + debug("part type: %s\n", "GPT"); + + if (gpt->MBR.PartTbl[0].FsFlag == 0xEE) + { + for (i = 0; i < 128; i++) + { + if (grub_memcmp(gpt->PartTbl[i].PartType, "Hah!IdontNeedEFI", 16) == 0) + { + debug("part %d is grub_bios part\n", i); + altboot = 1; + grub_env_set(args[3], "1"); + break; + } + else if (gpt->PartTbl[i].LastLBA == 0) + { + break; + } + } + } + + if (!altboot) + { + if (gpt->MBR.BootCode[92] == 0x22) + { + grub_file_seek(file, offset + 17908); + grub_file_read(file, &data, 1); + if (data == 0x23) + { + altboot = 1; + grub_env_set(args[3], "1"); + } + else + { + debug("offset data=0x%x\n", data); + } + } + else + { + debug("BootCode: 0x%x\n", gpt->MBR.BootCode[92]); + } + } + } + else + { + grub_env_set(args[2], "mbr"); + debug("part type: %s\n", "MBR"); + + for (i = 0; i < 4; i++) + { + if (gpt->MBR.PartTbl[i].FsFlag == 0xEF) + { + debug("part %d is esp part in MBR mode\n", i); + altboot = 1; + grub_env_set(args[3], "1"); + break; + } + } + } + } + else + { + debug("part type: %s\n", "xxx"); + } + +end: + grub_check_free(gpt); + grub_file_close(file); + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint32_t size = 0; + grub_uint32_t img_chunk_size = 0; + grub_file_t file; + grub_disk_t disk; + const char *pLastChain = NULL; + hiperiso_chain_head *chain; + + (void)ctxt; + (void)argc; + + if (NULL == g_img_chunk_list.chunk) + { + grub_printf("hiperiso not ready\n"); + return 1; + } + + if (g_img_trim_head_secnum > 0) + { + hiperiso_raw_trim_head(g_img_trim_head_secnum); + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + return 1; + } + + if (grub_strncmp(args[0], g_iso_path, grub_strlen(g_iso_path))) + { + file->vlnk = 1; + } + + img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + + size = sizeof(hiperiso_chain_head) + img_chunk_size; + + pLastChain = grub_env_get("hiso_chain_mem_addr"); + if (pLastChain) + { + chain = (hiperiso_chain_head *)grub_strtoul(pLastChain, NULL, 16); + if (chain) + { + debug("free last chain memory %p\n", chain); + grub_free(chain); + } + } + + chain = hiperiso_alloc_chain(size); + if (!chain) + { + grub_printf("Failed to alloc chain raw memory size %u\n", size); + grub_file_close(file); + return 1; + } + + hiperiso_memfile_env_set("hiso_chain_mem", chain, (ulonglong)size); + + grub_env_export("hiso_chain_mem_addr"); + grub_env_export("hiso_chain_mem_size"); + + grub_memset(chain, 0, sizeof(hiperiso_chain_head)); + + /* part 1: os parameter */ + g_hiperiso_chain_type = hiperiso_chain_linux; + hiperiso_fill_os_param(file, &(chain->os_param)); + + /* part 2: chain head */ + disk = file->device->disk; + chain->disk_drive = disk->id; + chain->disk_sector_size = (1 << disk->log_sector_size); + + chain->real_img_size_in_bytes = file->size; + if (g_img_trim_head_secnum > 0) + { + chain->real_img_size_in_bytes -= g_img_trim_head_secnum * 512; + } + + chain->virt_img_size_in_bytes = chain->real_img_size_in_bytes; + chain->boot_catalog = 0; + + /* part 3: image chunk */ + chain->img_chunk_offset = sizeof(hiperiso_chain_head); + chain->img_chunk_num = g_img_chunk_list.cur_chunk; + grub_memcpy((char *)chain + chain->img_chunk_offset, g_img_chunk_list.chunk, img_chunk_size); + + grub_file_seek(file, g_img_trim_head_secnum * 512); + grub_file_read(file, chain->boot_catalog_sector, 512); + + grub_file_close(file); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} diff --git a/src/grub2/hiperiso_windows.c b/src/grub2/hiperiso_windows.c new file mode 100644 index 0000000..f2a858d --- /dev/null +++ b/src/grub2/hiperiso_windows.c @@ -0,0 +1,2781 @@ +/****************************************************************************** + * hiperiso_windows.c + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" + +GRUB_MOD_LICENSE ("GPLv3+"); + +static int g_iso_fs_type = 0; +static int g_wim_total_patch_count = 0; +static int g_wim_valid_patch_count = 0; +static wim_patch *g_wim_patch_head = NULL; + +static grub_uint64_t g_suppress_wincd_override_offset = 0; +static grub_uint32_t g_suppress_wincd_override_data = 0; + +grub_uint8_t g_temp_buf[512]; + +grub_ssize_t lzx_decompress ( const void *data, grub_size_t len, void *buf ); +grub_ssize_t xca_decompress ( const void *data, grub_size_t len, void *buf ); + +static wim_patch *hiperiso_find_wim_patch(const char *path) +{ + int len = (int)grub_strlen(path); + wim_patch *node = g_wim_patch_head; + + while (node) + { + if (len == node->pathlen && 0 == grub_strcmp(path, node->path)) + { + return node; + } + node = node->next; + } + + return NULL; +} + +static int hiperiso_collect_wim_patch(const char *bcdfile) +{ + int i, j, k; + int rc = 1; + grub_uint64_t magic; + grub_file_t file = NULL; + char *buf = NULL; + wim_patch *node = NULL; + char c; + grub_uint8_t byte; + char valid; + char path[256]; + + g_hiperiso_case_insensitive = 1; + file = grub_file_open(bcdfile, HIPERISO_FILE_TYPE); + g_hiperiso_case_insensitive = 0; + if (!file) + { + debug("Failed to open file %s\n", bcdfile); + grub_errno = 0; + goto end; + } + + buf = grub_malloc(file->size + 8); + if (!buf) + { + goto end; + } + + grub_file_read(file, buf, file->size); + + for (i = 0; i < (int)file->size - 8; i++) + { + if (buf[i + 8] != 0) + { + continue; + } + + magic = *(grub_uint64_t *)(buf + i); + + /* .wim .WIM .Wim */ + if ((magic == 0x006D00690077002EULL) || + (magic == 0x004D00490057002EULL) || + (magic == 0x006D00690057002EULL)) + { + for (j = i; j > 0; j-= 2) + { + if (*(grub_uint16_t *)(buf + j) == 0) + { + break; + } + } + + if (j > 0) + { + byte = (grub_uint8_t)(*(grub_uint16_t *)(buf + j + 2)); + if (byte != '/' && byte != '\\') + { + continue; + } + + valid = 1; + for (k = 0, j += 2; k < (int)sizeof(path) - 1 && j < i + 8; j += 2) + { + byte = (grub_uint8_t)(*(grub_uint16_t *)(buf + j)); + c = (char)byte; + if (byte > '~' || byte < ' ') /* not printable */ + { + valid = 0; + break; + } + else if (c == '\\') + { + c = '/'; + } + + path[k++] = c; + } + path[k++] = 0; + + debug("@@@@ Find wim flag:<%s>\n", path); + + if (0 == valid) + { + debug("Invalid wim file %d\n", k); + } + else if (NULL == hiperiso_find_wim_patch(path)) + { + node = grub_zalloc(sizeof(wim_patch)); + if (node) + { + node->pathlen = grub_snprintf(node->path, sizeof(node->path), "%s", path); + + debug("add patch <%s>\n", path); + + if (g_wim_patch_head) + { + node->next = g_wim_patch_head; + } + g_wim_patch_head = node; + + g_wim_total_patch_count++; + } + } + else + { + debug("wim <%s> already exist\n", path); + } + } + } + } + +end: + check_free(file, grub_file_close); + grub_check_free(buf); + return rc; +} + +grub_err_t hiperiso_cmd_wim_patch_count(grub_extcmd_context_t ctxt, int argc, char **args) +{ + char buf[32]; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc == 1) + { + grub_snprintf(buf, sizeof(buf), "%d", g_wim_total_patch_count); + hiperiso_set_env(args[0], buf); + } + + return 0; +} + +grub_err_t hiperiso_cmd_collect_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args) +{ + wim_patch *node = NULL; + + (void)ctxt; + (void)argc; + (void)args; + + if (argc != 2) + { + return 1; + } + + debug("hiperiso_cmd_collect_wim_patch %s %s\n", args[0], args[1]); + + if (grub_strcmp(args[0], "bcd") == 0) + { + hiperiso_collect_wim_patch(args[1]); + return 0; + } + + if (NULL == hiperiso_find_wim_patch(args[1])) + { + node = grub_zalloc(sizeof(wim_patch)); + if (node) + { + node->pathlen = grub_snprintf(node->path, sizeof(node->path), "%s", args[1]); + + debug("add patch <%s>\n", args[1]); + + if (g_wim_patch_head) + { + node->next = g_wim_patch_head; + } + g_wim_patch_head = node; + + g_wim_total_patch_count++; + } + } + + return 0; +} + + +grub_err_t hiperiso_cmd_dump_wim_patch(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i = 0; + wim_patch *node = NULL; + + (void)ctxt; + (void)argc; + (void)args; + + for (node = g_wim_patch_head; node; node = node->next) + { + grub_printf("%d %s [%s]\n", i++, node->path, node->valid ? "SUCCESS" : "FAIL"); + } + + return 0; +} + + +static int wim_name_cmp(const char *search, grub_uint16_t *name, grub_uint16_t namelen) +{ + char c1 = hiso_to_upper(*search); + char c2 = hiso_to_upper(*name); + + while (namelen > 0 && (c1 == c2)) + { + search++; + name++; + namelen--; + + c1 = hiso_to_upper(*search); + c2 = hiso_to_upper(*name); + } + + if (namelen == 0 && *search == 0) + { + return 0; + } + + return 1; +} + +static int hiperiso_is_pe64(grub_uint8_t *buffer) +{ + grub_uint32_t pe_off; + + if (buffer[0] != 'M' || buffer[1] != 'Z') + { + return 0; + } + + pe_off = *(grub_uint32_t *)(buffer + 60); + + if (buffer[pe_off] != 'P' || buffer[pe_off + 1] != 'E') + { + return 0; + } + + if (*(grub_uint16_t *)(buffer + pe_off + 24) == 0x020b) + { + return 1; + } + + return 0; +} + +grub_err_t hiperiso_cmd_is_pe64(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int ret = 1; + grub_file_t file; + grub_uint8_t buf[512]; + + (void)ctxt; + (void)argc; + + file = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!file) + { + return 1; + } + + grub_memset(buf, 0, 512); + grub_file_read(file, buf, 512); + if (hiperiso_is_pe64(buf)) + { + debug("%s is PE64\n", args[0]); + ret = 0; + } + else + { + debug("%s is PE32\n", args[0]); + } + grub_file_close(file); + + return ret; +} + +grub_err_t hiperiso_cmd_sel_wimboot(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int size; + char *buf = NULL; + char configfile[128]; + + (void)ctxt; + (void)argc; + (void)args; + + debug("select wimboot argc:%d\n", argc); + + buf = (char *)grub_malloc(8192); + if (!buf) + { + return 0; + } + + size = (int)grub_snprintf(buf, 8192, + "menuentry \"Windows Setup (32-bit)\" {\n" + " set hiso_wimboot_sel=32\n" + "}\n" + "menuentry \"Windows Setup (64-bit)\" {\n" + " set hiso_wimboot_sel=64\n" + "}\n" + ); + buf[size] = 0; + + g_hiperiso_menu_esc = 1; + g_hiperiso_suppress_esc = 1; + g_hiperiso_suppress_esc_default = 1; + + grub_snprintf(configfile, sizeof(configfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)buf, size); + grub_script_execute_sourcecode(configfile); + + g_hiperiso_menu_esc = 0; + g_hiperiso_suppress_esc = 0; + + grub_free(buf); + + if (g_hiperiso_last_entry == 0) + { + debug("last entry=%d %s=32\n", g_hiperiso_last_entry, args[0]); + grub_env_set(args[0], "32"); + } + else + { + debug("last entry=%d %s=64\n", g_hiperiso_last_entry, args[0]); + grub_env_set(args[0], "64"); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_wimdows_reset(grub_extcmd_context_t ctxt, int argc, char **args) +{ + wim_patch *next = NULL; + wim_patch *node = g_wim_patch_head; + + (void)ctxt; + (void)argc; + (void)args; + + while (node) + { + next = node->next; + grub_free(node); + node = next; + } + + g_wim_patch_head = NULL; + g_wim_total_patch_count = 0; + g_wim_valid_patch_count = 0; + + return 0; +} + +static int hiperiso_load_jump_exe(const char *path, grub_uint8_t **data, grub_uint32_t *size, wim_hash *hash) +{ + grub_uint32_t i; + grub_uint32_t align; + grub_file_t file; + + debug("windows load jump %s\n", path); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", path); + if (!file) + { + debug("Can't open file %s\n", path); + return 1; + } + + align = hiperiso_align((int)file->size, 2048); + + debug("file %s size:%d align:%u\n", path, (int)file->size, align); + + *size = (grub_uint32_t)file->size; + *data = (grub_uint8_t *)grub_malloc(align); + if ((*data) == NULL) + { + debug("Failed to alloc memory size %u\n", align); + goto end; + } + + grub_file_read(file, (*data), file->size); + + if (hash) + { + grub_crypto_hash(GRUB_MD_SHA1, hash->sha1, (*data), file->size); + + if (g_hiperiso_debug) + { + debug("%s", "jump bin 64 hash: "); + for (i = 0; i < sizeof(hash->sha1); i++) + { + hiperiso_debug("%02x ", hash->sha1[i]); + } + hiperiso_debug("\n"); + } + } + +end: + + grub_file_close(file); + return 0; +} + +static int hiperiso_get_override_info(grub_file_t file, wim_tail *wim_data) +{ + grub_uint32_t start_block; + grub_uint64_t file_offset; + grub_uint64_t override_offset; + grub_uint32_t override_len; + grub_uint64_t fe_entry_size_offset; + + if (grub_strcmp(file->fs->name, "iso9660") == 0) + { + g_iso_fs_type = wim_data->iso_type = 0; + override_len = sizeof(hiperiso_iso9660_override); + override_offset = grub_iso9660_get_last_file_dirent_pos(file) + 2; + + grub_file_read(file, &start_block, 1); // just read for hook trigger + file_offset = grub_iso9660_get_last_read_pos(file); + + debug("iso9660 wim size:%llu override_offset:%llu file_offset:%llu\n", + (ulonglong)file->size, (ulonglong)override_offset, (ulonglong)file_offset); + } + else + { + g_iso_fs_type = wim_data->iso_type = 1; + override_len = sizeof(hiperiso_udf_override); + override_offset = grub_udf_get_last_file_attr_offset(file, &start_block, &fe_entry_size_offset); + + file_offset = grub_udf_get_file_offset(file); + + debug("UDF wim size:%llu override_offset:%llu file_offset:%llu start_block=%u\n", + (ulonglong)file->size, (ulonglong)override_offset, (ulonglong)file_offset, start_block); + } + + wim_data->file_offset = file_offset; + wim_data->udf_start_block = start_block; + wim_data->fe_entry_size_offset = fe_entry_size_offset; + wim_data->override_offset = override_offset; + wim_data->override_len = override_len; + + return 0; +} + +static int hiperiso_read_resource(grub_file_t fp, wim_header *wimhdr, wim_resource_header *head, void **buffer) +{ + int decompress_len = 0; + int total_decompress = 0; + grub_uint32_t i = 0; + grub_uint32_t chunk_num = 0; + grub_uint32_t chunk_size = 0; + grub_uint32_t last_chunk_size = 0; + grub_uint32_t last_decompress_size = 0; + grub_uint32_t cur_offset = 0; + grub_uint8_t *cur_dst = NULL; + grub_uint8_t *buffer_compress = NULL; + grub_uint8_t *buffer_decompress = NULL; + grub_uint32_t *chunk_offset = NULL; + + buffer_decompress = (grub_uint8_t *)grub_malloc(head->raw_size + head->size_in_wim); + if (NULL == buffer_decompress) + { + return 0; + } + + grub_file_seek(fp, head->offset); + + if (head->size_in_wim == head->raw_size) + { + grub_file_read(fp, buffer_decompress, head->size_in_wim); + *buffer = buffer_decompress; + return 0; + } + + buffer_compress = buffer_decompress + head->raw_size; + grub_file_read(fp, buffer_compress, head->size_in_wim); + + chunk_num = (head->raw_size + WIM_CHUNK_LEN - 1) / WIM_CHUNK_LEN; + cur_offset = (chunk_num - 1) * 4; + chunk_offset = (grub_uint32_t *)buffer_compress; + + //debug("%llu %llu chunk_num=%lu", (ulonglong)head->size_in_wim, (ulonglong)head->raw_size, chunk_num); + + cur_dst = buffer_decompress; + + for (i = 0; i < chunk_num - 1; i++) + { + chunk_size = (i == 0) ? chunk_offset[i] : chunk_offset[i] - chunk_offset[i - 1]; + + if (WIM_CHUNK_LEN == chunk_size) + { + grub_memcpy(cur_dst, buffer_compress + cur_offset, chunk_size); + decompress_len = (int)chunk_size; + } + else + { + if (wimhdr->flags & FLAG_HEADER_COMPRESS_XPRESS) + { + decompress_len = (int)xca_decompress(buffer_compress + cur_offset, chunk_size, cur_dst); + } + else + { + decompress_len = (int)lzx_decompress(buffer_compress + cur_offset, chunk_size, cur_dst); + } + } + + //debug("chunk_size:%u decompresslen:%d\n", chunk_size, decompress_len); + + total_decompress += decompress_len; + cur_dst += decompress_len; + cur_offset += chunk_size; + } + + /* last chunk */ + last_chunk_size = (grub_uint32_t)(head->size_in_wim - cur_offset); + last_decompress_size = head->raw_size - total_decompress; + + if (last_chunk_size < WIM_CHUNK_LEN && last_chunk_size == last_decompress_size) + { + debug("Last chunk %u uncompressed\n", last_chunk_size); + grub_memcpy(cur_dst, buffer_compress + cur_offset, last_chunk_size); + decompress_len = (int)last_chunk_size; + } + else + { + if (wimhdr->flags & FLAG_HEADER_COMPRESS_XPRESS) + { + decompress_len = (int)xca_decompress(buffer_compress + cur_offset, head->size_in_wim - cur_offset, cur_dst); + } + else + { + decompress_len = (int)lzx_decompress(buffer_compress + cur_offset, head->size_in_wim - cur_offset, cur_dst); + } + } + + cur_dst += decompress_len; + total_decompress += decompress_len; + + //debug("last chunk_size:%u decompresslen:%d tot:%d\n", last_chunk_size, decompress_len, total_decompress); + + if (cur_dst != buffer_decompress + head->raw_size) + { + debug("head->size_in_wim:%llu head->raw_size:%llu cur_dst:%p buffer_decompress:%p total_decompress:%d\n", + (ulonglong)head->size_in_wim, (ulonglong)head->raw_size, cur_dst, buffer_decompress, total_decompress); + grub_free(buffer_decompress); + return 1; + } + + *buffer = buffer_decompress; + return 0; +} + + +static wim_directory_entry * search_wim_dirent(wim_directory_entry *dir, const char *search_name) +{ + do + { + if (dir->len && dir->name_len) + { + if (wim_name_cmp(search_name, (grub_uint16_t *)(dir + 1), dir->name_len / 2) == 0) + { + return dir; + } + } + dir = (wim_directory_entry *)((grub_uint8_t *)dir + dir->len); + } while(dir->len); + + return NULL; +} + +static wim_directory_entry * search_full_wim_dirent +( + void *meta_data, + wim_directory_entry *dir, + const char **path +) +{ + wim_directory_entry *subdir = NULL; + wim_directory_entry *search = dir; + + while (*path) + { + subdir = (wim_directory_entry *)((char *)meta_data + search->subdir); + search = search_wim_dirent(subdir, *path); + path++; + } + + return search; +} + + + +static wim_lookup_entry * hiperiso_find_look_entry(wim_header *header, wim_lookup_entry *lookup, wim_hash *hash) +{ + grub_uint32_t i = 0; + + for (i = 0; i < (grub_uint32_t)header->lookup.raw_size / sizeof(wim_lookup_entry); i++) + { + if (grub_memcmp(&lookup[i].hash, hash, sizeof(wim_hash)) == 0) + { + return lookup + i; + } + } + + return NULL; +} + +static int parse_registry_setup_cmdline +( + grub_file_t file, + wim_header *head, + wim_lookup_entry *lookup, + void *meta_data, + wim_directory_entry *dir, + char *buf, + grub_uint32_t buflen +) +{ + char c; + int ret = 0; + grub_uint32_t i = 0; + grub_uint32_t reglen = 0; + wim_hash zerohash; + reg_vk *regvk = NULL; + wim_lookup_entry *look = NULL; + wim_directory_entry *wim_dirent = NULL; + char *decompress_data = NULL; + const char *reg_path[] = { "Windows", "System32", "config", "SYSTEM", NULL }; + + wim_dirent = search_full_wim_dirent(meta_data, dir, reg_path); + debug("search reg SYSTEM %p\n", wim_dirent); + if (!wim_dirent) + { + return 1; + } + + grub_memset(&zerohash, 0, sizeof(zerohash)); + if (grub_memcmp(&zerohash, wim_dirent->hash.sha1, sizeof(wim_hash)) == 0) + { + return 2; + } + + look = hiperiso_find_look_entry(head, lookup, &wim_dirent->hash); + if (!look) + { + return 3; + } + + reglen = (grub_uint32_t)look->resource.raw_size; + debug("find system lookup entry_id:%ld raw_size:%u\n", + ((long)look - (long)lookup) / sizeof(wim_lookup_entry), reglen); + + if (0 != hiperiso_read_resource(file, head, &(look->resource), (void **)&(decompress_data))) + { + return 4; + } + + if (grub_strncmp(decompress_data + 0x1000, "hbin", 4)) + { + ret_goto_end(5); + } + + for (i = 0x1000; i + sizeof(reg_vk) < reglen; i += 8) + { + regvk = (reg_vk *)(decompress_data + i); + if (regvk->sig == 0x6B76 && regvk->namesize == 7 && + regvk->datatype == 1 && regvk->flag == 1) + { + if (grub_strncasecmp((char *)(regvk + 1), "cmdline", 7) == 0) + { + debug("find registry cmdline i:%u offset:(0x%x)%u size:(0x%x)%u\n", + i, regvk->dataoffset, regvk->dataoffset, regvk->datasize, regvk->datasize); + break; + } + } + } + + if (i + sizeof(reg_vk) >= reglen || regvk == NULL) + { + ret_goto_end(6); + } + + if (regvk->datasize == 0 || (regvk->datasize & 0x80000000) > 0 || + regvk->dataoffset == 0 || regvk->dataoffset == 0xFFFFFFFF) + { + ret_goto_end(7); + } + + if (regvk->datasize / 2 >= buflen) + { + ret_goto_end(8); + } + + debug("start offset is 0x%x(%u)\n", 0x1000 + regvk->dataoffset + 4, 0x1000 + regvk->dataoffset + 4); + + for (i = 0; i < regvk->datasize; i+=2) + { + c = (char)(*(grub_uint16_t *)(decompress_data + 0x1000 + regvk->dataoffset + 4 + i)); + *buf++ = c; + } + + ret = 0; + +end: + grub_check_free(decompress_data); + return ret; +} + +static int parse_custom_setup_path(char *cmdline, const char **path, char *exefile) +{ + int i = 0; + int len = 0; + char *pos1 = NULL; + char *pos2 = NULL; + + if ((cmdline[0] == 'x' || cmdline[0] == 'X') && cmdline[1] == ':') + { + pos1 = pos2 = cmdline + 3; + + while (i < HISO_MAX_DIR_DEPTH && *pos2) + { + while (*pos2 && *pos2 != '\\' && *pos2 != '/') + { + pos2++; + } + + path[i++] = pos1; + + if (*pos2 == 0) + { + break; + } + + *pos2 = 0; + pos1 = pos2 + 1; + pos2 = pos1; + } + + if (i == 0 || i >= HISO_MAX_DIR_DEPTH) + { + return 1; + } + } + else + { + path[i++] = "Windows"; + path[i++] = "System32"; + path[i++] = cmdline; + } + + pos1 = (char *)path[i - 1]; + while (*pos1 != ' ' && *pos1 != '\t' && *pos1) + { + pos1++; + } + *pos1 = 0; + + len = (int)grub_strlen(path[i - 1]); + if (len < 4 || grub_strcasecmp(path[i - 1] + len - 4, ".exe") != 0) + { + grub_snprintf(exefile, 256, "%s.exe", path[i - 1]); + path[i - 1] = exefile; + } + + + debug("custom setup: %d <%s>\n", i, path[i - 1]); + return 0; +} + +static wim_directory_entry * search_replace_wim_dirent +( + grub_file_t file, + wim_header *head, + wim_lookup_entry *lookup, + void *meta_data, + wim_directory_entry *dir +) +{ + int ret; + char exefile[256] = {0}; + char cmdline[256] = {0}; + wim_directory_entry *wim_dirent = NULL; + wim_directory_entry *pecmd_dirent = NULL; + const char *peset_path[] = { "Windows", "System32", "peset.exe", NULL }; + const char *pecmd_path[] = { "Windows", "System32", "pecmd.exe", NULL }; + const char *winpeshl_path[] = { "Windows", "System32", "winpeshl.exe", NULL }; + const char *custom_path[HISO_MAX_DIR_DEPTH + 1] = { NULL }; + + pecmd_dirent = search_full_wim_dirent(meta_data, dir, pecmd_path); + debug("search pecmd.exe %p\n", pecmd_dirent); + + if (pecmd_dirent) + { + ret = parse_registry_setup_cmdline(file, head, lookup, meta_data, dir, cmdline, sizeof(cmdline) - 1); + if (0 == ret) + { + debug("registry setup cmdline:<%s>\n", cmdline); + + if (grub_strncasecmp(cmdline, "PECMD", 5) == 0) + { + wim_dirent = pecmd_dirent; + } + else if (grub_strncasecmp(cmdline, "PESET", 5) == 0) + { + wim_dirent = search_full_wim_dirent(meta_data, dir, peset_path); + debug("search peset.exe %p\n", wim_dirent); + } + else if (grub_strncasecmp(cmdline, "WINPESHL", 8) == 0) + { + wim_dirent = search_full_wim_dirent(meta_data, dir, winpeshl_path); + debug("search winpeshl.exe %p\n", wim_dirent); + } + else if (0 == parse_custom_setup_path(cmdline, custom_path, exefile)) + { + wim_dirent = search_full_wim_dirent(meta_data, dir, custom_path); + debug("search custom path %p\n", wim_dirent); + } + + if (wim_dirent) + { + return wim_dirent; + } + } + else + { + debug("registry setup cmdline failed : %d\n", ret); + } + } + + wim_dirent = pecmd_dirent; + if (wim_dirent) + { + return wim_dirent; + } + + wim_dirent = search_full_wim_dirent(meta_data, dir, winpeshl_path); + debug("search winpeshl.exe %p\n", wim_dirent); + if (wim_dirent) + { + return wim_dirent; + } + + return NULL; +} + + +static wim_lookup_entry * hiperiso_find_meta_entry(wim_header *header, wim_lookup_entry *lookup) +{ + grub_uint32_t i = 0; + grub_uint32_t index = 0;; + + if ((header == NULL) || (lookup == NULL)) + { + return NULL; + } + + for (i = 0; i < (grub_uint32_t)header->lookup.raw_size / sizeof(wim_lookup_entry); i++) + { + if (lookup[i].resource.flags & RESHDR_FLAG_METADATA) + { + index++; + if (index == header->boot_index) + { + return lookup + i; + } + } + } + + return NULL; +} + +static grub_uint64_t hiperiso_get_stream_len(wim_directory_entry *dir) +{ + grub_uint16_t i; + grub_uint64_t offset = 0; + wim_stream_entry *stream = (wim_stream_entry *)((char *)dir + dir->len); + + for (i = 0; i < dir->streams; i++) + { + offset += stream->len; + stream = (wim_stream_entry *)((char *)stream + stream->len); + } + + return offset; +} + +static int hiperiso_update_stream_hash(wim_patch *patch, wim_directory_entry *dir) +{ + grub_uint16_t i; + grub_uint64_t offset = 0; + wim_stream_entry *stream = (wim_stream_entry *)((char *)dir + dir->len); + + for (i = 0; i < dir->streams; i++) + { + if (grub_memcmp(stream->hash.sha1, patch->old_hash.sha1, sizeof(wim_hash)) == 0) + { + debug("find target stream %u, name_len:%u upadte hash\n", i, stream->name_len); + grub_memcpy(stream->hash.sha1, &(patch->wim_data.bin_hash), sizeof(wim_hash)); + } + + offset += stream->len; + stream = (wim_stream_entry *)((char *)stream + stream->len); + } + + return offset; +} + +static int hiperiso_update_all_hash(wim_patch *patch, void *meta_data, wim_directory_entry *dir) +{ + if ((meta_data == NULL) || (dir == NULL)) + { + return 0; + } + + if (dir->len < sizeof(wim_directory_entry)) + { + return 0; + } + + do + { + if (dir->subdir == 0 && grub_memcmp(dir->hash.sha1, patch->old_hash.sha1, sizeof(wim_hash)) == 0) + { + debug("find target file, name_len:%u upadte hash\n", dir->name_len); + grub_memcpy(dir->hash.sha1, &(patch->wim_data.bin_hash), sizeof(wim_hash)); + } + + if (dir->subdir) + { + hiperiso_update_all_hash(patch, meta_data, (wim_directory_entry *)((char *)meta_data + dir->subdir)); + } + + if (dir->streams) + { + hiperiso_update_stream_hash(patch, dir); + dir = (wim_directory_entry *)((char *)dir + dir->len + hiperiso_get_stream_len(dir)); + } + else + { + dir = (wim_directory_entry *)((char *)dir + dir->len); + } + } while (dir->len >= sizeof(wim_directory_entry)); + + return 0; +} + +static int hiperiso_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]; + grub_uint32_t jump_len = 0; + grub_uint32_t jump_align = 0; + grub_uint8_t *jump_data = NULL; + + pe64 = hiperiso_is_pe64(exe_data); + + grub_snprintf(file, sizeof(file), "%s/hisojump%d.exe", grub_env_get("hiso_path"), pe64 ? 64 : 32); + hiperiso_load_jump_exe(file, &jump_data, &jump_len, NULL); + jump_align = hiperiso_align(jump_len, 16); + + wim_data->jump_exe_len = jump_len; + wim_data->bin_raw_len = jump_align + sizeof(hiperiso_os_param) + windatalen + exe_len; + wim_data->bin_align_len = hiperiso_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(hiperiso_os_param) + windatalen, exe_data, exe_len); + } + + debug("jump_exe_len:%u bin_raw_len:%u bin_align_len:%u\n", + wim_data->jump_exe_len, wim_data->bin_raw_len, wim_data->bin_align_len); + + return 0; +} + +static int hiperiso_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(hiperiso_windows_data); + + pos = grub_strstr(iso, "/"); + if (!pos) + { + return size; + } + + script = hiperiso_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 hiperiso_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; + hiperiso_windows_data *data = (hiperiso_windows_data *)buf; + + grub_memset(data, 0, sizeof(hiperiso_windows_data)); + + env = grub_env_get("HISO_WIN11_BYPASS_CHECK"); + if (env && env[0] == '1' && env[1] == 0) + { + data->windows11_bypass_check = 1; + } + + env = grub_env_get("HISO_WIN11_BYPASS_NRO"); + if (env && env[0] == '1' && env[1] == 0) + { + data->windows11_bypass_nro = 1; + } + + pos = grub_strstr(isopath, "/"); + if (!pos) + { + return 1; + } + + if (dataflag & WINDATA_FLAG_TEMPLATE) + { + script = hiperiso_plugin_get_cur_install_template(pos, &template_node); + if (script) + { + data->auto_install_len = template_len = template_node->filelen; + debug("auto install script OK <%s> \n", script, template_len); + end = hiperiso_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 + { + debug("auto install script skipped or not configed %s\n", pos); + } + + script = (char *)hiperiso_plugin_get_injection(pos); + if (script) + { + if (hiperiso_check_file_exist("%s%s", hiperiso_get_env("hiso_iso_part"), script)) + { + debug("injection archive <%s> OK\n", script); + grub_snprintf(data->injection_archive, sizeof(data->injection_archive) - 1, "%s", script); + } + else + { + debug("injection archive <%s> NOT exist\n", script); + } + } + else + { + debug("injection archive not configed %s\n", pos); + } + + return 0; +} + +static int hiperiso_update_before_chain(hiperiso_os_param *param, char *isopath) +{ + grub_uint32_t jump_align = 0; + wim_lookup_entry *meta_look = NULL; + wim_security_header *security = NULL; + wim_directory_entry *rootdir = NULL; + wim_header *head = NULL; + wim_lookup_entry *lookup = NULL; + wim_patch *node = NULL; + wim_tail *wim_data = NULL; + + for (node = g_wim_patch_head; node; node = node->next) + { + if (0 == node->valid) + { + continue; + } + + wim_data = &node->wim_data; + head = &wim_data->wim_header; + lookup = (wim_lookup_entry *)wim_data->new_lookup_data; + + jump_align = hiperiso_align(wim_data->jump_exe_len, 16); + if (wim_data->jump_bin_data) + { + grub_memcpy(wim_data->jump_bin_data + jump_align, param, sizeof(hiperiso_os_param)); + hiperiso_fill_windows_rtdata(wim_data->jump_bin_data + jump_align + sizeof(hiperiso_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); + + security = (wim_security_header *)wim_data->new_meta_data; + if (security->len > 0) + { + rootdir = (wim_directory_entry *)(wim_data->new_meta_data + ((security->len + 7) & 0xFFFFFFF8U)); + } + else + { + rootdir = (wim_directory_entry *)(wim_data->new_meta_data + 8); + } + + /* update all winpeshl.exe dirent entry's hash */ + hiperiso_update_all_hash(node, wim_data->new_meta_data, rootdir); + + /* update winpeshl.exe lookup entry data (hash/offset/length) */ + if (node->replace_look) + { + debug("update replace lookup entry_id:%ld\n", ((long)node->replace_look - (long)lookup) / sizeof(wim_lookup_entry)); + node->replace_look->resource.raw_size = wim_data->bin_raw_len; + node->replace_look->resource.size_in_wim = wim_data->bin_raw_len; + node->replace_look->resource.flags = 0; + node->replace_look->resource.offset = wim_data->wim_align_size; + + grub_memcpy(node->replace_look->hash.sha1, wim_data->bin_hash.sha1, sizeof(wim_hash)); + } + + /* update metadata's hash */ + meta_look = hiperiso_find_meta_entry(head, lookup); + if (meta_look) + { + debug("find meta lookup entry_id:%ld\n", ((long)meta_look - (long)lookup) / sizeof(wim_lookup_entry)); + grub_memcpy(&meta_look->resource, &head->metadata, sizeof(wim_resource_header)); + grub_crypto_hash(GRUB_MD_SHA1, meta_look->hash.sha1, wim_data->new_meta_data, wim_data->new_meta_len); + } + } + + return 0; +} + +static int hiperiso_wimdows_locate_wim(const char *disk, wim_patch *patch, int windatalen) +{ + int rc; + grub_uint16_t i; + grub_file_t file; + grub_uint32_t exe_len; + grub_uint8_t *exe_data = NULL; + grub_uint8_t *decompress_data = NULL; + wim_lookup_entry *lookup = NULL; + wim_security_header *security = NULL; + wim_directory_entry *rootdir = NULL; + wim_directory_entry *search = NULL; + wim_stream_entry *stream = NULL; + wim_header *head = &(patch->wim_data.wim_header); + wim_tail *wim_data = &patch->wim_data; + + debug("windows locate wim start %s\n", patch->path); + + g_hiperiso_case_insensitive = 1; + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", disk, patch->path); + g_hiperiso_case_insensitive = 0; + + if (!file) + { + debug("File %s%s NOT exist\n", disk, patch->path); + return 1; + } + + hiperiso_get_override_info(file, &patch->wim_data); + + grub_file_seek(file, 0); + grub_file_read(file, head, sizeof(wim_header)); + + if (grub_memcmp(head->signature, WIM_HEAD_SIGNATURE, sizeof(head->signature))) + { + debug("Not a valid wim file %s\n", (char *)head->signature); + grub_file_close(file); + return 1; + } + + if (head->flags & FLAG_HEADER_COMPRESS_LZMS) + { + debug("LZMS compress is not supported 0x%x\n", head->flags); + grub_file_close(file); + return 1; + } + + rc = hiperiso_read_resource(file, head, &head->metadata, (void **)&decompress_data); + if (rc) + { + grub_printf("failed to read meta data %d\n", rc); + grub_file_close(file); + return 1; + } + + security = (wim_security_header *)decompress_data; + if (security->len > 0) + { + rootdir = (wim_directory_entry *)(decompress_data + ((security->len + 7) & 0xFFFFFFF8U)); + } + else + { + rootdir = (wim_directory_entry *)(decompress_data + 8); + } + + + debug("read lookup offset:%llu size:%llu\n", (ulonglong)head->lookup.offset, (ulonglong)head->lookup.raw_size); + lookup = grub_malloc(head->lookup.raw_size); + grub_file_seek(file, head->lookup.offset); + grub_file_read(file, lookup, head->lookup.raw_size); + + + + /* search winpeshl.exe dirent entry */ + search = search_replace_wim_dirent(file, head, lookup, decompress_data, rootdir); + if (!search) + { + debug("Failed to find replace file %p\n", search); + grub_file_close(file); + return 1; + } + + debug("find replace file at %p\n", search); + + grub_memset(&patch->old_hash, 0, sizeof(wim_hash)); + if (grub_memcmp(&patch->old_hash, search->hash.sha1, sizeof(wim_hash)) == 0) + { + debug("search hash all 0, now do deep search\n"); + stream = (wim_stream_entry *)((char *)search + search->len); + for (i = 0; i < search->streams; i++) + { + if (stream->name_len == 0) + { + grub_memcpy(&patch->old_hash, stream->hash.sha1, sizeof(wim_hash)); + debug("new search hash: %02x %02x %02x %02x %02x %02x %02x %02x\n", + hiperiso_varg_8(patch->old_hash.sha1)); + break; + } + stream = (wim_stream_entry *)((char *)stream + stream->len); + } + } + else + { + grub_memcpy(&patch->old_hash, search->hash.sha1, sizeof(wim_hash)); + } + + + /* find and extact winpeshl.exe */ + patch->replace_look = hiperiso_find_look_entry(head, lookup, &patch->old_hash); + if (patch->replace_look) + { + exe_len = (grub_uint32_t)patch->replace_look->resource.raw_size; + debug("find replace lookup entry_id:%ld raw_size:%u\n", + ((long)patch->replace_look - (long)lookup) / sizeof(wim_lookup_entry), exe_len); + + if (0 == hiperiso_read_resource(file, head, &(patch->replace_look->resource), (void **)&(exe_data))) + { + hiperiso_cat_exe_file_data(wim_data, exe_len, exe_data, windatalen); + grub_free(exe_data); + } + else + { + debug("failed to read replace file meta data %u\n", exe_len); + } + } + else + { + debug("failed to find lookup entry for replace file %02x %02x %02x %02x\n", + hiperiso_varg_4(patch->old_hash.sha1)); + } + + wim_data->wim_raw_size = (grub_uint32_t)file->size; + wim_data->wim_align_size = hiperiso_align(wim_data->wim_raw_size, 2048); + + grub_check_free(wim_data->new_meta_data); + wim_data->new_meta_data = decompress_data; + wim_data->new_meta_len = head->metadata.raw_size; + wim_data->new_meta_align_len = hiperiso_align(wim_data->new_meta_len, 2048); + + grub_check_free(wim_data->new_lookup_data); + wim_data->new_lookup_data = (grub_uint8_t *)lookup; + wim_data->new_lookup_len = (grub_uint32_t)head->lookup.raw_size; + wim_data->new_lookup_align_len = hiperiso_align(wim_data->new_lookup_len, 2048); + + head->metadata.flags = RESHDR_FLAG_METADATA; + head->metadata.offset = wim_data->wim_align_size + wim_data->bin_align_len; + head->metadata.size_in_wim = wim_data->new_meta_len; + head->metadata.raw_size = wim_data->new_meta_len; + + head->lookup.flags = 0; + head->lookup.offset = head->metadata.offset + wim_data->new_meta_align_len; + head->lookup.size_in_wim = wim_data->new_lookup_len; + head->lookup.raw_size = wim_data->new_lookup_len; + + grub_file_close(file); + + debug("%s", "windows locate wim finish\n"); + return 0; +} + +grub_err_t hiperiso_cmd_sel_winpe_wim(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i = 0; + int pos = 0; + int len = 0; + int find = 0; + char *cmd = NULL; + wim_patch *node = NULL; + wim_patch *tmp = NULL; + grub_file_t file = NULL; + wim_header *head = NULL; + char cfgfile[128]; + + (void)ctxt; + (void)argc; + + len = 8 * HISO_SIZE_1KB; + cmd = (char *)grub_malloc(len + sizeof(wim_header)); + if (!cmd) + { + return 1; + } + + head = (wim_header *)(cmd + len); + grub_env_unset("hiso_pe_wim_path"); + + for (node = g_wim_patch_head; node; node = node->next) + { + find = 0; + for (tmp = g_wim_patch_head; tmp != node; tmp = tmp->next) + { + if (tmp->valid && grub_strcasecmp(tmp->path, node->path) == 0) + { + find = 1; + break; + } + } + + if (find) + { + continue; + } + + g_hiperiso_case_insensitive = 1; + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s%s", args[0], node->path); + g_hiperiso_case_insensitive = 0; + if (!file) + { + debug("File %s%s NOT exist\n", args[0], node->path); + continue; + } + + grub_file_read(file, head, sizeof(wim_header)); + if (grub_memcmp(head->signature, WIM_HEAD_SIGNATURE, sizeof(head->signature))) + { + debug("Not a valid wim file %s\n", (char *)head->signature); + grub_file_close(file); + continue; + } + + if (head->flags & FLAG_HEADER_COMPRESS_LZMS) + { + debug("LZMS compress is not supported 0x%x\n", head->flags); + grub_file_close(file); + continue; + } + + grub_file_close(file); + node->valid = 1; + + hiso_len_ssprintf(cmd, pos, len, "menuentry \"%s\" --class=\"sel_wim\" {\n echo \"\"\n}\n", node->path); + } + + if (pos > 0) + { + g_hiperiso_menu_esc = 1; + g_hiperiso_suppress_esc = 1; + g_hiperiso_suppress_esc_default = 0; + g_hiperiso_secondary_menu_on = 1; + + grub_snprintf(cfgfile, sizeof(cfgfile), "configfile mem:0x%llx:size:%d", (ulonglong)(ulong)cmd, pos); + grub_script_execute_sourcecode(cfgfile); + + g_hiperiso_menu_esc = 0; + g_hiperiso_suppress_esc = 0; + g_hiperiso_suppress_esc_default = 1; + g_hiperiso_secondary_menu_on = 0; + + for (node = g_wim_patch_head; node; node = node->next) + { + if (node->valid) + { + if (i == g_hiperiso_last_entry) + { + grub_env_set("hiso_pe_wim_path", node->path); + break; + } + i++; + } + } + } + + grub_free(cmd); + return 0; +} + +grub_err_t hiperiso_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 = hiperiso_get_windows_rtdata_len(args[1], &dataflag); + + while (node) + { + node->wim_data.windata_flag = dataflag; + if (0 == hiperiso_wimdows_locate_wim(args[0], node, datalen)) + { + node->valid = 1; + g_wim_valid_patch_count++; + } + + node = node->next; + } + + return 0; +} + +static grub_uint32_t hiperiso_get_override_chunk_num(void) +{ + grub_uint32_t chunk_num = 0; + + if (g_iso_fs_type == 0) + { + /* ISO9660: */ + /* per wim */ + /* 1: file_size and file_offset */ + /* 2: new wim file header */ + chunk_num = g_wim_valid_patch_count * 2; + } + else + { + /* UDF: */ + /* global: */ + /* 1: block count in Partition Descriptor */ + + /* per wim */ + /* 1: file_size in file_entry or extend_file_entry */ + /* 2: data_size and position in extend data short ad */ + /* 3: new wim file header */ + chunk_num = g_wim_valid_patch_count * 3 + 1; + } + + if (g_suppress_wincd_override_offset > 0) + { + chunk_num++; + } + + return chunk_num; +} + +static void hiperiso_fill_suppress_wincd_override_data(void *override) +{ + hiperiso_override_chunk *cur = (hiperiso_override_chunk *)override; + + cur->override_size = 4; + cur->img_offset = g_suppress_wincd_override_offset; + grub_memcpy(cur->override_data, &g_suppress_wincd_override_data, cur->override_size); +} + +static void hiperiso_windows_fill_override_data_iso9660( grub_uint64_t isosize, void *override) +{ + grub_uint64_t sector; + grub_uint32_t new_wim_size; + hiperiso_override_chunk *cur; + wim_patch *node = NULL; + wim_tail *wim_data = NULL; + hiperiso_iso9660_override *dirent = NULL; + + sector = (isosize + 2047) / 2048; + + cur = (hiperiso_override_chunk *)override; + + if (g_suppress_wincd_override_offset > 0) + { + hiperiso_fill_suppress_wincd_override_data(cur); + cur++; + } + + debug("hiperiso_windows_fill_override_data_iso9660 %lu\n", (ulong)isosize); + + for (node = g_wim_patch_head; node; node = node->next) + { + wim_data = &node->wim_data; + if (0 == node->valid) + { + continue; + } + + new_wim_size = wim_data->wim_align_size + wim_data->bin_align_len + + wim_data->new_meta_align_len + wim_data->new_lookup_align_len; + + dirent = (hiperiso_iso9660_override *)wim_data->override_data; + + dirent->first_sector = (grub_uint32_t)sector; + dirent->size = new_wim_size; + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size_be = grub_swap_bytes32(dirent->size); + + sector += (new_wim_size / 2048); + + /* override 1: position and length in dirent */ + cur->img_offset = wim_data->override_offset; + cur->override_size = wim_data->override_len; + grub_memcpy(cur->override_data, wim_data->override_data, cur->override_size); + cur++; + + /* override 2: new wim file header */ + cur->img_offset = wim_data->file_offset; + cur->override_size = sizeof(wim_header); + grub_memcpy(cur->override_data, &(wim_data->wim_header), cur->override_size); + cur++; + } + + return; +} + +static int hiperiso_windows_fill_udf_short_ad(grub_file_t isofile, grub_uint32_t curpos, + wim_tail *wim_data, grub_uint32_t new_wim_size) +{ + int i; + grub_uint32_t total = 0; + grub_uint32_t left_size = 0; + hiperiso_udf_override *udf = NULL; + hiperiso_udf_override tmp[4]; + + grub_memset(tmp, 0, sizeof(tmp)); + grub_file_seek(isofile, wim_data->override_offset); + grub_file_read(isofile, tmp, sizeof(tmp)); + + left_size = new_wim_size; + udf = (hiperiso_udf_override *)wim_data->override_data; + + for (i = 0; i < 4; i++) + { + total += tmp[i].length; + if (total >= wim_data->wim_raw_size) + { + udf->length = left_size; + udf->position = curpos; + return 0; + } + else + { + udf->length = tmp[i].length; + udf->position = curpos; + } + + left_size -= tmp[i].length; + curpos += udf->length / 2048; + udf++; + wim_data->override_len += sizeof(hiperiso_udf_override); + } + + debug("######## Too many udf ad ######\n"); + return 1; +} + +static void hiperiso_windows_fill_override_data_udf(grub_file_t isofile, void *override) +{ + grub_uint32_t data32; + grub_uint64_t data64; + grub_uint64_t sector; + grub_uint32_t new_wim_size; + grub_uint64_t total_wim_size = 0; + grub_uint32_t udf_start_block = 0; + hiperiso_override_chunk *cur; + wim_patch *node = NULL; + wim_tail *wim_data = NULL; + + sector = (isofile->size + 2047) / 2048; + + cur = (hiperiso_override_chunk *)override; + + if (g_suppress_wincd_override_offset > 0) + { + hiperiso_fill_suppress_wincd_override_data(cur); + cur++; + } + + debug("hiperiso_windows_fill_override_data_udf %lu\n", (ulong)isofile->size); + + for (node = g_wim_patch_head; node; node = node->next) + { + wim_data = &node->wim_data; + if (node->valid) + { + if (udf_start_block == 0) + { + udf_start_block = wim_data->udf_start_block; + } + new_wim_size = wim_data->wim_align_size + wim_data->bin_align_len + + wim_data->new_meta_align_len + wim_data->new_lookup_align_len; + total_wim_size += new_wim_size; + } + } + + //override 1: sector number in pd data + cur->img_offset = grub_udf_get_last_pd_size_offset(); + cur->override_size = 4; + data32 = sector - udf_start_block + (total_wim_size / 2048); + grub_memcpy(cur->override_data, &(data32), 4); + + for (node = g_wim_patch_head; node; node = node->next) + { + wim_data = &node->wim_data; + if (0 == node->valid) + { + continue; + } + + new_wim_size = wim_data->wim_align_size + wim_data->bin_align_len + + wim_data->new_meta_align_len + wim_data->new_lookup_align_len; + + //override 2: filesize in file_entry + cur++; + cur->img_offset = wim_data->fe_entry_size_offset; + cur->override_size = 8; + data64 = new_wim_size; + grub_memcpy(cur->override_data, &(data64), 8); + + /* override 3: position and length in extend data */ + hiperiso_windows_fill_udf_short_ad(isofile, (grub_uint32_t)sector - udf_start_block, wim_data, new_wim_size); + + sector += (new_wim_size / 2048); + + cur++; + cur->img_offset = wim_data->override_offset; + cur->override_size = wim_data->override_len; + grub_memcpy(cur->override_data, wim_data->override_data, cur->override_size); + + /* override 4: new wim file header */ + cur++; + cur->img_offset = wim_data->file_offset; + cur->override_size = sizeof(wim_header); + grub_memcpy(cur->override_data, &(wim_data->wim_header), cur->override_size); + } + + return; +} + +static grub_uint32_t hiperiso_windows_get_virt_data_size(void) +{ + grub_uint32_t size = 0; + wim_tail *wim_data = NULL; + wim_patch *node = g_wim_patch_head; + + while (node) + { + if (node->valid) + { + wim_data = &node->wim_data; + size += sizeof(hiperiso_virt_chunk) + wim_data->bin_align_len + + wim_data->new_meta_align_len + wim_data->new_lookup_align_len; + } + node = node->next; + } + + return size; +} + +static void hiperiso_windows_fill_virt_data( grub_uint64_t isosize, hiperiso_chain_head *chain) +{ + grub_uint64_t sector; + grub_uint32_t offset; + grub_uint32_t wim_secs; + grub_uint32_t mem_secs; + char *override = NULL; + hiperiso_virt_chunk *cur = NULL; + wim_tail *wim_data = NULL; + wim_patch *node = NULL; + + sector = (isosize + 2047) / 2048; + offset = sizeof(hiperiso_virt_chunk) * g_wim_valid_patch_count; + + override = (char *)chain + chain->virt_chunk_offset; + cur = (hiperiso_virt_chunk *)override; + + for (node = g_wim_patch_head; node; node = node->next) + { + if (0 == node->valid) + { + continue; + } + + wim_data = &node->wim_data; + + wim_secs = wim_data->wim_align_size / 2048; + mem_secs = (wim_data->bin_align_len + wim_data->new_meta_align_len + wim_data->new_lookup_align_len) / 2048; + + cur->remap_sector_start = sector; + cur->remap_sector_end = cur->remap_sector_start + wim_secs; + cur->org_sector_start = (grub_uint32_t)(wim_data->file_offset / 2048); + + cur->mem_sector_start = cur->remap_sector_end; + cur->mem_sector_end = cur->mem_sector_start + mem_secs; + cur->mem_sector_offset = offset; + + sector += wim_secs + mem_secs; + cur++; + + grub_memcpy(override + offset, wim_data->jump_bin_data, wim_data->bin_raw_len); + offset += wim_data->bin_align_len; + + grub_memcpy(override + offset, wim_data->new_meta_data, wim_data->new_meta_len); + offset += wim_data->new_meta_align_len; + + grub_memcpy(override + offset, wim_data->new_lookup_data, wim_data->new_lookup_len); + offset += wim_data->new_lookup_align_len; + + chain->virt_img_size_in_bytes += wim_data->wim_align_size + + wim_data->bin_align_len + + wim_data->new_meta_align_len + + wim_data->new_lookup_align_len; + } + + return; +} + +static int hiperiso_windows_drive_map(hiperiso_chain_head *chain, int vlnk) +{ + int hd1 = 0; + grub_disk_t disk; + + debug("drive map begin <%p> <%d> ...\n", chain, vlnk); + + disk = grub_disk_open("hd1"); + if (disk) + { + grub_disk_close(disk); + hd1 = 1; + debug("BIOS hd1 exist\n"); + } + else + { + debug("failed to open disk %s\n", "hd1"); + } + + if (vlnk) + { + if (g_hiperiso_disk_bios_id == 0x80 && hd1) + { + debug("drive map needed vlnk %p\n", disk); + chain->drive_map = 0x81; + } + } + else if (chain->disk_drive == 0x80) + { + if (hd1) + { + debug("drive map needed normal %p\n", disk); + chain->drive_map = 0x81; + } + } + else + { + debug("no need to map 0x%x\n", chain->disk_drive); + } + + return 0; +} + +static int hiperiso_suppress_windows_cd_prompt(void) +{ + int rc = 1; + const char *cdprompt = NULL; + grub_uint64_t readpos = 0; + grub_file_t file = NULL; + grub_uint8_t data[32]; + + cdprompt = hiperiso_get_env("HISO_WINDOWS_CD_PROMPT"); + if (cdprompt && cdprompt[0] == '1' && cdprompt[1] == 0) + { + debug("HISO_WINDOWS_CD_PROMPT:<%s>\n", cdprompt); + return 0; + } + + g_hiperiso_case_insensitive = 1; + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s/boot/bootfix.bin", "(loop)"); + g_hiperiso_case_insensitive = 0; + + if (!file) + { + debug("Failed to open %s\n", "bootfix.bin"); + goto end; + } + + grub_file_read(file, data, 32); + + if (file->fs && file->fs->name && grub_strcmp(file->fs->name, "udf") == 0) + { + readpos = grub_udf_get_file_offset(file); + } + else + { + readpos = grub_iso9660_get_last_read_pos(file); + } + + debug("bootfix.bin readpos:%lu (sector:%lu) data: %02x %02x %02x %02x\n", + (ulong)readpos, (ulong)readpos / 2048, data[24], data[25], data[26], data[27]); + + if (*(grub_uint32_t *)(data + 24) == 0x13cd0080) + { + g_suppress_wincd_override_offset = readpos + 24; + g_suppress_wincd_override_data = 0x13cd00fd; + + rc = 0; + } + + debug("g_suppress_wincd_override_offset:%lu\n", (ulong)g_suppress_wincd_override_offset); + +end: + check_free(file, grub_file_close); + + return rc; +} + +static int hiperiso_extract_init_exe(char *wimfile, grub_uint8_t **pexe_data, grub_uint32_t *pexe_len, char *exe_name) +{ + int rc; + int ret = 1; + grub_uint16_t i; + grub_file_t file = NULL; + grub_uint32_t exe_len = 0; + wim_header *head = NULL; + grub_uint16_t *uname = NULL; + grub_uint8_t *exe_data = NULL; + grub_uint8_t *decompress_data = NULL; + wim_lookup_entry *lookup = NULL; + wim_security_header *security = NULL; + wim_directory_entry *rootdir = NULL; + wim_directory_entry *search = NULL; + wim_stream_entry *stream = NULL; + wim_lookup_entry *replace_look = NULL; + wim_header wimhdr; + wim_hash hashdata; + + head = &wimhdr; + + file = grub_file_open(wimfile, HIPERISO_FILE_TYPE); + if (!file) + { + goto out; + } + + grub_file_read(file, head, sizeof(wim_header)); + rc = hiperiso_read_resource(file, head, &head->metadata, (void **)&decompress_data); + if (rc) + { + grub_printf("failed to read meta data %d\n", rc); + goto out; + } + + security = (wim_security_header *)decompress_data; + if (security->len > 0) + { + rootdir = (wim_directory_entry *)(decompress_data + ((security->len + 7) & 0xFFFFFFF8U)); + } + else + { + rootdir = (wim_directory_entry *)(decompress_data + 8); + } + + debug("read lookup offset:%llu size:%llu\n", (ulonglong)head->lookup.offset, (ulonglong)head->lookup.raw_size); + lookup = grub_malloc(head->lookup.raw_size); + grub_file_seek(file, head->lookup.offset); + grub_file_read(file, lookup, head->lookup.raw_size); + + /* search winpeshl.exe dirent entry */ + search = search_replace_wim_dirent(file, head, lookup, decompress_data, rootdir); + if (!search) + { + debug("Failed to find replace file %p\n", search); + goto out; + } + + uname = (grub_uint16_t *)(search + 1); + for (i = 0; i < search->name_len / 2 && i < 200; i++) + { + exe_name[i] = (char)uname[i]; + } + exe_name[i] = 0; + debug("find replace file at %p <%s>\n", search, exe_name); + + grub_memset(&hashdata, 0, sizeof(wim_hash)); + if (grub_memcmp(&hashdata, search->hash.sha1, sizeof(wim_hash)) == 0) + { + debug("search hash all 0, now do deep search\n"); + stream = (wim_stream_entry *)((char *)search + search->len); + for (i = 0; i < search->streams; i++) + { + if (stream->name_len == 0) + { + grub_memcpy(&hashdata, stream->hash.sha1, sizeof(wim_hash)); + debug("new search hash: %02x %02x %02x %02x %02x %02x %02x %02x\n", + hiperiso_varg_8(hashdata.sha1)); + break; + } + stream = (wim_stream_entry *)((char *)stream + stream->len); + } + } + else + { + grub_memcpy(&hashdata, search->hash.sha1, sizeof(wim_hash)); + } + + /* find and extact winpeshl.exe */ + replace_look = hiperiso_find_look_entry(head, lookup, &hashdata); + if (replace_look) + { + exe_len = (grub_uint32_t)replace_look->resource.raw_size; + debug("find replace lookup entry_id:%ld raw_size:%u\n", + ((long)replace_look - (long)lookup) / sizeof(wim_lookup_entry), exe_len); + + if (0 != hiperiso_read_resource(file, head, &(replace_look->resource), (void **)&(exe_data))) + { + exe_len = 0; + exe_data = NULL; + debug("failed to read replace file meta data %u\n", exe_len); + } + } + else + { + debug("failed to find lookup entry for replace file %02x %02x %02x %02x\n", + hiperiso_varg_4(hashdata.sha1)); + } + + if (exe_data) + { + ret = 0; + *pexe_data = exe_data; + *pexe_len = exe_len; + } + +out: + + grub_check_free(lookup); + grub_check_free(decompress_data); + check_free(file, grub_file_close); + + return ret; +} + +grub_err_t hiperiso_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int rc = 0; + int wim64 = 0; + int datalen = 0; + int dataflag = 0; + grub_uint32_t exe_len = 0; + grub_uint32_t jump_align = 0; + const char *addr = NULL; + hiperiso_chain_head *chain = NULL; + grub_uint8_t *param = NULL; + grub_uint8_t *exe_data = NULL; + hiperiso_windows_data *rtdata = NULL; + char exename[128] = {0}; + wim_tail wim_data; + + (void)ctxt; + (void)argc; + + addr = grub_env_get("hiso_chain_mem_addr"); + if (!addr) + { + debug("Failed to find hiso_chain_mem_addr\n"); + return 1; + } + + chain = (hiperiso_chain_head *)(void *)grub_strtoul(addr, NULL, 16); + + if (grub_memcmp(&g_hiperiso_guid, &chain->os_param.guid, 16) != 0) + { + debug("os_param.guid not match\n"); + return 1; + } + + datalen = hiperiso_get_windows_rtdata_len(chain->os_param.hiso_img_path, &dataflag); + + rc = hiperiso_extract_init_exe(args[0], &exe_data, &exe_len, exename); + if (rc) + { + return 1; + } + wim64 = hiperiso_is_pe64(exe_data); + + grub_memset(&wim_data, 0, sizeof(wim_data)); + hiperiso_cat_exe_file_data(&wim_data, exe_len, exe_data, datalen); + grub_check_free(exe_data); + + jump_align = hiperiso_align(wim_data.jump_exe_len, 16); + param = wim_data.jump_bin_data; + + grub_memcpy(param + jump_align, &chain->os_param, sizeof(hiperiso_os_param)); + + rtdata = (hiperiso_windows_data *)(param + jump_align + sizeof(hiperiso_os_param)); + hiperiso_fill_windows_rtdata(rtdata, chain->os_param.hiso_img_path, dataflag); + + hiperiso_memfile_env_set("hiso_wimboot_mem", param, (ulonglong)(wim_data.bin_align_len)); + + grub_env_set(args[1], exename); + grub_env_set(args[2], wim64 ? "64" : "32"); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int unknown_image = 0; + int hiperiso_compatible = 0; + grub_uint32_t size = 0; + grub_uint64_t isosize = 0; + grub_uint32_t boot_catlog = 0; + grub_uint32_t img_chunk_size = 0; + grub_uint32_t override_size = 0; + grub_uint32_t virt_chunk_size = 0; + grub_file_t file; + grub_disk_t disk; + const char *pLastChain = NULL; + const char *compatible; + hiperiso_chain_head *chain; + + (void)ctxt; + (void)argc; + + debug("chain data begin <%s> ...\n", args[0]); + + compatible = grub_env_get("hiperiso_compatible"); + if (compatible && compatible[0] == 'Y') + { + hiperiso_compatible = 1; + } + + if (NULL == g_img_chunk_list.chunk) + { + grub_printf("hiperiso not ready\n"); + return 1; + } + + if (0 == hiperiso_compatible && g_wim_valid_patch_count == 0) + { + unknown_image = 1; + if (!g_hiperiso_wimboot_mode) + { + debug("Warning: %s was not recognized by Hiperiso\n", args[0]); + } + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + return 1; + } + + isosize = file->size; + + boot_catlog = hiperiso_get_iso_boot_catlog(file); + if (boot_catlog) + { + if (hiperiso_is_efi_os() && (!hiperiso_has_efi_eltorito(file, boot_catlog))) + { + grub_env_set("LoadIsoEfiDriver", "on"); + } + } + else + { + if (hiperiso_is_efi_os()) + { + grub_env_set("LoadIsoEfiDriver", "on"); + } + else + { + return grub_error(GRUB_ERR_BAD_ARGUMENT, "File %s is not bootable", args[0]); + } + } + + g_suppress_wincd_override_offset = 0; + if (!hiperiso_is_efi_os()) /* legacy mode */ + { + hiperiso_suppress_windows_cd_prompt(); + } + + img_chunk_size = g_img_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + + if (hiperiso_compatible || unknown_image) + { + override_size = g_suppress_wincd_override_offset > 0 ? sizeof(hiperiso_override_chunk) : 0; + size = sizeof(hiperiso_chain_head) + img_chunk_size + override_size; + } + else + { + override_size = hiperiso_get_override_chunk_num() * sizeof(hiperiso_override_chunk); + virt_chunk_size = hiperiso_windows_get_virt_data_size(); + size = sizeof(hiperiso_chain_head) + img_chunk_size + override_size + virt_chunk_size; + } + + pLastChain = grub_env_get("hiso_chain_mem_addr"); + if (pLastChain) + { + chain = (hiperiso_chain_head *)grub_strtoul(pLastChain, NULL, 16); + if (chain) + { + debug("free last chain memory %p\n", chain); + grub_free(chain); + } + } + + chain = hiperiso_alloc_chain(size); + if (!chain) + { + grub_printf("Failed to alloc chain win1 memory size %u\n", size); + grub_file_close(file); + return 1; + } + + hiperiso_memfile_env_set("hiso_chain_mem", chain, (ulonglong)size); + + grub_memset(chain, 0, sizeof(hiperiso_chain_head)); + + /* part 1: os parameter */ + g_hiperiso_chain_type = hiperiso_chain_windows; + hiperiso_fill_os_param(file, &(chain->os_param)); + + if (0 == unknown_image) + { + hiperiso_update_before_chain(&(chain->os_param), args[0]); + } + + /* part 2: chain head */ + disk = file->device->disk; + chain->disk_drive = disk->id; + chain->disk_sector_size = (1 << disk->log_sector_size); + chain->real_img_size_in_bytes = file->size; + chain->virt_img_size_in_bytes = (file->size + 2047) / 2048 * 2048; + chain->boot_catalog = boot_catlog; + + if (!hiperiso_is_efi_os()) + { + grub_file_seek(file, boot_catlog * 2048); + grub_file_read(file, chain->boot_catalog_sector, sizeof(chain->boot_catalog_sector)); + } + + /* part 3: image chunk */ + chain->img_chunk_offset = sizeof(hiperiso_chain_head); + chain->img_chunk_num = g_img_chunk_list.cur_chunk; + grub_memcpy((char *)chain + chain->img_chunk_offset, g_img_chunk_list.chunk, img_chunk_size); + + if (hiperiso_compatible || unknown_image) + { + if (g_suppress_wincd_override_offset > 0) + { + chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size; + chain->override_chunk_num = 1; + hiperiso_fill_suppress_wincd_override_data((char *)chain + chain->override_chunk_offset); + } + + return 0; + } + + if (0 == g_wim_valid_patch_count) + { + return 0; + } + + /* part 4: override chunk */ + chain->override_chunk_offset = chain->img_chunk_offset + img_chunk_size; + chain->override_chunk_num = hiperiso_get_override_chunk_num(); + + if (g_iso_fs_type == 0) + { + hiperiso_windows_fill_override_data_iso9660(isosize, (char *)chain + chain->override_chunk_offset); + } + else + { + hiperiso_windows_fill_override_data_udf(file, (char *)chain + chain->override_chunk_offset); + } + + /* part 5: virt chunk */ + chain->virt_chunk_offset = chain->override_chunk_offset + override_size; + chain->virt_chunk_num = g_wim_valid_patch_count; + hiperiso_windows_fill_virt_data(isosize, chain); + + if (hiperiso_is_efi_os() == 0) + { + hiperiso_windows_drive_map(chain, file->vlnk); + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_uint32_t hiperiso_get_wim_iso_offset(const char *filepath) +{ + grub_uint32_t imgoffset; + grub_file_t file; + char cmdbuf[128]; + + grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback wimiso \"%s\"", filepath); + grub_script_execute_sourcecode(cmdbuf); + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", "(wimiso)/boot/boot.wim"); + if (!file) + { + grub_printf("Failed to open boot.wim file in the image file\n"); + return 0; + } + + imgoffset = (grub_uint32_t)grub_iso9660_get_last_file_dirent_pos(file) + 2; + + debug("wimiso wim direct offset: %u\n", imgoffset); + + grub_file_close(file); + + grub_script_execute_sourcecode("loopback -d wimiso"); + + return imgoffset; +} + +static int hiperiso_get_wim_chunklist(grub_file_t wimfile, hiperiso_img_chunk_list *wimchunk) +{ + grub_memset(wimchunk, 0, sizeof(hiperiso_img_chunk_list)); + wimchunk->chunk = grub_malloc(sizeof(hiperiso_img_chunk) * DEFAULT_CHUNK_NUM); + if (NULL == wimchunk->chunk) + { + return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Can't allocate image chunk memoty\n"); + } + + wimchunk->max_chunk = DEFAULT_CHUNK_NUM; + wimchunk->cur_chunk = 0; + + hiperiso_get_block_list(wimfile, wimchunk, wimfile->device->disk->partition->start); + + return 0; +} + +grub_err_t hiperiso_cmd_is_standard_winiso(grub_extcmd_context_t ctxt, int argc, char **args) +{ + int i; + int ret = 1; + char prefix[32] = {0}; + const char *chkfile[] = + { + "boot/bcd", "boot/boot.sdi", NULL + }; + + (void)ctxt; + (void)argc; + + if (hiperiso_check_file_exist("%s/sources/boot.wim", args[0])) + { + prefix[0] = 0; + } + else if (hiperiso_check_file_exist("%s/x86/sources/boot.wim", args[0])) + { + grub_snprintf(prefix, sizeof(prefix), "/x86"); + } + else if (hiperiso_check_file_exist("%s/x64/sources/boot.wim", args[0])) + { + grub_snprintf(prefix, sizeof(prefix), "/x64"); + } + else + { + debug("No boot.wim found.\n"); + goto out; + } + + for (i = 0; chkfile[i]; i++) + { + if (!hiperiso_check_file_exist("%s%s/%s", args[0], prefix, chkfile[i])) + { + debug("%s not found.\n", chkfile[i]); + goto out; + } + } + + if ((!hiperiso_check_file_exist("%s%s/sources/install.wim", args[0], prefix)) && + (!hiperiso_check_file_exist("%s%s/sources/install.esd", args[0], prefix))) + { + debug("No install.wim(esd) found.\n"); + goto out; + } + + if (!hiperiso_check_file_exist("%s/setup.exe", args[0])) + { + debug("No setup.exe found.\n"); + goto out; + } + + ret = 0; + debug("This is standard Windows ISO.\n"); + +out: + + return ret; +} + +grub_err_t hiperiso_cmd_wim_check_bootable(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_uint32_t boot_index; + grub_file_t file = NULL; + wim_header *wimhdr = NULL; + + (void)ctxt; + (void)argc; + + wimhdr = grub_zalloc(sizeof(wim_header)); + if (!wimhdr) + { + return 1; + } + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", args[0]); + if (!file) + { + grub_free(wimhdr); + return 1; + } + + grub_file_read(file, wimhdr, sizeof(wim_header)); + grub_file_close(file); + boot_index = wimhdr->boot_index; + grub_free(wimhdr); + + if (boot_index == 0) + { + return 1; + } + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_vlnk_wim_chain_data(grub_file_t wimfile) +{ + grub_uint32_t i = 0; + grub_uint32_t imgoffset = 0; + grub_uint32_t size = 0; + grub_uint32_t isosector = 0; + grub_uint64_t wimsize = 0; + grub_uint32_t boot_catlog = 0; + grub_uint32_t img_chunk1_size = 0; + grub_uint32_t img_chunk2_size = 0; + grub_uint32_t override_size = 0; + grub_file_t file; + grub_disk_t disk; + const char *pLastChain = NULL; + hiperiso_chain_head *chain; + hiperiso_iso9660_override *dirent; + hiperiso_img_chunk *chunknode; + hiperiso_override_chunk *override; + hiperiso_img_chunk_list wimchunk; + + debug("vlnk wim chain data begin <%s> ...\n", wimfile->name); + + if (NULL == g_wimiso_chunk_list.chunk || NULL == g_wimiso_path) + { + grub_printf("hiperiso not ready\n"); + return 1; + } + + imgoffset = hiperiso_get_wim_iso_offset(g_wimiso_path); + if (imgoffset == 0) + { + grub_printf("image offset not found\n"); + return 1; + } + + if (0 != hiperiso_get_wim_chunklist(wimfile, &wimchunk)) + { + grub_printf("Failed to get wim chunklist\n"); + return 1; + } + wimsize = wimfile->size; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", g_wimiso_path); + if (!file) + { + return 1; + } + + boot_catlog = hiperiso_get_iso_boot_catlog(file); + + img_chunk1_size = g_wimiso_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + img_chunk2_size = wimchunk.cur_chunk * sizeof(hiperiso_img_chunk); + override_size = sizeof(hiperiso_override_chunk) + g_wimiso_size; + + size = sizeof(hiperiso_chain_head) + img_chunk1_size + img_chunk2_size + override_size; + + pLastChain = grub_env_get("hiso_chain_mem_addr"); + if (pLastChain) + { + chain = (hiperiso_chain_head *)grub_strtoul(pLastChain, NULL, 16); + if (chain) + { + debug("free last chain memory %p\n", chain); + grub_free(chain); + } + } + + chain = hiperiso_alloc_chain(size); + if (!chain) + { + grub_printf("Failed to alloc chain win2 memory size %u\n", size); + grub_file_close(file); + return 1; + } + + hiperiso_memfile_env_set("hiso_chain_mem", chain, (ulonglong)size); + + grub_memset(chain, 0, sizeof(hiperiso_chain_head)); + + /* part 1: os parameter */ + g_hiperiso_chain_type = hiperiso_chain_wim; + hiperiso_fill_os_param(wimfile, &(chain->os_param)); + + /* part 2: chain head */ + disk = wimfile->device->disk; + chain->disk_drive = disk->id; + chain->disk_sector_size = (1 << disk->log_sector_size); + chain->real_img_size_in_bytes = hiperiso_align_2k(file->size) + hiperiso_align_2k(wimsize); + chain->virt_img_size_in_bytes = chain->real_img_size_in_bytes; + chain->boot_catalog = boot_catlog; + + if (!hiperiso_is_efi_os()) + { + grub_file_seek(file, boot_catlog * 2048); + grub_file_read(file, chain->boot_catalog_sector, sizeof(chain->boot_catalog_sector)); + } + + /* part 3: image chunk */ + chain->img_chunk_offset = sizeof(hiperiso_chain_head); + chain->img_chunk_num = g_wimiso_chunk_list.cur_chunk + wimchunk.cur_chunk; + grub_memcpy((char *)chain + chain->img_chunk_offset, g_wimiso_chunk_list.chunk, img_chunk1_size); + + chunknode = (hiperiso_img_chunk *)((char *)chain + chain->img_chunk_offset); + for (i = 0; i < g_wimiso_chunk_list.cur_chunk; i++) + { + chunknode->disk_end_sector = chunknode->disk_end_sector - chunknode->disk_start_sector; + chunknode->disk_start_sector = 0; + chunknode++; + } + + /* fs cluster size >= 2048, so don't need to proc align */ + + /* align by 2048 */ + chunknode = wimchunk.chunk + wimchunk.cur_chunk - 1; + i = (chunknode->disk_end_sector + 1 - chunknode->disk_start_sector) % 4; + if (i) + { + chunknode->disk_end_sector += 4 - i; + } + + isosector = (grub_uint32_t)((file->size + 2047) / 2048); + for (i = 0; i < wimchunk.cur_chunk; i++) + { + chunknode = wimchunk.chunk + i; + chunknode->img_start_sector = isosector; + chunknode->img_end_sector = chunknode->img_start_sector + + ((chunknode->disk_end_sector + 1 - chunknode->disk_start_sector) / 4) - 1; + isosector = chunknode->img_end_sector + 1; + } + + grub_memcpy((char *)chain + chain->img_chunk_offset + img_chunk1_size, wimchunk.chunk, img_chunk2_size); + + /* part 4: override chunk */ + chain->override_chunk_offset = chain->img_chunk_offset + img_chunk1_size + img_chunk2_size; + chain->override_chunk_num = 1; + + override = (hiperiso_override_chunk *)((char *)chain + chain->override_chunk_offset); + override->img_offset = 0; + override->override_size = g_wimiso_size; + + grub_file_seek(file, 0); + grub_file_read(file, override->override_data, file->size); + + dirent = (hiperiso_iso9660_override *)(override->override_data + imgoffset); + dirent->first_sector = (grub_uint32_t)((file->size + 2047) / 2048); + dirent->size = (grub_uint32_t)(wimsize); + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size_be = grub_swap_bytes32(dirent->size); + + debug("imgoffset=%u first_sector=0x%x size=0x%x\n", imgoffset, dirent->first_sector, dirent->size); + + if (hiperiso_is_efi_os() == 0) + { + hiperiso_windows_drive_map(chain, 0); + } + + grub_file_close(file); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +static grub_err_t hiperiso_normal_wim_chain_data(grub_file_t wimfile) +{ + grub_uint32_t i = 0; + grub_uint32_t imgoffset = 0; + grub_uint32_t size = 0; + grub_uint32_t isosector = 0; + grub_uint64_t wimsize = 0; + grub_uint32_t boot_catlog = 0; + grub_uint32_t img_chunk1_size = 0; + grub_uint32_t img_chunk2_size = 0; + grub_uint32_t override_size = 0; + grub_file_t file; + grub_disk_t disk; + const char *pLastChain = NULL; + hiperiso_chain_head *chain; + hiperiso_iso9660_override *dirent; + hiperiso_img_chunk *chunknode; + hiperiso_override_chunk *override; + hiperiso_img_chunk_list wimchunk; + + debug("normal wim chain data begin <%s> ...\n", wimfile->name); + + if (NULL == g_wimiso_chunk_list.chunk || NULL == g_wimiso_path) + { + grub_printf("hiperiso not ready\n"); + return 1; + } + + imgoffset = hiperiso_get_wim_iso_offset(g_wimiso_path); + if (imgoffset == 0) + { + grub_printf("image offset not found\n"); + return 1; + } + + if (0 != hiperiso_get_wim_chunklist(wimfile, &wimchunk)) + { + grub_printf("Failed to get wim chunklist\n"); + return 1; + } + wimsize = wimfile->size; + + file = hiperiso_grub_file_open(HIPERISO_FILE_TYPE, "%s", g_wimiso_path); + if (!file) + { + return 1; + } + + boot_catlog = hiperiso_get_iso_boot_catlog(file); + + img_chunk1_size = g_wimiso_chunk_list.cur_chunk * sizeof(hiperiso_img_chunk); + img_chunk2_size = wimchunk.cur_chunk * sizeof(hiperiso_img_chunk); + override_size = sizeof(hiperiso_override_chunk); + + size = sizeof(hiperiso_chain_head) + img_chunk1_size + img_chunk2_size + override_size; + + pLastChain = grub_env_get("hiso_chain_mem_addr"); + if (pLastChain) + { + chain = (hiperiso_chain_head *)grub_strtoul(pLastChain, NULL, 16); + if (chain) + { + debug("free last chain memory %p\n", chain); + grub_free(chain); + } + } + + chain = hiperiso_alloc_chain(size); + if (!chain) + { + grub_printf("Failed to alloc chain win3 memory size %u\n", size); + grub_file_close(file); + return 1; + } + + hiperiso_memfile_env_set("hiso_chain_mem", chain, (ulonglong)size); + + grub_memset(chain, 0, sizeof(hiperiso_chain_head)); + + /* part 1: os parameter */ + g_hiperiso_chain_type = hiperiso_chain_wim; + hiperiso_fill_os_param(file, &(chain->os_param)); + + /* part 2: chain head */ + disk = file->device->disk; + chain->disk_drive = disk->id; + chain->disk_sector_size = (1 << disk->log_sector_size); + chain->real_img_size_in_bytes = hiperiso_align_2k(file->size) + hiperiso_align_2k(wimsize); + chain->virt_img_size_in_bytes = chain->real_img_size_in_bytes; + chain->boot_catalog = boot_catlog; + + if (!hiperiso_is_efi_os()) + { + grub_file_seek(file, boot_catlog * 2048); + grub_file_read(file, chain->boot_catalog_sector, sizeof(chain->boot_catalog_sector)); + } + + /* part 3: image chunk */ + chain->img_chunk_offset = sizeof(hiperiso_chain_head); + chain->img_chunk_num = g_wimiso_chunk_list.cur_chunk + wimchunk.cur_chunk; + grub_memcpy((char *)chain + chain->img_chunk_offset, g_wimiso_chunk_list.chunk, img_chunk1_size); + + /* fs cluster size >= 2048, so don't need to proc align */ + + /* align by 2048 */ + chunknode = wimchunk.chunk + wimchunk.cur_chunk - 1; + i = (chunknode->disk_end_sector + 1 - chunknode->disk_start_sector) % 4; + if (i) + { + chunknode->disk_end_sector += 4 - i; + } + + isosector = (grub_uint32_t)((file->size + 2047) / 2048); + for (i = 0; i < wimchunk.cur_chunk; i++) + { + chunknode = wimchunk.chunk + i; + chunknode->img_start_sector = isosector; + chunknode->img_end_sector = chunknode->img_start_sector + + ((chunknode->disk_end_sector + 1 - chunknode->disk_start_sector) / 4) - 1; + isosector = chunknode->img_end_sector + 1; + } + + grub_memcpy((char *)chain + chain->img_chunk_offset + img_chunk1_size, wimchunk.chunk, img_chunk2_size); + + /* part 4: override chunk */ + chain->override_chunk_offset = chain->img_chunk_offset + img_chunk1_size + img_chunk2_size; + chain->override_chunk_num = 1; + + override = (hiperiso_override_chunk *)((char *)chain + chain->override_chunk_offset); + override->img_offset = imgoffset; + override->override_size = sizeof(hiperiso_iso9660_override); + + dirent = (hiperiso_iso9660_override *)(override->override_data); + dirent->first_sector = (grub_uint32_t)((file->size + 2047) / 2048); + dirent->size = (grub_uint32_t)(wimsize); + dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); + dirent->size_be = grub_swap_bytes32(dirent->size); + + debug("imgoffset=%u first_sector=0x%x size=0x%x\n", imgoffset, dirent->first_sector, dirent->size); + + if (hiperiso_is_efi_os() == 0) + { + hiperiso_windows_drive_map(chain, 0); + } + + grub_file_close(file); + + HIPERISO_CMD_RETURN(GRUB_ERR_NONE); +} + +grub_err_t hiperiso_cmd_wim_chain_data(grub_extcmd_context_t ctxt, int argc, char **args) +{ + grub_err_t ret; + grub_file_t wimfile; + + (void)ctxt; + (void)argc; + + wimfile = grub_file_open(args[0], HIPERISO_FILE_TYPE); + if (!wimfile) + { + return 1; + } + + if (wimfile->vlnk) + { + ret = hiperiso_vlnk_wim_chain_data(wimfile); + } + else + { + ret = hiperiso_normal_wim_chain_data(wimfile); + } + + grub_file_close(wimfile); + return ret; +} + +int hiperiso_chain_file_size(const char *path) +{ + int size; + grub_file_t file; + + file = grub_file_open(path, HIPERISO_FILE_TYPE); + size = (int)(file->size); + + grub_file_close(file); + + return size; +} + +int hiperiso_chain_file_read(const char *path, int offset, int len, void *buf) +{ + int size; + grub_file_t file; + + file = grub_file_open(path, HIPERISO_FILE_TYPE); + grub_file_seek(file, offset); + size = grub_file_read(file, buf, len); + grub_file_close(file); + + return size; +} + diff --git a/src/grub2/huffman.c b/src/grub2/huffman.c new file mode 100644 index 0000000..1680056 --- /dev/null +++ b/src/grub2/huffman.c @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2014 Michael Brown . + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * @file + * + * Huffman alphabets + * + */ + +#include "wimboot.h" +#include "huffman.h" + +/** + * Transcribe binary value (for debugging) + * + * @v value Value + * @v bits Length of value (in bits) + * @ret string Transcribed value + */ +const char * huffman_bin ( unsigned long value, unsigned int bits ) { + static char buf[ ( 8 * sizeof ( value ) ) + 1 /* NUL */ ]; + char *out = buf; + + /* Sanity check */ + assert ( bits < sizeof ( buf ) ); + + /* Transcribe value */ + while ( bits-- ) + *(out++) = ( ( value & ( 1 << bits ) ) ? '1' : '0' ); + *out = '\0'; + + return buf; +} + +/** + * Dump Huffman alphabet (for debugging) + * + * @v alphabet Huffman alphabet + */ +static void __attribute__ (( unused )) +huffman_dump_alphabet ( struct huffman_alphabet *alphabet ) { + struct huffman_symbols *sym; + unsigned int bits; + unsigned int huf; + unsigned int i; + + (void)huf; + + /* Dump symbol table for each utilised length */ + for ( bits = 1 ; bits <= ( sizeof ( alphabet->huf ) / + sizeof ( alphabet->huf[0] ) ) ; bits++ ) { + sym = &alphabet->huf[ bits - 1 ]; + if ( sym->freq == 0 ) + continue; + huf = ( sym->start >> sym->shift ); + DBG ( "Huffman length %d start \"%s\" freq %d:", bits, + huffman_bin ( huf, sym->bits ), sym->freq ); + for ( i = 0 ; i < sym->freq ; i++ ) { + DBG ( " %03x", sym->raw[ huf + i ] ); + } + DBG ( "\n" ); + } + + /* Dump quick lookup table */ + DBG ( "Huffman quick lookup:" ); + for ( i = 0 ; i < ( sizeof ( alphabet->lookup ) / + sizeof ( alphabet->lookup[0] ) ) ; i++ ) { + DBG ( " %d", ( alphabet->lookup[i] + 1 ) ); + } + DBG ( "\n" ); +} + +/** + * Construct Huffman alphabet + * + * @v alphabet Huffman alphabet + * @v lengths Symbol length table + * @v count Number of symbols + * @ret rc Return status code + */ +int huffman_alphabet ( struct huffman_alphabet *alphabet, + uint8_t *lengths, unsigned int count ) { + struct huffman_symbols *sym; + unsigned int huf; + unsigned int cum_freq; + unsigned int bits; + unsigned int raw; + unsigned int adjustment; + unsigned int prefix; + int empty; + int complete; + + /* Clear symbol table */ + memset ( alphabet->huf, 0, sizeof ( alphabet->huf ) ); + + /* Count number of symbols with each Huffman-coded length */ + empty = 1; + for ( raw = 0 ; raw < count ; raw++ ) { + bits = lengths[raw]; + if ( bits ) { + alphabet->huf[ bits - 1 ].freq++; + empty = 0; + } + } + + /* In the degenerate case of having no symbols (i.e. an unused + * alphabet), generate a trivial alphabet with exactly two + * single-bit codes. This allows callers to avoid having to + * check for this special case. + */ + if ( empty ) + alphabet->huf[0].freq = 2; + + /* Populate Huffman-coded symbol table */ + huf = 0; + cum_freq = 0; + for ( bits = 1 ; bits <= ( sizeof ( alphabet->huf ) / + sizeof ( alphabet->huf[0] ) ) ; bits++ ) { + sym = &alphabet->huf[ bits - 1 ]; + sym->bits = bits; + sym->shift = ( HUFFMAN_BITS - bits ); + sym->start = ( huf << sym->shift ); + sym->raw = &alphabet->raw[cum_freq]; + huf += sym->freq; + if ( huf > ( 1U << bits ) ) { + DBG ( "Huffman alphabet has too many symbols with " + "lengths <=%d\n", bits ); + return -1; + } + huf <<= 1; + cum_freq += sym->freq; + } + complete = ( huf == ( 1U << bits ) ); + + /* Populate raw symbol table */ + for ( raw = 0 ; raw < count ; raw++ ) { + bits = lengths[raw]; + if ( bits ) { + sym = &alphabet->huf[ bits - 1 ]; + *(sym->raw++) = raw; + } + } + + /* Adjust Huffman-coded symbol table raw pointers and populate + * quick lookup table. + */ + for ( bits = 1 ; bits <= ( sizeof ( alphabet->huf ) / + sizeof ( alphabet->huf[0] ) ) ; bits++ ) { + sym = &alphabet->huf[ bits - 1 ]; + + /* Adjust raw pointer */ + sym->raw -= sym->freq; /* Reset to first symbol */ + adjustment = ( sym->start >> sym->shift ); + sym->raw -= adjustment; /* Adjust for quick indexing */ + + /* Populate quick lookup table */ + for ( prefix = ( sym->start >> HUFFMAN_QL_SHIFT ) ; + prefix < ( 1 << HUFFMAN_QL_BITS ) ; prefix++ ) { + alphabet->lookup[prefix] = ( bits - 1 ); + } + } + + /* Check that there are no invalid codes */ + if ( ! complete ) { + DBG ( "Huffman alphabet is incomplete\n" ); + return -1; + } + + return 0; +} + +/** + * Get Huffman symbol set + * + * @v alphabet Huffman alphabet + * @v huf Raw input value (normalised to HUFFMAN_BITS bits) + * @ret sym Huffman symbol set + */ +struct huffman_symbols * huffman_sym ( struct huffman_alphabet *alphabet, + unsigned int huf ) { + struct huffman_symbols *sym; + unsigned int lookup_index; + + /* Find symbol set for this length */ + lookup_index = ( huf >> HUFFMAN_QL_SHIFT ); + sym = &alphabet->huf[ alphabet->lookup[ lookup_index ] ]; + while ( huf < sym->start ) + sym--; + return sym; +} diff --git a/src/grub2/huffman.h b/src/grub2/huffman.h new file mode 100644 index 0000000..95bbae8 --- /dev/null +++ b/src/grub2/huffman.h @@ -0,0 +1,108 @@ +#ifndef _HUFFMAN_H +#define _HUFFMAN_H + +/* + * Copyright (C) 2014 Michael Brown . + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * @file + * + * Huffman alphabets + * + */ + +/** Maximum length of a Huffman symbol (in bits) */ +#define HUFFMAN_BITS 16 + +/** Raw huffman symbol */ +typedef uint16_t huffman_raw_symbol_t; + +/** Quick lookup length for a Huffman symbol (in bits) + * + * This is a policy decision. + */ +#define HUFFMAN_QL_BITS 7 + +/** Quick lookup shift */ +#define HUFFMAN_QL_SHIFT ( HUFFMAN_BITS - HUFFMAN_QL_BITS ) + +/** A Huffman-coded set of symbols of a given length */ +struct huffman_symbols { + /** Length of Huffman-coded symbols (in bits) */ + uint8_t bits; + /** Shift to normalise symbols of this length to HUFFMAN_BITS bits */ + uint8_t shift; + /** Number of Huffman-coded symbols having this length */ + uint16_t freq; + /** First symbol of this length (normalised to HUFFMAN_BITS bits) + * + * Stored as a 32-bit value to allow the value + * (1<bits; +} + +/** + * Get Huffman symbol value + * + * @v sym Huffman symbol set + * @v huf Raw input value (normalised to HUFFMAN_BITS bits) + * @ret raw Raw symbol value + */ +static inline __attribute__ (( always_inline )) huffman_raw_symbol_t +huffman_raw ( struct huffman_symbols *sym, unsigned int huf ) { + + return sym->raw[ huf >> sym->shift ]; +} + +extern int huffman_alphabet ( struct huffman_alphabet *alphabet, + uint8_t *lengths, unsigned int count ); +extern struct huffman_symbols * +huffman_sym ( struct huffman_alphabet *alphabet, unsigned int huf ); + +#endif /* _HUFFMAN_H */ diff --git a/src/grub2/lzx.c b/src/grub2/lzx.c new file mode 100644 index 0000000..732a96f --- /dev/null +++ b/src/grub2/lzx.c @@ -0,0 +1,668 @@ +/* + * Copyright (C) 2014 Michael Brown . + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * @file + * + * LZX decompression + * + * This algorithm is derived jointly from the document "[MS-PATCH]: + * LZX DELTA Compression and Decompression", available from + * + * http://msdn.microsoft.com/en-us/library/cc483133.aspx + * + * and from the file lzx-decompress.c in the wimlib source code. + * + */ + +#include "wimboot.h" +#include "huffman.h" +#include "lzx.h" + +/** Base positions, indexed by position slot */ +static unsigned int lzx_position_base[LZX_POSITION_SLOTS]; + +/** + * Attempt to accumulate bits from LZX bitstream + * + * @v lzx Decompressor + * @v bits Number of bits to accumulate + * @v norm_value Accumulated value (normalised to 16 bits) + * + * Note that there may not be sufficient accumulated bits in the + * bitstream; callers must check that sufficient bits are available + * before using the value. + */ +static int lzx_accumulate ( struct lzx *lzx, unsigned int bits ) { + const uint16_t *src16; + + /* Accumulate more bits if required */ + if ( ( lzx->bits < bits ) && + ( lzx->input.offset < lzx->input.len ) ) { + src16 = (const uint16_t *)( ( char * ) lzx->input.data + lzx->input.offset ); + lzx->input.offset += sizeof ( *src16 ); + lzx->accumulator |= ( *src16 << ( 16 - lzx->bits ) ); + lzx->bits += 16; + } + + return ( lzx->accumulator >> 16 ); +} + +/** + * Consume accumulated bits from LZX bitstream + * + * @v lzx Decompressor + * @v bits Number of bits to consume + * @ret rc Return status code + */ +static int lzx_consume ( struct lzx *lzx, unsigned int bits ) { + + /* Fail if insufficient bits are available */ + if ( lzx->bits < bits ) { + DBG ( "LZX input overrun in %#zx/%#zx out %#zx)\n", + lzx->input.offset, lzx->input.len, lzx->output.offset ); + return -1; + } + + /* Consume bits */ + lzx->accumulator <<= bits; + lzx->bits -= bits; + + return 0; +} + +/** + * Get bits from LZX bitstream + * + * @v lzx Decompressor + * @v bits Number of bits to fetch + * @ret value Value, or negative error + */ +static int lzx_getbits ( struct lzx *lzx, unsigned int bits ) { + int norm_value; + int rc; + + /* Accumulate more bits if required */ + norm_value = lzx_accumulate ( lzx, bits ); + + /* Consume bits */ + if ( ( rc = lzx_consume ( lzx, bits ) ) != 0 ) + return rc; + + return ( norm_value >> ( 16 - bits ) ); +} + +/** + * Align LZX bitstream for byte access + * + * @v lzx Decompressor + * @v bits Minimum number of padding bits + * @ret rc Return status code + */ +static int lzx_align ( struct lzx *lzx, unsigned int bits ) { + int pad; + + /* Get padding bits */ + pad = lzx_getbits ( lzx, bits ); + if ( pad < 0 ) + return pad; + + /* Consume all accumulated bits */ + lzx_consume ( lzx, lzx->bits ); + + return 0; +} + +/** + * Get bytes from LZX bitstream + * + * @v lzx Decompressor + * @v data Data buffer, or NULL + * @v len Length of data buffer + * @ret rc Return status code + */ +static int lzx_getbytes ( struct lzx *lzx, void *data, size_t len ) { + + /* Sanity check */ + if ( ( lzx->input.offset + len ) > lzx->input.len ) { + DBG ( "LZX input overrun in %#zx/%#zx out %#zx)\n", + lzx->input.offset, lzx->input.len, lzx->output.offset ); + return -1; + } + + /* Copy data */ + if ( data ) + memcpy ( data, ( lzx->input.data + lzx->input.offset ), len ); + lzx->input.offset += len; + + return 0; +} + +/** + * Decode LZX Huffman-coded symbol + * + * @v lzx Decompressor + * @v alphabet Huffman alphabet + * @ret raw Raw symbol, or negative error + */ +static int lzx_decode ( struct lzx *lzx, struct huffman_alphabet *alphabet ) { + struct huffman_symbols *sym; + int huf; + int rc; + + /* Accumulate sufficient bits */ + huf = lzx_accumulate ( lzx, HUFFMAN_BITS ); + if ( huf < 0 ) + return huf; + + /* Decode symbol */ + sym = huffman_sym ( alphabet, huf ); + + /* Consume bits */ + if ( ( rc = lzx_consume ( lzx, huffman_len ( sym ) ) ) != 0 ) + return rc; + + return huffman_raw ( sym, huf ); +} + +/** + * Generate Huffman alphabet from raw length table + * + * @v lzx Decompressor + * @v count Number of symbols + * @v bits Length of each length (in bits) + * @v lengths Lengths table to fill in + * @v alphabet Huffman alphabet to fill in + * @ret rc Return status code + */ +static int lzx_raw_alphabet ( struct lzx *lzx, unsigned int count, + unsigned int bits, uint8_t *lengths, + struct huffman_alphabet *alphabet ) { + unsigned int i; + int len; + int rc; + + /* Read lengths */ + for ( i = 0 ; i < count ; i++ ) { + len = lzx_getbits ( lzx, bits ); + if ( len < 0 ) + return len; + lengths[i] = len; + } + + /* Generate Huffman alphabet */ + if ( ( rc = huffman_alphabet ( alphabet, lengths, count ) ) != 0 ) + return rc; + + return 0; +} + +/** + * Generate pretree + * + * @v lzx Decompressor + * @v count Number of symbols + * @v lengths Lengths table to fill in + * @ret rc Return status code + */ +static int lzx_pretree ( struct lzx *lzx, unsigned int count, + uint8_t *lengths ) { + unsigned int i; + unsigned int length; + int dup = 0; + int code; + int rc; + + /* Generate pretree alphabet */ + if ( ( rc = lzx_raw_alphabet ( lzx, LZX_PRETREE_CODES, + LZX_PRETREE_BITS, lzx->pretree_lengths, + &lzx->pretree ) ) != 0 ) + return rc; + + /* Read lengths */ + for ( i = 0 ; i < count ; i++ ) { + + if ( dup ) { + + /* Duplicate previous length */ + lengths[i] = lengths[ i - 1 ]; + dup--; + + } else { + + /* Get next code */ + code = lzx_decode ( lzx, &lzx->pretree ); + if ( code < 0 ) + return code; + + /* Interpret code */ + if ( code <= 16 ) { + length = ( ( lengths[i] - code + 17 ) % 17 ); + } else if ( code == 17 ) { + length = 0; + dup = lzx_getbits ( lzx, 4 ); + if ( dup < 0 ) + return dup; + dup += 3; + } else if ( code == 18 ) { + length = 0; + dup = lzx_getbits ( lzx, 5 ); + if ( dup < 0 ) + return dup; + dup += 19; + } else if ( code == 19 ) { + length = 0; + dup = lzx_getbits ( lzx, 1 ); + if ( dup < 0 ) + return dup; + dup += 3; + code = lzx_decode ( lzx, &lzx->pretree ); + if ( code < 0 ) + return code; + length = ( ( lengths[i] - code + 17 ) % 17 ); + } else { + DBG ( "Unrecognised pretree code %d\n", code ); + return -1; + } + lengths[i] = length; + } + } + + /* Sanity check */ + if ( dup ) { + DBG ( "Pretree duplicate overrun\n" ); + return -1; + } + + return 0; +} + +/** + * Generate aligned offset Huffman alphabet + * + * @v lzx Decompressor + * @ret rc Return status code + */ +static int lzx_alignoffset_alphabet ( struct lzx *lzx ) { + int rc; + + /* Generate aligned offset alphabet */ + if ( ( rc = lzx_raw_alphabet ( lzx, LZX_ALIGNOFFSET_CODES, + LZX_ALIGNOFFSET_BITS, + lzx->alignoffset_lengths, + &lzx->alignoffset ) ) != 0 ) + return rc; + + return 0; +} + +/** + * Generate main Huffman alphabet + * + * @v lzx Decompressor + * @ret rc Return status code + */ +static int lzx_main_alphabet ( struct lzx *lzx ) { + int rc; + + /* Generate literal symbols pretree */ + if ( ( rc = lzx_pretree ( lzx, LZX_MAIN_LIT_CODES, + lzx->main_lengths.literals ) ) != 0 ) { + DBG ( "Could not construct main literal pretree\n" ); + return rc; + } + + /* Generate remaining symbols pretree */ + if ( ( rc = lzx_pretree ( lzx, ( LZX_MAIN_CODES - LZX_MAIN_LIT_CODES ), + lzx->main_lengths.remainder ) ) != 0 ) { + DBG ( "Could not construct main remainder pretree\n" ); + return rc; + } + + /* Generate Huffman alphabet */ + if ( ( rc = huffman_alphabet ( &lzx->main, lzx->main_lengths.literals, + LZX_MAIN_CODES ) ) != 0 ) { + DBG ( "Could not generate main alphabet\n" ); + return rc; + } + + return 0; +} + +/** + * Generate length Huffman alphabet + * + * @v lzx Decompressor + * @ret rc Return status code + */ +static int lzx_length_alphabet ( struct lzx *lzx ) { + int rc; + + /* Generate pretree */ + if ( ( rc = lzx_pretree ( lzx, LZX_LENGTH_CODES, + lzx->length_lengths ) ) != 0 ) { + DBG ( "Could not generate length pretree\n" ); + return rc; + } + + /* Generate Huffman alphabet */ + if ( ( rc = huffman_alphabet ( &lzx->length, lzx->length_lengths, + LZX_LENGTH_CODES ) ) != 0 ) { + DBG ( "Could not generate length alphabet\n" ); + return rc; + } + + return 0; +} + +/** + * Process LZX block header + * + * @v lzx Decompressor + * @ret rc Return status code + */ +static int lzx_block_header ( struct lzx *lzx ) { + size_t block_len; + int block_type; + int default_len; + int len_high; + int len_low; + int rc; + + /* Get block type */ + block_type = lzx_getbits ( lzx, LZX_BLOCK_TYPE_BITS ); + if ( block_type < 0 ) + return block_type; + lzx->block_type = block_type; + + /* Check block length */ + default_len = lzx_getbits ( lzx, 1 ); + if ( default_len < 0 ) + return default_len; + if ( default_len ) { + block_len = LZX_DEFAULT_BLOCK_LEN; + } else { + len_high = lzx_getbits ( lzx, 8 ); + if ( len_high < 0 ) + return len_high; + len_low = lzx_getbits ( lzx, 8 ); + if ( len_low < 0 ) + return len_low; + block_len = ( ( len_high << 8 ) | len_low ); + } + lzx->output.threshold = ( lzx->output.offset + block_len ); + + /* Handle block type */ + switch ( block_type ) { + case LZX_BLOCK_ALIGNOFFSET : + /* Generated aligned offset alphabet */ + if ( ( rc = lzx_alignoffset_alphabet ( lzx ) ) != 0 ) + return rc; + /* Fall through */ + case LZX_BLOCK_VERBATIM : + /* Generate main alphabet */ + if ( ( rc = lzx_main_alphabet ( lzx ) ) != 0 ) + return rc; + /* Generate lengths alphabet */ + if ( ( rc = lzx_length_alphabet ( lzx ) ) != 0 ) + return rc; + break; + case LZX_BLOCK_UNCOMPRESSED : + /* Align input stream */ + if ( ( rc = lzx_align ( lzx, 1 ) ) != 0 ) + return rc; + /* Read new repeated offsets */ + if ( ( rc = lzx_getbytes ( lzx, &lzx->repeated_offset, + sizeof ( lzx->repeated_offset )))!=0) + return rc; + break; + default: + DBG ( "Unrecognised block type %d\n", block_type ); + return -1; + } + + return 0; +} + +/** + * Process uncompressed data + * + * @v lzx Decompressor + * @ret rc Return status code + */ +static int lzx_uncompressed ( struct lzx *lzx ) { + void *data; + size_t len; + int rc; + + /* Copy bytes */ + data = ( lzx->output.data ? + ( lzx->output.data + lzx->output.offset ) : NULL ); + len = ( lzx->output.threshold - lzx->output.offset ); + if ( ( rc = lzx_getbytes ( lzx, data, len ) ) != 0 ) + return rc; + + /* Align input stream */ + if ( len % 2 ) + lzx->input.offset++; + + lzx->output.offset += len; + + return 0; +} + +/** + * Process an LZX token + * + * @v lzx Decompressor + * @ret rc Return status code + * + * Variable names are chosen to match the LZX specification + * pseudo-code. + */ +static int lzx_token ( struct lzx *lzx ) { + unsigned int length_header; + unsigned int position_slot; + unsigned int offset_bits; + unsigned int i; + size_t match_offset; + size_t match_length; + int verbatim_bits; + int aligned_bits; + int maindata; + int length; + uint8_t *copy; + + /* Get maindata symelse*/ + maindata = lzx_decode ( lzx, &lzx->main ); + if ( maindata < 0 ) + return maindata; + + /* Check for literals */ + if ( maindata < LZX_MAIN_LIT_CODES ) { + if ( lzx->output.data ) + lzx->output.data[lzx->output.offset] = maindata; + lzx->output.offset++; + return 0; + } + maindata -= LZX_MAIN_LIT_CODES; + + /* Calculate the match length */ + length_header = ( maindata & 7 ); + if ( length_header == 7 ) { + length = lzx_decode ( lzx, &lzx->length ); + if ( length < 0 ) + return length; + } else { + length = 0; + } + match_length = ( length_header + 2 + length ); + + /* Calculate the position slot */ + position_slot = ( maindata >> 3 ); + if ( position_slot < LZX_REPEATED_OFFSETS ) { + + /* Repeated offset */ + match_offset = lzx->repeated_offset[position_slot]; + lzx->repeated_offset[position_slot] = lzx->repeated_offset[0]; + lzx->repeated_offset[0] = match_offset; + + } else { + + /* Non-repeated offset */ + offset_bits = lzx_footer_bits ( position_slot ); + if ( ( lzx->block_type == LZX_BLOCK_ALIGNOFFSET ) && + ( offset_bits >= 3 ) ) { + verbatim_bits = lzx_getbits ( lzx, ( offset_bits - 3 )); + if ( verbatim_bits < 0 ) + return verbatim_bits; + verbatim_bits <<= 3; + aligned_bits = lzx_decode ( lzx, &lzx->alignoffset ); + if ( aligned_bits < 0 ) + return aligned_bits; + } else { + verbatim_bits = lzx_getbits ( lzx, offset_bits ); + if ( verbatim_bits < 0 ) + return verbatim_bits; + aligned_bits = 0; + } + match_offset = ( lzx_position_base[position_slot] + + verbatim_bits + aligned_bits - 2 ); + + /* Update repeated offset list */ + for ( i = ( LZX_REPEATED_OFFSETS - 1 ) ; i > 0 ; i-- ) + lzx->repeated_offset[i] = lzx->repeated_offset[ i - 1 ]; + lzx->repeated_offset[0] = match_offset; + } + + /* Copy data */ + if ( match_offset > lzx->output.offset ) { + DBG ( "LZX match underrun out 0x%x offset 0x%x len 0x%x\n", + lzx->output.offset, match_offset, match_length ); + return -1; + } + if ( lzx->output.data ) { + copy = &lzx->output.data[lzx->output.offset]; + for ( i = 0 ; i < match_length ; i++ ) + copy[i] = copy[ i - match_offset ]; + } + lzx->output.offset += match_length; + + return 0; +} + +/** + * Translate E8 jump addresses + * + * @v lzx Decompressor + */ +static void lzx_translate_jumps ( struct lzx *lzx ) { + size_t offset; + int32_t *target; + + /* Sanity check */ + if ( lzx->output.offset < 10 ) + return; + + /* Scan for jump instructions */ + for ( offset = 0 ; offset < ( lzx->output.offset - 10 ) ; offset++ ) { + + /* Check for jump instruction */ + if ( lzx->output.data[offset] != 0xe8 ) + continue; + + /* Translate jump target */ + target = ( ( int32_t * ) &lzx->output.data[ offset + 1 ] ); + if ( *target >= 0 ) { + if ( *target < LZX_WIM_MAGIC_FILESIZE ) + *target -= offset; + } else { + if ( *target >= -( ( int32_t ) offset ) ) + *target += LZX_WIM_MAGIC_FILESIZE; + } + offset += sizeof ( *target ); + } +} + +/** + * Decompress LZX-compressed data + * + * @v data Compressed data + * @v len Length of compressed data + * @v buf Decompression buffer, or NULL + * @ret out_len Length of decompressed data, or negative error + */ +ssize_t lzx_decompress ( const void *data, size_t len, void *buf ) { + struct lzx lzx; + unsigned int i; + int rc; + + /* Sanity check */ + if ( len % 2 ) { + DBG ( "LZX cannot handle odd-length input data\n" ); + //return -1; + } + + /* Initialise global state, if required */ + if ( ! lzx_position_base[ LZX_POSITION_SLOTS - 1 ] ) { + for ( i = 1 ; i < LZX_POSITION_SLOTS ; i++ ) { + lzx_position_base[i] = + ( lzx_position_base[i-1] + + ( 1 << lzx_footer_bits ( i - 1 ) ) ); + } + } + + /* Initialise decompressor */ + memset ( &lzx, 0, sizeof ( lzx ) ); + lzx.input.data = data; + lzx.input.len = len; + lzx.output.data = buf; + for ( i = 0 ; i < LZX_REPEATED_OFFSETS ; i++ ) + lzx.repeated_offset[i] = 1; + + /* Process blocks */ + while ( lzx.input.offset < lzx.input.len ) { + + /* Process block header */ + if ( ( rc = lzx_block_header ( &lzx ) ) != 0 ) + return rc; + + /* Process block contents */ + if ( lzx.block_type == LZX_BLOCK_UNCOMPRESSED ) { + + /* Copy uncompressed data */ + if ( ( rc = lzx_uncompressed ( &lzx ) ) != 0 ) + return rc; + + } else { + + /* Process token stream */ + while ( lzx.output.offset < lzx.output.threshold ) { + if ( ( rc = lzx_token ( &lzx ) ) != 0 ) + return rc; + } + } + } + + /* Postprocess to undo E8 jump compression */ + if ( lzx.output.data ) + lzx_translate_jumps ( &lzx ); + + return lzx.output.offset; +} diff --git a/src/grub2/lzx.h b/src/grub2/lzx.h new file mode 100644 index 0000000..6a4ed8f --- /dev/null +++ b/src/grub2/lzx.h @@ -0,0 +1,179 @@ +#ifndef _LZX_H +#define _LZX_H + +/* + * Copyright (C) 2014 Michael Brown . + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * @file + * + * LZX decompression + * + */ + +#include "huffman.h" + +/** Number of aligned offset codes */ +#define LZX_ALIGNOFFSET_CODES 8 + +/** Aligned offset code length (in bits) */ +#define LZX_ALIGNOFFSET_BITS 3 + +/** Number of pretree codes */ +#define LZX_PRETREE_CODES 20 + +/** Pretree code length (in bits) */ +#define LZX_PRETREE_BITS 4 + +/** Number of literal main codes */ +#define LZX_MAIN_LIT_CODES 256 + +/** Number of position slots */ +#define LZX_POSITION_SLOTS 30 + +/** Number of main codes */ +#define LZX_MAIN_CODES ( LZX_MAIN_LIT_CODES + ( 8 * LZX_POSITION_SLOTS ) ) + +/** Number of length codes */ +#define LZX_LENGTH_CODES 249 + +/** Block type length (in bits) */ +#define LZX_BLOCK_TYPE_BITS 3 + +/** Default block length */ +#define LZX_DEFAULT_BLOCK_LEN 32768 + +/** Number of repeated offsets */ +#define LZX_REPEATED_OFFSETS 3 + +/** Don't ask */ +#define LZX_WIM_MAGIC_FILESIZE 12000000 + +/** Block types */ +enum lzx_block_type { + /** Verbatim block */ + LZX_BLOCK_VERBATIM = 1, + /** Aligned offset block */ + LZX_BLOCK_ALIGNOFFSET = 2, + /** Uncompressed block */ + LZX_BLOCK_UNCOMPRESSED = 3, +}; + +/** An LZX input stream */ +struct lzx_input_stream { + /** Data */ + const uint8_t *data; + /** Length */ + size_t len; + /** Offset within stream */ + size_t offset; +}; + +/** An LZX output stream */ +struct lzx_output_stream { + /** Data, or NULL */ + uint8_t *data; + /** Offset within stream */ + size_t offset; + /** End of current block within stream */ + size_t threshold; +}; + +/** LZX decompressor */ +struct lzx { + /** Input stream */ + struct lzx_input_stream input; + /** Output stream */ + struct lzx_output_stream output; + /** Accumulator */ + uint32_t accumulator; + /** Number of bits in accumulator */ + unsigned int bits; + /** Block type */ + enum lzx_block_type block_type; + /** Repeated offsets */ + unsigned int repeated_offset[LZX_REPEATED_OFFSETS]; + + /** Aligned offset Huffman alphabet */ + struct huffman_alphabet alignoffset; + /** Aligned offset raw symbols + * + * Must immediately follow the aligned offset Huffman + * alphabet. + */ + huffman_raw_symbol_t alignoffset_raw[LZX_ALIGNOFFSET_CODES]; + /** Aligned offset code lengths */ + uint8_t alignoffset_lengths[LZX_ALIGNOFFSET_CODES]; + + /** Pretree Huffman alphabet */ + struct huffman_alphabet pretree; + /** Pretree raw symbols + * + * Must immediately follow the pretree Huffman alphabet. + */ + huffman_raw_symbol_t pretree_raw[LZX_PRETREE_CODES]; + /** Preetree code lengths */ + uint8_t pretree_lengths[LZX_PRETREE_CODES]; + + /** Main Huffman alphabet */ + struct huffman_alphabet main; + /** Main raw symbols + * + * Must immediately follow the main Huffman alphabet. + */ + huffman_raw_symbol_t main_raw[LZX_MAIN_CODES]; + /** Main code lengths */ + struct { + /** Literals */ + uint8_t literals[LZX_MAIN_LIT_CODES]; + /** Remaining symbols */ + uint8_t remainder[ LZX_MAIN_CODES - LZX_MAIN_LIT_CODES ]; + } __attribute__ (( packed )) main_lengths; + + /** Length Huffman alphabet */ + struct huffman_alphabet length; + /** Length raw symbols + * + * Must immediately follow the length Huffman alphabet. + */ + huffman_raw_symbol_t length_raw[LZX_LENGTH_CODES]; + /** Length code lengths */ + uint8_t length_lengths[LZX_LENGTH_CODES]; +}; + +/** + * Calculate number of footer bits for a given position slot + * + * @v position_slot Position slot + * @ret footer_bits Number of footer bits + */ +static inline unsigned int lzx_footer_bits ( unsigned int position_slot ) { + + if ( position_slot < 2 ) { + return 0; + } else if ( position_slot < 38 ) { + return ( ( position_slot / 2 ) - 1 ); + } else { + return 17; + } +} + +extern ssize_t lzx_decompress ( const void *data, size_t len, void *buf ); + +#endif /* _LZX_H */ diff --git a/src/grub2/miniz.c b/src/grub2/miniz.c new file mode 100644 index 0000000..60312a9 --- /dev/null +++ b/src/grub2/miniz.c @@ -0,0 +1,2587 @@ +/* miniz.c v1.12 - public domain deflate/inflate + See "unlicense" statement at the end of this file. + Rich Geldreich , last updated April 12, 2012 + Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt + + * Change History + 4/12/12 v1.12 - More comments, added low-level example5.c, fixed a couple minor level_and_flags issues in the archive API's. + level_and_flags can now be set to MZ_DEFAULT_COMPRESSION. Thanks to Bruce Dawson for the feedback/bug report. + 5/28/11 v1.11 - Added statement from unlicense.org + 5/27/11 v1.10 - Substantial compressor optimizations: + Level 1 is now ~4x faster than before. The L1 compressor's throughput now varies between 70-110MB/sec. on a + Core i7 (actual throughput varies depending on the type of data, and x64 vs. x86). + Improved baseline L2-L9 compression perf. Also, greatly improved compression perf. issues on some file types. + Refactored the compression code for better readability and maintainability. + Added level 10 compression level (L10 has slightly better ratio than level 9, but could have a potentially large + drop in throughput on some files). + 5/15/11 v1.09 - Initial stable release. + + * Low-level Deflate/Inflate implementation notes: + + Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or + greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses + approximately as well as zlib. + + Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function + coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory + block large enough to hold the entire file. + + The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation. + + * zlib-style API notes: + + miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in + zlib replacement in many apps: + The z_stream struct, optional memory allocation callbacks + deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound + inflateInit/inflateInit2/inflate/inflateEnd + compress, compress2, compressBound, uncompress + CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines. + Supports raw deflate streams or standard zlib streams with adler-32 checking. + + Limitations: + The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries. + I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but + there are no guarantees that miniz.c pulls this off perfectly. + + * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by + Alex Evans. Supports 1-4 bytes/pixel images. + + * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the + below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it. + + * Important: For best perf. be sure to customize the below macros for your target platform: + #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 + #define MINIZ_LITTLE_ENDIAN 1 + #define MINIZ_HAS_64BIT_REGISTERS 1 +*/ + +#ifndef MINIZ_HEADER_INCLUDED +#define MINIZ_HEADER_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wundef" + +#define size_t grub_size_t +#define uint8_t grub_uint8_t +#define uint16_t grub_uint16_t +#define uint32_t grub_uint32_t +#define uint64_t grub_uint64_t + +#define assert(a) + +#define memset grub_memset +#define memcpy grub_memcpy +#define memcmp grub_memcmp + +// Defines to completely disable specific portions of miniz.c: +// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. + +// Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. +//#define MINIZ_NO_ZLIB_APIS + +// Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. +//#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES + +// Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc. +// Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc +// callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user +// functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. +//#define MINIZ_NO_MALLOC + +#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__) +// MINIZ_X86_OR_X64_CPU is only used to help set the below macros. +#define MINIZ_X86_OR_X64_CPU 1 +#endif + +#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU +// Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. +#define MINIZ_LITTLE_ENDIAN 1 +#else +#error ("Not little endian") +#endif + +#if MINIZ_X86_OR_X64_CPU +// Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. +#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 +#endif + +#define MINIZ_HAS_64BIT_REGISTERS 1 + +// ------------------- zlib-style API Definitions. + +// For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. +typedef unsigned long mz_ulong; + +// Heap allocation callbacks. +// Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. +typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); +typedef void (*mz_free_func)(void *opaque, void *address); +typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); + +#define MZ_ADLER32_INIT (1) +// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. +mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len); + +#define MZ_CRC32_INIT (0) +// mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. +mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len); + +// Compression strategies. +enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 }; + +// Method +#define MZ_DEFLATED 8 + +#ifndef MINIZ_NO_ZLIB_APIS + +#define MZ_VERSION "9.1.12" +#define MZ_VERNUM 0x91C0 +#define MZ_VER_MAJOR 9 +#define MZ_VER_MINOR 1 +#define MZ_VER_REVISION 12 +#define MZ_VER_SUBREVISION 0 + +// Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). +enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 }; + +// Return status codes. MZ_PARAM_ERROR is non-standard. +enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 }; + +// Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. +enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 }; + +// Window bits +#define MZ_DEFAULT_WINDOW_BITS 15 + +struct mz_internal_state; + +// Compression/decompression stream struct. +typedef struct mz_stream_s +{ + const unsigned char *next_in; // pointer to next byte to read + unsigned int avail_in; // number of bytes available at next_in + mz_ulong total_in; // total number of bytes consumed so far + + unsigned char *next_out; // pointer to next byte to write + unsigned int avail_out; // number of bytes that can be written to next_out + mz_ulong total_out; // total number of bytes produced so far + + char *msg; // error msg (unused) + struct mz_internal_state *state; // internal state, allocated by zalloc/zfree + + mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc) + mz_free_func zfree; // optional heap free function (defaults to free) + void *opaque; // heap alloc function user pointer + + int data_type; // data_type (unused) + mz_ulong adler; // adler32 of the source or uncompressed data + mz_ulong crc32; // crc32 of the source or uncompressed data + mz_ulong reserved; +} mz_stream; + +typedef mz_stream *mz_streamp; + +// Returns the version string of miniz.c. +const char *mz_version(void); + +// mz_deflateInit() initializes a compressor with default options: +// Parameters: +// pStream must point to an initialized mz_stream struct. +// level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. +// level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. +// (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) +// Return values: +// MZ_OK on success. +// MZ_STREAM_ERROR if the stream is bogus. +// MZ_PARAM_ERROR if the input parameters are bogus. +// MZ_MEM_ERROR on out of memory. +int mz_deflateInit(mz_streamp pStream, int level); + +// mz_deflateInit2() is like mz_deflate(), except with more control: +// Additional parameters: +// method must be MZ_DEFLATED +// window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) +// mem_level must be between [1, 9] (it's checked but ignored by miniz.c) +int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy); + +// Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). +int mz_deflateReset(mz_streamp pStream); + +// mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. +// Parameters: +// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. +// flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. +// Return values: +// MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full). +// MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore. +// MZ_STREAM_ERROR if the stream is bogus. +// MZ_PARAM_ERROR if one of the parameters is invalid. +// MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.) +int mz_deflate(mz_streamp pStream, int flush); + +// mz_deflateEnd() deinitializes a compressor: +// Return values: +// MZ_OK on success. +// MZ_STREAM_ERROR if the stream is bogus. +int mz_deflateEnd(mz_streamp pStream); + +// mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. +mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len); + +// Single-call compression functions mz_compress() and mz_compress2(): +// Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. +int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); +int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level); + +// mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). +mz_ulong mz_compressBound(mz_ulong source_len); + +// Initializes a decompressor. +int mz_inflateInit(mz_streamp pStream); + +// mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer: +// window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). +int mz_inflateInit2(mz_streamp pStream, int window_bits); + +// Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. +// Parameters: +// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. +// flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. +// On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster). +// MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data. +// Return values: +// MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full. +// MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified. +// MZ_STREAM_ERROR if the stream is bogus. +// MZ_DATA_ERROR if the deflate stream is invalid. +// MZ_PARAM_ERROR if one of the parameters is invalid. +// MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again +// with more input data, or with more room in the output buffer (except when using single call decompression, described above). +int mz_inflate(mz_streamp pStream, int flush); + +// Deinitializes a decompressor. +int mz_inflateEnd(mz_streamp pStream); + +// Single-call decompression. +// Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. +int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); + +// Returns a string description of the specified error code, or NULL if the error code is invalid. +const char *mz_error(int err); + +// Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports. +// Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. +#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES + typedef unsigned char Byte; + typedef unsigned int uInt; + typedef mz_ulong uLong; + typedef Byte Bytef; + typedef uInt uIntf; + typedef char charf; + typedef int intf; + typedef void *voidpf; + typedef uLong uLongf; + typedef void *voidp; + typedef void *const voidpc; + #define Z_NULL 0 + #define Z_NO_FLUSH MZ_NO_FLUSH + #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH + #define Z_SYNC_FLUSH MZ_SYNC_FLUSH + #define Z_FULL_FLUSH MZ_FULL_FLUSH + #define Z_FINISH MZ_FINISH + #define Z_BLOCK MZ_BLOCK + #define Z_OK MZ_OK + #define Z_STREAM_END MZ_STREAM_END + #define Z_NEED_DICT MZ_NEED_DICT + #define Z_ERRNO MZ_ERRNO + #define Z_STREAM_ERROR MZ_STREAM_ERROR + #define Z_DATA_ERROR MZ_DATA_ERROR + #define Z_MEM_ERROR MZ_MEM_ERROR + #define Z_BUF_ERROR MZ_BUF_ERROR + #define Z_VERSION_ERROR MZ_VERSION_ERROR + #define Z_PARAM_ERROR MZ_PARAM_ERROR + #define Z_NO_COMPRESSION MZ_NO_COMPRESSION + #define Z_BEST_SPEED MZ_BEST_SPEED + #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION + #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION + #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY + #define Z_FILTERED MZ_FILTERED + #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY + #define Z_RLE MZ_RLE + #define Z_FIXED MZ_FIXED + #define Z_DEFLATED MZ_DEFLATED + #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS + #define alloc_func mz_alloc_func + #define free_func mz_free_func + #define internal_state mz_internal_state + #define z_stream mz_stream + #define deflateInit mz_deflateInit + #define deflateInit2 mz_deflateInit2 + #define deflateReset mz_deflateReset + #define deflate mz_deflate + #define deflateEnd mz_deflateEnd + #define deflateBound mz_deflateBound + #define compress mz_compress + #define compress2 mz_compress2 + #define compressBound mz_compressBound + #define inflateInit mz_inflateInit + #define inflateInit2 mz_inflateInit2 + #define inflate mz_inflate + #define inflateEnd mz_inflateEnd + #define uncompress mz_uncompress + #define z_crc32 mz_crc32 + #define z_adler32 mz_adler32 + #define MAX_WBITS 15 + #define MAX_MEM_LEVEL 9 + #define zError mz_error + #define ZLIB_VERSION MZ_VERSION + #define ZLIB_VERNUM MZ_VERNUM + #define ZLIB_VER_MAJOR MZ_VER_MAJOR + #define ZLIB_VER_MINOR MZ_VER_MINOR + #define ZLIB_VER_REVISION MZ_VER_REVISION + #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION + #define zlibVersion mz_version + #define zlib_version mz_version() +#endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES + +#endif // MINIZ_NO_ZLIB_APIS + +// ------------------- Types and macros + +typedef unsigned char mz_uint8; +typedef signed short mz_int16; +typedef unsigned short mz_uint16; +typedef unsigned int mz_uint32; +typedef unsigned int mz_uint; +typedef long long mz_int64; +typedef unsigned long long mz_uint64; +typedef int mz_bool; + +#define MZ_FALSE (0) +#define MZ_TRUE (1) + +#ifndef __WIN__ +#define MZ_MACRO_END while (0) +#else +// Works around MSVC's spammy "warning C4127: conditional expression is constant" message. +#define MZ_MACRO_END while (0, 0) +#endif + +// ------------------- Low-level Decompression API Definitions + +// Decompression flags used by tinfl_decompress(). +// TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. +// TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. +// TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). +// TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. +enum +{ + TINFL_FLAG_PARSE_ZLIB_HEADER = 1, + TINFL_FLAG_HAS_MORE_INPUT = 2, + TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4, + TINFL_FLAG_COMPUTE_ADLER32 = 8 +}; + +// High level decompression functions: +// tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). +// On entry: +// pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. +// On return: +// Function returns a pointer to the decompressed data, or NULL on failure. +// *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. +// The caller must free() the returned block when it's no longer needed. +void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); + +// tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. +// Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. +#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1)) +size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); + +// tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer. +// Returns 1 on success or 0 on failure. +typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser); +int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); + +struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor; + +// Max size of LZ dictionary. +#define TINFL_LZ_DICT_SIZE 32768 + +// Return status. +typedef enum +{ + TINFL_STATUS_BAD_PARAM = -3, + TINFL_STATUS_ADLER32_MISMATCH = -2, + TINFL_STATUS_FAILED = -1, + TINFL_STATUS_DONE = 0, + TINFL_STATUS_NEEDS_MORE_INPUT = 1, + TINFL_STATUS_HAS_MORE_OUTPUT = 2 +} tinfl_status; + +// Initializes the decompressor to its initial state. +#define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END +#define tinfl_get_adler32(r) (r)->m_check_adler32 +#define tinfl_get_crc32(r) (r)->m_check_crc32 + +// Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. +// This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. +tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags); + +// Internal/private bits follow. +enum +{ + TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19, + TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS +}; + +typedef struct +{ + mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]; + mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; +} tinfl_huff_table; + +#if MINIZ_HAS_64BIT_REGISTERS + #define TINFL_USE_64BIT_BITBUF 1 +#endif + +#if TINFL_USE_64BIT_BITBUF + typedef mz_uint64 tinfl_bit_buf_t; + #define TINFL_BITBUF_SIZE (64) +#else + typedef mz_uint32 tinfl_bit_buf_t; + #define TINFL_BITBUF_SIZE (32) +#endif + +struct tinfl_decompressor_tag +{ + mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_z_crc32, m_final, m_type, m_check_adler32, m_check_crc32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; + tinfl_bit_buf_t m_bit_buf; + size_t m_dist_from_out_buf_start; + tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]; + mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; +}; + +// ------------------- Low-level Compression API Definitions + +// Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently). +#define TDEFL_LESS_MEMORY 0 + +// tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): +// TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). +enum +{ + TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF +}; + +// TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data. +// TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). +// TDEFL_COMPUTE_CRC32: Always compute the crc-32 of the input data. +// TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. +// TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory). +// TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) +// TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. +// TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. +// TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. +enum +{ + TDEFL_WRITE_ZLIB_HEADER = 0x001000, + TDEFL_COMPUTE_ADLER32 = 0x002000, + TDEFL_COMPUTE_CRC32 = 0x004000, + TDEFL_GREEDY_PARSING_FLAG = 0x008000, + TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x010000, + TDEFL_RLE_MATCHES = 0x020000, + TDEFL_FILTER_MATCHES = 0x040000, + TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x080000, + TDEFL_FORCE_ALL_RAW_BLOCKS = 0x100000, +}; + +// High level compression functions: +// tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). +// On entry: +// pSrc_buf, src_buf_len: Pointer and size of source block to compress. +// flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression. +// On return: +// Function returns a pointer to the compressed data, or NULL on failure. +// *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. +// The caller must free() the returned block when it's no longer needed. +void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); + +// tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. +// Returns 0 on failure. +size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); + +// Compresses an image to a compressed PNG file in memory. +// On entry: +// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. +// On return: +// Function returns a pointer to the compressed data, or NULL on failure. +// *pLen_out will be set to the size of the PNG image file. +// The caller must free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. +void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out); + +// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. +typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser); + +// tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. +mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); + +enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 }; + +// TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes). +#if TDEFL_LESS_MEMORY +enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS }; +#else +enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS }; +#endif + +// The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. +typedef enum +{ + TDEFL_STATUS_BAD_PARAM = -2, + TDEFL_STATUS_PUT_BUF_FAILED = -1, + TDEFL_STATUS_OKAY = 0, + TDEFL_STATUS_DONE = 1, +} tdefl_status; + +// Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums +typedef enum +{ + TDEFL_NO_FLUSH = 0, + TDEFL_SYNC_FLUSH = 2, + TDEFL_FULL_FLUSH = 3, + TDEFL_FINISH = 4 +} tdefl_flush; + +// tdefl's compression state structure. +typedef struct +{ + tdefl_put_buf_func_ptr m_pPut_buf_func; + void *m_pPut_buf_user; + mz_uint m_flags, m_max_probes[2]; + int m_greedy_parsing; + mz_uint m_adler32, m_crc32, m_lookahead_pos, m_lookahead_size, m_dict_size; + mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end; + mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer; + mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish; + tdefl_status m_prev_return_status; + const void *m_pIn_buf; + void *m_pOut_buf; + size_t *m_pIn_buf_size, *m_pOut_buf_size; + tdefl_flush m_flush; + const mz_uint8 *m_pSrc; + size_t m_src_buf_left, m_out_buf_ofs; + mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1]; + mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; + mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; + mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; + mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE]; + mz_uint16 m_next[TDEFL_LZ_DICT_SIZE]; + mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE]; + mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE]; +} tdefl_compressor; + +// Initializes the compressor. +// There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. +// pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression. +// If pBut_buf_func is NULL the user should always call the tdefl_compress() API. +// flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) +tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); + +// Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. +tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush); + +// tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. +// tdefl_compress_buffer() always consumes the entire input buffer. +tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush); + +tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); +mz_uint32 tdefl_get_adler32(tdefl_compressor *d); +mz_uint32 tdefl_get_crc32(tdefl_compressor *d); + +// Create tdefl_compress() flags given zlib-style compression parameters. +// level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) +// window_bits may be -15 (raw deflate) or 15 (zlib) +// strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED +mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy); + +#endif // MINIZ_HEADER_INCLUDED + +// ------------------- End of Header: Implementation follows. (If you only want the header, define MINIZ_HEADER_FILE_ONLY.) + +#ifndef MINIZ_HEADER_FILE_ONLY + +typedef unsigned char mz_validate_uint16[sizeof(mz_uint16)==2 ? 1 : -1]; +typedef unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 : -1]; +typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1]; + +#define MZ_ASSERT(x) assert(x) + +#ifdef MINIZ_NO_MALLOC + #define MZ_MALLOC(x) NULL + #define MZ_FREE(x) x, ((void)0) + #define MZ_REALLOC(p, x) NULL +#else + #define MZ_MALLOC(x) grub_malloc(x) + #define MZ_FREE(x) grub_free(x) + #define MZ_REALLOC(p, x) grub_realloc(p, x) +#endif + +#define MZ_MAX(a,b) (((a)>(b))?(a):(b)) +#define MZ_MIN(a,b) (((a)<(b))?(a):(b)) +#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN + #define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) + #define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) +#else + #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U)) + #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) +#endif + +#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__MINGW64__) && !defined(__forceinline) + #define __forceinline +#endif + +// ------------------- zlib-style API's + +static void *def_alloc_func(void *opaque, size_t items, size_t size) { (void)opaque; return MZ_MALLOC(items * size); } +static void def_free_func(void *opaque, void *address) { (void)opaque, MZ_FREE(address); } + +mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len) +{ + mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16); size_t block_len = buf_len % 5552; + if (!ptr) return MZ_ADLER32_INIT; + while (buf_len) { + for (i = 0; i + 7 < block_len; i += 8, ptr += 8) { + s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1; + s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1; + } + for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1; + s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552; + } + return (s2 << 16) + s1; +} + +// Karl Malbrain's compact CRC-32. See "A compact CCITT crc16 and crc32 C implementation that balances processor cache usage against speed": http://www.geocities.com/malbrain/ +mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len) +{ + static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; + if (!ptr) return MZ_CRC32_INIT; + crc = ~crc; while (buf_len--) { mz_uint8 b = *ptr++; crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b & 0xF)]; crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b >> 4)]; } return ~crc; +} + +#ifndef MINIZ_NO_ZLIB_APIS + +const char *mz_version(void) +{ + return MZ_VERSION; +} + +int mz_deflateInit(mz_streamp pStream, int level) +{ + return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY); +} + +int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy) +{ + tdefl_compressor *pComp; + mz_uint comp_flags = TDEFL_COMPUTE_ADLER32 | TDEFL_COMPUTE_CRC32 | tdefl_create_comp_flags_from_zip_params(level, window_bits, strategy); + + if (!pStream) return MZ_STREAM_ERROR; + if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))) return MZ_PARAM_ERROR; + + pStream->data_type = 0; + pStream->adler = MZ_ADLER32_INIT; + pStream->crc32 = MZ_CRC32_INIT; + pStream->msg = NULL; + pStream->reserved = 0; + pStream->total_in = 0; + pStream->total_out = 0; + if (!pStream->zalloc) pStream->zalloc = def_alloc_func; + if (!pStream->zfree) pStream->zfree = def_free_func; + + pComp = (tdefl_compressor *)pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor)); + if (!pComp) + return MZ_MEM_ERROR; + + pStream->state = (struct mz_internal_state *)pComp; + + if (tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY) + { + mz_deflateEnd(pStream); + return MZ_PARAM_ERROR; + } + + return MZ_OK; +} + +int mz_deflateReset(mz_streamp pStream) +{ + if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree)) return MZ_STREAM_ERROR; + pStream->total_in = pStream->total_out = 0; + tdefl_init((tdefl_compressor*)pStream->state, NULL, NULL, ((tdefl_compressor*)pStream->state)->m_flags); + return MZ_OK; +} + +int mz_deflate(mz_streamp pStream, int flush) +{ + size_t in_bytes, out_bytes; + mz_ulong orig_total_in, orig_total_out; + int mz_status = MZ_OK; + + if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) || (!pStream->next_out)) return MZ_STREAM_ERROR; + if (!pStream->avail_out) return MZ_BUF_ERROR; + + if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH; + + if (((tdefl_compressor*)pStream->state)->m_prev_return_status == TDEFL_STATUS_DONE) + return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR; + + orig_total_in = pStream->total_in; orig_total_out = pStream->total_out; + for ( ; ; ) + { + tdefl_status defl_status; + in_bytes = pStream->avail_in; out_bytes = pStream->avail_out; + + defl_status = tdefl_compress((tdefl_compressor*)pStream->state, pStream->next_in, &in_bytes, pStream->next_out, &out_bytes, (tdefl_flush)flush); + pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; + pStream->total_in += (mz_uint)in_bytes; pStream->adler = tdefl_get_adler32((tdefl_compressor*)pStream->state); pStream->crc32 = tdefl_get_crc32((tdefl_compressor*)pStream->state); + + pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; + pStream->total_out += (mz_uint)out_bytes; + + if (defl_status < 0) + { + mz_status = MZ_STREAM_ERROR; + break; + } + else if (defl_status == TDEFL_STATUS_DONE) + { + mz_status = MZ_STREAM_END; + break; + } + else if (!pStream->avail_out) + break; + else if ((!pStream->avail_in) && (flush != MZ_FINISH)) + { + if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out)) + break; + return MZ_BUF_ERROR; // Can't make forward progress without some input. + } + } + return mz_status; +} + +int mz_deflateEnd(mz_streamp pStream) +{ + if (!pStream) return MZ_STREAM_ERROR; + if (pStream->state) + { + pStream->zfree(pStream->opaque, pStream->state); + pStream->state = NULL; + } + return MZ_OK; +} + +mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len) +{ + (void)pStream; + // This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.) + return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5); +} + +int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level) +{ + int status; + mz_stream stream; + memset(&stream, 0, sizeof(stream)); + + // In case mz_ulong is 64-bits (argh I hate longs). + if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR; + + stream.next_in = pSource; + stream.avail_in = (mz_uint32)source_len; + stream.next_out = pDest; + stream.avail_out = (mz_uint32)*pDest_len; + + status = mz_deflateInit(&stream, level); + if (status != MZ_OK) return status; + + status = mz_deflate(&stream, MZ_FINISH); + if (status != MZ_STREAM_END) + { + mz_deflateEnd(&stream); + return (status == MZ_OK) ? MZ_BUF_ERROR : status; + } + + *pDest_len = stream.total_out; + return mz_deflateEnd(&stream); +} + +int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) +{ + return mz_compress2(pDest, pDest_len, pSource, source_len, MZ_DEFAULT_COMPRESSION); +} + +mz_ulong mz_compressBound(mz_ulong source_len) +{ + return mz_deflateBound(NULL, source_len); +} + +typedef struct +{ + tinfl_decompressor m_decomp; + mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed; int m_window_bits; + mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]; + tinfl_status m_last_status; +} inflate_state; + +int mz_inflateInit2(mz_streamp pStream, int window_bits) +{ + inflate_state *pDecomp; + if (!pStream) return MZ_STREAM_ERROR; + if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)) return MZ_PARAM_ERROR; + + pStream->data_type = 0; + pStream->adler = 0; + pStream->crc32 = 0; + pStream->msg = NULL; + pStream->total_in = 0; + pStream->total_out = 0; + pStream->reserved = 0; + if (!pStream->zalloc) pStream->zalloc = def_alloc_func; + if (!pStream->zfree) pStream->zfree = def_free_func; + + pDecomp = (inflate_state*)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state)); + if (!pDecomp) return MZ_MEM_ERROR; + + pStream->state = (struct mz_internal_state *)pDecomp; + + tinfl_init(&pDecomp->m_decomp); + pDecomp->m_dict_ofs = 0; + pDecomp->m_dict_avail = 0; + pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT; + pDecomp->m_first_call = 1; + pDecomp->m_has_flushed = 0; + pDecomp->m_window_bits = window_bits; + + return MZ_OK; +} + +int mz_inflateInit(mz_streamp pStream) +{ + return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS); +} + +int mz_inflate(mz_streamp pStream, int flush) +{ + inflate_state* pState; + mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32; + size_t in_bytes, out_bytes, orig_avail_in; + tinfl_status status; + + if ((!pStream) || (!pStream->state)) return MZ_STREAM_ERROR; + if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH; + if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) return MZ_STREAM_ERROR; + + pState = (inflate_state*)pStream->state; + if (pState->m_window_bits > 0) decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER; + orig_avail_in = pStream->avail_in; + + first_call = pState->m_first_call; pState->m_first_call = 0; + if (pState->m_last_status < 0) return MZ_DATA_ERROR; + + if (pState->m_has_flushed && (flush != MZ_FINISH)) return MZ_STREAM_ERROR; + pState->m_has_flushed |= (flush == MZ_FINISH); + + if ((flush == MZ_FINISH) && (first_call)) + { + // MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. + decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF; + in_bytes = pStream->avail_in; out_bytes = pStream->avail_out; + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags); + pState->m_last_status = status; + pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes; + pStream->adler = tinfl_get_adler32(&pState->m_decomp); + pStream->crc32 = tinfl_get_crc32(&pState->m_decomp); + pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes; + + if (status < 0) + return MZ_DATA_ERROR; + else if (status != TINFL_STATUS_DONE) + { + pState->m_last_status = TINFL_STATUS_FAILED; + return MZ_BUF_ERROR; + } + return MZ_STREAM_END; + } + // flush != MZ_FINISH then we must assume there's more input. + if (flush != MZ_FINISH) decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT; + + if (pState->m_dict_avail) + { + n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); + memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); + pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n; + pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); + return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; + } + + for ( ; ; ) + { + in_bytes = pStream->avail_in; + out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs; + + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags); + pState->m_last_status = status; + + pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; + pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp); pStream->crc32 = tinfl_get_crc32(&pState->m_decomp); + + pState->m_dict_avail = (mz_uint)out_bytes; + + n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); + memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); + pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n; + pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); + + if (status < 0) + return MZ_DATA_ERROR; // Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). + else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in)) + return MZ_BUF_ERROR; // Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. + else if (flush == MZ_FINISH) + { + // The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. + if (status == TINFL_STATUS_DONE) + return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END; + // status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. + else if (!pStream->avail_out) + return MZ_BUF_ERROR; + } + else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail)) + break; + } + + return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; +} + +int mz_inflateEnd(mz_streamp pStream) +{ + if (!pStream) + return MZ_STREAM_ERROR; + if (pStream->state) + { + pStream->zfree(pStream->opaque, pStream->state); + pStream->state = NULL; + } + return MZ_OK; +} + +int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) +{ + mz_stream stream; + int status; + memset(&stream, 0, sizeof(stream)); + + // In case mz_ulong is 64-bits (argh I hate longs). + if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR; + + stream.next_in = pSource; + stream.avail_in = (mz_uint32)source_len; + stream.next_out = pDest; + stream.avail_out = (mz_uint32)*pDest_len; + + status = mz_inflateInit(&stream); + if (status != MZ_OK) + return status; + + status = mz_inflate(&stream, MZ_FINISH); + if (status != MZ_STREAM_END) + { + mz_inflateEnd(&stream); + return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status; + } + *pDest_len = stream.total_out; + + return mz_inflateEnd(&stream); +} + +const char *mz_error(int err) +{ + static struct { int m_err; const char *m_pDesc; } s_error_descs[] = + { + { MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" }, + { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" } + }; + mz_uint i; for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) if (s_error_descs[i].m_err == err) return s_error_descs[i].m_pDesc; + return NULL; +} + +#endif //MINIZ_NO_ZLIB_APIS + +// ------------------- Low-level Decompression (completely independent from all compression API's) + +#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l) +#define TINFL_MEMSET(p, c, l) memset(p, c, l) + +#define TINFL_CR_BEGIN switch(r->m_state) { case 0: +#define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END +#define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END +#define TINFL_CR_FINISH } + +// TODO: If the caller has indicated that there's no more input, and we attempt to read beyond the input buf, then something is wrong with the input because the inflator never +// reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads the end of the stream with 0's in this scenario. +#define TINFL_GET_BYTE(state_index, c) do { \ + if (pIn_buf_cur >= pIn_buf_end) { \ + for ( ; ; ) { \ + if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \ + TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \ + if (pIn_buf_cur < pIn_buf_end) { \ + c = *pIn_buf_cur++; \ + break; \ + } \ + } else { \ + c = 0; \ + break; \ + } \ + } \ + } else c = *pIn_buf_cur++; } MZ_MACRO_END + +#define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n)) +#define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END +#define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END + +// TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2. +// It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a +// Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the +// bit buffer contains >=15 bits (deflate's max. Huffman code size). +#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \ + do { \ + temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \ + if (temp >= 0) { \ + code_len = temp >> 9; \ + if ((code_len) && (num_bits >= code_len)) \ + break; \ + } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \ + code_len = TINFL_FAST_LOOKUP_BITS; \ + do { \ + temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ + } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \ + } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \ + } while (num_bits < 15); + +// TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read +// beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully +// decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32. +// The slow path is only executed at the very end of the input buffer. +#define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \ + int temp; mz_uint code_len, c; \ + if (num_bits < 15) { \ + if ((pIn_buf_end - pIn_buf_cur) < 2) { \ + TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \ + } else { \ + bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \ + } \ + } \ + if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \ + code_len = temp >> 9, temp &= 511; \ + else { \ + code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \ + } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END + +#if defined(__aarch64__) || defined(__arm__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmisleading-indentation" +#endif + +tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags) +{ + static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 }; + static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; + static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; + static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; + static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; + static const int s_min_table_sizes[3] = { 257, 1, 4 }; + + tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf; + const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size; + mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size; + size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start; + + // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). + if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; } + + num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start; + TINFL_CR_BEGIN + + bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1; + if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) + { + TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1); + counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8)); + if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4))))); + if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); } + } + + do + { + TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1; + if (r->m_type == 0) + { + TINFL_SKIP_BITS(5, num_bits & 7); + for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); } + if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); } + while ((counter) && (num_bits)) + { + TINFL_GET_BITS(51, dist, 8); + while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); } + *pOut_buf_cur++ = (mz_uint8)dist; + counter--; + } + while (counter) + { + size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); } + while (pIn_buf_cur >= pIn_buf_end) + { + if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) + { + TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT); + } + else + { + TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED); + } + } + n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter); + TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n; + } + } + else if (r->m_type == 3) + { + TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED); + } + else + { + if (r->m_type == 1) + { + mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i; + r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32); + for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8; + } + else + { + for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; } + MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; } + r->m_table_sizes[2] = 19; + } + for ( ; (int)r->m_type >= 0; r->m_type--) + { + int tree_next, tree_cur; tinfl_huff_table *pTable; + mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree); + for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++; + used_syms = 0, total = 0; next_code[0] = next_code[1] = 0; + for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); } + if ((65536 != total) && (used_syms > 1)) + { + TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED); + } + for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) + { + mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue; + cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1); + if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; } + if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } + rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1); + for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) + { + tree_cur -= ((rev_code >>= 1) & 1); + if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1]; + } + tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index; + } + if (r->m_type == 2) + { + for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); ) + { + mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; } + if ((dist == 16) && (!counter)) + { + TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED); + } + num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16]; + TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s; + } + if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter) + { + TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED); + } + TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]); + } + } + for ( ; ; ) + { + mz_uint8 *pSrc; + for ( ; ; ) + { + if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) + { + TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]); + if (counter >= 256) + break; + while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); } + *pOut_buf_cur++ = (mz_uint8)counter; + } + else + { + int sym2; mz_uint code_len; +#if TINFL_USE_64BIT_BITBUF + if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; } +#else + if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; } +#endif + if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) + code_len = sym2 >> 9; + else + { + code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0); + } + counter = sym2; bit_buf >>= code_len; num_bits -= code_len; + if (counter & 256) + break; + +#if !TINFL_USE_64BIT_BITBUF + if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; } +#endif + if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) + code_len = sym2 >> 9; + else + { + code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0); + } + bit_buf >>= code_len; num_bits -= code_len; + + pOut_buf_cur[0] = (mz_uint8)counter; + if (sym2 & 256) + { + pOut_buf_cur++; + counter = sym2; + break; + } + pOut_buf_cur[1] = (mz_uint8)sym2; + pOut_buf_cur += 2; + } + } + if ((counter &= 511) == 256) break; + + num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257]; + if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; } + + TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]); + num_extra = s_dist_extra[dist]; dist = s_dist_base[dist]; + if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; } + + dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start; + if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) + { + TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED); + } + + pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask); + + if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end) + { + while (counter--) + { + while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); } + *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask]; + } + continue; + } +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES + else if ((counter >= 9) && (counter <= dist)) + { + const mz_uint8 *pSrc_end = pSrc + (counter & ~7); + do + { + ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0]; + ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1]; + pOut_buf_cur += 8; + } while ((pSrc += 8) < pSrc_end); + if ((counter &= 7) < 3) + { + if (counter) + { + pOut_buf_cur[0] = pSrc[0]; + if (counter > 1) + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur += counter; + } + continue; + } + } +#endif + do + { + pOut_buf_cur[0] = pSrc[0]; + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur[2] = pSrc[2]; + pOut_buf_cur += 3; pSrc += 3; + } while ((int)(counter -= 3) > 2); + if ((int)counter > 0) + { + pOut_buf_cur[0] = pSrc[0]; + if ((int)counter > 1) + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur += counter; + } + } + } + } while (!(r->m_final & 1)); + if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) + { + TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; } + } + TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE); + TINFL_CR_FINISH + +common_exit: + r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start; + *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next; + if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0)) + { + const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size; + mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552; + while (buf_len) + { + for (i = 0; i + 7 < block_len; i += 8, ptr += 8) + { + s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1; + s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1; + } + for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1; + s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552; + } + r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH; + } + return status; +} + +#if defined(__aarch64__) || defined(__arm__) +#pragma GCC diagnostic pop +#endif + +// Higher level helper functions. +void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags) +{ + tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0; + *pOut_len = 0; + tinfl_init(&decomp); + for ( ; ; ) + { + size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity; + tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size, + (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF); + if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT)) + { + MZ_FREE(pBuf); *pOut_len = 0; return NULL; + } + src_buf_ofs += src_buf_size; + *pOut_len += dst_buf_size; + if (status == TINFL_STATUS_DONE) break; + new_out_buf_capacity = out_buf_capacity * 2; if (new_out_buf_capacity < 128) new_out_buf_capacity = 128; + pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity); + if (!pNew_buf) + { + MZ_FREE(pBuf); *pOut_len = 0; return NULL; + } + pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity; + } + return pBuf; +} + +size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags) +{ + tinfl_decompressor decomp; tinfl_status status; tinfl_init(&decomp); + status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf, &src_buf_len, (mz_uint8*)pOut_buf, (mz_uint8*)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF); + return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len; +} + +int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) +{ + int result = 0; + tinfl_decompressor decomp; + mz_uint8 *pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE); size_t in_buf_ofs = 0, dict_ofs = 0; + if (!pDict) + return TINFL_STATUS_FAILED; + tinfl_init(&decomp); + for ( ; ; ) + { + size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs; + tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size, + (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))); + in_buf_ofs += in_buf_size; + if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user))) + break; + if (status != TINFL_STATUS_HAS_MORE_OUTPUT) + { + result = (status == TINFL_STATUS_DONE); + break; + } + dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1); + } + MZ_FREE(pDict); + *pIn_buf_size = in_buf_ofs; + return result; +} + +// ------------------- Low-level Compression (independent from all decompression API's) + +// Purposely making these tables static for faster init and thread safety. +static const mz_uint16 s_tdefl_len_sym[256] = { + 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272, + 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276, + 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278, + 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280, + 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281, + 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282, + 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283, + 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 }; + +static const mz_uint8 s_tdefl_len_extra[256] = { + 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, + 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 }; + +static const mz_uint8 s_tdefl_small_dist_sym[512] = { + 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11, + 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13, + 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14, + 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, + 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, + 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16, + 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, + 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, + 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17, + 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, + 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, + 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 }; + +static const mz_uint8 s_tdefl_small_dist_extra[512] = { + 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5, + 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7 }; + +static const mz_uint8 s_tdefl_large_dist_sym[128] = { + 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26, + 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28, + 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 }; + +static const mz_uint8 s_tdefl_large_dist_extra[128] = { + 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, + 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, + 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 }; + +// Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values. +typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq; +static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1) +{ + mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; tdefl_sym_freq* pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist); + for (i = 0; i < num_syms; i++) { mz_uint freq = pSyms0[i].m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; } + while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--; + for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8) + { + const mz_uint32* pHist = &hist[pass << 8]; + mz_uint offsets[256], cur_ofs = 0; + for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; } + for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i]; + { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; } + } + return pCur_syms; +} + +// tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, alistair@cs.mu.oz.au, Jyrki Katajainen, jyrki@diku.dk, November 1996. +static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n) +{ + int root, leaf, next, avbl, used, dpth; + if (n==0) return; else if (n==1) { A[0].m_key = 1; return; } + A[0].m_key += A[1].m_key; root = 0; leaf = 2; + for (next=1; next < n-1; next++) + { + if (leaf>=n || A[root].m_key=n || (root=0; next--) A[next].m_key = A[A[next].m_key].m_key+1; + avbl = 1; used = dpth = 0; root = n-2; next = n-1; + while (avbl>0) + { + while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; } + while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; } + avbl = 2*used; dpth++; used = 0; + } +} + +// Limits canonical Huffman code table's max code size. +enum { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 }; +static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size) +{ + int i; mz_uint32 total = 0; if (code_list_len <= 1) return; + for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) pNum_codes[max_code_size] += pNum_codes[i]; + for (i = max_code_size; i > 0; i--) total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i)); + while (total != (1UL << max_code_size)) + { + pNum_codes[max_code_size]--; + for (i = max_code_size - 1; i > 0; i--) if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2; break; } + total--; + } +} + +static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table) +{ + int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; MZ_CLEAR_OBJ(num_codes); + if (static_table) + { + for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++; + } + else + { + tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms; + int num_used_syms = 0; + const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0]; + for (i = 0; i < table_len; i++) if (pSym_count[i]) { syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; syms0[num_used_syms++].m_sym_index = (mz_uint16)i; } + + pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); tdefl_calculate_minimum_redundancy(pSyms, num_used_syms); + + for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++; + + tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit); + + MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]); + for (i = 1, j = num_used_syms; i <= code_size_limit; i++) + for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i); + } + + next_code[1] = 0; for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1); + + for (i = 0; i < table_len; i++) + { + mz_uint rev_code = 0, code, code_size; if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) continue; + code = next_code[code_size]++; for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1); + d->m_huff_codes[table_num][i] = (mz_uint16)rev_code; + } +} + +#define TDEFL_PUT_BITS(b, l) do { \ + mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \ + d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \ + while (d->m_bits_in >= 8) { \ + if (d->m_pOutput_buf < d->m_pOutput_buf_end) \ + *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \ + d->m_bit_buffer >>= 8; \ + d->m_bits_in -= 8; \ + } \ +} MZ_MACRO_END + +#define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \ + if (rle_repeat_count < 3) { \ + d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \ + while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \ + } else { \ + d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \ +} rle_repeat_count = 0; } } + +#define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \ + if (rle_z_count < 3) { \ + d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \ + } else if (rle_z_count <= 10) { \ + d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \ + } else { \ + d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \ +} rle_z_count = 0; } } + +static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + +static void tdefl_start_dynamic_block(tdefl_compressor *d) +{ + int num_lit_codes, num_dist_codes, num_bit_lengths; mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index; + mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF; + + d->m_huff_count[0][256] = 1; + + tdefl_optimize_huffman_table(d, 0, TDEFL_MAX_HUFF_SYMBOLS_0, 15, MZ_FALSE); + tdefl_optimize_huffman_table(d, 1, TDEFL_MAX_HUFF_SYMBOLS_1, 15, MZ_FALSE); + + for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--) if (d->m_huff_code_sizes[0][num_lit_codes - 1]) break; + for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--) if (d->m_huff_code_sizes[1][num_dist_codes - 1]) break; + + memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes); + memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes); + total_code_sizes_to_pack = num_lit_codes + num_dist_codes; num_packed_code_sizes = 0; rle_z_count = 0; rle_repeat_count = 0; + + memset(&d->m_huff_count[2][0], 0, sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2); + for (i = 0; i < total_code_sizes_to_pack; i++) + { + mz_uint8 code_size = code_sizes_to_pack[i]; + if (!code_size) + { + TDEFL_RLE_PREV_CODE_SIZE(); + if (++rle_z_count == 138) { TDEFL_RLE_ZERO_CODE_SIZE(); } + } + else + { + TDEFL_RLE_ZERO_CODE_SIZE(); + if (code_size != prev_code_size) + { + TDEFL_RLE_PREV_CODE_SIZE(); + d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1); packed_code_sizes[num_packed_code_sizes++] = code_size; + } + else if (++rle_repeat_count == 6) + { + TDEFL_RLE_PREV_CODE_SIZE(); + } + } + prev_code_size = code_size; + } + if (rle_repeat_count) { TDEFL_RLE_PREV_CODE_SIZE(); } else { TDEFL_RLE_ZERO_CODE_SIZE(); } + + tdefl_optimize_huffman_table(d, 2, TDEFL_MAX_HUFF_SYMBOLS_2, 7, MZ_FALSE); + + TDEFL_PUT_BITS(2, 2); + + TDEFL_PUT_BITS(num_lit_codes - 257, 5); + TDEFL_PUT_BITS(num_dist_codes - 1, 5); + + for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--) if (d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[num_bit_lengths]]) break; + num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1)); TDEFL_PUT_BITS(num_bit_lengths - 4, 4); + for (i = 0; (int)i < num_bit_lengths; i++) TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3); + + for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; ) + { + mz_uint code = packed_code_sizes[packed_code_sizes_index++]; MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2); + TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]); + if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]); + } +} + +static void tdefl_start_static_block(tdefl_compressor *d) +{ + mz_uint i; + mz_uint8 *p = &d->m_huff_code_sizes[0][0]; + + for (i = 0; i <= 143; ++i) *p++ = 8; + for ( ; i <= 255; ++i) *p++ = 9; + for ( ; i <= 279; ++i) *p++ = 7; + for ( ; i <= 287; ++i) *p++ = 8; + + memset(d->m_huff_code_sizes[1], 5, 32); + + tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE); + tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE); + + TDEFL_PUT_BITS(1, 2); +} + +static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS +static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d) +{ + mz_uint flags; + mz_uint8 *pLZ_codes; + mz_uint8 *pOutput_buf = d->m_pOutput_buf; + mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf; + mz_uint64 bit_buffer = d->m_bit_buffer; + mz_uint bits_in = d->m_bits_in; + +#define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); } + + flags = 1; + for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1) + { + if (flags == 1) + flags = *pLZ_codes++ | 0x100; + + if (flags & 1) + { + mz_uint s0, s1, n0, n1, sym, num_extra_bits; + mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3; + + MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]); + + // This sequence coaxes MSVC into using cmov's vs. jmp's. + s0 = s_tdefl_small_dist_sym[match_dist & 511]; + n0 = s_tdefl_small_dist_extra[match_dist & 511]; + s1 = s_tdefl_large_dist_sym[match_dist >> 8]; + n1 = s_tdefl_large_dist_extra[match_dist >> 8]; + sym = (match_dist < 512) ? s0 : s1; + num_extra_bits = (match_dist < 512) ? n0 : n1; + + MZ_ASSERT(d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits); + } + else + { + mz_uint lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + + if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) + { + flags >>= 1; + lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + + if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) + { + flags >>= 1; + lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + } + } + } + + if (pOutput_buf >= d->m_pOutput_buf_end) + return MZ_FALSE; + + *(mz_uint64*)pOutput_buf = bit_buffer; + pOutput_buf += (bits_in >> 3); + bit_buffer >>= (bits_in & ~7); + bits_in &= 7; + } + +#undef TDEFL_PUT_BITS_FAST + + d->m_pOutput_buf = pOutput_buf; + d->m_bits_in = 0; + d->m_bit_buffer = 0; + + while (bits_in) + { + mz_uint32 n = MZ_MIN(bits_in, 16); + TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n); + bit_buffer >>= n; + bits_in -= n; + } + + TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]); + + return (d->m_pOutput_buf < d->m_pOutput_buf_end); +} +#else +static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d) +{ + mz_uint flags; + mz_uint8 *pLZ_codes; + + flags = 1; + for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1) + { + if (flags == 1) + flags = *pLZ_codes++ | 0x100; + if (flags & 1) + { + mz_uint sym, num_extra_bits; + mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3; + + MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); + TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]); + + if (match_dist < 512) + { + sym = s_tdefl_small_dist_sym[match_dist]; num_extra_bits = s_tdefl_small_dist_extra[match_dist]; + } + else + { + sym = s_tdefl_large_dist_sym[match_dist >> 8]; num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8]; + } + MZ_ASSERT(d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]); + TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits); + } + else + { + mz_uint lit = *pLZ_codes++; + MZ_ASSERT(d->m_huff_code_sizes[0][lit]); + TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); + } + } + + TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]); + + return (d->m_pOutput_buf < d->m_pOutput_buf_end); +} +#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS + +static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block) +{ + if (static_block) + tdefl_start_static_block(d); + else + tdefl_start_dynamic_block(d); + return tdefl_compress_lz_codes(d); +} + +static int tdefl_flush_block(tdefl_compressor *d, int flush) +{ + mz_uint saved_bit_buf, saved_bits_in; + mz_uint8 *pSaved_output_buf; + mz_bool comp_block_succeeded = MZ_FALSE; + int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size; + mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf; + + d->m_pOutput_buf = pOutput_buf_start; + d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16; + + MZ_ASSERT(!d->m_output_flush_remaining); + d->m_output_flush_ofs = 0; + d->m_output_flush_remaining = 0; + + *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left); + d->m_pLZ_code_buf -= (d->m_num_flags_left == 8); + + if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index)) + { + TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8); + } + + TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1); + + pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in; + + if (!use_raw_block) + comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48)); + + // If the block gets expanded, forget the current contents of the output buffer and send a raw block instead. + if ( ((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) && + ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size) ) + { + mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in; + TDEFL_PUT_BITS(0, 2); + if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } + for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF) + { + TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16); + } + for (i = 0; i < d->m_total_lz_bytes; ++i) + { + TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8); + } + } + // Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes. + else if (!comp_block_succeeded) + { + d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in; + tdefl_compress_block(d, MZ_TRUE); + } + + if (flush) + { + if (flush == TDEFL_FINISH) + { + if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } + if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER) { mz_uint i, a = d->m_adler32; for (i = 0; i < 4; i++) { TDEFL_PUT_BITS((a >> 24) & 0xFF, 8); a <<= 8; } } + } + else + { + mz_uint i, z = 0; TDEFL_PUT_BITS(0, 3); if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } for (i = 2; i; --i, z ^= 0xFFFF) { TDEFL_PUT_BITS(z & 0xFFFF, 16); } + } + } + + MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end); + + memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); + memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); + + d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes; d->m_total_lz_bytes = 0; d->m_block_index++; + + if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0) + { + if (d->m_pPut_buf_func) + { + *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf; + if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user)) + return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED); + } + else if (pOutput_buf_start == d->m_output_buf) + { + int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs)); + memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy); + d->m_out_buf_ofs += bytes_to_copy; + if ((n -= bytes_to_copy) != 0) + { + d->m_output_flush_ofs = bytes_to_copy; + d->m_output_flush_remaining = n; + } + } + else + { + d->m_out_buf_ofs += n; + } + } + + return d->m_output_flush_remaining; +} + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" + +#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p) +static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) + +{ + mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; + mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; + const mz_uint16 *s = (const mz_uint16*)(d->m_dict + pos), *p, *q; + mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s); + MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return; + for ( ; ; ) + { + for ( ; ; ) + { + if (--num_probes_left == 0) return; + #define TDEFL_PROBE \ + next_probe_pos = d->m_next[probe_pos]; \ + if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \ + probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ + if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break; + TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; + } + if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32; + do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && + (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) ); + if (!probe_len) + { + *pMatch_dist = dist; *pMatch_len = MZ_MIN(max_match_len, TDEFL_MAX_MATCH_LEN); break; + } + else if ((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(const mz_uint8*)p == *(const mz_uint8*)q)) > match_len) + { + *pMatch_dist = dist; if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len) break; + c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]); + } + } +} + +#pragma GCC diagnostic pop + +#else + +#if defined(__aarch64__) || defined(__arm__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmisleading-indentation" +#endif + +static __forceinline void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) +{ + mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; + mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; + const mz_uint8 *s = d->m_dict + pos, *p, *q; + mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1]; + MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return; + for ( ; ; ) + { + for ( ; ; ) + { + if (--num_probes_left == 0) return; + #define TDEFL_PROBE \ + next_probe_pos = d->m_next[probe_pos]; \ + if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \ + probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ + if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break; + TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; + } + if (!dist) break; p = s; q = d->m_dict + probe_pos; for (probe_len = 0; probe_len < max_match_len; probe_len++) if (*p++ != *q++) break; + if (probe_len > match_len) + { + *pMatch_dist = dist; if ((*pMatch_len = match_len = probe_len) == max_match_len) return; + c0 = d->m_dict[pos + match_len]; c1 = d->m_dict[pos + match_len - 1]; + } + } +} + +#if defined(__aarch64__) || defined(__arm__) +#pragma GCC diagnostic pop +#endif + +#endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +static mz_bool tdefl_compress_fast(tdefl_compressor *d) +{ + // Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio. + mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left; + mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags; + mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK; + + while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size))) + { + const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096; + mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK; + mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size); + d->m_src_buf_left -= num_bytes_to_process; + lookahead_size += num_bytes_to_process; + + while (num_bytes_to_process) + { + mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process); + memcpy(d->m_dict + dst_pos, d->m_pSrc, n); + if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) + memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos)); + d->m_pSrc += n; + dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK; + num_bytes_to_process -= n; + } + + dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size); + if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE)) break; + + while (lookahead_size >= 4) + { + mz_uint cur_match_dist, cur_match_len = 1; + mz_uint8 *pCur_dict = d->m_dict + cur_pos; + mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF; + mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK; + mz_uint probe_pos = d->m_hash[hash]; + d->m_hash[hash] = (mz_uint16)lookahead_pos; + + if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram)) + { + const mz_uint16 *p = (const mz_uint16 *)pCur_dict; + const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos); + mz_uint32 probe_len = 32; + do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && + (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) ); + cur_match_len = ((mz_uint)(p - (const mz_uint16 *)pCur_dict) * 2) + (mz_uint)(*(const mz_uint8 *)p == *(const mz_uint8 *)q); + if (!probe_len) + cur_match_len = cur_match_dist ? TDEFL_MAX_MATCH_LEN : 0; + + if ((cur_match_len < TDEFL_MIN_MATCH_LEN) || ((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U*1024U))) + { + cur_match_len = 1; + *pLZ_code_buf++ = (mz_uint8)first_trigram; + *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); + d->m_huff_count[0][(mz_uint8)first_trigram]++; + } + else + { + mz_uint32 s0, s1; + cur_match_len = MZ_MIN(cur_match_len, lookahead_size); + + MZ_ASSERT((cur_match_len >= TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 1) && (cur_match_dist <= TDEFL_LZ_DICT_SIZE)); + + cur_match_dist--; + + pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN); + *(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist; + pLZ_code_buf += 3; + *pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80); + + s0 = s_tdefl_small_dist_sym[cur_match_dist & 511]; + s1 = s_tdefl_large_dist_sym[cur_match_dist >> 8]; + d->m_huff_count[1][(cur_match_dist < 512) ? s0 : s1]++; + + d->m_huff_count[0][s_tdefl_len_sym[cur_match_len - TDEFL_MIN_MATCH_LEN]]++; + } + } + else + { + *pLZ_code_buf++ = (mz_uint8)first_trigram; + *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); + d->m_huff_count[0][(mz_uint8)first_trigram]++; + } + + if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; } + + total_lz_bytes += cur_match_len; + lookahead_pos += cur_match_len; + dict_size = MZ_MIN(dict_size + cur_match_len, TDEFL_LZ_DICT_SIZE); + cur_pos = (cur_pos + cur_match_len) & TDEFL_LZ_DICT_SIZE_MASK; + MZ_ASSERT(lookahead_size >= cur_match_len); + lookahead_size -= cur_match_len; + + if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) + { + int n; + d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size; + d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left; + if ((n = tdefl_flush_block(d, 0)) != 0) + return (n < 0) ? MZ_FALSE : MZ_TRUE; + total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left; + } + } + + while (lookahead_size) + { + mz_uint8 lit = d->m_dict[cur_pos]; + + total_lz_bytes++; + *pLZ_code_buf++ = lit; + *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); + if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; } + + d->m_huff_count[0][lit]++; + + lookahead_pos++; + dict_size = MZ_MIN(dict_size + 1, TDEFL_LZ_DICT_SIZE); + cur_pos = (cur_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK; + lookahead_size--; + + if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) + { + int n; + d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size; + d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left; + if ((n = tdefl_flush_block(d, 0)) != 0) + return (n < 0) ? MZ_FALSE : MZ_TRUE; + total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left; + } + } + } + + d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size; + d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left; + return MZ_TRUE; +} +#pragma GCC diagnostic pop +#endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN + +static __forceinline void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit) +{ + d->m_total_lz_bytes++; + *d->m_pLZ_code_buf++ = lit; + *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; } + d->m_huff_count[0][lit]++; +} + +static __forceinline void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist) +{ + mz_uint32 s0, s1; + + MZ_ASSERT((match_len >= TDEFL_MIN_MATCH_LEN) && (match_dist >= 1) && (match_dist <= TDEFL_LZ_DICT_SIZE)); + + d->m_total_lz_bytes += match_len; + + d->m_pLZ_code_buf[0] = (mz_uint8)(match_len - TDEFL_MIN_MATCH_LEN); + + match_dist -= 1; + d->m_pLZ_code_buf[1] = (mz_uint8)(match_dist & 0xFF); + d->m_pLZ_code_buf[2] = (mz_uint8)(match_dist >> 8); d->m_pLZ_code_buf += 3; + + *d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; } + + s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[match_dist >> 8]; + d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++; + + d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++; +} + +static mz_bool tdefl_compress_normal(tdefl_compressor *d) +{ + const mz_uint8 *pSrc = d->m_pSrc; size_t src_buf_left = d->m_src_buf_left; + tdefl_flush flush = d->m_flush; + + while ((src_buf_left) || ((flush) && (d->m_lookahead_size))) + { + mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos; + // Update dictionary and hash chains. Keeps the lookahead size equal to TDEFL_MAX_MATCH_LEN. + if ((d->m_lookahead_size + d->m_dict_size) >= (TDEFL_MIN_MATCH_LEN - 1)) + { + mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2; + mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK]; + mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size); + const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process; + src_buf_left -= num_bytes_to_process; + d->m_lookahead_size += num_bytes_to_process; + while (pSrc != pSrc_end) + { + mz_uint8 c = *pSrc++; d->m_dict[dst_pos] = c; if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c; + hash = ((hash << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1); + d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; d->m_hash[hash] = (mz_uint16)(ins_pos); + dst_pos = (dst_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK; ins_pos++; + } + } + else + { + while ((src_buf_left) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN)) + { + mz_uint8 c = *pSrc++; + mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK; + src_buf_left--; + d->m_dict[dst_pos] = c; + if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) + d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c; + if ((++d->m_lookahead_size + d->m_dict_size) >= TDEFL_MIN_MATCH_LEN) + { + mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2; + mz_uint hash = ((d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << (TDEFL_LZ_HASH_SHIFT * 2)) ^ (d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1); + d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; d->m_hash[hash] = (mz_uint16)(ins_pos); + } + } + } + d->m_dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - d->m_lookahead_size, d->m_dict_size); + if ((!flush) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN)) + break; + + // Simple lazy/greedy parsing state machine. + len_to_move = 1; cur_match_dist = 0; cur_match_len = d->m_saved_match_len ? d->m_saved_match_len : (TDEFL_MIN_MATCH_LEN - 1); cur_pos = d->m_lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK; + if (d->m_flags & (TDEFL_RLE_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS)) + { + if ((d->m_dict_size) && (!(d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))) + { + mz_uint8 c = d->m_dict[(cur_pos - 1) & TDEFL_LZ_DICT_SIZE_MASK]; + cur_match_len = 0; while (cur_match_len < d->m_lookahead_size) { if (d->m_dict[cur_pos + cur_match_len] != c) break; cur_match_len++; } + if (cur_match_len < TDEFL_MIN_MATCH_LEN) cur_match_len = 0; else cur_match_dist = 1; + } + } + else + { + tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len); + } + if (((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U*1024U)) || (cur_pos == cur_match_dist) || ((d->m_flags & TDEFL_FILTER_MATCHES) && (cur_match_len <= 5))) + { + cur_match_dist = cur_match_len = 0; + } + if (d->m_saved_match_len) + { + if (cur_match_len > d->m_saved_match_len) + { + tdefl_record_literal(d, (mz_uint8)d->m_saved_lit); + if (cur_match_len >= 128) + { + tdefl_record_match(d, cur_match_len, cur_match_dist); + d->m_saved_match_len = 0; len_to_move = cur_match_len; + } + else + { + d->m_saved_lit = d->m_dict[cur_pos]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len; + } + } + else + { + tdefl_record_match(d, d->m_saved_match_len, d->m_saved_match_dist); + len_to_move = d->m_saved_match_len - 1; d->m_saved_match_len = 0; + } + } + else if (!cur_match_dist) + tdefl_record_literal(d, d->m_dict[cur_pos]); + else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128)) + { + tdefl_record_match(d, cur_match_len, cur_match_dist); + len_to_move = cur_match_len; + } + else + { + d->m_saved_lit = d->m_dict[cur_pos]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len; + } + // Move the lookahead forward by len_to_move bytes. + d->m_lookahead_pos += len_to_move; + MZ_ASSERT(d->m_lookahead_size >= len_to_move); + d->m_lookahead_size -= len_to_move; + d->m_dict_size = MZ_MIN(d->m_dict_size + len_to_move, TDEFL_LZ_DICT_SIZE); + // Check if it's time to flush the current LZ codes to the internal output buffer. + if ( (d->m_pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) || + ( (d->m_total_lz_bytes > 31*1024) && (((((mz_uint)(d->m_pLZ_code_buf - d->m_lz_code_buf) * 115) >> 7) >= d->m_total_lz_bytes) || (d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))) ) + { + int n; + d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left; + if ((n = tdefl_flush_block(d, 0)) != 0) + return (n < 0) ? MZ_FALSE : MZ_TRUE; + } + } + + d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left; + return MZ_TRUE; +} + +static tdefl_status tdefl_flush_output_buffer(tdefl_compressor *d) +{ + if (d->m_pIn_buf_size) + { + *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf; + } + + if (d->m_pOut_buf_size) + { + size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining); + memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n); + d->m_output_flush_ofs += (mz_uint)n; + d->m_output_flush_remaining -= (mz_uint)n; + d->m_out_buf_ofs += n; + + *d->m_pOut_buf_size = d->m_out_buf_ofs; + } + + return (d->m_finished && !d->m_output_flush_remaining) ? TDEFL_STATUS_DONE : TDEFL_STATUS_OKAY; +} + +tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush) +{ + if (!d) + { + if (pIn_buf_size) *pIn_buf_size = 0; + if (pOut_buf_size) *pOut_buf_size = 0; + return TDEFL_STATUS_BAD_PARAM; + } + + d->m_pIn_buf = pIn_buf; d->m_pIn_buf_size = pIn_buf_size; + d->m_pOut_buf = pOut_buf; d->m_pOut_buf_size = pOut_buf_size; + d->m_pSrc = (const mz_uint8 *)(pIn_buf); d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0; + d->m_out_buf_ofs = 0; + d->m_flush = flush; + + if ( ((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status != TDEFL_STATUS_OKAY) || + (d->m_wants_to_finish && (flush != TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf) ) + { + if (pIn_buf_size) *pIn_buf_size = 0; + if (pOut_buf_size) *pOut_buf_size = 0; + return (d->m_prev_return_status = TDEFL_STATUS_BAD_PARAM); + } + d->m_wants_to_finish |= (flush == TDEFL_FINISH); + + if ((d->m_output_flush_remaining) || (d->m_finished)) + return (d->m_prev_return_status = tdefl_flush_output_buffer(d)); + +#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN + if (((d->m_flags & TDEFL_MAX_PROBES_MASK) == 1) && + ((d->m_flags & TDEFL_GREEDY_PARSING_FLAG) != 0) && + ((d->m_flags & (TDEFL_FILTER_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS | TDEFL_RLE_MATCHES)) == 0)) + { + if (!tdefl_compress_fast(d)) + return d->m_prev_return_status; + } + else +#endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN + { + if (!tdefl_compress_normal(d)) + return d->m_prev_return_status; + } + + if ((d->m_flags & (TDEFL_WRITE_ZLIB_HEADER | TDEFL_COMPUTE_ADLER32)) && (pIn_buf)) + d->m_adler32 = (mz_uint32)mz_adler32(d->m_adler32, (const mz_uint8 *)pIn_buf, d->m_pSrc - (const mz_uint8 *)pIn_buf); + + if (d->m_flags & TDEFL_COMPUTE_CRC32) + d->m_crc32 = (mz_uint32)mz_crc32(d->m_crc32, (const mz_uint8 *)pIn_buf, d->m_pSrc - (const mz_uint8 *)pIn_buf); + + if ((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining)) + { + if (tdefl_flush_block(d, flush) < 0) + return d->m_prev_return_status; + d->m_finished = (flush == TDEFL_FINISH); + if (flush == TDEFL_FULL_FLUSH) { MZ_CLEAR_OBJ(d->m_hash); MZ_CLEAR_OBJ(d->m_next); d->m_dict_size = 0; } + } + + return (d->m_prev_return_status = tdefl_flush_output_buffer(d)); +} + +tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush) +{ + MZ_ASSERT(d->m_pPut_buf_func); return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush); +} + +tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) +{ + d->m_pPut_buf_func = pPut_buf_func; d->m_pPut_buf_user = pPut_buf_user; + d->m_flags = (mz_uint)(flags); d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3; d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0; + d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3; + if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) MZ_CLEAR_OBJ(d->m_hash); + d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0; + d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0; + d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; + d->m_pOutput_buf = d->m_output_buf; d->m_pOutput_buf_end = d->m_output_buf; d->m_prev_return_status = TDEFL_STATUS_OKAY; + d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0; d->m_adler32 = 1; d->m_crc32 = 1; + d->m_pIn_buf = NULL; d->m_pOut_buf = NULL; + d->m_pIn_buf_size = NULL; d->m_pOut_buf_size = NULL; + d->m_flush = TDEFL_NO_FLUSH; d->m_pSrc = NULL; d->m_src_buf_left = 0; d->m_out_buf_ofs = 0; + memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); + memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); + return TDEFL_STATUS_OKAY; +} + +tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d) +{ + return d->m_prev_return_status; +} + +mz_uint32 tdefl_get_adler32(tdefl_compressor *d) +{ + return d->m_adler32; +} + +mz_uint32 tdefl_get_crc32(tdefl_compressor *d) +{ + return d->m_crc32; +} + +mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) +{ + tdefl_compressor *pComp; mz_bool succeeded; if (((buf_len) && (!pBuf)) || (!pPut_buf_func)) return MZ_FALSE; + pComp = (tdefl_compressor*)MZ_MALLOC(sizeof(tdefl_compressor)); if (!pComp) return MZ_FALSE; + succeeded = (tdefl_init(pComp, pPut_buf_func, pPut_buf_user, flags) == TDEFL_STATUS_OKAY); + succeeded = succeeded && (tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE); + MZ_FREE(pComp); return succeeded; +} + +typedef struct +{ + size_t m_size, m_capacity; + mz_uint8 *m_pBuf; + mz_bool m_expandable; +} tdefl_output_buffer; + +static mz_bool tdefl_output_buffer_putter(const void *pBuf, int len, void *pUser) +{ + tdefl_output_buffer *p = (tdefl_output_buffer *)pUser; + size_t new_size = p->m_size + len; + if (new_size > p->m_capacity) + { + size_t new_capacity = p->m_capacity; mz_uint8 *pNew_buf; if (!p->m_expandable) return MZ_FALSE; + do { new_capacity = MZ_MAX(128U, new_capacity << 1U); } while (new_size > new_capacity); + pNew_buf = (mz_uint8*)MZ_REALLOC(p->m_pBuf, new_capacity); if (!pNew_buf) return MZ_FALSE; + p->m_pBuf = pNew_buf; p->m_capacity = new_capacity; + } + memcpy((mz_uint8*)p->m_pBuf + p->m_size, pBuf, len); p->m_size = new_size; + return MZ_TRUE; +} + +void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags) +{ + tdefl_output_buffer out_buf; MZ_CLEAR_OBJ(out_buf); + if (!pOut_len) return MZ_FALSE; else *pOut_len = 0; + out_buf.m_expandable = MZ_TRUE; + if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) return NULL; + *pOut_len = out_buf.m_size; return out_buf.m_pBuf; +} + +size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags) +{ + tdefl_output_buffer out_buf; MZ_CLEAR_OBJ(out_buf); + if (!pOut_buf) return 0; + out_buf.m_pBuf = (mz_uint8*)pOut_buf; out_buf.m_capacity = out_buf_len; + if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) return 0; + return out_buf.m_size; +} + +static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 }; + +// level may actually range from [0,10] (10 is a "hidden" max level, where we want a bit more compression and it's fine if throughput to fall off a cliff on some files). +mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy) +{ + mz_uint comp_flags = s_tdefl_num_probes[(level >= 0) ? MZ_MIN(10, level) : MZ_DEFAULT_LEVEL] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0); + if (window_bits > 0) comp_flags |= TDEFL_WRITE_ZLIB_HEADER; + + if (!level) comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS; + else if (strategy == MZ_FILTERED) comp_flags |= TDEFL_FILTER_MATCHES; + else if (strategy == MZ_HUFFMAN_ONLY) comp_flags &= ~TDEFL_MAX_PROBES_MASK; + else if (strategy == MZ_FIXED) comp_flags |= TDEFL_FORCE_ALL_STATIC_BLOCKS; + else if (strategy == MZ_RLE) comp_flags |= TDEFL_RLE_MATCHES; + + return comp_flags; +} + +#ifdef _MSC_VER +#pragma warning (push) +#pragma warning (disable:4204) // nonstandard extension used : non-constant aggregate initializer (also supported by GNU C and C99, so no big deal) +#endif + +// Simple PNG writer function by Alex Evans, 2011. Released into the public domain: https://gist.github.com/908299, more context at +// http://altdevblogaday.org/2011/04/06/a-smaller-jpg-encoder/. +void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out) +{ + tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); tdefl_output_buffer out_buf; int i, bpl = w * num_chans, y, z; mz_uint32 c; *pLen_out = 0; + if (!pComp) return NULL; + MZ_CLEAR_OBJ(out_buf); out_buf.m_expandable = MZ_TRUE; out_buf.m_capacity = 57+MZ_MAX(64, (1+bpl)*h); if (NULL == (out_buf.m_pBuf = (mz_uint8*)MZ_MALLOC(out_buf.m_capacity))) { MZ_FREE(pComp); return NULL; } + // write dummy header + for (z = 41; z; --z) tdefl_output_buffer_putter(&z, 1, &out_buf); + // compress image data + tdefl_init(pComp, tdefl_output_buffer_putter, &out_buf, TDEFL_DEFAULT_MAX_PROBES | TDEFL_WRITE_ZLIB_HEADER); + for (y = 0; y < h; ++y) { tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH); tdefl_compress_buffer(pComp, (mz_uint8*)pImage + y * bpl, bpl, TDEFL_NO_FLUSH); } + if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE) { MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; } + // write real header + *pLen_out = out_buf.m_size-41; + { + mz_uint8 pnghdr[41]={0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, + 0,0,(mz_uint8)(w>>8),(mz_uint8)w,0,0,(mz_uint8)(h>>8),(mz_uint8)h,8,"\0\0\04\02\06"[num_chans],0,0,0,0,0,0,0, + (mz_uint8)(*pLen_out>>24),(mz_uint8)(*pLen_out>>16),(mz_uint8)(*pLen_out>>8),(mz_uint8)*pLen_out,0x49,0x44,0x41,0x54}; + c=(mz_uint32)mz_crc32(MZ_CRC32_INIT,pnghdr+12,17); for (i=0; i<4; ++i, c<<=8) ((mz_uint8*)(pnghdr+29))[i]=(mz_uint8)(c>>24); + memcpy(out_buf.m_pBuf, pnghdr, 41); + } + // write footer (IDAT CRC-32, followed by IEND chunk) + if (!tdefl_output_buffer_putter("\0\0\0\0\0\0\0\0\x49\x45\x4e\x44\xae\x42\x60\x82", 16, &out_buf)) { *pLen_out = 0; MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; } + c = (mz_uint32)mz_crc32(MZ_CRC32_INIT,out_buf.m_pBuf+41-4, *pLen_out+4); for (i=0; i<4; ++i, c<<=8) (out_buf.m_pBuf+out_buf.m_size-16)[i] = (mz_uint8)(c >> 24); + // compute final size of file, grab compressed data buffer and return + *pLen_out += 57; MZ_FREE(pComp); return out_buf.m_pBuf; +} + +#ifdef _MSC_VER +#pragma warning (pop) +#endif + +#pragma GCC diagnostic pop + +#endif // MINIZ_HEADER_FILE_ONLY + +/* + This is free and unencumbered software released into the public domain. + + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. + + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + For more information, please refer to +*/ diff --git a/src/grub2/miniz.h b/src/grub2/miniz.h new file mode 100644 index 0000000..971d34e --- /dev/null +++ b/src/grub2/miniz.h @@ -0,0 +1,2 @@ +#define MINIZ_HEADER_FILE_ONLY +#include "miniz.c" diff --git a/src/grub2/wimboot.h b/src/grub2/wimboot.h new file mode 100644 index 0000000..f6f9a38 --- /dev/null +++ b/src/grub2/wimboot.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * wimboot.h + * + * Copyright (c) 2020, longpanda + * + * 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 . + * + */ +#ifndef __WIMBOOT_H__ +#define __WIMBOOT_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiperiso_def.h" + + +#define size_t grub_size_t +#define ssize_t grub_ssize_t +#define memset grub_memset +#define memcpy grub_memcpy + +#define uint8_t grub_uint8_t +#define uint16_t grub_uint16_t +#define uint32_t grub_uint32_t +#define uint64_t grub_uint64_t +#define int32_t grub_int32_t + + + +#define assert(exp) + +//#define DBG grub_printf +#define DBG(fmt, ...) + +const char * huffman_bin ( unsigned long value, unsigned int bits ); + +#endif + diff --git a/src/grub2/xpress.c b/src/grub2/xpress.c new file mode 100644 index 0000000..bfb3125 --- /dev/null +++ b/src/grub2/xpress.c @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2012 Michael Brown . + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * @file + * + * Xpress Compression Algorithm (MS-XCA) decompression + * + */ + +#include "wimboot.h" +#include "huffman.h" +#include "xpress.h" + +#pragma GCC diagnostic ignored "-Wcast-align" + +/** + * Decompress XCA-compressed data + * + * @v data Compressed data + * @v len Length of compressed data + * @v buf Decompression buffer, or NULL + * @ret out_len Length of decompressed data, or negative error + */ +ssize_t xca_decompress ( const void *data, size_t len, void *buf ) { + const void *src = data; + const void *end = ( uint8_t * ) src + len; + uint8_t *out = buf; + size_t out_len = 0; + size_t out_len_threshold = 0; + const struct xca_huf_len *lengths; + struct xca xca; + uint32_t accum = 0; + int extra_bits = 0; + unsigned int huf; + struct huffman_symbols *sym; + unsigned int raw; + unsigned int match_len; + unsigned int match_offset_bits; + unsigned int match_offset; + const uint8_t *copy; + int rc; + + /* Process data stream */ + while ( src < end ) { + + /* (Re)initialise decompressor if applicable */ + if ( out_len >= out_len_threshold ) { + + /* Construct symbol lengths */ + lengths = src; + src = ( uint8_t * ) src + sizeof ( *lengths ); + if ( src > end ) { + DBG ( "XCA too short to hold Huffman lengths table.\n"); + return -1; + } + for ( raw = 0 ; raw < XCA_CODES ; raw++ ) + xca.lengths[raw] = xca_huf_len ( lengths, raw ); + + /* Construct Huffman alphabet */ + if ( ( rc = huffman_alphabet ( &xca.alphabet, + xca.lengths, + XCA_CODES ) ) != 0 ) + return rc; + + /* Initialise state */ + accum = XCA_GET16 ( src ); + accum <<= 16; + accum |= XCA_GET16 ( src ); + extra_bits = 16; + + /* Determine next threshold */ + out_len_threshold = ( out_len + XCA_BLOCK_SIZE ); + } + + /* Determine symbol */ + huf = ( accum >> ( 32 - HUFFMAN_BITS ) ); + sym = huffman_sym ( &xca.alphabet, huf ); + raw = huffman_raw ( sym, huf ); + accum <<= huffman_len ( sym ); + extra_bits -= huffman_len ( sym ); + if ( extra_bits < 0 ) { + accum |= ( XCA_GET16 ( src ) << ( -extra_bits ) ); + extra_bits += 16; + } + + /* Process symbol */ + if ( raw < XCA_END_MARKER ) { + + /* Literal symbol - add to output stream */ + if ( buf ) + *(out++) = raw; + out_len++; + + } else if ( ( raw == XCA_END_MARKER ) && + ( (uint8_t *) src >= ( ( uint8_t * ) end - 1 ) ) ) { + + /* End marker symbol */ + return out_len; + + } else { + + /* LZ77 match symbol */ + raw -= XCA_END_MARKER; + match_offset_bits = ( raw >> 4 ); + match_len = ( raw & 0x0f ); + if ( match_len == 0x0f ) { + match_len = XCA_GET8 ( src ); + if ( match_len == 0xff ) { + match_len = XCA_GET16 ( src ); + } else { + match_len += 0x0f; + } + } + match_len += 3; + if ( match_offset_bits ) { + match_offset = + ( ( accum >> ( 32 - match_offset_bits )) + + ( 1 << match_offset_bits ) ); + } else { + match_offset = 1; + } + accum <<= match_offset_bits; + extra_bits -= match_offset_bits; + if ( extra_bits < 0 ) { + accum |= ( XCA_GET16 ( src ) << (-extra_bits) ); + extra_bits += 16; + } + + /* Copy data */ + out_len += match_len; + if ( buf ) { + copy = ( out - match_offset ); + while ( match_len-- ) + *(out++) = *(copy++); + } + } + } + + return out_len; +} diff --git a/src/grub2/xpress.h b/src/grub2/xpress.h new file mode 100644 index 0000000..6a430f7 --- /dev/null +++ b/src/grub2/xpress.h @@ -0,0 +1,87 @@ +#ifndef _XCA_H +#define _XCA_H + +/* + * Copyright (C) 2012 Michael Brown . + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/** + * @file + * + * Xpress Compression Algorithm (MS-XCA) decompression + * + */ + +#include "huffman.h" + +/** Number of XCA codes */ +#define XCA_CODES 512 + +/** XCA decompressor */ +struct xca { + /** Huffman alphabet */ + struct huffman_alphabet alphabet; + /** Raw symbols + * + * Must immediately follow the Huffman alphabet. + */ + huffman_raw_symbol_t raw[XCA_CODES]; + /** Code lengths */ + uint8_t lengths[XCA_CODES]; +}; + +/** XCA symbol Huffman lengths table */ +struct xca_huf_len { + /** Lengths of each symbol */ + uint8_t nibbles[ XCA_CODES / 2 ]; +} __attribute__ (( packed )); + +/** + * Extract Huffman-coded length of a raw symbol + * + * @v lengths Huffman lengths table + * @v symbol Raw symbol + * @ret len Huffman-coded length + */ +static inline unsigned int xca_huf_len ( const struct xca_huf_len *lengths, + unsigned int symbol ) { + return ( ( ( lengths->nibbles[ symbol / 2 ] ) >> + ( 4 * ( symbol % 2 ) ) ) & 0x0f ); +} + +/** Get word from source data stream */ +#define XCA_GET16( src ) ( { \ + const uint16_t *src16 = src; \ + src = ( uint8_t * ) src + sizeof ( *src16 ); \ + *src16; } ) + +/** Get byte from source data stream */ +#define XCA_GET8( src ) ( { \ + const uint8_t *src8 = src; \ + src = ( uint8_t * ) src + sizeof ( *src8 ); \ + *src8; } ) + +/** XCA source data stream end marker */ +#define XCA_END_MARKER 256 + +/** XCA block size */ +#define XCA_BLOCK_SIZE ( 64 * 1024 ) + +extern ssize_t xca_decompress ( const void *data, size_t len, void *buf ); + +#endif /* _XCA_H */