I am using Python 3.10 and I am trying to read a Windows executable file, and output the binary data in a text format (1's and 0's) into a text file. I only require the binary, I do not want the offsets and the ASCII representation of the bytes. I do not want any spaces or new lines.
total = ""
with open("input.exe", "rb") as f:
while (byte := f.read(1)):
total = total + byte.decode("utf-8")
with open("output.txt", "w") as o:
o.write(total)
However, it is not working, I am presented with the following error.
Traceback (most recent call last):
File "converter.py", line 4, in <module>
total = total + byte.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 0: invalid start byte
A\0(letter A + NUL character), what would you expect in your text file?od?