Commit 0f8478fb authored by longpanda's avatar longpanda
Browse files

update for new release

parent a6d3ecc7
...@@ -62,7 +62,7 @@ cp -a ./tool/ENROLL_THIS_KEY_IN_MOKMANAGER.cer $tmpmnt/ ...@@ -62,7 +62,7 @@ cp -a ./tool/ENROLL_THIS_KEY_IN_MOKMANAGER.cer $tmpmnt/
mkdir -p $tmpmnt/tool mkdir -p $tmpmnt/tool
cp -a ./tool/mount* $tmpmnt/tool/ cp -a ./tool/mount* $tmpmnt/tool/
rm -f $tmpmnt/grub/i386-pc/* rm -f $tmpmnt/grub/i386-pc/*.img
umount $tmpmnt && rm -rf $tmpmnt umount $tmpmnt && rm -rf $tmpmnt
...@@ -79,6 +79,7 @@ xz --check=crc32 $tmpdir/boot/core.img ...@@ -79,6 +79,7 @@ xz --check=crc32 $tmpdir/boot/core.img
cp -a ./tool $tmpdir/ cp -a ./tool $tmpdir/
rm -f $tmpdir/ENROLL_THIS_KEY_IN_MOKMANAGER.cer rm -f $tmpdir/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
cp -a Ventoy2Disk.sh $tmpdir/ cp -a Ventoy2Disk.sh $tmpdir/
cp -a README $tmpdir/
cp -a CreatePersistentImg.sh $tmpdir/ cp -a CreatePersistentImg.sh $tmpdir/
dos2unix -q $tmpdir/Ventoy2Disk.sh dos2unix -q $tmpdir/Ventoy2Disk.sh
dos2unix -q $tmpdir/CreatePersistentImg.sh dos2unix -q $tmpdir/CreatePersistentImg.sh
...@@ -109,6 +110,7 @@ cp -a Ventoy2Disk*.exe $tmpdir/ ...@@ -109,6 +110,7 @@ cp -a Ventoy2Disk*.exe $tmpdir/
cp -a $LANG_DIR/languages.ini $tmpdir/ventoy/ cp -a $LANG_DIR/languages.ini $tmpdir/ventoy/
rm -rf $tmpdir/tool rm -rf $tmpdir/tool
rm -f $tmpdir/*.sh rm -f $tmpdir/*.sh
rm -f $tmpdir/README
zip -r ventoy-${curver}-windows.zip $tmpdir/ zip -r ventoy-${curver}-windows.zip $tmpdir/
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
\ No newline at end of file
imdisk follows LGPL license (see lgpl-3.0.txt)
Ventoy only use its binaries 7za.exe
========7zip License Information===============
7-Zip Extra
~~~~~~~~~~~
License for use and distribution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copyright (C) 1999-2019 Igor Pavlov.
7-Zip Extra files are under the GNU LGPL license.
Notes:
You can use 7-Zip Extra on any computer, including a computer in a commercial
organization. You don't need to register or pay for 7-Zip.
GNU LGPL information
--------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You can receive a copy of the GNU Lesser General Public License from
http://www.gnu.org/
/****************************************************************************** /******************************************************************************
* Ventoy2Disk.c * Ventoy2Disk.c
* *
* Copyright (c) 2020, longpanda <admin@ventoy.net> * Copyright (c) 2020, longpanda <admin@ventoy.net>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include <Windows.h> #include <Windows.h>
#include "resource.h" #include "resource.h"
#include "Language.h" #include "Language.h"
#include "Ventoy2Disk.h" #include "Ventoy2Disk.h"
PHY_DRIVE_INFO *g_PhyDriveList = NULL; PHY_DRIVE_INFO *g_PhyDriveList = NULL;
DWORD g_PhyDriveCount = 0; DWORD g_PhyDriveCount = 0;
static int g_FilterRemovable = 0; static int g_FilterRemovable = 0;
static int g_FilterUSB = 1; static int g_FilterUSB = 1;
int g_ForceOperation = 1; int g_ForceOperation = 1;
int ParseCmdLineOption(LPSTR lpCmdLine) int ParseCmdLineOption(LPSTR lpCmdLine)
{ {
int i; int i;
char cfgfile[MAX_PATH]; char cfgfile[MAX_PATH];
if (lpCmdLine && lpCmdLine[0]) if (lpCmdLine && lpCmdLine[0])
{ {
Log("CmdLine:<%s>", lpCmdLine); Log("CmdLine:<%s>", lpCmdLine);
} }
for (i = 0; i < __argc; i++) for (i = 0; i < __argc; i++)
{ {
if (strncmp(__argv[i], "-U", 2) == 0 || if (strncmp(__argv[i], "-U", 2) == 0 ||
strncmp(__argv[i], "-u", 2) == 0) strncmp(__argv[i], "-u", 2) == 0)
{ {
g_FilterUSB = 0; g_FilterUSB = 0;
} }
else if (strncmp(__argv[i], "-F", 2) == 0) else if (strncmp(__argv[i], "-F", 2) == 0)
{ {
g_ForceOperation = 1; g_ForceOperation = 1;
} }
} }
GetCurrentDirectoryA(sizeof(cfgfile), cfgfile); GetCurrentDirectoryA(sizeof(cfgfile), cfgfile);
strcat_s(cfgfile, sizeof(cfgfile), "\\Ventoy2Disk.ini"); strcat_s(cfgfile, sizeof(cfgfile), "\\Ventoy2Disk.ini");
if (0 == GetPrivateProfileIntA("Filter", "USB", 1, cfgfile)) if (0 == GetPrivateProfileIntA("Filter", "USB", 1, cfgfile))
{ {
g_FilterUSB = 0; g_FilterUSB = 0;
} }
if (1 == GetPrivateProfileIntA("Operation", "Force", 0, cfgfile)) if (1 == GetPrivateProfileIntA("Operation", "Force", 0, cfgfile))
{ {
g_ForceOperation = 1; g_ForceOperation = 1;
} }
Log("Control Flag: %d %d %d", g_FilterRemovable, g_FilterUSB, g_ForceOperation); Log("Control Flag: %d %d %d", g_FilterRemovable, g_FilterUSB, g_ForceOperation);
return 0; return 0;
} }
static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UINT64 *Part2StartSector) static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UINT64 *Part2StartSector)
{ {
int i; int i;
BOOL bRet; BOOL bRet;
DWORD dwSize; DWORD dwSize;
HANDLE hDrive; HANDLE hDrive;
MBR_HEAD MBR; MBR_HEAD MBR;
UINT32 PartStartSector; UINT32 PartStartSector;
UINT32 PartSectorCount; UINT32 PartSectorCount;
CHAR PhyDrivePath[128]; CHAR PhyDrivePath[128];
VTOY_GPT_INFO *pGpt = NULL; VTOY_GPT_INFO *pGpt = NULL;
safe_sprintf(PhyDrivePath, "\\\\.\\PhysicalDrive%d", PhyDrive); safe_sprintf(PhyDrivePath, "\\\\.\\PhysicalDrive%d", PhyDrive);
hDrive = CreateFileA(PhyDrivePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); hDrive = CreateFileA(PhyDrivePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
Log("Create file Handle:%p %s status:%u", hDrive, PhyDrivePath, LASTERR); Log("Create file Handle:%p %s status:%u", hDrive, PhyDrivePath, LASTERR);
if (hDrive == INVALID_HANDLE_VALUE) if (hDrive == INVALID_HANDLE_VALUE)
{ {
return FALSE; return FALSE;
} }
bRet = ReadFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL); bRet = ReadFile(hDrive, &MBR, sizeof(MBR), &dwSize, NULL);
Log("Read MBR Ret:%u Size:%u code:%u", bRet, dwSize, LASTERR); Log("Read MBR Ret:%u Size:%u code:%u", bRet, dwSize, LASTERR);
if ((!bRet) || (dwSize != sizeof(MBR))) if ((!bRet) || (dwSize != sizeof(MBR)))
{ {
CHECK_CLOSE_HANDLE(hDrive); CHECK_CLOSE_HANDLE(hDrive);
return FALSE; return FALSE;
} }
if (MBR.Byte55 != 0x55 || MBR.ByteAA != 0xAA) if (MBR.Byte55 != 0x55 || MBR.ByteAA != 0xAA)
{ {
Log("Byte55 ByteAA not match 0x%x 0x%x", MBR.Byte55, MBR.ByteAA); Log("Byte55 ByteAA not match 0x%x 0x%x", MBR.Byte55, MBR.ByteAA);
CHECK_CLOSE_HANDLE(hDrive); CHECK_CLOSE_HANDLE(hDrive);
return FALSE; return FALSE;
} }
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
Log("=========== Partition Table %d ============", i + 1); Log("=========== Partition Table %d ============", i + 1);
Log("PartTbl.Active = 0x%x", MBR.PartTbl[i].Active); Log("PartTbl.Active = 0x%x", MBR.PartTbl[i].Active);
Log("PartTbl.FsFlag = 0x%x", MBR.PartTbl[i].FsFlag); Log("PartTbl.FsFlag = 0x%x", MBR.PartTbl[i].FsFlag);
Log("PartTbl.StartSectorId = %u", MBR.PartTbl[i].StartSectorId); Log("PartTbl.StartSectorId = %u", MBR.PartTbl[i].StartSectorId);
Log("PartTbl.SectorCount = %u", MBR.PartTbl[i].SectorCount); Log("PartTbl.SectorCount = %u", MBR.PartTbl[i].SectorCount);
Log("PartTbl.StartHead = %u", MBR.PartTbl[i].StartHead); Log("PartTbl.StartHead = %u", MBR.PartTbl[i].StartHead);
Log("PartTbl.StartSector = %u", MBR.PartTbl[i].StartSector); Log("PartTbl.StartSector = %u", MBR.PartTbl[i].StartSector);
Log("PartTbl.StartCylinder = %u", MBR.PartTbl[i].StartCylinder); Log("PartTbl.StartCylinder = %u", MBR.PartTbl[i].StartCylinder);
Log("PartTbl.EndHead = %u", MBR.PartTbl[i].EndHead); Log("PartTbl.EndHead = %u", MBR.PartTbl[i].EndHead);
Log("PartTbl.EndSector = %u", MBR.PartTbl[i].EndSector); Log("PartTbl.EndSector = %u", MBR.PartTbl[i].EndSector);
Log("PartTbl.EndCylinder = %u", MBR.PartTbl[i].EndCylinder); Log("PartTbl.EndCylinder = %u", MBR.PartTbl[i].EndCylinder);
} }
if (MBR.PartTbl[0].FsFlag == 0xEE) if (MBR.PartTbl[0].FsFlag == 0xEE)
{ {
pGpt = malloc(sizeof(VTOY_GPT_INFO)); pGpt = malloc(sizeof(VTOY_GPT_INFO));
if (!pGpt) if (!pGpt)
{ {
CHECK_CLOSE_HANDLE(hDrive); CHECK_CLOSE_HANDLE(hDrive);
return FALSE; return FALSE;
} }
SetFilePointer(hDrive, 0, NULL, FILE_BEGIN); SetFilePointer(hDrive, 0, NULL, FILE_BEGIN);
bRet = ReadFile(hDrive, pGpt, sizeof(VTOY_GPT_INFO), &dwSize, NULL); bRet = ReadFile(hDrive, pGpt, sizeof(VTOY_GPT_INFO), &dwSize, NULL);
CHECK_CLOSE_HANDLE(hDrive); CHECK_CLOSE_HANDLE(hDrive);
if ((!bRet) || (dwSize != sizeof(VTOY_GPT_INFO))) if ((!bRet) || (dwSize != sizeof(VTOY_GPT_INFO)))
{ {
Log("Failed to read gpt info %d %u %d", bRet, dwSize, LASTERR); Log("Failed to read gpt info %d %u %d", bRet, dwSize, LASTERR);
return FALSE; return FALSE;
} }
if (memcmp(pGpt->Head.Signature, "EFI PART", 8)) if (memcmp(pGpt->Head.Signature, "EFI PART", 8))
{ {
Log("Invalid GPT signature"); Log("Invalid GPT signature");
return FALSE; return FALSE;
} }
if (memcmp(pGpt->PartTbl[1].Name, L"VTOYEFI", 7 * 2)) if (memcmp(pGpt->PartTbl[1].Name, L"VTOYEFI", 7 * 2))
{ {
Log("Invalid ventoy efi part name"); Log("Invalid ventoy efi part name");
return FALSE; return FALSE;
} }
*Part2StartSector = pGpt->PartTbl[1].StartLBA; *Part2StartSector = pGpt->PartTbl[1].StartLBA;
} }
else else
{ {
CHECK_CLOSE_HANDLE(hDrive); CHECK_CLOSE_HANDLE(hDrive);
if (MBR.PartTbl[0].StartSectorId != 2048) if (MBR.PartTbl[0].StartSectorId != 2048)
{ {
Log("Part1 not match %u", MBR.PartTbl[0].StartSectorId); Log("Part1 not match %u", MBR.PartTbl[0].StartSectorId);
return FALSE; return FALSE;
} }
PartStartSector = MBR.PartTbl[0].StartSectorId + MBR.PartTbl[0].SectorCount; PartStartSector = MBR.PartTbl[0].StartSectorId + MBR.PartTbl[0].SectorCount;
PartSectorCount = VENTOY_EFI_PART_SIZE / 512; PartSectorCount = VENTOY_EFI_PART_SIZE / 512;
if (MBR.PartTbl[1].FsFlag != 0xEF || if (MBR.PartTbl[1].FsFlag != 0xEF ||
MBR.PartTbl[1].StartSectorId != PartStartSector || MBR.PartTbl[1].StartSectorId != PartStartSector ||
MBR.PartTbl[1].SectorCount != PartSectorCount) MBR.PartTbl[1].SectorCount != PartSectorCount)
{ {
Log("Part2 not match [0x%x 0x%x] [%u %u] [%u %u]", Log("Part2 not match [0x%x 0x%x] [%u %u] [%u %u]",
MBR.PartTbl[1].FsFlag, 0xEF, MBR.PartTbl[1].FsFlag, 0xEF,
MBR.PartTbl[1].StartSectorId, PartStartSector, MBR.PartTbl[1].StartSectorId, PartStartSector,
MBR.PartTbl[1].SectorCount, PartSectorCount); MBR.PartTbl[1].SectorCount, PartSectorCount);
return FALSE; return FALSE;
} }
if (MBR.PartTbl[0].Active != 0x80 && MBR.PartTbl[1].Active != 0x80) if (MBR.PartTbl[0].Active != 0x80 && MBR.PartTbl[1].Active != 0x80)
{ {
Log("Part1 and Part2 are both NOT active 0x%x 0x%x", MBR.PartTbl[0].Active, MBR.PartTbl[1].Active); Log("Part1 and Part2 are both NOT active 0x%x 0x%x", MBR.PartTbl[0].Active, MBR.PartTbl[1].Active);
return FALSE; return FALSE;
} }
*Part2StartSector = MBR.PartTbl[1].StartSectorId; *Part2StartSector = MBR.PartTbl[1].StartSectorId;
} }
memcpy(pMBR, &MBR, sizeof(MBR_HEAD)); memcpy(pMBR, &MBR, sizeof(MBR_HEAD));
Log("PhysicalDrive%d is ventoy disk", PhyDrive); Log("PhysicalDrive%d is ventoy disk", PhyDrive);
return TRUE; return TRUE;
} }
static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount) static int FilterPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
{ {
DWORD i; DWORD i;
DWORD LogDrive; DWORD LogDrive;
int Letter = 'A'; int Count = 0;
int Id = 0; int Letter = 'A';
int LetterCount = 0; int Id = 0;
UINT64 Part2StartSector = 0; int LetterCount = 0;
PHY_DRIVE_INFO *CurDrive; UINT64 Part2StartSector = 0;
MBR_HEAD MBR; PHY_DRIVE_INFO *CurDrive;
int LogLetter[VENTOY_MAX_PHY_DRIVE]; MBR_HEAD MBR;
int PhyDriveId[VENTOY_MAX_PHY_DRIVE]; int LogLetter[VENTOY_MAX_PHY_DRIVE];
int PhyDriveId[VENTOY_MAX_PHY_DRIVE];
for (LogDrive = GetLogicalDrives(); LogDrive > 0; LogDrive >>= 1)
{ for (LogDrive = GetLogicalDrives(); LogDrive > 0; LogDrive >>= 1)
if (LogDrive & 0x01) {
{ if (LogDrive & 0x01)
LogLetter[LetterCount] = Letter; {
PhyDriveId[LetterCount] = GetPhyDriveByLogicalDrive(Letter); LogLetter[LetterCount] = Letter;
PhyDriveId[LetterCount] = GetPhyDriveByLogicalDrive(Letter);
Log("Logical Drive:%C ===> PhyDrive:%d", LogLetter[LetterCount], PhyDriveId[LetterCount]);
LetterCount++; Log("Logical Drive:%C ===> PhyDrive:%d", LogLetter[LetterCount], PhyDriveId[LetterCount]);
} LetterCount++;
}
Letter++;
} Letter++;
}
for (i = 0; i < DriveCount; i++)
{ for (i = 0; i < DriveCount; i++)
CurDrive = pDriveList + i; {
CurDrive = pDriveList + i;
CurDrive->Id = -1;
CurDrive->FirstDriveLetter = -1; CurDrive->Id = -1;
memset(CurDrive->DriveLetters, 0, sizeof(CurDrive->DriveLetters));
// Too big for MBR
if (CurDrive->SizeInBytes > 2199023255552ULL) // Too big for MBR
{ if (CurDrive->SizeInBytes > 2199023255552ULL)
Log("<%s %s> is filtered for too big for MBR.", CurDrive->VendorId, CurDrive->ProductId); {
continue; Log("<%s %s> is filtered for too big for MBR.", CurDrive->VendorId, CurDrive->ProductId);
} continue;
}
if (g_FilterRemovable && (!CurDrive->RemovableMedia))
{ if (g_FilterRemovable && (!CurDrive->RemovableMedia))
Log("<%s %s> is filtered for not removable.", CurDrive->VendorId, CurDrive->ProductId); {
continue; Log("<%s %s> is filtered for not removable.", CurDrive->VendorId, CurDrive->ProductId);
} continue;
}
if (g_FilterUSB && CurDrive->BusType != BusTypeUsb)
{ if (g_FilterUSB && CurDrive->BusType != BusTypeUsb)
Log("<%s %s> is filtered for not USB type.", CurDrive->VendorId, CurDrive->ProductId); {
continue; Log("<%s %s> is filtered for not USB type.", CurDrive->VendorId, CurDrive->ProductId);
} continue;
}
CurDrive->Id = Id++;
CurDrive->Id = Id++;
for (Letter = 0; Letter < LetterCount; Letter++)
{ for (Count = 0, Letter = 0; Letter < LetterCount; Letter++)
if (PhyDriveId[Letter] == CurDrive->PhyDrive) {
{ if (PhyDriveId[Letter] == CurDrive->PhyDrive)
CurDrive->FirstDriveLetter = LogLetter[Letter]; {
break; if (Count + 1 < sizeof(CurDrive->DriveLetters) / sizeof(CHAR))
} {
} CurDrive->DriveLetters[Count] = LogLetter[Letter];
}
if (IsVentoyPhyDrive(CurDrive->PhyDrive, CurDrive->SizeInBytes, &MBR, &Part2StartSector)) Count++;
{ }
CurDrive->PartStyle = (MBR.PartTbl[0].FsFlag == 0xEE) ? 1 : 0; }
GetVentoyVerInPhyDrive(CurDrive, Part2StartSector, CurDrive->VentoyVersion, sizeof(CurDrive->VentoyVersion));
} if (IsVentoyPhyDrive(CurDrive->PhyDrive, CurDrive->SizeInBytes, &MBR, &Part2StartSector))
} {
CurDrive->PartStyle = (MBR.PartTbl[0].FsFlag == 0xEE) ? 1 : 0;
// for safe GetVentoyVerInPhyDrive(CurDrive, Part2StartSector, CurDrive->VentoyVersion, sizeof(CurDrive->VentoyVersion));
for (i = 0; i < DriveCount; i++) }
{ }
CurDrive = pDriveList + i;
if (CurDrive->Id < 0) // for safe
{ for (i = 0; i < DriveCount; i++)
CurDrive->PhyDrive = 0x00FFFFFF; {
} CurDrive = pDriveList + i;
} if (CurDrive->Id < 0)
{
return Id; CurDrive->PhyDrive = 0x00FFFFFF;
} }
}
PHY_DRIVE_INFO * GetPhyDriveInfoById(int Id)
{ return Id;
DWORD i; }
for (i = 0; i < g_PhyDriveCount; i++)
{ PHY_DRIVE_INFO * GetPhyDriveInfoById(int Id)
if (g_PhyDriveList[i].Id >= 0 && g_PhyDriveList[i].Id == Id) {
{ DWORD i;
return g_PhyDriveList + i; for (i = 0; i < g_PhyDriveCount; i++)
} {
} if (g_PhyDriveList[i].Id >= 0 && g_PhyDriveList[i].Id == Id)
{
return NULL; return g_PhyDriveList + i;
} }
}
int SortPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
{ return NULL;
DWORD i, j; }
PHY_DRIVE_INFO TmpDriveInfo;
int SortPhysicalDrive(PHY_DRIVE_INFO *pDriveList, DWORD DriveCount)
for (i = 0; i < DriveCount; i++) {
{ DWORD i, j;
for (j = i + 1; j < DriveCount; j++) PHY_DRIVE_INFO TmpDriveInfo;
{
if (pDriveList[i].BusType == BusTypeUsb && pDriveList[j].BusType == BusTypeUsb) for (i = 0; i < DriveCount; i++)
{ {
if (pDriveList[i].RemovableMedia == FALSE && pDriveList[j].RemovableMedia == TRUE) for (j = i + 1; j < DriveCount; j++)
{ {
memcpy(&TmpDriveInfo, pDriveList + i, sizeof(PHY_DRIVE_INFO)); if (pDriveList[i].BusType == BusTypeUsb && pDriveList[j].BusType == BusTypeUsb)
memcpy(pDriveList + i, pDriveList + j, sizeof(PHY_DRIVE_INFO)); {
memcpy(pDriveList + j, &TmpDriveInfo, sizeof(PHY_DRIVE_INFO)); if (pDriveList[i].RemovableMedia == FALSE && pDriveList[j].RemovableMedia == TRUE)
} {
} memcpy(&TmpDriveInfo, pDriveList + i, sizeof(PHY_DRIVE_INFO));
} memcpy(pDriveList + i, pDriveList + j, sizeof(PHY_DRIVE_INFO));
} memcpy(pDriveList + j, &TmpDriveInfo, sizeof(PHY_DRIVE_INFO));
}
return 0; }
} }
}
int Ventoy2DiskInit(void)
{ return 0;
Log("\n===================== Enum All PhyDrives ====================="); }
g_PhyDriveList = (PHY_DRIVE_INFO *)malloc(sizeof(PHY_DRIVE_INFO)* VENTOY_MAX_PHY_DRIVE);
if (NULL == g_PhyDriveList) int Ventoy2DiskInit(void)
{ {
Log("Failed to alloc phy drive memory"); Log("\n===================== Enum All PhyDrives =====================");
return FALSE; g_PhyDriveList = (PHY_DRIVE_INFO *)malloc(sizeof(PHY_DRIVE_INFO)* VENTOY_MAX_PHY_DRIVE);
} if (NULL == g_PhyDriveList)
memset(g_PhyDriveList, 0, sizeof(PHY_DRIVE_INFO)* VENTOY_MAX_PHY_DRIVE); {
Log("Failed to alloc phy drive memory");
GetAllPhysicalDriveInfo(g_PhyDriveList, &g_PhyDriveCount); return FALSE;
}
SortPhysicalDrive(g_PhyDriveList, g_PhyDriveCount); memset(g_PhyDriveList, 0, sizeof(PHY_DRIVE_INFO)* VENTOY_MAX_PHY_DRIVE);
FilterPhysicalDrive(g_PhyDriveList, g_PhyDriveCount); GetAllPhysicalDriveInfo(g_PhyDriveList, &g_PhyDriveCount);
return 0; SortPhysicalDrive(g_PhyDriveList, g_PhyDriveCount);
}
FilterPhysicalDrive(g_PhyDriveList, g_PhyDriveCount);
int Ventoy2DiskDestroy(void)
{ return 0;
free(g_PhyDriveList); }
return 0;
} int Ventoy2DiskDestroy(void)
{
free(g_PhyDriveList);
return 0;
}
/****************************************************************************** /******************************************************************************
* Ventoy2Disk.h * Ventoy2Disk.h
* *
* Copyright (c) 2020, longpanda <admin@ventoy.net> * Copyright (c) 2020, longpanda <admin@ventoy.net>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the * published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#ifndef __VENTOY2DISK_H__ #ifndef __VENTOY2DISK_H__
#define __VENTOY2DISK_H__ #define __VENTOY2DISK_H__
#include <stdio.h> #include <stdio.h>
#define SIZE_1MB (1024 * 1024) #define SIZE_1MB (1024 * 1024)
#define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB) #define VENTOY_EFI_PART_SIZE (32 * SIZE_1MB)
#define VENTOY_PART1_START_SECTOR 2048 #define VENTOY_PART1_START_SECTOR 2048
#define VENTOY_FILE_BOOT_IMG "boot\\boot.img" #define VENTOY_FILE_BOOT_IMG "boot\\boot.img"
#define VENTOY_FILE_STG1_IMG "boot\\core.img.xz" #define VENTOY_FILE_STG1_IMG "boot\\core.img.xz"
#define VENTOY_FILE_DISK_IMG "ventoy\\ventoy.disk.img.xz" #define VENTOY_FILE_DISK_IMG "ventoy\\ventoy.disk.img.xz"
#define VENTOY_FILE_LOG "log.txt" #define VENTOY_FILE_LOG "log.txt"
#define VENTOY_FILE_VERSION "ventoy\\version" #define VENTOY_FILE_VERSION "ventoy\\version"
#define DRIVE_ACCESS_TIMEOUT 15000 // How long we should retry drive access (in ms) #define DRIVE_ACCESS_TIMEOUT 15000 // How long we should retry drive access (in ms)
#define DRIVE_ACCESS_RETRIES 150 // How many times we should retry #define DRIVE_ACCESS_RETRIES 150 // How many times we should retry
#define IsFileExist(Fmt, ...) IsPathExist(FALSE, Fmt, __VA_ARGS__) #define IsFileExist(Fmt, ...) IsPathExist(FALSE, Fmt, __VA_ARGS__)
#define IsDirExist(Fmt, ...) IsPathExist(TRUE, Fmt, __VA_ARGS__) #define IsDirExist(Fmt, ...) IsPathExist(TRUE, Fmt, __VA_ARGS__)
#define safe_sprintf(dst, fmt, ...) sprintf_s(dst, sizeof(dst), fmt, __VA_ARGS__) #define safe_sprintf(dst, fmt, ...) sprintf_s(dst, sizeof(dst), fmt, __VA_ARGS__)
#define safe_strcpy(dst, src) strcpy_s(dst, sizeof(dst), src) #define safe_strcpy(dst, src) strcpy_s(dst, sizeof(dst), src)
#define CHECK_CLOSE_HANDLE(Handle) \ #define CHECK_CLOSE_HANDLE(Handle) \
{\ {\
if (Handle != INVALID_HANDLE_VALUE) \ if (Handle != INVALID_HANDLE_VALUE) \
{\ {\
CloseHandle(Handle); \ CloseHandle(Handle); \
Handle = INVALID_HANDLE_VALUE; \ Handle = INVALID_HANDLE_VALUE; \
}\ }\
} }
#define LASTERR GetLastError() #define LASTERR GetLastError()
#pragma pack(1) #pragma pack(1)
typedef struct PART_TABLE typedef struct PART_TABLE
{ {
UINT8 Active; // 0x00 0x80 UINT8 Active; // 0x00 0x80
UINT8 StartHead; UINT8 StartHead;
UINT16 StartSector : 6; UINT16 StartSector : 6;
UINT16 StartCylinder : 10; UINT16 StartCylinder : 10;
UINT8 FsFlag; UINT8 FsFlag;
UINT8 EndHead; UINT8 EndHead;
UINT16 EndSector : 6; UINT16 EndSector : 6;
UINT16 EndCylinder : 10; UINT16 EndCylinder : 10;
UINT32 StartSectorId; UINT32 StartSectorId;
UINT32 SectorCount; UINT32 SectorCount;
}PART_TABLE; }PART_TABLE;
typedef struct MBR_HEAD typedef struct MBR_HEAD
{ {
UINT8 BootCode[446]; UINT8 BootCode[446];
PART_TABLE PartTbl[4]; PART_TABLE PartTbl[4];
UINT8 Byte55; UINT8 Byte55;
UINT8 ByteAA; UINT8 ByteAA;
}MBR_HEAD; }MBR_HEAD;
typedef struct VTOY_GPT_HDR typedef struct VTOY_GPT_HDR
{ {
CHAR Signature[8]; /* EFI PART */ CHAR Signature[8]; /* EFI PART */
UINT8 Version[4]; UINT8 Version[4];
UINT32 Length; UINT32 Length;
UINT32 Crc; UINT32 Crc;
UINT8 Reserved1[4]; UINT8 Reserved1[4];
UINT64 EfiStartLBA; UINT64 EfiStartLBA;
UINT64 EfiBackupLBA; UINT64 EfiBackupLBA;
UINT64 PartAreaStartLBA; UINT64 PartAreaStartLBA;
UINT64 PartAreaEndLBA; UINT64 PartAreaEndLBA;
GUID DiskGuid; GUID DiskGuid;
UINT64 PartTblStartLBA; UINT64 PartTblStartLBA;
UINT32 PartTblTotNum; UINT32 PartTblTotNum;
UINT32 PartTblEntryLen; UINT32 PartTblEntryLen;
UINT32 PartTblCrc; UINT32 PartTblCrc;
UINT8 Reserved2[420]; UINT8 Reserved2[420];
}VTOY_GPT_HDR; }VTOY_GPT_HDR;
typedef struct VTOY_GPT_PART_TBL typedef struct VTOY_GPT_PART_TBL
{ {
GUID PartType; GUID PartType;
GUID PartGuid; GUID PartGuid;
UINT64 StartLBA; UINT64 StartLBA;
UINT64 LastLBA; UINT64 LastLBA;
UINT64 Attr; UINT64 Attr;
UINT16 Name[36]; UINT16 Name[36];
}VTOY_GPT_PART_TBL; }VTOY_GPT_PART_TBL;
typedef struct VTOY_GPT_INFO typedef struct VTOY_GPT_INFO
{ {
MBR_HEAD MBR; MBR_HEAD MBR;
VTOY_GPT_HDR Head; VTOY_GPT_HDR Head;
VTOY_GPT_PART_TBL PartTbl[128]; VTOY_GPT_PART_TBL PartTbl[128];
}VTOY_GPT_INFO; }VTOY_GPT_INFO;
#pragma pack() #pragma pack()
#define VENTOY_MAX_PHY_DRIVE 128 #define VENTOY_MAX_PHY_DRIVE 128
typedef struct PHY_DRIVE_INFO typedef struct PHY_DRIVE_INFO
{ {
int Id; int Id;
int PhyDrive; int PhyDrive;
int PartStyle;//0:MBR 1:GPT int PartStyle;//0:MBR 1:GPT
UINT64 SizeInBytes; UINT64 SizeInBytes;
BYTE DeviceType; BYTE DeviceType;
BOOL RemovableMedia; BOOL RemovableMedia;
CHAR VendorId[128]; CHAR VendorId[128];
CHAR ProductId[128]; CHAR ProductId[128];
CHAR ProductRev[128]; CHAR ProductRev[128];
CHAR SerialNumber[128]; CHAR SerialNumber[128];
STORAGE_BUS_TYPE BusType; STORAGE_BUS_TYPE BusType;
int FirstDriveLetter; CHAR DriveLetters[64];
CHAR VentoyVersion[32];
CHAR VentoyVersion[32];
}PHY_DRIVE_INFO;
}PHY_DRIVE_INFO;
typedef enum PROGRESS_POINT
{ typedef enum PROGRESS_POINT
PT_START = 0, {
PT_LOCK_FOR_CLEAN, PT_START = 0,
PT_DEL_ALL_PART, PT_LOCK_FOR_CLEAN,
PT_LOCK_FOR_WRITE, PT_DEL_ALL_PART,
PT_FORMAT_PART1, PT_LOCK_FOR_WRITE,
PT_LOCK_VOLUME = PT_FORMAT_PART1, PT_FORMAT_PART1,
PT_FORMAT_PART2, PT_LOCK_VOLUME = PT_FORMAT_PART1,
PT_FORMAT_PART2,
PT_WRITE_VENTOY_START,
PT_WRITE_VENTOY_FINISH = PT_WRITE_VENTOY_START + 32, PT_WRITE_VENTOY_START,
PT_WRITE_VENTOY_FINISH = PT_WRITE_VENTOY_START + 32,
PT_WRITE_STG1_IMG,
PT_WRITE_PART_TABLE, PT_WRITE_STG1_IMG,
PT_MOUNT_VOLUME, PT_WRITE_PART_TABLE,
PT_MOUNT_VOLUME,
PT_FINISH
}PROGRESS_POINT; PT_FINISH
}PROGRESS_POINT;
#define PROGRESS_BAR_SET_POS(pos) SetProgressBarPos(pos)
#define PROGRESS_BAR_SET_POS(pos) SetProgressBarPos(pos)
extern PHY_DRIVE_INFO *g_PhyDriveList;
extern DWORD g_PhyDriveCount; extern PHY_DRIVE_INFO *g_PhyDriveList;
extern int g_ForceOperation; extern DWORD g_PhyDriveCount;
extern HWND g_ProgressBarHwnd; extern int g_ForceOperation;
extern HFONT g_language_normal_font; extern HWND g_ProgressBarHwnd;
extern HFONT g_language_bold_font; extern HFONT g_language_normal_font;
extern HFONT g_language_bold_font;
void Log(const char *Fmt, ...);
BOOL IsPathExist(BOOL Dir, const char *Fmt, ...); void Log(const char *Fmt, ...);
void DumpWindowsVersion(void); BOOL IsPathExist(BOOL Dir, const char *Fmt, ...);
const CHAR* GetLocalVentoyVersion(void); void DumpWindowsVersion(void);
const CHAR* ParseVentoyVersionFromString(CHAR *Buf); const CHAR* GetLocalVentoyVersion(void);
CHAR GetFirstUnusedDriveLetter(void); const CHAR* ParseVentoyVersionFromString(CHAR *Buf);
const CHAR * GetBusTypeString(STORAGE_BUS_TYPE Type); CHAR GetFirstUnusedDriveLetter(void);
int VentoyGetLocalBootImg(MBR_HEAD *pMBR); const CHAR * GetBusTypeString(STORAGE_BUS_TYPE Type);
int GetHumanReadableGBSize(UINT64 SizeBytes); int VentoyGetLocalBootImg(MBR_HEAD *pMBR);
void TrimString(CHAR *String); int GetHumanReadableGBSize(UINT64 SizeBytes);
int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR, int PartStyle); void TrimString(CHAR *String);
int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo); int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR, int PartStyle);
BOOL IsVentoyLogicalDrive(CHAR DriveLetter); int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo);
int GetRegDwordValue(HKEY Key, LPCSTR SubKey, LPCSTR ValueName, DWORD *pValue); BOOL IsVentoyLogicalDrive(CHAR DriveLetter);
int GetPhysicalDriveCount(void); int GetRegDwordValue(HKEY Key, LPCSTR SubKey, LPCSTR ValueName, DWORD *pValue);
int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount); int GetPhysicalDriveCount(void);
int GetPhyDriveByLogicalDrive(int DriveLetter); int GetAllPhysicalDriveInfo(PHY_DRIVE_INFO *pDriveList, DWORD *pDriveCount);
int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, UINT64 Part2StartSector, CHAR *VerBuf, size_t BufLen); int GetPhyDriveByLogicalDrive(int DriveLetter);
int Ventoy2DiskInit(void); int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, UINT64 Part2StartSector, CHAR *VerBuf, size_t BufLen);
int Ventoy2DiskDestroy(void); int Ventoy2DiskInit(void);
PHY_DRIVE_INFO * GetPhyDriveInfoById(int Id); int Ventoy2DiskDestroy(void);
int ParseCmdLineOption(LPSTR lpCmdLine); PHY_DRIVE_INFO * GetPhyDriveInfoById(int Id);
int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle); int ParseCmdLineOption(LPSTR lpCmdLine);
int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive); int InstallVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive, int PartStyle);
int VentoyFillBackupGptHead(VTOY_GPT_INFO *pInfo, VTOY_GPT_HDR *pHead); int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive);
void SetProgressBarPos(int Pos); int VentoyFillBackupGptHead(VTOY_GPT_INFO *pInfo, VTOY_GPT_HDR *pHead);
int ReadWholeFileToBuf(const CHAR *FileName, int ExtLen, void **Bufer, int *BufLen); void SetProgressBarPos(int Pos);
int INIT unxz(unsigned char *in, int in_size, int ReadWholeFileToBuf(const CHAR *FileName, int ExtLen, void **Bufer, int *BufLen);
int(*fill)(void *dest, unsigned int size), int INIT unxz(unsigned char *in, int in_size,
int(*flush)(void *src, unsigned int size), int(*fill)(void *dest, unsigned int size),
unsigned char *out, int *in_used, int(*flush)(void *src, unsigned int size),
void(*error)(char *x)); unsigned char *out, int *in_used,
void disk_io_set_param(HANDLE Handle, UINT64 SectorCount); void(*error)(char *x));
INT_PTR CALLBACK PartDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam); void disk_io_set_param(HANDLE Handle, UINT64 SectorCount);
int GetReservedSpaceInMB(void); INT_PTR CALLBACK PartDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
int FindProcessOccupyDisk(HANDLE hDrive, PHY_DRIVE_INFO *pPhyDrive); int GetReservedSpaceInMB(void);
int VentoyFillLocation(UINT64 DiskSizeInBytes, UINT32 StartSectorId, UINT32 SectorCount, PART_TABLE *Table); int FindProcessOccupyDisk(HANDLE hDrive, PHY_DRIVE_INFO *pPhyDrive);
int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLetter); int VentoyFillLocation(UINT64 DiskSizeInBytes, UINT32 StartSectorId, UINT32 SectorCount, PART_TABLE *Table);
UINT32 VentoyCrc32(void *Buffer, UINT32 Length); int ClearVentoyFromPhyDrive(HWND hWnd, PHY_DRIVE_INFO *pPhyDrive, char *pDrvLetter);
UINT32 VentoyCrc32(void *Buffer, UINT32 Length);
#define SET_FILE_POS(pos) \
liCurrentPosition.QuadPart = pos; \ #define SET_FILE_POS(pos) \
SetFilePointerEx(hDrive, liCurrentPosition, &liCurrentPosition, FILE_BEGIN)\ liCurrentPosition.QuadPart = pos; \
SetFilePointerEx(hDrive, liCurrentPosition, &liCurrentPosition, FILE_BEGIN)\
#endif
#endif
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -704,6 +704,73 @@ static int DeleteVentoyPart2MountPoint(DWORD PhyDrive) ...@@ -704,6 +704,73 @@ static int DeleteVentoyPart2MountPoint(DWORD PhyDrive)
return 1; return 1;
} }
static int DecompressInjectionArchive(const char *archive, DWORD PhyDrive)
{
int rc = 1;
BOOL bRet;
DWORD dwBytes;
HANDLE hDrive;
CHAR PhyPath[MAX_PATH];
STARTUPINFOA Si;
PROCESS_INFORMATION Pi;
GET_LENGTH_INFORMATION LengthInfo;
Log("DecompressInjectionArchive %s", archive);
sprintf_s(PhyPath, sizeof(PhyPath), "\\\\.\\PhysicalDrive%d", PhyDrive);
hDrive = CreateFileA(PhyPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
if (hDrive == INVALID_HANDLE_VALUE)
{
Log("Could not open the disk<%s>, error:%u", PhyPath, GetLastError());
goto End;
}
bRet = DeviceIoControl(hDrive, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &LengthInfo, sizeof(LengthInfo), &dwBytes, NULL);
if (!bRet)
{
Log("Could not get phy disk %s size, error:%u", PhyPath, GetLastError());
goto End;
}
g_FatPhyDrive = hDrive;
g_Part2StartSec = (LengthInfo.Length.QuadPart - VENTOY_EFI_PART_SIZE) / 512;
Log("Parse FAT fs...");
fl_init();
if (0 == fl_attach_media(VentoyFatDiskRead, NULL))
{
if (g_64bit_system)
{
CopyFileFromFatDisk("/ventoy/7z/64/7za.exe", "ventoy\\7za.exe");
}
else
{
CopyFileFromFatDisk("/ventoy/7z/32/7za.exe", "ventoy\\7za.exe");
}
sprintf_s(PhyPath, sizeof(PhyPath), "ventoy\\7za.exe x -y -aoa -oX:\\ %s", archive);
Log("extract inject to X:");
GetStartupInfoA(&Si);
Si.dwFlags |= STARTF_USESHOWWINDOW;
Si.wShowWindow = SW_HIDE;
CreateProcessA(NULL, PhyPath, NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);
WaitForSingleObject(Pi.hProcess, INFINITE);
}
fl_shutdown();
End:
SAFE_CLOSE_HANDLE(hDrive);
return rc;
}
static int ProcessUnattendedInstallation(const char *script) static int ProcessUnattendedInstallation(const char *script)
{ {
DWORD dw; DWORD dw;
...@@ -809,6 +876,24 @@ static int VentoyHook(ventoy_os_param *param) ...@@ -809,6 +876,24 @@ static int VentoyHook(ventoy_os_param *param)
Log("auto install no need"); Log("auto install no need");
} }
if (g_windows_data.injection_archive[0])
{
sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", Letter, g_windows_data.injection_archive);
if (IsPathExist(FALSE, "%s", IsoPath))
{
Log("decompress injection archive %s...", IsoPath);
DecompressInjectionArchive(IsoPath, DiskExtent.DiskNumber);
}
else
{
Log("injection archive %s not exist", IsoPath);
}
}
else
{
Log("no injection archive found");
}
return 0; return 0;
} }
......
...@@ -68,6 +68,7 @@ typedef struct ventoy_os_param ...@@ -68,6 +68,7 @@ typedef struct ventoy_os_param
typedef struct ventoy_windows_data typedef struct ventoy_windows_data
{ {
char auto_install_script[384]; char auto_install_script[384];
char injection_archive[384];
UINT8 reserved[128]; UINT8 reserved[128];
}ventoy_windows_data; }ventoy_windows_data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment