pub struct Decrypter<'a> { /* private fields */ }Expand description
A struct responsible for decrypting and extracting files from encrypted game archives.
Implementations§
Source§impl<'a> Decrypter<'a>
impl<'a> Decrypter<'a>
Sourcepub fn decrypt(
&'a mut self,
archive_data: &'a mut [u8],
) -> Result<impl Iterator<Item = ArchiveEntry<'a>>, ExtractError>
pub fn decrypt( &'a mut self, archive_data: &'a mut [u8], ) -> Result<impl Iterator<Item = ArchiveEntry<'a>>, ExtractError>
Returns an iterator over decrypted ArchiveEntry entries.
§Parameters
archive_data: The content of the archive file. This data is modified in-place, and requires to be a mutable reference.
§Returns
Iterator<Item = ArchiveEntry>if files were successfully decrypted.ExtractErrorotherwise.
§Errors
ExtractError::InvalidHeaderfor invalid header.ExtractError::InvalidEnginefor invalid header engine type byte.
§Example
use rpgmad_lib::Decrypter;
use std::{path::PathBuf, fs::{read, write, create_dir_all}};
let mut data = read("C:/Game/Game.rgss3a").unwrap();
let mut decrypter = Decrypter::new();
let decrypted_entries = decrypter.decrypt(&mut data).unwrap();
for entry in decrypted_entries {
let path = String::from_utf8_lossy(&entry.path);
let output_path = PathBuf::from("C:/Game").join(path.as_ref());
if let Some(parent) = output_path.parent() {
create_dir_all(parent).unwrap();
}
write(output_path, entry.data).unwrap();
}Sourcepub fn encrypted_buffer_size(
archive_entries: &[ArchiveEntry<'_>],
engine: Engine,
) -> usize
pub fn encrypted_buffer_size( archive_entries: &[ArchiveEntry<'_>], engine: Engine, ) -> usize
Returns the size for the encrypted buffer of archive entries in bytes.
It’s necessary to use this function to get the buffer size for the encrypted buffer before actually encrypting the data with Decrypter::encrypt.
§Parameters
archive_entries: Archive entries to encrypt.engine: Target archive engine.
§Example
See Decrypter::encrypt.
Sourcepub fn encrypt(
&mut self,
archive_entries: &[ArchiveEntry<'_>],
engine: Engine,
archive_buffer: &mut [u8],
)
pub fn encrypt( &mut self, archive_entries: &[ArchiveEntry<'_>], engine: Engine, archive_buffer: &mut [u8], )
Writes encrypted archive data to archive_buffer.
archive_buffer must be manually pre-allocated by you. You must use the size that Decrypter::encrypted_buffer_size function returns. This is done this way for no_std compatibility.
§Parameters
archive_entries: Archive entries to encrypt.engine: Target archive engine.archive_buffer: Buffer to write encrypted data into.
§Example
use rpgmad_lib::{Decrypter, Engine, ArchiveEntry};
use std::{fs::{read, write}, borrow::Cow};
let data = read("Graphics/Tilesets/Tileset1.png").unwrap();
let archive_entries = [ArchiveEntry {
path: b"Graphics/Tilesets/Tileset1.png",
data: &data,
}];
let encrypted_buffer_size = Decrypter::encrypted_buffer_size(&archive_entries, Engine::VXAce);
let mut archive_buffer = Vec::new();
archive_buffer.resize(encrypted_buffer_size, 0);
Decrypter::new().encrypt(&archive_entries, Engine::VXAce, &mut archive_buffer);
write("./Game.rgss3a", archive_buffer).unwrap();Trait Implementations§
Auto Trait Implementations§
impl<'a> !UnwindSafe for Decrypter<'a>
impl<'a> Freeze for Decrypter<'a>
impl<'a> RefUnwindSafe for Decrypter<'a>
impl<'a> Send for Decrypter<'a>
impl<'a> Sync for Decrypter<'a>
impl<'a> Unpin for Decrypter<'a>
impl<'a> UnsafeUnpin for Decrypter<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more