Pro text/hex editor
with Binary Templates

010 Editor - Text/Hex Editor Homepage

The following is a list of input/output functions that can be used when writing Templates or Scripts.


void BigEndian()
Indicates that all subsequent reads and writes from the file should use big-endian byte order. This function can be used in a Template to specify the byte order of variables. See LittleEndian to set little-endian byte order.


void BitfieldDisablePadding()
void BitfieldEnablePadding()
These functions control how multiple bitfields are packed into a set of bits. See Bitfields more information on bitfields. Padding is enabled by default.


int BitfieldGetCurrentShift()
Returns the number of bits that have been read so far when defining template variables using bitfields. This value, along with the FTell function, indicate the current bit read position in a file. Zero is returned if no bitfields have been defined. Note that this function returns the same value whether bitfields are being read in left-to-right or right-to-left format (see Bitfields for more information). The current bit read position is calculated differently when using padded bitfields versus unpadded bitfields. When using the padded bitfields (the default), the bit read position cumulates but will reset when the data type changes. For example:

    local int shift; 
    int a : 5;
    shift = BitfieldGetCurrentShift(); // value of 5
    int b : 12;
    shift = BitfieldGetCurrentShift(); // value of 17
    short c : 2;
    shift = BitfieldGetCurrentShift(); // value of 2

When using unpadded bitfields the position does not reset when the data type changes but the position is always in the range 0..7. For example:

    local int shift;
    BitfieldDisablePadding();
    short a : 3; 
    shift = BitfieldGetCurrentShift(); // value of 3
    short b : 7; 
    shift = BitfieldGetCurrentShift(); // value of 2 (10 mod 8)
Requires 010 Editor v15.0 or higher.

void BitfieldLeftToRight()
void BitfieldRightToLeft()
These functions control how bitfields are packed into a variable. See Bitfields for an introduction to using bitfields. The packing is different depending on if the Template is in big or little endian mode and the packing may change after calling the LittleEndian or BigEndian functions. In little endian mode the default is right-to-left and in big endian mode the default is left-to-right.


double ConvertBytesToDouble( uchar byteArray[] )
float ConvertBytesToFloat( uchar byteArray[] )
hfloat ConvertBytesToHFloat( uchar byteArray[] )
These functions take as input an array of hex bytes byteArray and returns either the double, float, or hfloat that is represented by those bytes. The byteArray parameter must contain at least 8 bytes for the ConvertBytesToDouble function, 4 bytes for the ConvertBytesToFloat function, or 2 bytes for the ConvertBytesToHFloat function. The conversion is performed using the endian for the current file, which can be controlled using the BigEndian or LittleEndian functions. See the ConvertDataToBytes function to convert a double, float, or hfloat to a set of bytes.

Requires 010 Editor v5.0 or higher.

int ConvertDataToBytes( data_type value, uchar byteArray[] )
Given a variable value that can be of any of the main data types (e.g. float, short, int, etc.), this function converts the variable to a set of bytes as it would be written to a file and stores the results in the byteArray variable. The return value is the number of bytes written to the array. Note that byteArray must be large enough to hold the bytes from the conversion. The endian used for the conversion is taken from the current file endian, which can be set using the BigEndian or LittleEndian functions.

Requires 010 Editor v3.1 or higher.

void DeleteBytes( int64 start, int64 size )
Deletes size bytes from the file, starting at local address start.


int DirectoryExists( string dir )
Returns true if the given directory exists on disk or false if it does not. dir should be the full path for a directory.


int DisasmGetMode()
Returns the current disassembler mode set with the DisasmSetMode function. If no disassembler mode has been set then zero is returned. The returned mode is a bitwise OR of the disassembler architecture and any disassembler options. The list of possible architectures and options is listed in the DisasmSetMode function.

Requires 010 Editor v12.0 or higher.

int64 DisasmNumOps( Opcode ops[] )
010 Editor has a special optimization for disassembling large blocks of data. When creating an Opcode array, the size specified between the '[' and ']' brackets is the number of bytes, not the number of Opcodes. Each Opcode contains a variable number of bytes meaning that the number of opcodes will always be less or equal to the number of bytes in the array. Call the DisasmNumOps function to retrieve the number of Opcodes inside the Opcode array. See Arrays of Opcodes for more information and an example.

