Add YuzuCrypt

This commit is contained in:
2026-04-10 15:29:05 +08:00
parent 122cd17ef5
commit ca24c31ede
2 changed files with 45 additions and 1 deletions

View File

@@ -187,6 +187,7 @@ enum CryptType {
first_xor: u8,
zero_xor: u8,
},
YuzuCrypt,
}
#[derive(Clone, Debug, Deserialize)]
@@ -299,6 +300,7 @@ impl Schema {
*first_xor,
*zero_xor,
)),
CryptType::YuzuCrypt => Box::new(YuzuCrypt::new(self.base.clone())),
})
}
}
@@ -1304,6 +1306,24 @@ impl<R: Read> Read for SmileCryptReader<R> {
}
}
seek_crypt_filehash_key_impl!(YuzuCrypt, YuzuCryptReader<T>);
impl<R: Read> Read for YuzuCryptReader<R> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let readed = self.inner.read(buf)?;
let hash = self.key ^ 0x1DDB6E7A;
let mut key = (hash ^ (hash >> 8) ^ (hash >> 16) ^ (hash >> 24)) as u8;
if key == 0 {
key = 0xD0;
}
for t in (&mut buf[..readed]).iter_mut() {
*t ^= key;
}
self.pos += readed as u64;
Ok(readed)
}
}
#[test]
fn test_deserialize_crypt() {
for (key, schema) in CRYPT_SCHEMA.iter() {
@@ -1311,6 +1331,26 @@ fn test_deserialize_crypt() {
}
}
#[test]
fn check_alias_exists() {
let mut alias = std::collections::HashSet::new();
for (key, schema) in CRYPT_SCHEMA.iter() {
if alias.contains(key.as_str()) {
panic!("Game {} is already used", key);
}
alias.insert(key.to_string());
if let Some(title) = &schema.title {
for part in title.split("|") {
let part = part.trim();
if alias.contains(part) {
panic!("Game alias {} in {} is already used", part, key);
}
alias.insert(part.to_string());
}
}
}
}
#[test]
fn test_cx_cb_table() {
for (key, list) in CX_CB_TABLE.iter() {