Commit ba5978d2 authored by longpanda's avatar longpanda
Browse files

1.0.66 release

parent c57717ae
......@@ -31,103 +31,7 @@
#include <sys/types.h>
#include <linux/fs.h>
#include <dirent.h>
#define IS_DIGIT(x) ((x) >= '0' && (x) <= '9')
#ifndef USE_DIET_C
#ifndef __mips__
typedef unsigned long long uint64_t;
#endif
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
#endif
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
typedef enum ventoy_fs_type
{
ventoy_fs_exfat = 0, /* 0: exfat */
ventoy_fs_ntfs, /* 1: NTFS */
ventoy_fs_ext, /* 2: ext2/ext3/ext4 */
ventoy_fs_xfs, /* 3: XFS */
ventoy_fs_udf, /* 4: UDF */
ventoy_fs_fat, /* 5: FAT */
ventoy_fs_max
}ventoy_fs_type;
#pragma pack(1)
typedef struct ventoy_guid
{
uint32_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[8];
}ventoy_guid;
typedef struct ventoy_image_disk_region
{
uint32_t image_sector_count; /* image sectors contained in this region */
uint32_t image_start_sector; /* image sector start */
uint64_t disk_start_sector; /* disk sector start */
}ventoy_image_disk_region;
typedef struct ventoy_image_location
{
ventoy_guid guid;
/* image sector size, currently this value is always 2048 */
uint32_t image_sector_size;
/* disk sector size, normally the value is 512 */
uint32_t disk_sector_size;
uint32_t region_count;
/*
* disk region data
* If the image file has more than one fragments in disk,
* there will be more than one region data here.
* You can calculate the region count by
*/
ventoy_image_disk_region regions[1];
/* ventoy_image_disk_region regions[2~region_count-1] */
}ventoy_image_location;
typedef struct ventoy_os_param
{
ventoy_guid guid; // VENTOY_GUID
uint8_t chksum; // checksum
uint8_t vtoy_disk_guid[16];
uint64_t vtoy_disk_size; // disk size in bytes
uint16_t vtoy_disk_part_id; // begin with 1
uint16_t vtoy_disk_part_type; // 0:exfat 1:ntfs other: reserved
char vtoy_img_path[384]; // It seems to be enough, utf-8 format
uint64_t vtoy_img_size; // image file size in bytes
/*
* Ventoy will write a copy of ventoy_image_location data into runtime memory
* this is the physically address and length of that memory.
* Address 0 means no such data exist.
* Address will be aligned by 4KB.
*
*/
uint64_t vtoy_img_location_addr;
uint32_t vtoy_img_location_len;
uint64_t vtoy_reserved[4]; // Internal use by ventoy
uint8_t vtoy_disk_signature[4];
uint8_t reserved[27];
}ventoy_os_param;
#pragma pack()
#include "vtoytool.h"
#ifndef O_BINARY
#define O_BINARY 0
......@@ -234,8 +138,16 @@ static void vtoy_dump_os_param(ventoy_os_param *param)
printf("param->vtoy_img_size = <%llu>\n", (unsigned long long)param->vtoy_img_size);
printf("param->vtoy_img_location_addr = <0x%llx>\n", (unsigned long long)param->vtoy_img_location_addr);
printf("param->vtoy_img_location_len = <%u>\n", param->vtoy_img_location_len);
printf("param->vtoy_reserved[0] = 0x%llx\n", (unsigned long long)param->vtoy_reserved[0]);
printf("param->vtoy_reserved[1] = 0x%llx\n", (unsigned long long)param->vtoy_reserved[1]);
printf("param->vtoy_reserved = %02x %02x %02x %02x %02x %02x %02x %02x\n",
param->vtoy_reserved[0],
param->vtoy_reserved[1],
param->vtoy_reserved[2],
param->vtoy_reserved[3],
param->vtoy_reserved[4],
param->vtoy_reserved[5],
param->vtoy_reserved[6],
param->vtoy_reserved[7]
);
printf("\n");
}
......@@ -392,7 +304,7 @@ static int vtoy_find_disk_by_size(unsigned long long size, char *diskname)
return rc;
}
static int vtoy_find_disk_by_guid(ventoy_os_param *param, char *diskname)
int vtoy_find_disk_by_guid(ventoy_os_param *param, char *diskname)
{
int rc = 0;
int count = 0;
......@@ -416,6 +328,7 @@ static int vtoy_find_disk_by_guid(ventoy_os_param *param, char *diskname)
}
memset(vtguid, 0, sizeof(vtguid));
memset(vtsig, 0, sizeof(vtsig));
rc = vtoy_get_disk_guid(p->d_name, vtguid, vtsig);
if (rc == 0 && memcmp(vtguid, param->vtoy_disk_guid, 16) == 0 &&
memcmp(vtsig, param->vtoy_disk_signature, 4) == 0)
......@@ -429,6 +342,43 @@ static int vtoy_find_disk_by_guid(ventoy_os_param *param, char *diskname)
return count;
}
static int vtoy_find_disk_by_sig(uint8_t *sig, char *diskname)
{
int rc = 0;
int count = 0;
DIR* dir = NULL;
struct dirent* p = NULL;
uint8_t vtguid[16];
uint8_t vtsig[16];
dir = opendir("/sys/block");
if (!dir)
{
return 0;
}
while ((p = readdir(dir)) != NULL)
{
if (!vtoy_is_possible_blkdev(p->d_name))
{
debug("disk %s is filted by name\n", p->d_name);
continue;
}
memset(vtguid, 0, sizeof(vtguid));
memset(vtsig, 0, sizeof(vtsig));
rc = vtoy_get_disk_guid(p->d_name, vtguid, vtsig);
if (rc == 0 && memcmp(vtsig, sig, 4) == 0)
{
sprintf(diskname, "%s", p->d_name);
count++;
}
}
closedir(dir);
return count;
}
static int vtoy_printf_iso_path(ventoy_os_param *param)
{
printf("%s\n", param->vtoy_img_path);
......@@ -453,6 +403,47 @@ static int vtoy_printf_fs(ventoy_os_param *param)
return 0;
}
static int vtoy_vlnk_printf(ventoy_os_param *param, char *diskname)
{
int cnt = 0;
uint8_t disk_sig[4];
uint8_t mbr[512];
int fd = -1;
char diskpath[128];
uint8_t check[8] = { 0x56, 0x54, 0x00, 0x47, 0x65, 0x00, 0x48, 0x44 };
memcpy(disk_sig, param->vtoy_reserved + 7, 4);
debug("vlnk disk sig: %02x %02x %02x %02x \n", disk_sig[0], disk_sig[1], disk_sig[2], disk_sig[3]);
cnt = vtoy_find_disk_by_sig(disk_sig, diskname);
if (cnt == 1)
{
snprintf(diskpath, sizeof(diskpath), "/dev/%s", diskname);
fd = open(diskpath, O_RDONLY | O_BINARY);
if (fd >= 0)
{
memset(mbr, 0, sizeof(mbr));
read(fd, mbr, sizeof(mbr));
close(fd);
if (memcmp(mbr + 0x190, check, 8) == 0)
{
printf("/dev/%s", diskname);
return 0;
}
else
{
debug("check data failed /dev/%s\n", diskname);
}
}
}
debug("find count=%d\n", cnt);
printf("unknown");
return 1;
}
static int vtoy_check_device(ventoy_os_param *param, const char *device)
{
unsigned long long size;
......@@ -524,7 +515,7 @@ static int vtoy_print_os_param(ventoy_os_param *param, char *diskname)
snprintf(diskpath, sizeof(diskpath) - 1, "/sys/class/block/%s2/size", diskname);
}
if (access(diskpath, F_OK) >= 0)
if (param->vtoy_reserved[6] == 0 && access(diskpath, F_OK) >= 0)
{
debug("get part size from sysfs for %s\n", diskpath);
......@@ -570,12 +561,13 @@ int vtoydump_main(int argc, char **argv)
int ch;
int print_path = 0;
int print_fs = 0;
int vlnk_print = 0;
char filename[256] = {0};
char diskname[256] = {0};
char device[64] = {0};
ventoy_os_param *param = NULL;
while ((ch = getopt(argc, argv, "c:f:p:s:v::")) != -1)
while ((ch = getopt(argc, argv, "c:f:p:t:s:v::")) != -1)
{
if (ch == 'f')
{
......@@ -594,6 +586,11 @@ int vtoydump_main(int argc, char **argv)
print_path = 1;
strncpy(filename, optarg, sizeof(filename) - 1);
}
else if (ch == 't')
{
vlnk_print = 1;
strncpy(filename, optarg, sizeof(filename) - 1);
}
else if (ch == 's')
{
print_fs = 1;
......@@ -655,6 +652,10 @@ int vtoydump_main(int argc, char **argv)
{
rc = vtoy_printf_fs(param);
}
else if (vlnk_print)
{
rc = vtoy_vlnk_printf(param, diskname);
}
else if (device[0])
{
rc = vtoy_check_device(param, device);
......
/******************************************************************************
* vtoytool.h
*
* Copyright (c) 2022, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __VTOYTOOL_H__
#define __VTOYTOOL_H__
#define IS_DIGIT(x) ((x) >= '0' && (x) <= '9')
#ifndef USE_DIET_C
#ifndef __mips__
typedef unsigned long long uint64_t;
#endif
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
#endif
#define VENTOY_GUID { 0x77772020, 0x2e77, 0x6576, { 0x6e, 0x74, 0x6f, 0x79, 0x2e, 0x6e, 0x65, 0x74 }}
typedef enum ventoy_fs_type
{
ventoy_fs_exfat = 0, /* 0: exfat */
ventoy_fs_ntfs, /* 1: NTFS */
ventoy_fs_ext, /* 2: ext2/ext3/ext4 */
ventoy_fs_xfs, /* 3: XFS */
ventoy_fs_udf, /* 4: UDF */
ventoy_fs_fat, /* 5: FAT */
ventoy_fs_max
}ventoy_fs_type;
#pragma pack(1)
typedef struct ventoy_guid
{
uint32_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[8];
}ventoy_guid;
typedef struct ventoy_image_disk_region
{
uint32_t image_sector_count; /* image sectors contained in this region */
uint32_t image_start_sector; /* image sector start */
uint64_t disk_start_sector; /* disk sector start */
}ventoy_image_disk_region;
typedef struct ventoy_image_location
{
ventoy_guid guid;
/* image sector size, currently this value is always 2048 */
uint32_t image_sector_size;
/* disk sector size, normally the value is 512 */
uint32_t disk_sector_size;
uint32_t region_count;
/*
* disk region data
* If the image file has more than one fragments in disk,
* there will be more than one region data here.
* You can calculate the region count by
*/
ventoy_image_disk_region regions[1];
/* ventoy_image_disk_region regions[2~region_count-1] */
}ventoy_image_location;
typedef struct ventoy_os_param
{
ventoy_guid guid; // VENTOY_GUID
uint8_t chksum; // checksum
uint8_t vtoy_disk_guid[16];
uint64_t vtoy_disk_size; // disk size in bytes
uint16_t vtoy_disk_part_id; // begin with 1
uint16_t vtoy_disk_part_type; // 0:exfat 1:ntfs other: reserved
char vtoy_img_path[384]; // It seems to be enough, utf-8 format
uint64_t vtoy_img_size; // image file size in bytes
/*
* Ventoy will write a copy of ventoy_image_location data into runtime memory
* this is the physically address and length of that memory.
* Address 0 means no such data exist.
* Address will be aligned by 4KB.
*
*/
uint64_t vtoy_img_location_addr;
uint32_t vtoy_img_location_len;
uint8_t vtoy_reserved[32]; // Internal use by ventoy
uint8_t vtoy_disk_signature[4];
uint8_t reserved[27];
}ventoy_os_param;
#pragma pack()
int vtoy_find_disk_by_guid(ventoy_os_param *param, char *diskname);
#endif
......@@ -40,6 +40,10 @@ static CHAR g_prog_full_path[MAX_PATH];
static CHAR g_prog_dir[MAX_PATH];
static CHAR g_prog_name[MAX_PATH];
#define VTOY_PECMD_PATH "X:\\Windows\\system32\\ventoy\\PECMD.EXE"
#define ORG_PECMD_PATH "X:\\Windows\\system32\\PECMD.EXE"
#define ORG_PECMD_BK_PATH "X:\\Windows\\system32\\PECMD.EXE_BACK.EXE"
#define AUTO_RUN_BAT "X:\\VentoyAutoRun.bat"
#define AUTO_RUN_LOG "X:\\VentoyAutoRun.log"
......@@ -431,7 +435,7 @@ out:
return bRet;
}
static int GetPhyDiskUUID(const char LogicalDrive, UINT8 *UUID, DISK_EXTENT *DiskExtent)
static int GetPhyDiskUUID(const char LogicalDrive, UINT8 *UUID, UINT32 *DiskSig, DISK_EXTENT *DiskExtent)
{
BOOL Ret;
DWORD dwSize;
......@@ -466,8 +470,9 @@ static int GetPhyDiskUUID(const char LogicalDrive, UINT8 *UUID, DISK_EXTENT *Dis
}
CloseHandle(Handle);
memcpy(DiskExtent, DiskExtents.Extents, sizeof(DiskExtent));
Log("%C: is in PhysicalDrive%d ", LogicalDrive, DiskExtents.Extents[0].DiskNumber);
memcpy(DiskExtent, DiskExtents.Extents, sizeof(DISK_EXTENT));
Log("%C: is in PhysicalDrive%d Offset:%llu", LogicalDrive, DiskExtents.Extents[0].DiskNumber,
(ULONGLONG)(DiskExtents.Extents[0].StartingOffset.QuadPart));
sprintf_s(PhyPath, sizeof(PhyPath), "\\\\.\\PhysicalDrive%d", DiskExtents.Extents[0].DiskNumber);
Handle = CreateFileA(PhyPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
......@@ -485,6 +490,11 @@ static int GetPhyDiskUUID(const char LogicalDrive, UINT8 *UUID, DISK_EXTENT *Dis
}
memcpy(UUID, SectorBuf + 0x180, 16);
if (DiskSig)
{
memcpy(DiskSig, SectorBuf + 0x1B8, 4);
}
CloseHandle(Handle);
return 0;
}
......@@ -1413,11 +1423,16 @@ static int VentoyHook(ventoy_os_param *param)
int i;
int rc;
BOOL find = FALSE;
BOOL vtoyfind = FALSE;
CHAR Letter;
CHAR MntLetter;
CHAR VtoyLetter;
DWORD Drives;
DWORD NewDrives;
UINT32 DiskSig;
UINT32 VtoySig;
DISK_EXTENT DiskExtent;
DISK_EXTENT VtoyDiskExtent;
UINT8 UUID[16];
CHAR IsoPath[MAX_PATH];
......@@ -1442,7 +1457,7 @@ static int VentoyHook(ventoy_os_param *param)
if (IsFileExist("%s", IsoPath))
{
Log("File exist under %C:", Letter);
if (GetPhyDiskUUID(Letter, UUID, &DiskExtent) == 0)
if (GetPhyDiskUUID(Letter, UUID, NULL, &DiskExtent) == 0)
{
if (memcmp(UUID, param->vtoy_disk_guid, 16) == 0)
{
......@@ -1481,6 +1496,60 @@ static int VentoyHook(ventoy_os_param *param)
Log("Find ISO file <%s>", IsoPath);
//Find VtoyLetter in Vlnk Mode
if (g_os_param_reserved[6] == 1)
{
memcpy(&VtoySig, g_os_param_reserved + 7, 4);
for (i = 0; i < 5; i++)
{
VtoyLetter = 'A';
Drives = GetLogicalDrives();
Log("Logic Drives: 0x%x VentoySig:%08X", Drives, VtoySig);
while (Drives)
{
if (Drives & 0x01)
{
if (GetPhyDiskUUID(VtoyLetter, UUID, &DiskSig, &VtoyDiskExtent) == 0)
{
Log("DiskSig=%08X PartStart=%lld", DiskSig, VtoyDiskExtent.StartingOffset.QuadPart);
if (DiskSig == VtoySig && VtoyDiskExtent.StartingOffset.QuadPart == SIZE_1MB)
{
Log("Ventoy Disk Sig match");
vtoyfind = TRUE;
break;
}
}
}
Drives >>= 1;
VtoyLetter++;
}
if (vtoyfind)
{
Log("Find Ventoy Letter: %C", VtoyLetter);
break;
}
else
{
Log("Now wait and retry ...");
Sleep(1000);
}
}
if (vtoyfind == FALSE)
{
Log("Failed to find ventoy disk");
return 1;
}
}
else
{
VtoyLetter = Letter;
Log("No vlnk mode %C", Letter);
}
Drives = GetLogicalDrives();
Log("Drives before mount: 0x%x", Drives);
......@@ -1519,12 +1588,12 @@ static int VentoyHook(ventoy_os_param *param)
}
// for protect
rc = DeleteVentoyPart2MountPoint(DiskExtent.DiskNumber);
rc = DeleteVentoyPart2MountPoint(VtoyDiskExtent.DiskNumber);
Log("Delete ventoy mountpoint: %s", rc == 0 ? "SUCCESS" : "NO NEED");
if (g_windows_data.auto_install_script[0])
{
sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", Letter, g_windows_data.auto_install_script);
sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", VtoyLetter, g_windows_data.auto_install_script);
if (IsFileExist("%s", IsoPath))
{
Log("use auto install script %s...", IsoPath);
......@@ -1542,11 +1611,11 @@ static int VentoyHook(ventoy_os_param *param)
if (g_windows_data.injection_archive[0])
{
sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", Letter, g_windows_data.injection_archive);
sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", VtoyLetter, g_windows_data.injection_archive);
if (IsFileExist("%s", IsoPath))
{
Log("decompress injection archive %s...", IsoPath);
DecompressInjectionArchive(IsoPath, DiskExtent.DiskNumber);
DecompressInjectionArchive(IsoPath, VtoyDiskExtent.DiskNumber);
if (IsFileExist("%s", AUTO_RUN_BAT))
{
......@@ -1886,6 +1955,14 @@ int real_main(int argc, char **argv)
return 0;
}
static void VentoyToUpper(CHAR *str)
{
int i;
for (i = 0; str[i]; i++)
{
str[i] = (CHAR)toupper(str[i]);
}
}
int main(int argc, char **argv)
{
......@@ -1920,12 +1997,24 @@ int main(int argc, char **argv)
}
else if (_stricmp(g_prog_name, "PECMD.exe") == 0)
{
Log("We need to rejump for pecmd ...");
strcpy_s(NewArgv0, sizeof(NewArgv0), g_prog_dir);
VentoyToUpper(NewArgv0);
if (NULL == strstr(NewArgv0, "SYSTEM32") && IsFileExist(ORG_PECMD_BK_PATH))
{
Log("Just call original pecmd.exe");
strcpy_s(CallParam, sizeof(CallParam), ORG_PECMD_PATH);
}
else
{
Log("We need to rejump for pecmd ...");
ventoy_check_create_directory();
CopyFileA(g_prog_full_path, "ventoy\\WinLogon.exe", TRUE);
ventoy_check_create_directory();
CopyFileA(g_prog_full_path, "ventoy\\WinLogon.exe", TRUE);
sprintf_s(CallParam, sizeof(CallParam), "ventoy\\WinLogon.exe %s", g_prog_full_path);
sprintf_s(CallParam, sizeof(CallParam), "ventoy\\WinLogon.exe %s", g_prog_full_path);
}
for (i = 1; i < argc; i++)
{
strcat_s(CallParam, sizeof(CallParam), " ");
......
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