Module disassembler
Expand description
Instructions, Disassembler based on ECMA-355
This module provides comprehensive CIL (Common Intermediate Language) instruction decoding and disassembly capabilities. It includes:
- Instruction Decoding: Parse individual CIL opcodes with full operand support
- Control Flow Analysis: Build basic blocks and analyze program flow
- Stack Effect Analysis: Track how instructions affect the evaluation stack
- Exception Handling: Parse try/catch/finally regions and exception handlers
§Key Types
disassembler::Instruction- Represents a decoded CIL instructiondisassembler::BasicBlock- A sequence of instructions with single entry/exitdisassembler::Operand- Instruction operands (immediates, tokens, targets)disassembler::FlowType- How instructions affect control flow
§Main Functions
disassembler::decode_instruction- Decode a single instructiondisassembler::decode_stream- Decode a sequence of instructionsdisassembler::decode_blocks- Build basic blocks from instruction stream
§Examples
use dotscope::{disassembler::decode_instruction, Parser};
let bytecode = &[0x00, 0x2A]; // nop, ret
let mut parser = Parser::new(bytecode);
let instruction = decode_instruction(&mut parser, 0x1000)?;
println!("Mnemonic: {}", instruction.mnemonic);
println!("Flow type: {:?}", instruction.flow_type);CIL (Common Intermediate Language) disassembler and instruction decoding engine.
This module provides comprehensive support for decoding, analyzing, and disassembling CIL bytecode from .NET assemblies. It includes instruction parsing, control flow analysis, stack effect tracking, and basic block construction.
§Key Types
- [
Instruction] - Represents a decoded CIL instruction - [
BasicBlock] - A sequence of instructions with single entry/exit - [
Operand] - Instruction operands (immediates, tokens, targets) - [
FlowType] - How instructions affect control flow
§Main Functions
- [
decode_instruction] - Decode a single instruction - [
decode_stream] - Decode a sequence of instructions - [
decode_method] - Decode an entire method body - [
decode_blocks] - Build basic blocks from instruction stream
§Example
use dotscope::disassembler::decode_instruction;
use dotscope::Parser;
let bytecode = &[0x00, 0x2A]; // nop, ret
let mut parser = Parser::new(bytecode);
let instruction = decode_instruction(&mut parser, 0x1000)?;
println!("Mnemonic: {}", instruction.mnemonic);Structs§
- Basic
Block - Represents a basic block in the control flow graph.
- CilInstruction
- Base implementation of a valid CIL instruction
- Instruction
- A decoded CIL instruction with all metadata needed for analysis and emulation.
- Stack
Behavior - Stack effect of an instruction.
Enums§
- Flow
Type - How an instruction affects control flow.
- Immediate
- Represents an immediate value type embedded in CIL instructions.
- Instruction
Category - Categorization of instructions by their primary function.
- Operand
- Represents an operand in a more structured way.
- Operand
Type - Types of operands for CIL instructions.
Constants§
- INSTRUCTIONS
- Single byte opcode instructions
- INSTRUCTIONS_
FE - Two byte opcode instructions
- INSTRUCTIONS_
FE_ MAX - Maximum opcode value for two byte instructions
- INSTRUCTIONS_
MAX - Maximum opcode value for single byte instructions
Functions§
- decode_
blocks - Decodes bytecode into a collection of basic blocks with control flow analysis.
- decode_
instruction - Decodes a single CIL instruction from the current parser position.
- decode_
stream - Decodes a continuous stream of CIL instructions from a byte stream.