mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-18 23:27:48 -04:00
Added rustii CLI wad edit command and required library features
This required a LOT more backend work than I expected. But hey, some of this stuff is being done better than it was in libWiiPy/WiiPy, so that's a win in my book. When changing both the Title ID and type of a WAD, the updated TID will only be written once (which also means the Title Key will only be re-encrypted once). This is an improvement over WiiPy where it will be updated as part of both changes. Some TMD fields have been made private and moved to getter/setter methods only as they are actually in use now and should only be set through the correct means.
This commit is contained in:
@@ -7,6 +7,7 @@ use std::io::{Cursor, Read, Write};
|
||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||
use sha1::{Sha1, Digest};
|
||||
use thiserror::Error;
|
||||
use crate::title::crypto;
|
||||
use crate::title::crypto::decrypt_title_key;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
@@ -43,7 +44,7 @@ pub struct Ticket {
|
||||
unknown1: [u8; 1],
|
||||
pub ticket_id: [u8; 8],
|
||||
pub console_id: [u8; 4],
|
||||
pub title_id: [u8; 8],
|
||||
title_id: [u8; 8],
|
||||
unknown2: [u8; 2],
|
||||
pub title_version: u16,
|
||||
pub permitted_titles_mask: [u8; 4],
|
||||
@@ -232,4 +233,18 @@ impl Ticket {
|
||||
self.signature_issuer = issuer.try_into().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets the Title ID of the Ticket.
|
||||
pub fn title_id(&self) -> [u8; 8] {
|
||||
self.title_id
|
||||
}
|
||||
|
||||
/// Sets a new Title ID for the Ticket. This will re-encrypt the Title Key, since the Title ID
|
||||
/// is used as the IV for decrypting the Title Key.
|
||||
pub fn set_title_id(&mut self, title_id: [u8; 8]) -> Result<(), TicketError> {
|
||||
let new_enc_title_key = crypto::encrypt_title_key(self.dec_title_key(), self.common_key_index, title_id, self.is_dev());
|
||||
self.title_key = new_enc_title_key;
|
||||
self.title_id = title_id;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user