Generate Signature For Patchのロゴ

Generate Signature For Patch

組織
HLND2T
generate-signature-for-patch

Generate and validate unique byte signatures for instructions that need to be runtime-patched using IDA Pro MCP. Use this skill when you need a signature to locate a specific instruction for patching (e.g., force/skip a branch, NOP a call, change an immediate operand). Triggers: patch signature, signature for patch, patch instruction signature, nop signature, jump patch signature, skip branch signature, force branch signature

概要

公開者HLND2T
リポジトリCS2_VibeSignatures
スキル名generate-signature-for-patch
スター
67
フォーク
11
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    HLND2TがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Generate Signature For Patch」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/HLND2T/CS2_VibeSignatures/tree/main/.claude/skills/generate-signature-for-patch
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HLND2T/CS2_VibeSignatures.git /tmp/CS2_VibeSignatures
mkdir -p .claude/skills
cp -r /tmp/CS2_VibeSignatures/.claude/skills/generate-signature-for-patch .claude/skills/generate-signature-for-patch
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでGenerate Signature For Patchを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にGenerate Signature For Patchを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Generate Signature For Patchは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Generate Signature for Patch

Generate a unique hex byte signature that locates an instruction to be patched at runtime, along with the replacement patch_bytes.

Core Concept

For patch signatures, we signature the instruction to be patched. The signature uniquely identifies the location so a runtime patcher can find and overwrite the original bytes with patch_bytes.

Hard requirements:

  1. The target instruction must be fully fixed (no wildcard bytes at all).
  2. Instructions other than the target instruction may use wildcarding.
  3. Signature length grows by complete instruction boundaries and stops at the shortest unique prefix.
  4. patch_bytes are determined by the LLM based on the desired patch effect, not by the script.
  5. len(patch_bytes) must equal len(original_instruction_bytes) (pad with 0x90 NOP if the replacement is shorter).

Strategy:

  • Forward-only expansion: Expand only forward (after target instruction). The signature may extend beyond the current function boundary into CC padding or the next function. patch_sig_disp is always 0 — the signature always starts at the target instruction.

Prerequisites

  • Target instruction address (the instruction to be patched)
  • Desired patch effect description (e.g., "skip if-branch", "NOP out function call", "change immediate value")
  • IDA Pro MCP session, resolved per mcp-ida-session.md: idb_list → idb_open (script fallback only if the endpoint is unreachable). Honor its IDB save discipline — an idle-TTL self-exit does not save.

Method

1. Determine patch_bytes (LLM Step — before running the script)

Examine the target instruction and its context using IDA Pro MCP, then determine the appropriate patch_bytes.

Common patch patterns:

  • Skip conditional branch (near jcc 0F 8x rel32 → jmp rel32): Replace first 6 bytes with E9 <new_rel32> 90. Compute new_rel32 = original branch target − (patch_addr + 5).
  • Skip conditional branch (short jcc 7x rel8 → jmp short): Replace 7x rel8 with EB rel8.
  • Force conditional branch to fall through: NOP the entire jcc instruction (90 90 ...).
  • NOP a call rel32: Replace E8 xx xx xx xx with 90 90 90 90 90.
  • NOP a call [reg+disp]: Replace all bytes with 90.
  • Change immediate operand: Modify the immediate bytes in-place.

2. Generate and Validate Signature (Single Step)

Use a single py_eval call that:

  • Collects instruction bytes from the target instruction forward, tests uniqueness.
  • Forward-only expansion (no backward expansion — patch_sig_disp is always 0).
  • Enforces no wildcard on the target instruction.
  • Computes both VA and RVA for the target instruction.
  • Outputs the shortest unique signature as patch_sig with metadata.
