010editor脚本语法深入分析

转自:http://blog.csdn.net/lichao890427/article/details/51870347

010editor是一款十六进制编辑器,和winhex相比支持更灵活的脚本语法,可以对文件、内存、磁盘进行操作

常用的模板库(*.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可执行文件

   registrayhive.bt 解析注册表(Hive)文件

   bson.bt 解析二进制json

常用的脚本库(*.1sc)用于操作数据http://www.sweetscape.com/010editor/repository/scripts/

二进制:

    CountBlocks.1sc 查找指定数据块

    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 复制到剪贴板

    DumpStrings.1sc 查找所有ascii unicode字符串


脚本语言语法类似于c++,这种结构体不同之处在于:

       访问变量时,从文件读取并显示,赋值变量时,写入文件

       可以使用控制语句如if for while

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. struct FILE   
  2. {  
  3.     struct HEADER   
  4.     {  
  5.         char type[4];  
  6.         int version;  
  7.         int numRecords;  
  8.     } header;  
  9.     struct RECORD   
  10.     {  
  11.     int employeeId;  
  12.     char name[40];  
  13.     float salary;  
  14.     } record[ header.numRecords ];  
  15. } file;  

控制语句实例:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. int i;  
  2. for( i = 0; i < file.header.numRecords; i++ )  
  3.  file.record[i].salary *= 2.0;  

基本语法

表达式

变量

数据类型

控制语句

函数

关键字

预处理

语法限制


表达式

支持标准c的操作符:+ - * / ~ ^ & | % ++ -- ?: << >> ()

支持的比较操作符:< ? <= >= == != !

支持的赋值操作符:= += -= *= /= &= ^= %= |= <<= >>=

布尔运算符:&& || !

常数:     

    10进制 456

    16进制 0xff 25h 0EFh

    8进制 013

    2进制 0b011

    u后缀表示unsigned    L后缀表示8字节int64值   

    指数 1e10

    浮点数 2.0f 2.0


变量

定义脚本变量

int x;
float a = 3.5f;
unsigned int myVar1, myVar2;

常量

const int TAG_EOF = 0x3545;

内建常量:true false TRUE FALSE M_PI PI


数据类型

8字节 char byte CHAR BYTE uchar ubyte UCHAR UBYTE

16字节 short int16 SHORT INT16 ushort uint16 USHORT UINT16 WORD

32字节 int int32 long INT INT32 LONG uint uint32 ulong UINT UINT32 ULONG DWORD

64字节 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;

数组和字符串

int myArray[15];

int myArray[ FileSize() - myInt * 0x10 + (17 << 5) ];//大小可以是变量

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. char str[15] = "First";  
  2. string s = "Second";  
  3. string r1 = str + s;  
  4. string r2 = str;  
  5. r2 += s;  
  6. return (r1 == r2);  

宽字符

 

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. wchar_t str1[15] = L"How now";  
  2. wstring str2 = "brown cow";  
  3. wstring str3 = str1 + L' ' + str2 + L'?';  


可以通过WStringToString StringToWString转换


控制语句

if语句

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. if( x < 5 )  
  2. x = 0;  
  3. or  
  4. if( y > x )  
  5. max = y;  
  6. else  
  7. {  
  8. max = x;  
  9. y = 0;  
  10. }  

for语句

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. for( i = 0, x = 0; i < 15; i++ )  
  2. {  
  3. x += i;  
  4. }  

while语句

 

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. while( myVar < 15 )  
  2. {  
  3. x *= myVar;  
  4. myVar += 2;  
  5. }  
  6. or  
  7. do  
  8. {  
  9. x *= myVar;  
  10. myVar += 2;  
  11. }  
  12. while( myVar < 23 );  


switch语句

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. switch( <variable> )  
  2. {  
  3. case <expression>: <statement>; [break;]  
  4. .  
  5. .  
  6. .  
  7. default : <statement>;  
  8. }  
  9. switch( value )  
  10. {  
  11. case 2 : result = 1; break;  
  12. case 4 : result = 2; break;  
  13. case 8 : result = 3; break;  
  14. case 16 : result = 4; break;  
  15. default : result = -1;  
  16. }  


循环控制:break continue return


函数 

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. string str = "Apple";  
  2. return Strlen( str );  
  3.   
  4. Printf( "string='%s' length='%d'\n", str, Strlen( str ) );  
  5.   
  6. void OutputInt( int d )  
  7. {  
  8. Printf( "%d\n", d );  
  9. }  
  10. OutputInt( 5 );  
  11.   
  12. char[] GetExtension( char filename[], int &extLength )  
  13. {  
  14. int pos = Strchr( filename, '.' );  
  15. if( pos == -1 )  
  16. {  
  17. extLength = 0;  
  18. return "";  
  19. }  
  20. else  
  21. {  
  22. extLength = Strlen( filename ) - pos - 1;  
  23. return SubStr( filename, pos + 1 );  
  24. }  
  25. }  

参数可以通过值或引用传递,010editor脚本不支持指针,但是可以用[]表示数组

程序中不需要main函数,代码从第一行开始执行


关键字

sizeof      

startof  用于计算变量起始地址

         SetCursorPos( startof( lines[0] ) );

exists  检查某变量是否声明

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. int i;  
  2. string s;  
  3. while( exists( file[i] ) )  
  4. {  
  5. s = file[i].frFileName;  
  6. Printf( "%s\n", s );  
  7. i++;  
  8. }  

function_exists 检查函数是否定义

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. if( function_exists(CopyStringToClipboard) )  
  2. {  
  3. ...  
  4. }  

this 引用当前结构体 

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. void PrintHeader( struct HEADER &h )  
  2. {  
  3. Printf( "ID1 = %d\n", h.ID1 );  
  4. Printf( "ID2 = %d\n", h.ID2 );  
  5. }  
  6. struct HEADER  
  7. {  
  8. int ID1;  
  9. int ID2;  
  10. PrintHeader( this );  
  11. } h1;  

parentof 访问包含变量的结构和union

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. void PrintHeader( struct HEADER &h )  
  2. {  
  3. Printf( "ID1 = %d\n", h.ID1 );  
  4. Printf( "ID2 = %d\n", h.ID2 );  
  5. }  
  6. struct HEADER  
  7. {  
  8. int ID1;  
  9. int ID2;  
  10. struct SUBITEM  
  11. {  
  12. int data1;  
  13. int data2;  
  14. PrintHeader( parentof(this) );  
  15. } item1;  
  16. PrintHeader( parentof(item1) );  
  17. } h1;  

预处理

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)

