HEXdump2BIN for OSX

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: HEXdump2BIN for OSX

Post by Dutchman »

You should rewrite the reading section. Now nd is made from nd+=n-1, but n originates from the split command which now is not used. ;)
Last edited by Dutchman on Thu Sep 07, 2017 8:42 am, edited 1 time in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: HEX2BIN for OSX

Post by rbytes »

Here is my best guess on how to do that, but I get strange results on my hex dump, and the program ends with an error when saving the binary file. The file is created, but is not a recognizeable music file. It takes a long time to process 4.5 MB!

Code: Select all

'HEXdumpWIN2BIN by rbytes
'concept by Dutchman, September 2017
'Transform hexdump-file from Windows 10 to binary file
'
'==== USER OPTIONS ====
Infile$="ironman.mp3HEXdump"
BinFile$="ironman.mp3"
'
'==== CONSTANTS ====
'
'==== PRESETS ====
OPTION BASE 1
'
'==== MAIN ====
'--- determine sizes
filesize=FILE_SIZE(InFile$)
FILE InFile$ READLINE line$
linesize=LEN(Line$)
PRINT "Operating on file """&InFile$&""":"
PRINT "Filesize=";"#":filesize
PRINT "Line length=";"#":linesize
lines=CEIL(filesize/linesize)
ns=lines*16 ' size of string-array
PRINT "Number of lines=";"#":lines
PRINT "Number of bytes in binary file is <=";"#":ns
DIM Dump$(ns)
'
'--- Read data into array
nd=1 'number of binary data
WHILE NOT FILE_END(InFile$)
  Dump$(nd)=line$
  nd+=1
  FILE InFile$ READLINE line$  
END WHILE
PRINT nd;"hex codes read."
PRINT "Last line contained ";"#":nd%16;"codes."
DIM Bin(ns)
'
'--- Write to binary file
IF FILE_EXISTS(BinFile$) THEN FILE BinFile$ DELETE
FOR i=1 TO nd
  Bin(i)=DEC(Dump$(i))
NEXT i
FILE BinFile$ WRITEDIM Bin
PRINT "Binary data written to """&BinFile$&"""."
'
'--- Test binary file
IF BinFile$="ironman.mp3" THEN
  PRINT "Test on binary file """&BinFile$&"""."
  MUSIC 1 LOAD BinFile$
  FOR i=1 TO 3
    MUSIC 1 PLAY
    PAUSE 1
  NEXT i
  'FILE BinFile$ DELETE
ENDIF
PRINT "Done"
END

The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: HEXdump2BIN for OSX

Post by Dutchman »

rbytes wrote:
Wed Sep 06, 2017 11:48 pm
Here is my best guess on how to do that, but I get strange results on my hex dump, and the program ends with an error when saving the binary file. The file is created, but is not a recognizeable music file. It takes a long time to process 4.5 MB!
I have changed my approach and use now pure hex-files, which are only two times the original size.
See "HEX2BIN for pure HEX-files" in viewtopic.php?f=20&t=1938&p=11757#p11757
I suppose that your example-file is also pure hex.
It should contain no spaces nor carriage return etc. So in fact it should contain a single (long or very long) line with HEX codes.
So please test the new approach.
That decoding-section is much simpler too. :D
Last edited by Dutchman on Thu Jan 19, 2023 3:27 pm, edited 1 time in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: HEXdump2BIN for OSX

Post by rbytes »

Thanks, Ton. I downloaded your new version and ran it on my test hexdump of some music. It was not recoverable as an audio file.

I will have to play with the hexdump settings in Windows. Swiss File Knife uses different flags for setting the dump characteristics. It may also be that there is a native hexdump operation for Windows, so I will look for that too.
The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: HEXdump2BIN for OSX

Post by Dutchman »

rbytes wrote:
Thu Sep 07, 2017 2:54 pm
… I downloaded your new version and ran it on my test hexdump of some music. It was not recoverable as an audio file. …
I would start with a short file, so that it easily can be inspected in a text editor.
You could also determine what the format is and then adapt the read and decode section.
If you send me a file, I could try to make a decoder.
A 'pure' HEX-file however would be the best solution.
Succes with your search :D

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: HEXdump2BIN for OSX

Post by rbytes »

Thanks, Ton. I appreciate your help.
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: HEXdump2BIN for OSX

Post by rbytes »

I have chosen a small file, ping,wav, which produces a ping sound. The best I can do is get a hexdump without text but apparently still with line feeds. The HEX file is slightly larger than twice the original size. I don't see any way in Swiss File Knife to output without line feeds. It does have the option of outputting 32 characters per line, which would likely speed up reading.

I used the modifiers -pure and -nofile to produce the attached. -pure encodes only hex characters and -nofile prevents the filename from being inserted as line 1. Maybe you can figure out how to read ping.wavHEX (remove the suffix .wav first). Currently only 16 bytes are being read, so I guess the reading is stopping after the first line.
Attachments
ping.wavHEX.wav
(8.06 KiB) Downloaded 425 times
The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: HEXdump2BIN for OSX

Post by Dutchman »

rbytes wrote:
Thu Sep 07, 2017 6:22 pm
I have chosen a small file, ping,wav, which produces a ping sound. The best I can do is get a hexdump without text but apparently still with line feeds. The HEX file is slightly larger than twice the original size. I don't see any way in Swiss File Knife to output without line feeds. It does have the option of outputting 32 characters per line, which would likely speed up reading.

I used the modifiers -pure and -nofile to produce the attached. -pure encodes only hex characters and -nofile prevents the filename from being inserted as line 1. Maybe you can figure out how to read ping.wavHEX (remove the suffix .wav first). Currently only 16 bytes are being read, so I guess the reading is stopping after the first line.
The file contains carriage-return characters.
I had also made such a file with the DOS command-line program Bin2Hex.exe downloaded from
http://www.softpedia.com/get/System/Fil ... 2Hex.shtml
With that program I generated the file "alarm.wavHEXdos" and adapted the HEX2BIN program.
The file can be transformed with Select=3.
See the HEX2BIN-topic for further details.
I renamed also the procedure description file to "BIN to HEX procedure" because it relates now to OSX and DOS.
Please try it with Select=3. :D

Post Reply