首页
社区
课程
招聘
[原创]编写010editor简单脚本
2017-11-27 19:44 13104

[原创]编写010editor简单脚本

2017-11-27 19:44
13104

编写010editor简单脚本


为了简单快速的执行一些数据转换,特意花了一点时间查看了010editor脚本的编写,下面简单的介绍010editor一个脚本。


010eiditor脚本以 xxx.1sc为结尾的文件,可以在程序中新建



在文件中编写脚本


底下就是脚本文件代码

//------------------------------------------------
//--- 010 Editor v7.0.2 Script File
//
//      File: 010
//   Authors: fily_sun
//   Version: 1.0
//   Purpose: 
//  Category: 
//   History: 
//------------------------------------------------

int count;
int i;

Printf("%d\n",FileSize());//打印文件大小
Printf("%s",ReadString(0));
count=InputNumber(GetScriptName(), "Enter number of times to paste:", "10"); //弹框获取字输入的数字

//循环解密
for(i=0;i<count;i++)
{
    Printf("%c",ReadByte(i)^0x15);
    WriteByte(i,ReadByte(i)^0x15);
}

//切换到最后打开的文件窗口
//FileSelect(GetFileNum()+1);

接下来介绍一下010editor提供的一些函数
该文档摘取010editor官方文档 http://www.sweetscape.com/010editor/manual/IntroScripts.htm


010editor脚本语法基本与c语言类似,在此不再多介绍。


0101editor提供了5类接口函数

    1.接口

    2.I/O数据流

    3.字符串操作

    4.数学函数

    5.工具


接口函数:http://www.sweetscape.com/010editor/manual/FuncInterface.htm
//添加书签
void AddBookmark( 
int64 pos, 
string name, 
string typename, 
int arraySize=-1, 
int forecolor=cNone, 
int backcolor=0xffffc4, 
int moveWithCursor=false )
 
//拷贝当前选择的字节到剪切版
void CopyToClipboard()
//剪切当前选择的字节到剪切版
void CutToClipboard()
//删除磁盘文件,该文件不能在010打开
int DeleteFile(char filename [])
//显示的变量格式
void DisplayFormatBinary()
void DisplayFormatDecimal()
void DisplayFormatHex()
void DisplayFormatOctal()

//关闭文件
void FileClose()
//当前打开的文件的句柄
int FileCount()

//如果给定的文件名存在于磁盘上,则返回true,否则返回false
int FileExists(const char filename [])

//新建一个文件
int FileNew(char interface [] =“”,int makeActive = true)
//打开现有的文件
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 GetBackColor()

//获取剪切板数据
int GetClipboardBytes(uchar buffer [],int maxBytes)

//获取剪切板数据
string GetClipboardString()

//获取当前时间
string GetCurrentTime(char format [] =“hh:mm:ss”)
//获取当前日期
string GetCurrentDate(char format [] =“MM / dd / yyyy”)

//获取时间日期
string GetCurrentDateTime(char format [] =“MM / dd / yyyy hh:mm:ss”)

//获取光标位置
int64 GetCursorPos()

//获取环境
char [] GetEnv(const char str [])

//获取当前完整文件名
char [] GetFileName()

//获取文件选项个数
int GetFileNum()


//返回每次单击鼠标滚轮前后滚动的行数。 
int GetMouseWheelScrollSpeed()
//滚动速度可以通过编辑器选项对话框或
SetMouseWheelScrollSpeed(int xxxx)

//获取文件是否只为读
int GetReadOnly()

//获取当前脚本名称
char [] GetScriptFileName()
wchar_t [] GetScriptFileNameW()

//获取选择的字节数
int64 GetSelSize()
//获取选中的字节开始
int64 GetSelStart()

//带标题的选择框,获取文件目录
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 [] =“所有文件(*)”,
    char filename [] =“”)
    
char [] InputString(
    const char title [],
    const char caption [],
    const char defaultValue []) 

//是否对文件修改
int IsModified()

//弹框
int MessageBox(int mask,const char title [],const char format [] [,argument,...])
//打印格式字符
int printf(const char format [] [,argument,...]) 

//设置光标位置
void SetCursorPos(int64 pos)

//设置文件是否只读
int SetReadOnly(int readonly)

IO数据流操作函数:http://www.sweetscape.com/010editor/manual/FuncIO.htm

//大端方式
void BigEndian()

//从文件xxx,开始删除size大小
void DeleteBytes( int64 start, int64 size )   

//文件末尾
int FEof()

//文件大小
int64 FileSize()

//将文件写入到另一个文件中
int FPrintf(int fileNum,char format [],...)

