Skip to content

meltedinhex/analyst-ai-pack / skills/reverse-engineering-binaries-with-binary-ninja

reverse-engineering-binaries-with-binary-ninja

Verified

Reverse engineers binaries with Binary Ninja using its analysis stack and Python API to enumerate functions, navigate IL levels (LLIL/MLIL/HLIL), and automate annotation and extraction. Activates for requests to reverse a binary with Binary Ninja, script the Binary Ninja API, or work with its intermediate languages.

FileKindSize
LICENSEother340 B
SKILL.mdskill md2.9 KB
references/api-reference.mdmarkdown1.2 KB
scripts/analyst.pyscript2.6 KB

scripts/analyst.py

View on GitHub
#!/usr/bin/env python3
"""Generate Binary Ninja Python API analysis scripts (and report API availability).

`check` reports whether the binaryninja API is importable. `skeleton` writes a Binary Ninja script
that opens a view, iterates functions, and exports functions/strings to JSON using the real API.
This tool only generates text — it does not run Binary Ninja or any sample.
"""
from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path

try:
    import binaryninja  # type: ignore  # noqa: F401
    HAVE_BN = True
except ImportError:
    HAVE_BN = False

FUNCTIONS_SNIPPET = '''
    for func in bv.functions:
        result["functions"].append({
            "name": func.name,
            "start": hex(func.start),
            "basic_blocks": len(list(func.basic_blocks)),
        })
'''

STRINGS_SNIPPET = '''
    for s in bv.get_strings():
        result["strings"].append({"value": s.value, "start": hex(s.start)})
'''


def check() -> dict:
    return {"binaryninja_api_available": HAVE_BN}


def skeleton(out: str, emit: list[str]) -> dict:
    keys = []
    body = []
    if "functions" in emit:
        keys.append('"functions": []')
        body.append(FUNCTIONS_SNIPPET)
    if "strings" in emit:
        keys.append('"strings": []')
        body.append(STRINGS_SNIPPET)
    script = (
        "#!/usr/bin/env python3\n"
        "# Binary Ninja headless analysis script (generated skeleton).\n"
        "import json\n"
        "import sys\n"
        "import binaryninja\n\n"
        "def analyze(path):\n"
        "    bv = binaryninja.open_view(path)\n"
        "    result = {%s}\n%s"
        "    return result\n\n"
        "if __name__ == '__main__':\n"
        "    print(json.dumps(analyze(sys.argv[1]), indent=2))\n"
    ) % (", ".join(keys), "".join(body))
    Path(out).write_text(script, encoding="utf-8")
    return {"output": out, "emits": emit, "binaryninja_api_available": HAVE_BN}


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(description="Binary Ninja script generator")
    sub = parser.add_subparsers(dest="cmd", required=True)
    sub.add_parser("check")
    ps = sub.add_parser("skeleton")
    ps.add_argument("--emit", default="functions,strings")
    ps.add_argument("--out", required=True)
    args = parser.parse_args(argv)
    if args.cmd == "check":
        print(json.dumps(check(), indent=2))
    else:
        print(json.dumps(skeleton(args.out, [e.strip() for e in args.emit.split(",")]),
                         indent=2))
    return 0


if __name__ == "__main__":
    sys.exit(main())
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 321kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 321kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 321kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 321kUpdated Claude CodeCodexVerifiedInstall