about summary refs log tree commit diff
path: root/utils/libtokencap/make_dict_v2.sh
blob: 1ddec06b4c4a1b47706fa9a4612c4bd553199ad6 (plain) (blame)
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
41
42
43
44
45
#help
usage() {
    echo "Usage: $0 -o <target_output> -b <target_bin> -p <LD_PRELOAD_PATH> [-t <timeout_sec>]"
    echo "Options:"
    echo "  -o  Path to target output directory"
    echo "  -b  Path to target program binary"
    echo "  -p  Path to LD_PRELOAD library"
    echo "  -t  Timeout in seconds"
    exit 1
}

#parse cli options
while getopts ":o:b:p:t:" opt; do
    case $opt in
        o) target_output="$OPTARG" ;;
        b) target_bin="$OPTARG" ;;
        p) LD_PRELOAD_PATH="$OPTARG" ;;
        t) timeout_sec="$OPTARG" ;;
        \?) echo "Invalid option: -$OPTARG" >&2; usage ;;
        :) echo "Option -$OPTARG requires an argument." >&2; usage ;;
    esac
done

#check options
if [ -z "$target_output" ] || [ -z "$target_bin" ] || [ -z "$LD_PRELOAD_PATH" ]; then
    echo "Error: Missing mandatory opts" >&2
    usage
fi

# initialize vars
AFL_TOKEN_FILE="${PWD}/temp_output.txt"
AFL_DICT_FILE="$(basename "$target_output").dict"

#generate token-file
{
    touch "$AFL_TOKEN_FILE"
    for i in $(find "$target_output" -type f -name "id*"); do
        LD_PRELOAD="$LD_PRELOAD_PATH" \
        timeout -s SIGKILL "$timeout_sec" \
        "$target_bin" "$i"
    done
} >"$AFL_TOKEN_FILE"

# sort & remove duplicates
sort -u "$AFL_TOKEN_FILE" >"$AFL_DICT_FILE"