قبلا تکه کد مشابهی رو به زبان سی فرستاده بودم. این همونه اما به زبان پایتون.
#!/usr/bin/python3
'''
HexView.Py - A simple File Viewer in Hexadecimal format.
Author: FarooqKZ
Under GPL3+. THIS SOFTWARE COMES WITH NO WARRENTY FROM MAIN AUTHOR.
'''
import sys # I inlcude this to use sys.exit() and sys.argv
def showhelp(): # this function shows usage of program
print("Usage: hexview.py file_path\n\tfile_path: Path of file to view.");
sys.exit()
if '-h' in sys.argv: #shows help if something like this passed to program: 'hexview.py -h'
showhelp()
path = sys.argv[1]
filestream = None
fbytes = None
try:
filestream = open(path,'br') # Open the file in Binary mode for Reading(br)
fbytes = filestream.read() # Read all bytes from the file
finally:
if filestream:
filestream.close()
rown = 0
print('')
for b in fbytes:
s = hex(b).upper()
s = s.replace('0X','')# "0XBA" => "BA"
if len(s) == 1:
print('0', end='')
print(s, end=' ')
rown += 1
if (rown % 27) == 0:
print('')
print("\n") # prints 2 newline
پیوند تکه کد در گیت هاب گیست ( برای دریافت به اینجا بروید)