Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: reverse hexdump

333 views
Skip to first unread message

foxidrive

unread,
Dec 14, 2011, 9:20:32 AM12/14/11
to
On 15/12/2011 01:12, superpollo wrote:
> on unix boxes one can hexdump, say, a binary file like a .png file to
> a textfile like this:
>
> 89504E470D0A1A0A0000000D4948445200000280000001E00803000000020F2CD60000
> 0300504C5445FFFFFF000000A0A0A0FF000000C0000080FFC000FF00EEEEC04000EEEE
> 002020C0FFC020008040A080FF804000FF80FF00C06000C0C0006080C0608000800040
> FF803060808060004040404080000000808060108060608060800000C00000FF006000
>
> and then reverse the process, i.e. giving the above text as input with a
> "reverse" flag on and get the origina binary as output.
>
> i understand that in dos/windows boxes there is the "debug" utility that
> does the dump. but:
>
> (1) can debug output to a text file as shown above?
> (2) cat debug do the reverse hexdump stuff?
> (3) if none of the above, is there a standard dos/windows command to do
> that?
>
> bye
>

On topic, you can do it with a batch file. This is from carlos.



Hello, With suggestions of foxidrive and Frank P Westlake (thanks
both) I build a new version of bhx. This new version 1.3 generate
batch code more efficient and vbs code more fast.

@echo off
:bhx_1.3
Del /f /q /a t.dat >nul 2>&1
For %%b In (
"4D534346000000007C050000000000002C000000000000000301010001000000000000"
"004400000001000100180B0000000000000000303CA91A20006268782E657865007BC8"
"D7C33005180B434BCD564D6C1B55107EEB04E46ED3382A115440C58B9354B6289B3480"
"D4442144240B8D8889ABA44A8590D3B5FDEC58D8BBEE7A93268803E004352C113DF400"
"1512A79E8B10420B8792AA1CCAA1521107A097E682B4565C29872219617599F7E39F10"
"28052E3C6B76DE9B9937F3CDBC79EB8DBC7A0EB520845A813C0F2107F1318AFE7EBC05"
"D4FEC457EDE8F33DD7BB1C69F27AD7CC7CA680F3A69136B51C4E68BA6E58384EB0B9A0"
"E38C8EC7A7A671CE481265DF3EB947F888AA084D4ABE1D7E3751A065AFF4E00ED9A94E"
"78740061818ECE7D1C37420D8EFAB97CFA34627931C38E665E673C561742A1FBC8F59F"
"0E7F10A1E17BE8158B2C59353040130F70DCCD03523DA524354BA3F3162E3840B97FA7"
"1D5463E3DFE23CB1F6F3DB653A39E7203C8AA2EE55A864F19BD66FAF3634B6EA2F567C"
"81D5C76061AB6DC58D56DB7FDCA507028625197889A2773FF53C4FECEBA9EF4381958F"
"20AF75B51A8575D4FDD047B7F9D7D48AAD56A9FADD08489C091ADC799E4138D62A4CEE"
"D8EA1DE6E1119FE8CC3575DB91182F8BF526F37A90A35E535D58DA1157BA16B8EC2FFE"
"FA5A6025CC40BBD4CDFB0729D4BD42B0E181F5D68D9A3D78DA729D972900881A75BF6F"
"6120441497F1B3EA2D5BDDB623D5C16B81E251C051EA64CEB68B1B1220B3D5329B94B7"
"7E1211579F047DE0B27A6B7523B0426B547A141E8E598F921351A49AF772B1220556F7"
"53AB62DDEA256E6543CD22DB90DA17FEE3CE6A5D1B66DA36B6B73BB0F23083542DBA12"
"180F5E1171BBA9C7F7EA7B7EF135675766F59058F500F7F05F39A12F85DD0529B32362"
"90D7EB01CE8B001FD425EF7049E9FA5DCFB3D5CDA8B3A7ABA64AFB4406304FB0792BE4"
"1A75E7F8DC19A1966E58AC68E0D2147DB4D398334CD9C695A5A718F00A83F41055BFC9"
"D4B725AE663B2E30D14D2E62A52F519FA2753BF9656059569D2B1C24B4D86752A371B9"
"7F9BDF073B52390EBDEA9EE317C28EDC5993E835A1BD3D2B4CE0BE5C90448B566B9DCC"
"F66EDB1D83DF058A4AA33545376D416757D979F30065F794240294CF4A5B3FB00A3D2B"
"352E21B8FB92798646A93667E46FCEA8762927D90EC86B7F0D57C5A1EF9F2833E4297B"
"489C0BCCB7D00EF8511A9E296ED68C6A3177BF5F9A4B4AEF6D0B8B22C1215C448DFE8F"
"BA9FF018EB6A59A058878E588740F4EDE1AE316D27ED121E1C64B3BF791E0467C5DC8E"
"BA3A122F2FE4F5FA83B45DBDDE36C13B04EF14FC80E08F0B8E05EF113C24F861C1FB05"
"7F46F0A3820F07EFE7BFF2FF3AE4178E9DC48B4794A7E513052D4D86707C7E49214B04"
"E796E3195D33976161C9EC7F3D4D74626A1653699692C82565549FA233689424E60D6C"
"A452F238C9E2BE14EE3B8DFB346CD1BF303CA22F64F1C0C8A123487ED130712F8C389E"
"D071484641D4DB3F7012056524A3301E37F0C808DF1352C1A142CDE3CF1DC13306CE12"
"3D16625B63613C6D913C1E90A90D9E9D4E9899BCA54C5BC9A9054B99353300736CDE8C"
"85C6B27A3A160A1E3A168C1D8A649262FBE1F8E1815898FEF0107E05320C2379ACC07C"
"E0BE38EE23438BF1420D390EF616822CA73FA4D2947EBD3849A559DAF80432F26090C4"
"2948E60CA0CBE86919CDCC135CC8BC01CA147C1EE5172C9CCA64098652F72B5CDB24D5"
"B51CD9E50FCCCCF83DCF773CD8F4BD16E4DF257F366C909F07FA18E822D0252007E86B"
"A06B4037807E04DA04BA0D7417A8BDFBBFEFCD15161326D4359B8545DECCE8560A2629"
"9A1EF0826566D924D55025B24681D0894928CB69D9AC91A0EB34B118B70873962A10F2"
"3AF0B984A15BA6914DE5E962AE40AC392D9F9FB396F38409605B4EA3AD9E2EC09A2C65"
"D867D9EF") Do >>t.dat (Echo.For b=1 To len^(%%b^) Step 2
Echo WScript.StdOut.Write Chr^(Clng^("&H"^&Mid^(%%b,b,2^)^)^) : Next)
Cscript /b /e:vbs t.dat > bhx.ex_
Del t.dat >nul 2>&1
Expand -r bhx.ex_ >nul 2>&1
Del bhx.ex_ >nul 2>&1




