Edit Anything

Professional text and hex editing
with Binary Templates technology.





010 Editor - Text/Hex Editor Homepage

Some binary file formats use variable types that are different from the regular Data Types. 010 Editor has a powerful syntax for letting you define custom variables in practically any format. To build a custom variable, write a custom function that converts a variable into a string. This string will be displayed in the Template Results panel as the value for the variable (this custom function is called a read function). Optionally, a write function can be written that converts a string in the Template Results panel back to the variable when the variable is edited and Enter is pressed. To assign a read and write function to a variable, use the syntax '<read= <function_name> [, write= <function_name> ] >'after a typedef. A read function takes as arguments a variable and returns a string. A write function takes as arguments a reference to a variable and a string. For example, to define a fixed point data type that uses 16 bits (the 8 high bits define the whole part and the 8 low bits define the fractional part), use:

    typedef ushort FIXEDPT <read=FIXEDPTRead, write=FIXEDPTWrite>;

    string FIXEDPTRead( FIXEDPT f )
    {
        string s;   
        SPrintf( s, "%lg", f / 256.0 );
        return s;
    }

    void FIXEDPTWrite( FIXEDPT &f, string s )
    {
        f = (FIXEDPT)( Atof( s ) * 256 );
    }

In this example, the FIXEDPT variable could be defined without a write function using '<read=FIXEDPTRead>', but the variable will be read-only in the Template Results panel. Note that the typedef must be defined before the functions in the source file. If an error can occur when a write function is called, change the return value to int and return 0 on success or -1 on failure.

If a run-time error occurs inside a read function, 010 Editor will display "(error)" in the Template Results panel and then display "(error)" every time the read function was to be called (010 Editor will not repeatedly call functions which cause run-time errors because of performance issues). Fix the error within the read function and then re-run the template to use the read function again.

When displaying arrays in the Template Results panel, usually no value is displayed for an array until the array is opened up. To specify a value beside the array, a custom variable can be defined. For example:

    typedef float VEC3F[3] <read=Vec3FRead, write=Vec3FWrite>;

    string Vec3FRead( VEC3F v )
    {
        string s;   
        SPrintf( s, "(%f %f %f)", v[0], v[1], v[2] );
        return s;
    }

    void Vec3FWrite( VEC3F &v, string s )
    {
        SScanf( s, "(%f %f %f)", v[0], v[1], v[2] );
    }

Note that currently, read/write functions cannot be declared simultaneously for an array of elements and for each element of the array. The same process can be used to display a value for a struct in the Template Results panel. For an example, see the 'ZIPTemplate.bt' file that uses a read function to display the file name beside each structure.


This is the manual for 010 Editor, a professional hex editor and disk editor. Use 010 Editor to edit the individual bytes of any binary file, hard drive, or process on your machine. 010 Editor contains a whole host of powerful analysis and editing tools, plus Binary Templates technology that allows any binary format to be understood.





Newsletter - Receive special offers, tips, tricks and news. Join now



010 Editor v8.0.1 is here!
What's new?


Navigation


Products

010 Editor














E-mail: info@sweetscape.com