这是使用File对象把可见十六进制与文件互转的一个函数。
;文件转十六进制
file2hex(file){
tmp_file := FileOpen(file, "r")
while not tmp_file.AtEOF { ;没有到结尾
tmp_file.RawRead(Data, 1)
tmp_hex := SubStr("00" . ToBase(Asc(Data),16),-1)
hex = % hex tmp_hex
}
tmp_file.Close()
return hex
}
;十六进制转文件 比如hex=313233 ,文件内容则为123
hex2file(hex,file){
tmp_file := FileOpen(file, "w")
if (Mod(StrLen(hex),2)=1) ;不是双数长度
return -1
while hex
{
StringLeft, tmp_hex, hex, 2
StringTrimLeft, hex,hex, 2
tmp_hex := "0x" tmp_hex
tmp_file.WriteUChar(tmp_hex)
}
tmp_file.Close()
tmp_file =
}
;进制转换函数
ToBase(n,b){
return (n < b ? "" : ToBase(n//b,b)) . ((d:=Mod(n,b)) < 10 ? d : Chr(d+55))
}
49 queries in 0.979 seconds |