Click here to Skip to main content
12,448,563 members (55,331 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked

Binary Templates - A New Way of Editing Binary Files

, 14 Jan 2004
Rate this:
Please Sign up or sign in to vote.
Introduces Binary Templates, a new way of editing binary files. Binary Templates look like C/C++ structures but are run as a program, and thus are extremely flexible and can be used for parsing virtually any binary file.

Sample Image - binary_templates.gif


Binary files have always been difficult to edit, usually involving scanning through an endless number of bytes using a hex editor. Binary Templates offer a new way to edit a binary file that is much easier and more intuitive. A Binary Template looks similar to a C/C++ structure definition; however, Binary Templates are much more powerful than structures since they are executed as a program. This difference allows complex expressions, functions, and control statements such as if-else or do-while, to be contained inside of the C/C++ structures. Thus Binary Templates are powerful and flexible enough to work with practically any binary file format, from WAV files up to Word documents.

Binary Templates are currently supported by 010 Editor, a professional hex editor by SweetScape Software. When a Binary Template is run in 010 Editor, a binary file is parsed into a hierarchal data structure that can be viewed and edited using the program's interface. To install 010 Editor and some sample Binary Templates for BMP and ZIP files, see the download link above.

Sample Code

The code below demonstrates a sample Binary Template that could be used to read your own custom image format. Whenever a variable is declared, that variable is mapped to a set of bytes in a binary file. For example, the variable header would be mapped to the first four bytes of the file, the variable version to the next 4 bytes, and so on.

// Define a structure used for a color
typedef struct
    uchar   red;
    uchar   green;
    uchar   blue;

// Define the image file
struct FILE
    // Define the header information
    char    header[4];
    int     version;
    int     width;
    int     height;
    int     format;

    // Define the lines of the bitmap
    struct LINE
        RGBTRIPLE colors[ file.width ];
    lines[ file.height ];

} file;

Binary Templates can also contain control statements. For example, to read a different set of lines based on the version, you could use:

// Define the lines of the bitmap
struct LINE
    if( file.version == 0 )
        RGBTRIPLE colors[file.width];
        RGBQUAD   colors[file.width];
lines[ file.height ];

Templates have a number of other powerful features. Local variables that are not mapped to a file can be declared using the local keyword. Over 90 different functions are available for reading data, manipulating strings, or calling mathematical functions. Coloring can be applied to different parts of the file and big and little endian data is easily handled. Most Templates parse a file starting at the beginning and move to the end; however, parsing a file in any order is possible by using the functions FSeek or FTell.

To see a Binary Template in action, download and install 010 Editor from the link at the top of the page. Then open a BMP or ZIP file and a Template will automatically be run. Next click on the 'Template' tab of the Inspector and the whole file will be presented in a data structure for easy editing.

For More Information

More information on Binary Templates or 010 Editor see:


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Canada Canada
No Biography provided

You may also be interested in...


Comments and Discussions

Generalfinding out LOC from a Binary File Pin
d_s_kumar30-Sep-04 19:51
memberd_s_kumar30-Sep-04 19:51 
GeneralRe: finding out LOC from a Binary File Pin
Mr.Prakash25-Nov-04 5:11
memberMr.Prakash25-Nov-04 5:11 
GeneralPlz delete this article, as this is a total ad. Pin
Snyp17-Jan-04 11:26
memberSnyp17-Jan-04 11:26 
GeneralRe: Plz delete this article, as this is a total ad. Pin
Jerry Jeremiah30-Apr-06 19:20
memberJerry Jeremiah30-Apr-06 19:20 
GeneralRe: Plz delete this article, as this is a total ad. Pin
Troy Marchand2-May-06 10:27
sitebuilderTroy Marchand2-May-06 10:27 
GeneralRe: Plz delete this article, as this is a total ad. Pin
Jerry Jeremiah2-May-06 19:28
memberJerry Jeremiah2-May-06 19:28 
QuestionWhere is the source code? Pin
WREY15-Jan-04 22:26
memberWREY15-Jan-04 22:26 
AnswerRe: Where is the source code? Pin
Ian Prest16-Jan-04 2:16
sussIan Prest16-Jan-04 2:16 
GeneralRe: Where is the source code? Pin
gsweet16-Jan-04 4:14
membergsweet16-Jan-04 4:14 
GeneralRe: Where is the source code? Pin
Darren Schroeder21-Jan-04 2:43
memberDarren Schroeder21-Jan-04 2:43 
GeneralRe: Where is the source code? Pin
Jerry Jeremiah30-Apr-06 19:34
memberJerry Jeremiah30-Apr-06 19:34 
GeneralRe: Where is the source code? Pin
gsweet2-May-06 10:41
membergsweet2-May-06 10:41 
GeneralRe: Where is the source code? Pin
Andrew Phillips7-Apr-08 18:45
memberAndrew Phillips7-Apr-08 18:45 
GeneralThis is great! Pin
Daniel Turini15-Jan-04 8:59
memberDaniel Turini15-Jan-04 8:59 
GeneralRe: This is great! Pin
leppie15-Jan-04 9:34
memberleppie15-Jan-04 9:34 
GeneralHell, THE editor ! Pin
Kochise15-Jan-04 20:29
memberKochise15-Jan-04 20:29 
GeneralRe: Hell, THE editor ! Pin
gsweet16-Jan-04 4:36
membergsweet16-Jan-04 4:36 
GeneralRe: This is great! Pin
Andrew Phillips7-Apr-08 18:39
memberAndrew Phillips7-Apr-08 18:39 
QuestionAdvantages? Pin
dog_spawn15-Jan-04 8:02
memberdog_spawn15-Jan-04 8:02 
AnswerRe: Advantages? Pin
gsweet16-Jan-04 3:52
membergsweet16-Jan-04 3:52 
GeneralRe: Advantages? Pin
dog_spawn16-Jan-04 4:02
memberdog_spawn16-Jan-04 4:02 
GeneralRe: Advantages? Pin
Andrew Phillips7-Apr-08 18:33
memberAndrew Phillips7-Apr-08 18:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160811.3 | Last Updated 15 Jan 2004
Article Copyright 2004 by gsweet
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid