Codebreaker

Struct Codebreaker 

Source
pub struct Codebreaker { /* private fields */ }
Expand description

A processor for CB v1 and v7 codes.

Implementations§

Source§

impl Codebreaker

Source

pub const fn new() -> Self

Returns a new processor for encrypting and decrypting a list of CB v1 and v7 codes.

Source

pub fn new_v7() -> Self

Returns a new processor for all CB v7 codes published on CMGSCCC.com.

Lets you omit B4336FA9 4DFEFB79 as the first code in the list.

Source

pub fn encrypt_code(&mut self, addr: u32, val: u32) -> (u32, u32)

Encrypts a code and returns the result.

§Example
use codebreaker::Codebreaker;

let mut cb = Codebreaker::new();
let code = cb.encrypt_code(0x2043AFCC, 0x2411FFFF);
assert_eq!(code, (0x2AFF014C, 0x2411FFFF));
Source

pub fn encrypt_code_mut(&mut self, addr: &mut u32, val: &mut u32)

Encrypts a code directly.

§Example
use codebreaker::Codebreaker;

let mut cb = Codebreaker::new();
let mut code = (0x2043AFCC, 0x2411FFFF);
cb.encrypt_code_mut(&mut code.0, &mut code.1);
assert_eq!(code, (0x2AFF014C, 0x2411FFFF));
Source

pub fn decrypt_code(&mut self, addr: u32, val: u32) -> (u32, u32)

Decrypts a code and returns the result.

§Example
use codebreaker::Codebreaker;

let encrypted: Vec<(u32, u32)> = vec![
    (0x2AFF014C, 0x2411FFFF),
    (0xB4336FA9, 0x4DFEFB79),
    (0x973E0B2A, 0xA7D4AF10),
];
let decrypted: Vec<(u32, u32)> = vec![
    (0x2043AFCC, 0x2411FFFF),
    (0xBEEFC0DE, 0x00000000),
    (0x2096F5B8, 0x000000BE),
];

let mut cb = Codebreaker::new();
for (i, code) in encrypted.iter().enumerate() {
    let result = cb.decrypt_code(code.0, code.1);
    assert_eq!(result, decrypted[i]);
}
Source

pub fn decrypt_code_mut(&mut self, addr: &mut u32, val: &mut u32)

Decrypts a code directly.

§Example
use codebreaker::Codebreaker;

let mut encrypted: Vec<(u32, u32)> = vec![
    (0x2AFF014C, 0x2411FFFF),
    (0xB4336FA9, 0x4DFEFB79),
    (0x973E0B2A, 0xA7D4AF10),
];
let decrypted: Vec<(u32, u32)> = vec![
    (0x2043AFCC, 0x2411FFFF),
    (0xBEEFC0DE, 0x00000000),
    (0x2096F5B8, 0x000000BE),
];

let mut cb = Codebreaker::new();
for code in encrypted.iter_mut() {
    cb.decrypt_code_mut(&mut code.0, &mut code.1);
}
assert_eq!(encrypted, decrypted);
Source

pub fn auto_decrypt_code(&mut self, addr: u32, val: u32) -> (u32, u32)

Smart version of decrypt_code that detects if and how a code needs to be decrypted.

§Example
use codebreaker::Codebreaker;

let input: Vec<(u32, u32)> = vec![
    (0x2043AFCC, 0x2411FFFF),
    (0x2A973DBD, 0x00000000),
    (0xB4336FA9, 0x4DFEFB79),
    (0x973E0B2A, 0xA7D4AF10),
];
let output: Vec<(u32, u32)> = vec![
    (0x2043AFCC, 0x2411FFFF),
    (0x201F6024, 0x00000000),
    (0xBEEFC0DE, 0x00000000),
    (0x2096F5B8, 0x000000BE),
];

let mut cb = Codebreaker::new();
for (i, code) in input.iter().enumerate() {
    assert_eq!(cb.auto_decrypt_code(code.0, code.1), output[i]);
}
Source

pub fn auto_decrypt_code_mut(&mut self, addr: &mut u32, val: &mut u32)

Smart version of decrypt_code_mut that detects if and how a code needs to be decrypted.

Trait Implementations§

Source§

impl Clone for Codebreaker

Source§

fn clone(&self) -> Codebreaker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Codebreaker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Codebreaker

Does the same as new.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for Codebreaker

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.