neo-decompiler 0.11.0

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::scan::next_code_line;

/// Find the end of the overflow block starting at the `if ... {` line.
pub(super) fn find_overflow_block_end(statements: &[String], if_idx: usize) -> Option<usize> {
    let mut end = find_matching_brace(statements, if_idx)?;

    if let Some(next) = next_code_line(statements, end + 1) {
        let trimmed = statements[next].trim();
        if trimmed == "else {" || trimmed == "} else {" {
            if let Some(else_end) = find_matching_brace(statements, next) {
                end = else_end;
            }
        }
    }

    Some(end)
}

/// Find the index of the closing `}` that matches the `{` at `open_idx`.
pub(super) fn find_matching_brace(statements: &[String], open_idx: usize) -> Option<usize> {
    let mut depth = 1i32;
    for (i, stmt) in statements.iter().enumerate().skip(open_idx + 1) {
        let trimmed = stmt.trim();
        if trimmed.is_empty() || trimmed.starts_with("//") {
            continue;
        }
        if trimmed == "}" || trimmed.starts_with("} ") {
            depth -= 1;
            if depth == 0 {
                return Some(i);
            }
        }
        if trimmed.ends_with('{') {
            depth += 1;
        }
    }
    None
}