Re emulation

From dslsdzc/rev-skills · View interactive version

Re emulation is an AI agent skill from the GitHub repository dslsdzc/rev-skills. 模拟执行:Unicorn/Qiling 框架。触发词:Unicorn、Qiling、模拟执行、emulate、无硬件运行

How to use this skill

Skill file

模拟执行(Unicorn / Qiling)

何时使用 / 何时不用

工具准备

模拟执行属动态执行,默认沙箱 + 网络隔离([[re-analyze/platform-tips]] 最高原则);本技能三件套均为 pip 包,Linux/macOS/Windows 通用,WSL 内可直接用([[re-analyze/platform-tips]] WSL 分支)。

unicorn

qiling(依赖 unicorn / capstone / pefile,自动装)

capstone(反汇编/解码输出用)

操作步骤

按顺序执行,每步记下结果;模拟产物(内存快照/明文段)sha256 存档([[re-triage]] 存证思路)。

  1. 场景判断:
  1. Unicorn 最小框架:

```python

from unicorn import *

from unicorn.x86_const import *

CODE = bytes.fromhex("b8 2a 00 00 00 c3") # mov eax, 0x2a; ret

mu = Uc(UC_ARCH_X86, UC_MODE_32)

mu.mem_map(0x1000, 0x1000) # 先映射一页(地址页对齐)

mu.mem_write(0x1000, CODE)

mu.reg_write(UC_X86_REG_ESP, 0x2000) # 设好栈(不设 ESP 会崩)

mu.emu_start(0x1000, 0x1000 + len(CODE)) # 执行到结束地址

print(hex(mu.reg_read(UC_X86_REG_EAX))) # 0x2a

```

要点: 内存必须 mem_map(页对齐)再 mem_write;栈寄存器必须设;emu_start(begin, until) 的 until 要覆盖代码结束地址,否则跑到非法地址

  1. Qiling 全系统模拟:

```python

from qiling import Qiling

ql = Qiling(["rootfs/x8664_linux/bin/x8664_hello"], "rootfs/x8664_linux") # 文件名以实际 rootfs 为准;examples/ 与 rootfs 需 git clone 官方仓库获取(pip 不含)

ql.run()

```

  1. 钩子(hook_code / hook_mem):

```python

def hook_code(uc, address, size, user_data):

if address == 0x401234:

print("hit target", hex(address))

mu.hook_add(UC_HOOK_CODE, hook_code) # 每指令回调

mu.hook_add(UC_HOOK_MEM_WRITE, hook_mem) # 内存写回调(脱壳记解密落点)

mu.hook_add(UC_HOOK_MEM_UNMAPPED, hook_bad) # 未映射访问回调

```

4.5. 状态保存/恢复与内存落盘:

  1. 结合 [[re-anti-analysis]] 的脱壳场景:

跨域联合

常见坑与陷阱

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.