010Editor腳本語法入門

<從老帖子扒過來的,CSDN之前被封號了>

簡介

??010editor是一款十六進(jìn)制編輯器,和winhex相比支持更靈活的腳本語法重虑,可以對文件蝇裤、內(nèi)存廷支、磁盤進(jìn)行操作

文件模板

??
(*.bt)用于識別文件類型http://www.sweetscape.com/010editor/repository/templates/

  • 支持cab gzip rar zip cda midi mp3 ogg wav avi flv mp4 rm pdf iso vhd lnk dmp dex androidmanifest class
  • Drive.bt 解析mbr fat16 fat43 hfs ntfs等
  • elf.bt 解析Linux elf格式的文件
  • exe.bt 解析windows pe x86/x64 格式文件(dll sys exe ...)
  • macho.bt 解析mac os可執(zhí)行文件
  • registrayhive.bt 解析注冊表(Hive)文件
  • bson.bt 解析二進(jìn)制json

腳本模板

??常用的腳本庫(*.1sc)用于操作數(shù)據(jù)http://www.sweetscape.com/010editor/repository/scripts/

  • CountBlocks.1sc 查找指定數(shù)據(jù)塊
  • DecodeBase64.1sc 解碼base64
  • EncodeBase64.1sc 編碼base64
  • Entropy.1sc 計算熵
  • JoinFIle.1sc SplitFile.1sc 分隔合并文件
  • Js-unicode-escape.1sc Js-unicode-unescape.1sc URLDecoder.1sc js編碼解碼
  • CopyAsAsm.1sc CopyAsBinary.1sc CopyAsCpp.1sc CopyAsPython.1sc 復(fù)制到剪貼板
  • DumpStrings.1sc 查找所有ascii unicode字符串

語法

010Editor內(nèi)置腳本語言語法類似于c++,這種結(jié)構(gòu)體不同之處在于:

  • 訪問變量時栓辜,從文件讀取并顯示恋拍,賦值變量時,寫入文件
  • 可以使用控制語句如if for while
    struct FILE   
    {  
        struct HEADER   
        {  
            char type[4];  
            int version;  
            int numRecords;  
        } header;  
        struct RECORD   
        {  
        int employeeId;  
        char name[40];  
        float salary;  
        } record[ header.numRecords ];  
    } file;  

控制語句實例:

    int i;  
    for( i = 0; i < file.header.numRecords; i++ )  
     file.record[i].salary *= 2.0;  

表達(dá)式

  • 支持標(biāo)準(zhǔn)c的操作符:+ - * / ~ ^ & | % ++ -- ?: << >> ()
  • 支持的比較操作符:< ? <= >= == != !
  • 支持的賦值操作符:= += -= *= /= &= ^= %= |= <<= >>=
  • 布爾運(yùn)算符:&& || !
  • 常數(shù)
    • 10進(jìn)制 456
    • 16進(jìn)制 0xff 25h 0EFh
    • 8進(jìn)制 013
    • 2進(jìn)制 0b011
    • u后綴表示unsigned L后綴表示8字節(jié)int64值
    • 指數(shù) 1e10
    • 浮點數(shù) 2.0f 2.0

變量

  • 定義腳本變量
int x;
float a = 3.5f;
unsigned int myVar1, myVar2;
  • 常量
const int TAG_EOF = 0x3545;
  • 內(nèi)建常量
true false TRUE FALSE M_PI PI

數(shù)據(jù)類型

  • 8字節(jié) char byte CHAR BYTE uchar ubyte UCHAR UBYTE
  • 16字節(jié) short int16 SHORT INT16 ushort uint16 USHORT UINT16 WORD
  • 32字節(jié) int int32 long INT INT32 LONG uint uint32 ulong UINT UINT32 ULONG DWORD
  • 64字節(jié) int64 quad QUAD INT64 __int64 uint64 uquad UQUAD UINT64 __uint64 QWORD
  • 浮點 float FLOAT double DOUBLE hfloat HFLOAT
  • 其他 DOSDATE DOSTIME FILETIME OLETIME time_t
  • 使用typedef
typedef unsigned int myInt;
typedef char myString[15];
myString s = "Test";
  • 使用enum
enum MYENUM { COMP_1, COMP_2 = 5, COMP_3 } var1;
enum <ushort> MYENUM { COMP_1, COMP_2 = 5, COMP_3 } var1;
  • 數(shù)組和字符串
int myArray[15];
int myArray[ FileSize() - myInt * 0x10 + (17 << 5) ];//大小可以是變量
    char str[15] = "First";  
    string s = "Second";  
    string r1 = str + s;  
    string r2 = str;  
    r2 += s;  
    return (r1 == r2);  
  • 寬字符
 wchar_t str1[15] = L"How now";  
wstring str2 = "brown cow";  
wstring str3 = str1 + L' ' + str2 + L'?'

可以通過WStringToString StringToWString轉(zhuǎn)換

