For a research project, I need to hash the "executable footprint" of an application. I don't have an expansive knowledge-base on this particular area.
I've tried cat bash
for example, and stdout prints gobbledygook.
How can I read an executable as normal ones and zeroes?
Asked
Active
Viewed 211 times
-1

Dolphiniac
- 1,632
- 1
- 9
- 9
-
An executable doesn't contain "normal ones and zeroes" (which is called `binary`, BTW). You have to read individual bytes (8 bits on modern OSes) and convert them to a binary representation for human eyes. An executable isn't "readable" like a book or a text file. – Ken White Mar 29 '13 at 02:22
-
Take a look at `uuencode`, which might give you a more manageable representation (i.e. plain text) of your binary files. Of course, whether this is useful depends on what you mean by "executable footprint". – Matthew Strawbridge Mar 29 '13 at 08:57
1 Answers
1
If you want to get the binary representation as bits from a file you can use the following python script calling it using python to_binary.py name_of_file
import sys
def bin(x):
return "".join(x & (1 << i) and "1" or "0" for i in range(7,-1,-1))
file = open(sys.argv[1], "rb")
contents = file.read()
file.close()
for byte in contents:
sys.stdout.write(bin(ord(byte)))
sys.stdout.write("\n")

joamag
- 1,382
- 1
- 9
- 15
-
I tried your code, and it seems to work correctly, though I can't be sure, of course. Would I be correct in assuming that this script will return the same binary sequence each time it is run on the same file and that each executable will return a different one? – Dolphiniac Mar 29 '13 at 06:43
-
Yes, the code generates the bit stream for the file. For different file contents a different stream is generated. – joamag Mar 29 '13 at 14:56