--
Regards,
Mic

superpollo

unread,
Dec 14, 2011, 9:34:55 AM12/14/11
to
foxidrive ha scritto:
thanks... i know that probably this is in the faq, and i promise i will
read them asap... but meanwhile, how do i execute the above code from
the prompt? i suppose i have that in a file...

bye

--
"Remember when teachers, public employees, Planned Parenthood,
NPR and PBS crashed the stock market, wiped out half of our 401Ks,
took trillions in TARP money, spilled oil in the Gulf of Mexico,
gave themselves billions in bonuses, and paid no taxes? Yeah,
me neither."

superpollo

unread,
Dec 14, 2011, 10:03:13 AM12/14/11
to
superpollo ha scritto:
i did it. it works ok, of course except for the "expand" part...

still... i hoped there was a standard dos tool instead of a full fledged
script to do that...

superpollo

unread,
Dec 14, 2011, 10:29:17 AM12/14/11
to
foxidrive ha scritto:
> On 15/12/2011 01:12, superpollo wrote:
>> on unix boxes one can hexdump, say, a binary file like a .png file to
>> a textfile like this:
>>
>> 89504E470D0A1A0A0000000D4948445200000280000001E00803000000020F2CD60000
>> 0300504C5445FFFFFF000000A0A0A0FF000000C0000080FFC000FF00EEEEC04000EEEE
>> 002020C0FFC020008040A080FF804000FF80FF00C06000C0C0006080C0608000800040
>> FF803060808060004040404080000000808060108060608060800000C00000FF006000
>>
>> and then reverse the process, i.e. giving the above text as input with a
>> "reverse" flag on and get the origina binary as output.
>>
>> i understand that in dos/windows boxes there is the "debug" utility that
>> does the dump. but:
>>
>> (1) can debug output to a text file as shown above?
>> (2) cat debug do the reverse hexdump stuff?
>> (3) if none of the above, is there a standard dos/windows command to do
>> that?
>>
>> bye
>>
>
> On topic, you can do it with a batch file. This is from carlos.
>
>
>
> Hello, With suggestions of foxidrive and Frank P Westlake (thanks
> both) I build a new version of bhx.

