2012-01-31 01:40:22 +00:00
|
|
|
/*
|
|
|
|
* Rufus: The Reliable USB Formatting Utility
|
|
|
|
* ISO file extraction
|
2015-01-01 23:39:28 +00:00
|
|
|
* Copyright © 2011-2015 Pete Batard <pete@akeo.ie>
|
2012-01-31 01:40:22 +00:00
|
|
|
* Based on libcdio's iso & udf samples:
|
2015-01-01 23:39:28 +00:00
|
|
|
* Copyright © 2003-2014 Rocky Bernstein <rocky@gnu.org>
|
2012-01-31 01:40:22 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Memory leaks detection - define _CRTDBG_MAP_ALLOC as preprocessor macro */
|
|
|
|
#ifdef _CRTDBG_MAP_ALLOC
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <direct.h>
|
2012-03-27 22:31:58 +00:00
|
|
|
#include <ctype.h>
|
2012-01-31 01:40:22 +00:00
|
|
|
|
|
|
|
#include <cdio/cdio.h>
|
|
|
|
#include <cdio/logging.h>
|
|
|
|
#include <cdio/iso9660.h>
|
|
|
|
#include <cdio/udf.h>
|
|
|
|
|
|
|
|
#include "rufus.h"
|
2012-02-01 14:26:36 +00:00
|
|
|
#include "msapi_utf8.h"
|
|
|
|
#include "resource.h"
|
2013-10-15 21:58:27 +00:00
|
|
|
#include "localization.h"
|
2012-01-31 01:40:22 +00:00
|
|
|
|
2012-02-01 14:26:36 +00:00
|
|
|
// How often should we update the progress bar (in 2K blocks) as updating
|
|
|
|
// the progress bar for every block will bring extraction to a crawl
|
2012-03-29 19:27:53 +00:00
|
|
|
#define PROGRESS_THRESHOLD 128
|
2012-02-07 02:05:58 +00:00
|
|
|
#define FOUR_GIGABYTES 4294967296LL
|
2012-01-31 01:40:22 +00:00
|
|
|
|
2012-02-01 14:26:36 +00:00
|
|
|
// Needed for UDF ISO access
|
2012-03-16 18:30:44 +00:00
|
|
|
CdIo_t* cdio_open (const char* psz_source, driver_id_t driver_id) {return NULL;}
|
|
|
|
void cdio_destroy (CdIo_t* p_cdio) {}
|
2012-01-31 01:40:22 +00:00
|
|
|
|
2014-12-16 23:24:06 +00:00
|
|
|
typedef struct {
|
|
|
|
BOOL is_syslinux_cfg;
|
|
|
|
BOOL is_grub_cfg;
|
|
|
|
BOOL is_old_c32[NB_OLD_C32];
|
|
|
|
} EXTRACT_PROPS;
|
|
|
|
|
2012-02-01 14:26:36 +00:00
|
|
|
RUFUS_ISO_REPORT iso_report;
|
2012-02-07 16:17:14 +00:00
|
|
|
int64_t iso_blocking_status = -1;
|
2014-04-13 14:20:20 +00:00
|
|
|
BOOL enable_iso = TRUE, enable_joliet = TRUE, enable_rockridge = TRUE, has_ldlinux_c32;
|
2012-02-07 16:17:14 +00:00
|
|
|
#define ISO_BLOCKING(x) do {x; iso_blocking_status++; } while(0)
|
2012-03-16 18:30:44 +00:00
|
|
|
static const char* psz_extract_dir;
|
2013-01-19 04:04:54 +00:00
|
|
|
static const char* bootmgr_efi_name = "bootmgr.efi";
|
2014-11-14 23:40:00 +00:00
|
|
|
static const char* grldr_name = "grldr";
|
2012-03-16 18:30:44 +00:00
|
|
|
static const char* ldlinux_name = "ldlinux.sys";
|
2014-01-21 17:08:41 +00:00
|
|
|
static const char* ldlinux_c32 = "ldlinux.c32";
|
2013-01-18 01:39:24 +00:00
|
|
|
static const char* efi_dirname = "/efi/boot";
|
2015-01-13 02:11:57 +00:00
|
|
|
static const char* efi_bootname[] = { "bootia32.efi", "bootx64.efi", "bootia64.efi", "bootarm.efi" };
|
2015-02-09 19:34:41 +00:00
|
|
|
static const char* install_wim_path = "/sources";
|
|
|
|
static const char* install_wim_name[] = { "install.wim", "install.swm" };
|
|
|
|
static const char* grub_dirname = "/boot/grub"; // NB: We don't support nonstandard config dir such as AROS' "/boot/pc/grub/"
|
2014-12-16 23:24:06 +00:00
|
|
|
static const char* grub_cfg = "grub.cfg";
|
2014-01-21 17:08:41 +00:00
|
|
|
static const char* syslinux_cfg[] = { "isolinux.cfg", "syslinux.cfg", "extlinux.conf"};
|
|
|
|
static const char dot_isolinux_bin[] = ".\\isolinux.bin";
|
|
|
|
static const char* isolinux_bin = &dot_isolinux_bin[2];
|
2012-03-16 18:30:44 +00:00
|
|
|
static const char* pe_dirname[] = { "/i386", "/minint" };
|
|
|
|
static const char* pe_file[] = { "ntdetect.com", "setupldr.bin", "txtsetup.sif" };
|
2014-01-02 23:21:30 +00:00
|
|
|
static const char* reactos_name = "setupldr.sys"; // TODO: freeldr.sys doesn't seem to work
|
2014-05-15 20:17:12 +00:00
|
|
|
static const char* kolibri_name = "kolibri.img";
|
2013-11-17 22:24:50 +00:00
|
|
|
static const char* autorun_name = "autorun.inf";
|
2014-02-09 23:38:16 +00:00
|
|
|
static const char* stupid_antivirus = " NOTE: This is usually caused by a poorly designed security solution. "
|
|
|
|
"See http://rufus.akeo.ie/compatibility.\r\n This file will be skipped for now, but you should really "
|
|
|
|
"look into using a *SMARTER* antivirus solution.";
|
2014-02-04 20:01:28 +00:00
|
|
|
const char* old_c32_name[NB_OLD_C32] = OLD_C32_NAMES;
|
2012-12-15 03:27:14 +00:00
|
|
|
static const int64_t old_c32_threshold[NB_OLD_C32] = OLD_C32_THRESHOLD;
|
2012-02-15 21:55:41 +00:00
|
|
|
static uint8_t i_joliet_level = 0;
|
2012-02-01 14:26:36 +00:00
|
|
|
static uint64_t total_blocks, nb_blocks;
|
|
|
|
static BOOL scan_only = FALSE;
|
2014-01-21 17:08:41 +00:00
|
|
|
static StrArray config_path, isolinux_path;
|
2012-01-31 01:40:22 +00:00
|
|
|
|
2013-10-26 23:05:54 +00:00
|
|
|
// Ensure filenames do not contain invalid FAT32 or NTFS characters
|
2014-11-20 23:00:59 +00:00
|
|
|
static __inline char* sanitize_filename(char* filename, BOOL* is_identical)
|
2013-10-26 23:05:54 +00:00
|
|
|
{
|
|
|
|
size_t i, j;
|
2014-11-20 23:00:59 +00:00
|
|
|
char* ret = NULL;
|
2013-10-26 23:05:54 +00:00
|
|
|
char unauthorized[] = {'<', '>', ':', '|', '*', '?'};
|
|
|
|
|
2014-11-20 23:00:59 +00:00
|
|
|
*is_identical = TRUE;
|
|
|
|
ret = safe_strdup(filename);
|
|
|
|
if (ret == NULL) {
|
2015-01-01 23:39:28 +00:00
|
|
|
uprintf("Could not allocate string for sanitized path");
|
2014-11-20 23:00:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-26 23:05:54 +00:00
|
|
|
// Must start after the drive part (D:\...) so that we don't eliminate the first column
|
2014-11-20 23:00:59 +00:00
|
|
|
for (i=2; i<safe_strlen(ret); i++) {
|
2013-10-26 23:05:54 +00:00
|
|
|
for (j=0; j<sizeof(unauthorized); j++) {
|
2014-11-20 23:00:59 +00:00
|
|
|
if (ret[i] == unauthorized[j]) {
|
|
|
|
ret[i] = '_';
|
|
|
|
*is_identical = FALSE;
|
2013-10-26 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-14 20:52:39 +00:00
|
|
|
static void log_handler (cdio_log_level_t level, const char *message)
|
2012-02-07 02:05:58 +00:00
|
|
|
{
|
2012-02-14 20:52:39 +00:00
|
|
|
switch(level) {
|
|
|
|
case CDIO_LOG_DEBUG:
|
2015-01-25 00:56:38 +00:00
|
|
|
// TODO: use a setting to enable libcdio debug?
|
2012-02-14 20:52:39 +00:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
uprintf("libcdio: %s\n", message);
|
|
|
|
}
|
2012-02-07 02:05:58 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 19:46:28 +00:00
|
|
|
/*
|
|
|
|
* Scan and set ISO properties
|
|
|
|
* Returns true if the the current file does not need to be processed further
|
|
|
|
*/
|
2014-12-16 23:24:06 +00:00
|
|
|
static BOOL check_iso_props(const char* psz_dirname, int64_t i_file_length, const char* psz_basename,
|
|
|
|
const char* psz_fullpath, EXTRACT_PROPS *props)
|
2012-02-21 19:46:28 +00:00
|
|
|
{
|
2012-03-16 18:30:44 +00:00
|
|
|
size_t i, j;
|
2012-02-21 19:46:28 +00:00
|
|
|
// Check for an isolinux/syslinux config file anywhere
|
2014-12-16 23:24:06 +00:00
|
|
|
memset(props, 0, sizeof(EXTRACT_PROPS));
|
2014-01-21 17:08:41 +00:00
|
|
|
for (i=0; i<ARRAYSIZE(syslinux_cfg); i++) {
|
2014-10-29 02:00:46 +00:00
|
|
|
if (safe_stricmp(psz_basename, syslinux_cfg[i]) == 0) {
|
2014-12-16 23:24:06 +00:00
|
|
|
props->is_syslinux_cfg = TRUE;
|
2014-10-29 02:00:46 +00:00
|
|
|
if ((scan_only) && (i == 1) && (safe_stricmp(psz_dirname, efi_dirname) == 0))
|
|
|
|
iso_report.has_efi_syslinux = TRUE;
|
|
|
|
}
|
2012-02-21 19:46:28 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 03:27:14 +00:00
|
|
|
// Check for an old incompatible c32 file anywhere
|
|
|
|
for (i=0; i<NB_OLD_C32; i++) {
|
|
|
|
if ((safe_stricmp(psz_basename, old_c32_name[i]) == 0) && (i_file_length <= old_c32_threshold[i]))
|
2014-12-16 23:24:06 +00:00
|
|
|
props->is_old_c32[i] = TRUE;
|
2012-03-11 01:55:25 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 23:24:06 +00:00
|
|
|
// Check for the Grub config file
|
|
|
|
if ((safe_stricmp(psz_dirname, grub_dirname) == 0) && (safe_stricmp(psz_basename, grub_cfg) == 0)) {
|
|
|
|
if (scan_only)
|
|
|
|
iso_report.has_grub2 = TRUE;
|
|
|
|
else
|
|
|
|
props->is_grub_cfg = TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-21 19:46:28 +00:00
|
|
|
if (scan_only) {
|
2014-12-16 23:24:06 +00:00
|
|
|
// Check for a syslinux v5.0+ file anywhere
|
|
|
|
if (safe_stricmp(psz_basename, ldlinux_c32) == 0) {
|
|
|
|
has_ldlinux_c32 = TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-15 20:17:12 +00:00
|
|
|
// Check for various files in root (psz_dirname = "")
|
2013-01-19 04:04:54 +00:00
|
|
|
if (*psz_dirname == 0) {
|
2013-05-19 22:02:16 +00:00
|
|
|
if (safe_strnicmp(psz_basename, bootmgr_efi_name, safe_strlen(bootmgr_efi_name)-5) == 0) {
|
2013-01-19 04:04:54 +00:00
|
|
|
iso_report.has_bootmgr = TRUE;
|
2013-05-19 22:02:16 +00:00
|
|
|
}
|
2014-11-14 23:40:00 +00:00
|
|
|
if (safe_stricmp(psz_basename, grldr_name) == 0) {
|
|
|
|
iso_report.has_grub4dos = TRUE;
|
2013-01-19 04:04:54 +00:00
|
|
|
}
|
2014-05-15 20:17:12 +00:00
|
|
|
if (safe_stricmp(psz_basename, kolibri_name) == 0) {
|
|
|
|
iso_report.has_kolibrios = TRUE;
|
|
|
|
}
|
2014-11-14 23:40:00 +00:00
|
|
|
if (safe_stricmp(psz_basename, bootmgr_efi_name) == 0) {
|
2015-01-13 02:11:57 +00:00
|
|
|
iso_report.has_efi |= 1;
|
2014-11-14 23:40:00 +00:00
|
|
|
}
|
2013-01-19 04:04:54 +00:00
|
|
|
}
|
2012-03-16 18:30:44 +00:00
|
|
|
|
2014-01-02 23:21:30 +00:00
|
|
|
// Check for ReactOS' setupldr.sys anywhere
|
|
|
|
if ((iso_report.reactos_path[0] == 0) && (safe_stricmp(psz_basename, reactos_name) == 0))
|
|
|
|
safe_strcpy(iso_report.reactos_path, sizeof(iso_report.reactos_path), psz_fullpath);
|
|
|
|
|
2015-01-13 02:11:57 +00:00
|
|
|
// Check for the EFI boot entries
|
|
|
|
if (safe_stricmp(psz_dirname, efi_dirname) == 0) {
|
|
|
|
for (i=0; i<ARRAYSIZE(efi_bootname); i++)
|
|
|
|
if (safe_stricmp(psz_basename, efi_bootname[i]) == 0)
|
2015-02-09 19:34:41 +00:00
|
|
|
iso_report.has_efi |= (2<<i); // start at 2 since "bootmgr.efi" is bit 0
|
2015-01-13 02:11:57 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 19:34:41 +00:00
|
|
|
// Check for "install.wim" or "install.swm" in "/sources"
|
|
|
|
if (safe_stricmp(psz_dirname, install_wim_path) == 0) {
|
|
|
|
for (i=0; i<ARRAYSIZE(install_wim_name); i++)
|
|
|
|
if (safe_stricmp(psz_basename, install_wim_name[i]) == 0)
|
2015-02-26 23:47:20 +00:00
|
|
|
static_sprintf(iso_report.install_wim_path, "?:\\%s\\%s", &install_wim_path[1], install_wim_name[i]);
|
2015-02-09 19:34:41 +00:00
|
|
|
}
|
2013-01-18 01:39:24 +00:00
|
|
|
|
2012-03-16 18:30:44 +00:00
|
|
|
// Check for PE (XP) specific files in "/i386" or "/minint"
|
|
|
|
for (i=0; i<ARRAYSIZE(pe_dirname); i++)
|
|
|
|
if (safe_stricmp(psz_dirname, pe_dirname[i]) == 0)
|
|
|
|
for (j=0; j<ARRAYSIZE(pe_file); j++)
|
|
|
|
if (safe_stricmp(psz_basename, pe_file[j]) == 0)
|
|
|
|
iso_report.winpe |= (1<<i)<<(ARRAYSIZE(pe_dirname)*j);
|
|
|
|
|
2014-12-16 23:24:06 +00:00
|
|
|
if (props->is_syslinux_cfg) {
|
2012-02-21 19:46:28 +00:00
|
|
|
// Maintain a list of all the isolinux/syslinux configs identified so far
|
|
|
|
StrArrayAdd(&config_path, psz_fullpath);
|
|
|
|
}
|
2014-01-21 17:08:41 +00:00
|
|
|
if (safe_stricmp(psz_basename, isolinux_bin) == 0) {
|
|
|
|
// Maintain a list of all the isolinux.bin files found
|
|
|
|
StrArrayAdd(&isolinux_path, psz_fullpath);
|
|
|
|
}
|
|
|
|
|
2012-12-15 03:27:14 +00:00
|
|
|
for (i=0; i<NB_OLD_C32; i++) {
|
2014-12-16 23:24:06 +00:00
|
|
|
if (props->is_old_c32[i])
|
2012-12-15 03:27:14 +00:00
|
|
|
iso_report.has_old_c32[i] = TRUE;
|
|
|
|
}
|
2012-02-21 19:46:28 +00:00
|
|
|
if (i_file_length >= FOUR_GIGABYTES)
|
|
|
|
iso_report.has_4GB_file = TRUE;
|
|
|
|
// Compute projected size needed
|
|
|
|
total_blocks += i_file_length/UDF_BLOCKSIZE;
|
|
|
|
// NB: ISO_BLOCKSIZE = UDF_BLOCKSIZE
|
|
|
|
if ((i_file_length != 0) && (i_file_length%ISO_BLOCKSIZE == 0)) //
|
|
|
|
total_blocks++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
// In case there's an ldlinux.sys on the ISO, prevent it from overwriting ours
|
2012-03-16 18:30:44 +00:00
|
|
|
if ((*psz_dirname == 0) && (safe_strcmp(psz_basename, ldlinux_name) == 0)) {
|
2012-02-21 19:46:28 +00:00
|
|
|
uprintf("skipping % file from ISO image\n", ldlinux_name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-16 23:24:06 +00:00
|
|
|
static void fix_config(const char* psz_fullpath, const char* psz_path, const char* psz_basename, EXTRACT_PROPS* props)
|
2014-11-07 23:57:17 +00:00
|
|
|
{
|
|
|
|
size_t i, nul_pos;
|
2014-12-16 23:24:06 +00:00
|
|
|
char *iso_label = NULL, *usb_label = NULL, *src, *dst;
|
2014-11-07 23:57:17 +00:00
|
|
|
|
|
|
|
nul_pos = safe_strlen(psz_fullpath);
|
|
|
|
src = safe_strdup(psz_fullpath);
|
|
|
|
if (src == NULL)
|
|
|
|
return;
|
|
|
|
for (i=0; i<nul_pos; i++)
|
|
|
|
if (src[i] == '/') src[i] = '\\';
|
|
|
|
|
2014-12-16 23:24:06 +00:00
|
|
|
if (props->is_syslinux_cfg) {
|
|
|
|
// Workaround for isolinux config files requiring an ISO label for kernel
|
|
|
|
// append that may be different from our USB label. Oh, and these labels
|
|
|
|
// must have spaces converted to \x20.
|
|
|
|
iso_label = replace_char(iso_report.label, ' ', "\\x20");
|
|
|
|
usb_label = replace_char(iso_report.usb_label, ' ', "\\x20");
|
|
|
|
if ((iso_label != NULL) && (usb_label != NULL)) {
|
|
|
|
if (replace_in_token_data(src, "append", iso_label, usb_label, TRUE) != NULL)
|
|
|
|
uprintf(" Patched %s: '%s' ⇨ '%s'\n", src, iso_label, usb_label);
|
|
|
|
// Fix dual BIOS + EFI support for tails and other ISOs
|
|
|
|
if ( (safe_stricmp(psz_path, efi_dirname) == 0) && (safe_stricmp(psz_basename, syslinux_cfg[0]) == 0) &&
|
|
|
|
(!iso_report.has_efi_syslinux) && (dst = safe_strdup(src)) ) {
|
|
|
|
dst[nul_pos-12] = 's'; dst[nul_pos-11] = 'y'; dst[nul_pos-10] = 's';
|
|
|
|
CopyFileA(src, dst, TRUE);
|
|
|
|
uprintf("Duplicated %s to %s\n", src, dst);
|
|
|
|
free(dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (props->is_grub_cfg) {
|
|
|
|
// Workaround for FreeNAS
|
|
|
|
iso_label = malloc(MAX_PATH);
|
|
|
|
usb_label = malloc(MAX_PATH);
|
|
|
|
if ((iso_label != NULL) && (usb_label != NULL)) {
|
|
|
|
safe_sprintf(iso_label, MAX_PATH, "cd9660:/dev/iso9660/%s", iso_report.label);
|
|
|
|
safe_sprintf(usb_label, MAX_PATH, "msdosfs:/dev/msdosfs/%s", iso_report.usb_label);
|
|
|
|
if (replace_in_token_data(src, "set", iso_label, usb_label, TRUE) != NULL)
|
|
|
|
uprintf(" Patched %s: '%s' ⇨ '%s'\n", src, iso_label, usb_label);
|
|
|
|
}
|
2014-11-07 23:57:17 +00:00
|
|
|
}
|
2014-12-16 23:24:06 +00:00
|
|
|
safe_free(iso_label);
|
|
|
|
safe_free(usb_label);
|
2014-11-09 19:55:17 +00:00
|
|
|
free(src);
|
2014-11-07 23:57:17 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 23:00:59 +00:00
|
|
|
static void print_extracted_file(char* psz_fullpath, int64_t i_file_length)
|
|
|
|
{
|
|
|
|
size_t i, nul_pos;
|
|
|
|
|
2015-01-23 02:26:41 +00:00
|
|
|
if (psz_fullpath == NULL)
|
|
|
|
return;
|
2014-11-20 23:00:59 +00:00
|
|
|
// Replace slashes with backslashes and append the size to the path for UI display
|
2015-01-23 02:26:41 +00:00
|
|
|
nul_pos = strlen(psz_fullpath);
|
2014-11-20 23:00:59 +00:00
|
|
|
for (i=0; i<nul_pos; i++)
|
|
|
|
if (psz_fullpath[i] == '/') psz_fullpath[i] = '\\';
|
|
|
|
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, TRUE, FALSE));
|
|
|
|
uprintf("Extracting: %s\n", psz_fullpath);
|
|
|
|
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, FALSE, FALSE));
|
2015-01-15 01:45:10 +00:00
|
|
|
// TODO: I don't think we need both of these...
|
2015-01-01 23:39:28 +00:00
|
|
|
SendMessageLU(GetDlgItem(hMainDialog, IDC_STATUS), SB_SETTEXTW, SBT_OWNERDRAW, psz_fullpath);
|
|
|
|
PrintStatus(0, MSG_000, psz_fullpath); // MSG_000 is "%s"
|
2014-11-20 23:00:59 +00:00
|
|
|
// ISO9660 cannot handle backslashes
|
|
|
|
for (i=0; i<nul_pos; i++)
|
|
|
|
if (psz_fullpath[i] == '\\') psz_fullpath[i] = '/';
|
|
|
|
// Remove the appended size for extraction
|
|
|
|
psz_fullpath[nul_pos] = 0;
|
|
|
|
}
|
|
|
|
|
2012-02-07 02:05:58 +00:00
|
|
|
// Returns 0 on success, nonzero on error
|
2012-01-31 01:40:22 +00:00
|
|
|
static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path)
|
|
|
|
{
|
2012-02-07 16:17:14 +00:00
|
|
|
HANDLE file_handle = NULL;
|
2013-11-17 22:24:50 +00:00
|
|
|
DWORD buf_size, wr_size, err;
|
2014-12-16 23:24:06 +00:00
|
|
|
EXTRACT_PROPS props;
|
|
|
|
BOOL r, is_identical;
|
2012-01-31 01:40:22 +00:00
|
|
|
int i_length;
|
2014-11-20 23:00:59 +00:00
|
|
|
size_t i;
|
|
|
|
char tmp[128], *psz_fullpath = NULL, *psz_sanpath = NULL;
|
2012-01-31 01:40:22 +00:00
|
|
|
const char* psz_basename;
|
|
|
|
udf_dirent_t *p_udf_dirent2;
|
|
|
|
uint8_t buf[UDF_BLOCKSIZE];
|
|
|
|
int64_t i_read, i_file_length;
|
|
|
|
|
|
|
|
if ((p_udf_dirent == NULL) || (psz_path == NULL))
|
|
|
|
return 1;
|
|
|
|
|
2012-02-01 14:26:36 +00:00
|
|
|
while ((p_udf_dirent = udf_readdir(p_udf_dirent)) != NULL) {
|
|
|
|
if (FormatStatus) goto out;
|
2012-01-31 01:40:22 +00:00
|
|
|
psz_basename = udf_get_filename(p_udf_dirent);
|
2013-10-30 20:29:55 +00:00
|
|
|
if (strlen(psz_basename) == 0)
|
|
|
|
continue;
|
2012-02-07 02:05:58 +00:00
|
|
|
i_length = (int)(3 + strlen(psz_path) + strlen(psz_basename) + strlen(psz_extract_dir) + 24);
|
2012-01-31 01:40:22 +00:00
|
|
|
psz_fullpath = (char*)calloc(sizeof(char), i_length);
|
|
|
|
if (psz_fullpath == NULL) {
|
|
|
|
uprintf("Error allocating file name\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2013-01-09 21:54:28 +00:00
|
|
|
i_length = _snprintf(psz_fullpath, i_length, "%s%s/%s", psz_extract_dir, psz_path, psz_basename);
|
2012-01-31 01:40:22 +00:00
|
|
|
if (i_length < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (udf_is_dir(p_udf_dirent)) {
|
2014-11-20 23:00:59 +00:00
|
|
|
if (!scan_only) {
|
|
|
|
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
|
|
|
|
IGNORE_RETVAL(_mkdirU(psz_sanpath));
|
|
|
|
safe_free(psz_sanpath);
|
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
p_udf_dirent2 = udf_opendir(p_udf_dirent);
|
|
|
|
if (p_udf_dirent2 != NULL) {
|
|
|
|
if (udf_extract_files(p_udf, p_udf_dirent2, &psz_fullpath[strlen(psz_extract_dir)]))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
2012-02-01 14:26:36 +00:00
|
|
|
i_file_length = udf_get_file_length(p_udf_dirent);
|
2014-12-16 23:24:06 +00:00
|
|
|
if (check_iso_props(psz_path, i_file_length, psz_basename, psz_fullpath, &props)) {
|
2012-02-01 14:26:36 +00:00
|
|
|
safe_free(psz_fullpath);
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-20 23:00:59 +00:00
|
|
|
print_extracted_file(psz_fullpath, i_file_length);
|
2012-12-15 03:27:14 +00:00
|
|
|
for (i=0; i<NB_OLD_C32; i++) {
|
2014-12-16 23:24:06 +00:00
|
|
|
if (props.is_old_c32[i] && use_own_c32[i]) {
|
2014-02-04 20:01:28 +00:00
|
|
|
static_sprintf(tmp, "%s/syslinux-%s/%s", FILES_DIR, embedded_sl_version_str[0], old_c32_name[i]);
|
|
|
|
if (CopyFileA(tmp, psz_fullpath, FALSE)) {
|
2012-12-15 03:27:14 +00:00
|
|
|
uprintf(" Replaced with local version\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uprintf(" Could not replace file: %s\n", WindowsErrorString());
|
2012-03-11 01:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-15 03:27:14 +00:00
|
|
|
if (i < NB_OLD_C32)
|
|
|
|
continue;
|
2014-11-20 23:00:59 +00:00
|
|
|
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
|
|
|
|
if (!is_identical)
|
|
|
|
uprintf(" File name sanitized to '%s'\n", psz_sanpath);
|
|
|
|
file_handle = CreateFileU(psz_sanpath, GENERIC_READ | GENERIC_WRITE,
|
2012-02-07 02:05:58 +00:00
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE) {
|
2013-11-17 22:24:50 +00:00
|
|
|
err = GetLastError();
|
2012-02-07 02:05:58 +00:00
|
|
|
uprintf(" Unable to create file: %s\n", WindowsErrorString());
|
2014-11-20 23:00:59 +00:00
|
|
|
if ((err == ERROR_ACCESS_DENIED) && (safe_strcmp(&psz_sanpath[3], autorun_name) == 0))
|
2014-02-09 23:38:16 +00:00
|
|
|
uprintf(stupid_antivirus);
|
|
|
|
else
|
|
|
|
goto out;
|
|
|
|
} else while (i_file_length > 0) {
|
2012-02-01 14:26:36 +00:00
|
|
|
if (FormatStatus) goto out;
|
2012-01-31 01:40:22 +00:00
|
|
|
memset(buf, 0, UDF_BLOCKSIZE);
|
|
|
|
i_read = udf_read_block(p_udf_dirent, buf, 1);
|
|
|
|
if (i_read < 0) {
|
2013-12-05 11:43:49 +00:00
|
|
|
uprintf(" Error reading UDF file %s\n", &psz_fullpath[strlen(psz_extract_dir)]);
|
2012-01-31 01:40:22 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2012-02-07 02:05:58 +00:00
|
|
|
buf_size = (DWORD)MIN(i_file_length, i_read);
|
2013-12-06 23:31:41 +00:00
|
|
|
for (i=0; i<WRITE_RETRIES; i++) {
|
|
|
|
ISO_BLOCKING(r = WriteFile(file_handle, buf, buf_size, &wr_size, NULL));
|
|
|
|
if ((!r) || (buf_size != wr_size)) {
|
|
|
|
uprintf(" Error writing file: %s", WindowsErrorString());
|
|
|
|
if (i < WRITE_RETRIES-1)
|
|
|
|
uprintf(" RETRYING...\n");
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
2013-12-06 23:31:41 +00:00
|
|
|
if (i >= WRITE_RETRIES) goto out;
|
2012-01-31 01:40:22 +00:00
|
|
|
i_file_length -= i_read;
|
2015-01-01 23:39:28 +00:00
|
|
|
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
|
2012-03-29 19:27:53 +00:00
|
|
|
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks);
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
2012-02-07 02:05:58 +00:00
|
|
|
// If you have a fast USB 3.0 device, the default Windows buffering does an
|
|
|
|
// excellent job at compensating for our small blocks read/writes to max out the
|
|
|
|
// device's bandwidth.
|
|
|
|
// The drawback however is with cancellation. With a large file, CloseHandle()
|
2012-02-07 16:17:14 +00:00
|
|
|
// may take forever to complete and is not interruptible. We try to detect this.
|
|
|
|
ISO_BLOCKING(safe_closehandle(file_handle));
|
2014-12-16 23:24:06 +00:00
|
|
|
if (props.is_syslinux_cfg || props.is_grub_cfg)
|
|
|
|
fix_config(psz_sanpath, psz_path, psz_basename, &props);
|
2014-11-20 23:00:59 +00:00
|
|
|
safe_free(psz_sanpath);
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
2012-02-01 14:26:36 +00:00
|
|
|
safe_free(psz_fullpath);
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
2012-02-01 14:26:36 +00:00
|
|
|
if (p_udf_dirent != NULL)
|
|
|
|
udf_dirent_free(p_udf_dirent);
|
2012-02-07 16:17:14 +00:00
|
|
|
ISO_BLOCKING(safe_closehandle(file_handle));
|
2012-02-01 14:26:36 +00:00
|
|
|
safe_free(psz_fullpath);
|
2012-01-31 01:40:22 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-02-07 02:05:58 +00:00
|
|
|
// Returns 0 on success, nonzero on error
|
2012-01-31 01:40:22 +00:00
|
|
|
static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
|
|
|
|
{
|
2012-02-07 16:17:14 +00:00
|
|
|
HANDLE file_handle = NULL;
|
2013-11-17 22:24:50 +00:00
|
|
|
DWORD buf_size, wr_size, err;
|
2014-12-16 23:24:06 +00:00
|
|
|
EXTRACT_PROPS props;
|
|
|
|
BOOL s, is_symlink, is_identical;
|
2012-01-31 01:40:22 +00:00
|
|
|
int i_length, r = 1;
|
2014-11-20 23:00:59 +00:00
|
|
|
char tmp[128], psz_fullpath[MAX_PATH], *psz_basename, *psz_sanpath;
|
2012-01-31 01:40:22 +00:00
|
|
|
const char *psz_iso_name = &psz_fullpath[strlen(psz_extract_dir)];
|
|
|
|
unsigned char buf[ISO_BLOCKSIZE];
|
|
|
|
CdioListNode_t* p_entnode;
|
|
|
|
iso9660_stat_t *p_statbuf;
|
|
|
|
CdioList_t* p_entlist;
|
2014-11-20 23:00:59 +00:00
|
|
|
size_t i, j;
|
2012-01-31 01:40:22 +00:00
|
|
|
lsn_t lsn;
|
|
|
|
int64_t i_file_length;
|
|
|
|
|
|
|
|
if ((p_iso == NULL) || (psz_path == NULL))
|
|
|
|
return 1;
|
|
|
|
|
2013-01-09 21:54:28 +00:00
|
|
|
i_length = _snprintf(psz_fullpath, sizeof(psz_fullpath), "%s%s/", psz_extract_dir, psz_path);
|
2012-01-31 01:40:22 +00:00
|
|
|
if (i_length < 0)
|
|
|
|
return 1;
|
|
|
|
psz_basename = &psz_fullpath[i_length];
|
|
|
|
|
|
|
|
p_entlist = iso9660_ifs_readdir(p_iso, psz_path);
|
2012-02-16 20:44:16 +00:00
|
|
|
if (!p_entlist) {
|
|
|
|
uprintf("Could not access directory %s\n", psz_path);
|
2012-01-31 01:40:22 +00:00
|
|
|
return 1;
|
2012-02-16 20:44:16 +00:00
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
|
2012-02-15 21:55:41 +00:00
|
|
|
_CDIO_LIST_FOREACH(p_entnode, p_entlist) {
|
2012-02-01 14:26:36 +00:00
|
|
|
if (FormatStatus) goto out;
|
2012-01-31 01:40:22 +00:00
|
|
|
p_statbuf = (iso9660_stat_t*) _cdio_list_node_data(p_entnode);
|
2013-01-13 00:41:21 +00:00
|
|
|
// Eliminate . and .. entries
|
2012-01-31 01:40:22 +00:00
|
|
|
if ( (strcmp(p_statbuf->filename, ".") == 0)
|
|
|
|
|| (strcmp(p_statbuf->filename, "..") == 0) )
|
|
|
|
continue;
|
2013-10-13 23:02:32 +00:00
|
|
|
// Rock Ridge requires an exception
|
2014-02-13 21:25:34 +00:00
|
|
|
is_symlink = FALSE;
|
2013-10-13 23:02:32 +00:00
|
|
|
if ((p_statbuf->rr.b3_rock == yep) && enable_rockridge) {
|
2013-01-13 00:41:21 +00:00
|
|
|
safe_strcpy(psz_basename, sizeof(psz_fullpath)-i_length-1, p_statbuf->filename);
|
2013-10-13 23:02:32 +00:00
|
|
|
if (safe_strlen(p_statbuf->filename) > 64)
|
|
|
|
iso_report.has_long_filename = TRUE;
|
2014-02-13 21:25:34 +00:00
|
|
|
// libcdio has a memleak for Rock Ridge symlinks. It doesn't look like there's an easy fix there as
|
|
|
|
// a generic list that's unaware of RR extensions is being used, so we prevent that memleak ourselves
|
|
|
|
is_symlink = (p_statbuf->rr.psz_symlink != NULL);
|
|
|
|
if (is_symlink)
|
|
|
|
iso_report.has_symlinks = TRUE;
|
|
|
|
if (scan_only)
|
|
|
|
safe_free(p_statbuf->rr.psz_symlink);
|
2013-10-13 23:02:32 +00:00
|
|
|
} else {
|
|
|
|
iso9660_name_translate_ext(p_statbuf->filename, psz_basename, i_joliet_level);
|
2013-01-13 00:41:21 +00:00
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
if (p_statbuf->type == _STAT_DIR) {
|
2014-11-20 23:00:59 +00:00
|
|
|
if (!scan_only) {
|
|
|
|
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
|
|
|
|
IGNORE_RETVAL(_mkdirU(psz_sanpath));
|
|
|
|
safe_free(psz_sanpath);
|
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
if (iso_extract_files(p_iso, psz_iso_name))
|
|
|
|
goto out;
|
|
|
|
} else {
|
2012-02-01 14:26:36 +00:00
|
|
|
i_file_length = p_statbuf->size;
|
2014-12-16 23:24:06 +00:00
|
|
|
if (check_iso_props(psz_path, i_file_length, psz_basename, psz_fullpath, &props)) {
|
2012-02-01 14:26:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-20 23:00:59 +00:00
|
|
|
print_extracted_file(psz_fullpath, i_file_length);
|
2012-12-15 03:27:14 +00:00
|
|
|
for (i=0; i<NB_OLD_C32; i++) {
|
2014-12-16 23:24:06 +00:00
|
|
|
if (props.is_old_c32[i] && use_own_c32[i]) {
|
2014-02-04 20:01:28 +00:00
|
|
|
static_sprintf(tmp, "%s/syslinux-%s/%s", FILES_DIR, embedded_sl_version_str[0], old_c32_name[i]);
|
|
|
|
if (CopyFileA(tmp, psz_fullpath, FALSE)) {
|
2012-12-15 03:27:14 +00:00
|
|
|
uprintf(" Replaced with local version\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uprintf(" Could not replace file: %s\n", WindowsErrorString());
|
2012-03-11 01:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-15 03:27:14 +00:00
|
|
|
if (i < NB_OLD_C32)
|
|
|
|
continue;
|
2014-11-20 23:00:59 +00:00
|
|
|
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
|
|
|
|
if (!is_identical)
|
|
|
|
uprintf(" File name sanitized to '%s'\n", psz_sanpath);
|
2014-02-13 21:25:34 +00:00
|
|
|
if (is_symlink) {
|
|
|
|
if (i_file_length == 0)
|
|
|
|
uprintf(" Ignoring Rock Ridge symbolic link to '%s'\n", p_statbuf->rr.psz_symlink);
|
|
|
|
safe_free(p_statbuf->rr.psz_symlink);
|
|
|
|
}
|
2014-11-20 23:00:59 +00:00
|
|
|
file_handle = CreateFileU(psz_sanpath, GENERIC_READ | GENERIC_WRITE,
|
2012-02-07 02:05:58 +00:00
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE) {
|
2013-11-17 22:24:50 +00:00
|
|
|
err = GetLastError();
|
2012-02-07 02:05:58 +00:00
|
|
|
uprintf(" Unable to create file: %s\n", WindowsErrorString());
|
2014-11-20 23:00:59 +00:00
|
|
|
if ((err == ERROR_ACCESS_DENIED) && (safe_strcmp(&psz_sanpath[3], autorun_name) == 0))
|
2014-02-09 23:38:16 +00:00
|
|
|
uprintf(stupid_antivirus);
|
|
|
|
else
|
|
|
|
goto out;
|
|
|
|
} else for (i=0; i_file_length>0; i++) {
|
2012-02-01 14:26:36 +00:00
|
|
|
if (FormatStatus) goto out;
|
2012-01-31 01:40:22 +00:00
|
|
|
memset(buf, 0, ISO_BLOCKSIZE);
|
|
|
|
lsn = p_statbuf->lsn + (lsn_t)i;
|
|
|
|
if (iso9660_iso_seek_read(p_iso, buf, lsn, 1) != ISO_BLOCKSIZE) {
|
|
|
|
uprintf(" Error reading ISO9660 file %s at LSN %lu\n",
|
|
|
|
psz_iso_name, (long unsigned int)lsn);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-02-07 02:05:58 +00:00
|
|
|
buf_size = (DWORD)MIN(i_file_length, ISO_BLOCKSIZE);
|
2013-12-06 23:31:41 +00:00
|
|
|
for (j=0; j<WRITE_RETRIES; j++) {
|
|
|
|
ISO_BLOCKING(s = WriteFile(file_handle, buf, buf_size, &wr_size, NULL));
|
|
|
|
if ((!s) || (buf_size != wr_size)) {
|
|
|
|
uprintf(" Error writing file: %s", WindowsErrorString());
|
|
|
|
if (j < WRITE_RETRIES-1)
|
|
|
|
uprintf(" RETRYING...\n");
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
2013-12-06 23:31:41 +00:00
|
|
|
if (j >= WRITE_RETRIES) goto out;
|
2012-01-31 01:40:22 +00:00
|
|
|
i_file_length -= ISO_BLOCKSIZE;
|
2015-01-01 23:39:28 +00:00
|
|
|
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
|
2012-03-29 19:27:53 +00:00
|
|
|
UpdateProgress(OP_DOS, 100.0f*nb_blocks/total_blocks);
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
2012-02-07 16:17:14 +00:00
|
|
|
ISO_BLOCKING(safe_closehandle(file_handle));
|
2014-12-16 23:24:06 +00:00
|
|
|
if (props.is_syslinux_cfg || props.is_grub_cfg)
|
|
|
|
fix_config(psz_sanpath, psz_path, psz_basename, &props);
|
2014-11-20 23:00:59 +00:00
|
|
|
safe_free(psz_sanpath);
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
r = 0;
|
|
|
|
|
|
|
|
out:
|
2012-02-07 16:17:14 +00:00
|
|
|
ISO_BLOCKING(safe_closehandle(file_handle));
|
2012-01-31 01:40:22 +00:00
|
|
|
_cdio_list_free(p_entlist, true);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-12-30 19:46:13 +00:00
|
|
|
void GetGrubVersion(char* buf, size_t buf_size)
|
|
|
|
{
|
|
|
|
char *p, unauthorized[] = {'<', '>', ':', '|', '*', '?', '\\', '/'};
|
|
|
|
size_t i;
|
|
|
|
const char grub_version_str[] = "GRUB version %s";
|
|
|
|
|
|
|
|
for (i=0; i<buf_size; i++) {
|
|
|
|
if (memcmp(&buf[i], grub_version_str, sizeof(grub_version_str)) == 0) {
|
|
|
|
safe_strcpy(iso_report.grub2_version, sizeof(iso_report.grub2_version), &buf[i + sizeof(grub_version_str)]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Sanitize the string
|
|
|
|
for (p = &iso_report.grub2_version[0]; *p; p++) {
|
|
|
|
for (i=0; i<sizeof(unauthorized); i++) {
|
|
|
|
if (*p == unauthorized[i])
|
|
|
|
*p = '_';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-04 01:33:54 +00:00
|
|
|
BOOL ExtractISO(const char* src_iso, const char* dest_dir, BOOL scan)
|
2012-01-31 01:40:22 +00:00
|
|
|
{
|
2014-08-05 23:57:32 +00:00
|
|
|
size_t i, size;
|
2012-05-30 23:49:28 +00:00
|
|
|
int j;
|
2014-01-21 17:08:41 +00:00
|
|
|
uint16_t sl_version;
|
2012-02-21 00:08:31 +00:00
|
|
|
FILE* fd;
|
2014-02-09 02:54:07 +00:00
|
|
|
int r = 1;
|
2012-01-31 01:40:22 +00:00
|
|
|
iso9660_t* p_iso = NULL;
|
|
|
|
udf_t* p_udf = NULL;
|
|
|
|
udf_dirent_t* p_udf_root;
|
2014-08-05 23:57:32 +00:00
|
|
|
char *tmp, *buf, *ext;
|
2014-01-21 17:08:41 +00:00
|
|
|
char path[MAX_PATH];
|
2012-03-27 19:31:15 +00:00
|
|
|
const char* basedir[] = { "i386", "minint" };
|
|
|
|
const char* tmp_sif = ".\\txtsetup.sif~";
|
2013-10-13 23:02:32 +00:00
|
|
|
iso_extension_mask_t iso_extension_mask = ISO_EXTENSION_ALL;
|
2012-02-01 14:26:36 +00:00
|
|
|
|
2014-04-13 14:20:20 +00:00
|
|
|
if ((!enable_iso) || (src_iso == NULL) || (dest_dir == NULL))
|
2012-02-01 14:26:36 +00:00
|
|
|
return FALSE;
|
2012-01-31 01:40:22 +00:00
|
|
|
|
2012-02-01 14:26:36 +00:00
|
|
|
scan_only = scan;
|
2012-02-14 20:52:39 +00:00
|
|
|
cdio_log_set_handler(log_handler);
|
2012-02-01 14:26:36 +00:00
|
|
|
psz_extract_dir = dest_dir;
|
2015-01-01 23:39:28 +00:00
|
|
|
// Change progress style to marquee for scanning
|
2012-02-01 14:26:36 +00:00
|
|
|
if (scan_only) {
|
2015-01-01 23:39:28 +00:00
|
|
|
SendMessage(hMainDialog, UM_PROGRESS_INIT, PBS_MARQUEE, 0);
|
2012-02-01 14:26:36 +00:00
|
|
|
total_blocks = 0;
|
2012-03-11 01:55:25 +00:00
|
|
|
memset(&iso_report, 0, sizeof(iso_report));
|
2014-01-21 17:08:41 +00:00
|
|
|
has_ldlinux_c32 = FALSE;
|
2012-02-21 00:08:31 +00:00
|
|
|
// String array of all isolinux/syslinux locations
|
|
|
|
StrArrayCreate(&config_path, 8);
|
2014-01-21 17:08:41 +00:00
|
|
|
StrArrayCreate(&isolinux_path, 8);
|
2015-01-01 23:39:28 +00:00
|
|
|
PrintInfo(0, MSG_202);
|
2012-02-01 14:26:36 +00:00
|
|
|
} else {
|
|
|
|
uprintf("Extracting files...\n");
|
2014-02-04 20:01:28 +00:00
|
|
|
IGNORE_RETVAL(_chdirU(app_dir));
|
2015-01-01 23:39:28 +00:00
|
|
|
PrintInfo(0, MSG_231);
|
2012-02-01 14:26:36 +00:00
|
|
|
if (total_blocks == 0) {
|
|
|
|
uprintf("Error: ISO has not been properly scanned.\n");
|
|
|
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_ISO_SCAN);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
nb_blocks = 0;
|
2012-02-07 16:17:14 +00:00
|
|
|
iso_blocking_status = 0;
|
2012-02-01 14:26:36 +00:00
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
|
|
|
|
/* First try to open as UDF - fallback to ISO if it failed */
|
|
|
|
p_udf = udf_open(src_iso);
|
|
|
|
if (p_udf == NULL)
|
|
|
|
goto try_iso;
|
2012-02-07 02:05:58 +00:00
|
|
|
uprintf("Disc image is an UDF image\n");
|
2012-01-31 01:40:22 +00:00
|
|
|
|
|
|
|
p_udf_root = udf_get_root(p_udf, true, 0);
|
|
|
|
if (p_udf_root == NULL) {
|
2015-01-01 23:39:28 +00:00
|
|
|
uprintf("Could not locate UDF root directory\n");
|
2012-01-31 01:40:22 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2012-02-14 20:52:39 +00:00
|
|
|
if (scan_only) {
|
|
|
|
if (udf_get_logical_volume_id(p_udf, iso_report.label, sizeof(iso_report.label)) <= 0)
|
|
|
|
iso_report.label[0] = 0;
|
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
r = udf_extract_files(p_udf, p_udf_root, "");
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
try_iso:
|
2013-10-13 23:02:32 +00:00
|
|
|
// Perform our first scan with Joliet disabled (if Rock Ridge is enabled), so that we can find if
|
2014-02-13 21:25:34 +00:00
|
|
|
// there exists a Rock Ridge file with a name > 64 chars or if there are symlinks. If that is the
|
|
|
|
// case then we also disable Joliet during the extract phase.
|
|
|
|
if ((!enable_joliet) || (enable_rockridge && (scan_only || iso_report.has_long_filename || iso_report.has_symlinks))) {
|
2013-10-13 23:02:32 +00:00
|
|
|
iso_extension_mask &= ~ISO_EXTENSION_JOLIET;
|
|
|
|
}
|
|
|
|
if (!enable_rockridge) {
|
|
|
|
iso_extension_mask &= ~ISO_EXTENSION_ROCK_RIDGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_iso = iso9660_open_ext(src_iso, iso_extension_mask);
|
2012-01-31 01:40:22 +00:00
|
|
|
if (p_iso == NULL) {
|
2015-02-11 23:22:18 +00:00
|
|
|
uprintf("'%s' doesn't look like an ISO image\n", src_iso);
|
2014-02-09 02:54:07 +00:00
|
|
|
r = 1;
|
2012-01-31 01:40:22 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2012-02-16 23:40:31 +00:00
|
|
|
uprintf("Disc image is an ISO9660 image\n");
|
2013-01-13 00:41:21 +00:00
|
|
|
i_joliet_level = iso9660_ifs_get_joliet_level(p_iso);
|
2012-02-14 20:52:39 +00:00
|
|
|
if (scan_only) {
|
2012-03-27 19:31:15 +00:00
|
|
|
if (iso9660_ifs_get_volume_id(p_iso, &tmp)) {
|
|
|
|
safe_strcpy(iso_report.label, sizeof(iso_report.label), tmp);
|
|
|
|
safe_free(tmp);
|
2012-02-16 20:44:16 +00:00
|
|
|
} else
|
2012-02-14 20:52:39 +00:00
|
|
|
iso_report.label[0] = 0;
|
2014-02-13 21:25:34 +00:00
|
|
|
} else {
|
|
|
|
if (iso_extension_mask & (ISO_EXTENSION_JOLIET|ISO_EXTENSION_ROCK_RIDGE))
|
|
|
|
uprintf("This image will be extracted using %s extensions (if present)",
|
|
|
|
(iso_extension_mask & ISO_EXTENSION_JOLIET)?"Joliet":"Rock Ridge");
|
|
|
|
else
|
|
|
|
uprintf("This image will not be extracted using any ISO extensions");
|
2012-02-14 20:52:39 +00:00
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
r = iso_extract_files(p_iso, "");
|
|
|
|
|
|
|
|
out:
|
2012-02-07 16:17:14 +00:00
|
|
|
iso_blocking_status = -1;
|
2012-02-01 14:26:36 +00:00
|
|
|
if (scan_only) {
|
2012-05-30 23:49:28 +00:00
|
|
|
// Remove trailing spaces from the label
|
2013-10-15 21:58:27 +00:00
|
|
|
for (j=(int)safe_strlen(iso_report.label)-1; ((j>=0)&&(isspaceU(iso_report.label[j]))); j--)
|
2012-05-30 23:49:28 +00:00
|
|
|
iso_report.label[j] = 0;
|
2012-02-01 14:26:36 +00:00
|
|
|
// We use the fact that UDF_BLOCKSIZE and ISO_BLOCKSIZE are the same here
|
|
|
|
iso_report.projected_size = total_blocks * ISO_BLOCKSIZE;
|
2012-02-21 00:08:31 +00:00
|
|
|
// We will link the existing isolinux.cfg from a syslinux.cfg we create
|
2014-01-21 17:08:41 +00:00
|
|
|
// If multiple config files exist, choose the one with the shortest path
|
|
|
|
// (so that a '/syslinux.cfg' is preferred over a '/isolinux/isolinux.cfg')
|
|
|
|
if (!IsStrArrayEmpty(config_path)) {
|
2014-01-22 01:28:25 +00:00
|
|
|
safe_strcpy(iso_report.cfg_path, sizeof(iso_report.cfg_path), config_path.String[0]);
|
2012-02-21 00:08:31 +00:00
|
|
|
for (i=1; i<config_path.Index; i++) {
|
2014-08-05 23:57:32 +00:00
|
|
|
// Tails uses an '/EFI/BOOT/isolinux.cfg' along with a '/isolinux/isolinux.cfg'
|
|
|
|
// which are the exact same length. However, only the /isolinux one will work,
|
|
|
|
// so for now, at equal length, always pick the latest.
|
|
|
|
// We may have to revisit this and prefer a path that contains '/isolinux' if
|
|
|
|
// this hack is not enough for other images.
|
|
|
|
if (safe_strlen(iso_report.cfg_path) >= safe_strlen(config_path.String[i]))
|
2014-01-22 01:28:25 +00:00
|
|
|
safe_strcpy(iso_report.cfg_path, sizeof(iso_report.cfg_path), config_path.String[i]);
|
2012-02-21 00:08:31 +00:00
|
|
|
}
|
|
|
|
uprintf("Will use %s for Syslinux\n", iso_report.cfg_path);
|
2014-01-21 17:08:41 +00:00
|
|
|
// Extract all of the isolinux.bin files we found to identify their versions
|
|
|
|
for (i=0; i<isolinux_path.Index; i++) {
|
2014-05-15 20:17:12 +00:00
|
|
|
size = (size_t)ExtractISOFile(src_iso, isolinux_path.String[i], dot_isolinux_bin, FILE_ATTRIBUTE_NORMAL);
|
2014-01-21 17:08:41 +00:00
|
|
|
if (size == 0) {
|
2014-01-22 01:28:25 +00:00
|
|
|
uprintf("Could not access %s\n", isolinux_path.String[i]);
|
2014-01-21 17:08:41 +00:00
|
|
|
} else {
|
|
|
|
buf = (char*)calloc(size, 1);
|
|
|
|
if (buf == NULL) break;
|
|
|
|
fd = fopen(dot_isolinux_bin, "rb");
|
|
|
|
if (fd == NULL) {
|
|
|
|
free(buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fread(buf, 1, size, fd);
|
|
|
|
fclose(fd);
|
2014-08-05 23:57:32 +00:00
|
|
|
sl_version = GetSyslinuxVersion(buf, size, &ext);
|
|
|
|
if (iso_report.sl_version == 0) {
|
|
|
|
safe_strcpy(iso_report.sl_version_ext, sizeof(iso_report.sl_version_ext), ext);
|
|
|
|
iso_report.sl_version = sl_version;
|
|
|
|
j = (int)i;
|
|
|
|
} else if ((iso_report.sl_version != sl_version) || (safe_strcmp(iso_report.sl_version_ext, ext) != 0)) {
|
|
|
|
uprintf("Found conflicting %s versions:\n '%s' (%d.%02d%s) vs '%s' (%d.%02d%s)\n", isolinux_bin,
|
|
|
|
isolinux_path.String[j], SL_MAJOR(iso_report.sl_version), SL_MINOR(iso_report.sl_version),
|
|
|
|
iso_report.sl_version_ext, isolinux_path.String[i], SL_MAJOR(sl_version), SL_MINOR(sl_version), ext);
|
2014-01-21 17:08:41 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
_unlink(dot_isolinux_bin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (iso_report.sl_version != 0) {
|
2014-01-24 19:59:23 +00:00
|
|
|
static_sprintf(iso_report.sl_version_str, "%d.%02d",
|
2014-01-21 17:08:41 +00:00
|
|
|
SL_MAJOR(iso_report.sl_version), SL_MINOR(iso_report.sl_version));
|
2014-08-05 23:57:32 +00:00
|
|
|
uprintf("Detected Isolinux version: %s%s (from '%s')",
|
|
|
|
iso_report.sl_version_str, iso_report.sl_version_ext, isolinux_path.String[j]);
|
2014-01-21 17:08:41 +00:00
|
|
|
if ( (has_ldlinux_c32 && (SL_MAJOR(iso_report.sl_version) < 5))
|
|
|
|
|| (!has_ldlinux_c32 && (SL_MAJOR(iso_report.sl_version) >= 5)) )
|
|
|
|
uprintf("Warning: Conflict between Isolinux version and the presence of ldlinux.c32...\n");
|
|
|
|
} else {
|
|
|
|
// Couldn't find a version from isolinux.bin. Force set to the versions we embed
|
|
|
|
iso_report.sl_version = embedded_sl_version[has_ldlinux_c32?1:0];
|
2014-01-24 19:59:23 +00:00
|
|
|
static_sprintf(iso_report.sl_version_str, "%d.%02d",
|
2014-01-21 17:08:41 +00:00
|
|
|
SL_MAJOR(iso_report.sl_version), SL_MINOR(iso_report.sl_version));
|
|
|
|
uprintf("Warning: Could not detect Isolinux version - Forcing to %s (embedded)",
|
|
|
|
iso_report.sl_version_str);
|
|
|
|
}
|
2012-02-21 00:08:31 +00:00
|
|
|
}
|
2012-03-27 19:31:15 +00:00
|
|
|
if (IS_WINPE(iso_report.winpe)) {
|
|
|
|
// In case we have a WinPE 1.x based iso, we extract and parse txtsetup.sif
|
|
|
|
// during scan, to see if /minint was provided for OsLoadOptions, as it decides
|
|
|
|
// whether we should use 0x80 or 0x81 as the disk ID in the MBR
|
|
|
|
safe_sprintf(path, sizeof(path), "/%s/txtsetup.sif",
|
|
|
|
basedir[((iso_report.winpe&WINPE_I386) == WINPE_I386)?0:1]);
|
2014-05-15 20:17:12 +00:00
|
|
|
ExtractISOFile(src_iso, path, tmp_sif, FILE_ATTRIBUTE_NORMAL);
|
2012-11-12 01:53:34 +00:00
|
|
|
tmp = get_token_data_file("OsLoadOptions", tmp_sif);
|
2012-03-27 19:31:15 +00:00
|
|
|
if (tmp != NULL) {
|
|
|
|
for (i=0; i<strlen(tmp); i++)
|
|
|
|
tmp[i] = (char)tolower(tmp[i]);
|
|
|
|
uprintf("Checking txtsetup.sif:\n OsLoadOptions = %s\n", tmp);
|
|
|
|
iso_report.uses_minint = (strstr(tmp, "/minint") != NULL);
|
|
|
|
}
|
|
|
|
_unlink(tmp_sif);
|
|
|
|
safe_free(tmp);
|
|
|
|
}
|
2014-12-30 19:46:13 +00:00
|
|
|
if (iso_report.has_grub2) {
|
|
|
|
// In case we have a GRUB2 based iso, we extract boot/grub/i386-pc/normal.mod to parse its version
|
2015-01-08 00:22:56 +00:00
|
|
|
iso_report.grub2_version[0] = 0;
|
2014-12-30 19:46:13 +00:00
|
|
|
if ((GetTempPathU(sizeof(path), path) != 0) && (GetTempFileNameU(path, APPLICATION_NAME, 0, path) != 0)) {
|
|
|
|
size = (size_t)ExtractISOFile(src_iso, "boot/grub/i386-pc/normal.mod", path, FILE_ATTRIBUTE_NORMAL);
|
|
|
|
buf = (char*)calloc(size, 1);
|
|
|
|
fd = fopen(path, "rb");
|
|
|
|
if ((size == 0) || (buf == NULL) || (fd == NULL)) {
|
|
|
|
uprintf("Could not read Grub version from 'boot/grub/i386-pc/normal.mod'");
|
|
|
|
} else {
|
|
|
|
fread(buf, 1, size, fd);
|
|
|
|
fclose(fd);
|
|
|
|
GetGrubVersion(buf, size);
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
_unlink(path);
|
|
|
|
}
|
2015-01-08 00:22:56 +00:00
|
|
|
if (iso_report.grub2_version[0] != 0)
|
|
|
|
uprintf("Detected Grub version: %s", iso_report.grub2_version);
|
|
|
|
else
|
|
|
|
uprintf("Could not detect Grub2 version");
|
2014-12-30 19:46:13 +00:00
|
|
|
}
|
2012-02-21 00:08:31 +00:00
|
|
|
StrArrayDestroy(&config_path);
|
2014-01-21 17:08:41 +00:00
|
|
|
StrArrayDestroy(&isolinux_path);
|
2015-01-01 23:39:28 +00:00
|
|
|
SendMessage(hMainDialog, UM_PROGRESS_EXIT, 0, 0);
|
2014-01-22 01:28:25 +00:00
|
|
|
} else if (HAS_SYSLINUX(iso_report)) {
|
2012-03-27 19:31:15 +00:00
|
|
|
safe_sprintf(path, sizeof(path), "%s\\syslinux.cfg", dest_dir);
|
2012-02-21 00:08:31 +00:00
|
|
|
// Create a /syslinux.cfg (if none exists) that points to the existing isolinux cfg
|
2012-03-27 19:31:15 +00:00
|
|
|
fd = fopen(path, "r");
|
2012-02-21 00:08:31 +00:00
|
|
|
if (fd == NULL) {
|
2012-03-27 19:31:15 +00:00
|
|
|
fd = fopen(path, "w"); // No "/syslinux.cfg" => create a new one
|
2012-02-21 00:08:31 +00:00
|
|
|
if (fd == NULL) {
|
2012-03-27 19:31:15 +00:00
|
|
|
uprintf("Unable to create %s - booting from USB will not work\n", path);
|
2012-02-21 00:08:31 +00:00
|
|
|
r = 1;
|
|
|
|
} else {
|
|
|
|
fprintf(fd, "DEFAULT loadconfig\n\nLABEL loadconfig\n CONFIG %s\n", iso_report.cfg_path);
|
|
|
|
for (i=safe_strlen(iso_report.cfg_path); (i>0)&&(iso_report.cfg_path[i]!='/'); i--);
|
|
|
|
if (i>0) {
|
|
|
|
iso_report.cfg_path[i] = 0;
|
|
|
|
fprintf(fd, " APPEND %s/\n", iso_report.cfg_path);
|
|
|
|
iso_report.cfg_path[i] = '/';
|
|
|
|
}
|
2012-03-27 19:31:15 +00:00
|
|
|
uprintf("Created: %s\n", path);
|
2012-02-21 00:08:31 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-01 19:19:12 +00:00
|
|
|
if (fd != NULL)
|
|
|
|
fclose(fd);
|
2012-02-01 14:26:36 +00:00
|
|
|
}
|
2012-01-31 01:40:22 +00:00
|
|
|
if (p_iso != NULL)
|
|
|
|
iso9660_close(p_iso);
|
|
|
|
if (p_udf != NULL)
|
|
|
|
udf_close(p_udf);
|
2012-02-01 14:26:36 +00:00
|
|
|
if ((r != 0) && (FormatStatus == 0))
|
2012-02-07 02:05:58 +00:00
|
|
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR((scan_only?ERROR_ISO_SCAN:ERROR_ISO_EXTRACT));
|
|
|
|
return (r == 0);
|
2012-01-31 01:40:22 +00:00
|
|
|
}
|
2012-03-27 19:31:15 +00:00
|
|
|
|
2014-05-15 20:17:12 +00:00
|
|
|
int64_t ExtractISOFile(const char* iso, const char* iso_file, const char* dest_file, DWORD attributes)
|
2012-03-27 19:31:15 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2012-03-27 22:31:58 +00:00
|
|
|
ssize_t read_size;
|
2014-01-14 20:17:07 +00:00
|
|
|
int64_t file_length, r = 0;
|
2012-03-27 19:31:15 +00:00
|
|
|
char buf[UDF_BLOCKSIZE];
|
|
|
|
DWORD buf_size, wr_size;
|
2014-01-14 20:17:07 +00:00
|
|
|
BOOL s;
|
2012-03-27 19:31:15 +00:00
|
|
|
iso9660_t* p_iso = NULL;
|
|
|
|
udf_t* p_udf = NULL;
|
|
|
|
udf_dirent_t *p_udf_root = NULL, *p_udf_file = NULL;
|
|
|
|
iso9660_stat_t *p_statbuf = NULL;
|
|
|
|
lsn_t lsn;
|
|
|
|
HANDLE file_handle = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
file_handle = CreateFileU(dest_file, GENERIC_READ | GENERIC_WRITE,
|
2014-05-15 20:17:12 +00:00
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, attributes, NULL);
|
2012-03-27 19:31:15 +00:00
|
|
|
if (file_handle == INVALID_HANDLE_VALUE) {
|
|
|
|
uprintf(" Unable to create file %s: %s\n", dest_file, WindowsErrorString());
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First try to open as UDF - fallback to ISO if it failed */
|
|
|
|
p_udf = udf_open(iso);
|
|
|
|
if (p_udf == NULL)
|
|
|
|
goto try_iso;
|
|
|
|
|
|
|
|
p_udf_root = udf_get_root(p_udf, true, 0);
|
|
|
|
if (p_udf_root == NULL) {
|
2015-01-01 23:39:28 +00:00
|
|
|
uprintf("Could not locate UDF root directory\n");
|
2012-03-27 19:31:15 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
p_udf_file = udf_fopen(p_udf_root, iso_file);
|
|
|
|
if (!p_udf_file) {
|
2015-01-01 23:39:28 +00:00
|
|
|
uprintf("Could not locate file %s in ISO image\n", iso_file);
|
2012-03-27 19:31:15 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
file_length = udf_get_file_length(p_udf_file);
|
|
|
|
while (file_length > 0) {
|
|
|
|
memset(buf, 0, UDF_BLOCKSIZE);
|
2012-03-27 22:31:58 +00:00
|
|
|
read_size = udf_read_block(p_udf_file, buf, 1);
|
|
|
|
if (read_size < 0) {
|
2012-03-27 19:31:15 +00:00
|
|
|
uprintf("Error reading UDF file %s\n", iso_file);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-03-27 22:31:58 +00:00
|
|
|
buf_size = (DWORD)MIN(file_length, read_size);
|
2012-03-27 19:31:15 +00:00
|
|
|
s = WriteFile(file_handle, buf, buf_size, &wr_size, NULL);
|
|
|
|
if ((!s) || (buf_size != wr_size)) {
|
|
|
|
uprintf(" Error writing file %s: %s\n", dest_file, WindowsErrorString());
|
|
|
|
goto out;
|
|
|
|
}
|
2012-03-27 22:31:58 +00:00
|
|
|
file_length -= read_size;
|
2014-01-21 17:08:41 +00:00
|
|
|
r += read_size;
|
2012-03-27 19:31:15 +00:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
try_iso:
|
|
|
|
p_iso = iso9660_open(iso);
|
|
|
|
if (p_iso == NULL) {
|
|
|
|
uprintf("Unable to open image '%s'.\n", iso);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_statbuf = iso9660_ifs_stat_translate(p_iso, iso_file);
|
|
|
|
if (p_statbuf == NULL) {
|
|
|
|
uprintf("Could not get ISO-9660 file information for file %s\n", iso_file);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_length = p_statbuf->size;
|
|
|
|
for (i = 0; file_length > 0; i++) {
|
|
|
|
memset(buf, 0, ISO_BLOCKSIZE);
|
|
|
|
lsn = p_statbuf->lsn + (lsn_t)i;
|
|
|
|
if (iso9660_iso_seek_read(p_iso, buf, lsn, 1) != ISO_BLOCKSIZE) {
|
|
|
|
uprintf(" Error reading ISO9660 file %s at LSN %lu\n", iso_file, (long unsigned int)lsn);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
buf_size = (DWORD)MIN(file_length, ISO_BLOCKSIZE);
|
|
|
|
s = WriteFile(file_handle, buf, buf_size, &wr_size, NULL);
|
|
|
|
if ((!s) || (buf_size != wr_size)) {
|
|
|
|
uprintf(" Error writing file %s: %s\n", dest_file, WindowsErrorString());
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
file_length -= ISO_BLOCKSIZE;
|
2014-01-21 17:08:41 +00:00
|
|
|
r += ISO_BLOCKSIZE;
|
2012-03-27 19:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
safe_closehandle(file_handle);
|
2012-03-27 22:31:58 +00:00
|
|
|
if (p_statbuf != NULL)
|
|
|
|
safe_free(p_statbuf->rr.psz_symlink);
|
2012-03-27 19:31:15 +00:00
|
|
|
safe_free(p_statbuf);
|
|
|
|
if (p_udf_root != NULL)
|
|
|
|
udf_dirent_free(p_udf_root);
|
|
|
|
if (p_udf_file != NULL)
|
|
|
|
udf_dirent_free(p_udf_file);
|
|
|
|
if (p_iso != NULL)
|
|
|
|
iso9660_close(p_iso);
|
|
|
|
if (p_udf != NULL)
|
|
|
|
udf_close(p_udf);
|
2014-01-21 17:08:41 +00:00
|
|
|
return r;
|
2012-03-27 19:31:15 +00:00
|
|
|
}
|
2015-01-14 00:51:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The following is used for native ISO mounting in Windows 8 or later
|
|
|
|
*/
|
2015-01-16 01:51:24 +00:00
|
|
|
#define VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT \
|
|
|
|
{ 0xEC984AECL, 0xA0F9, 0x47e9, { 0x90, 0x1F, 0x71, 0x41, 0x5A, 0x66, 0x34, 0x5B } }
|
2015-01-14 00:51:41 +00:00
|
|
|
|
|
|
|
typedef enum _VIRTUAL_DISK_ACCESS_MASK {
|
|
|
|
VIRTUAL_DISK_ACCESS_NONE = 0x00000000,
|
|
|
|
VIRTUAL_DISK_ACCESS_ATTACH_RO = 0x00010000,
|
|
|
|
VIRTUAL_DISK_ACCESS_ATTACH_RW = 0x00020000,
|
|
|
|
VIRTUAL_DISK_ACCESS_DETACH = 0x00040000,
|
|
|
|
VIRTUAL_DISK_ACCESS_GET_INFO = 0x00080000,
|
|
|
|
VIRTUAL_DISK_ACCESS_CREATE = 0x00100000,
|
|
|
|
VIRTUAL_DISK_ACCESS_METAOPS = 0x00200000,
|
|
|
|
VIRTUAL_DISK_ACCESS_READ = 0x000d0000,
|
|
|
|
VIRTUAL_DISK_ACCESS_ALL = 0x003f0000,
|
|
|
|
VIRTUAL_DISK_ACCESS_WRITABLE = 0x00320000
|
|
|
|
} VIRTUAL_DISK_ACCESS_MASK;
|
|
|
|
|
|
|
|
typedef enum _OPEN_VIRTUAL_DISK_FLAG {
|
|
|
|
OPEN_VIRTUAL_DISK_FLAG_NONE = 0x00000000,
|
|
|
|
OPEN_VIRTUAL_DISK_FLAG_NO_PARENTS = 0x00000001,
|
|
|
|
OPEN_VIRTUAL_DISK_FLAG_BLANK_FILE = 0x00000002,
|
|
|
|
OPEN_VIRTUAL_DISK_FLAG_BOOT_DRIVE = 0x00000004,
|
|
|
|
OPEN_VIRTUAL_DISK_FLAG_CACHED_IO = 0x00000008,
|
|
|
|
OPEN_VIRTUAL_DISK_FLAG_CUSTOM_DIFF_CHAIN = 0x00000010
|
|
|
|
} OPEN_VIRTUAL_DISK_FLAG;
|
|
|
|
|
|
|
|
typedef enum _OPEN_VIRTUAL_DISK_VERSION {
|
|
|
|
OPEN_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0,
|
|
|
|
OPEN_VIRTUAL_DISK_VERSION_1 = 1,
|
|
|
|
OPEN_VIRTUAL_DISK_VERSION_2 = 2
|
|
|
|
} OPEN_VIRTUAL_DISK_VERSION;
|
|
|
|
|
|
|
|
typedef enum _ATTACH_VIRTUAL_DISK_FLAG {
|
|
|
|
ATTACH_VIRTUAL_DISK_FLAG_NONE = 0x00000000,
|
|
|
|
ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY = 0x00000001,
|
|
|
|
ATTACH_VIRTUAL_DISK_FLAG_NO_DRIVE_LETTER = 0x00000002,
|
|
|
|
ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME = 0x00000004,
|
|
|
|
ATTACH_VIRTUAL_DISK_FLAG_NO_LOCAL_HOST = 0x00000008
|
|
|
|
} ATTACH_VIRTUAL_DISK_FLAG;
|
|
|
|
|
|
|
|
typedef enum _ATTACH_VIRTUAL_DISK_VERSION {
|
|
|
|
ATTACH_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0,
|
|
|
|
ATTACH_VIRTUAL_DISK_VERSION_1 = 1
|
|
|
|
} ATTACH_VIRTUAL_DISK_VERSION;
|
|
|
|
|
|
|
|
typedef enum _DETACH_VIRTUAL_DISK_FLAG {
|
|
|
|
DETACH_VIRTUAL_DISK_FLAG_NONE = 0x00000000
|
|
|
|
} DETACH_VIRTUAL_DISK_FLAG;
|
|
|
|
|
2015-01-23 02:26:41 +00:00
|
|
|
#ifndef _VIRTUAL_STORAGE_TYPE_DEFINED
|
|
|
|
#define _VIRTUAL_STORAGE_TYPE_DEFINED
|
2015-01-14 00:51:41 +00:00
|
|
|
typedef struct _VIRTUAL_STORAGE_TYPE {
|
|
|
|
ULONG DeviceId;
|
|
|
|
GUID VendorId;
|
|
|
|
} VIRTUAL_STORAGE_TYPE, *PVIRTUAL_STORAGE_TYPE;
|
2015-01-23 02:26:41 +00:00
|
|
|
#endif
|
2015-01-14 00:51:41 +00:00
|
|
|
|
|
|
|
typedef struct _OPEN_VIRTUAL_DISK_PARAMETERS {
|
|
|
|
OPEN_VIRTUAL_DISK_VERSION Version;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
ULONG RWDepth;
|
|
|
|
} Version1;
|
|
|
|
struct {
|
|
|
|
BOOL GetInfoOnly;
|
|
|
|
BOOL ReadOnly;
|
|
|
|
GUID ResiliencyGuid;
|
|
|
|
} Version2;
|
|
|
|
};
|
|
|
|
} OPEN_VIRTUAL_DISK_PARAMETERS, *POPEN_VIRTUAL_DISK_PARAMETERS;
|
|
|
|
|
|
|
|
typedef struct _ATTACH_VIRTUAL_DISK_PARAMETERS {
|
|
|
|
ATTACH_VIRTUAL_DISK_VERSION Version;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
ULONG Reserved;
|
|
|
|
} Version1;
|
|
|
|
};
|
|
|
|
} ATTACH_VIRTUAL_DISK_PARAMETERS, *PATTACH_VIRTUAL_DISK_PARAMETERS;
|
|
|
|
|
|
|
|
// VirtDisk API Prototypes - Only available for Windows 8 or later
|
|
|
|
PF_TYPE_DECL(WINAPI, DWORD, OpenVirtualDisk, (PVIRTUAL_STORAGE_TYPE, PCWSTR,
|
|
|
|
VIRTUAL_DISK_ACCESS_MASK, OPEN_VIRTUAL_DISK_FLAG, POPEN_VIRTUAL_DISK_PARAMETERS, PHANDLE));
|
|
|
|
PF_TYPE_DECL(WINAPI, DWORD, AttachVirtualDisk, (HANDLE, PSECURITY_DESCRIPTOR,
|
|
|
|
ATTACH_VIRTUAL_DISK_FLAG, ULONG, PATTACH_VIRTUAL_DISK_PARAMETERS, LPOVERLAPPED));
|
|
|
|
PF_TYPE_DECL(WINAPI, DWORD, DetachVirtualDisk, (HANDLE, DETACH_VIRTUAL_DISK_FLAG, ULONG));
|
|
|
|
PF_TYPE_DECL(WINAPI, DWORD, GetVirtualDiskPhysicalPath, (HANDLE, PULONG, PWSTR));
|
|
|
|
|
|
|
|
static char physical_path[128] = "";
|
|
|
|
static HANDLE mounted_handle = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
char* MountISO(const char* path)
|
|
|
|
{
|
|
|
|
VIRTUAL_STORAGE_TYPE vtype = { 1, VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT };
|
2015-01-16 01:51:24 +00:00
|
|
|
ATTACH_VIRTUAL_DISK_PARAMETERS vparams = {0};
|
2015-01-14 00:51:41 +00:00
|
|
|
DWORD r;
|
|
|
|
wchar_t wtmp[128];
|
|
|
|
ULONG size = ARRAYSIZE(wtmp);
|
|
|
|
wconvert(path);
|
|
|
|
char* ret = NULL;
|
|
|
|
|
|
|
|
PF_INIT_OR_OUT(OpenVirtualDisk, VirtDisk);
|
|
|
|
PF_INIT_OR_OUT(AttachVirtualDisk, VirtDisk);
|
|
|
|
PF_INIT_OR_OUT(GetVirtualDiskPhysicalPath, VirtDisk);
|
|
|
|
|
|
|
|
if ((mounted_handle != NULL) && (mounted_handle != INVALID_HANDLE_VALUE))
|
|
|
|
UnMountISO();
|
|
|
|
|
|
|
|
r = pfOpenVirtualDisk(&vtype, wpath, VIRTUAL_DISK_ACCESS_READ | VIRTUAL_DISK_ACCESS_GET_INFO,
|
|
|
|
OPEN_VIRTUAL_DISK_FLAG_NONE, NULL, &mounted_handle);
|
|
|
|
if (r != ERROR_SUCCESS) {
|
|
|
|
SetLastError(r);
|
|
|
|
uprintf("Could not open ISO '%s': %s", path, WindowsErrorString());
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-01-16 01:51:24 +00:00
|
|
|
vparams.Version = ATTACH_VIRTUAL_DISK_VERSION_1;
|
2015-01-14 00:51:41 +00:00
|
|
|
r = pfAttachVirtualDisk(mounted_handle, NULL, ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY |
|
|
|
|
ATTACH_VIRTUAL_DISK_FLAG_NO_DRIVE_LETTER, 0, &vparams, NULL);
|
|
|
|
if (r != ERROR_SUCCESS) {
|
|
|
|
SetLastError(r);
|
|
|
|
uprintf("Could not mount ISO '%s': %s", path, WindowsErrorString());
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = pfGetVirtualDiskPhysicalPath(mounted_handle, &size, wtmp);
|
|
|
|
if (r != ERROR_SUCCESS) {
|
|
|
|
SetLastError(r);
|
|
|
|
uprintf("Could not obtain physical path for mounted ISO '%s': %s", path, WindowsErrorString());
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
wchar_to_utf8_no_alloc(wtmp, physical_path, sizeof(physical_path));
|
|
|
|
ret = physical_path;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (ret == NULL)
|
|
|
|
UnMountISO();
|
|
|
|
wfree(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnMountISO(void)
|
|
|
|
{
|
|
|
|
PF_INIT_OR_OUT(DetachVirtualDisk, VirtDisk);
|
|
|
|
|
|
|
|
if ((mounted_handle == NULL) || (mounted_handle == INVALID_HANDLE_VALUE))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
pfDetachVirtualDisk(mounted_handle, DETACH_VIRTUAL_DISK_FLAG_NONE, 0);
|
|
|
|
safe_closehandle(mounted_handle);
|
|
|
|
out:
|
|
|
|
physical_path[0] = 0;
|
|
|
|
}
|