python - file is backwards, literally -


i have file looking at. when open in hex editor, start shows 00 00 while bottom shows 64 c4 54 f7. magic bytes elf 7f 45 4c 46 reverse of that. using python try , flip program around, when f7 54 c4 64 instead of desired 7f 45 4c 46. here code using

import sys  if len(sys.argv) < 2:     print "error: 1 argument required!"     exit(-1)  try:     f1 = open(sys.argv[1], 'r') except ioerror:     print "error: file cannot opened."     exit(-1)  # else lines = [] line in f1:     line = line.replace('\n', '')     reversedline = line[::-1]     lines.append(reversedline) f1.close()  reversedlines = lines[::-1] line in reversedlines:     print line 

end of file

after script

any appreciated

l = [] open(sys.argv[1], 'rb') f:     ch = f.read(1)     while ch != "":         byte = ord(ch)         reverse_byte = chr((byte & 15) << 4 | byte >> 4)         l.insert(0, reverse_byte)         ch = f.read(1)  open(sys.argv[1], 'wb') g:     byte in l:         g.write(byte) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -