Struct View

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 included in the patterns folder inside the distribution package.

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

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

Limitations

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.

The patterns folder in the distribution package includes samples such as tftp_rrq.yupat and zip_local_file.yupat. Editing those files is a good way to get started.

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

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.

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

Notes

Back to README

構造体ビュー

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

補足: .yupat のサンプルファイルは、配布パッケージ内の patterns フォルダに含まれています。

開き方

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

.yupat の書き方

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

基本ルール

よく使うディレクティブ

ディレクティブ 説明
@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> メンバー配置時のアラインメント上限を指定します。省略時は 80 の場合はメンバー間パディングを入れません。

対応している宣言

制限事項

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、前方宣言、通常メンバー、固定長配列、構造体メンバー、ポインタ、可変長配列が含まれています。

配布パッケージの patterns フォルダには、tftp_rrq.yupatzip_local_file.yupat などのサンプルが含まれています。まずはそれらを編集して使い始めるのがおすすめです。

画面の見方

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

表示の特徴

値の表示設定

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

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

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

ボタン

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

エラー表示

注意事項

README に戻る