• HEX2BIN


    第一种方法:

    php -r "echo bin2hex(file_get_contents('x.bin'));" >>hex.txt
    php -r "echo pack('H*',file_get_contents('hex.txt'));" >>x.bin
    

    第二种方法:

    Set fso=createobject("scripting.filesystemobject")
    if wscript.arguments.count<>1 then 
            wscript.echo "用法1:将文件拖到我身上!"&vbcrlf & "用法2:HBH.vbs ""filepath"" !"
            wscript.quit
    else
            if fso.fileexists(wscript.arguments(0))=false then 
            wscript.echo " 目标文件不存在 ":wscript.quit
            end if 
    end if
    
    
    Set file=fso.opentextfile(wscript.arguments(0))
    Fdata=file.readall
    file.close
    
    Isbin=false
    for k=1 to len(Fdata)
            ascii=asc(mid(ucase(Fdata),k,1))
            if (ascii<48 or ascii>70) or (ascii>57 and ascii<65) then 
             Isbin=true
             exit for
            end if
    next
    
    if Isbin=true then 
     ok=ReadBin(wscript.arguments(0))          '生成HEX文件                
    else
     ok=WriteBin(wscript.arguments(0), Fdata) '生成bin文件
    end if
    
    Function ReadBin(FileName)
     Dim Stream, ObjXML, MyNode
     Set ObjXML = CreateObject("Microsoft.XMLDOM")
     Set MyNode = ObjXML.CreateElement("binary")
     Set Stream = CreateObject("ADODB.Stream")
     MyNode.DataType = "bin.hex"
     Stream.Type = 1
     Stream.Open
     Stream.LoadFromFile FileName
     MyNode.NodeTypedValue = Stream.Read
     Stream.Close
    fso.opentextfile(FileName & ".txt",2,1).write(MyNode.Text)
     Set MyNode = Nothing
     Set Stream = Nothing
     Set ObjXML = Nothing
    End Function
    
    Function WriteBin(FileName, BufferData)
     Dim Stream, ObjXML, MyNode
     Set ObjXML = CreateObject("Microsoft.XMLDOM")
     Set MyNode = ObjXML.CreateElement("binary")
     Set Stream = CreateObject("ADODB.Stream")
     MyNode.DataType = "bin.hex"
     MyNode.Text = BufferData
     Stream.Type = 1
     Stream.Open
     Stream.Write MyNode.NodeTypedValue
     Stream.SaveToFile FileName & ".bin", 2
     Stream.Close
     Set stream = Nothing
     Set MyNode = Nothing
     Set ObjXML = Nothing
    End Function
    
    set Fdata=nothing
    set fso=nothing
    
  • 相关阅读:
    Nginx + uWSGI 配置django
    django视图缓存的实现
    scrapy 资料
    scrapy 安装
    程序题做题一般步骤
    检查代码的一般步骤
    Mathematical-Analysis-I-4
    Mathematical-Analysis-I-3
    Mathematical-Analysis-I-1
    Mathematical-Analysis-I-2
  • 原文地址:https://www.cnblogs.com/zpchcbd/p/12099554.html
Copyright © 2020-2023  润新知