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)
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
|
|
|
|
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)
I think the best way to read binary data in VBScript is with the ADODB.Stream object.
|
|
|
|
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)
Can you post a little example?
|
|
|
|
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)
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
|
|
|
|
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)
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
|
|
|
|