python
mcp__ida-pro-mcp__py_eval code="""
import idaapi, ida_bytes, idautils, ida_ua, ida_segment, json

def main():
    target_inst = <inst_addr>
    min_sig_bytes = 6
    max_sig_bytes = 96
    max_instructions = 64

    # --- Binary search wrapper (IDA 9.0+ find_bytes -> older bin_search fallback) ---
    def raw_bin_search(ea, max_ea, data, mask, flags=0):
        if hasattr(ida_bytes, 'find_bytes'):
            return ida_bytes.find_bytes(data, ea, range_end=max_ea, mask=mask, flags=flags)
        return ida_bytes.bin_search(ea, max_ea, data, mask, len(data), flags)

    image_base = idaapi.get_imagebase()

    f = idaapi.get_func(target_inst)
    if not f:
        print(json.dumps({
            "inst_va": hex(target_inst),
            "error": "target instruction is not inside a known function",
            "status": "failed"
        }))
        return

    insn0 = idautils.DecodeInstruction(target_inst)
    if not insn0 or insn0.size <= 0:
        print(json.dumps({
            "inst_va": hex(target_inst),
            "error": "failed to decode target instruction",
            "status": "failed"
        }))
        return

    raw0 = ida_bytes.get_bytes(target_inst, insn0.size)
    if not raw0:
        print(json.dumps({
            "inst_va": hex(target_inst),
            "error": "failed to read target instruction bytes",
            "status": "failed"
        }))
        return

    seg = ida_segment.get_segm_by_name(".text")
    if seg:
        search_start, search_end = seg.start_ea, seg.end_ea
    else:
        search_start, search_end = idaapi.cvar.inf.min_ea, idaapi.cvar.inf.max_ea

    # --- Helper: wildcard non-target instructions ---
    def wildcard_instruction(addr, insn_obj, raw_bytes):
        wild = set()
        for op in insn_obj.ops:
            ot = int(op.type)
            if ot == int(idaapi.o_void):
                continue
            if ot in (int(idaapi.o_imm), int(idaapi.o_near), int(idaapi.o_far), int(idaapi.o_mem), int(idaapi.o_displ)):
                offb = int(getattr(op, "offb", 0))
                if offb > 0 and offb < insn_obj.size:
                    dsz = ida_ua.get_dtype_size(getattr(op, "dtype", getattr(op, "dtyp", 0)))
                    if dsz <= 0:
                        dsz = insn_obj.size - offb
                    for i in range(offb, min(insn_obj.size, offb + dsz)):
                        wild.add(i)

                offo = int(getattr(op, "offo", 0))
                if offo > 0 and offo < insn_obj.size:
                    dsz2 = ida_ua.get_dtype_size(getattr(op, "dtype", getattr(op, "dtyp", 0)))
                    if dsz2 <= 0:
                        dsz2 = insn_obj.size - offo
                    for i in range(offo, min(insn_obj.size, offo + dsz2)):
                        wild.add(i)

        # Branch/call rel targets are volatile.
        b0 = raw_bytes[0]
        if b0 in (0xE8, 0xE9, 0xEB):
            for i in range(1, insn_obj.size):
                wild.add(i)
        elif b0 == 0x0F and insn_obj.size >= 2 and (raw_bytes[1] & 0xF0) == 0x80:
            for i in range(2, insn_obj.size):
                wild.add(i)
        elif 0x70 <= b0 <= 0x7F:
            for i in range(1, insn_obj.size):
                wild.add(i)

        tokens = []
        for idx in range(insn_obj.size):
            tokens.append("??" if idx in wild else f"{raw_bytes[idx]:02X}")
        return tokens

    # --- Helper: test uniqueness of a token list, expecting match at expected_addr ---
    def test_unique(tokens, expected_addr):
        if all(t == "??" for t in tokens):
            return False
        data = bytes(0 if t == "??" else int(t, 16) for t in tokens)
        mask = bytes(0x00 if t == "??" else 0xFF for t in tokens)
        flags = ida_bytes.BIN_SEARCH_FORWARD | ida_bytes.BIN_SEARCH_NOBREAK

        matches = []
        ea = raw_bin_search(search_start, search_end, data, mask, flags)
        while ea != idaapi.BADADDR and len(matches) < 2:
            matches.append(ea)
            ea = raw_bin_search(ea + 1, search_end, data, mask, flags)

        return len(matches) == 1 and matches[0] == expected_addr

    # ====================================================================
    # Forward-only expansion (signature starts at target_inst)
    # May extend beyond the current function into CC padding or next function.
    # ====================================================================
    limit_end = target_inst + max_sig_bytes
    fwd_tokens = []
    fwd_boundaries = []
    cursor = target_inst
    inst_count = 0
    target_inst_len = None

    while (
        cursor < search_end
        and cursor < limit_end
        and len(fwd_tokens) < max_sig_bytes
        and inst_count < max_instructions
    ):
        insn = idautils.DecodeInstruction(cursor)
        if not insn or insn.size <= 0:
            break
        raw = ida_bytes.get_bytes(cursor, insn.size)
        if not raw:
            break

        if cursor == target_inst:
            # Target instruction: fully fixed, no wildcards.
            target_inst_len = insn.size
            for idx in range(insn.size):
                if len(fwd_tokens) < max_sig_bytes:
                    fwd_tokens.append(f"{raw[idx]:02X}")
        else:
            toks = wildcard_instruction(cursor, insn, raw)
            for t in toks:
                if len(fwd_tokens) < max_sig_bytes:
                    fwd_tokens.append(t)

        fwd_boundaries.append(len(fwd_tokens))
        cursor += insn.size
        inst_count += 1

    if target_inst_len is None:
        print(json.dumps({
            "inst_va": hex(target_inst),
            "error": "no signature bytes collected",
            "status": "failed"
        }))
        return

    min_boundary = max(min_sig_bytes, target_inst_len)

    # Try expanding at each instruction boundary until unique
    phase1_sig = None
    phase1_boundary = 0
    for boundary in fwd_boundaries:
        if boundary < min_boundary:
            continue
        prefix = fwd_tokens[:boundary]
        if test_unique(prefix, target_inst):
            phase1_sig = " ".join(prefix)
            phase1_boundary = boundary
            break

    if phase1_sig:
        print(json.dumps({
            "patch_sig": phase1_sig,
            "sig_bytes": phase1_boundary,
            "patch_sig_va": hex(target_inst),
            "patch_sig_disp": 0,
            "patch_inst_length": target_inst_len,
            "patch_va": hex(target_inst),
            "patch_rva": hex(target_inst - image_base),
            "original_bytes": " ".join(f"{b:02X}" for b in raw0),
            "status": "success"
        }))
        return

    # Forward-only expansion exhausted without finding a unique signature.
    print(json.dumps({
        "patch_va": hex(target_inst),
        "patch_rva": hex(target_inst - image_base),
        "original_bytes": " ".join(f"{b:02X}" for b in raw0),
        "total_fwd_tokens": len(fwd_tokens),
        "sig_full_fwd": " ".join(fwd_tokens),
        "error": "no unique signature found with forward-only expansion",
        "status": "failed"
    }))

main()
"""