内建常量

_010EDITOR  010editor运行后定义

_010_WIN 运行在windows上定义

_010_MAC

_010_LINUX

_010_64BIT

条件编译

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #ifdef | #ifndef <constant_name>  
  2. (...)  
  3. [ #else ]  
  4. (...)  
  5. #endif  
  6. #ifndef CONSTANTS_H  
  7. #define CONSTANTS_H  

警告和错误

 

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #ifdef NUMBITS  
  2. value = value + NUMBITS;  
  3. #else  
  4. #warning "NUMBITS not defined!"  
  5. #endif  
  6.   
  7. #ifndef CURRENT_OS  
  8. #error "CURRENT_OS must be defined. Compilation stopped."  
  9. #endif  

include

#include "Vector.bt"


脚本限制

禁止使用指针,可以使用引用传参数

禁止使用#if预处理

禁止使用多维数组

禁止使用goto


 模板基础

声明模板变量

数据类型

结构体联合体

array duplicate optimizing

位域

表达式

控制语句

函数

关键字

预处理

include

定制变量

On-Demand结构体

模板限制


声明模板变量

特殊属性

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. < format=hex|decimal|octal|binary,  
  2. fgcolor=<color>,  
  3. bgcolor=<color>,  
  4. comment="<string>"|<function_name>,  
  5. name="<string>"|<function_name>,  
  6. open=true|false|suppress,  
  7. hidden=true|false,  
  8. read=<function_name>,  
  9. write=<function_name>  
  10. size=<number>|<function_name> >  

format 设置

int crc <format=hex>;
int flags <format=binary>;

color设置

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. int id <fgcolor=cBlack, bgcolor=0x0000FF>;  
  2.   
  3. SetForeColor( cRed );  
  4. int first; // will be colored red  
  5. int second; // will be colored red  
  6. SetForeColor( cNone );  
  7. int third; // will not be colored  

大小头端设置

注释设置

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. int machineStatus <comment="This should be greater than 15.">;  
  2.   
  3. int machineStatus <comment=MachineStatusComment>;  
  4. string MachineStatusComment( int status )  
  5. {  
  6. if( status <= 15 )  
  7. return "*** Invalid machine status";  
  8.   
  9.   
  10. else  
  11. return "Valid machine status";  
  12. }  

显示名设置

byte _si8 <name="Signed Byte">;

顺序:在声明模板变量后,当前文件指针后移,通过FTell获取当前位置,通过FSeek FSkip移动指针  通过ReadByte ReadShort ReadInt任意读取而不移动指针

局部变量

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. local int i, total = 0;  
  2. int recordCounts[5];  
  3. for( i = 0; i < 5; i++ )  
  4. total += recordCounts[i];  
  5. double records[ total ];  

打开状态设置

<open=true/false>展开/收敛节点

 

字符串

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. char str[];  
  2. string str;  
  3. wchar_t str[];  
  4. wstring str;  

隐藏设置

<hidden=true/false> 


结构体联合体

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. struct myStruct {  
  2. int a;  
  3. int b;  
  4. int c;  
  5. };  
  6.   
  7. struct myStruct {  
  8. int a;  
  9. int b;  
  10. int c;  
  11. } s1, s2;  
  12.   
  13. struct myIfStruct {  
  14. int a;  
  15. if( a > 5 )  
  16. int b;  
  17. else  
  18. int c;  
  19. } s;  
  20.   
  21. struct {  
  22. int width;  
  23. struct COLOR {  
  24. uchar r, g, b;  
  25. } colors[width];  
  26. } line1;  
  27.   
  28. typedef struct {  
  29. ushort id;  
  30. int size;  
  31. }  
  32. myData;  
  33.   
  34. union myUnion {  
  35. ushort s;  
  36. double d;  
  37. int i;  
  38. } u;  
  39.   
  40. //带参数结构体  
  41. struct VarSizeStruct (int arraySize)  
  42. {  
  43. int id;  
  44. int array[arraySize];  
  45. };  
  46.   
  47. typedef struct (int arraySize)  
  48. {  
  49. int id;  
  50. int array[arraySize];  
  51. } VarSizeStruct;  
  52. VarSizeStruct s1(5);  
  53. VarSizeStruct s2(7);  

array, duplicate, optimizing

010editor允许重复模板变量

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默认认为结构体大小一致,这样生成大量结构体数组的速度较快,若实际结构体大小不一致则可能产生问题,此时用optimize=false,如下例:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. typedef struct {  
  2. int id;  
  3. int length;  
  4. uchar data[ length ];  
  5. } RECORD;  
  6. 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;


用户变量

指定如何显示和修改数据

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. typedef ushort FIXEDPT <read=FIXEDPTRead, write=FIXEDPTWrite>;  
  2. string FIXEDPTRead( FIXEDPT f )  
  3. {  
  4. string s;  
  5. SPrintf( s, "%lg", f / 256.0 );  
  6. return s;  
  7. }  
  8. void FIXEDPTWrite( FIXEDPT &f, string s )  
  9. {  
  10. f = (FIXEDPT)( Atof( s ) * 256 );  
  11. }  
  12.   
  13. typedef float VEC3F[3] <read=Vec3FRead, write=Vec3FWrite>;  
  14. string Vec3FRead( VEC3F v )  
  15. {  
  16. string s;  
  17. SPrintf( s, "(%f %f %f)", v[0], v[1], v[2] );  
  18. return s;  
  19. }  
  20. void Vec3FWrite( VEC3F &v, string s )  
  21. {  
  22. SScanf( s, "(%f %f %f)", v[0], v[1], v[2] );  
  23. }  

On-Demand结构体

通过指定size解决大量变量消耗内存问题

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. typedef struct  
  2. {  
  3. int header;  
  4. int value1;  
  5. int value2;  
  6. } MyStruct <size=12>;  
  7.   
  8. typedef struct {  
  9. <...>  
  10. uint frCompressedSize;  
  11. uint frUncompressedSize;  
  12. ushort frFileNameLength;  
  13. ushort frExtraFieldLength;  
  14. if( frFileNameLength > 0 )  
  15. char frFileName[ frFileNameLength ];  
  16. if( frExtraFieldLength > 0 )  
  17. uchar frExtraField[ frExtraFieldLength ];  
  18. if( frCompressedSize > 0 )  
  19. uchar frData[ frCompressedSize ];  
  20. } ZIPFILERECORD <size=SizeZIPFILERECORD>;  
  21. int SizeZIPFILERECORD( ZIPFILERECORD &r )  
  22. {  
  23. return 30 + // base size of the struct  
  24. ReadUInt(startof(r)+18) + // size of the compressed data  
  25. ReadUShort(startof(r)+26) + // size of the file name  
  26. ReadUShort(startof(r)+28); // size of the extra field  
  27. }  


模板限制

禁止多维数组

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. typedef struct  
  2.  {  
  3.  float row[4];  
  4.  }  
  5.  MATRIX[4];  
  6.   
  7.  MATRIX m;  

接口函数

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //书签  
  2. void AddBookmark( int64 pos, string name, string typenameint arraySize=-1, int forecolor=cNone, int backcolor=0xffffc4, int moveWithCursor=false )  
  3. AddBookmark( GetCursorPos(), "endmarker","ZIPENDLOCATOR", -1, cRed );  
  4. int GetBookmarkArraySize( int index )  
  5. int GetBookmarkBackColor( int index )  
  6. int GetBookmarkForeColor( int index )  
  7. int GetBookmarkMoveWithCursor( int index )  
  8. string GetBookmarkName( int index )  
  9. int64 GetBookmarkPos( int index )  
  10. string GetBookmarkType( int index )  
  11. int GetNumBookmarks()  
  12. void RemoveBookmark( int index )  
  13. //断言  
  14. void Assert( int value, const char msg[] = "" )  
  15. Assert( numRecords > 10,"numRecords should be more than 10." );  
  16. //剪贴板  
  17. void ClearClipboard()  
  18. void CopyBytesToClipboard( uchar buffer[], int size, int charset=CHARSET_ANSI, int bigendian=false )  
  19. void CopyStringToClipboard( const char str[], int charset=CHARSET_ANSI )  
  20. void CopyToClipboard()  
  21. void CutToClipboard()  
  22. int GetClipboardBytes( uchar buffer[], int maxBytes )  
  23. int GetClipboardIndex()  
  24. string GetClipboardString()  
  25. void PasteFromClipboard()  
  26. int SetClipboardIndex( int index )  
  27.   
  28. 文件  
  29. int DeleteFile( char filename[] )    //删除文件,文件不能在编辑器中打开  
  30. void FileClose()//关闭当前文件  
  31. int FileCount()//获取editor打开的文件数  
  32. int FileExists( const char filename[] )//检测文件存在  
  33. int FileNew( char interface[]=""int makeActive=true )//创建爱你文件  
  34. int FileOpen( const char filename[], int runTemplate=falsechar interface[]=""int openDuplicate=false )//打开文件  
  35. int FileSave()   
  36. int FileSave( const char filename[] )   
  37. int FileSave( const wchar_t filename[] )   
  38. int FileSaveRange( const char filename[], int64 start, int64 size )   
  39. int FileSaveRange( const wchar_t filename[], int64 start, int64 size )//保存文件  
  40. void FileSelect( int index )//选择读写的文件  
  41. int FindOpenFile( const char path[] )   
  42. int FindOpenFileW( const wchar_t path[] )//查找并打开文件  
  43. int GetFileAttributesUnix()  
  44. int GetFileAttributesWin()  
  45. int SetFileAttributesUnix( int attributes )  
  46. int SetFileAttributesWin( int attributes )  
  47. int GetFileCharSet()  
  48. char[] GetFileInterface()  
  49. int SetFileInterface( const char name[] )  
  50. char[] GetFileName()  
  51. wchar_t[] GetFileNameW()  
  52. int GetFileNum()  
  53. int GetReadOnly()  
  54. int SetReadOnly( int readonly )  
  55. string GetTempDirectory()  
  56. char[] GetTempFileName()  
  57. char[] GetTemplateName()   
  58. wchar_t[] GetTemplateNameW()  
  59. char[] GetTemplateFileName()   
  60. wchar_t[] GetTemplateFileNameW()  
  61. char[] GetScriptName()   
  62. wchar_t[] GetScriptNameW()  
  63. char[] GetScriptFileName()   
  64. wchar_t[] GetScriptFileNameW()  
  65. char[] GetWorkingDirectory()   
  66. wchar_t[] GetWorkingDirectoryW()  
  67. int RenameFile( const char originalname[], const char newname[] )  
  68. void RequiresFile()  
  69. void RequiresVersion( int majorVer, int minorVer=0, int revision=0 )  
  70. void RunTemplate( const char filename[]=""int clearOutput=false )  
  71. int SetWorkingDirectory( const char dir[] )   
  72. int SetWorkingDirectoryW( const wchar_t dir[] )  
  73.   
  74. //输入  
  75. char[] InputDirectory( const char title[], const char defaultDir[]="" )  
  76. double InputFloat( const char title[], const char caption[], const char defaultValue[] )  
  77. int InputNumber( const char title[], const char caption[], const char defaultValue[] )  
  78. char[] InputOpenFileName( char title[], char filter[]="All files (*.*)"char filename[]="" )  
  79. TOpenFileNames InputOpenFileNames( char title[], char filter[]="All files (*.*)"char filename[]="" )  
  80.     int i;  
  81.     TOpenFileNames f = InputOpenFileNames(  
  82.     "Open File Test",  
  83.     "C Files (*.c *.cpp)|All Files (*.*)" );  
  84.     for( i = 0; i < f.count; i++ )  
  85.     Printf( "%s\n", f.file[i].filename );  
  86. 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[]="" )  
  87. char[] InputSaveFileName( char title[], char filter[]="All files (*.*)"char filename[]=""char extension[]="" )  
  88. char[] InputString( const char title[], const char caption[], const char defaultValue[] )  
  89. wstring InputWString( const char title[], const char caption[], const wstring defaultValue )  
  90. int InsertFile( const char filename[], int64 position )  
  91. int IsEditorFocused()  
  92. int IsModified()  
  93. int IsNoUIMode()  
  94. int MessageBox( int mask, const char title[], const char format[] [, argument, ... ] )  
  95. void OutputPaneClear()  
  96. int OutputPaneSave( const char filename[] )  
  97. void OutputPaneCopy()  
  98. int Printf( const char format[] [, argument, ... ] )  
  99.     Printf( "Num = %d, Float = %lf, Str = '%s'\n", 15, 5, "Test" );  
  100. void StatusMessage( const char format[] [, argument, ... ] )  
  101.   
  102.   
  103. int64 GetSelSize()  
  104. int64 GetSelStart()  
  105. void SetSelection( int64 start, int64 size )  
  106.   
  107. //颜色  
  108. int GetForeColor()  
  109. int GetBackColor()  
  110. void SetBackColor( int color )   
  111. void SetColor( int forecolor, int backcolor )   
  112. void SetForeColor( int color )  
  113.   
  114. int GetBytesPerLine()//获取显示列数  
  115.   
  116. //时间  
  117. string GetCurrentTime( char format[] = "hh:mm:ss" )  
  118. string GetCurrentDate( char format[] = "MM/dd/yyyy" )  
  119. string GetCurrentDateTime( char format[] = "MM/dd/yyyy hh:mm:ss" )  
  120.   
  121. void DisableUndo()//禁止undo  
  122. void EnableUndo()//允许undo  
  123.   
  124. //设置显示值  
  125. void DisplayFormatBinary()   
  126. void DisplayFormatDecimal()   
  127. void DisplayFormatHex()   
  128. void DisplayFormatOctal()  
  129.   
  130. int Exec( const char program[], const char arguments[], int wait=false ) int Exec( const char program[], const char arguments[], int wait, int &errorCode )  
  131. void Exit( int errorcode )  
  132. void Warning( const char format[] [, argument, ... ] )  
  133. void Terminate( int force=true )  
  134. char[] GetArg( int index ) wchar_t[] GetArgW( int index )//获取传递给脚本的命令  
  135. char[] GetEnv( const char str[] )//获取环境变量  
  136. int SetEnv( const char str[], const char value[] )  
  137. int GetNumArgs()  
  138.   
  139. void ExpandAll()//展开节点  
  140. void ExportCSV( const char filename[] )//导出  
  141. void ExportXML( const char filename[] )//导出  
  142.   
  143. int64 GetCursorPos()//获取当前指针  
  144. void SetCursorPos( int64 pos )  
  145. void Sleep( int milliseconds )  


