Created
June 29, 2015 15:58
-
-
Save berdario/114b2daf9b43fe924676 to your computer and use it in GitHub Desktop.
the "strings" command implemented in Python
This file contains 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
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
Line 11, Column 25 '(sys.argv[1])'