Add support to read int password from exe file

This commit is contained in:
2025-08-15 15:29:21 +08:00
parent 8f24b5aa02
commit bd9ba85687
9 changed files with 141 additions and 3 deletions

View File

@@ -11,6 +11,8 @@ use overf::wrapping;
use std::io::{Read, Seek, SeekFrom};
use std::sync::{Arc, Mutex};
pub use super::int_password::get_password_from_exe;
#[derive(Debug)]
/// Builder for CatSystem2 Archive scripts.
pub struct CSIntArcBuilder {}

View File

@@ -0,0 +1,38 @@
//! Get Password from CatSystem2 Executable
use crate::types::*;
use crate::utils::blowfish::{Blowfish, BlowfishLE};
use crate::utils::encoding::*;
use anyhow::Result;
use pelite::FileMap;
use pelite::pe32::*;
use std::path::Path;
/// Retrieves the int archive's password from a CatSystem2 executable file.
pub fn get_password_from_exe<S: AsRef<Path> + ?Sized>(exe_path: &S) -> Result<String> {
let path = exe_path.as_ref();
let file_map = FileMap::open(path)?;
let file = PeFile::from_bytes(&file_map)?;
let resources = file.resources()?;
let mut code = resources
.find_resource(&["V_CODE2".into(), "DATA".into()])?
.to_vec();
if code.len() < 8 {
return Err(anyhow::anyhow!("Invalid V_CODE2 resource length"));
}
let key = resources
.find_resource(&["KEY_CODE".into(), "KEY".into()])
.map(|s| {
let mut s = s.to_vec();
for i in s.iter_mut() {
*i ^= 0xCD;
}
s
})
.unwrap_or_else(|_| b"windmill".to_vec());
let blowfish: BlowfishLE = Blowfish::new(&key)?;
blowfish.decrypt_block(&mut code);
let len = code.iter().position(|&x| x == 0).unwrap_or(code.len());
let result = decode_to_string(Encoding::Cp932, &code[..len], true)?;
eprintln!("Used password from CatSystem2 executable: {}", result);
Ok(result)
}

View File

@@ -1,3 +1,4 @@
//! CatSystem2 Archive
pub mod int;
mod int_password;
mod twister;