構造体ビューは、.yupat で定義した構造を現在のカーソル位置に適用し、バイナリデータをフィールド単位で確認するための機能です。

補足: .yupat のサンプルは、サンプルファイルのダウンロードから入手できます。

開き方

  1. YuHex で解析したいファイルを開きます。
  2. メニュー(設定 - 解析 - 構造体ビュー)から構造体ビューウィンドウを表示します。
  3. 構造体ビューの 開く... ボタンから .yupat ファイルを選択します。
  4. 16進ダンプ領域 のカーソル位置を基準として、構造体ビューに解析結果が表示されます。

.yupat の書き方

.yupat は、C言語の struct 宣言に、YuHex 用のディレクティブを少し加えた定義ファイルです。

基本ルール

  • 文字コードは UTF-8 を推奨します。
  • コメントは // ... と /* ... */ が使えます。
  • 起点となる構造体は @entry で指定します。
  • 構造体定義が 1 つだけのファイルでは、@entry を省略できます。

よく使うディレクティブ

ディレクティブ 説明
@entry 型名 構造体ビューの起点になる構造体型を指定します。
@member_align 0 メンバー間の自動パディングを入れません。ファイルフォーマット定義ではよく使います。
@member_align 4, @member_align 8 自然アラインメントに従ってメンバーを配置し、必要ならパディングを入れます。
@pointer_size 4, @pointer_size 8 ポインタ型を何 byte として扱うかを指定します。
@sizeof_short, @sizeof_int, @sizeof_long など C の基本型サイズをファイル単位で上書きします。

すべてのディレクティブ

ディレクティブ 説明
@entry <type-name> 起点となる構造体型名を指定します。構造体定義が複数ある場合は必須です。
@sizeof_short <number> short 系を何 byte として扱うかを指定します。省略時は 2 です。
@sizeof_int <number> int 系を何 byte として扱うかを指定します。省略時は 4 です。
@sizeof_long <number> long 系を何 byte として扱うかを指定します。省略時は 8 です。
@sizeof_long_long <number> long long 系を何 byte として扱うかを指定します。省略時は 8 です。
@sizeof_float <number> float を何 byte として扱うかを指定します。省略時は 4 です。
@sizeof_double <number> double を何 byte として扱うかを指定します。省略時は 8 です。
@pointer_size <number> すべてのポインタ型を何 byte として扱うかを指定します。省略時は 8 です。
@member_align <number> メンバー配置時のアラインメント上限を指定します。省略時は 8、0 の場合はメンバー間パディングを入れません。

対応している宣言

  • struct name { ... };
  • typedef struct tag { ... } TYPE;
  • typedef 既存型 別名;
  • typedef struct tag TYPE; のような前方宣言
  • 通常メンバー: type name;
  • 固定長配列: type name[count];
  • 可変長配列: type name[];
  • ポインタ: type* name;

制限事項

  • union、enum、ビットフィールド、多次元配列には対応していません。
  • #include、#define、条件コンパイルなどのプリプロセッサ構文には対応していません。
  • 可変長配列 [] は、構造体の最後のメンバーにのみ置けます。

サイズ計算の制限

  • x64版では、配列の要素数とサイズ計算の各結果は、符号なし64ビット整数の範囲(最大 18446744073709551615)に収まる必要があります。
  • 固定長配列の「要素サイズ × 要素数」、メンバーの「オフセット + サイズ」、アラインメントによるパディングを含む構造体サイズのいずれかが上限を超える場合、定義ファイルの読み込みをエラーにします。小さなサイズへ折り返して解釈することはありません。
  • この上限はサイズ計算上の上限です。その大きさのデータを実際に読み込めることを保証するものではありません。

EBNF 風文法

file            = { ws | comment | directive | declaration } ;

directive       = "@entry" ident
                | "@sizeof_short" number
                | "@sizeof_int" number
                | "@sizeof_long" number
                | "@sizeof_long_long" number
                | "@sizeof_float" number
                | "@sizeof_double" number
                | "@pointer_size" number
                | "@member_align" number ;

declaration     = typedef_decl
                | struct_decl
                | forward_decl ;

typedef_decl    = "typedef" type_spec declarator_list ";" ;

struct_decl     = [ "typedef" ] "struct" [ ident ] "{"
                  member_decl* "}" [ ident ] ";" ;

forward_decl    = "typedef" "struct" ident ident ";" ;

member_decl     = type_spec declarator ";" ;

type_spec       = builtin_type
                | ident
                | "struct" ident ;

declarator_list = declarator { "," declarator } ;

declarator      = [ "*" ] ident [ array_suffix ] ;

array_suffix    = "[" number "]"
                | "[" "]" ;

サンプル

@member_align 0
@pointer_size 8
@entry sample_record

typedef unsigned char  BYTE;
typedef unsigned short WORD;
typedef struct nested_header nested_header_t;

