-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathiso.c
1768 lines (1652 loc) · 66.3 KB
/
iso.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Rufus: The Reliable USB Formatting Utility
* ISO file extraction
* Copyright © 2011-2023 Pete Batard <pete@akeo.ie>
* Based on libcdio's iso & udf samples:
* Copyright © 2003-2014 Rocky Bernstein <rocky@gnu.org>
*
* 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>
#include <ctype.h>
#include <assert.h>
#include <virtdisk.h>
#include <sys/stat.h>
#define DO_NOT_WANT_COMPATIBILITY
#include <cdio/cdio.h>
#include <cdio/logging.h>
#include <cdio/iso9660.h>
#include <cdio/udf.h>
#include "rufus.h"
#include "libfat.h"
#include "missing.h"
#include "resource.h"
#include "msapi_utf8.h"
#include "localization.h"
#include "bled/bled.h"
// 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
#define PROGRESS_THRESHOLD 128
#define FOUR_GIGABYTES 4294967296LL
// Needed for UDF symbolic link testing
#define S_IFLNK 0xA000
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
// Set the iso_open_ext() extension mask according to our global options
#define ISO_EXTENSION_MASK (ISO_EXTENSION_ALL & (enable_joliet ? ISO_EXTENSION_ALL : ~ISO_EXTENSION_JOLIET) & \
(enable_rockridge ? ISO_EXTENSION_ALL : ~ISO_EXTENSION_ROCK_RIDGE))
// Needed for UDF ISO access
CdIo_t* cdio_open (const char* psz_source, driver_id_t driver_id) {return NULL;}
void cdio_destroy (CdIo_t* p_cdio) {}
uint32_t GetInstallWimVersion(const char* iso);
typedef struct {
BOOLEAN is_cfg;
BOOLEAN is_conf;
BOOLEAN is_syslinux_cfg;
BOOLEAN is_grub_cfg;
BOOLEAN is_menu_cfg;
BOOLEAN is_old_c32[NB_OLD_C32];
} EXTRACT_PROPS;
RUFUS_IMG_REPORT img_report;
int64_t iso_blocking_status = -1;
extern BOOL preserve_timestamps, enable_ntfs_compression;
extern char* archive_path;
BOOL enable_iso = TRUE, enable_joliet = TRUE, enable_rockridge = TRUE, has_ldlinux_c32;
#define ISO_BLOCKING(x) do {x; iso_blocking_status++; } while(0)
static const char* psz_extract_dir;
static const char* bootmgr_name = "bootmgr";
const char* bootmgr_efi_name = "bootmgr.efi";
static const char* grldr_name = "grldr";
static const char* ldlinux_name = "ldlinux.sys";
static const char* ldlinux_c32 = "ldlinux.c32";
static const char* md5sum_name[] = { "MD5SUMS", "md5sum.txt" };
static const char* casper_dirname = "/casper";
static const char* proxmox_dirname = "/proxmox";
const char* efi_dirname = "/efi/boot";
const char* efi_bootname[ARCH_MAX] = {
"boot.efi", "bootia32.efi", "bootx64.efi", "bootarm.efi", "bootaa64.efi", "bootia64.efi",
"bootriscv32.efi", "bootriscv64.efi", "bootriscv128.efi", "bootebc.efi" };
static const char* sources_str = "/sources";
static const char* wininst_name[] = { "install.wim", "install.esd", "install.swm" };
// We only support GRUB/BIOS (x86) that uses a standard config dir (/boot/grub/i386-pc/)
// If the disc was mastered properly, GRUB/EFI will take care of itself
static const char* grub_dirname[] = { "/boot/grub/i386-pc", "/boot/grub2/i386-pc" };
static const char* grub_cfg[] = { "grub.cfg", "loopback.cfg" };
static const char* menu_cfg = "menu.cfg";
// NB: Do not alter the order of the array below without validating hardcoded indexes in check_iso_props
static const char* syslinux_cfg[] = { "isolinux.cfg", "syslinux.cfg", "extlinux.conf", "txt.cfg" };
static const char* isolinux_bin[] = { "isolinux.bin", "boot.bin" };
static const char* pe_dirname[] = { "/i386", "/amd64", "/minint" };
static const char* pe_file[] = { "ntdetect.com", "setupldr.bin", "txtsetup.sif" };
static const char* reactos_name = "setupldr.sys"; // TODO: freeldr.sys doesn't seem to work
static const char* kolibri_name = "kolibri.img";
static const char* autorun_name = "autorun.inf";
static const char* manjaro_marker = ".miso";
static const char* pop_os_name = "pop-os";
static const char* stupid_antivirus = " NOTE: This is usually caused by a poorly designed security solution. "
"See https://bit.ly/40qDtyF.\r\n This file will be skipped for now, but you should really "
"look into using a *SMARTER* antivirus solution.";
const char* old_c32_name[NB_OLD_C32] = OLD_C32_NAMES;
static const int64_t old_c32_threshold[NB_OLD_C32] = OLD_C32_THRESHOLD;
static uint8_t joliet_level = 0;
static uint64_t total_blocks, nb_blocks;
static BOOL scan_only = FALSE;
static StrArray config_path, isolinux_path, modified_path;
static char symlinked_syslinux[MAX_PATH];
// Ensure filenames do not contain invalid FAT32 or NTFS characters
static __inline char* sanitize_filename(char* filename, BOOL* is_identical)
{
size_t i, j;
char* ret = NULL;
char unauthorized[] = { '*', '?', '<', '>', ':', '|' };
*is_identical = TRUE;
ret = safe_strdup(filename);
if (ret == NULL) {
uprintf("Could not allocate string for sanitized path");
return NULL;
}
// Must start after the drive part (D:\...) so that we don't eliminate the first column
for (i=2; i<safe_strlen(ret); i++) {
for (j=0; j<sizeof(unauthorized); j++) {
if (ret[i] == unauthorized[j]) {
ret[i] = '_';
*is_identical = FALSE;
}
}
}
return ret;
}
static void log_handler (cdio_log_level_t level, const char *message)
{
uprintf("libcdio: %s", message);
}
/*
* Scan and set ISO properties
* Returns true if the the current file does not need to be processed further
*/
static BOOL check_iso_props(const char* psz_dirname, int64_t file_length, const char* psz_basename,
const char* psz_fullpath, EXTRACT_PROPS *props)
{
size_t i, j, len;
// Check for an isolinux/syslinux config file anywhere
memset(props, 0, sizeof(EXTRACT_PROPS));
for (i = 0; i < ARRAYSIZE(syslinux_cfg); i++) {
if (safe_stricmp(psz_basename, syslinux_cfg[i]) == 0) {
props->is_cfg = TRUE; // Required for "extlinux.conf"
props->is_syslinux_cfg = TRUE;
// Maintain a list of all the isolinux/syslinux config files identified so far
if ((scan_only) && (i < 3))
StrArrayAdd(&config_path, psz_fullpath, TRUE);
if ((scan_only) && (i == 1) && (safe_stricmp(psz_dirname, efi_dirname) == 0))
img_report.has_efi_syslinux = TRUE;
}
}
// Check for archiso loader/entries/*.conf files
if (safe_stricmp(psz_dirname, "/loader/entries") == 0) {
len = safe_strlen(psz_basename);
props->is_conf = ((len > 4) && (stricmp(&psz_basename[len - 5], ".conf") == 0));
}
// 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) && (file_length <= old_c32_threshold[i]))
props->is_old_c32[i] = TRUE;
}
if (!scan_only) { // Write-time checks
// Check for config files that may need patching
len = safe_strlen(psz_basename);
if ((len >= 4) && safe_stricmp(&psz_basename[len - 4], ".cfg") == 0) {
props->is_cfg = TRUE;
for (i = 0; i < ARRAYSIZE(grub_cfg); i++) {
if (safe_stricmp(psz_basename, grub_cfg[i]) == 0)
props->is_grub_cfg = TRUE;
}
if (safe_stricmp(psz_basename, menu_cfg) == 0) {
props->is_menu_cfg = TRUE;
}
}
// In case there's an ldlinux.sys on the ISO, prevent it from overwriting ours
if ((psz_dirname != NULL) && (psz_dirname[0] == 0) && (safe_stricmp(psz_basename, ldlinux_name) == 0)) {
uprintf("Skipping '%s' file from ISO image", psz_basename);
return TRUE;
}
} else { // Scan-time checks
// Check for GRUB artifacts
for (i = 0; i < ARRAYSIZE(grub_dirname); i++) {
if (safe_stricmp(psz_dirname, grub_dirname[i]) == 0)
img_report.has_grub2 = (uint8_t)i + 1;
}
// Check for a syslinux v5.0+ file anywhere
if (safe_stricmp(psz_basename, ldlinux_c32) == 0) {
has_ldlinux_c32 = TRUE;
}
// Check for a '/casper#####' directory (non-empty)
if (safe_strnicmp(psz_dirname, casper_dirname, strlen(casper_dirname)) == 0) {
img_report.uses_casper = TRUE;
if (safe_strstr(psz_dirname, pop_os_name) != NULL)
img_report.disable_iso = TRUE;
}
// Check for a '/proxmox' directory
if (safe_stricmp(psz_dirname, proxmox_dirname) == 0) {
img_report.disable_iso = TRUE;
}
// Check for various files and directories in root (psz_dirname = "")
if ((psz_dirname != NULL) && (psz_dirname[0] == 0)) {
if (safe_stricmp(psz_basename, bootmgr_name) == 0) {
img_report.has_bootmgr = TRUE;
}
if (safe_stricmp(psz_basename, bootmgr_efi_name) == 0) {
img_report.has_efi |= 1;
img_report.has_bootmgr_efi = TRUE;
}
if (safe_stricmp(psz_basename, grldr_name) == 0) {
img_report.has_grub4dos = TRUE;
}
if (safe_stricmp(psz_basename, kolibri_name) == 0) {
img_report.has_kolibrios = TRUE;
}
if (safe_stricmp(psz_basename, manjaro_marker) == 0) {
img_report.disable_iso = TRUE;
}
for (i = 0; i < ARRAYSIZE(md5sum_name); i++) {
if (safe_stricmp(psz_basename, md5sum_name[i]) == 0)
img_report.has_md5sum = (uint8_t)(i + 1);
}
}
// Check for ReactOS' setupldr.sys anywhere
if ((img_report.reactos_path[0] == 0) && (safe_stricmp(psz_basename, reactos_name) == 0))
static_strcpy(img_report.reactos_path, psz_fullpath);
// Check for the first 'efi*.img' we can find (that hopefully contains EFI boot files)
if (!HAS_EFI_IMG(img_report) && (safe_strlen(psz_basename) >= 7) &&
(safe_strnicmp(psz_basename, "efi", 3) == 0) &&
(safe_stricmp(&psz_basename[strlen(psz_basename) - 4], ".img") == 0))
static_strcpy(img_report.efi_img_path, psz_fullpath);
// 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)
img_report.has_efi |= (2 << i); // start at 2 since "bootmgr.efi" is bit 0
}
if (psz_dirname != NULL) {
if (safe_stricmp(&psz_dirname[max(0, ((int)safe_strlen(psz_dirname)) -
((int)strlen(sources_str)))], sources_str) == 0) {
// Check for "install.###" in "###/sources/"
for (i = 0; i < ARRAYSIZE(wininst_name); i++) {
if (safe_stricmp(psz_basename, wininst_name[i]) == 0) {
if (img_report.wininst_index < MAX_WININST) {
static_sprintf(img_report.wininst_path[img_report.wininst_index],
"?:%s", psz_fullpath);
img_report.wininst_index++;
}
}
}
}
}
// Check for PE (XP) specific files in "/i386", "/amd64" 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)
img_report.winpe |= (1<<j)<<(ARRAYSIZE(pe_dirname)*i);
for (i=0; i<ARRAYSIZE(isolinux_bin); i++) {
if (safe_stricmp(psz_basename, isolinux_bin[i]) == 0) {
// Maintain a list of all the isolinux.bin files found
StrArrayAdd(&isolinux_path, psz_fullpath, TRUE);
}
}
for (i=0; i<NB_OLD_C32; i++) {
if (props->is_old_c32[i])
img_report.has_old_c32[i] = TRUE;
}
if (file_length >= FOUR_GIGABYTES)
img_report.has_4GB_file = TRUE;
// Compute projected size needed (NB: ISO_BLOCKSIZE = UDF_BLOCKSIZE)
if (file_length != 0)
total_blocks += (file_length + (ISO_BLOCKSIZE - 1)) / ISO_BLOCKSIZE;
return TRUE;
}
return FALSE;
}
// Apply various workarounds to Linux config files
static void fix_config(const char* psz_fullpath, const char* psz_path, const char* psz_basename, EXTRACT_PROPS* props)
{
BOOL modified = FALSE, patched;
size_t nul_pos;
char *iso_label = NULL, *usb_label = NULL, *src, *dst;
src = safe_strdup(psz_fullpath);
if (src == NULL)
return;
nul_pos = strlen(src);
to_windows_path(src);
// Add persistence to the kernel options
if ((boot_type == BT_IMAGE) && HAS_PERSISTENCE(img_report) && persistence_size) {
if ((props->is_grub_cfg) || (props->is_menu_cfg) || (props->is_syslinux_cfg)) {
if (replace_in_token_data(src, props->is_grub_cfg ? "linux" : "append",
"file=/cdrom/preseed", "persistent file=/cdrom/preseed", TRUE) != NULL) {
// Ubuntu & derivatives are assumed to use 'file=/cdrom/preseed/...'
// or 'layerfs-path=minimal.standard.live.squashfs' (see below)
// somewhere in their kernel options and use 'persistent' as keyword.
uprintf(" Added 'persistent' kernel option");
modified = TRUE;
// Also remove Ubuntu's "maybe-ubiquity" to avoid splash screen (GRUB only)
if ((props->is_grub_cfg) && replace_in_token_data(src, "linux",
"maybe-ubiquity", "", TRUE))
uprintf(" Removed 'maybe-ubiquity' kernel option");
} else if (replace_in_token_data(src, "linux", "layerfs-path=minimal.standard.live.squashfs",
"persistent layerfs-path=minimal.standard.live.squashfs", TRUE) != NULL) {
// Ubuntu 23.04 uses GRUB only with the above and does not use "maybe-ubiquity"
uprintf(" Added 'persistent' kernel option");
modified = TRUE;
} else if (replace_in_token_data(src, props->is_grub_cfg ? "linux" : "append",
"boot=live", "boot=live persistence", TRUE) != NULL) {
// Debian & derivatives are assumed to use 'boot=live' in
// their kernel options and use 'persistence' as keyword.
uprintf(" Added 'persistence' kernel option");
modified = TRUE;
}
// Other distros can go to hell. Seriously, just check all partitions for
// an ext volume with the right label and use persistence *THEN*. I mean,
// why on earth do you need a bloody *NONSTANDARD* kernel option and/or a
// "persistence.conf" file. This is SO INCREDIBLY RETARDED that it makes
// Windows look smart in comparison. Great job there, Linux people!
}
}
// Workaround for 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.
if ((props->is_cfg) || (props->is_conf)) {
// Older versions of GRUB EFI used "linuxefi", newer just use "linux".
// Also, in their great wisdom, the openSUSE maintainers added a 'set linux=linux'
// line to their grub.cfg, which means that their kernel option cfg_token is no longer
//'linux' but '$linux'... and we have to add a workaround for that.
// Then, newer Arch and derivatives added an extra "search --label ..." command
// in their GRUB conf, which we need to cater for in supplement of the kernel line.
// Finally, we're just shoving the known isolinux/syslinux tokens in there to process
// all config files equally.
static const char* cfg_token[] = { "options", "append", "linux", "linuxefi", "$linux", "search" };
iso_label = replace_char(img_report.label, ' ', "\\x20");
usb_label = replace_char(img_report.usb_label, ' ', "\\x20");
if ((iso_label != NULL) && (usb_label != NULL)) {
patched = FALSE;
for (int i = 0; i < ARRAYSIZE(cfg_token); i++) {
if (replace_in_token_data(src, cfg_token[i], iso_label, usb_label, TRUE) != NULL) {
modified = TRUE;
patched = TRUE;
}
}
if (patched)
uprintf(" Patched %s: '%s' ➔ '%s'\n", src, iso_label, usb_label);
// Since version 8.2, and https://github.com/rhinstaller/anaconda/commit/a7661019546ec1d8b0935f9cb0f151015f2e1d95,
// Red Hat derivatives have changed their CD-ROM detection policy which leads to the installation source
// not being found. So we need to use 'inst.repo' instead of 'inst.stage2' in the kernel options.
// *EXCEPT* this should not be done for netinst media such as Fedora 37 netinstall and trying to differentiate
// netinst from regular is a pain. So, because I don't have all day to fix the mess that Red-Hat created when
// they introduced a kernel option to decide where the source packages should be picked from we're just going
// to *hope* that users didn't rename their ISOs and check whether it contains 'netinst' or not. Oh well...
patched = FALSE;
if (img_report.rh8_derivative && (strstr(image_path, "netinst") == NULL)) {
for (int i = 0; i < ARRAYSIZE(cfg_token); i++) {
if (replace_in_token_data(src, cfg_token[i], "inst.stage2", "inst.repo", TRUE) != NULL) {
modified = TRUE;
patched = TRUE;
}
}
if (patched)
uprintf(" Patched %s: '%s' ➔ '%s'\n", src, "inst.stage2", "inst.repo");
}
}
safe_free(iso_label);
safe_free(usb_label);
}
// Fix dual BIOS + EFI support for tails and other ISOs
if ( (props->is_syslinux_cfg) && (safe_stricmp(psz_path, efi_dirname) == 0) &&
(safe_stricmp(psz_basename, syslinux_cfg[0]) == 0) &&
(!img_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);
}
// Workaround for FreeNAS
if (props->is_grub_cfg) {
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", img_report.label);
safe_sprintf(usb_label, MAX_PATH, "msdosfs:/dev/msdosfs/%s", img_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);
modified = TRUE;
}
}
safe_free(iso_label);
safe_free(usb_label);
}
if (modified)
StrArrayAdd(&modified_path, psz_fullpath, TRUE);
free(src);
}
static void print_extracted_file(char* psz_fullpath, uint64_t file_length)
{
size_t nul_pos;
if (psz_fullpath == NULL)
return;
// Replace slashes with backslashes and append the size to the path for UI display
to_windows_path(psz_fullpath);
nul_pos = strlen(psz_fullpath);
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(file_length, TRUE, FALSE));
uprintf("Extracting: %s\n", psz_fullpath);
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(file_length, FALSE, FALSE));
PrintStatus(0, MSG_000, psz_fullpath); // MSG_000 is "%s"
// Remove the appended size for extraction
psz_fullpath[nul_pos] = 0;
// ISO9660 cannot handle backslashes
to_unix_path(psz_fullpath);
}
static void alt_print_extracted_file(const char* psz_fullpath, uint64_t file_length)
{
uprintf("Extracting: %s (%s)", psz_fullpath, SizeToHumanReadable(file_length, FALSE, FALSE));
PrintStatus(0, MSG_000, psz_fullpath);
}
// Convert from time_t to FILETIME
// Uses 3 static entries so that we can convert 3 concurrent values at the same time
static LPFILETIME __inline to_filetime(time_t t)
{
static int i = 0;
static FILETIME ft[3], *r;
LONGLONG ll = (t * 10000000LL) + 116444736000000000LL;
r = &ft[i];
r->dwLowDateTime = (DWORD)ll;
r->dwHighDateTime = (DWORD)(ll >> 32);
i = (i + 1) % ARRAYSIZE(ft);
return r;
}
// Helper function to restore the timestamp on a directory
static void __inline set_directory_timestamp(char* path, LPFILETIME creation, LPFILETIME last_access, LPFILETIME modify)
{
HANDLE dir_handle = CreateFileU(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if ((dir_handle == INVALID_HANDLE_VALUE) || (!SetFileTime(dir_handle, creation, last_access, modify)))
uprintf(" Could not set timestamp for directory '%s': %s", path, WindowsErrorString());
safe_closehandle(dir_handle);
}
// Returns 0 on success, nonzero on error
static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path)
{
HANDLE file_handle = NULL;
DWORD buf_size, wr_size, err;
EXTRACT_PROPS props;
BOOL r, is_identical;
int length;
size_t i;
char tmp[128], *psz_fullpath = NULL, *psz_sanpath = NULL;
const char* psz_basename;
udf_dirent_t *p_udf_dirent2;
uint8_t buf[UDF_BLOCKSIZE];
int64_t read, file_length;
if ((p_udf_dirent == NULL) || (psz_path == NULL))
return 1;
if (psz_path[0] == 0)
UpdateProgressWithInfoInit(NULL, TRUE);
while ((p_udf_dirent = udf_readdir(p_udf_dirent)) != NULL) {
if (FormatStatus) goto out;
psz_basename = udf_get_filename(p_udf_dirent);
if (strlen(psz_basename) == 0)
continue;
length = (int)(3 + strlen(psz_path) + strlen(psz_basename) + strlen(psz_extract_dir) + 24);
psz_fullpath = (char*)calloc(sizeof(char), length);
if (psz_fullpath == NULL) {
uprintf("Error allocating file name");
goto out;
}
length = _snprintf(psz_fullpath, length, "%s%s/%s", psz_extract_dir, psz_path, psz_basename);
if (length < 0) {
goto out;
}
if (S_ISLNK(udf_get_posix_filemode(p_udf_dirent)))
img_report.has_symlinks = SYMLINKS_UDF;
if (udf_is_dir(p_udf_dirent)) {
if (!scan_only) {
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
IGNORE_RETVAL(_mkdirU(psz_sanpath));
if (preserve_timestamps) {
set_directory_timestamp(psz_sanpath, to_filetime(udf_get_attribute_time(p_udf_dirent)),
to_filetime(udf_get_access_time(p_udf_dirent)), to_filetime(udf_get_modification_time(p_udf_dirent)));
}
safe_free(psz_sanpath);
}
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 {
file_length = udf_get_file_length(p_udf_dirent);
if (check_iso_props(psz_path, file_length, psz_basename, psz_fullpath, &props)) {
safe_free(psz_fullpath);
continue;
}
print_extracted_file(psz_fullpath, file_length);
for (i = 0; i < NB_OLD_C32; i++) {
if (props.is_old_c32[i] && use_own_c32[i]) {
static_sprintf(tmp, "%s/syslinux-%s/%s", FILES_DIR, embedded_sl_version_str[0], old_c32_name[i]);
if (CopyFileU(tmp, psz_fullpath, FALSE)) {
uprintf(" Replaced with local version %s", IsFileInDB(tmp)?"✓":"✗");
break;
}
uprintf(" Could not replace file: %s", WindowsErrorString());
}
}
if (i < NB_OLD_C32)
continue;
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
if (!is_identical)
uprintf(" File name sanitized to '%s'", psz_sanpath);
file_handle = CreatePreallocatedFile(psz_sanpath, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, file_length);
if (file_handle == INVALID_HANDLE_VALUE) {
err = GetLastError();
uprintf(" Unable to create file: %s", WindowsErrorString());
if (((err == ERROR_ACCESS_DENIED) || (err == ERROR_INVALID_HANDLE)) &&
(safe_strcmp(&psz_sanpath[3], autorun_name) == 0))
uprintf(stupid_antivirus);
else
goto out;
} else {
while (file_length > 0) {
if (FormatStatus) goto out;
memset(buf, 0, UDF_BLOCKSIZE);
read = udf_read_block(p_udf_dirent, buf, 1);
if (read < 0) {
uprintf(" Error reading UDF file %s", &psz_fullpath[strlen(psz_extract_dir)]);
goto out;
}
buf_size = (DWORD)MIN(file_length, read);
ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES));
if (!r) {
uprintf(" Error writing file: %s", WindowsErrorString());
goto out;
}
file_length -= read;
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
UpdateProgressWithInfo(OP_FILE_COPY, MSG_231, nb_blocks, total_blocks);
}
}
if ((preserve_timestamps) && (!SetFileTime(file_handle, to_filetime(udf_get_attribute_time(p_udf_dirent)),
to_filetime(udf_get_access_time(p_udf_dirent)), to_filetime(udf_get_modification_time(p_udf_dirent)))))
uprintf(" Could not set timestamp: %s", WindowsErrorString());
// 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()
// may take forever to complete and is not interruptible. We try to detect this.
ISO_BLOCKING(safe_closehandle(file_handle));
if (props.is_cfg || props.is_conf)
fix_config(psz_sanpath, psz_path, psz_basename, &props);
safe_free(psz_sanpath);
}
safe_free(psz_fullpath);
}
return 0;
out:
udf_dirent_free(p_udf_dirent);
ISO_BLOCKING(safe_closehandle(file_handle));
safe_free(psz_sanpath);
safe_free(psz_fullpath);
return 1;
}
// This updates the MD5SUMS/md5sum.txt file that some distros (Ubuntu, Mint...)
// use to validate the media. Because we may alter some of the validated files
// to add persistence and whatnot, we need to alter the MD5 list as a result.
// The format of the file is expected to always be "<MD5SUM> <FILE_PATH>" on
// individual lines.
static void update_md5sum(void)
{
BOOL display_header = TRUE;
intptr_t pos;
uint32_t i, j, size, md5_size;
uint8_t *buf = NULL, sum[16];
char md5_path[64], *md5_data = NULL, *str_pos;
if (!img_report.has_md5sum)
goto out;
assert(img_report.has_md5sum <= ARRAYSIZE(md5sum_name));
if (img_report.has_md5sum > ARRAYSIZE(md5sum_name))
goto out;
static_sprintf(md5_path, "%s\\%s", psz_extract_dir, md5sum_name[img_report.has_md5sum - 1]);
md5_size = read_file(md5_path, (uint8_t**)&md5_data);
if (md5_size == 0)
goto out;
for (i = 0; i < modified_path.Index; i++) {
str_pos = strstr(md5_data, &modified_path.String[i][2]);
if (str_pos == NULL)
// File is not listed in md5 sums
continue;
if (display_header) {
uprintf("Updating %s:", md5_path);
display_header = FALSE;
}
uprintf("● %s", &modified_path.String[i][2]);
pos = str_pos - md5_data;
size = read_file(modified_path.String[i], &buf);
if (size == 0)
continue;
HashBuffer(HASH_MD5, buf, size, sum);
free(buf);
while ((pos > 0) && (md5_data[pos - 1] != '\n'))
pos--;
for (j = 0; j < 16; j++) {
md5_data[pos + 2 * j] = ((sum[j] >> 4) < 10) ? ('0' + (sum[j] >> 4)) : ('a' - 0xa + (sum[j] >> 4));
md5_data[pos + 2 * j + 1] = ((sum[j] & 15) < 10) ? ('0' + (sum[j] & 15)) : ('a' - 0xa + (sum[j] & 15));
}
}
write_file(md5_path, md5_data, md5_size);
free(md5_data);
out:
StrArrayDestroy(&modified_path);
}
// Returns 0 on success, >0 on error, <0 to ignore current dir
static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
{
HANDLE file_handle = NULL;
DWORD buf_size, wr_size, err;
EXTRACT_PROPS props;
BOOL is_symlink, is_identical, free_p_statbuf = FALSE;
int length, r = 1;
char tmp[128], psz_fullpath[MAX_PATH], *psz_basename = NULL, *psz_sanpath = NULL;
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;
CdioISO9660FileList_t* p_entlist;
size_t i;
lsn_t lsn;
int64_t file_length;
if ((p_iso == NULL) || (psz_path == NULL))
return 1;
length = _snprintf(psz_fullpath, sizeof(psz_fullpath), "%s%s/", psz_extract_dir, psz_path);
if (length < 0)
return 1;
psz_basename = &psz_fullpath[length];
p_entlist = iso9660_ifs_readdir(p_iso, psz_path);
if (!p_entlist) {
uprintf("Could not access directory %s", psz_path);
return 1;
}
if (psz_path[0] == 0)
UpdateProgressWithInfoInit(NULL, TRUE);
_CDIO_LIST_FOREACH(p_entnode, p_entlist) {
if (FormatStatus) goto out;
p_statbuf = (iso9660_stat_t*) _cdio_list_node_data(p_entnode);
free_p_statbuf = FALSE;
if (scan_only && (p_statbuf->rr.b3_rock == yep) && enable_rockridge) {
if (p_statbuf->rr.u_su_fields & ISO_ROCK_SUF_PL) {
if (!img_report.has_deep_directories)
uprintf(" Note: The selected ISO uses Rock Ridge 'deep directories'.\r\n"
" Because of this, it may take a very long time to scan or extract...");
img_report.has_deep_directories = TRUE;
// Due to the nature of the parsing of Rock Ridge deep directories
// which requires performing a *very costly* search of the whole
// ISO9660 file system to find the matching LSN, ISOs with loads of
// deep directory entries (e.g. OPNsense) are very slow to parse...
// To speed up the scan process, and since we expect deep directory
// entries to appear below anything we care for, we cut things
// short by telling the parent not to bother any further once we
// find that we are dealing with a deep directory.
r = -1;
// Add at least one extra block, since we're skipping content.
total_blocks++;
goto out;
}
}
// Eliminate . and .. entries
if ( (strcmp(p_statbuf->filename, ".") == 0)
|| (strcmp(p_statbuf->filename, "..") == 0) )
continue;
// Rock Ridge requires an exception
is_symlink = FALSE;
if ((p_statbuf->rr.b3_rock == yep) && enable_rockridge) {
safe_strcpy(psz_basename, sizeof(psz_fullpath) - length - 1, p_statbuf->filename);
if (safe_strlen(p_statbuf->filename) > 64)
img_report.has_long_filename = TRUE;
is_symlink = (p_statbuf->rr.psz_symlink != NULL);
if (is_symlink)
img_report.has_symlinks = SYMLINKS_RR;
} else {
iso9660_name_translate_ext(p_statbuf->filename, psz_basename, joliet_level);
}
if (p_statbuf->type == _STAT_DIR) {
if (!scan_only) {
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
IGNORE_RETVAL(_mkdirU(psz_sanpath));
if (preserve_timestamps) {
LPFILETIME ft = to_filetime(mktime(&p_statbuf->tm));
set_directory_timestamp(psz_sanpath, ft, ft, ft);
}
safe_free(psz_sanpath);
}
r = iso_extract_files(p_iso, psz_iso_name);
if (r > 0)
goto out;
if (r < 0) // Stop processing current dir
break;
} else {
file_length = p_statbuf->total_size;
if (check_iso_props(psz_path, file_length, psz_basename, psz_fullpath, &props)) {
continue;
}
if (!is_symlink)
print_extracted_file(psz_fullpath, file_length);
for (i = 0; i < NB_OLD_C32; i++) {
if (props.is_old_c32[i] && use_own_c32[i]) {
static_sprintf(tmp, "%s/syslinux-%s/%s", FILES_DIR, embedded_sl_version_str[0], old_c32_name[i]);
if (CopyFileU(tmp, psz_fullpath, FALSE)) {
uprintf(" Replaced with local version %s", IsFileInDB(tmp)?"✓":"✗");
break;
}
uprintf(" Could not replace file: %s", WindowsErrorString());
}
}
if (i < NB_OLD_C32)
continue;
psz_sanpath = sanitize_filename(psz_fullpath, &is_identical);
if (!is_identical)
uprintf(" File name sanitized to '%s'", psz_sanpath);
if (is_symlink) {
if (file_length == 0) {
if ((safe_stricmp(p_statbuf->filename, "syslinux") == 0) &&
// Special handling for ISOs that have a syslinux → isolinux symbolic link (e.g. Knoppix)
(safe_stricmp(p_statbuf->rr.psz_symlink, "isolinux") == 0)) {
static_strcpy(symlinked_syslinux, psz_fullpath);
print_extracted_file(psz_fullpath, file_length);
uprintf(" Found Rock Ridge symbolic link to '%s'", p_statbuf->rr.psz_symlink);
} else if (strcmp(psz_path, "/firmware") == 0) {
// Special handling for ISOs that use symlinks for /firmware/ (e.g. Debian non-free)
// TODO: Do we want to do this for all file symlinks?
char target_path[256];
static_sprintf(target_path, "%s/%s", psz_path, p_statbuf->rr.psz_symlink);
p_statbuf = iso9660_ifs_stat_translate(p_iso, target_path);
if (p_statbuf != NULL) {
// The original p_statbuf will be freed automatically, but not
// the new one so we need to force an explicit free.
free_p_statbuf = TRUE;
file_length = p_statbuf->total_size;
print_extracted_file(psz_fullpath, file_length);
uprintf(" Duplicated from '%s'", target_path);
} else {
uprintf("Could not resolve Rock Ridge Symlink - ABORTING!");
goto out;
}
} else {
// TODO: Ideally, we'd want to create a text file that contains the target link
print_extracted_file(psz_fullpath, file_length);
uprintf(" Ignoring Rock Ridge symbolic link to '%s'", p_statbuf->rr.psz_symlink);
}
}
}
file_handle = CreatePreallocatedFile(psz_sanpath, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, file_length);
if (file_handle == INVALID_HANDLE_VALUE) {
err = GetLastError();
uprintf(" Unable to create file: %s", WindowsErrorString());
if (((err == ERROR_ACCESS_DENIED) || (err == ERROR_INVALID_HANDLE)) &&
(safe_strcmp(&psz_sanpath[3], autorun_name) == 0))
uprintf(stupid_antivirus);
else
goto out;
} else for (i = 0; file_length > 0; i++) {
if (FormatStatus) goto out;
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",
psz_iso_name, (long unsigned int)lsn);
goto out;
}
buf_size = (DWORD)MIN(file_length, ISO_BLOCKSIZE);
ISO_BLOCKING(r = WriteFileWithRetry(file_handle, buf, buf_size, &wr_size, WRITE_RETRIES));
if (!r) {
uprintf(" Error writing file: %s", WindowsErrorString());
goto out;
}
file_length -= ISO_BLOCKSIZE;
if (nb_blocks++ % PROGRESS_THRESHOLD == 0)
UpdateProgressWithInfo(OP_FILE_COPY, MSG_231, nb_blocks, total_blocks);
}
if (preserve_timestamps) {
LPFILETIME ft = to_filetime(mktime(&p_statbuf->tm));
if (!SetFileTime(file_handle, ft, ft, ft))
uprintf(" Could not set timestamp: %s", WindowsErrorString());
}
if (free_p_statbuf)
iso9660_stat_free(p_statbuf);
ISO_BLOCKING(safe_closehandle(file_handle));
if (props.is_cfg || props.is_conf)
fix_config(psz_sanpath, psz_path, psz_basename, &props);
safe_free(psz_sanpath);
}
}
r = 0;
out:
ISO_BLOCKING(safe_closehandle(file_handle));
iso9660_filelist_free(p_entlist);
safe_free(psz_sanpath);
return r;
}
void GetGrubVersion(char* buf, size_t buf_size)
{
// In typical "I'll make my own Open Source... with blackjack and hookers!" fashion,
// IBM/Red-Hat/Fedora took it upon themselves to "fix" the double space typo from the
// GRUB version string. But of course, just like their introduction of GRUB calls like
// 'grub_debug_is_enabled', they didn't want to bother upstreaming their changes...
// On the other hand, boy do they want to leech of FSF/GNU developed software, while
// not having it mention GNU anywhere. See:
// https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/0024-Don-t-say-GNU-Linux-in-generated-menus.patch
const char* grub_version_str[] = { "GRUB version %s", "GRUB version %s" };
const char* grub_debug_is_enabled_str = "grub_debug_is_enabled";
const size_t max_string_size = 32; // The strings above *MUST* be no longer than this value
size_t i, j;
BOOL has_grub_debug_is_enabled = FALSE;
// Make sure we don't overflow our buffer
if (buf_size > max_string_size) {
for (i = 0; i < buf_size - max_string_size; i++) {
for (j = 0; j < ARRAYSIZE(grub_version_str); j++) {
if (memcmp(&buf[i], grub_version_str[j], strlen(grub_version_str[j]) + 1) == 0)
static_strcpy(img_report.grub2_version, &buf[i + strlen(grub_version_str[j]) + 1]);
}
if (memcmp(&buf[i], grub_debug_is_enabled_str, strlen(grub_debug_is_enabled_str)) == 0)
has_grub_debug_is_enabled = TRUE;
}
}
uprintf(" Reported Grub version: %s", img_report.grub2_version);
// <Shakes fist angrily> "KASPERSKYYYYYY!!!..." (https://github.com/pbatard/rufus/issues/467)
// But seriously, these guys should know better than "security" through obscurity...
if (img_report.grub2_version[0] == '0')
img_report.grub2_version[0] = 0;
// For some obscure reason, openSUSE have decided that their Live images should
// use /boot/grub2/ as their prefix directory instead of the standard /boot/grub/
// This creates a MAJOR issue because the prefix directory is hardcoded in
// 'core.img', and Rufus must install a 'core.img', that is not provided by the
// ISO, for the USB to boot (since even trying to pick the one from ISOHybrid
// does usually not guarantees the presence of the FAT driver which is mandatory
// for ISO boot).
// Therefore, when *someone* uses a nonstandard GRUB prefix directory, our base
// 'core.img' can't work with their image, since it isn't able to load modules
// like 'normal.mod', that are required to access the configuration files. Oh and
// you can forget about direct editing the prefix string inside 'core.img' since
// GRUB are forcing LZMA compression for BIOS payloads. And it gets even better,
// because even if you're trying to be smart and use GRUB's earlyconfig features
// to do something like:
// if [ -e /boot/grub2/i386-pc/normal.mod ]; then set prefix = ...
// you still must embed 'configfile.mod' and 'normal.mod' in 'core.img' in order
// to do that, which ends up tripling the file size...
// Also, as mentioned above, Fedora, Ubuntu and others have started applying
// *BREAKING* patches willy-nilly, without bothering to alter the GRUB version
// string. And it gets worse with 2.06 since there are patches we can't detect
// that will produce "452: out of range pointer" whether they are applied OR NOT
// (meaning that if you use a patched GRUB 2.06 with unpatched GRUB 2.06 modules
// you will get the error, and if you use unpatched with patched modules, you
// will also get the error).
// Soooo, since the universe, and project maintainers who do not REALISE that
// NOT RELEASING IN A TIMELY MANNER *DOES* HAVE VERY NEGATIVE CONSEQUENCES FOR
// END USERS, are conspiring against us, and since we already have a facility
// for it, we'll use it to dowload the relevant 'core.img' by appending a missing
// version suffix as needed. Especially, if GRUB only identifies itself as '2.06'
// we'll append a sanitized version of the ISO label to try to differentiate
// between GRUB 2.06 incompatible versions...
if (img_report.grub2_version[0] != 0) {
// Make sure we append '-nonstandard' and '-gdie' before the sanitized label.
BOOL append_label = (safe_strcmp(img_report.grub2_version, "2.06") == 0);
// Must be in the same order as we have on the server
if (img_report.has_grub2 > 1)
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), "-nonstandard");
if (has_grub_debug_is_enabled)
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), "-gdie");
if (append_label) {
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), "-");
safe_strcat(img_report.grub2_version, sizeof(img_report.grub2_version), img_report.label);
}
sanitize_label(img_report.grub2_version);
}
}
BOOL ExtractISO(const char* src_iso, const char* dest_dir, BOOL scan)
{
size_t i, j, size, sl_index = 0;
uint16_t sl_version;
FILE* fd;
int k, r = 1;
iso9660_t* p_iso = NULL;
iso9660_pvd_t pvd;
udf_t* p_udf = NULL;
udf_dirent_t* p_udf_root;
char *tmp, *buf, *ext;
char path[MAX_PATH], path2[16];
const char* basedir[] = { "i386", "amd64", "minint" };
const char* tmp_sif = ".\\txtsetup.sif~";
iso_extension_mask_t iso_extension_mask = ISO_EXTENSION_ALL;
char* spacing = " ";
if ((!enable_iso) || (src_iso == NULL) || (dest_dir == NULL))
return FALSE;
scan_only = scan;
if (!scan_only)
spacing = "";
cdio_log_set_handler(log_handler);
psz_extract_dir = dest_dir;
// Change progress style to marquee for scanning
if (scan_only) {
uprintf("ISO analysis:");
SendMessage(hMainDialog, UM_PROGRESS_INIT, PBS_MARQUEE, 0);
total_blocks = 0;
has_ldlinux_c32 = FALSE;
// String array of all isolinux/syslinux locations
StrArrayCreate(&config_path, 8);
StrArrayCreate(&isolinux_path, 8);
PrintInfo(0, MSG_202);
} else {
uprintf("Extracting files...\n");
IGNORE_RETVAL(_chdirU(app_data_dir));
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;