I/O函数

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. void BigEndian()//设置大小头端  
  2. int IsBigEndian()  
  3. int IsLittleEndian()  
  4. void LittleEndian()  
  5.   
  6. double ConvertBytesToDouble( uchar byteArray[] ) //数据转换  
  7. float ConvertBytesToFloat( uchar byteArray[] )   
  8. hfloat ConvertBytesToHFloat( uchar byteArray[] )  
  9. int ConvertDataToBytes( data_type value, uchar byteArray[] )  
  10. void DeleteBytes( int64 start, int64 size )//删除数据  
  11. void InsertBytes( int64 start, int64 size, uchar value=0 )//插入数据  
  12. void OverwriteBytes( int64 start, int64 size, uchar value=0 )  
  13.   
  14. char ReadByte( int64 pos=FTell() ) //读取数据  
  15. double ReadDouble( int64 pos=FTell() )   
  16. float ReadFloat( int64 pos=FTell() )   
  17. hfloat ReadHFloat( int64 pos=FTell() )   
  18. int ReadInt( int64 pos=FTell() )   
  19. int64 ReadInt64( int64 pos=FTell() )   
  20. int64 ReadQuad( int64 pos=FTell() )   
  21. short ReadShort( int64 pos=FTell() )  
  22. uchar ReadUByte( int64 pos=FTell() )   
  23. uint ReadUInt( int64 pos=FTell() )   
  24. uint64 ReadUInt64( int64 pos=FTell() )   
  25. uint64 ReadUQuad( int64 pos=FTell() )   
  26. ushort ReadUShort( int64 pos=FTell() )  
  27. void ReadBytes( uchar buffer[], int64 pos, int n )  
  28. char[] ReadString( int64 pos, int maxLen=-1 )  
  29. int ReadStringLength( int64 pos, int maxLen=-1 )  
  30. wstring ReadWString( int64 pos, int maxLen=-1 )  
  31. int ReadWStringLength( int64 pos, int maxLen=-1 )  
  32. wstring ReadWLine( int64 pos, int maxLen=-1 )  
  33. char[] ReadLine( int64 pos, int maxLen=-1, int includeLinefeeds=true )  
  34.   
  35. void WriteByte( int64 pos, char value ) //写入数据  
  36. void WriteDouble( int64 pos, double value )   
  37. void WriteFloat( int64 pos, float value )   
  38. void WriteHFloat( int64 pos, float value )   
  39. void WriteInt( int64 pos, int value )   
  40. void WriteInt64( int64 pos, int64 value )   
  41. void WriteQuad( int64 pos, int64 value )   
  42. void WriteShort( int64 pos, short value )   
  43. void WriteUByte( int64 pos, uchar value )   
  44. void WriteUInt( int64 pos, uint value )   
  45. void WriteUInt64( int64 pos, uint64 value )   
  46. void WriteUQuad( int64 pos, uint64 value )   
  47. void WriteUShort( int64 pos, ushort value )  
  48. void WriteBytes( const uchar buffer[], int64 pos, int n )  
  49. void WriteString( int64 pos, const char value[] )  
  50. void WriteWString( int64 pos, const wstring value )  
  51.   
  52. int DirectoryExists( string dir )  
  53. int MakeDir( string dir )  
  54. int FEof()  
  55. int64 FileSize()  
  56. TFileList FindFiles( string dir, string filter )  
  57.     TFileList fl = FindFiles( "C:\\temp\\", "*.zip" );  
  58.     int i;  
  59.     Printf( "Num files = %d\n", fl.filecount );  
  60.     for( i = 0; i < fl.filecount; i++ )  
  61.     {  
  62.     Printf( " %s\n", fl.file[i].filename );  
  63.     }  
  64.     Printf( "\n" );  
  65.     Printf( "Num dirs = %d\n", fl.dircount );  
  66.     for( i = 0; i < fl.dircount; i++ )  
  67.     {  
  68.     Printf( " %s\n", fl.dir[i].dirname );  
  69.     }  
  70. int FPrintf( int fileNum, char format[], ... )  
  71. int FSeek( int64 pos )  
  72. int FSkip( int64 offset )  
  73. int64 FTell()  
  74.   
  75. int64 TextAddressToLine( int64 address )  
  76. int TextAddressToColumn( int64 address )  
  77. int64 TextColumnToAddress( int64 line, int column )  
  78. int64 TextGetNumLines()  
  79. int TextGetLineSize( int64 line, int includeLinefeeds=true )  
  80. int64 TextLineToAddress( int64 line )  
  81. int TextReadLine( char buffer[], int64 line, int maxsize, int includeLinefeeds=true )  
  82. int TextReadLineW( wchar_t buffer[], int64 line, int maxsize, int includeLinefeeds=true )  
  83. void TextWriteLineW( const wchar_t buffer[], int64 line, int includeLinefeeds=true )  
  84. void TextWriteLine( const char buffer[], int64 line, int includeLinefeeds=true )  

