Re nim

From dslsdzc/rev-skills · View interactive version

Re nim is an AI agent skill from the GitHub repository dslsdzc/rev-skills. Nim 编译产物逆向:运行时识别、NimString 结构、异常与 GC 路径。 触发词:Nim逆向、nim、NimString、NimMain、nim 产物。

How to use this skill

Skill file

Nim 逆向

何时使用 / 何时不用

工具准备

readelf / llvm-nm(符号与节分析)

Ghidra / IDA(反编译底座)

nim 编译器(可选,对照编译)

xxd + Python struct(字节级核对)

操作步骤

按顺序执行,每步产物存档(路径 + sha256,见 [[re-triage]])。

  1. 产物识别:

```sh

readelf -s sample | grep -iE 'NimMain|nimGC|NimString' | head # ELF;Mach-O 用 llvm-nm

readelf -s sample | grep -iE 'nimIncRef|nimDecRef|rawNewString|eqStrings' | head

```

  1. 字符串与序列结构(先判 GC 模式):

```

栈/对象内: len(int64) | p(ptr) ───────────────┐

堆上 payload: cap(int64, bit62=字面量标记) | data[cap+1] ←┘

```

字符串本体只有 16 字节句柄,内容在独立堆块——分析对象结构时按句柄跳转,别在对象里找字符数据

  1. 内存中定位字符串(动态/转储场景):

```python

# 在内存转储中按 v2 布局找字符串:cap 是 8 字节对齐的容量值,data 后跟可打印 ASCII

# 候选: 8 字节对齐的 cap + len 匹配的 data → 反推 NimStringV2 起点

```

字符串内容在堆上 payload 里,栈上只有 len+指针;先按 cap 前缀特征定位 payload,再往回找引用它的 NimStringV2([[examples]] 有完整示例)。

  1. 异常与 raises 路径:
  1. GC 与引用计数(按 GC 模式分叉):
  1. C 混合编译边界:
  1. stripped 产物兜底:

```sh

strings -n 6 sample | grep -E '@m.*\.nim\.c' | head # C 生成缓存文件名(含模块名,release 也嵌入)

strings -n 6 sample | grep -iE 'fatal\.nim|Exception' | head

```

跨域联合

常见坑与陷阱

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.