This script shows the Hex dump of a file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,
this script opens an IE windows and shows the hex dump of the file dropped on the icon.
If you do not use drag and drop, you can choose a file from the open dialog box (needs the
appropriate library registered).
Giovanni.


'<%
'************************************************
' File: HexDump2.vbs (VBScript)
' Author: Giovanni Cenati
' 16 june 2005
' Mostra in IE un file in esadecimale
' Shows a hex dump of a selected file
' http://digilander.libero.it
' Codice utilizzabile citando il sito.
' Based on a script post by spmlinton at sk sympatico ca
' in the newsgroup microsoft.public.scripting.vbscript
' on Thu, 27 Mar 2003
'************************************************
Set objArgs = WScript.Arguments 'Vedo se ci sono degli argomenti passati allo script
if objargs.count=0 then
Set comDlg=CreateObject("MSComDlg.CommonDialog.1")
const cdlOFNHideReadOnly = 4 'Nasconde la casella "sola lettura"
const cdlOFNFileMustExist = 4096 'Puoi scegliere solo files esistenti
Const cdlOFNExplorer = 524288 'Finestra in stile win95
comDlg.Flags = cdlOFNHideReadOnly + cdlOFNFileMustExist + cdlOFNExplorer
comDlg.Filter = "Tutti i files|*.*"
comDlg.DialogTitle="Visualizza un file in formato esadecimale"
'comDlg.InitDir="c:\"
comDlg.maxfilesize=500
'comDlg.FileName="c:\autoexec.bat"
comDlg.ShowOpen
if comDlg.FileName="" then wscript.quit
FName= comDlg.FileName
'Ricordo il filename scelto. Saves the filename in variable
set comDlg=nothing 'Scarica l'oggetto. Discards object
else
fName = objArgs(0)
end if

' Lancia Internet Explorer per mostrare i risultati.
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank" ' documento vuoto. Empty doc.
' Importante: aspetta che Internet Explorer sia pronto
Do While (oIE.Busy) ' Waits until IE is ready
WScript.Sleep 200 ' Sospende per 200 millisecondi.
Loop
oIE.Visible = 1 ' Internet Explorer è visibile.
oIE.ToolBar = 1 ' ed ha la toolbar così è presente il pulsante "stampa"
Set doc1 = oIE.Document ' Punta al documento...
doc1.open ' ...lo apre
' Scrive le intestazioni html. Writes html headers
doc1.writeln("<html><head><title>" & Title & "</title></head>")
doc1.writeln("<body bgcolor='#FAF0F0'><pre>")

Const ForReading = 1
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(FName) 'apro il file. Open file for reading
set ts=f.OpenAsTextStream(ForReading,0) 'in lettura
byteCtr=0
chCtr=0

doc1.writeln(Fname)
doc1.writeln(f.size & " bytes")
doc1.writeln()
do while not ts.atendofstream
ch=ts.read(1) 'Legge un carattere. Reads a char
chCtr=chCtr + 1 'E ne tiene nota nel conteggio. Counts it

hexch=hex(asc(ch)) 'Ne determina il codice ascii. Finds ascii code
if len(hexch)< 2 then hexch="0" & hexch
hexLine=hexLine & hexch & " " 'Adds it to the string

if asc(ch)> 31 and asc(ch)< 127 then 'Printable?
if ch=">" then ch="&gt;" '(IE lo interpreterebbe come un tag)
if ch="<" then ch="&lt;" '(IE would think it's a tag)
ascStr=ascStr & ch 'è stampabile. Yes
else
ascStr=ascStr & "." 'non è stampabile. No
end if



'Prepara la stampa di una riga:
'indirizzo - 16 esadecimali - 16 caratteri ascii
'Prepares a line to be displayed:
'Address, 16 hex characters, 16 ascii
if chCtr=16 or ts.atendofstream then
lineStr=byteCtr & vbtab & hexLine & vbtab & ascStr
'Now manages last line if it has less than 16 chars
if chCtr<16 then 'Se l'ultima riga ha meno di 16 cartteri...
lineStr=byteCtr & vbtab & hexLine 'inizio normalmente
for r= (chCtr+1) to 16 'poi riempio la parte restante della riga
lineStr= lineStr & "-- " 'con dei caratteri
next
lineStr = lineStr & vbtab & ascStr 'e finisco normalmente
end if
'Writes output to Internet Explorer
doc1.writeln(lineStr) 'Scrive in IE la riga creata
byteCtr=byteCtr + chCtr 'incrementa l'indirizzo
chCtr=0 'e azzera il parziale
ascStr=""
hexLine=""
end if
loop

'Chiude le intestazioni html
'Closes html headers
doc1.writeln("</pre></body></html>")
doc1.close

set fso=nothing
set f=nothing
set ts=nothing
--
Giovanni Cenati (Aosta, Italy)
Write to user "Reventlov" and domain at katamail com
http://digilander.libero.it/Cenati (VbScript)
.



Relevant Pages

  • Re: Modifying a record field value while not blocking it to others
    ... And of course again the record you are trying to modify has not to be 'open' ... someone opens that ID=12 record everything in it is locked. ... often add a script line which opens a random record if the file holds enough ... system where customers use Credits when renting items and get Credits ...
    (comp.databases.filemaker)
  • Re: Right click on text vs. right click on hyperlink
    ... I were to do that the built-in Windows way, I have to go down about ... >> me to open in one step the editing page of any archive page in my ... >> contains the below Windows script. ... >> that url and opens the editing page. ...
    (microsoft.public.scripting.vbscript)
  • Re: & Now, a Script to List the Running Process Info - Re: Useful little Script to Show the
    ... Done that to the desktop folder, ... at a Command Prompt, with the Name of the Script File (after a Space, ... a Folder where the Command Prompt Opens (either the Root of the ...
    (uk.people.silversurfers)
  • Re: The power of Windows script
    ... htm file that contains the script, and the script opens a new Word ... get the selection, the url, and the title. ... that copies text that's in Word and that opens a new e-mail. ... ' Running a macro in Word that turns the url into a hyperlink. ...
    (microsoft.public.scripting.vbscript)
  • Re: simple script to read and output Mailbox body to file.
    ... Hi please could someone point to what I have done wrong as the script runs ... ## This script will open and parse email messages body content. ... # 'r+' opens the file for both reading and writing. ... # openreturns a file object, and is most commonly used with two arguments: ...
    (comp.lang.python)