Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dadigang
Ventoy
Commits
595b9441
Commit
595b9441
authored
Jun 15, 2022
by
longpanda
Browse files
Support prameters expansion in auto install script.
parent
0f3d48b3
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
381 additions
and
53 deletions
+381
-53
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
+19
-0
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
+193
-0
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
+19
-2
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c
+11
-20
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c
+11
-1
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
+65
-20
GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h
GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h
+7
-1
INSTALL/ventoy/vtoyjump32.exe
INSTALL/ventoy/vtoyjump32.exe
+0
-0
INSTALL/ventoy/vtoyjump64.exe
INSTALL/ventoy/vtoyjump64.exe
+0
-0
vtoyjump/vtoyjump/vtoyjump.c
vtoyjump/vtoyjump/vtoyjump.c
+47
-8
vtoyjump/vtoyjump/vtoyjump.h
vtoyjump/vtoyjump/vtoyjump.h
+9
-1
No files found.
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
View file @
595b9441
...
@@ -76,7 +76,26 @@ void ventoy_str_toupper(char *str)
...
@@ -76,7 +76,26 @@ void ventoy_str_toupper(char *str)
}
}
}
}
char
*
ventoy_str_last
(
char
*
str
,
char
ch
)
{
char
*
pos
=
NULL
;
char
*
last
=
NULL
;
if
(
!
str
)
{
return
NULL
;
}
for
(
pos
=
str
;
*
pos
;
pos
++
)
{
if
(
*
pos
==
ch
)
{
last
=
pos
;
}
}
return
last
;
}
int
ventoy_strcmp
(
const
char
*
pattern
,
const
char
*
str
)
int
ventoy_strcmp
(
const
char
*
pattern
,
const
char
*
str
)
{
{
...
...
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
View file @
595b9441
...
@@ -45,6 +45,7 @@
...
@@ -45,6 +45,7 @@
#include <grub/charset.h>
#include <grub/charset.h>
#include <grub/crypto.h>
#include <grub/crypto.h>
#include <grub/lib/crc.h>
#include <grub/lib/crc.h>
#include <grub/random.h>
#include <grub/ventoy.h>
#include <grub/ventoy.h>
#include "ventoy_def.h"
#include "ventoy_def.h"
#include "miniz.h"
#include "miniz.h"
...
@@ -3366,12 +3367,177 @@ end:
...
@@ -3366,12 +3367,177 @@ end:
VENTOY_CMD_RETURN
(
GRUB_ERR_NONE
);
VENTOY_CMD_RETURN
(
GRUB_ERR_NONE
);
}
}
static
int
ventoy_var_expand
(
int
*
flag
,
const
char
*
var
,
char
*
value
,
int
len
)
{
int
i
=
0
;
int
n
=
0
;
char
c
;
grub_uint8_t
bytes
[
32
];
if
(
grub_strncmp
(
var
,
"VT_RAND_"
,
8
)
==
0
)
{
grub_crypto_get_random
(
bytes
,
sizeof
(
bytes
));
if
(
grub_strcmp
(
var
+
8
,
"9"
)
==
0
)
{
n
=
1
;
}
else
if
(
grub_strcmp
(
var
+
8
,
"99"
)
==
0
)
{
n
=
2
;
}
else
if
(
grub_strcmp
(
var
+
8
,
"999"
)
==
0
)
{
n
=
3
;
}
else
if
(
grub_strcmp
(
var
+
8
,
"9999"
)
==
0
)
{
n
=
4
;
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
value
[
i
]
=
'0'
+
(
bytes
[
i
]
%
10
);
}
}
else
{
if
(
*
flag
==
0
)
{
*
flag
=
1
;
grub_printf
(
"
\n
=================== Parameter Expansion ===================
\n\n
"
);
}
grub_printf
(
"<%s>: "
,
var
);
grub_refresh
();
while
(
i
<
(
len
-
1
))
{
c
=
grub_getkey
();
if
((
c
==
'\n'
)
||
(
c
==
'\r'
))
{
grub_printf
(
"
\n
"
);
grub_refresh
();
break
;
}
if
(
grub_isprint
(
c
))
{
grub_printf
(
"%c"
,
c
);
grub_refresh
();
value
[
i
++
]
=
c
;
value
[
i
]
=
0
;
}
else
if
(
c
==
'\b'
)
{
if
(
i
>
0
)
{
value
[
i
-
1
]
=
' '
;
grub_printf
(
"
\r
<%s>: %s"
,
var
,
value
);
value
[
i
-
1
]
=
0
;
grub_printf
(
"
\r
<%s>: %s"
,
var
,
value
);
grub_refresh
();
i
--
;
}
}
}
}
if
(
value
[
0
]
==
0
)
{
grub_snprintf
(
value
,
len
,
"%s"
,
var
);
}
return
0
;
}
static
int
ventoy_auto_install_var_expand
(
install_template
*
node
)
{
int
pos
=
0
;
int
flag
=
0
;
int
newlen
=
0
;
char
*
start
=
NULL
;
char
*
end
=
NULL
;
char
*
newbuf
=
NULL
;
char
*
curline
=
NULL
;
char
*
nextline
=
NULL
;
grub_uint8_t
*
code
=
NULL
;
char
value
[
512
];
code
=
(
grub_uint8_t
*
)
node
->
filebuf
;
if
((
code
[
0
]
==
0xff
&&
code
[
1
]
==
0xfe
)
||
(
code
[
0
]
==
0xfe
&&
code
[
1
]
==
0xff
))
{
debug
(
"UCS-2 encoding NOT supported
\n
"
);
return
0
;
}
start
=
grub_strstr
(
node
->
filebuf
,
"$<"
);
if
(
!
start
)
{
debug
(
"no need to expand variable, no start.
\n
"
);
return
0
;
}
end
=
grub_strstr
(
start
+
2
,
">$"
);
if
(
!
end
)
{
debug
(
"no need to expand variable, no end.
\n
"
);
return
0
;
}
newlen
=
grub_max
(
node
->
filelen
*
10
,
VTOY_SIZE_128KB
);
newbuf
=
grub_malloc
(
newlen
);
if
(
!
newbuf
)
{
debug
(
"Failed to alloc newbuf %d
\n
"
,
newlen
);
return
0
;
}
for
(
curline
=
node
->
filebuf
;
curline
;
curline
=
nextline
)
{
nextline
=
ventoy_get_line
(
curline
);
start
=
grub_strstr
(
curline
,
"$<"
);
if
(
start
)
{
end
=
grub_strstr
(
start
+
2
,
">$"
);
}
if
(
start
&&
end
)
{
*
start
=
*
end
=
0
;
VTOY_APPEND_NEWBUF
(
curline
);
value
[
sizeof
(
value
)
-
1
]
=
0
;
ventoy_var_expand
(
&
flag
,
start
+
2
,
value
,
sizeof
(
value
)
-
1
);
VTOY_APPEND_NEWBUF
(
value
);
VTOY_APPEND_NEWBUF
(
end
+
2
);
}
else
{
VTOY_APPEND_NEWBUF
(
curline
);
}
newbuf
[
pos
++
]
=
'\n'
;
}
grub_free
(
node
->
filebuf
);
node
->
filebuf
=
newbuf
;
node
->
filelen
=
pos
;
return
0
;
}
static
grub_err_t
ventoy_cmd_sel_auto_install
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
static
grub_err_t
ventoy_cmd_sel_auto_install
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
{
{
int
i
=
0
;
int
i
=
0
;
int
pos
=
0
;
int
pos
=
0
;
int
defidx
=
1
;
int
defidx
=
1
;
char
*
buf
=
NULL
;
char
*
buf
=
NULL
;
grub_file_t
file
=
NULL
;
char
configfile
[
128
];
char
configfile
[
128
];
install_template
*
node
=
NULL
;
install_template
*
node
=
NULL
;
...
@@ -3440,6 +3606,33 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
...
@@ -3440,6 +3606,33 @@ static grub_err_t ventoy_cmd_sel_auto_install(grub_extcmd_context_t ctxt, int ar
node
->
cursel
=
g_ventoy_last_entry
-
1
;
node
->
cursel
=
g_ventoy_last_entry
-
1
;
grub_check_free
(
node
->
filebuf
);
node
->
filelen
=
0
;
if
(
node
->
cursel
>=
0
&&
node
->
cursel
<
node
->
templatenum
)
{
file
=
ventoy_grub_file_open
(
VENTOY_FILE_TYPE
,
"%s%s"
,
ventoy_get_env
(
"vtoy_iso_part"
),
node
->
templatepath
[
node
->
cursel
].
path
);
if
(
file
)
{
node
->
filebuf
=
grub_malloc
(
file
->
size
+
1
);
if
(
node
->
filebuf
)
{
grub_file_read
(
file
,
node
->
filebuf
,
file
->
size
);
grub_file_close
(
file
);
node
->
filebuf
[
file
->
size
]
=
0
;
node
->
filelen
=
(
int
)
file
->
size
;
ventoy_auto_install_var_expand
(
node
);
}
}
else
{
debug
(
"Failed to open auto install script <%s%s>
\n
"
,
ventoy_get_env
(
"vtoy_iso_part"
),
node
->
templatepath
[
node
->
cursel
].
path
);
}
}
VENTOY_CMD_RETURN
(
GRUB_ERR_NONE
);
VENTOY_CMD_RETURN
(
GRUB_ERR_NONE
);
}
}
...
...
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
View file @
595b9441
...
@@ -36,11 +36,14 @@
...
@@ -36,11 +36,14 @@
#define VTOY_SIZE_512KB (512 * 1024)
#define VTOY_SIZE_512KB (512 * 1024)
#define VTOY_SIZE_1KB 1024
#define VTOY_SIZE_1KB 1024
#define VTOY_SIZE_32KB (32 * 1024)
#define VTOY_SIZE_32KB (32 * 1024)
#define VTOY_SIZE_128KB (128 * 1024)
#define JSON_SUCCESS 0
#define JSON_SUCCESS 0
#define JSON_FAILED 1
#define JSON_FAILED 1
#define JSON_NOT_FOUND 2
#define JSON_NOT_FOUND 2
#define WINDATA_FLAG_TEMPLATE 1
#define ulong unsigned long
#define ulong unsigned long
#define ulonglong unsigned long long
#define ulonglong unsigned long long
...
@@ -84,6 +87,16 @@
...
@@ -84,6 +87,16 @@
return (err);\
return (err);\
}
}
#define VTOY_APPEND_NEWBUF(buf) \
{\
char *__c = buf;\
while (*__c)\
{\
newbuf[pos++] = *__c;\
__c++;\
}\
}
typedef
enum
VTOY_FILE_FLT
typedef
enum
VTOY_FILE_FLT
{
{
VTOY_FILE_FLT_ISO
=
0
,
/* .iso */
VTOY_FILE_FLT_ISO
=
0
,
/* .iso */
...
@@ -488,6 +501,7 @@ typedef struct wim_tail
...
@@ -488,6 +501,7 @@ typedef struct wim_tail
grub_uint8_t
*
jump_bin_data
;
grub_uint8_t
*
jump_bin_data
;
grub_uint32_t
bin_raw_len
;
grub_uint32_t
bin_raw_len
;
grub_uint32_t
bin_align_len
;
grub_uint32_t
bin_align_len
;
grub_uint32_t
windata_flag
;
grub_uint8_t
*
new_meta_data
;
grub_uint8_t
*
new_meta_data
;
grub_uint32_t
new_meta_len
;
grub_uint32_t
new_meta_len
;
...
@@ -853,6 +867,9 @@ typedef struct install_template
...
@@ -853,6 +867,9 @@ typedef struct install_template
int
templatenum
;
int
templatenum
;
file_fullpath
*
templatepath
;
file_fullpath
*
templatepath
;
char
*
filebuf
;
int
filelen
;
struct
install_template
*
next
;
struct
install_template
*
next
;
}
install_template
;
}
install_template
;
...
@@ -1061,15 +1078,15 @@ extern grub_uint32_t g_ventoy_plat_data;
...
@@ -1061,15 +1078,15 @@ extern grub_uint32_t g_ventoy_plat_data;
void
ventoy_str_tolower
(
char
*
str
);
void
ventoy_str_tolower
(
char
*
str
);
void
ventoy_str_toupper
(
char
*
str
);
void
ventoy_str_toupper
(
char
*
str
);
char
*
ventoy_get_line
(
char
*
start
);
char
*
ventoy_get_line
(
char
*
start
);
char
*
ventoy_str_last
(
char
*
str
,
char
ch
);
int
ventoy_cmp_img
(
img_info
*
img1
,
img_info
*
img2
);
int
ventoy_cmp_img
(
img_info
*
img1
,
img_info
*
img2
);
void
ventoy_swap_img
(
img_info
*
img1
,
img_info
*
img2
);
void
ventoy_swap_img
(
img_info
*
img1
,
img_info
*
img2
);
char
*
ventoy_plugin_get_cur_install_template
(
const
char
*
isopath
);
char
*
ventoy_plugin_get_cur_install_template
(
const
char
*
isopath
,
install_template
**
cur
);
install_template
*
ventoy_plugin_find_install_template
(
const
char
*
isopath
);
install_template
*
ventoy_plugin_find_install_template
(
const
char
*
isopath
);
persistence_config
*
ventoy_plugin_find_persistent
(
const
char
*
isopath
);
persistence_config
*
ventoy_plugin_find_persistent
(
const
char
*
isopath
);
grub_uint64_t
ventoy_get_vtoy_partsize
(
int
part
);
grub_uint64_t
ventoy_get_vtoy_partsize
(
int
part
);
void
ventoy_plugin_dump_injection
(
void
);
void
ventoy_plugin_dump_injection
(
void
);
void
ventoy_plugin_dump_auto_install
(
void
);
void
ventoy_plugin_dump_auto_install
(
void
);
int
ventoy_fill_windows_rtdata
(
void
*
buf
,
char
*
isopath
);
int
ventoy_plugin_get_persistent_chunklist
(
const
char
*
isopath
,
int
index
,
ventoy_img_chunk_list
*
chunk_list
);
int
ventoy_plugin_get_persistent_chunklist
(
const
char
*
isopath
,
int
index
,
ventoy_img_chunk_list
*
chunk_list
);
const
char
*
ventoy_plugin_get_injection
(
const
char
*
isopath
);
const
char
*
ventoy_plugin_get_injection
(
const
char
*
isopath
);
const
char
*
ventoy_plugin_get_menu_alias
(
int
type
,
const
char
*
isopath
);
const
char
*
ventoy_plugin_get_menu_alias
(
int
type
,
const
char
*
isopath
);
...
...
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c
View file @
595b9441
...
@@ -1211,6 +1211,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
...
@@ -1211,6 +1211,7 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
grub_file_t
file
;
grub_file_t
file
;
grub_file_t
archfile
;
grub_file_t
archfile
;
grub_file_t
tmpfile
;
grub_file_t
tmpfile
;
install_template
*
template_node
=
NULL
;
ventoy_img_chunk_list
chunk_list
;
ventoy_img_chunk_list
chunk_list
;
(
void
)
ctxt
;
(
void
)
ctxt
;
...
@@ -1257,26 +1258,17 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
...
@@ -1257,26 +1258,17 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
persistent_buf
=
(
char
*
)(
chunk_list
.
chunk
);
persistent_buf
=
(
char
*
)(
chunk_list
.
chunk
);
}
}
template_file
=
ventoy_plugin_get_cur_install_template
(
args
[
1
]);
template_file
=
ventoy_plugin_get_cur_install_template
(
args
[
1
]
,
&
template_node
);
if
(
template_file
)
if
(
template_file
)
{
{
debug
(
"auto install template: <%s>
\n
"
,
template_file
);
debug
(
"auto install template: <%s> <addr:%p> <len:%d>
\n
"
,
tmpfile
=
ventoy_grub_file_open
(
VENTOY_FILE_TYPE
,
"%s%s"
,
args
[
2
],
template_file
);
template_file
,
template_node
->
filebuf
,
template_node
->
filelen
);
if
(
tmpfile
)
{
template_size
=
template_node
->
filelen
;
debug
(
"auto install script size %d
\n
"
,
(
int
)
tmpfile
->
size
);
template_buf
=
grub_malloc
(
template_size
);
template_size
=
tmpfile
->
size
;
if
(
template_buf
)
template_buf
=
grub_malloc
(
template_size
);
if
(
template_buf
)
{
grub_file_read
(
tmpfile
,
template_buf
,
template_size
);
}
grub_file_close
(
tmpfile
);
}
else
{
{
debug
(
"Failed to open install script %s%s
\n
"
,
args
[
2
]
,
template_
fil
e
);
grub_memcpy
(
template_buf
,
template_node
->
filebuf
,
template_
siz
e
);
}
}
}
}
else
else
...
@@ -1363,15 +1355,14 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
...
@@ -1363,15 +1355,14 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
{
{
headlen
=
ventoy_cpio_newc_fill_head
(
buf
,
template_size
,
template_buf
,
"ventoy/autoinstall"
);
headlen
=
ventoy_cpio_newc_fill_head
(
buf
,
template_size
,
template_buf
,
"ventoy/autoinstall"
);
buf
+=
headlen
+
ventoy_align
(
template_size
,
4
);
buf
+=
headlen
+
ventoy_align
(
template_size
,
4
);
grub_check_free
(
template_buf
);
}
}
if
(
persistent_size
>
0
&&
persistent_buf
)
if
(
persistent_size
>
0
&&
persistent_buf
)
{
{
headlen
=
ventoy_cpio_newc_fill_head
(
buf
,
persistent_size
,
persistent_buf
,
"ventoy/ventoy_persistent_map"
);
headlen
=
ventoy_cpio_newc_fill_head
(
buf
,
persistent_size
,
persistent_buf
,
"ventoy/ventoy_persistent_map"
);
buf
+=
headlen
+
ventoy_align
(
persistent_size
,
4
);
buf
+=
headlen
+
ventoy_align
(
persistent_size
,
4
);
grub_check_free
(
persistent_buf
);
grub_free
(
persistent_buf
);
persistent_buf
=
NULL
;
}
}
if
(
injection_size
>
0
&&
injection_buf
)
if
(
injection_size
>
0
&&
injection_buf
)
...
...
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c
View file @
595b9441
...
@@ -2641,10 +2641,15 @@ install_template * ventoy_plugin_find_install_template(const char *isopath)
...
@@ -2641,10 +2641,15 @@ install_template * ventoy_plugin_find_install_template(const char *isopath)
return
NULL
;
return
NULL
;
}
}
char
*
ventoy_plugin_get_cur_install_template
(
const
char
*
isopath
)
char
*
ventoy_plugin_get_cur_install_template
(
const
char
*
isopath
,
install_template
**
cur
)
{
{
install_template
*
node
=
NULL
;
install_template
*
node
=
NULL
;
if
(
cur
)
{
*
cur
=
NULL
;
}
node
=
ventoy_plugin_find_install_template
(
isopath
);
node
=
ventoy_plugin_find_install_template
(
isopath
);
if
((
!
node
)
||
(
!
node
->
templatepath
))
if
((
!
node
)
||
(
!
node
->
templatepath
))
{
{
...
@@ -2656,6 +2661,11 @@ char * ventoy_plugin_get_cur_install_template(const char *isopath)
...
@@ -2656,6 +2661,11 @@ char * ventoy_plugin_get_cur_install_template(const char *isopath)
return
NULL
;
return
NULL
;
}
}
if
(
cur
)
{
*
cur
=
node
;
}
return
node
->
templatepath
[
node
->
cursel
].
path
;
return
node
->
templatepath
[
node
->
cursel
].
path
;
}
}
...
...
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
View file @
595b9441
...
@@ -1015,7 +1015,7 @@ static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directo
...
@@ -1015,7 +1015,7 @@ static int ventoy_update_all_hash(wim_patch *patch, void *meta_data, wim_directo
return
0
;
return
0
;
}
}
static
int
ventoy_cat_exe_file_data
(
wim_tail
*
wim_data
,
grub_uint32_t
exe_len
,
grub_uint8_t
*
exe_data
)
static
int
ventoy_cat_exe_file_data
(
wim_tail
*
wim_data
,
grub_uint32_t
exe_len
,
grub_uint8_t
*
exe_data
,
int
windatalen
)
{
{
int
pe64
=
0
;
int
pe64
=
0
;
char
file
[
256
];
char
file
[
256
];
...
@@ -1030,14 +1030,14 @@ static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, g
...
@@ -1030,14 +1030,14 @@ static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, g
jump_align
=
ventoy_align
(
jump_len
,
16
);
jump_align
=
ventoy_align
(
jump_len
,
16
);
wim_data
->
jump_exe_len
=
jump_len
;
wim_data
->
jump_exe_len
=
jump_len
;
wim_data
->
bin_raw_len
=
jump_align
+
sizeof
(
ventoy_os_param
)
+
sizeof
(
ventoy_windows_data
)
+
exe_len
;
wim_data
->
bin_raw_len
=
jump_align
+
sizeof
(
ventoy_os_param
)
+
windatalen
+
exe_len
;
wim_data
->
bin_align_len
=
ventoy_align
(
wim_data
->
bin_raw_len
,
2048
);
wim_data
->
bin_align_len
=
ventoy_align
(
wim_data
->
bin_raw_len
,
2048
);
wim_data
->
jump_bin_data
=
grub_malloc
(
wim_data
->
bin_align_len
);
wim_data
->
jump_bin_data
=
grub_malloc
(
wim_data
->
bin_align_len
);
if
(
wim_data
->
jump_bin_data
)
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_data
,
jump_len
);
grub_memcpy
(
wim_data
->
jump_bin_data
+
jump_align
+
sizeof
(
ventoy_os_param
)
+
sizeof
(
ventoy_windows_data
)
,
exe_data
,
exe_len
);
grub_memcpy
(
wim_data
->
jump_bin_data
+
jump_align
+
sizeof
(
ventoy_os_param
)
+
windatalen
,
exe_data
,
exe_len
);
}
}
debug
(
"jump_exe_len:%u bin_raw_len:%u bin_align_len:%u
\n
"
,
debug
(
"jump_exe_len:%u bin_raw_len:%u bin_align_len:%u
\n
"
,
...
@@ -1046,26 +1046,68 @@ static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, g
...
@@ -1046,26 +1046,68 @@ static int ventoy_cat_exe_file_data(wim_tail *wim_data, grub_uint32_t exe_len, g
return
0
;
return
0
;
}
}
int
ventoy_
fill
_windows_rtdata
(
void
*
buf
,
char
*
isopath
)
static
int
ventoy_
get
_windows_rtdata
_len
(
const
char
*
iso
,
int
*
flag
)
{
{
int
size
=
0
;
int
template_file_len
=
0
;
char
*
pos
=
NULL
;
char
*
pos
=
NULL
;
char
*
script
=
NULL
;
char
*
script
=
NULL
;
install_template
*
template_node
=
NULL
;
*
flag
=
0
;
size
=
(
int
)
sizeof
(
ventoy_windows_data
);
pos
=
grub_strstr
(
iso
,
"/"
);
if
(
!
pos
)
{
return
size
;
}
script
=
ventoy_plugin_get_cur_install_template
(
pos
,
&
template_node
);
if
(
script
)
{
(
*
flag
)
|=
WINDATA_FLAG_TEMPLATE
;
template_file_len
=
template_node
->
filelen
;
}
return
size
+
template_file_len
;
}
static
int
ventoy_fill_windows_rtdata
(
void
*
buf
,
char
*
isopath
,
int
dataflag
)
{
int
template_len
=
0
;
char
*
pos
=
NULL
;
char
*
end
=
NULL
;
char
*
script
=
NULL
;
const
char
*
env
=
NULL
;
const
char
*
env
=
NULL
;
install_template
*
template_node
=
NULL
;
ventoy_windows_data
*
data
=
(
ventoy_windows_data
*
)
buf
;
ventoy_windows_data
*
data
=
(
ventoy_windows_data
*
)
buf
;
grub_memset
(
data
,
0
,
sizeof
(
ventoy_windows_data
));
grub_memset
(
data
,
0
,
sizeof
(
ventoy_windows_data
));
env
=
grub_env_get
(
"VTOY_WIN11_BYPASS_CHECK"
);
if
(
env
&&
env
[
0
]
==
'1'
&&
env
[
1
]
==
0
)
{
data
->
windows11_bypass_check
=
1
;
}
pos
=
grub_strstr
(
isopath
,
"/"
);
pos
=
grub_strstr
(
isopath
,
"/"
);
if
(
!
pos
)
if
(
!
pos
)
{
{
return
1
;
return
1
;
}
}
script
=
ventoy_plugin_get_cur_install_template
(
pos
);
if
(
dataflag
&
WINDATA_FLAG_TEMPLATE
)
if
(
script
)
{
{
debug
(
"auto install script <%s>
\n
"
,
script
);
script
=
ventoy_plugin_get_cur_install_template
(
pos
,
&
template_node
);
grub_snprintf
(
data
->
auto_install_script
,
sizeof
(
data
->
auto_install_script
)
-
1
,
"%s"
,
script
);
if
(
script
)
{
data
->
auto_install_len
=
template_len
=
template_node
->
filelen
;
debug
(
"auto install script OK <%s> <len:%d>
\n
"
,
script
,
template_len
);
end
=
ventoy_str_last
(
script
,
'/'
);
grub_snprintf
(
data
->
auto_install_script
,
sizeof
(
data
->
auto_install_script
)
-
1
,
"%s"
,
end
?
end
+
1
:
script
);
grub_memcpy
(
data
+
1
,
template_node
->
filebuf
,
template_len
);
}
}
}
else
else
{
{
...
@@ -1090,12 +1132,6 @@ int ventoy_fill_windows_rtdata(void *buf, char *isopath)
...
@@ -1090,12 +1132,6 @@ int ventoy_fill_windows_rtdata(void *buf, char *isopath)
debug
(
"injection archive not configed %s
\n
"
,
pos
);
debug
(
"injection archive not configed %s
\n
"
,
pos
);
}
}
env
=
grub_env_get
(
"VTOY_WIN11_BYPASS_CHECK"
);
if
(
env
&&
env
[
0
]
==
'1'
&&
env
[
1
]
==
0
)
{
data
->
windows11_bypass_check
=
1
;
}
return
0
;
return
0
;
}
}
...
@@ -1125,7 +1161,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
...
@@ -1125,7 +1161,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
if
(
wim_data
->
jump_bin_data
)
if
(
wim_data
->
jump_bin_data
)
{
{
grub_memcpy
(
wim_data
->
jump_bin_data
+
jump_align
,
param
,
sizeof
(
ventoy_os_param
));
grub_memcpy
(
wim_data
->
jump_bin_data
+
jump_align
,
param
,
sizeof
(
ventoy_os_param
));
ventoy_fill_windows_rtdata
(
wim_data
->
jump_bin_data
+
jump_align
+
sizeof
(
ventoy_os_param
),
isopath
);
ventoy_fill_windows_rtdata
(
wim_data
->
jump_bin_data
+
jump_align
+
sizeof
(
ventoy_os_param
),
isopath
,
wim_data
->
windata_flag
);
}
}
grub_crypto_hash
(
GRUB_MD_SHA1
,
wim_data
->
bin_hash
.
sha1
,
wim_data
->
jump_bin_data
,
wim_data
->
bin_raw_len
);
grub_crypto_hash
(
GRUB_MD_SHA1
,
wim_data
->
bin_hash
.
sha1
,
wim_data
->
jump_bin_data
,
wim_data
->
bin_raw_len
);
...
@@ -1168,7 +1204,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
...
@@ -1168,7 +1204,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
return
0
;
return
0
;
}
}
static
int
ventoy_wimdows_locate_wim
(
const
char
*
disk
,
wim_patch
*
patch
)
static
int
ventoy_wimdows_locate_wim
(
const
char
*
disk
,
wim_patch
*
patch
,
int
windatalen
)
{
{
int
rc
;
int
rc
;
grub_uint16_t
i
;
grub_uint16_t
i
;
...
@@ -1285,7 +1321,7 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
...
@@ -1285,7 +1321,7 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
if
(
0
==
ventoy_read_resource
(
file
,
head
,
&
(
patch
->
replace_look
->
resource
),
(
void
**
)
&
(
exe_data
)))
if
(
0
==
ventoy_read_resource
(
file
,
head
,
&
(
patch
->
replace_look
->
resource
),
(
void
**
)
&
(
exe_data
)))
{
{
ventoy_cat_exe_file_data
(
wim_data
,
exe_len
,
exe_data
);
ventoy_cat_exe_file_data
(
wim_data
,
exe_len
,
exe_data
,
windatalen
);
grub_free
(
exe_data
);
grub_free
(
exe_data
);
}
}
else
else
...
@@ -1330,15 +1366,20 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
...
@@ -1330,15 +1366,20 @@ static int ventoy_wimdows_locate_wim(const char *disk, wim_patch *patch)
grub_err_t
ventoy_cmd_locate_wim_patch
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
grub_err_t
ventoy_cmd_locate_wim_patch
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
{
{
int
datalen
=
0
;
int
dataflag
=
0
;
wim_patch
*
node
=
g_wim_patch_head
;
wim_patch
*
node
=
g_wim_patch_head
;
(
void
)
ctxt
;
(
void
)
ctxt
;
(
void
)
argc
;
(
void
)
argc
;
(
void
)
args
;
(
void
)
args
;
datalen
=
ventoy_get_windows_rtdata_len
(
args
[
1
],
&
dataflag
);
while
(
node
)
while
(
node
)
{
{
if
(
0
==
ventoy_wimdows_locate_wim
(
args
[
0
],
node
))
node
->
wim_data
.
windata_flag
=
dataflag
;
if
(
0
==
ventoy_wimdows_locate_wim
(
args
[
0
],
node
,
datalen
))
{
{
node
->
valid
=
1
;
node
->
valid
=
1
;
g_wim_valid_patch_count
++
;
g_wim_valid_patch_count
++
;
...
@@ -1751,6 +1792,8 @@ end:
...
@@ -1751,6 +1792,8 @@ end:
grub_err_t
ventoy_cmd_windows_wimboot_data
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
grub_err_t
ventoy_cmd_windows_wimboot_data
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
{
{
int
datalen
=
0
;
int
dataflag
=
0
;
grub_uint32_t
size
=
0
;
grub_uint32_t
size
=
0
;
const
char
*
addr
=
NULL
;
const
char
*
addr
=
NULL
;
ventoy_chain_head
*
chain
=
NULL
;
ventoy_chain_head
*
chain
=
NULL
;
...
@@ -1776,7 +1819,9 @@ grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc,
...
@@ -1776,7 +1819,9 @@ grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc,
return
1
;
return
1
;
}
}
size
=
sizeof
(
ventoy_os_param
)
+
sizeof
(
ventoy_windows_data
);
datalen
=
ventoy_get_windows_rtdata_len
(
chain
->
os_param
.
vtoy_img_path
,
&
dataflag
);
size
=
sizeof
(
ventoy_os_param
)
+
datalen
;
param
=
(
ventoy_os_param
*
)
grub_zalloc
(
size
);
param
=
(
ventoy_os_param
*
)
grub_zalloc
(
size
);
if
(
!
param
)
if
(
!
param
)
{
{
...
@@ -1784,7 +1829,7 @@ grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc,
...
@@ -1784,7 +1829,7 @@ grub_err_t ventoy_cmd_windows_wimboot_data(grub_extcmd_context_t ctxt, int argc,
}
}
grub_memcpy
(
param
,
&
chain
->
os_param
,
sizeof
(
ventoy_os_param
));
grub_memcpy
(
param
,
&
chain
->
os_param
,
sizeof
(
ventoy_os_param
));
ventoy_fill_windows_rtdata
(
param
+
1
,
param
->
vtoy_img_path
);
ventoy_fill_windows_rtdata
(
param
+
1
,
param
->
vtoy_img_path
,
dataflag
);
grub_snprintf
(
envbuf
,
sizeof
(
envbuf
),
"0x%lx"
,
(
unsigned
long
)
param
);
grub_snprintf
(
envbuf
,
sizeof
(
envbuf
),
"0x%lx"
,
(
unsigned
long
)
param
);
grub_env_set
(
"vtoy_wimboot_mem_addr"
,
envbuf
);
grub_env_set
(
"vtoy_wimboot_mem_addr"
,
envbuf
);
...
...
GRUB2/MOD_SRC/grub-2.04/include/grub/ventoy.h
View file @
595b9441
...
@@ -139,7 +139,13 @@ typedef struct ventoy_windows_data
...
@@ -139,7 +139,13 @@ typedef struct ventoy_windows_data
char
auto_install_script
[
384
];
char
auto_install_script
[
384
];
char
injection_archive
[
384
];
char
injection_archive
[
384
];
grub_uint8_t
windows11_bypass_check
;
grub_uint8_t
windows11_bypass_check
;
grub_uint8_t
reserved
[
255
];
grub_uint32_t
auto_install_len
;
grub_uint8_t
reserved
[
255
-
4
];
/* auto_intall file buf */
/* ...... + auto_install_len */
}
ventoy_windows_data
;
}
ventoy_windows_data
;
...
...
INSTALL/ventoy/vtoyjump32.exe
View file @
595b9441
No preview for this file type
INSTALL/ventoy/vtoyjump64.exe
View file @
595b9441
No preview for this file type
vtoyjump/vtoyjump/vtoyjump.c
View file @
595b9441
...
@@ -47,6 +47,8 @@ static CHAR g_prog_name[MAX_PATH];
...
@@ -47,6 +47,8 @@ static CHAR g_prog_name[MAX_PATH];
#define AUTO_RUN_BAT "X:\\VentoyAutoRun.bat"
#define AUTO_RUN_BAT "X:\\VentoyAutoRun.bat"
#define AUTO_RUN_LOG "X:\\VentoyAutoRun.log"
#define AUTO_RUN_LOG "X:\\VentoyAutoRun.log"
#define VTOY_AUTO_FILE "X:\\_vtoy_auto_install"
#define LOG_FILE "X:\\Windows\\system32\\ventoy.log"
#define LOG_FILE "X:\\Windows\\system32\\ventoy.log"
#define MUTEX_LOCK(hmutex) if (hmutex != NULL) LockStatus = WaitForSingleObject(hmutex, INFINITE)
#define MUTEX_LOCK(hmutex) if (hmutex != NULL) LockStatus = WaitForSingleObject(hmutex, INFINITE)
#define MUTEX_UNLOCK(hmutex) if (hmutex != NULL && WAIT_OBJECT_0 == LockStatus) ReleaseMutex(hmutex)
#define MUTEX_UNLOCK(hmutex) if (hmutex != NULL && WAIT_OBJECT_0 == LockStatus) ReleaseMutex(hmutex)
...
@@ -255,9 +257,25 @@ End:
...
@@ -255,9 +257,25 @@ End:
return
rc
;
return
rc
;
}
}
static
BOOL
CheckPeHead
(
BYTE
*
Head
)
static
BOOL
CheckPeHead
(
BYTE
*
Buffer
,
DWORD
Size
,
DWORD
Offset
)
{
{
UINT32
PeOffset
;
UINT32
PeOffset
;
BYTE
*
Head
=
NULL
;
DWORD
End
;
ventoy_windows_data
*
pdata
=
NULL
;
Head
=
Buffer
+
Offset
;
pdata
=
(
ventoy_windows_data
*
)
Head
;
Head
+=
sizeof
(
ventoy_windows_data
);
if
(
pdata
->
auto_install_script
[
0
]
&&
pdata
->
auto_install_len
>
0
)
{
End
=
Offset
+
sizeof
(
ventoy_windows_data
)
+
pdata
->
auto_install_len
+
60
;
if
(
End
<
Size
)
{
Head
+=
pdata
->
auto_install_len
;
}
}
if
(
Head
[
0
]
!=
'M'
||
Head
[
1
]
!=
'Z'
)
if
(
Head
[
0
]
!=
'M'
||
Head
[
1
]
!=
'Z'
)
{
{
...
@@ -1647,11 +1665,10 @@ static int VentoyHook(ventoy_os_param *param)
...
@@ -1647,11 +1665,10 @@ static int VentoyHook(ventoy_os_param *param)
if
(
g_windows_data
.
auto_install_script
[
0
])
if
(
g_windows_data
.
auto_install_script
[
0
])
{
{
sprintf_s
(
IsoPath
,
sizeof
(
IsoPath
),
"%C:%s"
,
VtoyLetter
,
g_windows_data
.
auto_install_script
);
if
(
IsFileExist
(
"%s"
,
VTOY_AUTO_FILE
))
if
(
IsFileExist
(
"%s"
,
IsoPath
))
{
{
Log
(
"use auto install script %s..."
,
IsoPath
);
Log
(
"use auto install script %s..."
,
VTOY_AUTO_FILE
);
ProcessUnattendedInstallation
(
IsoPath
);
ProcessUnattendedInstallation
(
VTOY_AUTO_FILE
);
}
}
else
else
{
{
...
@@ -1724,6 +1741,25 @@ static int VentoyHook(ventoy_os_param *param)
...
@@ -1724,6 +1741,25 @@ static int VentoyHook(ventoy_os_param *param)
return
0
;
return
0
;
}
}
static
int
ExtractWindowsDataFile
(
char
*
databuf
)
{
int
len
=
0
;
char
*
filedata
=
NULL
;
ventoy_windows_data
*
pdata
=
(
ventoy_windows_data
*
)
databuf
;
Log
(
"ExtractWindowsDataFile: auto install <%s:%d>"
,
pdata
->
auto_install_script
,
pdata
->
auto_install_len
);
filedata
=
databuf
+
sizeof
(
ventoy_windows_data
);
if
(
pdata
->
auto_install_script
[
0
]
&&
pdata
->
auto_install_len
>
0
)
{
SaveBuffer2File
(
VTOY_AUTO_FILE
,
filedata
,
pdata
->
auto_install_len
);
filedata
+=
pdata
->
auto_install_len
;
len
=
pdata
->
auto_install_len
;
}
return
len
;
}
int
VentoyJumpWimboot
(
INT
argc
,
CHAR
**
argv
,
CHAR
*
LunchFile
)
int
VentoyJumpWimboot
(
INT
argc
,
CHAR
**
argv
,
CHAR
*
LunchFile
)
{
{
...
@@ -1741,6 +1777,7 @@ int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile)
...
@@ -1741,6 +1777,7 @@ int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile)
memcpy
(
&
g_os_param
,
buf
,
sizeof
(
ventoy_os_param
));
memcpy
(
&
g_os_param
,
buf
,
sizeof
(
ventoy_os_param
));
memcpy
(
&
g_windows_data
,
buf
+
sizeof
(
ventoy_os_param
),
sizeof
(
ventoy_windows_data
));
memcpy
(
&
g_windows_data
,
buf
+
sizeof
(
ventoy_os_param
),
sizeof
(
ventoy_windows_data
));
ExtractWindowsDataFile
(
buf
+
sizeof
(
ventoy_os_param
));
memcpy
(
g_os_param_reserved
,
g_os_param
.
vtoy_reserved
,
sizeof
(
g_os_param_reserved
));
memcpy
(
g_os_param_reserved
,
g_os_param
.
vtoy_reserved
,
sizeof
(
g_os_param_reserved
));
if
(
g_os_param_reserved
[
0
]
==
1
)
if
(
g_os_param_reserved
[
0
]
==
1
)
...
@@ -1800,6 +1837,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
...
@@ -1800,6 +1837,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
{
{
int
rc
=
1
;
int
rc
=
1
;
int
stat
=
0
;
int
stat
=
0
;
int
exlen
=
0
;
DWORD
Pos
;
DWORD
Pos
;
DWORD
PeStart
;
DWORD
PeStart
;
DWORD
FileSize
;
DWORD
FileSize
;
...
@@ -1835,12 +1873,13 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
...
@@ -1835,12 +1873,13 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
for
(
PeStart
=
0
;
PeStart
<
FileSize
;
PeStart
+=
16
)
for
(
PeStart
=
0
;
PeStart
<
FileSize
;
PeStart
+=
16
)
{
{
if
(
CheckOsParam
((
ventoy_os_param
*
)(
Buffer
+
PeStart
))
&&
if
(
CheckOsParam
((
ventoy_os_param
*
)(
Buffer
+
PeStart
))
&&
CheckPeHead
(
Buffer
+
PeStart
+
sizeof
(
ventoy_os_param
)
+
sizeof
(
ventoy_windows_data
)
))
CheckPeHead
(
Buffer
,
FileSize
,
PeStart
+
sizeof
(
ventoy_os_param
)))
{
{
Log
(
"Find os pararm at %u"
,
PeStart
);
Log
(
"Find os pararm at %u"
,
PeStart
);
memcpy
(
&
g_os_param
,
Buffer
+
PeStart
,
sizeof
(
ventoy_os_param
));
memcpy
(
&
g_os_param
,
Buffer
+
PeStart
,
sizeof
(
ventoy_os_param
));
memcpy
(
&
g_windows_data
,
Buffer
+
PeStart
+
sizeof
(
ventoy_os_param
),
sizeof
(
ventoy_windows_data
));
memcpy
(
&
g_windows_data
,
Buffer
+
PeStart
+
sizeof
(
ventoy_os_param
),
sizeof
(
ventoy_windows_data
));
exlen
=
ExtractWindowsDataFile
(
Buffer
+
PeStart
+
sizeof
(
ventoy_os_param
));
memcpy
(
g_os_param_reserved
,
g_os_param
.
vtoy_reserved
,
sizeof
(
g_os_param_reserved
));
memcpy
(
g_os_param_reserved
,
g_os_param
.
vtoy_reserved
,
sizeof
(
g_os_param_reserved
));
if
(
g_os_param_reserved
[
0
]
==
1
)
if
(
g_os_param_reserved
[
0
]
==
1
)
...
@@ -1858,7 +1897,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
...
@@ -1858,7 +1897,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
}
}
}
}
PeStart
+=
sizeof
(
ventoy_os_param
)
+
sizeof
(
ventoy_windows_data
);
PeStart
+=
sizeof
(
ventoy_os_param
)
+
sizeof
(
ventoy_windows_data
)
+
exlen
;
sprintf_s
(
LunchFile
,
MAX_PATH
,
"ventoy
\\
%s"
,
GetFileNameInPath
(
ExeFileName
));
sprintf_s
(
LunchFile
,
MAX_PATH
,
"ventoy
\\
%s"
,
GetFileNameInPath
(
ExeFileName
));
MUTEX_LOCK
(
g_vtoyins_mutex
);
MUTEX_LOCK
(
g_vtoyins_mutex
);
...
...
vtoyjump/vtoyjump/vtoyjump.h
View file @
595b9441
...
@@ -72,7 +72,15 @@ typedef struct ventoy_windows_data
...
@@ -72,7 +72,15 @@ typedef struct ventoy_windows_data
char
auto_install_script
[
384
];
char
auto_install_script
[
384
];
char
injection_archive
[
384
];
char
injection_archive
[
384
];
UINT8
windows11_bypass_check
;
UINT8
windows11_bypass_check
;
UINT8
reserved
[
255
];
UINT32
auto_install_len
;
UINT8
reserved
[
255
-
4
];
/* auto install script file data ... + auto_install_len */
/* ...... */
}
ventoy_windows_data
;
}
ventoy_windows_data
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment