@@ -31,9 +31,9 @@ enum WiiDiscWriterState {
3131 /// Setups the data to be written
3232 Init ,
3333 /// Parse the data to be written
34- Parse ( u64 , usize , Vec < u8 > ) ,
34+ Parse ( u64 , u64 , Vec < u8 > ) ,
3535 /// Writing the accumulated data
36- Writing ( u64 , usize , Vec < u8 > , Vec < u8 > ) ,
36+ Writing ( u64 , u64 , Vec < u8 > , Vec < u8 > ) ,
3737
3838 // States for the closing process
3939 SeekToLastGroup ( u64 , Vec < u8 > ) ,
@@ -79,10 +79,10 @@ fn h0_process(sector: &mut WiiSector) {
7979 let hash = & mut sector. hash ;
8080 let data = & sector. data ;
8181 for j in 0 ..consts:: WII_SECTOR_DATA_HASH_COUNT {
82- hash. h0 [ j] . copy_from_slice (
82+ hash. h0 [ j as usize ] . copy_from_slice (
8383 & Sha1 :: from (
84- & data[ j * consts:: WII_SECTOR_DATA_HASH_SIZE
85- ..( j + 1 ) * consts:: WII_SECTOR_DATA_HASH_SIZE ] ,
84+ & data[ ( j * consts:: WII_SECTOR_DATA_HASH_SIZE ) as usize
85+ ..( ( j + 1 ) * consts:: WII_SECTOR_DATA_HASH_SIZE ) as usize ] ,
8686 )
8787 . digest ( )
8888 . bytes ( ) ,
@@ -161,13 +161,13 @@ fn hash_group(group: &mut WiiGroup) -> [u8; consts::WII_HASH_SIZE] {
161161/// Implementation of the Segher's fake signing algorithm
162162fn fake_sign ( part : & mut WiiPartition , hashes : & [ [ u8 ; consts:: WII_HASH_SIZE ] ] ) {
163163 let content = & mut part. tmd . contents [ 0 ] ;
164- let mut hashes_ = Vec :: with_capacity ( consts:: WII_H3_SIZE ) ;
164+ let mut hashes_ = Vec :: with_capacity ( consts:: WII_H3_SIZE as usize ) ;
165165 hashes_. extend ( hashes. iter ( ) . flatten ( ) ) ;
166- hashes_. resize ( consts:: WII_H3_SIZE , 0 ) ;
166+ hashes_. resize ( consts:: WII_H3_SIZE as usize , 0 ) ;
167167 crate :: debug!(
168168 "[fake_sign] Hashes size: 0x{:08X}; Hashes padding size: 0x{:08X}; H3 size: 0x{:08X}" ,
169169 hashes. len( ) * consts:: WII_HASH_SIZE ,
170- consts:: WII_H3_SIZE - hashes. len( ) * consts:: WII_HASH_SIZE ,
170+ consts:: WII_H3_SIZE - hashes. len( ) as u64 * consts:: WII_HASH_SIZE as u64 ,
171171 hashes_. len( )
172172 ) ;
173173 content
@@ -199,7 +199,7 @@ fn encrypt_group(group: &mut WiiGroup, part_key: AesKey) {
199199 let mut iv = [ 0u8 ; consts:: WII_KEY_SIZE ] ;
200200 aes_encrypt_inplace ( sector. hash . as_array_mut ( ) , & iv, & part_key) ;
201201 iv[ ..consts:: WII_KEY_SIZE ] . copy_from_slice (
202- & sector. hash . as_array_mut ( ) [ consts:: WII_SECTOR_IV_OFF ..] [ ..consts:: WII_KEY_SIZE ] ,
202+ & sector. hash . as_array_mut ( ) [ consts:: WII_SECTOR_IV_OFF as usize ..] [ ..consts:: WII_KEY_SIZE ] ,
203203 ) ;
204204 aes_encrypt_inplace ( & mut sector. data , & iv, & part_key) ;
205205 } ;
@@ -307,7 +307,7 @@ where
307307 part. header . tmd_offset = PartHeader :: BLOCK_SIZE as u64 ;
308308 part. header . cert_offset = part. header . tmd_offset + part. header . tmd_size as u64 ;
309309 part. header . h3_offset = std:: cmp:: max (
310- consts:: WII_H3_OFFSET as u64 ,
310+ consts:: WII_H3_OFFSET ,
311311 part. header . cert_offset + part. header . cert_size as u64 ,
312312 ) ;
313313 part. header . data_offset =
@@ -351,15 +351,15 @@ fn prepare_header(part: &mut WiiPartition, hashes: &[[u8; consts::WII_HASH_SIZE]
351351 let part_offset = part. part_offset ;
352352 crate :: debug!( "Partition offset: 0x{part_offset:08X?}" ) ;
353353 crate :: trace!( "Partition Header: {:?}" , part. header) ;
354- let mut buf = Vec :: with_capacity ( part. header . h3_offset as usize + consts:: WII_H3_SIZE ) ;
354+ let mut buf = Vec :: with_capacity ( ( part. header . h3_offset + consts:: WII_H3_SIZE ) as usize ) ;
355355 let h3_padding =
356356 part. header . h3_offset as usize - ( PartHeader :: BLOCK_SIZE + part. tmd . get_size ( ) ) ;
357357 //let mut buf = vec![0u8; PartHeader::BLOCK_SIZE + part.tmd.get_size()];
358358 buf. extend_from_slice ( & <[ u8 ; PartHeader :: BLOCK_SIZE ] >:: from ( & part. header ) ) ;
359359 buf. extend ( std:: iter:: repeat ( 0 ) . take ( part. tmd . get_size ( ) + h3_padding) ) ;
360360 buf. extend ( hashes. iter ( ) . flatten ( ) ) ;
361361 buf. extend (
362- std:: iter:: repeat ( 0 ) . take ( consts:: WII_H3_SIZE - hashes. len ( ) * consts:: WII_HASH_SIZE ) ,
362+ std:: iter:: repeat ( 0 ) . take ( ( consts:: WII_H3_SIZE - hashes. len ( ) as u64 * consts:: WII_HASH_SIZE as u64 ) as usize ) ,
363363 ) ;
364364 TitleMetaData :: set_partition ( & mut buf, PartHeader :: BLOCK_SIZE , & part. tmd ) ;
365365 buf
@@ -393,8 +393,8 @@ where
393393 // The "virtual" start and end, in the sense that they are the positions within the decrypted partition.
394394 let vstart = status. cursor ;
395395 let vend = vstart + buf. len ( ) as u64 ;
396- let start_blk_idx = ( vstart / consts:: WII_SECTOR_DATA_SIZE as u64 ) as usize ;
397- let end_blk_idx = ( ( vend - 1 ) / consts:: WII_SECTOR_DATA_SIZE as u64 ) as usize ;
396+ let start_blk_idx = vstart / consts:: WII_SECTOR_DATA_SIZE ;
397+ let end_blk_idx = ( vend - 1 ) / consts:: WII_SECTOR_DATA_SIZE ;
398398 let start_group_idx = start_blk_idx / 64 ;
399399 let start_block_idx_in_group = start_blk_idx % 64 ;
400400 let end_group_idx = end_blk_idx / 64 ;
@@ -445,12 +445,12 @@ where
445445 for i in start_blk..=end_blk {
446446 // Offsets in the group buffer (decrypted address)
447447 let buffer_start =
448- std:: cmp:: max ( cursor, ( i as u64 ) * consts:: WII_SECTOR_DATA_SIZE as u64 )
449- % consts:: WII_SECTOR_DATA_SIZE as u64 ;
448+ std:: cmp:: max ( cursor, i * consts:: WII_SECTOR_DATA_SIZE )
449+ % consts:: WII_SECTOR_DATA_SIZE ;
450450 let buffer_end = std:: cmp:: min (
451451 ( cursor + in_buf. len ( ) as u64 ) - 1 ,
452- ( i as u64 + 1 ) * consts:: WII_SECTOR_DATA_SIZE as u64 - 1 ,
453- ) % consts:: WII_SECTOR_DATA_SIZE as u64
452+ ( i + 1 ) * consts:: WII_SECTOR_DATA_SIZE - 1 ,
453+ ) % consts:: WII_SECTOR_DATA_SIZE
454454 + 1 ;
455455 let size = ( buffer_end - buffer_start) as usize ;
456456 assert ! ( size <= 0x7C00 ) ;
@@ -459,30 +459,30 @@ where
459459 i,
460460 buffer_start,
461461 buffer_end,
462- curr_buf. len( ) - ( buffer_end - buffer_start) as usize ,
462+ curr_buf. len( ) as u64 - ( buffer_end - buffer_start) ,
463463 ) ;
464464 let data;
465465 ( data, curr_buf) = curr_buf. split_at ( size) ;
466- status. group . sub_groups [ ( i / 8 ) % 8 ] . sectors [ i % 8 ] . data
466+ status. group . sub_groups [ ( ( i / 8 ) % 8 ) as usize ] . sectors [ ( i % 8 ) as usize ] . data
467467 [ buffer_start as usize ..buffer_end as usize ]
468468 . copy_from_slice ( data) ;
469- if buffer_end == consts:: WII_SECTOR_DATA_SIZE as u64 * 64 {
469+ if buffer_end == consts:: WII_SECTOR_DATA_SIZE * 64 {
470470 crate :: trace!( "Reached end of group #{}" , group_idx) ;
471471 }
472472 }
473473 if ( status. cursor + ( buf. len ( ) - curr_buf. len ( ) ) as u64 )
474- % ( consts:: WII_SECTOR_DATA_SIZE as u64 * 64 )
474+ % ( consts:: WII_SECTOR_DATA_SIZE * 64 )
475475 == 0
476476 {
477477 // We are at the start of a group. We can hash and encrypt the group and write it.
478478 crate :: trace!( "Hashing and encrypting group #{}" , group_idx) ;
479- if status. hashes . len ( ) <= group_idx {
479+ if status. hashes . len ( ) as u64 <= group_idx {
480480 status
481481 . hashes
482- . resize ( group_idx + 1 , [ 0u8 ; consts:: WII_HASH_SIZE ] ) ;
482+ . resize ( group_idx as usize + 1 , [ 0u8 ; consts:: WII_HASH_SIZE ] ) ;
483483 }
484484 let group_hash = hash_group ( & mut status. group ) ;
485- status. hashes [ group_idx] . copy_from_slice ( & group_hash) ;
485+ status. hashes [ group_idx as usize ] . copy_from_slice ( & group_hash) ;
486486 let part_key =
487487 decrypt_title_key ( & status. disc . partitions . partitions [ part_idx] . header . ticket ) ;
488488 if !status. disc . disc_header . disable_disc_encrypt {
@@ -528,11 +528,11 @@ where
528528 cx. waker ( ) . wake_by_ref ( ) ;
529529 Poll :: Pending
530530 } else {
531- if cursor % ( consts:: WII_SECTOR_DATA_SIZE as u64 * 64 ) == 0 {
532- cursor += consts:: WII_SECTOR_DATA_SIZE as u64 * 64 ;
531+ if cursor % ( consts:: WII_SECTOR_DATA_SIZE * 64 ) == 0 {
532+ cursor += consts:: WII_SECTOR_DATA_SIZE * 64 ;
533533 } else {
534- cursor = ( cursor / ( consts:: WII_SECTOR_DATA_SIZE as u64 * 64 ) + 1 )
535- * consts:: WII_SECTOR_DATA_SIZE as u64
534+ cursor = ( cursor / ( consts:: WII_SECTOR_DATA_SIZE * 64 ) + 1 )
535+ * consts:: WII_SECTOR_DATA_SIZE
536536 * 64 ;
537537 }
538538 if curr_buf. is_empty ( ) {
@@ -614,7 +614,7 @@ where
614614 encrypt_group ( & mut status. group , part_key) ;
615615 }
616616
617- status. state = if status. cursor % ( consts:: WII_SECTOR_DATA_SIZE as u64 * 64 ) != 0 {
617+ status. state = if status. cursor % ( consts:: WII_SECTOR_DATA_SIZE * 64 ) != 0 {
618618 WiiDiscWriterState :: SeekToLastGroup ( n_group - 1 , status. group . to_vec ( ) )
619619 } else {
620620 let hashes = status. hashes . clone ( ) ;
0 commit comments