| OLD | NEW |
| 1 #!/usr/bin/python2 | 1 #!/usr/bin/python2 |
| 2 # | 2 # |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Generate a dictionary for libFuzzer or AFL-based fuzzer. | 7 """Generate a dictionary for libFuzzer or AFL-based fuzzer. |
| 8 | 8 |
| 9 Invoked manually using a fuzzer binary and target format/protocol specification. | 9 Invoked manually using a fuzzer binary and target format/protocol specification. |
| 10 Works better for text formats or protocols. For binary ones may be useless. | 10 Works better for text formats or protocols. For binary ones may be useless. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 def DecodeHTML(html_data): | 30 def DecodeHTML(html_data): |
| 31 """HTML-decoding of the data.""" | 31 """HTML-decoding of the data.""" |
| 32 html_parser = HTMLParser.HTMLParser() | 32 html_parser = HTMLParser.HTMLParser() |
| 33 data = html_parser.unescape(html_data.decode('ascii', 'ignore')) | 33 data = html_parser.unescape(html_data.decode('ascii', 'ignore')) |
| 34 return data.encode('ascii', 'ignore') | 34 return data.encode('ascii', 'ignore') |
| 35 | 35 |
| 36 | 36 |
| 37 def EscapeDictionaryElement(element): | 37 def EscapeDictionaryElement(element): |
| 38 """Escape all unprintable and control characters in an element.""" | 38 """Escape all unprintable and control characters in an element.""" |
| 39 return element.encode('string_escape').replace('"', '\"') | 39 element_escaped = element.encode('string_escape') |
| 40 # Remove escaping for single quote because it breaks libFuzzer. |
| 41 element_escaped = element_escaped.replace('\\\'', '\'') |
| 42 # Add escaping for double quote. |
| 43 element_escaped = element_escaped.replace('"', '\\"') |
| 44 return element_escaped |
| 40 | 45 |
| 41 | 46 |
| 42 def ExtractWordsFromBinary(filepath, min_length=MIN_STRING_LENGTH): | 47 def ExtractWordsFromBinary(filepath, min_length=MIN_STRING_LENGTH): |
| 43 """Extract words (splitted strings) from a binary executable file.""" | 48 """Extract words (splitted strings) from a binary executable file.""" |
| 44 rodata = PreprocessAndReadRodata(filepath) | 49 rodata = PreprocessAndReadRodata(filepath) |
| 45 words = [] | 50 words = [] |
| 46 | 51 |
| 47 strings_re = re.compile(r'[^\x00-\x1F\x7F-\xFF]{%d,}' % min_length) | 52 strings_re = re.compile(r'[^\x00-\x1F\x7F-\xFF]{%d,}' % min_length) |
| 48 # Use different encodings for strings extraction. | 53 # Use different encodings for strings extraction. |
| 49 for encoding in ENCODING_TYPES: | 54 for encoding in ENCODING_TYPES: |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 'i - intersection, q - quoted, u - uppercase.') | 227 'i - intersection, q - quoted, u - uppercase.') |
| 223 args = parser.parse_args() | 228 args = parser.parse_args() |
| 224 | 229 |
| 225 dictionary = GenerateDictionary(args.fuzzer, args.spec, args.strategy, | 230 dictionary = GenerateDictionary(args.fuzzer, args.spec, args.strategy, |
| 226 is_html=bool(args.html)) | 231 is_html=bool(args.html)) |
| 227 WriteDictionary(args.out, dictionary) | 232 WriteDictionary(args.out, dictionary) |
| 228 | 233 |
| 229 | 234 |
| 230 if __name__ == '__main__': | 235 if __name__ == '__main__': |
| 231 main() | 236 main() |
| OLD | NEW |