Haytham Mtair
Haytham Mtair

Reputation: 117

Hex to binary using VBScript

Is it possible to convert a Hexdump to binary using VBS? I made a program that reads any file as Byte array, then it converts it to Hex. In output Hexdump looks like this

00 00 00 0A 4D

til the end. Now i want to know if i can convert it back to binary and execute it using a VBScript. I will appreciate any help, thank you.

Upvotes: 3

Views: 8022

Answers (2)

Zimba
Zimba

Reputation: 3683

You could make an array out of the hex dump, prepend with "&h", then write the binary file:

Dim File : Set File = CreateObject("Scripting.FileSystemObject").CreateTextFile("Jim.bin")
data = Array(&h00,&h00,&h00,&h0A,&h4D)

for each x in data
File.write chr(x)
next

File.Close

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200233

Something like this should work:

hexstr = "00 00 00 0A 4D"

hexarr = Split(hexstr)
ReDim binarr(UBound(hexarr))

For i = 0 To UBound(hexarr)
  binarr(i) = Chr(CInt("&h" & hexarr(i)))
Next

binstr = Join(binarr, "")

Upvotes: 3

Related Questions