curious: what does bhx do?

foxidrive

unread,
Dec 14, 2011, 11:11:00 AM12/14/11
to
On 15/12/2011 02:29, superpollo wrote:
> foxidrive ha scritto:
>> On 15/12/2011 01:12, superpollo wrote:
>>> on unix boxes one can hexdump, say, a binary file like a .png file to
>>> a textfile like this:
>>>
>>> 89504E470D0A1A0A0000000D4948445200000280000001E00803000000020F2CD60000
>>> 0300504C5445FFFFFF000000A0A0A0FF000000C0000080FFC000FF00EEEEC04000EEEE
>>> 002020C0FFC020008040A080FF804000FF80FF00C06000C0C0006080C0608000800040
>>> FF803060808060004040404080000000808060108060608060800000C00000FF006000
>>>
>>> and then reverse the process, i.e. giving the above text as input with a
>>> "reverse" flag on and get the origina binary as output.
>>>
>>> i understand that in dos/windows boxes there is the "debug" utility that
>>> does the dump. but:
>>>
>>> (1) can debug output to a text file as shown above?
>>> (2) cat debug do the reverse hexdump stuff?
>>> (3) if none of the above, is there a standard dos/windows command to do
>>> that?
>>>
>>> bye
>>>
>>
>> On topic, you can do it with a batch file. This is from carlos.
>>
>>
>>
>> Hello, With suggestions of foxidrive and Frank P Westlake (thanks
>> both) I build a new version of bhx.
>
> curious: what does bhx do?

It generates the script from your binary file.



--
Regards,
Mic

superpollo

unread,
Dec 14, 2011, 11:27:43 AM12/14/11
to
d'oh.

fine, thanks... it is crazy that a simple utility like xxd(1) is missing
though.

bye

foxidrive

unread,
Dec 14, 2011, 11:37:59 AM12/14/11
to
On 15/12/2011 03:27, superpollo wrote:
> d'oh.
>
> fine, thanks... it is crazy that a simple utility like xxd(1) is missing
> though.

Geeze mate, you'll find a lot of other tools missing too. Sed for starters which I find particularly useful.

Windows batch file have traditionally been cobbled together using undocumented techniques (and third party programs) and is the charm in creating batch files.


With NT versions of windows it became a lot easier, but it is still patchwork in many ways. Microsoft made Powershell as a batch replacement - I have yet to do much with it.



--
Regards,
Mic

Todd Vargo

unread,
Dec 14, 2011, 5:16:33 PM12/14/11
to
On 12/14/2011 11:11 AM, foxidrive wrote:
> On 15/12/2011 02:29, superpollo wrote:
>> foxidrive ha scritto:
>>> On 15/12/2011 01:12, superpollo wrote:
>>>> on unix boxes one can hexdump, say, a binary file like a .png file to
>>>> a textfile like this:
>>>>
>>>> 89504E470D0A1A0A0000000D4948445200000280000001E00803000000020F2CD60000
>>>> 0300504C5445FFFFFF000000A0A0A0FF000000C0000080FFC000FF00EEEEC04000EEEE
>>>> 002020C0FFC020008040A080FF804000FF80FF00C06000C0C0006080C0608000800040
>>>> FF803060808060004040404080000000808060108060608060800000C00000FF006000
>>>>
>>>> and then reverse the process, i.e. giving the above text as input with a
>>>> "reverse" flag on and get the origina binary as output.
>>>>
>>>> i understand that in dos/windows boxes there is the "debug" utility that
>>>> does the dump. but:
>>>>
>>>> (1) can debug output to a text file as shown above?
Yes but very cumbersome.

