Python hexdumper with a difference.


 
Thread Tools Search this Thread
Top Forums Programming Python hexdumper with a difference.
# 1  
Old 09-05-2016
Python hexdumper with a difference.

Hi guys...

I haven't done any real Python code since I started messing with Shell Scripting in January 2012 when I started AudioScope.

Well I fished a little project out of my ANCIENT AMIGA files which created a raw hexdump of any binary file within reason for a stock A1200(HD).

Well although there was Python 1.4.0 to 2.0.1 for the classic AMIGA I could only use version 1.4.0 as this did not require an MMU or FP hardware for use.

Well the other day I decided to make it totally platform independent AND version independent and this is the result...

This task WAS difficult to do but the learning curve was worth the effort.

Boy oh boy have I forgotten a lot about Python...
Code:
# 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 AMIGA A1200(HD), with Python, 1.4.0 to 2.0.1.
# 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 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=binary.read(1)
	char=hex(ord(char))
	char=char[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' etension.
# 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()

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. UNIX for Advanced & Expert Users

A hexdumper using echo only...

Hi guys... Sometime ago I said I was going to attempt an Android project. I got my phone for XMAS and after installing a terminal program I realised how limited the command line is. I do NOT intend to __root__ the phone at this point but I can read and write to certain folders. The biggest... (14 Replies)
Discussion started by: wisecracker
14 Replies

5. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

6. SuSE

"ssh suse-server 'python -V' > python-version.out" not redirecting

Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here. I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
Discussion started by: Druonysus
3 Replies

7. Programming

what is the main difference between difference between using nonatomic lseek and O_APPEND

I think both write at the end of the file ...... but is there a sharp difference between those 2 instruction ..... thank you this is my 3rd question today forgive me :D (1 Reply)
Discussion started by: fwrlfo
1 Replies

8. Programming

Python: bash-shell-like less functionality in the python shell

Hello, Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells? Example: >>> import subprocess >>> help(subprocess) ... ... I'm hoping so as I hate scrolling and love how less works with... (0 Replies)
Discussion started by: Narnie
0 Replies

9. Shell Programming and Scripting

what is python?

I heard that its a new programming language but ill like to get a deeper explaination of it. (1 Reply)
Discussion started by: kprescod4158
1 Replies
Login or Register to Ask a Question