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