Project

binp

0.0
The project is in a healthy, maintained state
simple binary file parser.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Binp - Binary Parser

バイナリファイルからデータを抽出するツール。

offset, size type, endianness を指定して、バイナリファイルのどこからどこまでをどのように解釈するかを指定できる。

使い方

Usage: binp [options] FILE
    -c, --config VALUE               設定ファイルパス
    -a, --all                        name, value 以外のすべての項目(endianness, offset, size, type)を表示する
    -p, --polling VALUE              指定したポーリング間隔(ミリ秒)で再表示します
    -w, --watch                      ファイル更新時に再表示します

インストール方法

gem コマンドでインストールしてください。

gem install binp

設定例

以下内容のバイナリファイルをパースする場合について説明する。

example.bin

+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-------+
|  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 |    14 |
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-------+
| 00 | 00 | 00 | 00 | 00 | 00 | 00 | 01 | 00 | 00 | 00 | 01 | 00 | 01 |    01 |
+---------------------------------------+-------------------+---------+-------+
| UINT64                                | UINT32            |  UINT16 | UINT8 |
+---------------------------------------+-------------------+---------+-------+
※ エンディアンはリトルエンディアン

以下のように、設定ファイルに name, offset, size, type を記述する。

setting.yaml

- name: UINT64_value
  offset: 0
  size: 8
  type: UINT64
  endianness: LITTLE
- name: UINT32_value
  offset: 8
  size: 4
  type: UINT32
  endianness: LITTLE
- name: UINT16_value
  offset: 12
  size: 2
  type: UINT16
  endianness: LITTLE
- name: UINT8_value
  offset: 14
  size: 1
  type: UINT8
  endianness: LITTLE

binary_parser.rb に設定ファイルとバイナリファイルを指定して実行する。

実行結果は以下のようになる。

$ ruby binary_parser.rb -c setting.yaml example.bin
  +--------------+-------------------+
  | name         | value             |
  +--------------+-------------------+
  | UINT64_value | 72057594037927936 |
  | UINT32_value | 16777216          |
  | UINT16_value | 256               |
  | UINT8_value  | 1                 |
  +--------------+-------------------+

-a オプションで追加の情報が出力される。

$ ruby binary_parser.rb -a -c setting.yaml example.bin
  +------------+--------------+--------+------+--------+-------------------+
  | endianness | name         | offset | size | type   | value             |
  +------------+--------------+--------+------+--------+-------------------+
  | LITTLE     | UINT64_value | 0      | 8    | UINT64 | 72057594037927936 |
  | LITTLE     | UINT32_value | 8      | 4    | UINT32 | 16777216          |
  | LITTLE     | UINT16_value | 12     | 2    | UINT16 | 256               |
  | LITTLE     | UINT8_value  | 14     | 1    | UINT8  | 1                 |
  +------------+--------------+--------+------+--------+-------------------+

TODO:

  • : テーブル形式で表示
  • : 文字列型サポート
    • : UTF8
  • : ビットフラグサポート
  • : type からの size 自動設定
  • : json 形式で表示