I am writing a python script which looks at common computer files and examines them for similar bytes, words, double word's. Though I need/want to see the files in Hex, ande cannot really seem to get python to open a simple file in python. I have tried codecs.open with hex as the encoding, but when I operate on the file descriptor it always spits back
File "main.py", line 41, in <module>
main()
File "main.py", line 38, in main
process_file(sys.argv[1])
File "main.py", line 27, in process_file
seeker(line.rstrip("\n"))
File "main.py", line 15, in seeker
for unit in f.read(2):
File "/usr/lib/python2.6/codecs.py", line 666, in read
return self.reader.read(size)
File "/usr/lib/python2.6/codecs.py", line 472, in read
newchars, decodedbytes = self.decode(data, self.errors)
File "/usr/lib/python2.6/encodings/hex_codec.py", line 50, in decode
return hex_decode(input,errors)
File "/usr/lib/python2.6/encodings/hex_codec.py", line 42, in hex_decode
output = binascii.a2b_hex(input)
TypeError: Non-hexadecimal digit found
def seeker(_file):
f = codecs.open(_file, "rb", "hex")
for LINE in f.read():
print LINE
f.close()
I really just want to see files, and operate on them as if it was in a hex editor like xxd. Also is it possible to read a file in increments of maybe a word at a time.
No this is not homework.