0

Im trying to decode a binary file.

Here is a sniped from the file:

Content-Length: 122092
Content-Type: application/octet-stream


b'\x00\x01\x00\x00\x00\x0e\x00\x80\x00\x03\x00`FFTMm\x02\xd2u\x00\x00\x00\xec\x00\x00\x00\x1cGDEF\x00\'\x023\x00\x00\x01\x08\x00\x00\x00\x1eOS/2\x886z\x01\x00\x00\x01(\x00\x00\x00`cmap\xc9\x03\xa0\xac\x00\x00\x01\x88\x00\x00\x02\xc2gasp\xff\xff\x00\x03\x00\x00\x04L\x00\x00\x00\x08glyf\x05.G/\x00\x00\x04T\x00\x01\xb1\xechead\t\xe6\x15\x97\x00\x01\xb6@\x00\x00\x006hhea\x0e\xf9\n(\x00\x01\xb6x\x00\x00\x00$hmtx:b\x13<\x00\x01\xb6\x9c\x00\x00\x08\xaaloca\x18\xce\x84\xc4\x00\x01\xbfH\x00\x00\x04\\maxp\x02\x96\x02\x1c\x00\x01\xc3\xa4\x00\x00\x00

...

\xf52\xb5{ \x9e\xa8V\xb1\x93\x89m8\xca\xca\xdf\x14K\xb1g\x1dX3\xe4\xa3\xa5e\x195>\x9a&\x15\xa8\xa5eZ\xfe\x00c\x80\x06\xef\xb6\x18M\x06\x9d\xc1\xc0\xeb\x95\xc5\x8e\xce?\xcdh\xbetV\xfb\xbe\x99\x03\xbb\x

I used following code to decode the file:

file_data = open('font2.txt', 'rb').read()
file_data = file_data.decode('utf-16')
print(file_data)

Unfortunately it seems that it will not be decoded correctly. The output of decode is the same as in the encoded file.

Do you have any suggestions how to solve it?

I am grateful for any hints. :)

3
  • 1
    Does this answer your question? Reading a binary file as plain text using Python Commented Dec 2, 2019 at 10:21
  • First of all, do you know how the file was encoded? Commented Dec 2, 2019 at 11:02
  • @AdamStrauss: Unfortunately no Same output like in the input file. @sophros: No, I don`t know. But maybe this information helps: Last-Modified: Mon, 02 Dec 2019 07:46:05 Content-Length: 122092 Content-Type: application/octet-stream Connection: Closed Commented Dec 2, 2019 at 11:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.