[ui] add a new selection dialog for Windows 11 setup customization

* This moves the extended Windows 11 options (bypass TPM & Secure Boot) away from
  "Image options" into a new explicit dialog, along with supplementary customization
  such as enabling offline account (for Windows 11 22H2) and skipping all data
  collection questions.
* This customization is now enacted through an unattend.xml file rather than offline
  registry manipulation, so that this *should* also work with the Windows Store version.
* Also update arch detection and rework/reorganize upcoming translation changes.
* Note: The 'Remove "unsupported hardware" desktop watermark' option is *UNTESTED*.
This commit is contained in:
Pete Batard 2022-06-23 13:34:24 +01:00
parent 9690742d91
commit a0d669232c
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
11 changed files with 317 additions and 179 deletions

View file

@ -71,9 +71,10 @@ extern const int nb_steps[FS_MAX];
extern uint32_t dur_mins, dur_secs;
extern uint32_t wim_nb_files, wim_proc_files, wim_extra_files;
static int actual_fs_type, wintogo_index = -1, wininst_index = 0;
extern BOOL force_large_fat32, enable_ntfs_compression, lock_drive, zero_drive, fast_zeroing, enable_file_indexing, write_as_image;
extern BOOL use_vds, write_as_esp, is_vds_available;
extern BOOL force_large_fat32, enable_ntfs_compression, lock_drive, zero_drive, fast_zeroing, enable_file_indexing;
extern BOOL write_as_image, use_vds, write_as_esp, is_vds_available, enable_inplace;
extern const grub_patch_t grub_patch[2];
extern char* unattend_xml_path;
uint8_t *grub2_buf = NULL, *sec_buf = NULL;
long grub2_len;
@ -1468,80 +1469,69 @@ static BOOL SetupWinToGo(DWORD DriveIndex, const char* drive_name, BOOL use_esp)
}
/*
* Edit sources/boot.wim registry to remove Windows 11 install restrictions
* Add unattend.xml to 'sources\boot.wim' (install) or 'Windows\Panther\' (Windows To Go)
*/
BOOL RemoveWindows11Restrictions(char drive_letter)
BOOL ApplyWindowsCustomization(char drive_letter, BOOL windows_to_go)
{
BOOL r = FALSE, is_hive_mounted = FALSE;
int i;
BOOL r = FALSE;
const int wim_index = 2;
const char* offline_hive_name = "RUFUS_OFFLINE_HIVE";
const char* key_name[] = { "BypassTPMCheck", "BypassSecureBootCheck" };
char boot_wim_path[] = "#:\\sources\\boot.wim", key_path[64];
char* mount_path = NULL;
char path[MAX_PATH];
HKEY hKey = NULL, hSubKey = NULL;
LSTATUS status;
DWORD dwDisp, dwVal = 1;
char boot_wim_path[] = "?:\\sources\\boot.wim";
char appraiserres_dll_src[] = "?:\\sources\\appraiserres.dll";
char appraiserres_dll_dst[] = "?:\\sources\\appraiserres.bak";
char *mount_path = NULL, path[MAX_PATH];
boot_wim_path[0] = drive_letter;
UpdateProgressWithInfoForce(OP_PATCH, MSG_324, 0, PATCH_PROGRESS_TOTAL);
uprintf("Mounting '%s'...", boot_wim_path);
mount_path = WimMountImage(boot_wim_path, wim_index);
if (mount_path == NULL)
goto out;
static_sprintf(path, "%s\\Windows\\System32\\config\\SYSTEM", mount_path);
if (!MountRegistryHive(HKEY_LOCAL_MACHINE, offline_hive_name, path))
goto out;
UpdateProgressWithInfoForce(OP_PATCH, MSG_324, 102, PATCH_PROGRESS_TOTAL);
is_hive_mounted = TRUE;
static_sprintf(key_path, "%s\\Setup", offline_hive_name);
status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_path, 0, KEY_READ | KEY_CREATE_SUB_KEY, &hKey);
if (status != ERROR_SUCCESS) {
SetLastError(status);
uprintf("Could not open 'HKLM\\SYSTEM\\Setup' registry key: %s", WindowsErrorString());
goto out;
}
status = RegCreateKeyExA(hKey, "LabConfig", 0, NULL, 0,
KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_CREATE_SUB_KEY, NULL, &hSubKey, &dwDisp);
if (status != ERROR_SUCCESS) {
SetLastError(status);
uprintf("Could not create 'HKLM\\SYSTEM\\Setup\\LabConfig' registry key: %s", WindowsErrorString());
goto out;
}
for (i = 0; i < ARRAYSIZE(key_name); i++) {
status = RegSetValueExA(hSubKey, key_name[i], 0, REG_DWORD, (LPBYTE)&dwVal, sizeof(DWORD));
if (status != ERROR_SUCCESS) {
SetLastError(status);
uprintf("Could not set 'HKLM\\SYSTEM\\Setup\\LabConfig\\%s' registry key: %s",
key_name[i], WindowsErrorString());
assert(unattend_xml_path != NULL);
uprintf("Applying Windows customization:");
if (windows_to_go) {
static_sprintf(path, "%c:\\Windows\\Panther", drive_letter);
if (!CreateDirectoryA(path, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
uprintf("Could not create '%s' : %s", path, WindowsErrorString());
goto out;
}
uprintf("Created 'HKLM\\SYSTEM\\Setup\\LabConfig\\%s' registry key", key_name[i]);
static_sprintf(path, "%c:\\Windows\\Panther\\unattend.xml", drive_letter);
if (!CopyFileA(unattend_xml_path, path, TRUE)) {
uprintf("Could not create '%s' : %s", path, WindowsErrorString());
goto out;
}
uprintf("Added '%s'", path);
} else {
boot_wim_path[0] = drive_letter;
if (enable_inplace) {
// Create a backup of sources\appraiserres.dll and then create an empty file to
// allow in-place upgrades without TPM/SB. Note that we need to create an empty,
// appraiserres.dll otherwise setup.exe extracts its own.
appraiserres_dll_src[0] = drive_letter;
appraiserres_dll_dst[0] = drive_letter;
if (!MoveFileExU(appraiserres_dll_src, appraiserres_dll_dst, MOVEFILE_REPLACE_EXISTING))
uprintf("Could not rename '%s': %s", appraiserres_dll_src, WindowsErrorString());
else
CloseHandle(CreateFileU(appraiserres_dll_src, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL));
uprintf("Renamed '%s' → '%s'", appraiserres_dll_src, appraiserres_dll_dst);
}
UpdateProgressWithInfoForce(OP_PATCH, MSG_325, 0, PATCH_PROGRESS_TOTAL);
uprintf("Mounting '%s'...", boot_wim_path);
mount_path = WimMountImage(boot_wim_path, wim_index);
if (mount_path == NULL)
goto out;
static_sprintf(path, "%s\\Autounattend.xml", mount_path);
if (!CopyFileU(unattend_xml_path, path, TRUE)) {
uprintf("Could not create boot.wim 'Autounattend.xml': %s", WindowsErrorString());
goto out;
}
uprintf("Added 'Autounattend.xml' to '%s'", boot_wim_path);
UpdateProgressWithInfoForce(OP_PATCH, MSG_325, 103, PATCH_PROGRESS_TOTAL);
}
UpdateProgressWithInfoForce(OP_PATCH, MSG_324, 103, PATCH_PROGRESS_TOTAL);
r = TRUE;
out:
if (hSubKey != NULL)
RegCloseKey(hSubKey);
if (hKey != NULL)
RegCloseKey(hKey);
if (is_hive_mounted) {
UnmountRegistryHive(HKEY_LOCAL_MACHINE, offline_hive_name);
UpdateProgressWithInfoForce(OP_PATCH, MSG_324, 104, PATCH_PROGRESS_TOTAL);
}
if (mount_path) {
uprintf("Unmounting '%s'...", boot_wim_path, wim_index);
WimUnmountImage(boot_wim_path, wim_index);
UpdateProgressWithInfo(OP_PATCH, MSG_325, PATCH_PROGRESS_TOTAL, PATCH_PROGRESS_TOTAL);
}
UpdateProgressWithInfo(OP_PATCH, MSG_324, PATCH_PROGRESS_TOTAL, PATCH_PROGRESS_TOTAL);
free(mount_path);
return r;
}
@ -1900,8 +1890,6 @@ DWORD WINAPI FormatThread(void* param)
char drive_letters[27], fs_name[32], label[64];
char logfile[MAX_PATH], *userdir;
char efi_dst[] = "?:\\efi\\boot\\bootx64.efi";
char appraiserres_dll_src[] = "?:\\sources\\appraiserres.dll";
char appraiserres_dll_dst[] = "?:\\sources\\appraiserres.bak";
char kolibri_dst[] = "?:\\MTLD_F32";
char grub4dos_dst[] = "?:\\grldr";
@ -2336,6 +2324,10 @@ DWORD WINAPI FormatThread(void* param)
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_ISO_EXTRACT);
goto out;
}
if (unattend_xml_path != NULL) {
if (!ApplyWindowsCustomization(drive_name[0], TRUE))
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_PATCH);
}
} else {
assert(!img_report.is_windows_img);
if (!ExtractISO(image_path, drive_name, FALSE)) {
@ -2374,20 +2366,8 @@ DWORD WINAPI FormatThread(void* param)
if (!SetupWinPE(drive_name[0]))
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_PATCH);
}
if (ComboBox_GetCurItemData(hImageOption) == IMOP_WIN_EXTENDED) {
// Create a backup of sources\appraiserres.dll and then create an empty file to
// allow in-place upgrades without TPM/SB. Note that we need to create an empty,
// appraiserres.dll otherwise setup.exe extracts its own.
appraiserres_dll_src[0] = drive_name[0];
appraiserres_dll_dst[0] = drive_name[0];
uprintf("Renaming: '%s' → '%s'", appraiserres_dll_src, appraiserres_dll_dst);
if (!MoveFileExU(appraiserres_dll_src, appraiserres_dll_dst, MOVEFILE_REPLACE_EXISTING))
uprintf(" Rename failed: %s", WindowsErrorString());
else
CloseHandle(CreateFileU(appraiserres_dll_src, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL));
// Now patch for boot-time TPM/SB checks.
if (!RemoveWindows11Restrictions(drive_name[0]))
if (unattend_xml_path != NULL) {
if (!ApplyWindowsCustomization(drive_name[0], FALSE))
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_PATCH);
}
}