控制語句

  • if語句
    if( x < 5 )  
    x = 0;  
    or  
    if( y > x )  
    max = y;  
    else  
    {  
    max = x;  
    y = 0;  
    }  
  • for有
    for( i = 0, x = 0; i < 15; i++ )  
    {  
    x += i;  
    }  
  • while語句
    while( myVar < 15 )  
    {  
    x *= myVar;  
    myVar += 2;  
    }  
    or  
    do  
    {  
    x *= myVar;  
    myVar += 2;  
    }  
    while( myVar < 23 );  
  • switch語句
    switch( <variable> )  
    {  
    case <expression>: <statement>; [break;]  
    .  
    .  
    .  
    default : <statement>;  
    }  
    switch( value )  
    {  
    case 2 : result = 1; break;  
    case 4 : result = 2; break;  
    case 8 : result = 3; break;  
    case 16 : result = 4; break;  
    default : result = -1;  
    }  
  • 循環(huán)控制
break continue return

函數(shù)

    string str = "Apple";  
    return Strlen( str );  
      
    Printf( "string='%s' length='%d'\n", str, Strlen( str ) );  
      
    void OutputInt( int d )  
    {  
    Printf( "%d\n", d );  
    }  
    OutputInt( 5 );  
      
    char[] GetExtension( char filename[], int &extLength )  
    {  
    int pos = Strchr( filename, '.' );  
    if( pos == -1 )  
    {  
    extLength = 0;  
    return "";  
    }  
    else  
    {  
    extLength = Strlen( filename ) - pos - 1;  
    return SubStr( filename, pos + 1 );  
    }  
    }  

??參數(shù)可以通過值或引用傳遞藕甩,010editor腳本不支持指針施敢,但是可以用[]表示數(shù)組
?程序中不需要main函數(shù),代碼從第一行開始執(zhí)行

關(guān)鍵字

  • sizeof
  • startof 用于計算變量起始地址
         SetCursorPos( startof( lines[0] ) );
  • exists 檢查某變量是否聲明
    int i;  
    string s;  
    while( exists( file[i] ) )  
    {  
    s = file[i].frFileName;  
    Printf( "%s\n", s );  
    i++;  
    }  
  • function_exists 檢查函數(shù)是否定義
    if( function_exists(CopyStringToClipboard) )  
    {  
    ...  
    }  
  • this 引用當(dāng)前結(jié)構(gòu)體
    void PrintHeader( struct HEADER &h )  
    {  
    Printf( "ID1 = %d\n", h.ID1 );  
    Printf( "ID2 = %d\n", h.ID2 );  
    }  
    struct HEADER  
    {  
    int ID1;  
    int ID2;  
    PrintHeader( this );  
    } h1;  
  • parentof 訪問包含變量的結(jié)構(gòu)和union
    void PrintHeader( struct HEADER &h )  
    {  
    Printf( "ID1 = %d\n", h.ID1 );  
    Printf( "ID2 = %d\n", h.ID2 );  
    }  
    struct HEADER  
    {  
    int ID1;  
    int ID2;  
    struct SUBITEM  
    {  
    int data1;  
    int data2;  
    PrintHeader( parentof(this) );  
    } item1;  
    PrintHeader( parentof(item1) );  
    } h1;  

預(yù)處理

  • define
#define PI 3.14159265
#define CHECK_VALUE if( value > 5) { \
Printf( "Invalid value %d\n", value ); \
Exit(-1); }
#define FILE_ICON 12
#define FOLDER_ICON (FILE_ICON+100)
  • 內(nèi)建常量
