Edit Anything

Professional text and hex editing
with Binary Templates technology.





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.


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.


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. 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 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 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 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. 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 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 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.


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.


void OverwriteBytes( int64 start, int64 size, uchar value=0 )
Overwrites size bytes in the file starting at 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 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 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 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 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 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 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 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 byte position 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, 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, 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. 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. 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 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 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 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 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 binary 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 is here!
What's new?


Navigation


Products

010 Editor














E-mail: info@sweetscape.com