Text Classification
Laya
Safetensors
system-one
reverse-engineering
x86-64
assembly
windows-api
static-analysis
Instructions to use ntraidmode/laya-x64-v4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Laya
How to use ntraidmode/laya-x64-v4 with Laya:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download ask_func.py from ntraidmode/laya-x64-v4: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/ntraidmode/laya-x64-v4/resolve/main/ask_func.py
- Command line
-
hf download hf://ntraidmode/laya-x64-v4/ask_func.py
-
curl -L -o ask_func.py https://huggingface.co/ntraidmode/laya-x64-v4/resolve/main/ask_func.py
2.45 kB
| import argparse | |
| import json | |
| from pathlib import Path | |
| import laya | |
| ROOT = Path(__file__).parent | |
| DEFAULT_MODEL = str(ROOT / "models" / "laya-x64-func") | |
| from build_labeling import (ALGO_OPTIONS, CATEGORY_OPTIONS, BUG_OPTIONS, ALGO_Q, CAT_Q, VULN_Q, BUG_Q) | |
| QUESTIONS = { | |
| "algorithm": {"type": "choice", "instructions": ALGO_Q, "criteria": {o: None for o in ALGO_OPTIONS}}, | |
| "category": {"type": "choice", "instructions": CAT_Q, "criteria": {o: None for o in CATEGORY_OPTIONS}}, | |
| "vulnerable": {"type": "noul", "instructions": VULN_Q}, | |
| "bug_type": {"type": "choice", "instructions": BUG_Q, "criteria": {o: None for o in BUG_OPTIONS}}, | |
| } | |
| def read_asm(source): | |
| """source is a path to a text file of assembly, or raw hex bytes to disassemble with Capstone.""" | |
| p = Path(source) | |
| if p.exists(): | |
| return p.read_text(encoding="utf-8").strip() | |
| import capstone | |
| from laya_x64 import normalize | |
| md = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_64) | |
| data = bytes.fromhex(source.replace(" ", "")) | |
| return "\n".join(normalize(i.mnemonic, i.op_str) for i in md.disasm(data, 0x1000)) | |
| def main(): | |
| ap = argparse.ArgumentParser(description="Ask the v2 model about a whole x86-64 function.") | |
| ap.add_argument("source", help="path to an .asm text file, or a hex byte string to disassemble") | |
| ap.add_argument("--model", default=DEFAULT_MODEL) | |
| ap.add_argument("--max-len", type=int, default=1024) | |
| ap.add_argument("--json", action="store_true") | |
| args = ap.parse_args() | |
| asm = read_asm(args.source) | |
| agent = laya.load(args.model, device="cuda") | |
| result = agent.predict({"function": asm}, QUESTIONS, max_len=args.max_len)["answers"] | |
| n_insns = sum(1 for l in asm.splitlines() if l.strip() and not l.rstrip().endswith(":")) | |
| print(f"\nfunction: {n_insns} instructions\n" + "-" * 40) | |
| if args.json: | |
| print(json.dumps(result, indent=2, default=str)); return | |
| a = result["algorithm"] | |
| print(f"algorithm : {a['choice']:24} ({a['probabilities'][a['choice']]:.0%})") | |
| c = result["category"] | |
| print(f"category : {c['choice']:24} ({c['probabilities'][c['choice']]:.0%})") | |
| v = result["vulnerable"]["noul"] | |
| print(f"vulnerable: {'YES' if v >= 0.5 else 'no':24} ({max(v, 1 - v):.0%})") | |
| if v >= 0.5: | |
| b = result["bug_type"] | |
| print(f"bug_type : {b['choice']:24} ({b['probabilities'][b['choice']]:.0%})") | |
| if __name__ == "__main__": | |
| main() | |