_010EDITOR  010editor運(yùn)行后定義
_010_WIN 運(yùn)行在windows上定義
_010_MAC
_010_LINUX
_010_64BIT
  • 條件編譯
    #ifdef | #ifndef <constant_name>  
    (...)  
    [ #else ]  
    (...)  
    #endif  
    #ifndef CONSTANTS_H  
    #define CONSTANTS_H  
  • 警告和錯誤
    #ifdef NUMBITS  
    value = value + NUMBITS;  
    #else  
    #warning "NUMBITS not defined!"  
    #endif  
    #ifndef CURRENT_OS  
    #error "CURRENT_OS must be defined. Compilation stopped."  
    #endif  
  • include
#include "Vector.bt"

腳本限制

  • 禁止使用指針辛萍,可以使用引用傳參數(shù)
  • 禁止使用#if預(yù)處理
  • 禁止使用多維數(shù)組
  • 禁止使用goto

模板基礎(chǔ)

聲明模板變量

  • 特殊屬性
    < format=hex|decimal|octal|binary,  
    fgcolor=<color>,  
    bgcolor=<color>,  
    comment="<string>"|<function_name>,  
    name="<string>"|<function_name>,  
    open=true|false|suppress,  
    hidden=true|false,  
    read=<function_name>,  
    write=<function_name>  
    size=<number>|<function_name> >  
  • format設(shè)置
int crc <format=hex>;
int flags <format=binary>;
  • color設(shè)置
    int id <fgcolor=cBlack, bgcolor=0x0000FF>;  
    SetForeColor( cRed );  
    int first; // will be colored red  
    int second; // will be colored red  
    SetForeColor( cNone );  
    int third; // will not be colored  
  • 大小頭端設(shè)置

  • 注釋設(shè)置

    int machineStatus <comment="This should be greater than 15.">;  
    int machineStatus <comment=MachineStatusComment>;  
    string MachineStatusComment( int status )  
    {  
    if( status <= 15 )  
    return "*** Invalid machine status";  
    else  
    return "Valid machine status";  
    }  
  • 顯示名設(shè)置
 byte _si8 <name="Signed Byte">;

順序:在聲明模板變量后悯姊,當(dāng)前文件指針后移,通過FTell獲取當(dāng)前位置贩毕,通過FSeek FSkip移動指針  通過ReadByte ReadShort ReadInt任意讀取而不移動指針
  • 局部變量
    local int i, total = 0;  
    int recordCounts[5];  
    for( i = 0; i < 5; i++ )  
    total += recordCounts[i];  
    double records[ total ];  
  • 打開狀態(tài)設(shè)置
<open=true/false>展開/收斂節(jié)點
  • 字符串
    char str[];  
    string str;  
    wchar_t str[];  
    wstring str;  
  • 隱藏設(shè)置
<hidden=true/false>

結(jié)構(gòu)體聯(lián)合體

    struct myStruct {  
    int a;  
    int b;  
    int c;  
    };  
      
    struct myStruct {  
    int a;  
    int b;  
    int c;  
    } s1, s2;  
      
    struct myIfStruct {  
    int a;  
    if( a > 5 )  
    int b;  
    else  
    int c;  
    } s;  
      
    struct {  
    int width;  
    struct COLOR {  
    uchar r, g, b;  
    } colors[width];  
    } line1;  
      
    typedef struct {  
    ushort id;  
    int size;  
    }  
    myData;  
      
    union myUnion {  
    ushort s;  
    double d;  
    int i;  
    } u;  
      
    //帶參數(shù)結(jié)構(gòu)體  
    struct VarSizeStruct (int arraySize)  
    {  
    int id;  
    int array[arraySize];  
    };  
      
    typedef struct (int arraySize)  
    {  
    int id;  
    int array[arraySize];  
    } VarSizeStruct;  
    VarSizeStruct s1(5);  
    VarSizeStruct s2(7);  
 array, duplicate, optimizing

010editor允許重復(fù)模板變量

int x;/x[0]
int y;
int x;//x[1]

local int i;
for( i = 0; i < 5; i++ )
int x;//x[0-5]

010editor默認(rèn)認(rèn)為結(jié)構(gòu)體大小一致悯许,這樣生成大量結(jié)構(gòu)體數(shù)組的速度較快,若實際結(jié)構(gòu)體大小不一致則可能產(chǎn)生問題辉阶,此時用optimize=false先壕,如下例:
    typedef struct {  
    int id;  
    int length;  
    uchar data[ length ];  
    } RECORD;  
    RECORD record[5] <optimize=false>;  

位域

 int alpha : 5;
int : 12;
int beta : 15;

enum <ushort> ENUM1 { VAL1_1=25, VAL1_2=29, VAL1_3=7 } var1 : 12;
enum <ushort> ENUM2 { VAL2_1=5, VAL2_2=6 } var2 : 4;

用戶變量

指定如何顯示和修改數(shù)據(jù)

    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 );  
    }  
      
    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] );  
    }  

On-Demand結(jié)構(gòu)體

通過指定size解決大量變量消耗內(nèi)存問題

    typedef struct  
    {  
    int header;  
    int value1;  
    int value2;  
    } MyStruct <size=12>;  
      
    typedef struct {  
    <...>  
    uint frCompressedSize;  
    uint frUncompressedSize;  
    ushort frFileNameLength;  
    ushort frExtraFieldLength;  
    if( frFileNameLength > 0 )  
    char frFileName[ frFileNameLength ];  
    if( frExtraFieldLength > 0 )  
    uchar frExtraField[ frExtraFieldLength ];  
    if( frCompressedSize > 0 )  
    uchar frData[ frCompressedSize ];  
    } ZIPFILERECORD <size=SizeZIPFILERECORD>;  
    int SizeZIPFILERECORD( ZIPFILERECORD &r )  
    {  
    return 30 + // base size of the struct  
    ReadUInt(startof(r)+18) + // size of the compressed data  
    ReadUShort(startof(r)+26) + // size of the file name  
    ReadUShort(startof(r)+28); // size of the extra field  
    }  

模板限制

禁止多維數(shù)組

    typedef struct  
     {  
     float row[4];  
     }  
     MATRIX[4];  
     MATRIX m;  

函數(shù)