struct nested_header {
    WORD flags;
    BYTE reserved[2];
};

typedef struct sample_record {
    WORD            magic;
    BYTE            version;
    BYTE            name_length;
    BYTE            name[8];
    nested_header_t header;
    void*           next;
    char            payload[];
} sample_record;

このサンプルには、typedef、前方宣言、通常メンバー、固定長配列、構造体メンバー、ポインタ、可変長配列が含まれています。

サンプルファイルのダウンロード

無料版・Microsoft Store版で共通のサンプルです。任意のフォルダに保存し、構造体ビューの 開く... から選択してください。配布パッケージには同梱していません。

画面の見方

項目 説明
オフセット 16進ダンプ領域 のカーソル位置を基準にした実ファイル上の位置を表示します。
値 フィールドの内容を表示します。数値、16進列、ASCII文字列など、表示形式を切り替えられます。
サイズ フィールドのサイズを byte 単位で表示します。可変長配列は 1+ のように表示されます。
フィールド 構造体名、メンバー名、または <padding> を表示します。

表示の特徴

  • 入れ子の構造体は、親行の下に 1 段だけフラット展開して表示します。
  • 親となる構造体行の値は空欄で表示します。
  • 固定長フィールドの全バイトが入力データ内に収まらない場合、値は -(表示不可)とします。不足分を入力データの範囲外から読み取ることはありません。
  • 表示行数は最大 256 行です。超える場合は末尾に ... を表示します。
  • 列幅はドラッグで変更できます。列境界をダブルクリックすると既定幅に戻ります。

値の表示設定

値 列の見出し右側にあるボタンから、表示形式を切り替えられます。

設定項目 内容
バイト配列表示 16進列 と ASCII文字列 を切り替えます。
数値の並び Little Endian と Big Endian を切り替えます。
数値の表示 Hex と Dec を切り替えます。

ASCII文字列表示では、次のルールで表示します。

  • \0 が見つかった場合は、そこまでを文字列として表示します。
  • 途中で非 ASCII 文字または制御文字が現れた場合は、そこまでを文字列として表示し、末尾に ... を付けます。
  • 先頭から文字列として解釈できない場合は、16進列表示にフォールバックします。

ボタン

ボタン 説明
開く... .yupat 定義ファイルを選択します。
再読込(F5) 現在開いている .yupat 定義ファイルを再読込します。
クリア 現在の構造体定義を外し、構造体ビューを空にします。
情報 定義ファイルの情報ペインを開閉します。

エラー表示

  • 定義ファイルにエラーがある場合は、構造体ビュー内にエラーメッセージを表示します。
  • エラーの位置を特定できる場合は、行番号、列番号、該当行、位置キャレットを表示します。
  • エラーメッセージ欄はテキスト選択とコピーに対応しています。

注意事項

  • 構造体ビューは、現在のカーソル位置からデータを解釈します。見たい場所へカーソルを移動してから使用してください。
  • 構造体ビューは、定義ファイルそのものの意味解釈までは行いません。必要に応じて値の表示形式を切り替えて確認してください。

無料版の機能・使い方に戻る

Struct View applies a structure defined in a .yupat file to the current cursor position and lets you inspect binary data field by field.

Note: Sample .yupat files are available from Download Sample Files.

How to Open It

  1. Open the file you want to inspect in YuHex.
  2. Open the Struct View window from the menu.
  3. Click Open... in Struct View and select a .yupat file.
  4. The structure is applied relative to the current cursor position in the hex dump area.

Writing .yupat Files

A .yupat file is a C-style structure definition file with a small set of YuHex-specific directives.

Basic Rules

  • UTF-8 is recommended.
  • Both // ... and /* ... */ comments are supported.
  • Use @entry to specify the root structure.
  • If the file defines only one structure, @entry can be omitted.

Common Directives

Directive Description
@entry type_name Specifies the root structure type for Struct View.
@member_align 0 Disables automatic padding between members. This is often useful for file format definitions.
@member_align 4, @member_align 8 Places members using natural alignment and inserts padding when needed.
@pointer_size 4, @pointer_size 8 Defines the size of pointer types in bytes.
@sizeof_short, @sizeof_int, @sizeof_long, etc. Overrides the sizes of C basic types for this file.

All Directives

Directive Description
@entry <type-name> Specifies the root structure type. Required when the file defines multiple structures.
@sizeof_short <number> Sets the size of short types. Default: 2.
@sizeof_int <number> Sets the size of int types. Default: 4.
@sizeof_long <number> Sets the size of long types. Default: 8.
@sizeof_long_long <number> Sets the size of long long types. Default: 8.
@sizeof_float <number> Sets the size of float. Default: 4.
@sizeof_double <number> Sets the size of double. Default: 8.
@pointer_size <number> Sets the size of all pointer types. Default: 8.
@member_align <number> Sets the maximum alignment used when placing members. Default: 8. A value of 0 disables member padding.

