binary dataFYI: Below is a script I ported from an original version published more a year ago
from ANTOINE Jean-Luc. The script dumps the content of any file (also exe or dll)
als a sequenz of hex values. Use the code to study how to access binary files using
FileSystemObject object. Then if you have the bytes you need, you can convert them
easily into an integer:
result = byte0 + byte1*246 + byte3 * 256*256
Hope this helps (sorry for the German comments, I was too lazy to localize that stuff).
G. Born
Check out the WSH Bazaar at:
www.borncity.de
'************************************************
' File: Hexdump.vbs (WSH-Beispiel in VBScript)
' Autor: (c) G. Born
'
' Zweck: Gibt den Inhalt einer Datei als Hexdump aus.
' Die ursprngliche Idee stammt von:
' Achtung: Ben?tigt die Komponente WinExtend.ocx
' zum ?ffnen des Dateidialogs.
'************************************************
Option Explicit
Dim arg, name, Title, dlg, text
DIM f, temp, a, s, n, c, r, k
Title = "WSH-Beispiel"
' Wurde der Dateiname bergeben?
set arg = Wscript.Arguments ' hole Argumentsauflistung
If arg.Count Then ' Ja, hole Name
name = arg.item(0)
Else
' Wir arbeiten mit der WSHFileDialog-Methode
Set dlg = WScript.CreateObject ("WSHExtend.WinExt")
If (dlg.WSHFileDialog("C:\")) Then
name = dlg.FolderName
If (Right(name,Len(name)-1) <> ":\") Then name = name + "\"
name = name + dlg.FileName
Else
WScript.Quit 1 ' Abgebrochen
End If
End if
' Jetzt holen wir das FilesystemObject-Objekt
Set f = CreateObject("Scripting.FileSystemObject")
If Not f.FileExists(name) Then ' Datei gefunden?
MsgBox "Datei " & name & " existiert nicht", _
vbOKOnly + vbExclamation, Title
WScript.Quit 2 ' Beenden
End If
temp = f.GetTempName ' hole tempor?rer Dateiname
Set c = f.CreateTextFile(temp, -1)
Set a = f.OpenTextFile(name, 1)
c.WriteLine("Datei: " & name & vbCRLF)
n = 0
While Not a.AtEndOfStream
If (n Mod 16) = 0 Then ' Zeilenanfang?
s = Right("00000" & Hex(n), 6)
r = " "
End If
k = Asc(a.Read(1)) ' lese Zeichen
If k > 31 And k < 128 Then
r = r & Chr(k)
Else
r = r & "."
End if
s = s & " " & Right("0" & Hex(k), 2)
n = n + 1
If ((n Mod 16) = 0) or a.AtEndOfStream Then _
c.WriteLine(s) & Space(((n Mod 16)>0)*((n Mod 16)*3-48)) & r
Wend
a.Close ' Eingabedatei schlie?en
c.Close ' Ausgabedatei schlie?en
If (MsgBox ("Dateidump anzeigen ?", vbYesNo + vbQuestion, Title) _
= vbYes) Then
Set c = WScript.CreateObject("WScript.Shell")
c.Run "notepad.exe " & temp, 1 ,-1
End if
f.DeleteFile temp ' Ausgabedatei l?schen
'*************************************************
'*** Ende -> WSH powered by Gnter Born ***
'*************************************************
I need to read some values from a file generated by a software product we use. The file consists of fixed length records with fixed length fields. Some of the fields contain binary values; for example "RCDCOUNT START 25 LEN 3 BINARY". Does anyone know a simple way to read these fileds aand convert the binary values to decimal in script?
TIA
Ed