接口函數(shù)

    //書簽  
    void AddBookmark( int64 pos, string name, string typename, int arraySize=-1, int forecolor=cNone, int backcolor=0xffffc4, int moveWithCursor=false )  
    AddBookmark( GetCursorPos(), "endmarker","ZIPENDLOCATOR", -1, cRed );  
    int GetBookmarkArraySize( int index )  
    int GetBookmarkBackColor( int index )  
    int GetBookmarkForeColor( int index )  
    int GetBookmarkMoveWithCursor( int index )  
    string GetBookmarkName( int index )  
    int64 GetBookmarkPos( int index )  
    string GetBookmarkType( int index )  
    int GetNumBookmarks()  
    void RemoveBookmark( int index )  
    //斷言  
    void Assert( int value, const char msg[] = "" )  
    Assert( numRecords > 10,"numRecords should be more than 10." );  
    //剪貼板  
    void ClearClipboard()  
    void CopyBytesToClipboard( uchar buffer[], int size, int charset=CHARSET_ANSI, int bigendian=false )  
    void CopyStringToClipboard( const char str[], int charset=CHARSET_ANSI )  
    void CopyToClipboard()  
    void CutToClipboard()  
    int GetClipboardBytes( uchar buffer[], int maxBytes )  
    int GetClipboardIndex()  
    string GetClipboardString()  
    void PasteFromClipboard()  
    int SetClipboardIndex( int index )  
      
    文件  
    int DeleteFile( char filename[] )    //刪除文件,文件不能在編輯器中打開  
    void FileClose()//關(guān)閉當(dāng)前文件  
    int FileCount()//獲取editor打開的文件數(shù)  
    int FileExists( const char filename[] )//檢測文件存在  
    int FileNew( char interface[]="", int makeActive=true )//創(chuàng)建愛你文件  
    int FileOpen( const char filename[], int runTemplate=false, char interface[]="", int openDuplicate=false )//打開文件  
    int FileSave()   
    int FileSave( const char filename[] )   
    int FileSave( const wchar_t filename[] )   
    int FileSaveRange( const char filename[], int64 start, int64 size )   
    int FileSaveRange( const wchar_t filename[], int64 start, int64 size )//保存文件  
    void FileSelect( int index )//選擇讀寫的文件  
    int FindOpenFile( const char path[] )   
    int FindOpenFileW( const wchar_t path[] )//查找并打開文件  
    int GetFileAttributesUnix()  
    int GetFileAttributesWin()  
    int SetFileAttributesUnix( int attributes )  
    int SetFileAttributesWin( int attributes )  
    int GetFileCharSet()  
    char[] GetFileInterface()  
    int SetFileInterface( const char name[] )  
    char[] GetFileName()  
    wchar_t[] GetFileNameW()  
    int GetFileNum()  
    int GetReadOnly()  
    int SetReadOnly( int readonly )  
    string GetTempDirectory()  
    char[] GetTempFileName()  
    char[] GetTemplateName()   
    wchar_t[] GetTemplateNameW()  
    char[] GetTemplateFileName()   
    wchar_t[] GetTemplateFileNameW()  
    char[] GetScriptName()   
    wchar_t[] GetScriptNameW()  
    char[] GetScriptFileName()   
    wchar_t[] GetScriptFileNameW()  
    char[] GetWorkingDirectory()   
    wchar_t[] GetWorkingDirectoryW()  
    int RenameFile( const char originalname[], const char newname[] )  
    void RequiresFile()  
    void RequiresVersion( int majorVer, int minorVer=0, int revision=0 )  
    void RunTemplate( const char filename[]="", int clearOutput=false )  
    int SetWorkingDirectory( const char dir[] )   
    int SetWorkingDirectoryW( const wchar_t dir[] )  
      
    //輸入  
    char[] InputDirectory( const char title[], const char defaultDir[]="" )  
    double InputFloat( const char title[], const char caption[], const char defaultValue[] )  
    int InputNumber( const char title[], const char caption[], const char defaultValue[] )  
    char[] InputOpenFileName( char title[], char filter[]="All files (*.*)", char filename[]="" )  
    TOpenFileNames InputOpenFileNames( char title[], char filter[]="All files (*.*)", char filename[]="" )  
        int i;  
        TOpenFileNames f = InputOpenFileNames(  
        "Open File Test",  
        "C Files (*.c *.cpp)|All Files (*.*)" );  
        for( i = 0; i < f.count; i++ )  
        Printf( "%s\n", f.file[i].filename );  
    int InputRadioButtonBox( const char title[], const char caption[], int defaultIndex, const char str1[], const char str2[], const char str3[]="", const char str4[]="", const char str5[]="", const char str6[]="", const char str7[]="", const char str8[]="", const char str9[]="", const char str10[]="", const char str11[]="", const char str12[]="", const char str13[]="", const char str14[]="", const char str15[]="" )  
    char[] InputSaveFileName( char title[], char filter[]="All files (*.*)", char filename[]="", char extension[]="" )  
    char[] InputString( const char title[], const char caption[], const char defaultValue[] )  
    wstring InputWString( const char title[], const char caption[], const wstring defaultValue )  
    int InsertFile( const char filename[], int64 position )  
    int IsEditorFocused()  
    int IsModified()  
    int IsNoUIMode()  
    int MessageBox( int mask, const char title[], const char format[] [, argument, ... ] )  
    void OutputPaneClear()  
    int OutputPaneSave( const char filename[] )  
    void OutputPaneCopy()  
    int Printf( const char format[] [, argument, ... ] )  
        Printf( "Num = %d, Float = %lf, Str = '%s'\n", 15, 5, "Test" );  
    void StatusMessage( const char format[] [, argument, ... ] )  
      
      
    int64 GetSelSize()  
    int64 GetSelStart()  
    void SetSelection( int64 start, int64 size )  
      
    //顏色  
    int GetForeColor()  
    int GetBackColor()  
    void SetBackColor( int color )   
    void SetColor( int forecolor, int backcolor )   
    void SetForeColor( int color )  
      
    int GetBytesPerLine()//獲取顯示列數(shù)  
      
    //時間  
    string GetCurrentTime( char format[] = "hh:mm:ss" )  
    string GetCurrentDate( char format[] = "MM/dd/yyyy" )  
    string GetCurrentDateTime( char format[] = "MM/dd/yyyy hh:mm:ss" )  
      
    void DisableUndo()//禁止undo  
    void EnableUndo()//允許undo  
      
    //設(shè)置顯示值  
    void DisplayFormatBinary()   
    void DisplayFormatDecimal()   
    void DisplayFormatHex()   
    void DisplayFormatOctal()  
      
    int Exec( const char program[], const char arguments[], int wait=false ) int Exec( const char program[], const char arguments[], int wait, int &errorCode )  
    void Exit( int errorcode )  
    void Warning( const char format[] [, argument, ... ] )  
    void Terminate( int force=true )  
    char[] GetArg( int index ) wchar_t[] GetArgW( int index )//獲取傳遞給腳本的命令  
    char[] GetEnv( const char str[] )//獲取環(huán)境變量  
    int SetEnv( const char str[], const char value[] )  
    int GetNumArgs()  
      
    void ExpandAll()//展開節(jié)點  
    void ExportCSV( const char filename[] )//導(dǎo)出  
    void ExportXML( const char filename[] )//導(dǎo)出  
      
    int64 GetCursorPos()//獲取當(dāng)前指針  
    void SetCursorPos( int64 pos )  
    void Sleep( int milliseconds )  

