@@ -36,7 +36,7 @@ static bool is_iso_file(const fs::file& file, u64* size = nullptr)
3636
3737 file.read_at (32768ULL + 1 , magic, 5 );
3838
39- bool ret = magic[0 ] == ' C' && magic[1 ] == ' D' && magic[2 ] == ' 0' && magic[3 ] == ' 0' && magic[4 ] == ' 1' ;
39+ const bool ret = magic[0 ] == ' C' && magic[1 ] == ' D' && magic[2 ] == ' 0' && magic[3 ] == ' 0' && magic[4 ] == ' 1' ;
4040
4141 if (size && ret)
4242 {
@@ -48,12 +48,17 @@ static bool is_iso_file(const fs::file& file, u64* size = nullptr)
4848
4949bool is_iso_file (const std::string& path, u64 * size, bool * is_raw_device)
5050{
51+ if (path.empty ())
52+ {
53+ return false ;
54+ }
55+
5156 std::string new_path = path;
5257
5358 // "new_path" is updated with the raw device path in case "path" points to a BD drive
54- bool raw_device = fs::get_optical_raw_device (path, &new_path);
59+ const bool raw_device = fs::get_optical_raw_device (path, &new_path);
5560
56- if (path. empty () || ( !raw_device && fs::is_dir (path) ))
61+ if (!raw_device && fs::is_dir (path))
5762 {
5863 return false ;
5964 }
@@ -86,7 +91,7 @@ static void reset_iv(std::array<u8, 16>& iv, u32 lba)
8691}
8792
8893// Main function that will decrypt the sector(s)
89- static bool decrypt_data (aes_context& aes, u64 offset, unsigned char * buffer, unsigned char * out_buffer, u64 size)
94+ static bool decrypt_data (aes_context& aes, u64 offset, const unsigned char * buffer, unsigned char * out_buffer, u64 size)
9095{
9196 // The following preliminary checks are good to be provided.
9297 // Commented out to gain a bit of performance, just because we know the caller is providing values in the expected range
@@ -115,7 +120,7 @@ static bool decrypt_data(aes_context& aes, u64 offset, unsigned char* buffer, un
115120 // Otherwise, the IV is based on sector's LBA
116121 if (sector_offset != 0 )
117122 {
118- memcpy (iv.data (), buffer, 16 );
123+ std:: memcpy (iv.data (), buffer, 16 );
119124 cur_offset = 16 ;
120125 }
121126 else
@@ -190,7 +195,7 @@ iso_type_status iso_file_decryption::get_key(const std::string& key_path, aes_co
190195 // binary (".key") and so not needing any further conversion from hex string to bytes
191196 if (key_len == sizeof (key))
192197 {
193- memcpy (key.data (), key_str, sizeof (key));
198+ std:: memcpy (key.data (), key_str, sizeof (key));
194199 }
195200 else
196201 {
@@ -271,7 +276,7 @@ iso_type_status iso_file_decryption::retrieve_key(iso_archive& archive, std::str
271276
272277 for (auto path_it = entries.begin (); path_it != entries.end (); path_it++)
273278 {
274- auto dir_entry = std::move (*path_it);
279+ const auto dir_entry = std::move (*path_it);
275280
276281 if (dir_entry.name == " ." || dir_entry.name == " .." || dir_entry.is_directory )
277282 {
@@ -293,7 +298,7 @@ iso_type_status iso_file_decryption::retrieve_key(iso_archive& archive, std::str
293298 }
294299
295300 // If the decrypted data match the magic value
296- if (memcmp (magic_value.data (), dec_sec.data (), magic_value.size ()) == 0 )
301+ if (std:: memcmp (magic_value.data (), dec_sec.data (), magic_value.size ()) == 0 )
297302 {
298303 return iso_type_status::REDUMP_ISO ;
299304 }
@@ -447,12 +452,12 @@ bool iso_file_decryption::init(const std::string& path, iso_archive* archive)
447452 static const unsigned char k3k3y_dec_watermark[16 ] =
448453 {0x44 , 0x6E , 0x63 , 0x72 , 0x79 , 0x70 , 0x74 , 0x65 , 0x64 , 0x20 , 0x33 , 0x4B , 0x20 , 0x42 , 0x4C , 0x44 };
449454
450- if (memcmp (&k3k3y_enc_watermark[0 ], &sec0_sec1[0xF70 ], sizeof (k3k3y_enc_watermark)) == 0 )
455+ if (std:: memcmp (&k3k3y_enc_watermark[0 ], &sec0_sec1[0xF70 ], sizeof (k3k3y_enc_watermark)) == 0 )
451456 {
452457 // Grab D1 from the 3k3y sector
453458 unsigned char key[16 ];
454459
455- memcpy (key, &sec0_sec1[0xF80 ], 0x10 );
460+ std:: memcpy (key, &sec0_sec1[0xF80 ], 0x10 );
456461
457462 // Convert D1 to KEY and generate the "m_aes_dec" context
458463 unsigned char key_d1[] = {0x38 , 11 , 0xcf , 11 , 0x53 , 0x45 , 0x5b , 60 , 120 , 0x17 , 0xab , 0x4f , 0xa3 , 0xba , 0x90 , 0xed };
@@ -476,7 +481,7 @@ bool iso_file_decryption::init(const std::string& path, iso_archive* archive)
476481 iso_log.error (" init: Failed to set encryption type to ENC_3K3Y: %s" , path);
477482 }
478483 }
479- else if (memcmp (&k3k3y_dec_watermark[0 ], &sec0_sec1[0xF70 ], sizeof (k3k3y_dec_watermark)) == 0 )
484+ else if (std:: memcmp (&k3k3y_dec_watermark[0 ], &sec0_sec1[0xF70 ], sizeof (k3k3y_dec_watermark)) == 0 )
480485 {
481486 m_enc_type = iso_encryption_type::DEC_3K3Y ; // SET ENCRYPTION TYPE: DEC_3K3Y
482487 }
@@ -592,12 +597,10 @@ u64 iso_file_encrypted::read_at(u64 offset, void* buffer, u64 size)
592597 }
593598
594599 const u64 archive_first_offset = file_offset (offset);
595- const u64 archive_last_offset = archive_first_offset + max_size - 1 ;
596- u64 total_read;
600+ const u64 archive_last_offset = archive_first_offset + max_size - 1 ;;
597601
598602 iso_sector first_sec, last_sec;
599- u64 offset_aligned;
600- u64 offset_aligned_first_out;
603+ u64 offset_aligned_first_out = 0 ;
601604
602605 first_sec.lba_address = (archive_first_offset / ISO_SECTOR_SIZE ) * ISO_SECTOR_SIZE ;
603606 first_sec.offset = archive_first_offset % ISO_SECTOR_SIZE ;
@@ -613,7 +616,7 @@ u64 iso_file_encrypted::read_at(u64 offset, void* buffer, u64 size)
613616
614617 if (!m_raw_device)
615618 {
616- offset_aligned = first_sec.offset & ~0xF ;
619+ const u64 offset_aligned = first_sec.offset & ~0xF ;
617620 offset_aligned_first_out = (first_sec.offset + first_sec.size ) & ~0xF ;
618621
619622 first_sec.offset_aligned = offset_aligned != 0 ? offset_aligned - 16 : 0 ; // Eventually include the previous block (used as IV)
@@ -629,12 +632,12 @@ u64 iso_file_encrypted::read_at(u64 offset, void* buffer, u64 size)
629632 first_sec.address_aligned = first_sec.lba_address ;
630633 }
631634
632- total_read = m_file.read_at (first_sec.address_aligned , &reinterpret_cast <u8 *>(m_buf)[first_sec.offset_aligned ], first_sec.size_aligned );
635+ u64 total_read = m_file.read_at (first_sec.address_aligned , &reinterpret_cast <u8 *>(m_buf)[first_sec.offset_aligned ], first_sec.size_aligned );
633636
634637 m_dec->decrypt (first_sec.address_aligned , &reinterpret_cast <u8 *>(m_buf)[first_sec.offset_aligned ], first_sec.size_aligned , m_meta.name );
635- memcpy (buffer, &reinterpret_cast <u8 *>(m_buf)[first_sec.offset ], first_sec.size );
638+ std:: memcpy (buffer, &reinterpret_cast <u8 *>(m_buf)[first_sec.offset ], first_sec.size );
636639
637- u64 sector_count = (last_sec.lba_address - first_sec.lba_address ) / ISO_SECTOR_SIZE + 1 ;
640+ const u64 sector_count = (last_sec.lba_address - first_sec.lba_address ) / ISO_SECTOR_SIZE + 1 ;
638641
639642 if (sector_count < 2 ) // If no more sector(s)
640643 {
@@ -658,7 +661,7 @@ u64 iso_file_encrypted::read_at(u64 offset, void* buffer, u64 size)
658661 {
659662 if (!m_raw_device)
660663 {
661- u64 inner_sector_size = (sector_count - 2 ) * ISO_SECTOR_SIZE ;
664+ const u64 inner_sector_size = (sector_count - 2 ) * ISO_SECTOR_SIZE ;
662665
663666 total_read += m_file.read_at (first_sec.lba_address + ISO_SECTOR_SIZE , &reinterpret_cast <u8 *>(buffer)[first_sec.size ], inner_sector_size);
664667
@@ -673,7 +676,7 @@ u64 iso_file_encrypted::read_at(u64 offset, void* buffer, u64 size)
673676 total_read += m_file.read_at (first_sec.lba_address + ISO_SECTOR_SIZE + inner_sector_offset, m_buf, ISO_SECTOR_SIZE );
674677
675678 m_dec->decrypt (first_sec.lba_address + ISO_SECTOR_SIZE + inner_sector_offset, m_buf, ISO_SECTOR_SIZE , m_meta.name );
676- memcpy (&reinterpret_cast <u8 *>(buffer)[first_sec.size + inner_sector_offset], m_buf, ISO_SECTOR_SIZE );
679+ std:: memcpy (&reinterpret_cast <u8 *>(buffer)[first_sec.size + inner_sector_offset], m_buf, ISO_SECTOR_SIZE );
677680 }
678681 }
679682 }
@@ -696,7 +699,7 @@ u64 iso_file_encrypted::read_at(u64 offset, void* buffer, u64 size)
696699 total_read += m_file.read_at (last_sec.address_aligned , m_buf, last_sec.size_aligned );
697700
698701 m_dec->decrypt (last_sec.address_aligned , m_buf, last_sec.size_aligned , m_meta.name );
699- memcpy (&reinterpret_cast <u8 *>(buffer)[max_size - last_sec.size ], m_buf, last_sec.size );
702+ std:: memcpy (&reinterpret_cast <u8 *>(buffer)[max_size - last_sec.size ], m_buf, last_sec.size );
700703
701704 //
702705 // As last, check for an unlikely reading error (decoding also failed due to use of partially initialized buffer)
@@ -1120,7 +1123,7 @@ psf::registry iso_archive::open_psf(const std::string& path)
11201123
11211124iso_file::iso_file (const std::string& path, bs_t <fs::open_mode> mode)
11221125{
1123- m_file = std::move ( fs::file (path, mode) );
1126+ m_file = fs::file (path, mode);
11241127
11251128 if (!m_file)
11261129 {
@@ -1134,7 +1137,7 @@ iso_file::iso_file(const std::string& path, bs_t<fs::open_mode> mode)
11341137
11351138 m_file.seek (m_meta.extents [0 ].start * ISO_SECTOR_SIZE );
11361139
1137- m_raw_device = fs::is_optical_raw_device (path) ? true : false ;
1140+ m_raw_device = fs::is_optical_raw_device (path);
11381141
11391142 // IMPORTANT NOTE: It must be aligned (probably enough on multiple of 4) to support raw device, otherwise any read from file will fail
11401143#if defined(_WIN32)
@@ -1147,7 +1150,7 @@ iso_file::iso_file(const std::string& path, bs_t<fs::open_mode> mode)
11471150iso_file::iso_file (const std::string& path, bs_t <fs::open_mode> mode, const iso_fs_node& node)
11481151 : m_meta(node.metadata)
11491152{
1150- m_file = std::move ( fs::file (path, mode) );
1153+ m_file = fs::file (path, mode);
11511154
11521155 if (!m_file)
11531156 {
@@ -1158,7 +1161,7 @@ iso_file::iso_file(const std::string& path, bs_t<fs::open_mode> mode, const iso_
11581161
11591162 m_file.seek (m_meta.extents [0 ].start * ISO_SECTOR_SIZE );
11601163
1161- m_raw_device = fs::is_optical_raw_device (path) ? true : false ;
1164+ m_raw_device = fs::is_optical_raw_device (path);
11621165
11631166 // IMPORTANT NOTE: It must be aligned (probably enough on multiple of 4) to support raw device, otherwise any read from file will fail
11641167#if defined(_WIN32)
@@ -1248,12 +1251,11 @@ u64 iso_file::read_at(u64 offset, void* buffer, u64 size)
12481251 }
12491252
12501253 const u64 archive_first_offset = file_offset (offset);
1251- u64 total_read;
12521254
12531255 // If it's not a raw device
12541256 if (!m_raw_device)
12551257 {
1256- total_read = m_file.read_at (archive_first_offset, buffer, max_size);
1258+ u64 total_read = m_file.read_at (archive_first_offset, buffer, max_size);
12571259
12581260 if (total_read != max_size)
12591261 {
@@ -1303,11 +1305,11 @@ u64 iso_file::read_at(u64 offset, void* buffer, u64 size)
13031305 // First sector
13041306 //
13051307
1306- total_read = m_file.read_at (first_sec.lba_address , m_buf, ISO_SECTOR_SIZE );
1308+ u64 total_read = m_file.read_at (first_sec.lba_address , m_buf, ISO_SECTOR_SIZE );
13071309
1308- memcpy (buffer, &reinterpret_cast <u8 *>(m_buf)[first_sec.offset ], first_sec.size );
1310+ std:: memcpy (buffer, &reinterpret_cast <u8 *>(m_buf)[first_sec.offset ], first_sec.size );
13091311
1310- u64 sector_count = (last_sec.lba_address - first_sec.lba_address ) / ISO_SECTOR_SIZE + 1 ;
1312+ const u64 sector_count = (last_sec.lba_address - first_sec.lba_address ) / ISO_SECTOR_SIZE + 1 ;
13111313
13121314 if (sector_count < 2 ) // If no more sector(s)
13131315 {
@@ -1335,7 +1337,7 @@ u64 iso_file::read_at(u64 offset, void* buffer, u64 size)
13351337 {
13361338 total_read += m_file.read_at (first_sec.lba_address + ISO_SECTOR_SIZE + sector_offset, m_buf, ISO_SECTOR_SIZE );
13371339
1338- memcpy (&reinterpret_cast <u8 *>(buffer)[first_sec.size + sector_offset], m_buf, ISO_SECTOR_SIZE );
1340+ std:: memcpy (&reinterpret_cast <u8 *>(buffer)[first_sec.size + sector_offset], m_buf, ISO_SECTOR_SIZE );
13391341 }
13401342 }
13411343
@@ -1345,7 +1347,7 @@ u64 iso_file::read_at(u64 offset, void* buffer, u64 size)
13451347
13461348 total_read += m_file.read_at (last_sec.address_aligned , m_buf, ISO_SECTOR_SIZE );
13471349
1348- memcpy (&reinterpret_cast <u8 *>(buffer)[max_size - last_sec.size ], m_buf, last_sec.size );
1350+ std:: memcpy (&reinterpret_cast <u8 *>(buffer)[max_size - last_sec.size ], m_buf, last_sec.size );
13491351
13501352 //
13511353 // As last, check for an unlikely reading error
0 commit comments