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
a9be2fd4
Commit
a9be2fd4
authored
Oct 14, 2021
by
longpanda
Browse files
Improvement for some special WinPE
parent
f354d2b7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
264 additions
and
296 deletions
+264
-296
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
+2
-0
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
+72
-5
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
+188
-289
vtoyjump/vtoyjump/vtoyjump.vcxproj
vtoyjump/vtoyjump/vtoyjump.vcxproj
+2
-2
No files found.
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
View file @
a9be2fd4
...
...
@@ -21,6 +21,8 @@
#ifndef __VENTOY_DEF_H__
#define __VENTOY_DEF_H__
#define VTOY_MAX_DIR_DEPTH 32
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
#define VTOY_PART_BUF_LEN (128 * 1024)
...
...
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_windows.c
View file @
a9be2fd4
...
...
@@ -776,6 +776,67 @@ end:
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
<
VTOY_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
>=
VTOY_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
,
...
...
@@ -786,38 +847,44 @@ static wim_directory_entry * search_replace_wim_dirent
)
{
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
[
VTOY_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
));
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
);
ventoy_str_toupper
(
cmdline
);
if
(
grub_strncmp
(
cmdline
,
"PECMD"
,
5
)
==
0
)
if
(
grub_strnc
asec
mp
(
cmdline
,
"PECMD"
,
5
)
==
0
)
{
wim_dirent
=
pecmd_dirent
;
}
else
if
(
grub_strncmp
(
cmdline
,
"PESET"
,
5
)
==
0
)
else
if
(
grub_strnc
asec
mp
(
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_strncmp
(
cmdline
,
"WINPESHL"
,
8
)
==
0
)
else
if
(
grub_strnc
asec
mp
(
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
)
{
...
...
INSTALL/ventoy/vtoyjump32.exe
View file @
a9be2fd4
No preview for this file type
INSTALL/ventoy/vtoyjump64.exe
View file @
a9be2fd4
No preview for this file type
vtoyjump/vtoyjump/vtoyjump.c
View file @
a9be2fd4
/******************************************************************************
* vtoyjump.c
*
* Copyright (c) 202
0
, longpanda <admin@ventoy.net>
* Copyright (c) 202
1
, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
...
...
@@ -31,22 +31,55 @@
static
ventoy_os_param
g_os_param
;
static
ventoy_windows_data
g_windows_data
;
static
UINT8
g_os_param_reserved
[
32
];
static
BOOL
g_64bit_system
=
FALSE
;
static
INT
g_system_bit
=
VTOY_BIT
;
static
ventoy_guid
g_ventoy_guid
=
VENTOY_GUID
;
static
HANDLE
g_vtoylog_mutex
=
NULL
;
static
HANDLE
g_vtoyins_mutex
=
NULL
;
//Unicode "CmdLine"
static
BOOL
g_PecmdHasCmdLine
=
FALSE
;
static
UCHAR
g_aucCmdLineHex
[]
=
{
0x43
,
0x00
,
0x6D
,
0x00
,
0x64
,
0x00
,
0x4C
,
0x00
,
0x69
,
0x00
,
0x6E
,
0x00
,
0x65
,
0x00
};
static
CHAR
g_prog_full_path
[
MAX_PATH
];
static
CHAR
g_prog_dir
[
MAX_PATH
];
static
CHAR
g_prog_name
[
MAX_PATH
];
#define
VTOY_PID
_FILE "X:\\Windows\\
S
ystem32\\
pid
ventoy"
#define
LOG
_FILE
"X:\\Windows\\
s
ystem32\\ventoy
.log
"
#define MUTEX_LOCK(hmutex) if (hmutex != NULL) LockStatus = WaitForSingleObject(hmutex, INFINITE)
#define MUTEX_UNLOCK(hmutex) if (hmutex != NULL && WAIT_OBJECT_0 == LockStatus) ReleaseMutex(hmutex)
static
const
char
*
GetFileNameInPath
(
const
char
*
fullpath
)
{
int
i
;
if
(
strstr
(
fullpath
,
":"
))
{
for
(
i
=
(
int
)
strlen
(
fullpath
);
i
>
0
;
i
--
)
{
if
(
fullpath
[
i
-
1
]
==
'/'
||
fullpath
[
i
-
1
]
==
'\\'
)
{
return
fullpath
+
i
;
}
}
}
return
fullpath
;
}
static
int
split_path_name
(
char
*
fullpath
,
char
*
dir
,
char
*
name
)
{
CHAR
ch
;
CHAR
*
Pos
=
NULL
;
Pos
=
(
CHAR
*
)
GetFileNameInPath
(
fullpath
);
strcpy_s
(
name
,
MAX_PATH
,
Pos
);
ch
=
*
(
Pos
-
1
);
*
(
Pos
-
1
)
=
0
;
strcpy_s
(
dir
,
MAX_PATH
,
fullpath
);
*
(
Pos
-
1
)
=
ch
;
return
0
;
}
void
Log
(
const
char
*
Fmt
,
...)
{
va_list
Arg
;
...
...
@@ -70,7 +103,7 @@ void Log(const char *Fmt, ...)
MUTEX_LOCK
(
g_vtoylog_mutex
);
fopen_s
(
&
File
,
"ventoy.log"
,
"a+"
);
fopen_s
(
&
File
,
LOG_FILE
,
"a+"
);
if
(
File
)
{
fwrite
(
szBuf
,
1
,
Len
,
File
);
...
...
@@ -233,24 +266,6 @@ static BOOL CheckPeHead(BYTE *Head)
return
TRUE
;
}
static
BOOL
IsPe64
(
BYTE
*
buffer
)
{
DWORD
pe_off
;
if
(
!
CheckPeHead
(
buffer
))
{
return
FALSE
;
}
pe_off
=
*
(
UINT32
*
)(
buffer
+
60
);
if
(
*
(
UINT16
*
)(
buffer
+
pe_off
+
24
)
==
0x020b
)
{
return
TRUE
;
}
return
FALSE
;
}
static
BOOL
CheckOsParam
(
ventoy_os_param
*
param
)
{
...
...
@@ -528,7 +543,7 @@ int VentoyMountY(HANDLE Handle)
for
(
i
=
0
;
physicalDriveName
[
i
];
i
++
)
{
physicalDriveNameA
[
i
]
=
toupper
((
CHAR
)(
physicalDriveName
[
i
]));
physicalDriveNameA
[
i
]
=
(
CHAR
)
toupper
((
CHAR
)(
physicalDriveName
[
i
]));
}
Log
(
"physicalDriveNameA=<%s>"
,
physicalDriveNameA
);
...
...
@@ -553,8 +568,10 @@ int VentoyMountY(HANDLE Handle)
return
bRet
?
0
:
1
;
}
static
BOOL
VentoyNeedMountY
(
const
char
*
IsoPath
)
static
BOOL
Ventoy
API
NeedMountY
(
const
char
*
IsoPath
)
{
(
void
)
IsoPath
;
/* TBD */
return
FALSE
;
}
...
...
@@ -576,7 +593,7 @@ static int VentoyAttachVirtualDisk(HANDLE Handle, const char *IsoPath)
DriveYFree
=
1
;
}
if
(
DriveYFree
&&
VentoyNeedMountY
(
IsoPath
))
if
(
DriveYFree
&&
Ventoy
API
NeedMountY
(
IsoPath
))
{
return
VentoyMountY
(
Handle
);
}
...
...
@@ -744,7 +761,7 @@ static BOOL Is2K10PE(void)
return
bRet
;
}
static
CHAR
GetMountLogicalDrive
(
void
)
static
CHAR
Get
IMDisk
MountLogicalDrive
(
void
)
{
CHAR
Letter
=
'Y'
;
DWORD
Drives
;
...
...
@@ -832,7 +849,7 @@ static int VentoyRunImdisk(const char *IsoPath, const char *imdiskexe)
Log
(
"VentoyRunImdisk <%s> <%s>"
,
IsoPath
,
imdiskexe
);
Letter
=
GetMountLogicalDrive
();
Letter
=
Get
IMDisk
MountLogicalDrive
();
sprintf_s
(
Cmdline
,
sizeof
(
Cmdline
),
"%s -a -o ro -f
\"
%s
\"
-m %C:"
,
imdiskexe
,
IsoPath
,
Letter
);
Log
(
"mount iso to %C: use imdisk cmd <%s>"
,
Letter
,
Cmdline
);
...
...
@@ -909,7 +926,7 @@ int VentoyMountISOByImdisk(const char *IsoPath, DWORD PhyDrive)
if
(
0
==
fl_attach_media
(
VentoyFatDiskRead
,
NULL
))
{
if
(
g_
64bit_
system
)
if
(
g_system
_bit
==
64
)
{
CopyFileFromFatDisk
(
"/ventoy/imdisk/64/imdisk.sys"
,
"ventoy
\\
imdisk.sys"
);
CopyFileFromFatDisk
(
"/ventoy/imdisk/64/imdisk.exe"
,
"ventoy
\\
imdisk.exe"
);
...
...
@@ -1132,7 +1149,7 @@ static int DecompressInjectionArchive(const char *archive, DWORD PhyDrive)
if
(
0
==
fl_attach_media
(
VentoyFatDiskRead
,
NULL
))
{
if
(
g_64bit_system
)
if
(
g_system_bit
==
64
)
{
CopyFileFromFatDisk
(
"/ventoy/7z/64/7za.exe"
,
"ventoy
\\
7za.exe"
);
}
...
...
@@ -1345,24 +1362,6 @@ static int VentoyHook(ventoy_os_param *param)
return
0
;
}
const
char
*
GetFileNameInPath
(
const
char
*
fullpath
)
{
int
i
;
const
char
*
pos
=
NULL
;
if
(
strstr
(
fullpath
,
":"
))
{
for
(
i
=
(
int
)
strlen
(
fullpath
);
i
>
0
;
i
--
)
{
if
(
fullpath
[
i
-
1
]
==
'/'
||
fullpath
[
i
-
1
]
==
'\\'
)
{
return
fullpath
+
i
;
}
}
}
return
fullpath
;
}
int
VentoyJumpWimboot
(
INT
argc
,
CHAR
**
argv
,
CHAR
*
LunchFile
)
{
...
...
@@ -1371,13 +1370,7 @@ int VentoyJumpWimboot(INT argc, CHAR **argv, CHAR *LunchFile)
DWORD
size
=
0
;
DWORD
Pos
;
#ifdef VTOY_32
g_64bit_system
=
FALSE
;
#else
g_64bit_system
=
TRUE
;
#endif
Log
(
"VentoyJumpWimboot %dbit"
,
g_64bit_system
?
64
:
32
);
Log
(
"VentoyJumpWimboot %dbit"
,
g_system_bit
);
sprintf_s
(
LunchFile
,
MAX_PATH
,
"X:
\\
setup.exe"
);
...
...
@@ -1441,24 +1434,6 @@ static int ventoy_check_create_directory(void)
return
0
;
}
static
BOOL
VentoyFindCmdLineStr
(
BYTE
*
buf
,
DWORD
size
)
{
DWORD
i
=
0
;
UINT32
uiDataChk
;
UINT32
uiDataHex
=
*
(
UINT32
*
)(
g_aucCmdLineHex
);
for
(
i
=
0
;
i
<
size
-
sizeof
(
g_aucCmdLineHex
);
i
+=
16
)
{
uiDataChk
=
*
(
UINT32
*
)(
buf
+
i
);
if
(
uiDataChk
==
uiDataHex
&&
memcmp
(
buf
+
i
,
g_aucCmdLineHex
,
sizeof
(
g_aucCmdLineHex
))
==
0
)
{
return
TRUE
;
}
}
return
FALSE
;
}
int
VentoyJump
(
INT
argc
,
CHAR
**
argv
,
CHAR
*
LunchFile
)
{
int
rc
=
1
;
...
...
@@ -1484,8 +1459,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
goto
End
;
}
g_64bit_system
=
IsPe64
(
Buffer
);
Log
(
"VentoyJump %dbit"
,
g_64bit_system
?
64
:
32
);
Log
(
"VentoyJump %dbit"
,
g_system_bit
);
MUTEX_LOCK
(
g_vtoyins_mutex
);
stat
=
ventoy_check_create_directory
();
...
...
@@ -1537,13 +1511,6 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
SaveBuffer2File
(
LunchFile
,
Buffer
+
PeStart
,
FileSize
-
PeStart
);
MUTEX_UNLOCK
(
g_vtoyins_mutex
);
#ifdef VTOY_REJUMP_SUPPORTED
if
(
_stricmp
(
LunchFile
,
"ventoy
\\
PECMD.EXE"
)
==
0
)
{
g_PecmdHasCmdLine
=
VentoyFindCmdLineStr
(
Buffer
+
PeStart
,
FileSize
-
PeStart
);
}
#endif
break
;
}
}
...
...
@@ -1574,244 +1541,176 @@ End:
}
static
int
ventoy_append_process_id
(
const
char
*
pidfile
)
int
real_main
(
int
argc
,
char
**
argv
)
{
DWORD
PID
=
0
;
FILE
*
fp
=
NULL
;
PID
=
GetCurrentProcessId
();
fopen_s
(
&
fp
,
pidfile
,
"a+"
);
if
(
!
fp
)
{
return
1
;
}
fprintf_s
(
fp
,
"%u
\n
"
,
PID
);
fclose
(
fp
);
return
0
;
}
static
int
ventoy_get_instance_id
(
const
char
*
pidfile
)
{
int
instance
=
0
;
FILE
*
fp
=
NULL
;
char
line
[
256
];
int
i
=
0
;
int
rc
=
0
;
CHAR
NewFile
[
MAX_PATH
];
CHAR
LunchFile
[
MAX_PATH
];
CHAR
CallParam
[
1024
]
=
{
0
};
STARTUPINFOA
Si
;
PROCESS_INFORMATION
Pi
;
fopen_s
(
&
fp
,
pidfile
,
"r"
);
if
(
!
fp
)
{
return
1
;
}
Log
(
"#### real_main #### argc = %d"
,
argc
);
Log
(
"program full path: <%s>"
,
g_prog_full_path
);
Log
(
"program dir: <%s>"
,
g_prog_dir
);
Log
(
"program name:: <%s>"
,
g_prog_name
);
while
(
fgets
(
line
,
sizeof
(
line
),
fp
))
{
instance
++
;
}
Log
(
"argc = %d"
,
argc
);
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
Log
(
"argv[%d]=<%s>"
,
i
,
argv
[
i
]);
if
(
i
>
0
)
{
strcat_s
(
CallParam
,
sizeof
(
CallParam
),
" "
);
strcat_s
(
CallParam
,
sizeof
(
CallParam
),
argv
[
i
]);
}
}
fclose
(
fp
);
return
instance
+
1
;
}
GetStartupInfoA
(
&
Si
);
memset
(
LunchFile
,
0
,
sizeof
(
LunchFile
));
int
main
(
int
argc
,
char
**
argv
)
{
int
i
=
0
;
int
rc
=
0
;
int
id
=
0
;
BOOL
ReJump
=
FALSE
;
CHAR
*
Pos
=
NULL
;
CHAR
CurDir
[
MAX_PATH
];
CHAR
LunchFile
[
MAX_PATH
];
CHAR
CallParam
[
1024
]
=
{
0
};
DWORD
LockStatus
=
0
;
STARTUPINFOA
Si
;
PROCESS_INFORMATION
Pi
;
#ifdef VTOY_REJUMP_SUPPORTED
if
(
argv
[
0
]
&&
strcmp
(
argv
[
0
],
"ventoy
\\
WinLogon.exe"
)
==
0
)
{
GetStartupInfoA
(
&
Si
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
if
(
strstr
(
argv
[
0
],
"vtoyjump.exe"
))
{
rc
=
VentoyJumpWimboot
(
argc
,
argv
,
LunchFile
);
}
else
{
rc
=
VentoyJump
(
argc
,
argv
,
LunchFile
);
}
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"PECMD.EXE"
);
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
strcat_s
(
LunchFile
,
sizeof
(
LunchFile
),
" "
);
strcat_s
(
LunchFile
,
sizeof
(
LunchFile
),
argv
[
i
]);
}
Log
(
"LunchFile=<%s> CallParam=<%s>"
,
LunchFile
,
CallParam
);
CreateProcessA
(
NULL
,
LunchFile
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
return
0
;
}
#endif
if
(
_stricmp
(
g_prog_name
,
"winpeshl.exe"
)
!=
0
&&
IsFileExist
(
"ventoy
\\
%s"
,
g_prog_name
))
{
sprintf_s
(
NewFile
,
sizeof
(
NewFile
),
"%s_BACK.EXE"
,
g_prog_full_path
)
;
MoveFileA
(
g_prog_full_path
,
NewFile
);
Log
(
"Move <%s> to <%s>"
,
g_prog_full_path
,
NewFile
);
g_PecmdHasCmdLine
=
0
;
g_vtoylog_mutex
=
CreateMutexA
(
NULL
,
FALSE
,
"VTOYLOG_LOCK"
);
g_vtoyins_mutex
=
CreateMutexA
(
NULL
,
FALSE
,
"VTOYINS_LOCK"
);
sprintf_s
(
NewFile
,
sizeof
(
NewFile
),
"ventoy
\\
%s"
,
g_prog_name
)
;
CopyFileA
(
NewFile
,
g_prog_full_path
,
TRUE
);
Log
(
"Copy <%s> to <%s>"
,
NewFile
,
g_prog_full_path
);
MUTEX_LOCK
(
g_vtoyins_mutex
);
if
(
IsFileExist
(
VTOY_PID_FILE
))
{
id
=
ventoy_get_instance_id
(
VTOY_PID_FILE
);
}
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
g_prog_full_path
);
Log
(
"Final lunchFile is <%s>"
,
LunchFile
);
}
else
{
id
=
1
;
Log
(
"We don't need to recover original <%s>"
,
g_prog_name
)
;
}
ventoy_append_process_id
(
VTOY_PID_FILE
);
MUTEX_UNLOCK
(
g_vtoyins_mutex
);
if
(
argv
[
0
]
&&
argv
[
0
][
0
]
&&
argv
[
0
][
1
]
==
':'
)
{
GetCurrentDirectoryA
(
sizeof
(
CurDir
),
CurDir
);
if
(
g_os_param_reserved
[
0
]
==
3
)
{
Log
(
"Open log for debug ..."
);
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
"notepad.exe ventoy.log"
);
}
else
{
if
(
CallParam
[
0
])
{
strcat_s
(
LunchFile
,
sizeof
(
LunchFile
),
CallParam
);
}
else
if
(
NULL
==
strstr
(
LunchFile
,
"setup.exe"
))
{
Log
(
"Not setup.exe, hide windows."
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
}
strcpy_s
(
LunchFile
,
sizeof
(
LunchFile
),
argv
[
0
]
);
Pos
=
(
char
*
)
GetFileNameInPath
(
LunchFile
);
Log
(
"Ventoy jump %s ..."
,
rc
==
0
?
"success"
:
"failed"
);
}
strcat_s
(
CurDir
,
sizeof
(
CurDir
),
"
\\
"
);
strcat_s
(
CurDir
,
sizeof
(
CurDir
),
Pos
);
Log
(
"Now launch <%s> ..."
,
LunchFile
);
if
(
_stricmp
(
argv
[
0
],
CurDir
)
!=
0
)
{
*
Pos
=
0
;
SetCurrentDirectoryA
(
LunchFile
);
}
}
if
(
g_os_param_reserved
[
0
]
==
4
)
{
Log
(
"Open cmd for debug ..."
);
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
"cmd.exe"
);
}
#ifdef VTOY_32
Log
(
"######## VentoyJump 32bit [%d] ##########"
,
id
);
#else
Log
(
"######## VentoyJump 64bit [%d] ##########"
,
id
);
#endif
Log
(
"Backup log at this point"
);
CopyFileA
(
LOG_FILE
,
"X:
\\
Windows
\\
ventoy.backup"
,
TRUE
);
Log
(
"argc = %d"
,
argc
);
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
Log
(
"argv[%d]=<%s>"
,
i
,
argv
[
i
]);
if
(
i
>
0
)
{
strcat_s
(
CallParam
,
sizeof
(
CallParam
),
" "
);
strcat_s
(
CallParam
,
sizeof
(
CallParam
),
argv
[
i
]);
}
}
CreateProcessA
(
NULL
,
LunchFile
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
if
(
Pos
&&
*
Pos
==
0
)
{
Log
(
"Old current directory = <%s>"
,
CurDir
);
Log
(
"New current directory = <%s>"
,
LunchFile
);
}
else
for
(
i
=
0
;
rc
&&
i
<
1800
;
i
++
)
{
GetCurrentDirectoryA
(
sizeof
(
CurDir
),
CurDir
);
Log
(
"Current directory = <%s>"
,
CurDir
);
Log
(
"Ventoy hook failed, now wait and retry ..."
);
Sleep
(
1000
);
rc
=
VentoyHook
(
&
g_os_param
);
}
GetStartupInfoA
(
&
Si
);
Log
(
"Wait process..."
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
memset
(
LunchFile
,
0
,
sizeof
(
LunchFile
));
Log
(
"vtoyjump finished"
);
return
0
;
}
if
(
strstr
(
argv
[
0
],
"vtoyjump.exe"
))
{
rc
=
VentoyJumpWimboot
(
argc
,
argv
,
LunchFile
);
}
else
{
rc
=
VentoyJump
(
argc
,
argv
,
LunchFile
);
}
Log
(
"id=%d LunchFile=<%s> CallParam=<%s>"
,
id
,
LunchFile
,
CallParam
);
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
STARTUPINFOA
Si
;
PROCESS_INFORMATION
Pi
;
CHAR
CurDir
[
MAX_PATH
];
CHAR
NewArgv0
[
MAX_PATH
];
CHAR
CallParam
[
1024
]
=
{
0
};
if
(
id
==
1
&&
_stricmp
(
argv
[
0
],
"PECMD.EXE"
)
==
0
&&
_stricmp
(
LunchFile
,
"ventoy
\\
PECMD.EXE"
)
==
0
)
{
MUTEX_LOCK
(
g_vtoyins_mutex
);
id
=
ventoy_get_instance_id
(
VTOY_PID_FILE
);
MUTEX_UNLOCK
(
g_vtoyins_mutex
);
g_vtoylog_mutex
=
CreateMutexA
(
NULL
,
FALSE
,
"VTOYLOG_LOCK"
);
g_vtoyins_mutex
=
CreateMutexA
(
NULL
,
FALSE
,
"VTOYINS_LOCK"
);
Log
(
"Current instance id is: %d"
,
id
);
Log
(
"######## VentoyJump %dbit ##########"
,
g_system_bit
);
if
(
id
==
2
)
{
#ifdef VTOY_REJUMP_SUPPORTED
if
(
g_PecmdHasCmdLine
)
{
ReJump
=
TRUE
;
CopyFileA
(
"PECMD.EXE"
,
"ventoy
\\
WinLogon.exe"
,
TRUE
);
}
#endif
GetCurrentDirectoryA
(
sizeof
(
CurDir
),
CurDir
);
Log
(
"Current directory is <%s>"
,
CurDir
);
GetModuleFileNameA
(
NULL
,
g_prog_full_path
,
MAX_PATH
);
split_path_name
(
g_prog_full_path
,
g_prog_dir
,
g_prog_name
);
MoveFileA
(
"PECMD.EXE"
,
"PECMD_BACK.EXE"
);
CopyFileA
(
"ventoy
\\
PECMD.EXE"
,
"PECMD.EXE"
,
TRUE
);
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
"PECMD.EXE"
);
Log
(
"Move original PECMD.EXE <%s>"
,
LunchFile
);
}
else
{
Log
(
"%d instance started, don't move PECMD.EXE"
,
id
);
}
}
Log
(
"EXE path: <%s> dir:<%s> name:<%s>"
,
g_prog_full_path
,
g_prog_dir
,
g_prog_name
);
if
(
g_os_param_reserved
[
0
]
==
3
)
{
Log
(
"Open log for debug ..."
);
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
"notepad.exe ventoy.log"
);
}
else
{
if
(
CallParam
[
0
])
{
strcat_s
(
LunchFile
,
sizeof
(
LunchFile
),
CallParam
);
}
else
if
(
NULL
==
strstr
(
LunchFile
,
"setup.exe"
))
{
Log
(
"Not setup.exe, hide windows."
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
}
if
(
_stricmp
(
g_prog_name
,
"WinLogon.exe"
)
==
0
)
{
Log
(
"This time is rejump back ..."
);
strcpy_s
(
g_prog_full_path
,
sizeof
(
g_prog_full_path
),
argv
[
1
]);
split_path_name
(
g_prog_full_path
,
g_prog_dir
,
g_prog_name
);
Log
(
"Ventoy jump %s ..."
,
rc
==
0
?
"success"
:
"failed"
);
}
Log
(
"Now launch <%s> ..."
,
LunchFile
);
return
real_main
(
argc
-
1
,
argv
+
1
);
}
else
if
(
_stricmp
(
g_prog_name
,
"PECMD.exe"
)
==
0
)
{
Log
(
"We need to rejump for pecmd ..."
);
if
(
g_os_param_reserved
[
0
]
==
4
)
{
Log
(
"Open cmd for debug ..."
);
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
"cmd.exe"
);
}
ventoy_check_create_directory
();
CopyFileA
(
g_prog_full_path
,
"ventoy
\\
WinLogon.exe"
,
TRUE
);
#ifdef VTOY_REJUMP_SUPPORTED
if
(
ReJump
)
{
sprintf_s
(
CallParam
,
sizeof
(
CallParam
),
"ventoy
\\
WinLogon.exe%s"
,
LunchFile
+
strlen
(
"PECMD.EXE"
));
Log
(
"Now rejump to pecmd.exe <%s> ..."
,
CallParam
);
sprintf_s
(
CallParam
,
sizeof
(
CallParam
),
"ventoy
\\
WinLogon.exe %s"
,
g_prog_full_path
);
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
strcat_s
(
CallParam
,
sizeof
(
CallParam
),
" "
);
strcat_s
(
CallParam
,
sizeof
(
CallParam
),
argv
[
i
]);
}
CreateProcessA
(
NULL
,
CallParam
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
Log
(
"Now rejump to <%s> ..."
,
CallParam
);
GetStartupInfoA
(
&
Si
);
CreateProcessA
(
NULL
,
CallParam
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
Log
(
"Wait rejump process..."
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
Log
(
"rejump finished"
);
return
0
;
}
#
else
(
void
)
ReJump
;
#endif
Log
(
"Wait rejump process..."
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
Log
(
"rejump finished"
);
return
0
;
}
else
{
Log
(
"We don't need to rejump ..."
);
CreateProcessA
(
NULL
,
LunchFile
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
strcpy_s
(
NewArgv0
,
sizeof
(
NewArgv0
),
g_prog_full_path
);
argv
[
0
]
=
NewArgv0
;
for
(
i
=
0
;
rc
&&
i
<
1800
;
i
++
)
{
Log
(
"Ventoy hook failed, now wait and retry ..."
);
Sleep
(
1000
);
rc
=
VentoyHook
(
&
g_os_param
);
}
return
real_main
(
argc
,
argv
);
}
}
Log
(
"Wait process..."
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
Log
(
"vtoyjump finished"
);
return
0
;
}
vtoyjump/vtoyjump/vtoyjump.vcxproj
View file @
a9be2fd4
...
...
@@ -126,7 +126,7 @@
<Optimization>
MaxSpeed
</Optimization>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<PreprocessorDefinitions>
VTOY_32;FATFS_INC_FORMAT_SUPPORT=0;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<PreprocessorDefinitions>
VTOY_
BIT=
32;FATFS_INC_FORMAT_SUPPORT=0;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<SDLCheck>
true
</SDLCheck>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
</ClCompile>
...
...
@@ -146,7 +146,7 @@
<Optimization>
MaxSpeed
</Optimization>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<PreprocessorDefinitions>
VTOY_64;FATFS_INC_FORMAT_SUPPORT=0;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<PreprocessorDefinitions>
VTOY_
BIT=
64;FATFS_INC_FORMAT_SUPPORT=0;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<SDLCheck>
true
</SDLCheck>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
</ClCompile>
...
...
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