Requires 010 Editor v12.0 or higher.

int DisasmOpSizeFromFile( int64 pos )
Given a starting address pos in a file, calculates the Opcode at that address and returns the number of bytes the Opcode uses. Returns 0 if no valid opcode could be found at the address. Note the current disassembly mode must be set with DisasmSetMode before this function is called. This function can be used in Scripts or Templates and see Disassembly in Scripts for more information.

Requires 010 Editor v12.0 or higher.

string DisasmOpString( Opcode &op )
Given an Opcode op, this function converts the opcode into a string which represents the assembly language for that opcode and returns the string. If the opcode could not be converted into assembly language then an empty string is returned. See the Disassembler and Disassembly in Templates help topics for more information about Opcodes.

Requires 010 Editor v12.0 or higher.

string DisasmOpStringFromFile( int64 pos )
Given a position in a file pos, this function converts the bytes starting at the position into an Opcode and returns a string representing the Opcode. If no valid Opcode is found then an empty string is returned. The number of bytes the Opcode uses can be calculated with the DisasmOpSizeFromFile function. A disassembly mode must be set with the DisasmSetMode function before calling this function. Scripts and Templates can both use this function and see Disassembly in Scripts for more information.

Requires 010 Editor v12.0 or higher.

void DisasmSetMode( int mode )
Sets the current disassembler mode, which consists of an architecture possibly OR'd with a number of option flags. Any Opcode variables defined after this function is called will be assigned the given disassembler mode. The disassembler mode can also be assigned to a variable using the syntax < disasm=<mode> > after a variable and see Disassembly in Templates for more information. The following architectures constants are available:

  • DISASM_ARM_32
  • DISASM_ARM_64
  • DISASM_MIPS_32
  • DISASM_MIPS_64
  • DISASM_X86_16
  • DISASM_X86_32
  • DISASM_X86_64
  • DISASM_POWERPC_32
  • DISASM_POWERPC_64
  • DISASM_SPARC
  • DISASM_SYSTEMZ
  • DISASM_XCORE
  • DISASM_M68K (Motorola 68000)

An architecture constant may be OR'd with a number of different flags:

  • DISASM_OPTION_ATT - use AT&T syntax for assembly language
  • DISASM_OPTION_ARM_V8
  • DISASM_OPTION_ARM_MCLASS
  • DISASM_OPTION_ARM_THUMB
  • DISASM_OPTION_MIPS_MICRO
  • DISASM_OPTION_MIPS_32R6
  • DISASM_OPTION_MIPS_2
  • DISASM_OPTION_MIPS_3
  • DISASM_OPTION_POWERPC_QPX
  • DISASM_OPTION_SPARC_V9
  • DISASM_OPTION_M68K_010
  • DISASM_OPTION_M68K_020
  • DISASM_OPTION_M68K_030
  • DISASM_OPTION_M68K_040
  • DISASM_OPTION_M68K_060

For example:

    DisasmSetMode( DISASM_X86_32 | DISASM_OPTION_ATT );
Requires 010 Editor v12.0 or higher.
Requires 010 Editor v13.0 or higher for DISASM_M68K constants.

int FEof()
Returns true if the current read position is at the end of the file.


int64 FileSize()
Returns the size of the current file in bytes.


TFileList FindFiles( string dir, string filter )
This function scans the given directory dir and returns all files that match the filter. The filter can contain the wildcard characters * and ? and can contain multiple filters separated by semi-colons (for example, "*.cpp;*.c;*.h"). The results are returned in a TFileList structure which has a filecount variable indicating the number of files that match the filter, and an array of file variables which each contain a string filename. The TFileList also contains a list of sub-directories in the given directory. The dircount variable indicates how many sub-directories exist and an array of dir variables contains a dirname string for each directory. For example:

     TFileList fl = FindFiles( "C:\\temp\\", "*.zip" );
     int i;
     Printf( "Num files = %d\n", fl.filecount );
     for( i = 0; i < fl.filecount; i++ )
     {
         Printf( " %s\n", fl.file[i].filename );
     }
     Printf( "\n" );
     Printf( "Num dirs = %d\n", fl.dircount );
     for( i = 0; i < fl.dircount; i++ )
     {
         Printf( " %s\n", fl.dir[i].dirname );
     } 