Supported Declarations

  • struct name { ... };
  • typedef struct tag { ... } TYPE;
  • typedef existing_type alias;
  • typedef struct tag TYPE; style forward declarations
  • Normal members: type name;
  • Fixed-size arrays: type name[count];
  • Flexible arrays: type name[];
  • Pointers: type* name;

Limitations

  • union, enum, bit fields, and multi-dimensional arrays are not supported.
  • Preprocessor constructs such as #include, #define, and conditional compilation are not supported.
  • A flexible array [] can only appear as the last member of a structure.

Size Calculation Limits

  • In the x64 edition, array element counts and every result of size calculations must fit in an unsigned 64-bit integer (maximum 18446744073709551615).
  • Loading the definition file fails if an array's element size multiplied by its count, a member's offset plus its size, or the structure size including alignment padding exceeds this limit. The calculation never wraps around to a smaller size.
  • This is an arithmetic limit, not a guarantee that data of that size can actually be loaded.

EBNF-style Grammar

file            = { ws | comment | directive | declaration } ;

directive       = "@entry" ident
                | "@sizeof_short" number
                | "@sizeof_int" number
                | "@sizeof_long" number
                | "@sizeof_long_long" number
                | "@sizeof_float" number
                | "@sizeof_double" number
                | "@pointer_size" number
                | "@member_align" number ;

declaration     = typedef_decl
                | struct_decl
                | forward_decl ;

typedef_decl    = "typedef" type_spec declarator_list ";" ;

struct_decl     = [ "typedef" ] "struct" [ ident ] "{"
                  member_decl* "}" [ ident ] ";" ;

forward_decl    = "typedef" "struct" ident ident ";" ;

member_decl     = type_spec declarator ";" ;

type_spec       = builtin_type
                | ident
                | "struct" ident ;

declarator_list = declarator { "," declarator } ;

declarator      = [ "*" ] ident [ array_suffix ] ;

array_suffix    = "[" number "]"
                | "[" "]" ;

Sample

@member_align 0
@pointer_size 8
@entry sample_record

typedef unsigned char  BYTE;
typedef unsigned short WORD;
typedef struct nested_header nested_header_t;

struct nested_header {
    WORD flags;
    BYTE reserved[2];
};

typedef struct sample_record {
    WORD            magic;
    BYTE            version;
    BYTE            name_length;
    BYTE            name[8];
    nested_header_t header;
    void*           next;
    char            payload[];
} sample_record;

This sample includes all currently supported directives, along with typedef, a forward declaration, normal members, a fixed-size array, a nested structure member, a pointer, and a flexible array member.

Download Sample Files

These samples work with both the Free Edition and Microsoft Store Edition. Save a file in any folder, then select it using Open... in Struct View. Samples are not bundled with the distribution package.

Reading the View

Item Description
Offset Shows the actual file offset relative to the current cursor position in the hex dump area.
Value Shows the field value. You can switch between numeric, hex-byte, and ASCII string display modes.
Size Shows the field size in bytes. Flexible arrays are shown as 1+, for example.
Field Shows the structure name, member name, or <padding>.

Display Behavior

  • Nested structures are expanded only one level under the parent row.
  • Parent structure rows show an empty value column.
  • If the input data does not contain all bytes of a fixed-size field, its value is shown as - (unavailable). Missing bytes are never read from outside the input data.
  • The view shows up to 256 rows. If there are more, ... is shown at the end.
  • Column widths can be changed by dragging. Double-click a column separator to restore the default width.

Value Display Settings

Use the button on the right side of the Value header to change how values are shown.

Setting Description
Byte Array Display Switches between Hex Bytes and ASCII String.
Numeric Endian Switches between Little Endian and Big Endian.
Numeric Base Switches between Hex and Dec.

ASCII string display follows these rules.

  • If \0 is found, the string is shown up to that point.
  • If a non-ASCII or control character appears, the string is shown up to that point and ... is appended.
  • If the data cannot be interpreted as a string from the first byte, the display falls back to hex bytes.

Buttons

Button Description
Open... Selects a .yupat definition file.
Reload (F5) Reloads the currently opened .yupat file.
Clear Clears the current structure definition and empties the view.
Info Shows or hides the definition file information pane.

Error Display

  • If the definition file contains an error, Struct View shows the error message inside the window.
  • When the error location is available, the message includes the line number, column number, source line, and caret position.
  • The error text area supports text selection and copy.

Notes

  • Struct View interprets data from the current cursor position. Move the cursor to the location you want to inspect before opening a definition file.
  • Struct View does not apply semantic protocol-specific interpretation by itself. Change the value display mode as needed when checking raw data.

Back to Free Edition features and usage