Result handling:

  • status == "success" -> Use patch_sig directly as final signature. Proceed to Step 3.
  • status == "failed" -> See Step 4.

3. Verify patch_bytes (Optional but Recommended)

After generating the signature, verify the LLM-determined patch_bytes by applying them in IDA and checking the disassembly, then restore the original bytes.

Step 3a: Apply patch and inspect

Use mcp__ida-pro-mcp__patch to write patch_bytes at patch_va:

mcp__ida-pro-mcp__patch addr="<patch_va>" data="<patch_bytes hex>"

Then use mcp__ida-pro-mcp__decompile or mcp__ida-pro-mcp__disasm to verify the patch effect matches the desired behavior.

Step 3b: Restore original bytes

After verification, always restore the original bytes:

mcp__ida-pro-mcp__patch addr="<patch_va>" data="<original_bytes hex>"

If the patch effect does not match expectations, revise patch_bytes and repeat from Step 1.

4. Iterate if Needed

If Step 2 returns status: "failed":

  1. Increase max_sig_bytes (e.g. from 96 to 192) and re-run Step 2.
  2. Increase max_instructions (e.g. from 64 to 128) if function instructions are short.
  3. If still not unique, consider patching a different instruction that achieves the same effect and re-run.

5. Continue with Unfinished Tasks

If we are called by a task from a task list / parent SKILL, restore and continue with the unfinished tasks.

Output Format

Required:

  • patch_sig: Space-separated hex bytes with ?? for wildcards.
  • patch_bytes: Space-separated hex bytes to write at the patch location.

Recommended metadata:

  • patch_sig_va: VA of signature start (always equals patch_va since patch_sig_disp is always 0).
  • patch_sig_disp: Always 0 — signature always starts at the target instruction.
  • patch_inst_length: Length of the target instruction in bytes.
  • patch_va: VA of the instruction to be patched.
  • patch_rva: RVA of the instruction to be patched (VA − image base).
  • original_bytes: Original bytes of the target instruction (for restore/rollback).

Example Output

Patch effect: skip conditional branch jbe → unconditional jmp (the if block becomes dead code).

yaml
patch_sig: "0F 86 AF 00 00 00 0F 57 C0 0F 2E C2"
patch_va: 0x180A00E2F
patch_rva: 0xA00E2F
patch_sig_disp: 0
patch_inst_length: 6
original_bytes: "0F 86 AF 00 00 00"
patch_bytes: "E9 B0 00 00 00 90"

In this example:

  • Original instruction: jbe loc_180A00EE4 (6 bytes: 0F 86 AF 00 00 00)
  • Patch converts it to jmp loc_180A00EE4 + nop: E9 B0 00 00 00 90
  • new_rel32 = 0x180A00EE4 − (0x180A00E2F + 5) = 0xB0 → B0 00 00 00
  • The branch now always jumps, making the if-block dead code

よくある質問

AIスキル「Generate Signature For Patch」では何ができますか?

Generate and validate unique byte signatures for instructions that need to be runtime-patched using IDA Pro MCP. Use this skill when you need a signature to locate a specific instruction for patching (e.g., force/skip a branch, NOP a call, change an immediate operand). Triggers: patch signature, signature for patch, patch instruction signature, nop signature, jump patch signature, skip branch signature, force branch signature

TypingMindでGenerate Signature For Patchを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Generate Signature For Patchはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにGenerate Signature For Patchをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/HLND2T/CS2_VibeSignatures/tree/main/.claude/skills/generate-signature-for-patchを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Generate Signature For Patchを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Generate Signature For Patchで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもGenerate Signature For Patchを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Generate Signature For Patch」は無料ですか?

はい。HLND2TがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