pub struct Decoder<'spec> { /* private fields */ }Expand description
Decoder for a compiled SLEIGH specification.
Implementations§
Source§impl<'spec> Decoder<'spec>
impl<'spec> Decoder<'spec>
Sourcepub fn new(spec: &'spec CompiledSpec) -> Self
pub fn new(spec: &'spec CompiledSpec) -> Self
Creates a decoder for spec.
Sourcepub fn decode_one<'bytes>(
&self,
addr: u64,
bytes: &'bytes [u8],
context: &ContextBytes,
) -> Result<Instruction<'spec, 'bytes>, DecodeError>
pub fn decode_one<'bytes>( &self, addr: u64, bytes: &'bytes [u8], context: &ContextBytes, ) -> Result<Instruction<'spec, 'bytes>, DecodeError>
Decodes one instruction at addr from bytes.
§Errors
Returns a DecodeError: NoMatch if no constructor matches the
bytes (including when they run out mid-instruction), InvalidContext
if context is not this specification’s context length,
InvalidAction if a disassembly action divides by zero or shifts past
the word width, and AmbiguousMatch if several constructors match and
none is more specific.
Decoding is pure: context is read, never written. An instruction that
wants to change it for later instructions says so through
Instruction::context_effects, and ContextDatabase is the opt-in
store that feeds those back.
let decoder = Decoder::new(&spec);
let context = spec.new_context();
// `bytes` is the stream from `addr` on; only what the instruction
// needs is read, and the rest is left for the next call.
let instruction = decoder.decode_one(0x1000, &[1, 1, 1], &context)?;
assert_eq!(instruction.display()?, "inc");
assert_eq!(instruction.len(), 1);
assert_eq!(instruction.next_address(), 0x1001);Sourcepub fn decode_one_shaped<'bytes>(
&self,
addr: u64,
bytes: &'bytes [u8],
context: &ContextBytes,
) -> Result<(Instruction<'spec, 'bytes>, Shape), DecodeError>
pub fn decode_one_shaped<'bytes>( &self, addr: u64, bytes: &'bytes [u8], context: &ContextBytes, ) -> Result<(Instruction<'spec, 'bytes>, Shape), DecodeError>
decode_one, also reporting the instruction’s
Shape: which bits chose its constructors and which fields are
its parameters. Costs a little more than a plain decode.
Two encodings of one shape — equal after masking, whatever their
parameters — decode to the same constructors and operand layout
under the same context, so per-encoding work can be shared across
them; see Shape.