Disassembler

Struct Disassembler 

Source
pub struct Disassembler<'d> { /* private fields */ }
Expand description

Gfx packet macro disassembler.

This struct allows configuring general settings that control the generated output. Once the disassembler is configured, call disassemble to produce a string with the disassembly of the passed Gfx packets.

Refer to the Customizer struct to further customize how each Gfx macro is outputted or register callbacks for the different kinds of macros.

§Examples

Disassemble F3DEX packets without any kind of customization

use gfxd_rs::{Customizer, Disassembler, Microcode};

pub fn plain_disasm_f3dex(data: &[u8]) -> String {
    let mut customizer = Customizer::new();

    Disassembler::new()
        .disassemble(data, Microcode::F3dex, &mut customizer)
}

Use a dynamic argument and print each macro on a different line.

use gfxd_rs::{Customizer, Disassembler, MacroPrinter, Microcode};

pub fn disasm_pretty(data: &[u8], microcode: Microcode, dynamic: &str) -> String {
    let mut customizer = Customizer::new();

    // This has to be binded to a local variable to avoid dropping it too soon.
    let mut macro_fn = |printer: &mut MacroPrinter, _info: &mut _| {
        // Write 4 spaces.
        printer.write_str("    ");
        // Call the original macro handler, to emit the macro as-is.
        let ret = printer.macro_dflt();
        // Write a newline after the macro.
        printer.write_str(",\n");
        ret
    };
    customizer
        .macro_fn(&mut macro_fn);

    Disassembler::new()
        .dynamic(Some(dynamic))
        .disassemble(data, microcode, &mut customizer)
}

Implementations§

Source§

impl<'d> Disassembler<'d>

Source

pub const fn new() -> Self

Construct a Disassembler instance.

Consult the Disassembler struct documentation for more information.

Source

pub fn dynamic(&mut self, dynamic: Option<&'d str>) -> &mut Self

Enable or disable the use of dynamic g macros instead of static gs macros, and select the dynamic display list pointer argument to be used.

If Some, this value will be used by macro_dflt as the first argument to dynamic macros. If None, dynamic macros are disabled and gs macros are used. Defaults to None.

Also affects the result of macro_name, as it will return either the dynamic or static version of the macro name as selected by this setting.

Source

pub fn stop_on_invalid(&mut self, value: bool) -> &mut Self

Stop execution when encountering an invalid macro.

Enabled by default.

Source

pub fn stop_on_end(&mut self, value: bool) -> &mut Self

Stop execution when encountering a SPBranchList or SPEndDisplayList.

Enabled by default.

Source

pub fn emit_dec_color(&mut self, value: bool) -> &mut Self

Print color components as decimal instead of hexadecimal.

Disabled by default.

Source

pub fn emit_q_macro(&mut self, value: bool) -> &mut Self

Print fixed-point conversion q macros for fixed-point values.

Disabled by default.

Source

pub fn emit_ext_macro(&mut self, value: bool) -> &mut Self

Emit non-standard macros.

Some commands are valid (though possibly meaningless), but have no macros associated with them, such as a standalone G_RDPHALF_1. When this feature is enabled, such a command will produce a non-standard gsDPHalf1 macro instead of a raw hexadecimal command.

Also enables some non-standard multi-packet texture loading macros.

Disabled by default.

Source

pub fn disassemble( self, data: &[u8], microcode: Microcode, customizer: &mut Customizer<'_>, ) -> String

Start executing gfxd with the current settings.

The data argument is a big endian byte array containing the Gfx packets to be disassembled.

microcode corresponds to the target microcode to decode the data.

customizer allows registering callbacks to customize the output or to extract data from each macro type.

For each macro, the macro handler registered with macro_fn is called.

Execution ends when:

Trait Implementations§

Source§

impl<'d> Clone for Disassembler<'d>

Source§

fn clone(&self) -> Disassembler<'d>

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<'d> Debug for Disassembler<'d>

Source§

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

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

impl Default for Disassembler<'_>

Source§

fn default() -> Self

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

impl<'d> Hash for Disassembler<'d>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'d> PartialEq for Disassembler<'d>

Source§

fn eq(&self, other: &Disassembler<'d>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'d> Copy for Disassembler<'d>

Source§

impl<'d> Eq for Disassembler<'d>

Source§

impl<'d> StructuralPartialEq for Disassembler<'d>

Auto Trait Implementations§

§

impl<'d> Freeze for Disassembler<'d>

§

impl<'d> RefUnwindSafe for Disassembler<'d>

§

impl<'d> Send for Disassembler<'d>

§

impl<'d> Sync for Disassembler<'d>

§

impl<'d> Unpin for Disassembler<'d>

§

impl<'d> UnwindSafe for Disassembler<'d>

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.