Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def has_string(stream, byteary):
- """Quick function to check if a stream contains a byteary"""
- if isinstance(byteary, str):
- byteary = byteary.encode('utf-8')
- import io
- buf_len = len(byteary)
- suffixes = [
- byteary[-i:]
- for i in range(3, buf_len)
- ]
- whole = io.BytesIO()
- while True:
- r = stream.read(buf_len*32)
- if not r:
- break
- whole.write(r)
- if any(suf in r for suf in suffixes):
- if byteary in whole.getvalue():
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement