From a3c2c7486ef6830751fd0a5e2a6cb91b432f28a5 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 6 Jul 2021 15:23:11 -0700 Subject: fix doc items, add example for use of yaxpeax_x86 by yaxpeax_arch traits --- src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 2bee840..84353ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, +//! >(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::(data); +//! ``` +//! //! ## `#![no_std]` //! //! `yaxpeax-x86` supports `no_std` usage. to be built `no_std`, `yaxpeax-x86` only needs -- cgit v1.1