I have a file encoded in a strange pattern. For example,
Char (1 byte) | Integer (4 bytes) | Double (8 bytes) | etc...
So far, I wrote the code below, but I have not been able to figure out why still shows garbage in the screen. Any help will be greatly appreciated.
BRK_File = 'commands.BRK'
input = open(BRK_File, "rb")
rev = input.read(1)
filesize = input.read(4)
highpoint = input.read(8)
which = input.read(1)
print 'Revision: ', rev
print 'File size: ', filesize
print 'High point: ', highpoint
print 'Which: ', which
while True
opcode = input.read(1)
print 'Opcode: ', opcode
if opcode = 120:
break
elif
#other opcodes
To decode the PDF, or make the text editable in programs such as Microsoft Word or Google Documents, an intermediate program such as Acrobat Pro, or the less expensive Foxit Reader, must be used.
If the PDF still doesn't work after updating Acrobat Reader, go to Help > Repair installation. Restore previous version. Another method to repairing a damaged PDF is restoring it to a previous version. Head to the location where the PDF is saved, right click on the file and select Restore previous versions.
Step 1- Press Windows Key + X, and a menu will appear select Control Panel. Step 2- Go to the program and click on Uninstall a program. Step 3- Go for Adobe Acrobat Reader, then right-clicks and select Change from the menu. Step 4- Now click next and then select the Repair option.
Unsupported file type: This is the most common reason you cannot open PDF. Occasionally some files may erroneously have the default application set to Adobe Reader. This problem is usually an inadvertent human error. Outdated Acrobat or Adobe Reader: An outdated Adobe Reader or Acrobat program will throw this error.
read()
returns a string, which you need to decode to get the binary data. You could use the struct
module to do the decoding.
Something along the following lines should do the trick:
import struct
...
fmt = 'cid' # char, int, double
data = input.read(struct.calcsize(fmt))
rev, filesize, highpoint = struct.unpack(fmt, data)
You may have to deal with endianness issues, but struct
makes that pretty easy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With