Magikaは、最新のディープラーニング技術を活用した新感覚のAI搭載ファイルタイプ検出ツールです。数MB程度の軽量で高度に最適化されたカスタムモデルを採用し、シングルCPUでも数ミリ秒で正確なファイル識別を実現します。Magikaは~100Mサンプル、200以上のコンテンツタイプ(バイナリ形式とテキスト形式の両方を含む)のデータセットで学習・評価されており、テストセットで平均~99%の精度を達成しています。
以下はMagikaのコマンドライン出力の例です:
Magikaは大規模に活用され、Gmail、Drive、Safe Browsingのファイルを適切なセキュリティ・コンテンツポリシースキャナーにルーティングすることでGoogleユーザーの安全性向上に貢献しており、毎週数千億のサンプルを処理しています。また、VirusTotal(例)やabuse.ch(例)にも統合されています。
詳細については、Google OSSブログの初回発表記事、Magikaのウェブサイト、およびIEEE/ACM International Conference on Software Engineering (ICSE) 2025で発表された研究論文をご参照ください。
何もインストールせずに、ブラウザ上でローカル動作するウェブデモでMagikaをお試しいただけます!
-rも使用可能。high-confidence、medium-confidence、best-guessなどの異なる予測モードでエラー耐性を制御可能。MagikaはRustで書かれたCLIを提供し、複数の方法でインストールできます。
magika Pythonパッケージ経由:
pipx install magika
brew経由(macOS / Linux)
brew install magika
インストーラースクリプト経由:
curl -LsSf https://securityresearch.google/magika/install.sh | sh
または:
powershell -ExecutionPolicy Bypass -c "irm https://securityresearch.google/magika/install.ps1 | iex"
magika-cli Rustパッケージ経由:
cargo install --locked magika-cli
pip install magika
npm install magika
以下に、すぐに使い始めるための簡単な例をいくつか示します。
Magikaの内部動作については、Magikaウェブサイトのコアコンセプトセクションをご覧ください。
% cd tests_data/basic && magika -r * | head
asm/code.asm: Assembly (code)
batch/simple.bat: DOS batch file (code)
c/code.c: C source (code)
css/code.css: CSS source (code)
csv/magika_test.csv: CSV document (code)
dockerfile/Dockerfile: Dockerfile (code)
docx/doc.docx: Microsoft Word 2007+ document (document)
docx/magika_test.docx: Microsoft Word 2007+ document (document)
eml/sample.eml: RFC 822 mail (text)
empty/empty_file: Empty file (inode)
% magika ./tests_data/basic/python/code.py --json
[
{
"path": "./tests_data/basic/python/code.py",
"result": {
"status": "ok",
"value": {
"dl": {
"description": "Python source",
"extensions": [
"py",
"pyi"
],
"group": "code",
"is_text": true,
"label": "python",
"mime_type": "text/x-python"
},
"output": {
"description": "Python source",
"extensions": [
"py",
"pyi"
],
"group": "code",
"is_text": true,
"label": "python",
"mime_type": "text/x-python"
},
"score": 0.996999979019165
}
}
}
]
% cat tests_data/basic/ini/doc.ini | magika -
-: INI configuration file (text)
% magika --help
Determines file content types using AI
Usage: magika [OPTIONS] [PATH]...
Arguments:
[PATH]...
List of paths to the files to analyze.
Use a dash (-) to read from standard input (can only be used once).
Options:
-r, --recursive
Identifies files within directories instead of identifying the directory itself
--no-dereference
Identifies symbolic links as is instead of identifying their content by following them
--colors
Prints with colors regardless of terminal support
--no-colors
Prints without colors regardless of terminal support
-s, --output-score
Prints the prediction score in addition to the content type
-i, --mime-type
Prints the MIME type instead of the content type description
-l, --label
Prints a simple label instead of the content type description
--json
Prints in JSON format
--jsonl
Prints in JSONL format
--format <CUSTOM>
Prints using a custom format (use --help for details).
The following placeholders are supported:
%p The file path
%l The unique label identifying the content type
%d The description of the content type
%g The group of the content type
%m The MIME type of the content type
%e Possible file extensions for the content type
%s The score of the content type for the file
%S The score of the content type for the file in percent
%b The model output if overruled (empty otherwise)
%% A literal %
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
CLIの詳細な例とドキュメントについては、https://crates.io/crates/magika-cli をご覧ください。
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_bytes(b'function log(msg) {console.log(msg);}')
>>> print(res.output.label)
javascript
>>> from magika import Magika
>>> m = Magika()
>>> res = m.identify_path('./tests_data/basic/ini/doc.ini')
>>> print(res.output.label)
ini
>>> from magika import Magika
>>> m = Magika()
>>> with open('./tests_data/basic/ini/doc.ini', 'rb') as f:
>>> res = m.identify_stream(f)
>>> print(res.output.label)
ini
Pythonモジュールの詳細な例とドキュメントについては、Python Magika モジュールセクションをご覧ください。
詳しいドキュメントについては、Magikaのウェブサイトをご確認ください:
直接、[email protected] までご連絡ください。
Apache 2.0; 詳細はLICENSEをご覧ください。
本プロジェクトはGoogleの公式プロジェクトではありません。Googleによるサポートはなく、Googleはその品質、商品性、特定目的への適合性に関するすべての保証を明示的に否認します。