用VBS读写二进制文件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

    Function ReadBinary(FileName)
      Dim Buf(), I
      With CreateObject("ADODB.Stream")
        .Mode = 3: .Type = 1: .Open: .LoadFromFile FileName
        ReDim Buf(.Size - 1)
        For I = 0 To .Size - 1: Buf(I) = AscB(.Read(1)): Next
        .Close
      End With
      ReadBinary = Buf
    End Function

    Sub WriteBinary(FileName, Buf)
      Dim I, aBuf, Size, bStream
      Size = UBound(Buf): ReDim aBuf(Size \ 2)
      For I = 0 To Size - 1 Step 2
          aBuf(I \ 2) = ChrW(Buf(I + 1) * 256 + Buf(I))
      Next
      If I = Size Then aBuf(I \ 2) = ChrW(Buf(I))
      aBuf=Join(aBuf, "")
      Set bStream = CreateObject("ADODB.Stream")
      bStream.Type = 1: bStream.Open
      With CreateObject("ADODB.Stream")
        .Type = 2 : .Open: .WriteText aBuf
        .Position = 2: .CopyTo bStream: .Close
      End With
      bStream.SaveToFile FileName, 2: bStream.Close
      Set bStream = Nothing
    End Sub