AgentSkillsCN

new-identifier

新增全新的 TEE 识别器,从模板生成、测试用例编写,到 Analyzer 注册,全程自动化完成。

SKILL.md
--- frontmatter
name: new-identifier
description: 新しいTEE識別器を追加します。雛形生成からテスト作成、analyzer登録まで自動化。
allowed-tools: Read, Edit, Write, Bash, Grep, Glob

新規TEE識別器追加スキル

新しいTEE形式(TEEGRIS、iTrustee等)の識別器を追加する際に使用します。

実行手順

1. TEE情報を確認

ユーザーに以下を確認:

  • TEE名(例: TEEGRIS)
  • マジックバイト(わかれば)
  • ファイル拡張子
  • サンプルファイル(あれば)

2. シグネチャを追加

src/ta_inspector/identifier/signatures.py に追加:

python
# <TEE_NAME> signatures
<TEE_NAME>_MAGIC = b"XXXX"  # マジックバイト
<TEE_NAME>_EXTENSIONS = [".ext1", ".ext2"]

3. 識別器ファイルを作成

src/ta_inspector/identifier/<tee>.py を作成:

python
"""<TEE_NAME> Trusted Application identifier."""

from pathlib import Path
from typing import Optional

from .base import BaseIdentifier, TAInfo
from .signatures import <TEE_NAME>_MAGIC, <TEE_NAME>_EXTENSIONS


class <TEE_NAME>Identifier(BaseIdentifier):
    """Identifier for <TEE_NAME> Trusted Applications."""

    def supports(self, file_path: Path) -> bool:
        """Check if file might be a <TEE_NAME> TA."""
        return file_path.suffix.lower() in <TEE_NAME>_EXTENSIONS

    def identify(self, file_path: Path) -> Optional[TAInfo]:
        """Identify if file is a <TEE_NAME> TA."""
        try:
            with open(file_path, "rb") as f:
                magic = f.read(len(<TEE_NAME>_MAGIC))

                if magic != <TEE_NAME>_MAGIC:
                    return None

                # ヘッダー解析
                # TODO: TEE固有のヘッダー構造を解析

                return TAInfo(
                    tee_type="<TEE_NAME>",
                    file_path=file_path,
                    confidence=0.9,
                    uuid=None,
                    is_encrypted=False,
                    is_signed=False,
                    signature_algo=None,
                    header_info={"magic": magic.hex()},
                )
        except Exception:
            return None

4. analyzer.pyに登録

src/ta_inspector/identifier/analyzer.py__init__ に追加:

python
from .<tee> import <TEE_NAME>Identifier

class TAAnalyzer:
    def __init__(self):
        self.identifiers = [
            OPTEEIdentifier(),
            QSEEIdentifier(),
            KinibiIdentifier(),
            MTEEIdentifier(),
            <TEE_NAME>Identifier(),  # 追加
        ]

5. テストを作成

tests/test_identifier/test_<tee>.py を作成:

python
import pytest
from pathlib import Path
from ta_inspector.identifier.<tee> import <TEE_NAME>Identifier


class Test<TEE_NAME>Identifier:
    @pytest.fixture
    def identifier(self):
        return <TEE_NAME>Identifier()

    def test_supports_valid_extension(self, identifier):
        assert identifier.supports(Path("test.ext1"))
        assert not identifier.supports(Path("test.txt"))

    def test_identify_valid_ta(self, identifier, tmp_path):
        ta_file = tmp_path / "test.ext1"
        ta_file.write_bytes(b"XXXX" + b"\x00" * 100)

        result = identifier.identify(ta_file)

        assert result is not None
        assert result.tee_type == "<TEE_NAME>"
        assert result.confidence >= 0.8

    def test_identify_invalid_magic(self, identifier, tmp_path):
        ta_file = tmp_path / "test.ext1"
        ta_file.write_bytes(b"ZZZZ" + b"\x00" * 100)

        result = identifier.identify(ta_file)
        assert result is None

6. 確認

bash
# テスト実行
pytest tests/test_identifier/test_<tee>.py -v

# リント・型チェック
ruff check src/ta_inspector/identifier/<tee>.py
mypy src/ta_inspector/identifier/<tee>.py

参考実装

チェックリスト

  • signatures.pyにシグネチャ追加
  • 識別器クラスを作成
  • supports() を実装
  • identify() を実装(ヘッダー解析)
  • analyzer.pyに登録
  • テストを作成
  • ruff/mypyでチェック