FlexHEX Editor - Just the Right Tool to Edit Binaries

Introduction

Files and Drives

Inspecting Data

Editing Data

Navigation

Search and Replace

Tools

Complex Data Types

Loading and Mapping

Editing Structured Data

Structure Definition

Structures

Unions

Arrays

Strings

Enumerations

Bit Structures

Basic Types

Special Fields

Advanced Features


 

 

Unions

Unions are very similar to structures except all the union fields reside on the same address. Unions are useful when you need different representations of the same memory area.

union CREATION_TIME {
  FILETIME CreationTime;
  qword TimeNumVal;
};

This definition lets you access the same 64-bit value either as a date/time value or as a hexadecimal 64-bit number. In order to add more representations just extend the union:

union CREATION_TIME {
  FILETIME CreationTime;
  qword TimeNumVal;
  byte TimeArray[8];
};

This definition lets you also access each byte of the date/time value separately.

Tip The size of the union is the size of its largest field.

Anonymous Unions

Like a structure, a union may be anonymous:

struct FILE_DESCRIPTOR {
  FILETIME CreationTime;
  union {
    struct {
      unsigned byte Minor;
      unsigned byte Major;
    } VersionBytes;
    hex word VersionWord;
  } Version;
  char szName[];
};

The anonymous union in this example has two fields: VersionBytes, which in turn is an anonymous structure, and two byte hex value VersionWord. Both the fields is of size two bytes so the size of the union is also two bytes.

Anonymous definition may occur only within another definition and is allowed wherever a type name is expected.

 

 
Copyright © 2007 Inv Softworks LLC
All rights reserved
 
Home | Product | Download | Order | Support | Documentation | Company