neo-decompiler 0.10.2

Neo N3 NEF decompiler: parse, disassemble, lift bytecode to high-level pseudocode and C# skeletons, with a CLI, JSON reports, and optional WebAssembly bindings.
Documentation
use super::types::{MethodRef, MethodSpan, MethodTable};

impl MethodTable {
    /// Return all known method spans ordered by start offset.
    pub(in super::super) fn spans(&self) -> &[MethodSpan] {
        &self.spans
    }

    /// Iterate known method spans as `(start, end, method_ref)` triples
    /// ordered by `start`. Used by the structured-IR per-method view to
    /// extract a sub-CFG per method.
    pub fn methods(&self) -> impl Iterator<Item = (usize, usize, &MethodRef)> {
        self.spans.iter().map(|s| (s.start, s.end, &s.method))
    }

    /// Resolve the method that contains the given bytecode offset.
    #[must_use]
    pub fn method_for_offset(&self, offset: usize) -> MethodRef {
        match self.spans.binary_search_by_key(&offset, |span| span.start) {
            Ok(index) => self.spans[index].method.clone(),
            Err(0) => self
                .spans
                .first()
                .map(|span| span.method.clone())
                .unwrap_or_else(|| MethodRef::synthetic(offset)),
            Err(index) => {
                let span = &self.spans[index - 1];
                span.method.clone()
            }
        }
    }

    /// Resolve an internal call target to a method reference.
    /// `spans` is kept sorted by start offset, so we use binary search.
    #[must_use]
    pub fn resolve_internal_target(&self, target_offset: usize) -> MethodRef {
        match self
            .spans
            .binary_search_by_key(&target_offset, |span| span.start)
        {
            Ok(index) => self.spans[index].method.clone(),
            Err(_) => MethodRef::synthetic(target_offset),
        }
    }

    /// Return the manifest ABI method index for a method starting at `offset`, if any.
    #[must_use]
    pub fn manifest_index_for_start(&self, offset: usize) -> Option<usize> {
        self.manifest_index_by_start.get(&offset).copied()
    }
}