diff options
| author | iximeow <me@iximeow.net> | 2021-07-06 15:23:11 -0700 | 
|---|---|---|
| committer | iximeow <me@iximeow.net> | 2021-07-06 15:24:13 -0700 | 
| commit | a3c2c7486ef6830751fd0a5e2a6cb91b432f28a5 (patch) | |
| tree | 8985316fb7ba6b0fddde35cfe02205912da6cdf1 /src | |
| parent | e21703dbd5498d9114ff2354ddd30b8a11cfe47d (diff) | |
fix doc items, add example for use of yaxpeax_x86 by yaxpeax_arch traits1.0.3
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 46 | 
1 files changed, 43 insertions, 3 deletions
@@ -17,9 +17,9 @@  //!  //! instructions, operands, registers, and generally all decoding structures, are in their mode's  //! repsective submodule: -//! * `x86_64`/`amd64` decoding is under [`yaxpeax_x86::long_mode`] -//! * `x86_32`/`x86` decoding is under [`yaxpeax_x86::protected_mode`] -//! * `x86_16`/`8086` decoding is under [`yaxpeax_x86::real_mode`] +//! * `x86_64`/`amd64` decoding is under [`long_mode`] +//! * `x86_32`/`x86` decoding is under [`protected_mode`] +//! * `x86_16`/`8086` decoding is under [`real_mode`]  //!  //! all modes have equivalent data available in a decoded instruction. for example, all modes have  //! library-friendly `Operand` and `RegSpec` types: @@ -48,6 +48,46 @@  //! assert_eq!("dword", mem_size.to_string());  //! ```  //! +//! `yaxpeax-x86` can also be used to decode instructions generically through the `yaxpeax-arch` +//! traits: +//! ``` +//! mod decoder { +//!     use yaxpeax_arch::{Arch, AddressDisplay, Decoder, Reader, ReaderBuilder}; +//! +//!     pub fn decode_stream< +//!         'data, +//!         A: yaxpeax_arch::Arch, +//!         U: ReaderBuilder<A::Address, A::Word>, +//!     >(data: U) where +//!         A::Instruction: std::fmt::Display, +//!     { +//!         let mut reader = ReaderBuilder::read_from(data); +//!         let mut address: A::Address = reader.total_offset(); +//! +//!         let decoder = A::Decoder::default(); +//!         let mut decode_res = decoder.decode(&mut reader); +//!         loop { +//!             match decode_res { +//!                 Ok(ref inst) => { +//!                     println!("{}: {}", address.show(), inst); +//!                     decode_res = decoder.decode(&mut reader); +//!                     address = reader.total_offset(); +//!                 } +//!                 Err(e) => { +//!                     println!("{}: decode error: {}", address.show(), e); +//!                     break; +//!                 } +//!             } +//!         } +//!     } +//! } +//! +//! use yaxpeax_x86::amd64::{Arch as x86_64}; +//! use yaxpeax_arch::{ReaderBuilder, U8Reader}; +//! let data: &[u8] = &[0x55, 0x33, 0xc0, 0x48, 0x8b, 0x02, 0x5d, 0xc3]; +//! decoder::decode_stream::<x86_64, _>(data); +//! ``` +//!  //! ## `#![no_std]`  //!  //! `yaxpeax-x86` supports `no_std` usage. to be built `no_std`, `yaxpeax-x86` only needs  | 
