Created
July 31, 2016 18:24
-
-
Save NanoDano/c32363cb1b991484596fca8ddf6e703f to your computer and use it in GitHub Desktop.
Find ASCII characters in a binary file with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find_ascii_in_binary.py - Identify ASCII characters in binary files | |
import sys | |
from functools import partial | |
chunk_size = 1 | |
with open(sys.argv[1], 'rb') as in_file: | |
for data in iter(partial(in_file.read, chunk_size), b''): | |
x = int.from_bytes(data, byteorder='big') | |
if (x > 64 and x < 91) or (x > 96 and x < 123) : | |
sys.stdout.write(chr(x)) | |
else: | |
sys.stdout.write('.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment