Skip to content

Instantly share code, notes, and snippets.

@berdario
Created Jun 29, 2015
Embed
What would you like to do?
the "strings" command implemented in Python
from mmap import mmap, PROT_READ
import re
import sys
def strings(fname, n=6):
with open(fname, 'rb') as f, mmap(f.fileno(), 0, prot=PROT_READ) as m:
for match in re.finditer(('([\w/]{%s}[\w/]*)' % n).encode(), m):
yield match.group(0)
if __name__ == '__main__':
for word in strings(sys.argv[1]):
print(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment