File: common.py

package info (click to toggle)
aflplusplus 4.21c-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,496 kB
  • sloc: ansic: 110,361; cpp: 16,725; sh: 4,855; python: 3,793; makefile: 963; javascript: 515; java: 43; sql: 3; xml: 1
file content (40 lines) | stat: -rw-r--r-- 858 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# encoding: utf-8
"""
Module containing functions shared between multiple AFL modules

@author:     Christian Holler (:decoder)

@license:

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

@contact:    choller@mozilla.com
"""

from __future__ import print_function
import random
import os
import re


def randel(l):
    if not l:
        return None
    return l[random.randint(0, len(l) - 1)]


def randel_pop(l):
    if not l:
        return None
    return l.pop(random.randint(0, len(l) - 1))


def write_exc_example(data, exc):
    exc_name = re.sub(r"[^a-zA-Z0-9]", "_", repr(exc))

    if not os.path.exists(exc_name):
        with open(exc_name, "w") as f:
            f.write(data)