IO函數(shù)

 void BigEndian()//設(shè)置大小頭端  
int IsBigEndian()  
int IsLittleEndian()  
void LittleEndian()  
  
double ConvertBytesToDouble( uchar byteArray[] ) //數(shù)據(jù)轉(zhuǎn)換  
float ConvertBytesToFloat( uchar byteArray[] )   
hfloat ConvertBytesToHFloat( uchar byteArray[] )  
int ConvertDataToBytes( data_type value, uchar byteArray[] )  
void DeleteBytes( int64 start, int64 size )//刪除數(shù)據(jù)  
void InsertBytes( int64 start, int64 size, uchar value=0 )//插入數(shù)據(jù)  
void OverwriteBytes( int64 start, int64 size, uchar value=0 )  
  
char ReadByte( int64 pos=FTell() ) //讀取數(shù)據(jù)  
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() )  
void ReadBytes( uchar buffer[], int64 pos, int n )  
char[] ReadString( int64 pos, int maxLen=-1 )  
int ReadStringLength( int64 pos, int maxLen=-1 )  
wstring ReadWString( int64 pos, int maxLen=-1 )  
int ReadWStringLength( int64 pos, int maxLen=-1 )  
wstring ReadWLine( int64 pos, int maxLen=-1 )  
char[] ReadLine( int64 pos, int maxLen=-1, int includeLinefeeds=true )  
  
void WriteByte( int64 pos, char value ) //寫入數(shù)據(jù)  
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 )  
void WriteBytes( const uchar buffer[], int64 pos, int n )  
void WriteString( int64 pos, const char value[] )  
void WriteWString( int64 pos, const wstring value )  
  
int DirectoryExists( string dir )  
int MakeDir( string dir )  
int FEof()  
int64 FileSize()  
TFileList FindFiles( string dir, string filter )  
    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[], ... )  
int FSeek( int64 pos )  
int FSkip( int64 offset )  
int64 FTell()  
  
int64 TextAddressToLine( int64 address )  
int TextAddressToColumn( int64 address )  
int64 TextColumnToAddress( int64 line, int column )  
int64 TextGetNumLines()  
int TextGetLineSize( int64 line, int includeLinefeeds=true )  
int64 TextLineToAddress( int64 line )  
int TextReadLine( char buffer[], int64 line, int maxsize, int includeLinefeeds=true )  
int TextReadLineW( wchar_t buffer[], int64 line, int maxsize, int includeLinefeeds=true )  
void TextWriteLineW( const wchar_t buffer[], int64 line, int includeLinefeeds=true )  
void TextWriteLine( const char buffer[], int64 line, int includeLinefeeds=true ) 

字符串函數(shù)

 //類型轉(zhuǎn)換  
double Atof( const char s[] )  
int Atoi( const char s[] )  
int64 BinaryStrToInt( const char s[] )  
    return BinaryStrToInt( "01001101" );  
