This is not a hexreader. This code creates a raw hexdump of a binary file that is whitespace, optional, delimited. The dump is saved into the current directory with a ".hex" extension.
It works on just about any current platform but is designed around a stock Amiga A1200(HD) with Python 1.4.0. It also works on the current stable version 3.5.2.
I needed a hexdump some years ago for banging the Amiga hardware, and decided to modify recently for another usage but it had to still work on version 1.4.0 for the classic A1200.
Enjoy...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # hexdump.py
#
# Original idea, (C)2006-2016, B.Walker, G0LCU.
# Issued as Creative Commons CC0 licence.
# Modified to suit _all_ versions of python.
#
# exec(open("Full path to hexdump.py").read())
# For all versions OR...
# execfile("Full path to hexdump.py")
# ...for versions 2.x.x and below.
# Works from Python 1.4.0 to 3.5.2 without modification.
#
# IMPORTANT! There is NO error checking in this code. It relies entirely
# on Python's own tracebacks for user and/or programming errors.
#
# Tested on:-
# 1) Classic stock AMIGA A1200(HD), OS 3.0x, with Python, 1.4.0 to 2.0.1.
# WinUAE and FS-UAE running AMIGA OS 3.1x. (E-UAE might work too.)
# 2) Windows 8.1, with Python, 2.7.9 and 3.4.3.
# 3) OSX 10.7.5, OSX 10.11.6, with Python 2.5.x, 2.6.x, 2.7.x and 3.5.2.
# 4) Ubuntu 16.04, 64 bit, with Python 2.7.11 and 3.5.1.
#
# Obviously there are versions missed out as I no longer have them,
# but suffice it to say that this was written around an AMIGA about 10 years
# ago so I decided to make it universal recently and issue as a fun project...
import sys
if sys.version[0]>="3": raw_input=input
filename=raw_input("Full path and filename, then press ENTER:- ")
binary=open(filename,"rb+")
length=len(binary.read())
array=""
for position in range(0,length,1):
binary.seek(position)
char=hex(ord(binary.read(1)))[2:]
if len(char)<=1: char="0"+char
# Remove the whitespace for a pure hex-string.
# array=array+char
array=array+char+" "
binary.close()
# Create a pseudo-array, whitespace delimited, this line can be ommitted.
# Bending the rules of print as a statement and as a function here. ;o)
print("%s" %(array))
# Save the text _hex_ dump as the original filename with the '.hex' extension.
# In this specification the HEX file length should be exactly 3 times the size
# of the original binary file length. It is deliberately whitespace delimited.
filename=filename+".hex"
hexadecimal=open(filename,"w")
hexadecimal.write(array)
hexadecimal.close()
|
Works from Python 1.4.0 for the Amiga, (thanks to Irman de Jong), to the current 3.5.2 on ?all? current OSes...
Bazza, G0LCU.