0

I am currently making a python hexdump program that writes the hex values of a disk image into a new text file. But for some reason the textfile created is always just full of white space. I dont think the text file is actually "empty" since its size is around 500+MB

I'd just like to know what I might be doing wrong and how I should fix it

Here is my code so far:

#!/usr/bin/python
from binascii import hexlify
filename = "diskimage.img"
hexstring = ""
with open(filename,'rb') as readfile:
    txtfile = open("output.txt", 'wb')
    for part in iter(lambda: readfile.read(1024), ''):
        append = part.encode('hex')     
        txtfile.write(append)   
    txtfile.close() 
  • This works for me. How do you check the content of `output.txt`? –  Aug 08 '14 at 09:15
  • Is the textfile actually twice the size of diskimage? Try `head -c 1000 output.txt` to see beginning of it - certainly your editor can bug *badly* when meeting a **line** with 500 million characters. – Antti Haapala -- Слава Україні Aug 08 '14 at 09:28
  • yes its roughly twice the disk image's size (266MB). I tried the head command and I guess it was just a case of my text editor bugging. Even xxd took a while to print the whole hexdump out – user3249400 Aug 08 '14 at 09:44

0 Answers0