char[] ConvertString( const char src[], int srcCharSet, int destCharSet )  
    CHARSET_ASCII CHARSET_ANSI CHARSET_OEM CHARSET_EBCDIC CHARSET_UNICODE CHARSET_MAC CHARSET_ARABIC CHARSET_BALTIC CHARSET_CHINESE_S CHARSET_CHINESE_T CHARSET_CYRILLIC CHARSET_EASTEUROPE CHARSET_GREEK CHARSET_HEBREW CHARSET_JAPANESE CHARSET_KOREAN_J CHARSET_KOREAN_W CHARSET_THAI CHARSET_TURKISH CHARSET_VIETNAMESE CHARSET_UTF8  
string DosDateToString( DOSDATE d, char format[] = "MM/dd/yyyy" )  
string DosTimeToString( DOSTIME t, char format[] = "hh:mm:ss" )  
string EnumToString( enum e )  
string FileTimeToString( FILETIME ft, char format[] = "MM/dd/yyyy hh:mm:ss" )  
    int hour, minute, second, day, month, year;  
    string s = FileTimeToString( ft );  
    SScanf( s, "%02d/%02d/%04d %02d:%02d:%02d",  
    month, day, year, hour, minute, second );  
    year++;  
    SPrintf( s, "%02d/%02d/%04d %02d:%02d:%02d",  
    month, day, year, hour, minute, second );  
int StringToDosDate( string s, DOSDATE &d, char format[] = "MM/dd/yyyy" )  
int StringToDosTime( string s, DOSTIME &t, char format[] = "hh:mm:ss" )  
int StringToFileTime( string s, FILETIME &ft, char format[] = "MM/dd/yyyy hh:mm:ss" )  
int StringToOleTime( string s, OLETIME &ot, char format[] = "MM/dd/yyyy hh:mm:ss" )  
int StringToTimeT( string s, time_t &t, char format[] = "MM/dd/yyyy hh:mm:ss" )  
char[] StringToUTF8( const char src[], int srcCharSet=CHARSET_ANSI )  
wstring StringToWString( const char str[], int srcCharSet=CHARSET_ANSI )  
  
//內(nèi)存操作  
int Memcmp( const uchar s1[], const uchar s2[], int n )  
void Memcpy( uchar dest[], const uchar src[], int n, int destOffset=0, int srcOffset=0 )  
void Memset( uchar s[], int c, int n )  
string OleTimeToString( OLETIME ot, char format[] = "MM/dd/yyyy hh:mm:ss" )  
int RegExMatch( string str, string regex ); //正則匹配  
int RegExMatchW( wstring str, wstring regex );  
int RegExSearch( string str, string regex, int &matchSize, int startPos=0 );   
int RegExSearchW( wstring str, wstring regex, int &matchSize, int startPos=0 );  
    if( RegExMatch( "test@test.ca",  
    "\\b[A-Za-z0-9.%_+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,4}\\b" )  
    == false )  
    {  
    Warning( "Invalid email address" );  
    return -1;  
    }  
    int result, size;  
    result = RegExSearch(  
    "12:03:23 AM - 192.168.0.10 : www.sweetscape.com/",  
    "\\d{1,3}\\.\\d{1,3}.\\d{1,3}.\\d{1,3}", size );  
    Printf( "Match at pos %d of size %d\n", result, size );  
void Strcat( char dest[], const char src[] )  
int Strchr( const char s[], char c )  
int Strcmp( const char s1[], const char s2[] )   
void Strcpy( char dest[], const char src[] )  
char[] StrDel( const char str[], int start, int count )   
int Stricmp( const char s1[], const char s2[] )  
int Strlen( const char s[] )  
int Strncmp( const char s1[], const char s2[], int n )  
void Strncpy( char dest[], const char src[], int n )   
int Strnicmp( const char s1[], const char s2[], int n )  
int Strstr( const char s1[], const char s2[] )  
char[] SubStr( const char str[], int start, int count=-1 )  
string TimeTToString( time_t t, char format[] = "MM/dd/yyyy hh:mm:ss" )  
char ToLower( char c ) wchar_t ToLowerW( wchar_t c )  
char ToUpper( char c ) wchar_t ToUpperW( wchar_t c )  
void WMemcmp( const wchar_t s1[], const wchar_t s2[], int n )  
void WMemcpy( wchar_t dest[], const wchar_t src[], int n, int destOffset=0, int srcOffset=0 )  
void WMemset( wchar_t s[], int c, int n )  
void WStrcat( wchar_t dest[], const wchar_t src[] )  
int WStrchr( const wchar_t s[], wchar_t c )  
int WStrcmp( const wchar_t s1[], const wchar_t s2[] )  
void WStrcpy( wchar_t dest[], const wchar_t src[] )  
wchar_t[] WStrDel( const whar_t str[], int start, int count )   
int WStricmp( const wchar_t s1[], const wchar_t s2[] )  
char[] WStringToString( const wchar_t str[], int destCharSet=CHARSET_ANSI )  
char[] WStringToUTF8( const wchar_t str[] )  
int WStrlen( const wchar_t s[] )  
int WStrncmp( const wchar_t s1[], const wchar_t s2[], int n )  
void WStrncpy( wchar_t dest[], const wchar_t src[], int n )  
int WStrnicmp( const wchar_t s1[], const wchar_t s2[], int n )   
int WStrstr( const wchar_t s1[], const wchar_t s2[] )  
wchar_t[] WSubStr( const wchar_t str[], int start, int count=-1 )  
  