字符串函数

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //类型转换  
  2. double Atof( const char s[] )  
  3. int Atoi( const char s[] )  
  4. int64 BinaryStrToInt( const char s[] )  
  5.     return BinaryStrToInt( "01001101" );  
  6. char[] ConvertString( const char src[], int srcCharSet, int destCharSet )  
  7.     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  
  8. string DosDateToString( DOSDATE d, char format[] = "MM/dd/yyyy" )  
  9. string DosTimeToString( DOSTIME t, char format[] = "hh:mm:ss" )  
  10. string EnumToString( enum e )  
  11. string FileTimeToString( FILETIME ft, char format[] = "MM/dd/yyyy hh:mm:ss" )  
  12.     int hour, minute, second, day, month, year;  
  13.     string s = FileTimeToString( ft );  
  14.     SScanf( s, "%02d/%02d/%04d %02d:%02d:%02d",  
  15.     month, day, year, hour, minute, second );  
  16.     year++;  
  17.     SPrintf( s, "%02d/%02d/%04d %02d:%02d:%02d",  
  18.     month, day, year, hour, minute, second );  
  19. int StringToDosDate( string s, DOSDATE &d, char format[] = "MM/dd/yyyy" )  
  20. int StringToDosTime( string s, DOSTIME &t, char format[] = "hh:mm:ss" )  
  21. int StringToFileTime( string s, FILETIME &ft, char format[] = "MM/dd/yyyy hh:mm:ss" )  
  22. int StringToOleTime( string s, OLETIME &ot, char format[] = "MM/dd/yyyy hh:mm:ss" )  
  23. int StringToTimeT( string s, time_t &t, char format[] = "MM/dd/yyyy hh:mm:ss" )  
  24. char[] StringToUTF8( const char src[], int srcCharSet=CHARSET_ANSI )  
  25. wstring StringToWString( const char str[], int srcCharSet=CHARSET_ANSI )  
  26.   
  27. //内存操作  
  28. int Memcmp( const uchar s1[], const uchar s2[], int n )  
  29. void Memcpy( uchar dest[], const uchar src[], int n, int destOffset=0, int srcOffset=0 )  
  30. void Memset( uchar s[], int c, int n )  
  31. string OleTimeToString( OLETIME ot, char format[] = "MM/dd/yyyy hh:mm:ss" )  
  32. int RegExMatch( string str, string regex ); //正则匹配  
  33. int RegExMatchW( wstring str, wstring regex );  
  34. int RegExSearch( string str, string regex, int &matchSize, int startPos=0 );   
  35. int RegExSearchW( wstring str, wstring regex, int &matchSize, int startPos=0 );  
  36.     if( RegExMatch( "test@test.ca",  
  37.     "\\b[A-Za-z0-9.%_+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,4}\\b" )  
  38.     == false )  
  39.     {  
  40.     Warning( "Invalid email address" );  
  41.     return -1;  
  42.     }  
  43.     int result, size;  
  44.     result = RegExSearch(  
  45.     "12:03:23 AM - 192.168.0.10 : www.sweetscape.com/",  
  46.     "\\d{1,3}\\.\\d{1,3}.\\d{1,3}.\\d{1,3}", size );  
  47.     Printf( "Match at pos %d of size %d\n", result, size );  
  48. void Strcat( char dest[], const char src[] )  
  49. int Strchr( const char s[], char c )  
  50. int Strcmp( const char s1[], const char s2[] )   
  51. void Strcpy( char dest[], const char src[] )  
  52. char[] StrDel( const char str[], int start, int count )   
  53. int Stricmp( const char s1[], const char s2[] )  
  54. int Strlen( const char s[] )  
  55. int Strncmp( const char s1[], const char s2[], int n )  
  56. void Strncpy( char dest[], const char src[], int n )   
  57. int Strnicmp( const char s1[], const char s2[], int n )  
  58. int Strstr( const char s1[], const char s2[] )  
  59. char[] SubStr( const char str[], int start, int count=-1 )  
  60. string TimeTToString( time_t t, char format[] = "MM/dd/yyyy hh:mm:ss" )  
  61. char ToLower( char c ) wchar_t ToLowerW( wchar_t c )  
  62. char ToUpper( char c ) wchar_t ToUpperW( wchar_t c )  
  63. void WMemcmp( const wchar_t s1[], const wchar_t s2[], int n )  
  64. void WMemcpy( wchar_t dest[], const wchar_t src[], int n, int destOffset=0, int srcOffset=0 )  
  65. void WMemset( wchar_t s[], int c, int n )  
  66. void WStrcat( wchar_t dest[], const wchar_t src[] )  
  67. int WStrchr( const wchar_t s[], wchar_t c )  
  68. int WStrcmp( const wchar_t s1[], const wchar_t s2[] )  
  69. void WStrcpy( wchar_t dest[], const wchar_t src[] )  
  70. wchar_t[] WStrDel( const whar_t str[], int start, int count )   
  71. int WStricmp( const wchar_t s1[], const wchar_t s2[] )  
  72. char[] WStringToString( const wchar_t str[], int destCharSet=CHARSET_ANSI )  
  73. char[] WStringToUTF8( const wchar_t str[] )  
  74. int WStrlen( const wchar_t s[] )  
  75. int WStrncmp( const wchar_t s1[], const wchar_t s2[], int n )  
  76. void WStrncpy( wchar_t dest[], const wchar_t src[], int n )  
  77. int WStrnicmp( const wchar_t s1[], const wchar_t s2[], int n )   
  78. int WStrstr( const wchar_t s1[], const wchar_t s2[] )  
  79. wchar_t[] WSubStr( const wchar_t str[], int start, int count=-1 )  
  80.   
  81. char[] FileNameGetBase( const char path[], int includeExtension=true ) //获取文件名  
  82. wchar_t[] FileNameGetBaseW( const wchar_t path[], int includeExtension=true )  
  83. char[] FileNameGetExtension( const char path[] )   
  84. wchar_t[] FileNameGetExtensionW( const wchar_t path[] )  
  85. char[] FileNameGetPath( const char path[], int includeSlash=true )   
  86. wchar_t[] FileNameGetPathW( const wchar_t path[], int includeSlash=true )  
  87. char[] FileNameSetExtension( const char path[], const char extension[] )   
  88. wchar_t[] FileNameSetExtensionW( const wchar_t path[], const wchar_t extension[] )   
  89.   
  90. //格式化字符串  
  91. int SPrintf( char buffer[], const char format[] [, argument, ... ] )  
  92. int SScanf( char str[], char format[], ... )  

