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 UINT8 g_os_param_reserved
[32];
33 static BOOL g_64bit_system
= FALSE
;
34 static ventoy_guid g_ventoy_guid
= VENTOY_GUID
;
36 void Log(const char *Fmt
, ...)
45 Len
+= sprintf_s(szBuf
, sizeof(szBuf
),
46 "[%4d/%02d/%02d %02d:%02d:%02d.%03d] ",
47 Sys
.wYear
, Sys
.wMonth
, Sys
.wDay
,
48 Sys
.wHour
, Sys
.wMinute
, Sys
.wSecond
,
52 Len
+= vsnprintf_s(szBuf
+ Len
, sizeof(szBuf
)-Len
, sizeof(szBuf
)-Len
, Fmt
, Arg
);
55 fopen_s(&File
, "ventoy.log", "a+");
58 fwrite(szBuf
, 1, Len
, File
);
59 fwrite("\n", 1, 1, File
);
65 static int LoadNtDriver(const char *DrvBinPath
)
71 SC_HANDLE hServiceMgr
;
73 char name
[256] = { 0 };
75 for (i
= (int)strlen(DrvBinPath
) - 1; i
>= 0; i
--)
77 if (DrvBinPath
[i
] == '\\' || DrvBinPath
[i
] == '/')
79 sprintf_s(name
, sizeof(name
), "%s", DrvBinPath
+ i
+ 1);
84 Log("Load NT driver: %s %s", DrvBinPath
, name
);
86 hServiceMgr
= OpenSCManagerA(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
87 if (hServiceMgr
== NULL
)
89 Log("OpenSCManager failed Error:%u", GetLastError());
93 Log("OpenSCManager OK");
95 hService
= CreateServiceA(hServiceMgr
,
99 SERVICE_KERNEL_DRIVER
,
100 SERVICE_DEMAND_START
,
101 SERVICE_ERROR_NORMAL
,
103 NULL
, NULL
, NULL
, NULL
, NULL
);
104 if (hService
== NULL
)
106 Status
= GetLastError();
107 if (Status
!= ERROR_IO_PENDING
&& Status
!= ERROR_SERVICE_EXISTS
)
109 Log("CreateService failed v %u", Status
);
110 CloseServiceHandle(hServiceMgr
);
114 hService
= OpenServiceA(hServiceMgr
, name
, SERVICE_ALL_ACCESS
);
115 if (hService
== NULL
)
117 Log("OpenService failed %u", Status
);
118 CloseServiceHandle(hServiceMgr
);
123 Log("CreateService imdisk OK");
125 Ret
= StartServiceA(hService
, 0, NULL
);
128 Log("StartService OK");
132 Status
= GetLastError();
133 if (Status
== ERROR_SERVICE_ALREADY_RUNNING
)
139 Log("StartService error %u", Status
);
144 CloseServiceHandle(hService
);
145 CloseServiceHandle(hServiceMgr
);
147 Log("Load NT driver %s", rc
? "failed" : "success");
152 static int ReadWholeFile2Buf(const char *Fullpath
, void **Data
, DWORD
*Size
)
160 Log("ReadWholeFile2Buf <%s>", Fullpath
);
162 Handle
= CreateFileA(Fullpath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
163 if (Handle
== INVALID_HANDLE_VALUE
)
165 Log("Could not open the file<%s>, error:%u", Fullpath
, GetLastError());
169 FileSize
= SetFilePointer(Handle
, 0, NULL
, FILE_END
);
171 Buffer
= malloc(FileSize
);
174 Log("Failed to alloc memory size:%u", FileSize
);
178 SetFilePointer(Handle
, 0, NULL
, FILE_BEGIN
);
179 if (!ReadFile(Handle
, Buffer
, FileSize
, &dwSize
, NULL
))
181 Log("ReadFile failed, dwSize:%u error:%u", dwSize
, GetLastError());
188 Log("Success read file size:%u", FileSize
);
193 SAFE_CLOSE_HANDLE(Handle
);
198 static BOOL
CheckPeHead(BYTE
*Head
)
202 if (Head
[0] != 'M' || Head
[1] != 'Z')
207 PeOffset
= *(UINT32
*)(Head
+ 60);
208 if (*(UINT32
*)(Head
+ PeOffset
) != 0x00004550)
216 static BOOL
IsPe64(BYTE
*buffer
)
220 if (!CheckPeHead(buffer
))
225 pe_off
= *(UINT32
*)(buffer
+ 60);
226 if (*(UINT16
*)(buffer
+ pe_off
+ 24) == 0x020b)
235 static BOOL
CheckOsParam(ventoy_os_param
*param
)
240 if (memcmp(¶m
->guid
, &g_ventoy_guid
, sizeof(ventoy_guid
)))
245 for (i
= 0; i
< sizeof(ventoy_os_param
); i
++)
247 Sum
+= *((BYTE
*)param
+ i
);
255 if (param
->vtoy_img_location_addr
% 4096)
263 static int SaveBuffer2File(const char *Fullpath
, void *Buffer
, DWORD Length
)
269 Log("SaveBuffer2File <%s> len:%u", Fullpath
, Length
);
271 Handle
= CreateFileA(Fullpath
, GENERIC_READ
| GENERIC_WRITE
,
272 FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, CREATE_NEW
, 0, 0);
273 if (Handle
== INVALID_HANDLE_VALUE
)
275 Log("Could not create new file, error:%u", GetLastError());
279 WriteFile(Handle
, Buffer
, Length
, &dwSize
, NULL
);
284 SAFE_CLOSE_HANDLE(Handle
);
289 static BOOL
IsPathExist(BOOL Dir
, const char *Fmt
, ...)
294 CHAR FilePath
[MAX_PATH
];
297 vsnprintf_s(FilePath
, sizeof(FilePath
), sizeof(FilePath
), Fmt
, Arg
);
300 hFile
= CreateFileA(FilePath
, FILE_READ_EA
, FILE_SHARE_READ
, 0, OPEN_EXISTING
, 0, 0);
301 if (INVALID_HANDLE_VALUE
== hFile
)
308 Attr
= GetFileAttributesA(FilePath
);
312 if ((Attr
& FILE_ATTRIBUTE_DIRECTORY
) == 0)
319 if (Attr
& FILE_ATTRIBUTE_DIRECTORY
)
328 static int GetPhyDiskUUID(const char LogicalDrive
, UINT8
*UUID
, DISK_EXTENT
*DiskExtent
)
333 VOLUME_DISK_EXTENTS DiskExtents
;
335 UINT8 SectorBuf
[512];
337 Log("GetPhyDiskUUID %C", LogicalDrive
);
339 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\%C:", LogicalDrive
);
340 Handle
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
341 if (Handle
== INVALID_HANDLE_VALUE
)
343 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
347 Ret
= DeviceIoControl(Handle
,
348 IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
,
352 (DWORD
)(sizeof(DiskExtents
)),
355 if (!Ret
|| DiskExtents
.NumberOfDiskExtents
== 0)
357 Log("DeviceIoControl IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed, error:%u", GetLastError());
363 memcpy(DiskExtent
, DiskExtents
.Extents
, sizeof(DiskExtent
));
364 Log("%C: is in PhysicalDrive%d ", LogicalDrive
, DiskExtents
.Extents
[0].DiskNumber
);
366 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\PhysicalDrive%d", DiskExtents
.Extents
[0].DiskNumber
);
367 Handle
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
368 if (Handle
== INVALID_HANDLE_VALUE
)
370 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
374 if (!ReadFile(Handle
, SectorBuf
, sizeof(SectorBuf
), &dwSize
, NULL
))
376 Log("ReadFile failed, dwSize:%u error:%u", dwSize
, GetLastError());
381 memcpy(UUID
, SectorBuf
+ 0x180, 16);
386 int VentoyMountISOByAPI(const char *IsoPath
)
390 WCHAR wFilePath
[512] = { 0 };
391 VIRTUAL_STORAGE_TYPE StorageType
;
392 OPEN_VIRTUAL_DISK_PARAMETERS OpenParameters
;
393 ATTACH_VIRTUAL_DISK_PARAMETERS AttachParameters
;
395 Log("VentoyMountISOByAPI <%s>", IsoPath
);
397 MultiByteToWideChar(CP_ACP
, 0, IsoPath
, (int)strlen(IsoPath
), wFilePath
, (int)(sizeof(wFilePath
) / sizeof(WCHAR
)));
399 memset(&StorageType
, 0, sizeof(StorageType
));
400 memset(&OpenParameters
, 0, sizeof(OpenParameters
));
401 memset(&AttachParameters
, 0, sizeof(AttachParameters
));
403 OpenParameters
.Version
= OPEN_VIRTUAL_DISK_VERSION_1
;
404 AttachParameters
.Version
= ATTACH_VIRTUAL_DISK_VERSION_1
;
406 Status
= OpenVirtualDisk(&StorageType
, wFilePath
, VIRTUAL_DISK_ACCESS_READ
, 0, &OpenParameters
, &Handle
);
407 if (Status
!= ERROR_SUCCESS
)
409 if (ERROR_VIRTDISK_PROVIDER_NOT_FOUND
== Status
)
411 Log("VirtualDisk for ISO file is not supported in current system");
415 Log("Failed to open virtual disk ErrorCode:%u", Status
);
420 Log("OpenVirtualDisk success");
422 Status
= AttachVirtualDisk(Handle
, NULL
, ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY
| ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME
, 0, &AttachParameters
, NULL
);
423 if (Status
!= ERROR_SUCCESS
)
425 Log("Failed to attach virtual disk ErrorCode:%u", Status
);
435 static HANDLE g_FatPhyDrive
;
436 static UINT64 g_Part2StartSec
;
438 static int CopyFileFromFatDisk(const CHAR
* SrcFile
, const CHAR
*DstFile
)
445 Log("CopyFileFromFatDisk (%s)==>(%s)", SrcFile
, DstFile
);
447 flfile
= fl_fopen(SrcFile
, "rb");
450 fl_fseek(flfile
, 0, SEEK_END
);
451 size
= (int)fl_ftell(flfile
);
452 fl_fseek(flfile
, 0, SEEK_SET
);
454 buf
= (char *)malloc(size
);
457 fl_fread(buf
, 1, size
, flfile
);
460 SaveBuffer2File(DstFile
, buf
, size
);
470 static int VentoyFatDiskRead(uint32 Sector
, uint8
*Buffer
, uint32 SectorCount
)
475 LARGE_INTEGER liCurrentPosition
;
477 liCurrentPosition
.QuadPart
= Sector
+ g_Part2StartSec
;
478 liCurrentPosition
.QuadPart
*= 512;
479 SetFilePointerEx(g_FatPhyDrive
, liCurrentPosition
, &liCurrentPosition
, FILE_BEGIN
);
481 ReadSize
= (DWORD
)(SectorCount
* 512);
483 bRet
= ReadFile(g_FatPhyDrive
, Buffer
, ReadSize
, &dwSize
, NULL
);
484 if (bRet
== FALSE
|| dwSize
!= ReadSize
)
486 Log("ReadFile error bRet:%u WriteSize:%u dwSize:%u ErrCode:%u\n", bRet
, ReadSize
, dwSize
, GetLastError());
492 static CHAR
GetMountLogicalDrive(void)
496 DWORD Mask
= 0x2000000;
498 Drives
= GetLogicalDrives();
499 Log("Drives=0x%x", Drives
);
503 if ((Drives
& Mask
) == 0)
515 int VentoyMountISOByImdisk(const char *IsoPath
, DWORD PhyDrive
)
522 CHAR PhyPath
[MAX_PATH
];
524 PROCESS_INFORMATION Pi
;
525 GET_LENGTH_INFORMATION LengthInfo
;
527 Log("VentoyMountISOByImdisk %s", IsoPath
);
529 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\PhysicalDrive%d", PhyDrive
);
530 hDrive
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
531 if (hDrive
== INVALID_HANDLE_VALUE
)
533 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
537 bRet
= DeviceIoControl(hDrive
, IOCTL_DISK_GET_LENGTH_INFO
, NULL
, 0, &LengthInfo
, sizeof(LengthInfo
), &dwBytes
, NULL
);
540 Log("Could not get phy disk %s size, error:%u", PhyPath
, GetLastError());
544 g_FatPhyDrive
= hDrive
;
545 g_Part2StartSec
= (LengthInfo
.Length
.QuadPart
- VENTOY_EFI_PART_SIZE
) / 512;
547 Log("Parse FAT fs...");
551 if (0 == fl_attach_media(VentoyFatDiskRead
, NULL
))
555 CopyFileFromFatDisk("/ventoy/imdisk/64/imdisk.sys", "ventoy\\imdisk.sys");
556 CopyFileFromFatDisk("/ventoy/imdisk/64/imdisk.exe", "ventoy\\imdisk.exe");
557 CopyFileFromFatDisk("/ventoy/imdisk/64/imdisk.cpl", "ventoy\\imdisk.cpl");
561 CopyFileFromFatDisk("/ventoy/imdisk/32/imdisk.sys", "ventoy\\imdisk.sys");
562 CopyFileFromFatDisk("/ventoy/imdisk/32/imdisk.exe", "ventoy\\imdisk.exe");
563 CopyFileFromFatDisk("/ventoy/imdisk/32/imdisk.cpl", "ventoy\\imdisk.cpl");
566 GetCurrentDirectoryA(sizeof(PhyPath
), PhyPath
);
567 strcat_s(PhyPath
, sizeof(PhyPath
), "\\ventoy\\imdisk.sys");
569 if (LoadNtDriver(PhyPath
) == 0)
573 Letter
= GetMountLogicalDrive();
574 sprintf_s(PhyPath
, sizeof(PhyPath
), "ventoy\\imdisk.exe -a -o ro -f %s -m %C:", IsoPath
, Letter
);
576 Log("mount iso to %C: use imdisk cmd <%s>", Letter
, PhyPath
);
578 GetStartupInfoA(&Si
);
580 Si
.dwFlags
|= STARTF_USESHOWWINDOW
;
581 Si
.wShowWindow
= SW_HIDE
;
583 CreateProcessA(NULL
, PhyPath
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
584 WaitForSingleObject(Pi
.hProcess
, INFINITE
);
591 SAFE_CLOSE_HANDLE(hDrive
);
596 static int MountIsoFile(CONST CHAR
*IsoPath
, DWORD PhyDrive
)
598 if (IsWindows8OrGreater())
600 Log("This is Windows 8 or latter...");
601 if (VentoyMountISOByAPI(IsoPath
) == 0)
603 Log("Mount iso by API success");
608 Log("Mount iso by API failed, maybe not supported, try imdisk");
609 return VentoyMountISOByImdisk(IsoPath
, PhyDrive
);
614 Log("This is before Windows 8 ...");
615 if (VentoyMountISOByImdisk(IsoPath
, PhyDrive
) == 0)
617 Log("Mount iso by imdisk success");
622 return VentoyMountISOByAPI(IsoPath
);
627 static int GetPhyDriveByLogicalDrive(int DriveLetter
)
632 VOLUME_DISK_EXTENTS DiskExtents
;
635 sprintf_s(PhyPath
, sizeof(PhyPath
), "\\\\.\\%C:", (CHAR
)DriveLetter
);
637 Handle
= CreateFileA(PhyPath
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0, OPEN_EXISTING
, 0, 0);
638 if (Handle
== INVALID_HANDLE_VALUE
)
640 Log("Could not open the disk<%s>, error:%u", PhyPath
, GetLastError());
644 Ret
= DeviceIoControl(Handle
,
645 IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
,
649 (DWORD
)(sizeof(DiskExtents
)),
653 if (!Ret
|| DiskExtents
.NumberOfDiskExtents
== 0)
655 Log("DeviceIoControl IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS failed %s, error:%u", PhyPath
, GetLastError());
656 SAFE_CLOSE_HANDLE(Handle
);
659 SAFE_CLOSE_HANDLE(Handle
);
661 Log("LogicalDrive:%s PhyDrive:%d Offset:%llu ExtentLength:%llu",
663 DiskExtents
.Extents
[0].DiskNumber
,
664 DiskExtents
.Extents
[0].StartingOffset
.QuadPart
,
665 DiskExtents
.Extents
[0].ExtentLength
.QuadPart
668 return (int)DiskExtents
.Extents
[0].DiskNumber
;
672 static int DeleteVentoyPart2MountPoint(DWORD PhyDrive
)
677 CHAR DriveName
[] = "?:\\";
679 Log("DeleteVentoyPart2MountPoint Phy%u ...", PhyDrive
);
681 Drives
= GetLogicalDrives();
684 if ((Drives
& 0x01) && IsPathExist(FALSE
, "%C:\\ventoy\\ventoy.cpio", Letter
))
686 Log("File %C:\\ventoy\\ventoy.cpio exist", Letter
);
688 PhyDisk
= GetPhyDriveByLogicalDrive(Letter
);
689 Log("PhyDisk=%u for %C", PhyDisk
, Letter
);
691 if (PhyDisk
== PhyDrive
)
693 DriveName
[0] = Letter
;
694 DeleteVolumeMountPointA(DriveName
);
706 static int VentoyHook(ventoy_os_param
*param
)
710 DISK_EXTENT DiskExtent
;
711 DWORD Drives
= GetLogicalDrives();
713 CHAR IsoPath
[MAX_PATH
];
715 Log("Logical Drives=0x%x Path:<%s>", Drives
, param
->vtoy_img_path
);
721 sprintf_s(IsoPath
, sizeof(IsoPath
), "%C:\\%s", Letter
, param
->vtoy_img_path
);
722 if (IsPathExist(FALSE
, "%s", IsoPath
))
724 Log("File exist under %C:", Letter
);
725 if (GetPhyDiskUUID(Letter
, UUID
, &DiskExtent
) == 0)
727 if (memcmp(UUID
, param
->vtoy_disk_guid
, 16) == 0)
729 Log("Disk UUID match");
736 Log("File NOT exist under %C:", Letter
);
746 Log("Failed to find ISO file");
750 Log("Find ISO file <%s>", IsoPath
);
752 rc
= MountIsoFile(IsoPath
, DiskExtent
.DiskNumber
);
753 Log("Mount ISO FILE: %s", rc
== 0 ? "SUCCESS" : "FAILED");
756 rc
= DeleteVentoyPart2MountPoint(DiskExtent
.DiskNumber
);
757 Log("Delete ventoy mountpoint: %s", rc
== 0 ? "SUCCESS" : "NO NEED");
762 const char * GetFileNameInPath(const char *fullpath
)
765 const char *pos
= NULL
;
767 if (strstr(fullpath
, ":"))
769 for (i
= (int)strlen(fullpath
); i
> 0; i
--)
771 if (fullpath
[i
- 1] == '/' || fullpath
[i
- 1] == '\\')
781 int VentoyJump(INT argc
, CHAR
**argv
, CHAR
*LunchFile
)
788 CHAR ExeFileName
[MAX_PATH
];
790 sprintf_s(ExeFileName
, sizeof(ExeFileName
), "%s", argv
[0]);
791 if (!IsPathExist(FALSE
, "%s", ExeFileName
))
793 Log("File %s NOT exist, now try %s.exe", ExeFileName
, ExeFileName
);
794 sprintf_s(ExeFileName
, sizeof(ExeFileName
), "%s.exe", argv
[0]);
796 Log("File %s exist ? %s", ExeFileName
, IsPathExist(FALSE
, "%s", ExeFileName
) ? "YES" : "NO");
799 if (ReadWholeFile2Buf(ExeFileName
, (void **)&Buffer
, &FileSize
))
804 g_64bit_system
= IsPe64(Buffer
);
806 if (!IsPathExist(TRUE
, "ventoy"))
808 if (!CreateDirectoryA("ventoy", NULL
))
810 Log("Failed to create ventoy directory err:%u", GetLastError());
815 for (PeStart
= 0; PeStart
< FileSize
; PeStart
+= 16)
817 if (CheckOsParam((ventoy_os_param
*)(Buffer
+ PeStart
)) &&
818 CheckPeHead(Buffer
+ PeStart
+ sizeof(ventoy_os_param
)))
820 Log("Find os pararm at %u", PeStart
);
822 memcpy(&g_os_param
, Buffer
+ PeStart
, sizeof(ventoy_os_param
));
823 memcpy(g_os_param_reserved
, g_os_param
.vtoy_reserved
, sizeof(g_os_param_reserved
));
825 if (g_os_param_reserved
[0] == 1)
827 Log("break here for debug .....");
832 for (Pos
= 0; Pos
< sizeof(g_os_param
.vtoy_img_path
) && g_os_param
.vtoy_img_path
[Pos
]; Pos
++)
834 if (g_os_param
.vtoy_img_path
[Pos
] == '/')
836 g_os_param
.vtoy_img_path
[Pos
] = '\\';
840 PeStart
+= sizeof(ventoy_os_param
);
841 sprintf_s(LunchFile
, MAX_PATH
, "ventoy\\%s", GetFileNameInPath(ExeFileName
));
842 SaveBuffer2File(LunchFile
, Buffer
+ PeStart
, FileSize
- PeStart
);
847 if (PeStart
>= FileSize
)
849 Log("OS param not found");
853 if (g_os_param_reserved
[0] == 2)
855 Log("skip hook for debug .....");
860 rc
= VentoyHook(&g_os_param
);
872 int main(int argc
, char **argv
)
877 CHAR CurDir
[MAX_PATH
];
878 CHAR LunchFile
[MAX_PATH
];
880 PROCESS_INFORMATION Pi
;
882 if (argv
[0] && argv
[0][0] && argv
[0][1] == ':')
884 GetCurrentDirectoryA(sizeof(CurDir
), CurDir
);
886 strcpy_s(LunchFile
, sizeof(LunchFile
), argv
[0]);
887 Pos
= (char *)GetFileNameInPath(LunchFile
);
889 strcat_s(CurDir
, sizeof(CurDir
), "\\");
890 strcat_s(CurDir
, sizeof(CurDir
), Pos
);
892 if (_stricmp(argv
[0], CurDir
) != 0)
895 SetCurrentDirectoryA(LunchFile
);
899 Log("######## VentoyJump ##########");
900 Log("argc = %d argv[0] = <%s>", argc
, argv
[0]);
902 if (Pos
&& *Pos
== 0)
904 Log("Old current directory = <%s>", CurDir
);
905 Log("New current directory = <%s>", LunchFile
);
909 GetCurrentDirectoryA(sizeof(CurDir
), CurDir
);
910 Log("Current directory = <%s>", CurDir
);
913 GetStartupInfoA(&Si
);
915 memset(LunchFile
, 0, sizeof(LunchFile
));
916 rc
= VentoyJump(argc
, argv
, LunchFile
);
918 if (g_os_param_reserved
[0] == 3)
920 Log("Open log for debug ...");
921 sprintf_s(LunchFile
, sizeof(LunchFile
), "%s", "notepad.exe ventoy.log");
925 Si
.dwFlags
|= STARTF_USESHOWWINDOW
;
926 Si
.wShowWindow
= SW_HIDE
;
927 Log("Ventoy jump %s ...", rc
== 0 ? "success" : "failed");
930 CreateProcessA(NULL
, LunchFile
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &Si
, &Pi
);
934 Log("Ventoy hook failed, now wait and retry ...");
937 rc
= VentoyHook(&g_os_param
);
940 WaitForSingleObject(Pi
.hProcess
, INFINITE
);