char[] FileNameGetBase( const char path[], int includeExtension=true ) //獲取文件名  
wchar_t[] FileNameGetBaseW( const wchar_t path[], int includeExtension=true )  
char[] FileNameGetExtension( const char path[] )   
wchar_t[] FileNameGetExtensionW( const wchar_t path[] )  
char[] FileNameGetPath( const char path[], int includeSlash=true )   
wchar_t[] FileNameGetPathW( const wchar_t path[], int includeSlash=true )  
char[] FileNameSetExtension( const char path[], const char extension[] )   
wchar_t[] FileNameSetExtensionW( const wchar_t path[], const wchar_t extension[] )   
  
//格式化字符串  
int SPrintf( char buffer[], const char format[] [, argument, ... ] )  
int SScanf( char str[], char format[], ... ) 

數(shù)學(xué)函數(shù)

    double Abs( double x )  
    double Ceil( double x )  
    double Cos( double a )  
    double Exp( double x )  
    double Floor( double x)  
    double Log( double x )  
    double Max( double a, double b )  
    double Min( double a, double b)  
    double Pow( double x, double y)  
    int Random( int maximum )  
    double Sin( double a )  
    double Sqrt( double x )  
    data_type SwapBytes( data_type x )  
    double Tan( double a )  

工具函數(shù)

    //計算校驗和  
    int64 Checksum( int algorithm, int64 start=0, int64 size=0, int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
        CHECKSUM_BYTE CHECKSUM_SHORT_LE CHECKSUM_SHORT_BE CHECKSUM_INT_LE CHECKSUM_INT_BE CHECKSUM_INT64_LE CHECKSUM_INT64_BE CHECKSUM_SUM8 CHECKSUM_SUM16 CHECKSUM_SUM32 CHECKSUM_SUM64 CHECKSUM_CRC16 CHECKSUM_CRCCCITT CHECKSUM_CRC32 CHECKSUM_ADLER32  
    int ChecksumAlgArrayStr( int algorithm, char result[], uchar *buffer, int64 size, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
    int ChecksumAlgArrayBytes( int algorithm, uchar result[], uchar *buffer, int64 size, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
    int ChecksumAlgStr( int algorithm, char result[], int64 start=0, int64 size=0, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
    int ChecksumAlgBytes( int algorithm, uchar result[], int64 start=0, int64 size=0, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
      
    //查找比較  
    TCompareResults Compare( int type, int fileNumA, int fileNumB, int64 startA=0, int64 sizeA=0, int64 startB=0, int64 sizeB=0, int matchcase=true, int64 maxlookahead=10000, int64 minmatchlength=8, int64 quickmatch=512 )  
        int i, f1, f2;  
        FileOpen( "C:\\temp\\test1" );  
        f1 = GetFileNum();  
        FileOpen( "C:\\temp\\test2" );  
        f2 = GetFileNum();  
        TCompareResults r = Compare( COMPARE_SYNCHRONIZE, f1, f2 );  
        for( i = 0; i < r.count; i++ )  
        {  
        Printf( "%d %Ld %Ld %Ld %Ld\n",  
        r.record[i].type,  
        r.record[i].startA,  
        r.record[i].sizeA,  
        r.record[i].startB,  
        r.record[i].sizeB );  
        }  
    TFindResults FindAll( <datatype> data, int matchcase=true, int wholeword=false, int method=0, double tolerance=0.0, int dir=1, int64 start=0, int64 size=0, int wildcardMatchLength=24 )  
        int i;  
        TFindResults r = FindAll( "Test" );  
        Printf( "%d\n", r.count );  
        for( i = 0; i < r.count; i++ )  
        Printf( "%Ld %Ld\n", r.start[i], r.size[i] );  
    int64 FindFirst( <datatype> data, int matchcase=true, int wholeword=false, int method=0, double tolerance=0.0, int dir=1, int64 start=0, int64 size=0, int wildcardMatchLength=24 )  
    TFindInFilesResults FindInFiles( <datatype> data, char dir[], char mask[], int subdirs=true, int openfiles=false, int matchcase=true, int wholeword=false, int method=0, double tolerance=0.0, int wildcardMatchLength=24 )  
        int i, j;  
        TFindInFilesResults r = FindInFiles( "PK",  
        "C:\\temp", "*.zip" );  
        Printf( "%d\n", r.count );  
        for( i = 0; i < r.count; i++ )  
        {  
        Printf( " %s\n", r.file[i].filename );  
        Printf( " %d\n", r.file[i].count );  
        for( j = 0; j < r.file[i].count; j++ )  
        Printf( " %Ld %Ld\n",  
        r.file[i].start[j],  
        r.file[i].size[j] );  
        }  
    int64 FindNext( int dir=1 )  
    TFindStringsResults FindStrings( int minStringLength, int type, int matchingCharTypes, wstring customChars="", int64 start=0, int64 size=0, int requireNull=false )  
        TFindStringsResults r = FindStrings( 5, FINDSTRING_ASCII,  
        FINDSTRING_LETTERS | FINDSTRING_CUSTOM, "$&" );  
        Printf( "%d\n", r.count );  
        for( i = 0; i < r.count; i++ )  
        Printf( "%Ld %Ld %d\n", r.start[i], r.size[i], r.type[i] );  
          
    //類型轉(zhuǎn)換  
    char ConvertASCIIToEBCDIC( char ascii )  
    void ConvertASCIIToUNICODE( int len, const char ascii[], ubyte unicode[], int bigendian=false )  
    void ConvertASCIIToUNICODEW( int len, const char ascii[], ushort unicode[] )   
    char ConvertEBCDICToASCII( char ebcdic )  
    void ConvertUNICODEToASCII( int len, const ubyte unicode[], char ascii[], int bigendian=false )  
    void ConvertUNICODEToASCIIW( int len, const ushort unicode[], char ascii[] )  
      
    int ExportFile( int type, char filename[], int64 start=0, int64 size=0, int64 startaddress=0,int bytesperrow=16, int wordaddresses=0 )  
    int ImportFile( int type, char filename[], int wordaddresses=false, int defaultByteValue=-1 )  
    int GetSectorSize()   
    int HexOperation( int operation, int64 start, int64 size, operand, step=0, int64 skip=0 )  
    int64 Histogram( int64 start, int64 size, int64 result[256] )  
    int IsDrive()  
    int IsLogicalDrive()  
    int IsPhysicalDrive()  
    int IsProcess()  
    int OpenLogicalDrive( char driveletter )  
    int OpenPhysicalDrive( int physicalID )  
    int OpenProcessById( int processID, int openwriteable=true )  
    int OpenProcessByName( char processname[], int openwriteable=true )  
    int ReplaceAll( <datatype> finddata, <datatype> replacedata, int matchcase=true, int wholeword=false, int method=0, double tolerance=0.0, int dir=1, int64 start=0, int64 size=0, int padwithzeros=false, int wildcardMatchLength=24 )  
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末谆甜,一起剝皮案震驚了整個濱河市垃僚,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌规辱,老刑警劉巖谆棺,帶你破解...
    沈念sama閱讀 216,324評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異罕袋,居然都是意外死亡改淑,警方通過查閱死者的電腦和手機(jī)碍岔,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,356評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來朵夏,“玉大人蔼啦,你說我怎么就攤上這事⊙霾” “怎么了捏肢?”我有些...
    開封第一講書人閱讀 162,328評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長饥侵。 經(jīng)常有香客問我鸵赫,道長,這世上最難降的妖魔是什么躏升? 我笑而不...
    開封第一講書人閱讀 58,147評論 1 292
  • 正文 為了忘掉前任奉瘤,我火速辦了婚禮,結(jié)果婚禮上煮甥,老公的妹妹穿的比我還像新娘盗温。我一直安慰自己,他們只是感情好成肘,可當(dāng)我...
    茶點故事閱讀 67,160評論 6 388
  • 文/花漫 我一把揭開白布卖局。 她就那樣靜靜地躺著,像睡著了一般双霍。 火紅的嫁衣襯著肌膚如雪砚偶。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,115評論 1 296
  • 那天洒闸,我揣著相機(jī)與錄音染坯,去河邊找鬼。 笑死丘逸,一個胖子當(dāng)著我的面吹牛单鹿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播深纲,決...
    沈念sama閱讀 40,025評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼仲锄,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了湃鹊?” 一聲冷哼從身側(cè)響起儒喊,我...
    開封第一講書人閱讀 38,867評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎币呵,沒想到半個月后怀愧,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,307評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,528評論 2 332
  • 正文 我和宋清朗相戀三年芯义,在試婚紗的時候發(fā)現(xiàn)自己被綠了肛搬。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,688評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡毕贼,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出蛤奢,到底是詐尸還是另有隱情鬼癣,我是刑警寧澤,帶...
    沈念sama閱讀 35,409評論 5 343
  • 正文 年R本政府宣布啤贩,位于F島的核電站待秃,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏痹屹。R本人自食惡果不足惜章郁,卻給世界環(huán)境...
    茶點故事閱讀 41,001評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望志衍。 院中可真熱鬧暖庄,春花似錦、人聲如沸楼肪。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,657評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽春叫。三九已至肩钠,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間暂殖,已是汗流浹背价匠。 一陣腳步聲響...
    開封第一講書人閱讀 32,811評論 1 268
  • 我被黑心中介騙來泰國打工程储, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留蜈缤,地道東北人。 一個月前我還...
    沈念sama閱讀 47,685評論 2 368
  • 正文 我出身青樓帜羊,卻偏偏與公主長得像晨横,于是被迫代替她去往敵國和親毙石。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,573評論 2 353