mirror of
https://github.com/moshix/mvs.git
synced 2026-03-06 10:43:31 +00:00
Create hexdump.py
a hex dumper in python
This commit is contained in:
39
hexdump.py
Normal file
39
hexdump.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/opt/homebrew/bin/python3.10
|
||||
|
||||
# Copyright 2023 by moshix
|
||||
#
|
||||
#
|
||||
# hexdump.py a hex disassembler in ython
|
||||
#
|
||||
#
|
||||
# Usage: hexdump.py objectfile
|
||||
# dumps hex in groups of 16 bytes
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# v0.1 Humble beginnings
|
||||
# v0.2 open file and read into byte array data
|
||||
# v0.3 extract program name from MVS object file at position 8..16
|
||||
# v0.4 loop thru object starting from position 359 and print out hex program
|
||||
# v0.5
|
||||
import sys
|
||||
|
||||
def hexdump(filename):
|
||||
with open(filename, 'rb') as f:
|
||||
counter = 0
|
||||
while True:
|
||||
chunk = f.read(16)
|
||||
if not chunk:
|
||||
break
|
||||
hexdata = ' '.join(f'{byte:02X}' for byte in chunk)
|
||||
textdata = ''.join(chr(byte) if 32 <= byte <= 126 else '.' for byte in chunk)
|
||||
print(f'{counter:08X} {hexdata:<48} {textdata}')
|
||||
counter += 16
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
print(f'Usage: {sys.argv[0]} <filename>')
|
||||
sys.exit(1)
|
||||
hexdump(sys.argv[1])
|
||||
Reference in New Issue
Block a user