>>>> (2) cat debug do the reverse hexdump stuff?
No.

>>>> (3) if none of the above, is there a standard dos/windows command to do
>>>> that?
Standard command, no. But you can create a vbscript to do what you want.

>>>>
>>>> bye
>>>>
>>>
>>> On topic, you can do it with a batch file. This is from carlos.
>>>
>>>
>>>
>>> Hello, With suggestions of foxidrive and Frank P Westlake (thanks
>>> both) I build a new version of bhx.
>>
>> curious: what does bhx do?
>
> It generates the script from your binary file.

Shouldn't it generate a hex dump from a binary file, and in reverse, a
binary file from the hex dump? (I did not run the script to see.)

BTW, superpollo's original post seems to have got lost.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

superpollo

unread,
Dec 14, 2011, 6:20:10 PM12/14/11
to
Todd Vargo ha scritto:
maybe it was a bit too long for your news-server (try another one, please)

bye

Todd Vargo

unread,
Dec 15, 2011, 1:23:22 AM12/15/11
to
On 12/14/2011 6:20 PM, superpollo wrote:
> Todd Vargo ha scritto:
>> On 12/14/2011 11:11 AM, foxidrive wrote:
>>> On 15/12/2011 02:29, superpollo wrote:
>>>> foxidrive ha scritto:
>>>>> On 15/12/2011 01:12, superpollo wrote:
>>>>>> on unix boxes one can hexdump, say, a binary file like a .png file to
>>>>>> a textfile like this:
<snip>

>>
>> BTW, superpollo's original post seems to have got lost.
>
> maybe it was a bit too long for your news-server (try another one, please)

Checked on 3 different servers, two of which specifically state they
ignore cancel msg requests.

Also, googlegroups confirms that foxidrive's post was the first post in
this thread.

http://groups.google.com/group/alt.msdos.batch/browse_thread/thread/4a970d8993ab1c1b#

Maybe it was posted in a different group with follow-up redirected here?

Todd Vargo

unread,
Dec 15, 2011, 1:33:21 AM12/15/11
to
Nevermind, found it on terranews. Strange that googlegroups does not
have it. Are you still looking for a solution? One where you provide a
source filespec and an output filespec and optionally provide a reverse
flag?

superpollo

unread,
Dec 15, 2011, 1:27:23 PM12/15/11
to
still looking...

Todd Vargo

unread,
Dec 15, 2011, 2:17:20 PM12/15/11
to
Ok, this is a batch group but not knowing the target OS, this solution
is a vbscript for Win98+ systems.

'hexdump.vbs
'Usage:
'cscript /nologo hexdump.vbs <infile.ext >hexdump.txt
'cscript /nologo hexdump.vbs -r <hexdump.txt >outfile.ext
'
Dim StdIn, StdOut
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
If WScript.Arguments.Count = 0 Then
Do While Not StdIn.AtEndOfStream
StdOut.Write Right("0"+Hex(Asc(StdIn.Read(1))),2)
n = n + 1
If n = 35 Then
n = 0
StdOut.Write vbCrLf
End If
Loop
ElseIf WScript.Arguments.count = 1 Then
If Lcase(WScript.Arguments(0)) = "-r" Then
Do While Not StdIn.AtEndOfStream
str = StdIn.ReadLine
For i = 1 to Len(str) step 2
StdOut.Write Chr("&H"+Mid(str,i,2))
Next
Loop
End If
End If


Now, you can either use it on command line using the syntax as shown at
the top of the script, or create a batch wrapper to invoke it. This is a
simple batch example without any error trapping. I leave it for you to
improve as deemed necessary.

::hexdump.bat
@echo off
if %1.==-r. goto :reverse
cscript /nologo hexdump.vbs <%1 >%2
goto :eof
::
:reverse
cscript /nologo hexdump.vbs -r <%2 >%3
:eof
0 new messages