//设置文件指针(模版中重要)
int FSeek(int64 pos)

//读取当前文件指针偏移,可以是正或负
int FSkip(int64 offset)
//文件当前的位置
int64 FTell()

//在指定位置插入数据
void InsertBytes(int64 start,Int64 size,UCHAR value= 0)
//指定位置覆盖数据
void OverwriteBytes(int64 start,int64 size,uchar value = 0)

//读取默认当前位置 数据
char ReadByte(int64 pos = FTell())
double ReadDouble(int64 pos = FTell())
float ReadFloat(int64 pos = FTell())
hFloat ReadFloat(int64 pos = FTell())
int ReadInt(int64 pos = FTell())
int64 ReadInt64(int64 pos = FTell())
int64 ReadQuad(int64 pos = FTell())
short ReadShort(int64 pos = FTell())
uchar ReadUser(int64 pos = FTell())
uint ReadUInt(int64 pos = FTell 
uint64 ReadUInt64(int64 pos = FTell())
uint64 ReadUQuad(int64 pos = FTell())
ushort ReadUShort(int64 pos = FTell())

//读取一行
char [] ReadLine(int64 pos,int maxLen = -1,int includeLinefeeds = true)

//读取指定位置大小字节
void ReadBytes(uchar buffer [],int64 pos,int n)

//读取文件当前的行号,不能是16进制文文件
int64 TextGetNumLines()

//指定位置写入数据
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 )




字符串操作函数:http://www.sweetscape.com/010editor/manual/FuncString.htm 
//将字符串转换为浮点数。错误时返回零。
double Atof(const char s [])

//将字符串转换为整数。错误时返回零。
int Atoi(const char s [])

//二进制转整形
int64 BinaryStrToInt(const char s [])

//字符编码成其他格式         有值: CHARSET_ASCII ,CHARSET_UNICODE,CHARSET_UTF8
char [] ConvertString(const char src [],int srcCharSet,int destCharSet)

//获取文件名中不带文件夹路径的名字()  例如:F:/temp/1.txt    返回1.txt
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)

//修改文件扩展名         “C:\ temp \ file.bmp” ==FileNameSetExtension(“C:\\ temp \\ file.dat”,“bmp”);
char [] FileNameSetExtension(const char path [],const char extension [])
wchar_t [] FileNameSetExtensionW(const wchar_t path [],const wchar_t extension [])

//转换文件时间
string (FILETIME ft,char format [] =“MM / dd / yyyy hh:mm:ss”)

//内存比较
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)
//内存置 c字节
void Memset(uchar s [],int c,int n)

//正则表达式
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); 

//与c语言一样,打印字符到buffer中
int SPrintf(char buffer [],const char format [] [,argument,...])

int SScanf(char str [],char format [],...)

//字符拼接
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)

//转换宽字节
wstring StringToWString(const char str [],int srcCharSet = CHARSET_ANSI)

//返回空字符前 s中的字节数。
int Strlen(const char s [])

//与Strcmp类似,但不超过 n个字符进行比较。
int Strncmp(const char s1 [],const char s2 [],int n)

//与 Strcpy类似,除了最多 n个字符将被复制。
void Strncpy(char dest [],const char src [],int n)

//出现相同字符的位置
int strstr(const char S1 [],为const char S2 [])

//转换小写
char ToLower(char c)
wchar_t ToLowerW(wchar_t c)
//转换大写
char ToUpper(char c)
wchar_t ToUpperW(wchar_t c)

//宽字节转换utf-8格式
char [] WStringToUTF8(const wchar_t str [])


数学函数:http://www.sweetscape.com/010editor/manual/FuncMath.htm

//返回浮点数 x的绝对值。
double Abs(double x)

//返回不小于 x的最小整数。
double Ceil(double x)

//返回数字 a和 b中较大的一个。
double Max(double a,double b)

//返回数字 a和 b中较小的一个。
double Min(double a,double b)

//随机数
int Random(int maximum)
//平方
double Pow(double x,double y)

//平方根
double Sqrt(double x)

//正弦
double Sin(double a)
double Tan(double a)
double Cos(double a)

这里只列出其中一部分,更多文档查看官方文件!



[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
点赞2
打赏
分享
最新回复 (2)
雪    币: 9
活跃值: (145)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
yber 2017-12-31 08:23
2
0
谢谢分享
雪    币: 8290
活跃值: (4826)
能力值: ( LV4,RANK:45 )
在线值:
发帖
回帖
粉丝
v0id_ 2020-12-18 23:27
3
0
好用,学习了
游客
登录 | 注册 方可回帖
返回