int FPrintf( int fileNum, char format[], ... )
Performs a Printf starting from format and writes the resulting string to the file with index fileNum. Use the function GetFileNum to get the index of a file. The string is written at the current read/write position as given by FSeek and then the read/write position is moved forward. Use this function to read data from one file and write the results to another file. This function can also be used in a Template to write data to a different file as the Template is being run (see Permissions). See Printf for more information on format specifiers.


int FSeek( int64 pos )
Sets the current read position to the local address pos. The read position is used when defining variables in a Template. Using this function, bytes can be processed in any order. Returns 0 if successful or -1 if the address was out of range. Use the FTell function to query the current read position.


int FSkip( int64 offset )
Moves the current read position ahead by offset bytes. offset can also be negative to move the read position backwards. The read position is used when defining variables in a template. Using this function, bytes can be processed in any order. Returns 0 if successful, or -1 if the address was out of range.


int64 FTell()
Returns the current read position of the file in local coordinates. This read position is used when defining variables in a Template. Every time a variable is defined in a template, the read position moves ahead the number of bytes used by the variable. See the FSeek and FSkip functions for another way to change the read position, and note that functions like ReadByte do not affect the read position.


void InsertBytes( int64 start, int64 size, uchar value=0 )
Inserts size bytes into the file starting at local address start. If start is at the end of the file, the file will be lengthened by size bytes. The value of each inserted byte can be controlled using the value parameter. Note that this function or any of the 'Write' functions can be used to lengthen a file. See also the OverwriteBytes function to overwrite data in a file.

Requires 010 Editor v5.0 or higher for the value parameter.

int IsBigEndian()
Returns true if the file is being read in big-endian byte order, or false otherwise.


int IsBitfieldLeftToRight()
Returns true if bitfields are being packed from left-to-right or false if bitfields are being packed from right-to-left. The current bitfield packing direction can be modified with the functions BitfieldLeftToRight and BitfieldRightToLeft.

Requires 010 Editor v11.0 or higher.

int IsBitfieldPaddingEnabled()
Returns true if padding is enabled for bitfields. Padding determines how bitfields are packed into variables and see the BitfieldEnablePadding or BitfieldDisablePadding functions to change the padding state.

Requires 010 Editor v11.0 or higher.

int IsLittleEndian()
Returns true if the file is being read in little-endian byte order, or false otherwise.


void LittleEndian()
Indicates that all subsequent reads and writes from the file should use little-endian byte order. This function can be used in a Template to specify the byte order of variables. See BigEndian to set big-endian byte order.


int MakeDir( string dir )
Attempts to create the directory given by dir. If any of the parent directories of the given directory do not exist, they will be created too. For example, MakeDir( "C:\\app\\data\\backup\\" ) will create the directories "C:\app\" and "C:\app\data\" if necessary. Returns true if the functions succeeds or false otherwise. dir is specified in UTF-8 format.


void OverwriteBytes( int64 start, int64 size, uchar value=0 )
Overwrites size bytes in the file starting at local address start. The value of each byte written is controlled by the value parameter. If the overwrite goes past the end of the file, the file will automatically be lengthened. See also the InsertBytes function to insert data into a file.

Requires 010 Editor v5.0 or higher.

char ReadByte( int64 pos=FTell() )
double ReadDouble( int64 pos=FTell() )
float ReadFloat( int64 pos=FTell() )
hfloat ReadHFloat( int64 pos=FTell() )
int ReadInt( int64 pos=FTell() )
int64 ReadInt64( int64 pos=FTell() )
int64 ReadQuad( int64 pos=FTell() )
short ReadShort( int64 pos=FTell() )
uchar ReadUByte( int64 pos=FTell() )
uint ReadUInt( int64 pos=FTell() )
uint64 ReadUInt64( int64 pos=FTell() )
uint64 ReadUQuad( int64 pos=FTell() )
ushort ReadUShort( int64 pos=FTell() )
Returns data read from the file at local address pos. If no pos is given, pos defaults to the current read position as reported by FTell. These functions can be used in a Template to read data from a file without declaring a variable and note that these functions do not affect the current read position.

Requires 010 Editor v5.0 or higher for the ReadHFloat function.
Requires 010 Editor v6.0 or higher for the default parameter.