数学函数

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. double Abs( double x )  
  2. double Ceil( double x )  
  3. double Cos( double a )  
  4. double Exp( double x )  
  5. double Floor( double x)  
  6. double Log( double x )  
  7. double Max( double a, double b )  
  8. double Min( double a, double b)  
  9. double Pow( double x, double y)  
  10. int Random( int maximum )  
  11. double Sin( double a )  
  12. double Sqrt( double x )  
  13. data_type SwapBytes( data_type x )  
  14. double Tan( double a )  

工具函数

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //计算校验和  
  2. int64 Checksum( int algorithm, int64 start=0, int64 size=0, int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
  3.     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  
  4. int ChecksumAlgArrayStr( int algorithm, char result[], uchar *buffer, int64 size, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
  5. int ChecksumAlgArrayBytes( int algorithm, uchar result[], uchar *buffer, int64 size, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
  6. int ChecksumAlgStr( int algorithm, char result[], int64 start=0, int64 size=0, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
  7. int ChecksumAlgBytes( int algorithm, uchar result[], int64 start=0, int64 size=0, char ignore[]="", int64 crcPolynomial=-1, int64 crcInitValue=-1 )  
  8.   
  9. //查找比较  
  10. 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 )  
  11.     int i, f1, f2;  
  12.     FileOpen( "C:\\temp\\test1" );  
  13.     f1 = GetFileNum();  
  14.     FileOpen( "C:\\temp\\test2" );  
  15.     f2 = GetFileNum();  
  16.     TCompareResults r = Compare( COMPARE_SYNCHRONIZE, f1, f2 );  
  17.     for( i = 0; i < r.count; i++ )  
  18.     {  
  19.     Printf( "%d %Ld %Ld %Ld %Ld\n",  
  20.     r.record[i].type,  
  21.     r.record[i].startA,  
  22.     r.record[i].sizeA,  
  23.     r.record[i].startB,  
  24.     r.record[i].sizeB );  
  25.     }  
  26. TFindResults FindAll( <datatype> data, int matchcase=trueint wholeword=falseint method=0, double tolerance=0.0, int dir=1, int64 start=0, int64 size=0, int wildcardMatchLength=24 )  
  27.     int i;  
  28.     TFindResults r = FindAll( "Test" );  
  29.     Printf( "%d\n", r.count );  
  30.     for( i = 0; i < r.count; i++ )  
  31.     Printf( "%Ld %Ld\n", r.start[i], r.size[i] );  
  32. int64 FindFirst( <datatype> data, int matchcase=trueint wholeword=falseint method=0, double tolerance=0.0, int dir=1, int64 start=0, int64 size=0, int wildcardMatchLength=24 )  
  33. TFindInFilesResults FindInFiles( <datatype> data, char dir[], char mask[], int subdirs=trueint openfiles=falseint matchcase=trueint wholeword=falseint method=0, double tolerance=0.0, int wildcardMatchLength=24 )  
  34.     int i, j;  
  35.     TFindInFilesResults r = FindInFiles( "PK",  
  36.     "C:\\temp""*.zip" );  
  37.     Printf( "%d\n", r.count );  
  38.     for( i = 0; i < r.count; i++ )  
  39.     {  
  40.     Printf( " %s\n", r.file[i].filename );  
  41.     Printf( " %d\n", r.file[i].count );  
  42.     for( j = 0; j < r.file[i].count; j++ )  
  43.     Printf( " %Ld %Ld\n",  
  44.     r.file[i].start[j],  
  45.     r.file[i].size[j] );  
  46.     }  
  47. int64 FindNext( int dir=1 )  
  48. TFindStringsResults FindStrings( int minStringLength, int type, int matchingCharTypes, wstring customChars="", int64 start=0, int64 size=0, int requireNull=false )  
  49.     TFindStringsResults r = FindStrings( 5, FINDSTRING_ASCII,  
  50.     FINDSTRING_LETTERS | FINDSTRING_CUSTOM, "$&" );  
  51.     Printf( "%d\n", r.count );  
  52.     for( i = 0; i < r.count; i++ )  
  53.     Printf( "%Ld %Ld %d\n", r.start[i], r.size[i], r.type[i] );  
  54.       
  55. //类型转换  
  56. char ConvertASCIIToEBCDIC( char ascii )  
  57. void ConvertASCIIToUNICODE( int len, const char ascii[], ubyte unicode[], int bigendian=false )  
  58. void ConvertASCIIToUNICODEW( int len, const char ascii[], ushort unicode[] )   
  59. char ConvertEBCDICToASCII( char ebcdic )  
  60. void ConvertUNICODEToASCII( int len, const ubyte unicode[], char ascii[], int bigendian=false )  
  61. void ConvertUNICODEToASCIIW( int len, const ushort unicode[], char ascii[] )  
  62.   
  63. int ExportFile( int type, char filename[], int64 start=0, int64 size=0, int64 startaddress=0,int bytesperrow=16, int wordaddresses=0 )  
  64. int ImportFile( int type, char filename[], int wordaddresses=falseint defaultByteValue=-1 )  
  65. int GetSectorSize()   
  66. int HexOperation( int operation, int64 start, int64 size, operand, step=0, int64 skip=0 )  
  67. int64 Histogram( int64 start, int64 size, int64 result[256] )  
  68. int IsDrive()  
  69. int IsLogicalDrive()  
  70. int IsPhysicalDrive()  
  71. int IsProcess()  
  72. int OpenLogicalDrive( char driveletter )  
  73. int OpenPhysicalDrive( int physicalID )  
  74. int OpenProcessById( int processID, int openwriteable=true )  
  75. int OpenProcessByName( char processname[], int openwriteable=true )  
  76. int ReplaceAll( <datatype> finddata, <datatype> replacedata, int matchcase=trueint wholeword=falseint method=0, double tolerance=0.0, int dir=1, int64 start=0, int64 size=0, int padwithzeros=falseint wildcardMatchLength=24 )  

另附本人写的binxml.bt,可以解析apk中的AndroidManifest.xml resource.arsc /res/*.xml


  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值