@@ -495,10 +495,10 @@ const xoff_t lseek_offsets[LSEEK_OFFSETS_LEN] = {START_LSEEK_OFFSET, XGD3_LSEEK_
495
495
#define XISO_PAD_BYTE 0xff
496
496
#define XISO_PAD_SHORT 0xffff
497
497
498
- #define XISO_MEDIA_ENABLE "\xe8\xca\xfd\xff\xff\x85\xc0\x7d"
499
- #define XISO_MEDIA_ENABLE_BYTE '\xeb'
500
498
#define XISO_MEDIA_ENABLE_LENGTH 8
501
499
#define XISO_MEDIA_ENABLE_BYTE_POS 7
500
+ const unsigned char xiso_media_enable [XISO_MEDIA_ENABLE_LENGTH ] = { 0xe8 , 0xca , 0xfd , 0xff , 0xff , 0x85 , 0xc0 , 0x7d };
501
+ const unsigned char xiso_media_enable_byte = 0xeb ;
502
502
503
503
#define n_sectors (size ) ( (size) / XISO_SECTOR_SIZE + ( (size) % XISO_SECTOR_SIZE ? 1 : 0 ) )
504
504
#define n_dword (offset ) ( (offset) / XISO_DWORD_SIZE + ( (offset) % XISO_DWORD_SIZE ? 1 : 0 ) )
@@ -592,8 +592,8 @@ static avl_result avl_insert( dir_node_avl **in_root, dir_node_avl *in_node );
592
592
static int avl_traverse_depth_first ( dir_node_avl * in_root , traversal_callback in_callback , void * in_context , avl_traversal_method in_method , int in_depth );
593
593
594
594
static void boyer_moore_done ();
595
- static char * boyer_moore_search ( char * in_text , size_t in_text_len );
596
- static int boyer_moore_init ( const char * in_pattern , size_t in_pat_len , size_t in_alphabet_size );
595
+ static unsigned char * boyer_moore_search ( unsigned char * in_text , size_t in_text_len );
596
+ static int boyer_moore_init ( const unsigned char * in_pattern , size_t in_pat_len , size_t in_alphabet_size );
597
597
598
598
static int free_dir_node_avl (dir_node_avl * in_dir_node_avl , void * in_context , int in_depth );
599
599
static int extract_file ( int in_xiso , dir_node * in_file , modes in_mode , const char * path );
@@ -625,12 +625,12 @@ static void write_sector( int in_xiso, xoff_t in_start, const char *in_name, con
625
625
626
626
static size_t s_pat_len ;
627
627
static bool s_quiet = false;
628
- static const char * s_pattern = NULL ;
628
+ static const unsigned char * s_pattern = NULL ;
629
629
static size_t * s_gs_table = NULL ;
630
630
static size_t * s_bc_table = NULL ;
631
631
static long long s_total_bytes = 0 ;
632
632
static int s_total_files = 0 ;
633
- static char * s_copy_buffer = NULL ;
633
+ static unsigned char * s_copy_buffer = NULL ;
634
634
static bool s_real_quiet = false;
635
635
static bool s_media_enable = true;
636
636
static long long s_total_bytes_all_isos = 0 ;
@@ -742,7 +742,7 @@ int main( int argc, char **argv ) {
742
742
743
743
exiso_log (banner );
744
744
745
- if ((extract || rewrite || create ) && (s_copy_buffer = (char * )malloc (READWRITE_BUFFER_SIZE )) == NULL ) mem_err ();
745
+ if ((extract || rewrite || create ) && (s_copy_buffer = (unsigned char * )malloc (READWRITE_BUFFER_SIZE )) == NULL ) mem_err ();
746
746
747
747
}
748
748
@@ -757,7 +757,7 @@ int main( int argc, char **argv ) {
757
757
}
758
758
}
759
759
760
- if ( ! err && ( create || rewrite ) ) err = boyer_moore_init ( XISO_MEDIA_ENABLE , XISO_MEDIA_ENABLE_LENGTH , k_default_alphabet_size );
760
+ if ( ! err && ( create || rewrite ) ) err = boyer_moore_init ( xiso_media_enable , XISO_MEDIA_ENABLE_LENGTH , k_default_alphabet_size );
761
761
762
762
if ( ! err && create ) {
763
763
/* After this loop create will be NULL, so remember not to check it anymore */
@@ -949,7 +949,7 @@ static int log_err(unused_release const char* in_file, unused_release int in_lin
949
949
950
950
static int verify_xiso ( int in_xiso , uint32_t * out_root_dir_sector , uint32_t * out_root_dir_size , const char * in_iso_name ) {
951
951
int i , err = 0 ;
952
- char buffer [XISO_HEADER_DATA_LENGTH ];
952
+ unsigned char buffer [XISO_HEADER_DATA_LENGTH ];
953
953
954
954
for (i = 0 ; !err && i < LSEEK_OFFSETS_LEN ; i ++ ) {
955
955
if (lseek_with_error (in_xiso , (xoff_t )XISO_HEADER_OFFSET + lseek_offsets [i ], SEEK_SET ) == -1 ) seek_err ();
@@ -967,7 +967,7 @@ static int verify_xiso( int in_xiso, uint32_t *out_root_dir_sector, uint32_t *ou
967
967
968
968
little32 ( * out_root_dir_sector );
969
969
little32 ( * out_root_dir_size );
970
-
970
+
971
971
// seek to header tail and verify media tag
972
972
if ( ! err && lseek_with_error (in_xiso , (xoff_t )XISO_FILETIME_SIZE + XISO_UNUSED_SIZE , SEEK_CUR ) == -1 ) seek_err ();
973
973
if ( ! err && read ( in_xiso , buffer , XISO_HEADER_DATA_LENGTH ) != XISO_HEADER_DATA_LENGTH ) read_err ();
@@ -983,12 +983,12 @@ static int verify_xiso( int in_xiso, uint32_t *out_root_dir_sector, uint32_t *ou
983
983
984
984
985
985
static int create_xiso ( char * in_root_directory , const char * in_output_directory , dir_node_avl * in_root , int in_xiso , char * * out_iso_path , char * in_name , progress_callback in_progress_callback ) {
986
- xoff_t pos = 0 ;
986
+ xoff_t size = 0 ;
987
987
dir_node_avl root = { 0 };
988
988
file_time_t ft = 0 ;
989
989
write_tree_context wt_context = { 0 };
990
990
uint32_t start_sector = 0 ;
991
- int i = 0 , n = 0 , xiso = -1 , err = 0 ;
991
+ int i = 0 , n = 0 , xiso = -1 , err = 0 , pad = 0 ;
992
992
char * cwd = NULL , * iso_name = NULL , * xiso_path = NULL , * iso_dir = NULL , * real_path = NULL , * in_dir_path = NULL ;
993
993
994
994
s_total_bytes = s_total_files = 0 ;
@@ -1118,14 +1118,15 @@ static int create_xiso( char *in_root_directory, const char *in_output_directory
1118
1118
err = avl_traverse_depth_first ( & root , (traversal_callback ) write_tree , & wt_context , k_prefix , 0 );
1119
1119
}
1120
1120
1121
- if ( ! err && ( pos = lseek ( xiso , (xoff_t ) 0 , SEEK_END ) ) == -1 ) seek_err ();
1121
+ if ( ! err && ( size = lseek ( xiso , (xoff_t ) 0 , SEEK_END ) ) == -1 ) seek_err ();
1122
1122
if (!err ) {
1123
- i = (int )((XISO_FILE_MODULUS - pos % XISO_FILE_MODULUS ) % XISO_FILE_MODULUS );
1124
- memset (s_copy_buffer , 0 , i );
1125
- if (write (xiso , s_copy_buffer , i ) != i ) write_err ();
1123
+ pad = (int )((XISO_FILE_MODULUS - (size % XISO_FILE_MODULUS )) % XISO_FILE_MODULUS );
1124
+ size += pad ;
1125
+ memset (s_copy_buffer , 0 , pad );
1126
+ if (write (xiso , s_copy_buffer , pad ) != pad ) write_err ();
1126
1127
}
1127
1128
1128
- if ( ! err ) err = write_volume_descriptors ( xiso , (uint32_t )(( pos + ( xoff_t ) i ) / XISO_SECTOR_SIZE ) );
1129
+ if ( ! err ) err = write_volume_descriptors ( xiso , (uint32_t )(size / XISO_SECTOR_SIZE ) );
1129
1130
1130
1131
if ( ! err && lseek ( xiso , (xoff_t ) XISO_OPTIMIZED_TAG_OFFSET , SEEK_SET ) == -1 ) seek_err ();
1131
1132
if ( ! err && write ( xiso , XISO_OPTIMIZED_TAG , XISO_OPTIMIZED_TAG_LENGTH ) != XISO_OPTIMIZED_TAG_LENGTH ) write_err ();
@@ -1267,15 +1268,15 @@ static int traverse_xiso(int in_xiso, xoff_t in_dir_start, uint16_t entry_offset
1267
1268
}
1268
1269
else if (strategy != discover_strategy ) { // When discovering, the padding means end of sector
1269
1270
exiso_warn ("Invalid node found and skipped!" ); // When not discovering, the padding means a bad entry, skip it without failing
1270
- return err ; // We're done if not discovering
1271
+ return 0 ; // We're done if not discovering
1271
1272
}
1272
1273
// We're discovering, so set the offset to the start of the next sector
1273
- if (! err ) entry_offset = n_sectors (entry_offset * XISO_DWORD_SIZE ) * XISO_SECTOR_SIZE / XISO_DWORD_SIZE ;
1274
+ entry_offset = n_sectors (entry_offset * XISO_DWORD_SIZE ) * XISO_SECTOR_SIZE / XISO_DWORD_SIZE ;
1274
1275
continue ;
1275
1276
}
1276
1277
1277
1278
// Read node
1278
- if (!err ) if ( (node = calloc (1 , sizeof (dir_node ))) == NULL ) mem_err ();
1279
+ if (!err && (node = calloc (1 , sizeof (dir_node ))) == NULL ) mem_err ();
1279
1280
if (!err && read (in_xiso , & r_offset , XISO_TABLE_OFFSET_SIZE ) != XISO_TABLE_OFFSET_SIZE ) read_err ();
1280
1281
if (!err && read (in_xiso , & node -> start_sector , XISO_SECTOR_OFFSET_SIZE ) != XISO_SECTOR_OFFSET_SIZE ) read_err ();
1281
1282
if (!err && read (in_xiso , & node -> file_size , XISO_FILESIZE_SIZE ) != XISO_FILESIZE_SIZE ) read_err ();
@@ -1444,15 +1445,15 @@ static int process_node(int in_xiso, dir_node* node, const char* in_path, modes
1444
1445
static dir_node_avl * avl_fetch ( dir_node_avl * in_root , const char * in_filename ) {
1445
1446
int result ;
1446
1447
1447
- for ( ;; ) {
1448
- if ( in_root == NULL ) return NULL ;
1449
-
1448
+ while (in_root != NULL ) {
1450
1449
result = avl_compare_key ( in_filename , in_root -> filename_cp1252 );
1451
1450
1452
1451
if ( result < 0 ) in_root = in_root -> left ;
1453
1452
else if ( result > 0 ) in_root = in_root -> right ;
1454
1453
else return in_root ;
1455
1454
}
1455
+
1456
+ return NULL ;
1456
1457
}
1457
1458
1458
1459
@@ -1567,20 +1568,19 @@ static void avl_rotate_right( dir_node_avl **in_root ) {
1567
1568
}
1568
1569
1569
1570
1570
- static int avl_compare_key ( const char * in_lhs , const char * in_rhs ) {
1571
+ static int avl_compare_key (const char * in_lhs , const char * in_rhs ) {
1571
1572
unsigned char a , b ;
1572
1573
1573
- for ( ;; ) {
1574
+ do {
1574
1575
a = (unsigned char )toupperCP1252 (* in_lhs ++ );
1575
1576
b = (unsigned char )toupperCP1252 (* in_rhs ++ );
1576
-
1577
- if ( a ) {
1578
- if ( b ) {
1579
- if ( a < b ) return -1 ;
1580
- if ( a > b ) return 1 ;
1581
- } else return 1 ;
1582
- } else return b ? -1 : 0 ;
1583
- }
1577
+
1578
+ if (a < b ) return -1 ;
1579
+ if (a > b ) return 1 ;
1580
+ } while (a && b );
1581
+
1582
+ /* If we're here, both a and b are '\0', otherwise we would have returned before. */
1583
+ return 0 ;
1584
1584
}
1585
1585
1586
1586
@@ -1620,7 +1620,7 @@ static int avl_traverse_depth_first( dir_node_avl *in_root, traversal_callback i
1620
1620
#endif
1621
1621
1622
1622
1623
- static int boyer_moore_init ( const char * in_pattern , size_t in_pat_len , size_t in_alphabet_size ) {
1623
+ static int boyer_moore_init ( const unsigned char * in_pattern , size_t in_pat_len , size_t in_alphabet_size ) {
1624
1624
size_t j , k , t , t1 , q , q1 , * aux = NULL ;
1625
1625
int err = 0 ;
1626
1626
@@ -1635,7 +1635,7 @@ static int boyer_moore_init( const char *in_pattern, size_t in_pat_len, size_t i
1635
1635
if ((s_bc_table = (size_t * )malloc (in_alphabet_size * sizeof (size_t ))) == NULL ) mem_err ();
1636
1636
if (!err ) {
1637
1637
for (k = 0 ; k < in_alphabet_size ; k ++ ) s_bc_table [k ] = in_pat_len ;
1638
- for (k = 0 ; k < in_pat_len ; k ++ ) s_bc_table [( unsigned char ) in_pattern [k ]] = in_pat_len - 1 - k ;
1638
+ for (k = 0 ; k < in_pat_len ; k ++ ) s_bc_table [in_pattern [k ]] = in_pat_len - 1 - k ;
1639
1639
}
1640
1640
1641
1641
// Delta2 table (dd' algorithm with Rytter correction)
@@ -1683,7 +1683,7 @@ static void boyer_moore_done() {
1683
1683
}
1684
1684
1685
1685
1686
- static char * boyer_moore_search (char * in_text , size_t in_text_len ) {
1686
+ static unsigned char * boyer_moore_search (unsigned char * in_text , size_t in_text_len ) {
1687
1687
size_t i , j ;
1688
1688
1689
1689
if (s_pat_len == 0 ) return in_text ;
@@ -1694,7 +1694,7 @@ static char* boyer_moore_search(char* in_text, size_t in_text_len) {
1694
1694
if (j == 0 ) return in_text + i ;
1695
1695
}
1696
1696
1697
- i += max (s_bc_table [( unsigned char ) in_text [i ]], s_gs_table [j ]);
1697
+ i += max (s_bc_table [in_text [i ]], s_gs_table [j ]);
1698
1698
}
1699
1699
return NULL ;
1700
1700
}
@@ -1815,7 +1815,7 @@ static int write_tree( dir_node_avl *in_avl, write_tree_context *in_context, unu
1815
1815
1816
1816
1817
1817
static int write_file ( dir_node_avl * in_avl , write_tree_context * in_context , unused int in_depth ) {
1818
- char * p = NULL ;
1818
+ unsigned char * p = NULL ;
1819
1819
uint32_t bytes = 0 , size = 0 ;
1820
1820
int err = 0 , fd = -1 , n = 0 , i = 0 ;
1821
1821
size_t len ;
@@ -1849,7 +1849,11 @@ static int write_file( dir_node_avl *in_avl, write_tree_context *in_context, unu
1849
1849
bytes -= n ;
1850
1850
if (s_media_enable && xbe_file ) {
1851
1851
n += i ;
1852
- for (p = s_copy_buffer ; (p = boyer_moore_search (p , n - (long )(p - s_copy_buffer ))) != NULL ; p += XISO_MEDIA_ENABLE_LENGTH ) p [XISO_MEDIA_ENABLE_BYTE_POS ] = XISO_MEDIA_ENABLE_BYTE ;
1852
+ p = s_copy_buffer ;
1853
+ while ((p = boyer_moore_search (p , (size_t )n - (p - s_copy_buffer ))) != NULL ) {
1854
+ p [XISO_MEDIA_ENABLE_BYTE_POS ] = xiso_media_enable_byte ;
1855
+ p += XISO_MEDIA_ENABLE_LENGTH ;
1856
+ }
1853
1857
if (bytes ) {
1854
1858
i = XISO_MEDIA_ENABLE_LENGTH - 1 ;
1855
1859
n -= i ;
@@ -2187,7 +2191,9 @@ static void write_sector( int in_xiso, xoff_t in_start, const char *in_name, con
2187
2191
ssize_t wrote ;
2188
2192
xoff_t curpos = 0 ;
2189
2193
int fp = -1 , err = 0 ;
2190
- char * cwd , * sect = NULL , buf [ 256 ];
2194
+ char buf [256 ];
2195
+ char * cwd ;
2196
+ unsigned char * sect = NULL ;
2191
2197
2192
2198
if ( ( cwd = getcwd ( NULL , 0 ) ) == NULL ) mem_err ();
2193
2199
if ( ! err && chdir ( DEBUG_DUMP_DIRECTORY ) == -1 ) chdir_err ( DEBUG_DUMP_DIRECTORY );
@@ -2198,7 +2204,7 @@ static void write_sector( int in_xiso, xoff_t in_start, const char *in_name, con
2198
2204
if ( ! err && ( curpos = lseek_with_error ( in_xiso , 0 , SEEK_CUR ) ) == -1 ) seek_err ();
2199
2205
if ( ! err && lseek_with_error ( in_xiso , in_start , SEEK_SET ) == -1 ) seek_err ();
2200
2206
2201
- if ( ! err && ( sect = (char * ) malloc ( XISO_SECTOR_SIZE ) ) == NULL ) mem_err ();
2207
+ if ( ! err && ( sect = (unsigned char * ) malloc ( XISO_SECTOR_SIZE ) ) == NULL ) mem_err ();
2202
2208
2203
2209
if ( ! err && read ( in_xiso , sect , XISO_SECTOR_SIZE ) != XISO_SECTOR_SIZE ) read_err ();
2204
2210
if ( ! err && ( wrote = write ( fp , sect , XISO_SECTOR_SIZE ) ) != XISO_SECTOR_SIZE ) write_err ();
0 commit comments