Function decrypt_archive

Source
pub fn decrypt_archive(data: &[u8]) -> Result<Vec<DecryptedFile>, ExtractError>
Expand description

A convenience function to decrypt an archive in a single call.

This is a wrapper around Decrypter::decrypt with automatic initialization.

§Parameters

  • data: The content of the archive file.

§Returns

  • Ok(Vec<DecryptedFile>) if files were successfully decrypted.
  • Err(ExtractError::InvalidHeader) for invalid header.
  • Err(ExtractError::InvalidEngine) for invalid header engine type byte.

§Example

use rpgmad_lib::decrypt_archive;
use std::path::PathBuf;


let data: Vec<u8> = std::fs::read("C:/Game/Game.rgss3a").unwrap();
let decrypted_files = decrypt_archive(&data).unwrap();

for file in decrypted_files {
    let path = String::from_utf8_lossy(&file.path);
    let output_path = PathBuf::from("C:/Game").join(path.as_ref());

    if let Some(parent) = output_path.parent() {
        std::fs::create_dir_all(parent).unwrap();
    }

    std::fs::write(output_path, file.content).unwrap();
}