1 /******************************************************************************
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #include <VersionHelpers.h>
29 #include "fat_filelib.h"
31 static ventoy_os_param g_os_param
;
32 static ventoy_windows_data g_windows_data
;
33 static UINT8 g_os_param_reserved
[32];
34 static BOOL g_64bit_system
= FALSE
;
35 static ventoy_guid g_ventoy_guid
= VENTOY_GUID
;
36 static HANDLE g_vtoylog_mutex
= NULL
;
37 static HANDLE g_vtoyins_mutex
= NULL
;
40 static BOOL g_PecmdHasCmdLine
= FALSE
;
41 static UCHAR g_aucCmdLineHex
[] =
43 0x43, 0x00, 0x6D, 0x00, 0x64, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x65, 0x00
46 #define VTOY_PID_FILE "X:\\Windows\\System32\\pidventoy"
47 #define MUTEX_LOCK(hmutex) if (hmutex != NULL) LockStatus = WaitForSingleObject(hmutex, INFINITE)
48 #define MUTEX_UNLOCK(hmutex) if (hmutex != NULL && WAIT_OBJECT_0 == LockStatus) ReleaseMutex(hmutex)
50 void Log(const char *Fmt
, ...)
58 DWORD PID
= GetCurrentProcessId();
61 Len
+= sprintf_s(szBuf
, sizeof(szBuf
),
62 "[%4d/%02d/%02d %02d:%02d:%02d.%03d] [%u] ",
63 Sys
.wYear
, Sys
.wMonth
, Sys
.wDay
,
64 Sys
.wHour
, Sys
.wMinute
, Sys
.wSecond
,
65 Sys
.wMilliseconds
, PID
);
68 Len
+= vsnprintf_s(szBuf
+ Len
, sizeof(szBuf
)-Len
, sizeof(szBuf
)-Len
, Fmt
, Arg
);
71 MUTEX_LOCK(g_vtoylog_mutex
);
73 fopen_s(&File
, "ventoy.log", "a+");
76 fwrite(szBuf
, 1, Len
, File
);
77 fwrite("\n", 1, 1, File
);
81 MUTEX_UNLOCK(g_vtoylog_mutex
);
85 static int LoadNtDriver(const char *DrvBinPath
)
91 SC_HANDLE hServiceMgr
;
93 char name
[256] = { 0 };
95 for (i
= (int)strlen(DrvBinPath
) - 1; i
>= 0; i
--)
97 if (DrvBinPath
[i
] == '\\' || DrvBinPath
[i
] == '/')
99 sprintf_s(name
, sizeof(name
), "%s", DrvBinPath
+ i
+ 1);
104 Log("Load NT driver: %s %s", DrvBinPath
, name
);
106 hServiceMgr
= OpenSCManagerA(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
107 if (hServiceMgr
== NULL
)
109 Log("OpenSCManager failed Error:%u", GetLastError());
113 Log("OpenSCManager OK");
115 hService
= CreateServiceA(hServiceMgr
,
119 SERVICE_KERNEL_DRIVER
,
120 SERVICE_DEMAND_START
,
121 SERVICE_ERROR_NORMAL
,
123 NULL
, NULL
, NULL
, NULL
, NULL
);
124 if (hService
== NULL
)
126 Status
= GetLastError();
127 if (Status
!= ERROR_IO_PENDING
&& Status
!= ERROR_SERVICE_EXISTS
)
129 Log("CreateService failed v %u", Status
);
130 CloseServiceHandle(hServiceMgr
);
134 hService
= OpenServiceA(hServiceMgr
, name
, SERVICE_ALL_ACCESS
);
135 if (hService
== NULL
)
137 Log("OpenService failed %u", Status
);
138 CloseServiceHandle(hServiceMgr
);
143 Log("CreateService imdisk OK");
145 Ret
= StartServiceA(hService
, 0, NULL
);
148 Log("StartService OK");
152 Status
= GetLastError();
153 if (Status
== ERROR_SERVICE_ALREADY_RUNNING
)
159 Log("StartService error %u", Status
);
164 CloseServiceHandle(hService
);
165 CloseServiceHandle(hServiceMgr
);
167 Log("Load NT driver %s", rc
? "failed" : "success");
172 static int ReadWholeFile2Buf(const char *Fullpath
, void **Data
, DWORD
*Size
)
180 Log("ReadWholeFile2Buf <%s>", Fullpath
);
182 Handle
= CreateFileA(Fullpath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
183 if (Handle
== INVALID_HANDLE_VALUE
)
185 Log("Could not open the file<%s>, error:%u", Fullpath
, GetLastError());
189 FileSize
= SetFilePointer(Handle
, 0, NULL
, FILE_END
);
191 Buffer
= malloc(FileSize
);
194 Log("Failed to alloc memory size:%u", FileSize
);
198 SetFilePointer(Handle
, 0, NULL
, FILE_BEGIN
);
199 if (!ReadFile(Handle
, Buffer
, FileSize
, &dwSize
, NULL
))
201 Log("ReadFile failed, dwSize:%u error:%u", dwSize
, GetLastError());
208 Log("Success read file size:%u", FileSize
);
213 SAFE_CLOSE_HANDLE(Handle
);
218 static BOOL
CheckPeHead(BYTE
*Head
)
222 if (Head
[0] != 'M' || Head
[1] != 'Z')
227 PeOffset
= *(UINT32
*)(Head
+ 60);
228 if (*(UINT32
*)(Head
+ PeOffset
) != 0x00004550)
236 static BOOL
IsPe64(BYTE
*buffer
)
240 if (!CheckPeHead(buffer
))
245 pe_off
= *(UINT32
*)(buffer
+ 60);
246 if (*(UINT16
*)(buffer
+ pe_off
+ 24) == 0x020b)
255 static BOOL
CheckOsParam(ventoy_os_param
*param
)
260 if (memcmp(¶m
->guid
, &g_ventoy_guid
, sizeof(ventoy_guid
)))
265 for (i
= 0; i
< sizeof(ventoy_os_param
); i
++)
267 Sum
+= *((BYTE
*)param
+ i
);
275 if (param
->vtoy_img_location_addr
% 4096)
283 static int SaveBuffer2File(const char *Fullpath
, void *Buffer
, DWORD Length
)
289 Log("SaveBuffer2File <%s> len:%u", Fullpath
, Length
);
291 Handle
= CreateFileA(Fullpath
, GENERIC_READ
| GENERIC_WRITE
,
292 FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, CREATE_NEW
, 0, 0);
293 if (Handle
== INVALID_HANDLE_VALUE
)
295 Log("Could not create new file, error:%u", GetLastError());
299 WriteFile(Handle
, Buffer
, Length
, &dwSize
, NULL
);
304 SAFE_CLOSE_HANDLE(Handle
);
309 static int IsUTF8Encode(const char *src
)
312 const UCHAR
*Byte
= (const UCHAR
*)src
;
314 for (i
= 0; i
< MAX_PATH
&& Byte
[i
]; i
++)
325 static int Utf8ToUtf16(const char* src
, WCHAR
* dst
)
327 int size
= MultiByteToWideChar(CP_UTF8
, 0, src
, -1, dst
, 0);
328 return MultiByteToWideChar(CP_UTF8
, 0, src
, -1, dst
, size
+ 1);
331 static BOOL
IsDirExist(const char *Fmt
, ...)
336 CHAR FilePathA
[MAX_PATH
];
337 WCHAR FilePathW
[MAX_PATH
];
340 vsnprintf_s(FilePathA
, sizeof(FilePathA
), sizeof(FilePathA
), Fmt
, Arg
);
343 UTF8
= IsUTF8Encode(FilePathA
);
347 Utf8ToUtf16(FilePathA
, FilePathW
);
348 Attr
= GetFileAttributesW(FilePathW
);
352 Attr
= GetFileAttributesA(FilePathA
);
355 if (Attr
!= INVALID_FILE_ATTRIBUTES
&& (Attr
& FILE_ATTRIBUTE_DIRECTORY
))
363 static BOOL
IsFileExist(const char *Fmt
, ...)
370 CHAR FilePathA
[MAX_PATH
];
371 WCHAR FilePathW
[MAX_PATH
];
374 vsnprintf_s(FilePathA
, sizeof(FilePathA
), sizeof(FilePathA
), Fmt
, Arg
);
377 UTF8
= IsUTF8Encode(FilePathA
);
381 Utf8ToUtf16(FilePathA
, FilePathW
);
382 hFile
= CreateFileW(FilePathW
, FILE_READ_EA
, FILE_SHARE_READ
, 0, OPEN_EXISTING
, 0, 0);
386 hFile
= CreateFileA(FilePathA
, FILE_READ_EA
, FILE_SHARE_READ
, 0, OPEN_EXISTING
, 0, 0);
388 if (INVALID_HANDLE_VALUE
== hFile
)
397 Attr
= GetFileAttributesW(FilePathW
);
401 Attr
= GetFileAttributesA(FilePathA
);
404 if (Attr
& FILE_ATTRIBUTE_DIRECTORY
)
412 Log("File <%s> %s", FilePathA
, (bRet
? "exist" : "NOT exist"));
416 static int GetPhyDiskUUID(const char LogicalDrive
, UINT8
*UUID
, DISK_EXTENT
*DiskExtent
)
421 VOLUME_DISK_EXTENTS DiskExtents
;
423 UINT8 SectorBuf
[512];
425 Log("GetPhyDiskUUID %C", LogicalDrive
);
427 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\%C:", LogicalDrive
);
428 Handle
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
429 if (Handle
== INVALID_HANDLE_VALUE
)
431 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
435 Ret
= DeviceIoControl(Handle
,
436 IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
,
440 (DWORD
)(sizeof(DiskExtents
)),
443 if (!Ret
|| DiskExtents
.NumberOfDiskExtents
== 0)
445 Log("DeviceIoControl IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed, error:%u", GetLastError());
451 memcpy(DiskExtent
, DiskExtents
.Extents
, sizeof(DiskExtent
));
452 Log("%C: is in PhysicalDrive%d ", LogicalDrive
, DiskExtents
.Extents
[0].DiskNumber
);
454 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\PhysicalDrive%d", DiskExtents
.Extents
[0].DiskNumber
);
455 Handle
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
456 if (Handle
== INVALID_HANDLE_VALUE
)
458 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
462 if (!ReadFile(Handle
, SectorBuf
, sizeof(SectorBuf
), &dwSize
, NULL
))
464 Log("ReadFile failed, dwSize:%u error:%u", dwSize
, GetLastError());
469 memcpy(UUID
, SectorBuf
+ 0x180, 16);
474 static int VentoyMountAnywhere(HANDLE Handle
)
477 ATTACH_VIRTUAL_DISK_PARAMETERS AttachParameters
;
479 Log("VentoyMountAnywhere");
481 memset(&AttachParameters
, 0, sizeof(AttachParameters
));
482 AttachParameters
.Version
= ATTACH_VIRTUAL_DISK_VERSION_1
;
484 Status
= AttachVirtualDisk(Handle
, NULL
, ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY
| ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME
, 0, &AttachParameters
, NULL
);
485 if (Status
!= ERROR_SUCCESS
)
487 Log("Failed to attach virtual disk ErrorCode:%u", Status
);
494 int VentoyMountY(HANDLE Handle
)
499 DWORD physicalDriveNameSize
;
501 WCHAR physicalDriveName
[MAX_PATH
];
502 CHAR physicalDriveNameA
[MAX_PATH
];
503 CHAR cdromDriveName
[MAX_PATH
];
504 ATTACH_VIRTUAL_DISK_PARAMETERS AttachParameters
;
508 memset(&AttachParameters
, 0, sizeof(AttachParameters
));
509 AttachParameters
.Version
= ATTACH_VIRTUAL_DISK_VERSION_1
;
511 Status
= AttachVirtualDisk(Handle
, NULL
, ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY
| ATTACH_VIRTUAL_DISK_FLAG_NO_DRIVE_LETTER
| ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME
, 0, &AttachParameters
, NULL
);
512 if (Status
!= ERROR_SUCCESS
)
514 Log("Failed to attach virtual disk ErrorCode:%u", Status
);
518 memset(physicalDriveName
, 0, sizeof(physicalDriveName
));
519 memset(physicalDriveNameA
, 0, sizeof(physicalDriveNameA
));
521 physicalDriveNameSize
= MAX_PATH
;
522 Status
= GetVirtualDiskPhysicalPath(Handle
, &physicalDriveNameSize
, physicalDriveName
);
523 if (Status
!= ERROR_SUCCESS
)
525 Log("Failed GetVirtualDiskPhysicalPath ErrorCode:%u", Status
);
529 for (i
= 0; physicalDriveName
[i
]; i
++)
531 physicalDriveNameA
[i
] = toupper((CHAR
)(physicalDriveName
[i
]));
534 Log("physicalDriveNameA=<%s>", physicalDriveNameA
);
536 Pos
= strstr(physicalDriveNameA
, "CDROM");
539 Log("Not cdrom phy drive");
543 sprintf_s(cdromDriveName
, sizeof(cdromDriveName
), "\\Device\\%s", Pos
);
544 Log("cdromDriveName=<%s>", cdromDriveName
);
546 for (i
= 0; i
< 3 && (bRet
== FALSE
); i
++)
549 bRet
= DefineDosDeviceA(DDD_RAW_TARGET_PATH
, "Y:", cdromDriveName
);
550 Log("DefineDosDeviceA %s", bRet
? "success" : "failed");
556 static BOOL
VentoyNeedMountY(const char *IsoPath
)
562 static int VentoyAttachVirtualDisk(HANDLE Handle
, const char *IsoPath
)
567 Drives
= GetLogicalDrives();
568 if ((1 << 24) & Drives
)
570 Log("Y: is occupied");
575 Log("Y: is free now");
579 if (DriveYFree
&& VentoyNeedMountY(IsoPath
))
581 return VentoyMountY(Handle
);
585 return VentoyMountAnywhere(Handle
);
589 int VentoyMountISOByAPI(const char *IsoPath
)
593 WCHAR wFilePath
[512] = { 0 };
594 VIRTUAL_STORAGE_TYPE StorageType
;
595 OPEN_VIRTUAL_DISK_PARAMETERS OpenParameters
;
597 Log("VentoyMountISOByAPI <%s>", IsoPath
);
599 if (IsUTF8Encode(IsoPath
))
601 MultiByteToWideChar(CP_UTF8
, 0, IsoPath
, (int)strlen(IsoPath
), wFilePath
, (int)(sizeof(wFilePath
) / sizeof(WCHAR
)));
605 MultiByteToWideChar(CP_ACP
, 0, IsoPath
, (int)strlen(IsoPath
), wFilePath
, (int)(sizeof(wFilePath
) / sizeof(WCHAR
)));
608 memset(&StorageType
, 0, sizeof(StorageType
));
609 memset(&OpenParameters
, 0, sizeof(OpenParameters
));
611 OpenParameters
.Version
= OPEN_VIRTUAL_DISK_VERSION_1
;
613 Status
= OpenVirtualDisk(&StorageType
, wFilePath
, VIRTUAL_DISK_ACCESS_READ
, 0, &OpenParameters
, &Handle
);
614 if (Status
!= ERROR_SUCCESS
)
616 if (ERROR_VIRTDISK_PROVIDER_NOT_FOUND
== Status
)
618 Log("VirtualDisk for ISO file is not supported in current system");
622 Log("Failed to open virtual disk ErrorCode:%u", Status
);
627 Log("OpenVirtualDisk success");
629 Status
= VentoyAttachVirtualDisk(Handle
, IsoPath
);
630 if (Status
!= ERROR_SUCCESS
)
632 Log("Failed to attach virtual disk ErrorCode:%u", Status
);
637 Log("VentoyAttachVirtualDisk success");
644 static HANDLE g_FatPhyDrive
;
645 static UINT64 g_Part2StartSec
;
647 static int CopyFileFromFatDisk(const CHAR
* SrcFile
, const CHAR
*DstFile
)
654 Log("CopyFileFromFatDisk (%s)==>(%s)", SrcFile
, DstFile
);
656 flfile
= fl_fopen(SrcFile
, "rb");
659 fl_fseek(flfile
, 0, SEEK_END
);
660 size
= (int)fl_ftell(flfile
);
661 fl_fseek(flfile
, 0, SEEK_SET
);
663 buf
= (char *)malloc(size
);
666 fl_fread(buf
, 1, size
, flfile
);
669 SaveBuffer2File(DstFile
, buf
, size
);
679 static int VentoyFatDiskRead(uint32 Sector
, uint8
*Buffer
, uint32 SectorCount
)
684 LARGE_INTEGER liCurrentPosition
;
686 liCurrentPosition
.QuadPart
= Sector
+ g_Part2StartSec
;
687 liCurrentPosition
.QuadPart
*= 512;
688 SetFilePointerEx(g_FatPhyDrive
, liCurrentPosition
, &liCurrentPosition
, FILE_BEGIN
);
690 ReadSize
= (DWORD
)(SectorCount
* 512);
692 bRet
= ReadFile(g_FatPhyDrive
, Buffer
, ReadSize
, &dwSize
, NULL
);
693 if (bRet
== FALSE
|| dwSize
!= ReadSize
)
695 Log("ReadFile error bRet:%u WriteSize:%u dwSize:%u ErrCode:%u\n", bRet
, ReadSize
, dwSize
, GetLastError());
701 static BOOL
Is2K10PE(void)
707 fopen_s(&fp
, "X:\\Windows\\System32\\PECMD.INI", "r");
713 memset(szLine
, 0, sizeof(szLine
));
714 while (fgets(szLine
, sizeof(szLine
) - 1, fp
))
716 if (strstr(szLine
, "\\2k10\\"))
727 static CHAR
GetMountLogicalDrive(void)
731 DWORD Mask
= 0x1000000;
733 // fixed use M as mountpoint for 2K10 PE
736 Log("Use M: for 2K10 PE");
740 Drives
= GetLogicalDrives();
741 Log("Drives=0x%x", Drives
);
745 if ((Drives
& Mask
) == 0)
757 UINT64
GetVentoyEfiPartStartSector(HANDLE hDrive
)
762 VTOY_GPT_INFO
*pGpt
= NULL
;
763 UINT64 StartSector
= 0;
765 SetFilePointer(hDrive
, 0, NULL
, FILE_BEGIN
);
767 bRet
= ReadFile(hDrive
, &MBR
, sizeof(MBR
), &dwSize
, NULL
);
768 Log("Read MBR Ret:%u Size:%u code:%u", bRet
, dwSize
, LASTERR
);
770 if ((!bRet
) || (dwSize
!= sizeof(MBR
)))
775 if (MBR
.PartTbl
[0].FsFlag
== 0xEE)
777 Log("GPT partition style");
779 pGpt
= malloc(sizeof(VTOY_GPT_INFO
));
785 SetFilePointer(hDrive
, 0, NULL
, FILE_BEGIN
);
786 bRet
= ReadFile(hDrive
, pGpt
, sizeof(VTOY_GPT_INFO
), &dwSize
, NULL
);
787 if ((!bRet
) || (dwSize
!= sizeof(VTOY_GPT_INFO
)))
789 Log("Failed to read gpt info %d %u %d", bRet
, dwSize
, LASTERR
);
793 StartSector
= pGpt
->PartTbl
[1].StartLBA
;
798 Log("MBR partition style");
799 StartSector
= MBR
.PartTbl
[1].StartSectorId
;
802 Log("GetVentoyEfiPart StartSector: %llu", StartSector
);
806 static int VentoyRunImdisk(const char *IsoPath
, const char *imdiskexe
)
811 PROCESS_INFORMATION Pi
;
813 Log("VentoyRunImdisk <%s> <%s>", IsoPath
, imdiskexe
);
815 Letter
= GetMountLogicalDrive();
816 sprintf_s(Cmdline
, sizeof(Cmdline
), "%s -a -o ro -f \"%s\" -m %C:", imdiskexe
, IsoPath
, Letter
);
817 Log("mount iso to %C: use imdisk cmd <%s>", Letter
, Cmdline
);
819 if (IsUTF8Encode(IsoPath
))
822 GetStartupInfoW(&Si
);
823 Si
.dwFlags
|= STARTF_USESHOWWINDOW
;
824 Si
.wShowWindow
= SW_HIDE
;
826 Utf8ToUtf16(Cmdline
, CmdlineW
);
827 CreateProcessW(NULL
, CmdlineW
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
829 Log("This is UTF8 encoding");
834 GetStartupInfoA(&Si
);
835 Si
.dwFlags
|= STARTF_USESHOWWINDOW
;
836 Si
.wShowWindow
= SW_HIDE
;
838 CreateProcessA(NULL
, Cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
840 Log("This is ANSI encoding");
843 Log("Wait for imdisk process ...");
844 WaitForSingleObject(Pi
.hProcess
, INFINITE
);
845 Log("imdisk process finished");
850 int VentoyMountISOByImdisk(const char *IsoPath
, DWORD PhyDrive
)
856 CHAR PhyPath
[MAX_PATH
];
857 GET_LENGTH_INFORMATION LengthInfo
;
859 Log("VentoyMountISOByImdisk %s", IsoPath
);
861 if (IsFileExist("X:\\Windows\\System32\\imdisk.exe"))
863 Log("imdisk.exe exist, use it directly...");
864 VentoyRunImdisk(IsoPath
, "imdisk.exe");
868 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\PhysicalDrive%d", PhyDrive
);
869 hDrive
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
870 if (hDrive
== INVALID_HANDLE_VALUE
)
872 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
876 bRet
= DeviceIoControl(hDrive
, IOCTL_DISK_GET_LENGTH_INFO
, NULL
, 0, &LengthInfo
, sizeof(LengthInfo
), &dwBytes
, NULL
);
879 Log("Could not get phy disk %s size, error:%u", PhyPath
, GetLastError());
883 g_FatPhyDrive
= hDrive
;
884 g_Part2StartSec
= GetVentoyEfiPartStartSector(hDrive
);
886 Log("Parse FAT fs...");
890 if (0 == fl_attach_media(VentoyFatDiskRead
, NULL
))
894 CopyFileFromFatDisk("/ventoy/imdisk/64/imdisk.sys", "ventoy\\imdisk.sys");
895 CopyFileFromFatDisk("/ventoy/imdisk/64/imdisk.exe", "ventoy\\imdisk.exe");
896 CopyFileFromFatDisk("/ventoy/imdisk/64/imdisk.cpl", "ventoy\\imdisk.cpl");
900 CopyFileFromFatDisk("/ventoy/imdisk/32/imdisk.sys", "ventoy\\imdisk.sys");
901 CopyFileFromFatDisk("/ventoy/imdisk/32/imdisk.exe", "ventoy\\imdisk.exe");
902 CopyFileFromFatDisk("/ventoy/imdisk/32/imdisk.cpl", "ventoy\\imdisk.cpl");
905 GetCurrentDirectoryA(sizeof(PhyPath
), PhyPath
);
906 strcat_s(PhyPath
, sizeof(PhyPath
), "\\ventoy\\imdisk.sys");
908 if (LoadNtDriver(PhyPath
) == 0)
910 VentoyRunImdisk(IsoPath
, "ventoy\\imdisk.exe");
918 SAFE_CLOSE_HANDLE(hDrive
);
923 static int MountIsoFile(CONST CHAR
*IsoPath
, DWORD PhyDrive
)
925 if (IsWindows8OrGreater())
927 Log("This is Windows 8 or latter...");
928 if (VentoyMountISOByAPI(IsoPath
) == 0)
930 Log("Mount iso by API success");
935 Log("Mount iso by API failed, maybe not supported, try imdisk");
936 return VentoyMountISOByImdisk(IsoPath
, PhyDrive
);
941 Log("This is before Windows 8 ...");
942 if (VentoyMountISOByImdisk(IsoPath
, PhyDrive
) == 0)
944 Log("Mount iso by imdisk success");
949 return VentoyMountISOByAPI(IsoPath
);
954 static int GetPhyDriveByLogicalDrive(int DriveLetter
)
959 VOLUME_DISK_EXTENTS DiskExtents
;
962 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\%C:", (CHAR
)DriveLetter
);
964 Handle
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
965 if (Handle
== INVALID_HANDLE_VALUE
)
967 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
971 Ret
= DeviceIoControl(Handle
,
972 IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
,
976 (DWORD
)(sizeof(DiskExtents
)),
980 if (!Ret
|| DiskExtents
.NumberOfDiskExtents
== 0)
982 Log("DeviceIoControl IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed %s, error:%u", PhyPath
, GetLastError());
983 SAFE_CLOSE_HANDLE(Handle
);
986 SAFE_CLOSE_HANDLE(Handle
);
988 Log("LogicalDrive:%s PhyDrive:%d Offset:%llu ExtentLength:%llu",
990 DiskExtents
.Extents
[0].DiskNumber
,
991 DiskExtents
.Extents
[0].StartingOffset
.QuadPart
,
992 DiskExtents
.Extents
[0].ExtentLength
.QuadPart
995 return (int)DiskExtents
.Extents
[0].DiskNumber
;
999 static int DeleteVentoyPart2MountPoint(DWORD PhyDrive
)
1004 CHAR DriveName
[] = "?:\\";
1006 Log("DeleteVentoyPart2MountPoint Phy%u ...", PhyDrive
);
1008 Drives
= GetLogicalDrives();
1011 if ((Drives
& 0x01) && IsFileExist("%C:\\ventoy\\ventoy.cpio", Letter
))
1013 Log("File %C:\\ventoy\\ventoy.cpio exist", Letter
);
1015 PhyDisk
= GetPhyDriveByLogicalDrive(Letter
);
1016 Log("PhyDisk=%u for %C", PhyDisk
, Letter
);
1018 if (PhyDisk
== PhyDrive
)
1020 DriveName
[0] = Letter
;
1021 DeleteVolumeMountPointA(DriveName
);
1033 static BOOL
check_tar_archive(const char *archive
, CHAR
*tarName
)
1037 const char *pos
= archive
;
1038 const char *slash
= archive
;
1042 if (*pos
== '\\' || *pos
== '/')
1049 len
= (int)strlen(slash
);
1051 if (len
> 7 && (strncmp(slash
+ len
- 7, ".tar.gz", 7) == 0 || strncmp(slash
+ len
- 7, ".tar.xz", 7) == 0))
1053 nameLen
= (int)sprintf_s(tarName
, MAX_PATH
, "X:%s", slash
);
1054 tarName
[nameLen
- 3] = 0;
1057 else if (len
> 8 && strncmp(slash
+ len
- 8, ".tar.bz2", 8) == 0)
1059 nameLen
= (int)sprintf_s(tarName
, MAX_PATH
, "X:%s", slash
);
1060 tarName
[nameLen
- 4] = 0;
1063 else if (len
> 9 && strncmp(slash
+ len
- 9, ".tar.lzma", 9) == 0)
1065 nameLen
= (int)sprintf_s(tarName
, MAX_PATH
, "X:%s", slash
);
1066 tarName
[nameLen
- 5] = 0;
1073 static int DecompressInjectionArchive(const char *archive
, DWORD PhyDrive
)
1080 DWORD flags
= CREATE_NO_WINDOW
;
1081 CHAR StrBuf
[MAX_PATH
];
1082 CHAR tarName
[MAX_PATH
];
1084 PROCESS_INFORMATION Pi
;
1085 PROCESS_INFORMATION NewPi
;
1086 GET_LENGTH_INFORMATION LengthInfo
;
1087 SECURITY_ATTRIBUTES Sa
= { sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
1089 Log("DecompressInjectionArchive %s", archive
);
1091 sprintf_s(StrBuf
, sizeof(StrBuf
), "\\\\.\\PhysicalDrive%d", PhyDrive
);
1092 hDrive
= CreateFileA(StrBuf
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
1093 if (hDrive
== INVALID_HANDLE_VALUE
)
1095 Log("Could not open the disk<%s>, error:%u", StrBuf
, GetLastError());
1099 bRet
= DeviceIoControl(hDrive
, IOCTL_DISK_GET_LENGTH_INFO
, NULL
, 0, &LengthInfo
, sizeof(LengthInfo
), &dwBytes
, NULL
);
1102 Log("Could not get phy disk %s size, error:%u", StrBuf
, GetLastError());
1106 g_FatPhyDrive
= hDrive
;
1107 g_Part2StartSec
= GetVentoyEfiPartStartSector(hDrive
);
1109 Log("Parse FAT fs...");
1113 if (0 == fl_attach_media(VentoyFatDiskRead
, NULL
))
1117 CopyFileFromFatDisk("/ventoy/7z/64/7za.exe", "ventoy\\7za.exe");
1121 CopyFileFromFatDisk("/ventoy/7z/32/7za.exe", "ventoy\\7za.exe");
1124 sprintf_s(StrBuf
, sizeof(StrBuf
), "ventoy\\7za.exe x -y -aoa -oX:\\ %s", archive
);
1126 Log("extract inject to X:");
1127 Log("cmdline:<%s>", StrBuf
);
1129 GetStartupInfoA(&Si
);
1131 hOut
= CreateFileA("ventoy\\7z.log",
1133 FILE_SHARE_WRITE
| FILE_SHARE_READ
,
1136 FILE_ATTRIBUTE_NORMAL
,
1139 Si
.dwFlags
|= STARTF_USESTDHANDLES
;
1141 if (hOut
!= INVALID_HANDLE_VALUE
)
1143 Si
.hStdError
= hOut
;
1144 Si
.hStdOutput
= hOut
;
1147 CreateProcessA(NULL
, StrBuf
, NULL
, NULL
, TRUE
, flags
, NULL
, NULL
, &Si
, &Pi
);
1148 WaitForSingleObject(Pi
.hProcess
, INFINITE
);
1151 // decompress tar archive, for tar.gz/tar.xz/tar.bz2
1153 if (check_tar_archive(archive
, tarName
))
1155 Log("Decompress tar archive...<%s>", tarName
);
1157 sprintf_s(StrBuf
, sizeof(StrBuf
), "ventoy\\7za.exe x -y -aoa -oX:\\ %s", tarName
);
1159 CreateProcessA(NULL
, StrBuf
, NULL
, NULL
, TRUE
, flags
, NULL
, NULL
, &Si
, &NewPi
);
1160 WaitForSingleObject(NewPi
.hProcess
, INFINITE
);
1162 Log("Now delete %s", tarName
);
1163 DeleteFileA(tarName
);
1166 SAFE_CLOSE_HANDLE(hOut
);
1172 SAFE_CLOSE_HANDLE(hDrive
);
1177 static int ProcessUnattendedInstallation(const char *script
)
1183 CHAR CurDir
[MAX_PATH
];
1185 Log("Copy unattended XML ...");
1187 GetCurrentDirectory(sizeof(CurDir
), CurDir
);
1189 if ((Letter
>= 'A' && Letter
<= 'Z') || (Letter
>= 'a' && Letter
<= 'z'))
1191 Log("Current Drive Letter: %C", Letter
);
1198 sprintf_s(CurDir
, sizeof(CurDir
), "%C:\\Autounattend.xml", Letter
);
1199 Log("Copy file <%s> --> <%s>", script
, CurDir
);
1200 CopyFile(script
, CurDir
, FALSE
);
1202 Ret
= RegCreateKeyEx(HKEY_LOCAL_MACHINE
, "System\\Setup", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hKey
, &dw
);
1203 if (ERROR_SUCCESS
== Ret
)
1205 Ret
= RegSetValueEx(hKey
, "UnattendFile", 0, REG_SZ
, CurDir
, (DWORD
)(strlen(CurDir
) + 1));
1211 static int VentoyHook(ventoy_os_param
*param
)
1215 DISK_EXTENT DiskExtent
;
1216 DWORD Drives
= GetLogicalDrives();
1218 CHAR IsoPath
[MAX_PATH
];
1220 Log("Logical Drives=0x%x Path:<%s>", Drives
, param
->vtoy_img_path
);
1222 if (IsUTF8Encode(param
->vtoy_img_path
))
1224 Log("This file is UTF8 encoding\n");
1231 sprintf_s(IsoPath
, sizeof(IsoPath
), "%C:\\%s", Letter
, param
->vtoy_img_path
);
1232 if (IsFileExist("%s", IsoPath
))
1234 Log("File exist under %C:", Letter
);
1235 if (GetPhyDiskUUID(Letter
, UUID
, &DiskExtent
) == 0)
1237 if (memcmp(UUID
, param
->vtoy_disk_guid
, 16) == 0)
1239 Log("Disk UUID match");
1246 Log("File NOT exist under %C:", Letter
);
1256 Log("Failed to find ISO file");
1260 Log("Find ISO file <%s>", IsoPath
);
1262 rc
= MountIsoFile(IsoPath
, DiskExtent
.DiskNumber
);
1263 Log("Mount ISO FILE: %s", rc
== 0 ? "SUCCESS" : "FAILED");
1266 rc
= DeleteVentoyPart2MountPoint(DiskExtent
.DiskNumber
);
1267 Log("Delete ventoy mountpoint: %s", rc
== 0 ? "SUCCESS" : "NO NEED");
1269 if (g_windows_data
.auto_install_script
[0])
1271 sprintf_s(IsoPath
, sizeof(IsoPath
), "%C:%s", Letter
, g_windows_data
.auto_install_script
);
1272 if (IsFileExist("%s", IsoPath
))
1274 Log("use auto install script %s...", IsoPath
);
1275 ProcessUnattendedInstallation(IsoPath
);
1279 Log("auto install script %s not exist", IsoPath
);
1284 Log("auto install no need");
1287 if (g_windows_data
.injection_archive
[0])
1289 sprintf_s(IsoPath
, sizeof(IsoPath
), "%C:%s", Letter
, g_windows_data
.injection_archive
);
1290 if (IsFileExist("%s", IsoPath
))
1292 Log("decompress injection archive %s...", IsoPath
);
1293 DecompressInjectionArchive(IsoPath
, DiskExtent
.DiskNumber
);
1297 Log("injection archive %s not exist", IsoPath
);
1302 Log("no injection archive found");
1308 const char * GetFileNameInPath(const char *fullpath
)
1311 const char *pos
= NULL
;
1313 if (strstr(fullpath
, ":"))
1315 for (i
= (int)strlen(fullpath
); i
> 0; i
--)
1317 if (fullpath
[i
- 1] == '/' || fullpath
[i
- 1] == '\\')
1319 return fullpath
+ i
;
1327 int VentoyJumpWimboot(INT argc
, CHAR
**argv
, CHAR
*LunchFile
)
1335 g_64bit_system
= FALSE
;
1337 g_64bit_system
= TRUE
;
1340 Log("VentoyJumpWimboot %dbit", g_64bit_system
? 64 : 32);
1342 sprintf_s(LunchFile
, MAX_PATH
, "X:\\setup.exe");
1344 ReadWholeFile2Buf("wimboot.data", &buf
, &size
);
1345 Log("wimboot.data size:%d", size
);
1347 memcpy(&g_os_param
, buf
, sizeof(ventoy_os_param
));
1348 memcpy(&g_windows_data
, buf
+ sizeof(ventoy_os_param
), sizeof(ventoy_windows_data
));
1349 memcpy(g_os_param_reserved
, g_os_param
.vtoy_reserved
, sizeof(g_os_param_reserved
));
1351 if (g_os_param_reserved
[0] == 1)
1353 Log("break here for debug .....");
1358 for (Pos
= 0; Pos
< sizeof(g_os_param
.vtoy_img_path
) && g_os_param
.vtoy_img_path
[Pos
]; Pos
++)
1360 if (g_os_param
.vtoy_img_path
[Pos
] == '/')
1362 g_os_param
.vtoy_img_path
[Pos
] = '\\';
1366 if (g_os_param_reserved
[0] == 2)
1368 Log("skip hook for debug .....");
1373 rc
= VentoyHook(&g_os_param
);
1385 static int ventoy_check_create_directory(void)
1387 if (IsDirExist("ventoy"))
1389 Log("ventoy directory already exist");
1393 Log("ventoy directory not exist, now create it.");
1394 if (!CreateDirectoryA("ventoy", NULL
))
1396 Log("Failed to create ventoy directory err:%u", GetLastError());
1404 static BOOL
VentoyFindCmdLineStr(BYTE
*buf
, DWORD size
)
1408 UINT32 uiDataHex
= *(UINT32
*)(g_aucCmdLineHex
);
1410 for (i
= 0; i
< size
- sizeof(g_aucCmdLineHex
); i
+= 16)
1412 uiDataChk
= *(UINT32
*)(buf
+ i
);
1413 if (uiDataChk
== uiDataHex
&& memcmp(buf
+ i
, g_aucCmdLineHex
, sizeof(g_aucCmdLineHex
)) == 0)
1422 int VentoyJump(INT argc
, CHAR
**argv
, CHAR
*LunchFile
)
1429 DWORD LockStatus
= 0;
1430 BYTE
*Buffer
= NULL
;
1431 CHAR ExeFileName
[MAX_PATH
];
1433 sprintf_s(ExeFileName
, sizeof(ExeFileName
), "%s", argv
[0]);
1434 if (!IsFileExist("%s", ExeFileName
))
1436 Log("File %s NOT exist, now try %s.exe", ExeFileName
, ExeFileName
);
1437 sprintf_s(ExeFileName
, sizeof(ExeFileName
), "%s.exe", argv
[0]);
1439 Log("File %s exist ? %s", ExeFileName
, IsFileExist("%s", ExeFileName
) ? "YES" : "NO");
1442 if (ReadWholeFile2Buf(ExeFileName
, (void **)&Buffer
, &FileSize
))
1447 g_64bit_system
= IsPe64(Buffer
);
1448 Log("VentoyJump %dbit", g_64bit_system
? 64 : 32);
1450 MUTEX_LOCK(g_vtoyins_mutex
);
1451 stat
= ventoy_check_create_directory();
1452 MUTEX_UNLOCK(g_vtoyins_mutex
);
1459 for (PeStart
= 0; PeStart
< FileSize
; PeStart
+= 16)
1461 if (CheckOsParam((ventoy_os_param
*)(Buffer
+ PeStart
)) &&
1462 CheckPeHead(Buffer
+ PeStart
+ sizeof(ventoy_os_param
) + sizeof(ventoy_windows_data
)))
1464 Log("Find os pararm at %u", PeStart
);
1466 memcpy(&g_os_param
, Buffer
+ PeStart
, sizeof(ventoy_os_param
));
1467 memcpy(&g_windows_data
, Buffer
+ PeStart
+ sizeof(ventoy_os_param
), sizeof(ventoy_windows_data
));
1468 memcpy(g_os_param_reserved
, g_os_param
.vtoy_reserved
, sizeof(g_os_param_reserved
));
1470 if (g_os_param_reserved
[0] == 1)
1472 Log("break here for debug .....");
1477 for (Pos
= 0; Pos
< sizeof(g_os_param
.vtoy_img_path
) && g_os_param
.vtoy_img_path
[Pos
]; Pos
++)
1479 if (g_os_param
.vtoy_img_path
[Pos
] == '/')
1481 g_os_param
.vtoy_img_path
[Pos
] = '\\';
1485 PeStart
+= sizeof(ventoy_os_param
) + sizeof(ventoy_windows_data
);
1486 sprintf_s(LunchFile
, MAX_PATH
, "ventoy\\%s", GetFileNameInPath(ExeFileName
));
1488 MUTEX_LOCK(g_vtoyins_mutex
);
1489 if (IsFileExist("%s", LunchFile
))
1491 Log("vtoyjump multiple call ...");
1493 MUTEX_UNLOCK(g_vtoyins_mutex
);
1497 SaveBuffer2File(LunchFile
, Buffer
+ PeStart
, FileSize
- PeStart
);
1498 MUTEX_UNLOCK(g_vtoyins_mutex
);
1500 #ifdef VTOY_REJUMP_SUPPORTED
1501 if (_stricmp(LunchFile
, "ventoy\\PECMD.EXE") == 0)
1503 g_PecmdHasCmdLine
= VentoyFindCmdLineStr(Buffer
+ PeStart
, FileSize
- PeStart
);
1511 if (PeStart
>= FileSize
)
1513 Log("OS param not found");
1517 if (g_os_param_reserved
[0] == 2)
1519 Log("skip hook for debug .....");
1524 rc
= VentoyHook(&g_os_param
);
1538 static int ventoy_append_process_id(const char *pidfile
)
1543 PID
= GetCurrentProcessId();
1545 fopen_s(&fp
, pidfile
, "a+");
1551 fprintf_s(fp
, "%u\n", PID
);
1557 static int ventoy_get_instance_id(const char *pidfile
)
1563 fopen_s(&fp
, pidfile
, "r");
1569 while (fgets(line
, sizeof(line
), fp
))
1575 return instance
+ 1;
1578 int main(int argc
, char **argv
)
1583 BOOL ReJump
= FALSE
;
1585 CHAR CurDir
[MAX_PATH
];
1586 CHAR LunchFile
[MAX_PATH
];
1587 CHAR CallParam
[1024] = { 0 };
1588 DWORD LockStatus
= 0;
1590 PROCESS_INFORMATION Pi
;
1592 #ifdef VTOY_REJUMP_SUPPORTED
1593 if (argv
[0] && strcmp(argv
[0], "ventoy\\WinLogon.exe") == 0)
1595 GetStartupInfoA(&Si
);
1596 Si
.dwFlags
|= STARTF_USESHOWWINDOW
;
1597 Si
.wShowWindow
= SW_HIDE
;
1599 sprintf_s(LunchFile
, sizeof(LunchFile
), "PECMD.EXE");
1600 for (i
= 1; i
< argc
; i
++)
1602 strcat_s(LunchFile
, sizeof(LunchFile
), " ");
1603 strcat_s(LunchFile
, sizeof(LunchFile
), argv
[i
]);
1606 CreateProcessA(NULL
, LunchFile
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
1607 WaitForSingleObject(Pi
.hProcess
, INFINITE
);
1612 g_PecmdHasCmdLine
= 0;
1613 g_vtoylog_mutex
= CreateMutexA(NULL
, FALSE
, "VTOYLOG_LOCK");
1614 g_vtoyins_mutex
= CreateMutexA(NULL
, FALSE
, "VTOYINS_LOCK");
1616 MUTEX_LOCK(g_vtoyins_mutex
);
1617 if (IsFileExist(VTOY_PID_FILE
))
1619 id
= ventoy_get_instance_id(VTOY_PID_FILE
);
1625 ventoy_append_process_id(VTOY_PID_FILE
);
1626 MUTEX_UNLOCK(g_vtoyins_mutex
);
1628 if (argv
[0] && argv
[0][0] && argv
[0][1] == ':')
1630 GetCurrentDirectoryA(sizeof(CurDir
), CurDir
);
1632 strcpy_s(LunchFile
, sizeof(LunchFile
), argv
[0]);
1633 Pos
= (char *)GetFileNameInPath(LunchFile
);
1635 strcat_s(CurDir
, sizeof(CurDir
), "\\");
1636 strcat_s(CurDir
, sizeof(CurDir
), Pos
);
1638 if (_stricmp(argv
[0], CurDir
) != 0)
1641 SetCurrentDirectoryA(LunchFile
);
1646 Log("######## VentoyJump 32bit [%d] ##########", id
);
1648 Log("######## VentoyJump 64bit [%d] ##########", id
);
1651 Log("argc = %d", argc
);
1652 for (i
= 0; i
< argc
; i
++)
1654 Log("argv[%d]=<%s>", i
, argv
[i
]);
1657 strcat_s(CallParam
, sizeof(CallParam
), " ");
1658 strcat_s(CallParam
, sizeof(CallParam
), argv
[i
]);
1662 if (Pos
&& *Pos
== 0)
1664 Log("Old current directory = <%s>", CurDir
);
1665 Log("New current directory = <%s>", LunchFile
);
1669 GetCurrentDirectoryA(sizeof(CurDir
), CurDir
);
1670 Log("Current directory = <%s>", CurDir
);
1673 GetStartupInfoA(&Si
);
1675 memset(LunchFile
, 0, sizeof(LunchFile
));
1677 if (strstr(argv
[0], "vtoyjump.exe"))
1679 rc
= VentoyJumpWimboot(argc
, argv
, LunchFile
);
1683 rc
= VentoyJump(argc
, argv
, LunchFile
);
1686 Log("id=%d LunchFile=<%s> CallParam=<%s>", id
, LunchFile
, CallParam
);
1688 if (id
== 1 && _stricmp(argv
[0], "PECMD.EXE") == 0 && _stricmp(LunchFile
, "ventoy\\PECMD.EXE") == 0)
1690 MUTEX_LOCK(g_vtoyins_mutex
);
1691 id
= ventoy_get_instance_id(VTOY_PID_FILE
);
1692 MUTEX_UNLOCK(g_vtoyins_mutex
);
1694 Log("Current instance id is: %d", id
);
1698 #ifdef VTOY_REJUMP_SUPPORTED
1699 if (g_PecmdHasCmdLine
)
1702 CopyFileA("PECMD.EXE", "ventoy\\WinLogon.exe", TRUE
);
1706 MoveFileA("PECMD.EXE", "PECMD_BACK.EXE");
1707 CopyFileA("ventoy\\PECMD.EXE", "PECMD.EXE", TRUE
);
1708 sprintf_s(LunchFile
, sizeof(LunchFile
), "%s", "PECMD.EXE");
1709 Log("Move original PECMD.EXE <%s>", LunchFile
);
1713 Log("%d instance started, don't move PECMD.EXE", id
);
1717 if (g_os_param_reserved
[0] == 3)
1719 Log("Open log for debug ...");
1720 sprintf_s(LunchFile
, sizeof(LunchFile
), "%s", "notepad.exe ventoy.log");
1726 strcat_s(LunchFile
, sizeof(LunchFile
), CallParam
);
1728 else if (NULL
== strstr(LunchFile
, "setup.exe"))
1730 Log("Not setup.exe, hide windows.");
1731 Si
.dwFlags
|= STARTF_USESHOWWINDOW
;
1732 Si
.wShowWindow
= SW_HIDE
;
1735 Log("Ventoy jump %s ...", rc
== 0 ? "success" : "failed");
1738 Log("Now launch <%s> ...", LunchFile
);
1740 if (g_os_param_reserved
[0] == 4)
1742 Log("Open cmd for debug ...");
1743 sprintf_s(LunchFile
, sizeof(LunchFile
), "%s", "cmd.exe");
1746 #ifdef VTOY_REJUMP_SUPPORTED
1749 sprintf_s(CallParam
, sizeof(CallParam
), "ventoy\\WinLogon.exe%s", LunchFile
+ strlen("PECMD.EXE"));
1750 Log("Now rejump to pecmd.exe <%s> ...", CallParam
);
1752 CreateProcessA(NULL
, CallParam
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
1754 Log("Wait rejump process...");
1755 WaitForSingleObject(Pi
.hProcess
, INFINITE
);
1756 Log("rejump finished");
1763 CreateProcessA(NULL
, LunchFile
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
1765 for (i
= 0; rc
&& i
< 1800; i
++)
1767 Log("Ventoy hook failed, now wait and retry ...");
1769 rc
= VentoyHook(&g_os_param
);
1772 Log("Wait process...");
1773 WaitForSingleObject(Pi
.hProcess
, INFINITE
);
1775 Log("vtoyjump finished");