Skip to content

Instantly share code, notes, and snippets.

@NanoDano
Created July 31, 2016 18:24
Show Gist options
  • Save NanoDano/c32363cb1b991484596fca8ddf6e703f to your computer and use it in GitHub Desktop.
Save NanoDano/c32363cb1b991484596fca8ddf6e703f to your computer and use it in GitHub Desktop.
Find ASCII characters in a binary file with Python
# 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