Skip to content

Commit e73622d

Browse files
authored
Merge pull request #5 from R-YaTian/patch3
Fix decrypting exefs which encrypted via seed crypto
2 parents 2247ec8 + 4edd03d commit e73622d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn scramblekey(key_x: u128, key_y: u128) -> u128 {
9797
rol(value, 87)
9898
}
9999

100-
fn dump_section(ncch: &mut File, cia: &mut CiaReader, offset: u64, size: u32, sec_type: NcchSection, sec_idx: usize, ctr: [u8; 16], uses_extra_crypto: u8, fixed_crypto: u8, encrypted: bool, keyys: [u128; 2]) {
100+
fn dump_section(ncch: &mut File, cia: &mut CiaReader, offset: u64, size: u32, sec_type: NcchSection, sec_idx: usize, ctr: [u8; 16], uses_extra_crypto: u8, fixed_crypto: u8, use_seed_crypto: bool, encrypted: bool, keyys: [u128; 2]) {
101101
let sections = ["ExHeader", "ExeFS", "RomFS"];
102102
const CHUNK: u32 = 4194304; // 4 MiB
103103
debug!(" {} offset: {:08X}", sections[sec_idx], offset);
@@ -163,7 +163,7 @@ fn dump_section(ncch: &mut File, cia: &mut CiaReader, offset: u64, size: u32, se
163163
.unwrap()
164164
.apply_keystream(&mut exetmp);
165165

166-
if flag_to_bool(uses_extra_crypto) {
166+
if flag_to_bool(uses_extra_crypto) || use_seed_crypto {
167167
let mut exetmp2 = exedata;
168168
key = u128::to_be_bytes(scramblekey(KEYS_0[get_crypto_key(&uses_extra_crypto)], keyys[1]));
169169

@@ -400,17 +400,17 @@ fn parse_ncch(cia: &mut CiaReader, offs: u64, mut titleid: [u8; 8]) {
400400
let mut counter: [u8; 16];
401401
if header.exhdrsize != 0 {
402402
counter = get_ncch_aes_counter(&header, NcchSection::ExHeader);
403-
dump_section(&mut ncch, cia, 512, header.exhdrsize * 2, NcchSection::ExHeader, 0, counter, uses_extra_crypto, fixed_crypto, encrypted, [ncch_key_y, key_y]);
403+
dump_section(&mut ncch, cia, 512, header.exhdrsize * 2, NcchSection::ExHeader, 0, counter, uses_extra_crypto, fixed_crypto, use_seed_crypto, encrypted, [ncch_key_y, key_y]);
404404
}
405405

406406
if header.exefssize != 0 {
407407
counter = get_ncch_aes_counter(&header, NcchSection::ExeFS);
408-
dump_section(&mut ncch, cia, (header.exefsoffset * MEDIA_UNIT_SIZE) as u64, header.exefssize * MEDIA_UNIT_SIZE, NcchSection::ExeFS, 1, counter, uses_extra_crypto, fixed_crypto, encrypted, [ncch_key_y, key_y]);
408+
dump_section(&mut ncch, cia, (header.exefsoffset * MEDIA_UNIT_SIZE) as u64, header.exefssize * MEDIA_UNIT_SIZE, NcchSection::ExeFS, 1, counter, uses_extra_crypto, fixed_crypto, use_seed_crypto, encrypted, [ncch_key_y, key_y]);
409409
}
410410

411411
if header.romfssize != 0 {
412412
counter = get_ncch_aes_counter(&header, NcchSection::RomFS);
413-
dump_section(&mut ncch, cia, (header.romfsoffset * MEDIA_UNIT_SIZE) as u64, header.romfssize * MEDIA_UNIT_SIZE, NcchSection::RomFS, 2, counter, uses_extra_crypto, fixed_crypto, encrypted, [ncch_key_y, key_y]);
413+
dump_section(&mut ncch, cia, (header.romfsoffset * MEDIA_UNIT_SIZE) as u64, header.romfssize * MEDIA_UNIT_SIZE, NcchSection::RomFS, 2, counter, uses_extra_crypto, fixed_crypto, use_seed_crypto, encrypted, [ncch_key_y, key_y]);
414414
}
415415

416416
info!("{}", base);

0 commit comments

Comments
 (0)