char[] ReadLine( int64 pos, int maxLen=-1, int includeLinefeeds=true )
Reads a string from the file starting at local address pos. Reads characters until a null-character or end-of-line sequence is found. If maxLen is greater than zero, the returned string will have at most maxLen characters but if maxLen is -1 the parameter will be ignored. If includeLinefeeds is true the linefeeds will be returned as part of the string, otherwise the linefeed characters will not be included.

Requires 010 Editor v5.0 or higher for the maxLen parameter.
Requires 010 Editor v6.0 or higher for the includeLinefeeds parameter.

void ReadBytes( uchar buffer[], int64 pos, int n )
Reads n bytes starting from the local address pos into the character array buffer. Note that char[] and uchar[] can be used interchangeably.


char[] ReadString( int64 pos, int maxLen=-1 )
Reads a string from the file starting at local address pos. Reads characters until a null-character is found or maxLen characters are read. If maxLen equals -1, the maxLen parameter is ignored.

Requires 010 Editor v5.0 or higher for the maxLen parameter.

int ReadStringLength( int64 pos, int maxLen=-1 )
Returns the length of a null-terminated string if it were read at the local address pos in the target file. In other words, this function counts the number of bytes until a null-byte is encountered, starting from address pos. The returned length includes space for the null-character. If maxLen is greater than zero, the returned string will have at most maxLen bytes but if maxLen is -1, the file will be scanned until the end-of-file is reached.

Requires 010 Editor v4.0 or higher.

wstring ReadWLine( int64 pos, int maxLen=-1 )
Reads a wide (unicode) string from the file starting at local address pos. The string is read until a null-character or end-of-line sequence is encountered. If maxLen is greater than zero, the returned string will have at most maxLen characters but if maxLen is -1 the parameter will be ignored. Note that the endian used for reading is taken from the current file endian, which can be set using the BigEndian or LittleEndian functions.

Requires 010 Editor v3.1 or higher.
Requires 010 Editor v5.0 or higher for the maxLen parameter.

wstring ReadWString( int64 pos, int maxLen=-1 )
Reads a wide (unicode) string from the file starting at the local address pos. The string is read until a null-character is encountered or maxLen characters are read. If maxLen equals -1, the maxLen parameter is ignored. Note that the endian used for reading is taken from the current file endian, which can be set using the BigEndian or LittleEndian functions.

Requires 010 Editor v3.1 or higher.
Requires 010 Editor v5.0 or higher for the maxLen parameter.

int ReadWStringLength( int64 pos, int maxLen=-1 )
Calculates the number of characters in a null-terminated Unicode string if it were read at local address pos in the target file. This is equivalent to counting the number of words (a word is a group of two hex bytes) in the file until a word with zero value is encountered. The returned count includes the null-terminating word. By default this function searches until it reaches the end of the file but can be limited to a set number of characters by setting maxLen to a value greater than zero.

Requires 010 Editor v4.0 or higher.

int64 TextAddressToLine( int64 address )
Given address in local coordinates, the position of a byte within a text file, this function returns the number of the line that contains that byte. Note that lines are numbered starting from 0. If the file is not a text file or the address is invalid, -1 is returned. See TextLineToAddress for the inverse operation.

Requires 010 Editor v3.2 or higher.

int TextAddressToColumn( int64 address )
Given an address of a byte in a file in local coordinates, this function returns the text column where that byte is located. Note that a column number is returned only when using a fixed-width font, otherwise -1 is returned. If the address does not reference a valid byte or the file is not a text file, -1 is also returned.

Requires 010 Editor v3.2 or higher.

int64 TextColumnToAddress( int64 line, int column )
Given a line number line (note that line numbers start from 0) and a column, this function returns the byte address of the character in that column in local coordinates. If the address cannot be determined -1 is returned or if the line contains less than column number of columns, the address of the last character on the line is returned.

Requires 010 Editor v4.0 or higher.

int64 TextGetNumLines()
Returns the number of lines in the current text file. If the current file is a hex file, -1 is returned.

Requires 010 Editor v3.2 or higher.

int TextGetLineSize( int64 line, int includeLinefeeds=true )
Returns the number of bytes that the given line contains. The returned size includes the size of the linefeeds if includeLinefeeds is true but does not include the size of the linefeeds if includeLinefeeds is false. Note that line numbers start at 0 and if an invalid line is passed to this function, -1 is returned. If the current file is not a text file, -1 is also returned.

Requires 010 Editor v3.2 or higher.
Requires 010 Editor v6.0 or higher for the includeLinefeeds parameter.

int64 TextLineToAddress( int64 line )
Given a line number, this function returns the address of the first byte of that line in local coordinates. Note that line numbers start with 0. See TextAddressToLine for the inverse operation.

Requires 010 Editor v3.2 or higher.

int TextReadLine( char buffer[], int64 line, int maxsize, int includeLinefeeds=true )
This function reads the byte data from line number line and places it into the string buffer. Up to maxsize bytes will be read from the file and the number of bytes read is returned. If line is an invalid line an empty string will be placed into the buffer. Note that the returned string will not include linefeed characters if includeLinefeeds is false.

Requires 010 Editor v3.2 or higher.
Requires 010 Editor v6.0 or higher for the includeLinefeeds parameter.

int TextReadLineW( wchar_t buffer[], int64 line, int maxsize, int includeLinefeeds=true )
Reads bytes from the given line and places them into the wide string buffer. The full line, up to maxsize characters will be read from the file and the number of characters read is returned. Use this function if the current file is a Unicode file, otherwise use the TextReadLine function. The returned buffer will include linefeed characters if includeLinefeeds is true and will not include linefeeds if includeLinefeeds is false.

Requires 010 Editor v3.2 or higher.
Requires 010 Editor v6.0 or higher for the includeLinefeeds parameter.

void TextWriteLine( const char buffer[], int64 line, int includeLinefeeds=true )
Writes the data from the buffer to the given line, replacing the existing data of that line. Note that line numbers start at 0. If the line to write is longer or shorter than the existing line, the file will be automatically expanded or contracted. If includeLinefeeds is true the data to write should contain a linefeed at the end of the line, and if includeLinefeeds is false the data should not contain a linefeed.

Requires 010 Editor v3.2 or higher.
Requires 010 Editor v6.0 or higher for the includeLinefeeds parameter.

void TextWriteLineW( const wchar_t buffer[], int64 line, int includeLinefeeds=true )
This function writes the wide string from buffer to the given text file at line number line. Use this function if the current file is a Unicode file, otherwise use the TextWriteLine function. Line numbers start at 0 and if the data to write is longer or shorter than the existing line, the file will be automatically expanded or contracted. buffer should contain a linefeed if includeLinefeeds is true and buffer should not contain linefeeds if includeLinefeeds is false.

Requires 010 Editor v3.2 or higher.
Requires 010 Editor v6.0 or higher for the includeLinefeeds parameter.

void WriteByte( int64 pos, char value )
void WriteDouble( int64 pos, double value )
void WriteFloat( int64 pos, float value )
void WriteHFloat( int64 pos, float value )
void WriteInt( int64 pos, int value )
void WriteInt64( int64 pos, int64 value )
void WriteQuad( int64 pos, int64 value )
void WriteShort( int64 pos, short value )
void WriteUByte( int64 pos, uchar value )
void WriteUInt( int64 pos, uint value )
void WriteUInt64( int64 pos, uint64 value )
void WriteUQuad( int64 pos, uint64 value )
void WriteUShort( int64 pos, ushort value )
Writes the value to the current file at the local address pos. Note that if bytes are written past the end of the file, the file will automatically be expanded.

Requires 010 Editor v5.0 or higher for the WriteHFloat function.

void WriteBytes( const uchar buffer[], int64 pos, int n )
Writes n bytes from the array buffer to the file at the local address pos. Note that char[] and uchar[] can be used interchangeably. If bytes are written past the end of the file, the file will automatically be expanded.


void WriteString( int64 pos, const char value[] )
Writes the string value to the current file at local address pos. Stops when the null-character is reached.


void WriteWString( int64 pos, const wstring value )
Writes the wide string value to the current file at local address pos and stops when the null-character is reached. Note that the endian used for writing is taken from the current file endian, which can be set using the BigEndian or LittleEndian functions.

Requires 010 Editor v3.1 or higher.

















This is the manual for 010 Editor, a professional hex editor and text 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 v15.0 is here!
What's new?



E-mail: info@sweetscape.com