fNET/lib.rs
1//! An iced-style decoder for raw .NET CIL method code, including Mono extensions.
2//!
3//! The default build uses only `core`: decoding, prefix grouping, switch target
4//! iteration, and formatting require no allocator. Instructions borrow their
5//! original bytes, so an arbitrarily large `switch` remains a `Copy` value.
6//!
7//! ```
8//! use fNET::{BufSink, Code, Decoder, DecoderOptions, FmtFormatter, Formatter};
9//!
10//! let bytes = [0x1f, 42, 0x2b, 0xfc, 0x2a];
11//! let mut decoder = Decoder::new(&bytes, 0x1000, DecoderOptions::NONE);
12//! let instruction = decoder.decode();
13//! assert_eq!(instruction.code(), Code::LdcI4S);
14//! assert_eq!(instruction.immediate_i32(), Some(42));
15//! let branch = decoder.decode();
16//! assert_eq!(branch.near_branch_target(), Some(0x1000));
17//! let mut buffer = [0; 64];
18//! let mut text = BufSink::new(&mut buffer);
19//! FmtFormatter::new().format(&branch, &mut text).unwrap();
20//! assert_eq!(text.as_str(), "br.s IL_1000");
21//! ```
22//!
23//! This crate disassembles opcode streams. It does not parse PE files, resolve
24//! metadata signatures, or verify stack types. Structural prefix validation is
25//! available separately from permissive byte decoding.
26
27#![no_std]
28#![forbid(unsafe_code)]
29#![allow(non_snake_case)]
30
31#[cfg(feature = "alloc")]
32extern crate alloc;
33#[cfg(feature = "std")]
34extern crate std;
35
36pub mod decoder;
37pub mod error;
38pub mod extensions;
39pub mod format;
40mod generated;
41pub mod instruction;
42pub mod op_code;
43pub mod operand;
44pub mod prefix;
45
46pub use decoder::{Decoder, DecoderOptions, FeatureSet, MonoDialect, PrefixedIter};
47pub use error::DecodeError;
48pub use extensions::{ExtensionError, ExtensionTable};
49#[cfg(feature = "alloc")]
50pub use format::format_to_string;
51pub use format::{BufSink, FmtFormatter, Formatter, FormatterOptions, SymbolResolver};
52pub use generated::{
53 ALL_CODES, Code, EARLY_MONO_OPCODES, JULY2002_MONO_OPCODES, LEGACY_MONO_OVERRIDES,
54 MAY2004_MONO_OPCODES, Mnemonic, OPCODE_COUNT,
55};
56pub use instruction::{Instruction, PrefixedInstruction};
57pub use op_code::{
58 FlowControl, OpCodeInfo, OpCodeKind, OperandKind, StackBehaviourPop, StackBehaviourPush,
59};
60pub use operand::{MetadataToken, Operand, SwitchTargets, TokenKind};
61pub use prefix::{PrefixMetadataResolver, PrefixValidationError, PrefixValidationOptions};