3 Commits

Author SHA1 Message Date
f4e4a48aa3 Add MiburoCrypt 2026-05-02 22:08:07 +08:00
aa40b2aa7b Add UTF-16 LE mark to stream 2026-05-02 19:42:04 +08:00
6d7cf5f42e Add support to decompress file in ××な彼女のつくりかた2 2026-05-02 19:27:08 +08:00
2 changed files with 157 additions and 1 deletions

View File

@@ -177,6 +177,10 @@
"$type": "HashCrypt",
"Title": "ばぁばとママとの超熟母娘丼 ~3世代での家庭内エッチ~ | 爱你深至夏海蔚蓝"
},
"Bakumatsu Jinchuu Houkoku Resshiden Miburo": {
"$type": "MiburoCrypt",
"Title": "幕末尽忠報国烈士伝 MIBURO"
},
"Bakunyuu Oyakodon": {
"$type": "DieselmineCrypt",
"Title": "爆乳母娘丼 ~仕事先の親子が寝取りやすそうな件~"

View File

@@ -258,6 +258,7 @@ enum CryptType {
},
SyangrilaSmartCrypt,
Kano2Crypt,
MiburoCrypt,
}
#[derive(Clone, Debug, Deserialize)]
@@ -408,6 +409,7 @@ impl Schema {
)),
CryptType::SyangrilaSmartCrypt => Box::new(SyangrilaSmartCrypt::new(self.base.clone())),
CryptType::Kano2Crypt => Box::new(Kano2Crypt::new(self.base.clone())),
CryptType::MiburoCrypt => Box::new(MiburoCrypt::new(self.base.clone())),
})
}
}
@@ -2205,7 +2207,86 @@ impl<R: Read> Read for SyangrilaSmartCryptReader<R> {
}
}
seek_crypt_filehash_key_u8_impl!(Kano2Crypt, Kano2CryptReader<T>);
const WARC_MAGIC: &[u8] = b"warc";
const WARC_TYPE_KEY: [u8; 3] = [0x27, 0xaf, 0x67];
const WARC_SIZE_KEY: [u8; 4] = [0x7d, 0x16, 0x9f, 0xf1];
#[derive(Debug)]
pub struct Kano2Crypt {
base: BaseSchema,
}
impl Kano2Crypt {
pub fn new(base: BaseSchema) -> Self {
Self { base }
}
}
impl Crypt for Kano2Crypt {
base_schema_impl!();
fn decrypt_supported(&self) -> bool {
true
}
fn decrypt_seek_supported(&self) -> bool {
true
}
fn decrypt<'a>(
&self,
entry: &Xp3Entry,
cur_seg: &Segment,
stream: Box<dyn Read + Send + Sync + 'a>,
) -> Result<Box<dyn ReadDebug + Send + Sync + 'a>> {
Ok(Box::new(Kano2CryptReader::new(
stream,
cur_seg,
entry.file_hash as u8,
)))
}
fn decrypt_with_seek<'a>(
&self,
entry: &Xp3Entry,
cur_seg: &Segment,
stream: Box<dyn ReadSeek + Send + Sync + 'a>,
) -> Result<Box<dyn ReadSeek + Send + Sync + 'a>> {
Ok(Box::new(Kano2CryptReader::new(
stream,
cur_seg,
entry.file_hash as u8,
)))
}
fn need_filter(&self, _filename: &str, buf: &[u8], buf_len: usize) -> bool {
buf_len >= 4 && buf.starts_with(WARC_MAGIC)
}
fn filter<'a>(&self, mut entry: Entry<'a>) -> Result<Box<dyn ReadDebug + Send + Sync + 'a>> {
let mut magic = [0; 4];
entry.read_exact(&mut magic)?;
if &magic != WARC_MAGIC {
anyhow::bail!("Unsupported magic: {:?}.", magic);
}
let mut typ = [0; 3];
entry.read_exact(&mut typ)?;
for i in 0..3 {
typ[i] ^= WARC_TYPE_KEY[i];
}
if &typ != b"STR" && &typ != b"OCT" && &typ != b"AOD" && &typ != b"INT" && &typ != b"REL" {
eprintln!("WARNING: Unknown type key: {:?}", typ);
crate::COUNTER.inc_warning();
}
let mut size = [0; 4];
entry.read_exact(&mut size)?;
for i in 0..4 {
size[i] ^= typ[0] ^ WARC_SIZE_KEY[i];
}
let _uncompressed_size = u32::from_le_bytes(size);
let reader = flate2::read::ZlibDecoder::new(entry);
if &typ == b"STR" {
return Ok(Box::new(PrefixStream::new(vec![0xFF, 0xFE], reader)));
}
Ok(Box::new(reader))
}
}
seek_reader_key_impl!(Kano2CryptReader<T>, u8);
impl<R: Read> Read for Kano2CryptReader<R> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
@@ -2222,6 +2303,77 @@ impl<R: Read> Read for Kano2CryptReader<R> {
}
}
#[derive(Debug)]
pub struct MiburoCrypt {
base: BaseSchema,
}
impl MiburoCrypt {
pub fn new(base: BaseSchema) -> Self {
Self { base }
}
fn init_key(mut hash: u32) -> [u8; 29] {
hash &= 0x1FFFFFFF;
hash |= (hash & 1) << 29;
let mut key = [0; 29];
for i in 0..29 {
key[i] = hash as u8;
hash = (hash >> 8) | ((hash << 0x15) & 0xFF000000);
}
key
}
}
impl Crypt for MiburoCrypt {
base_schema_impl!();
fn decrypt_supported(&self) -> bool {
true
}
fn decrypt_seek_supported(&self) -> bool {
true
}
fn decrypt<'a>(
&self,
entry: &Xp3Entry,
cur_seg: &Segment,
stream: Box<dyn Read + Send + Sync + 'a>,
) -> Result<Box<dyn ReadDebug + Send + Sync + 'a>> {
Ok(Box::new(MiburoCryptReader::new(
stream,
cur_seg,
Self::init_key(entry.file_hash),
)))
}
fn decrypt_with_seek<'a>(
&self,
entry: &Xp3Entry,
cur_seg: &Segment,
stream: Box<dyn ReadSeek + Send + Sync + 'a>,
) -> Result<Box<dyn ReadSeek + Send + Sync + 'a>> {
Ok(Box::new(MiburoCryptReader::new(
stream,
cur_seg,
Self::init_key(entry.file_hash),
)))
}
}
seek_reader_key_impl!(MiburoCryptReader<T>, [u8; 29]);
impl<R: Read> Read for MiburoCryptReader<R> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let readed = self.inner.read(buf)?;
let mut offset = ((self.seg_start + self.pos) % 29) as usize;
for t in buf[..readed].iter_mut() {
*t ^= self.key[offset];
offset = (offset + 1) % 29;
}
self.pos += readed as u64;
Ok(readed)
}
}
#[test]
fn test_deserialize_crypt() {
for (key, schema) in CRYPT_SCHEMA.iter() {