Skip to main content

Decrypter

Struct Decrypter 

Source
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>

Source

pub fn new() -> Self

Creates a new Decrypter with empty buffer.

Source

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
§Errors
§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();
}
Source

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.

Source

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§

Source§

impl Default for Decrypter<'_>

Source§

fn default() -> Self

Returns a new Decrypter with default parameters.

Equivalent to calling Decrypter::new.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.