Yield Unicode strings (UTF-16-LE encoded ASCII) from a buf string of binary data. :param buf: A bytestring. :type buf: str :param n: The minimum length of strings to extract. :type n: int :rtype: Sequence[string]
(buf, n=3)
| 48 | |
| 49 | |
| 50 | def extract_unicode_strings(buf, n=3): |
| 51 | """ |
| 52 | Yield Unicode strings (UTF-16-LE encoded ASCII) from a buf string of binary data. |
| 53 | |
| 54 | :param buf: A bytestring. |
| 55 | :type buf: str |
| 56 | :param n: The minimum length of strings to extract. |
| 57 | :type n: int |
| 58 | :rtype: Sequence[string] |
| 59 | """ |
| 60 | if not buf: |
| 61 | return |
| 62 | |
| 63 | reg = b'((?:[%s]\x00){%d,})' % (ASCII_BYTE, n) |
| 64 | r = re.compile(reg) |
| 65 | for match in r.finditer(buf): |
| 66 | try: |
| 67 | yield match.group().decode('utf-16') |
| 68 | except UnicodeDecodeError: |
| 69 | pass |
| 70 | |
| 71 | |
| 72 | def extract_strings(buf, n=3): |
no test coverage detected