3

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.

2 Answers 2

3

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, "")
Sign up to request clarification or add additional context in comments.

3 Comments

Having an off day? You cannot CInt a string that represents a byte in Hex in VBScript. (And you missed a ) on the ReDim line)
@AutomatedChaos Sure you can. You just need to prepend the string with &h, which is what I forgot. Fixed.
Ooh, nice solution. I was thinking about creating a dictionary with all hex pairs in 256 entries and their Chr'd Int value. Then with each pair, you do a lookup in the dictionary and use the item in the array. But this is much better.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.