Read File as binary

Author Message
Baumi2003

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 11/22/2010
  • Status: offline
Read File as binary Monday, November 22, 2010 8:16 AM (permalink)
0
Hi,
 
I need to read a file and I need to get each Byte as a hex-value like in a HexEditor.
for example the file test.bin
The content of th file is: "User Template"
and I need the Hexcodes from this file like: 55 73 65 72 20 54 65 6D 70 6C 61 74 65 29
 
Hope someone can post an example
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:Read File as binary Monday, November 22, 2010 8:23 AM (permalink)
    0
    I think the best way to read binary data in VBScript is with the ADODB.Stream object.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      Baumi2003

      • Total Posts : 2
      • Scores: 0
      • Reward points : 0
      • Joined: 11/22/2010
      • Status: offline
      Re:Read File as binary Monday, November 22, 2010 8:27 AM (permalink)
      0
      Can you post a little example?
       
      #3
        Fredledingue

        • Total Posts : 572
        • Scores: 2
        • Reward points : 0
        • Joined: 5/9/2005
        • Location: Europe
        • Status: offline
        Re:Read File as binary Monday, November 22, 2010 10:54 AM (permalink)
        0
        t=BinaryToString(ReadBinaryFile("tempindex.dat"))   
        ' +----------------------------------------------------------------------------+
        ' | Converts binary data to a string (BSTR) using ADO recordset.          Thanks to "Vengy" 
        ' +----------------------------------------------------------------------------+
        Function BinaryToString(xBinary)
            Dim Binary
            'MultiByte data must be converted To VT_UI1 | VT_ARRAY first.
            If vartype(xBinary)=8 Then
         Binary = MultiByteToBinary(xBinary)
         Else
         Binary = xBinary
         End If
         
            Dim RS, LBinary
            Const adLongVarChar = 201
            Set RS = CreateObject("ADODB.Recordset")
            LBinary = LenB(Binary)     If LBinary>0 Then
              RS.Fields.Append "mBinary", adLongVarChar, LBinary
              RS.Open
              RS.AddNew
              RS("mBinary").AppendChunk Binary 
              RS.Update
              BinaryToString = RS("mBinary")
            Else
              BinaryToString = ""
            End If
        End Function 
        ' +----------------------------------------------------------------------------+
        ' | Read Binary Index.dat file.                         Thanks to "Vengy"                       |
        ' +----------------------------------------------------------------------------+
        Function ReadBinaryFile(FileName)
         Set BinaryStream = CreateObject("ADODB.Stream")
            BinaryStream.Type = 1
            BinaryStream.Open
            BinaryStream.LoadFromFile FileName
            ReadBinaryFile = BinaryStream.Read
            BinaryStream.Close
        End Function 

        Fred
         
        #4
          manuavaran

          • Total Posts : 2
          • Scores: 0
          • Reward points : 0
          • Joined: 12/18/2011
          • Location: India
          • Status: offline
          Re:Read File as binary Tuesday, December 20, 2011 5:18 PM (permalink)
          0
          Dear Fred,
          is there any way to decode the .log files to readable format. is it will be the reverse of this process?
          thanks in advance
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9