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


 

 

Bit Structures

Bit structures provide a tool for accessing individual bits.

bitstruct FlagDword {
  Flag1[1];
  Flag2[1];
  Mask[3];
};

This declaration introduces two one bit fields Flag1 and Flag2, and one three bit field Mask. Field values are treated as unsigned decimals, so Flag1 and Flag2 may be either 0 or 1, and Mask accepts value from 0 to 7.

The keyword bitstruct may be preceded by a size specifier byte, word, dword, or qword. If the size keyword is omitted, FlexHEX assumes the size is 32-bit; for instance, the above declaration defines a 32-bit (double word) structure.

Bits are allocated incrementally starting from the least significant bit. In the above example Flag1 occupies bit 0, Flag2 - bit 1, and Mask - bits 2 to 4. In order to skip some bits use the unused keyword. For example, the following declaration:

byte bitstruct FlagByte {
  unused[1];
  Valid[1];
  Locked[1];
  unused[2];
  nLocks[3];
};

will create a byte-sized bit structure with the bits positioned as follows:

  • Bit 0 is not used.
  • Bit flag Valid occupies bit 1.
  • Bit flag Locked occupies bit 2.
  • Bits 3 and 4 are not used.
  • The three-bit long number nLocks occupies bits 5 to 7.

Anonymous Bit Structures

Like other composite data structures, bit structures may be anonymous, that is used without declaring an associated type. An anonymous bit structure lacks the type name between the bitstruct keyword and the opening curly bracket, and can be used wherever a type name is expected.

struct DocumentRecord {
  FILETIME CreationTime;
  byte bitstruct {
    Valid[1];
    Locked[1];
  } Status;
  char szName[];
};

 

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