#!/bin/bash

set -eu

SCRIPT_DIR=$(dirname $(realpath $0))
source ${SCRIPT_DIR}/helper

declare -a targets=(
    "Stack protected: yes"
    "Fortify Source functions: yes"
    "Read-only relocations: yes"
    "Immediate binding: yes"
)

info "Checking hardening ..."
options="--nobranchprotection --nocfprotection"
for binary in "${binaries[@]}"; do
    hardening-check ${options} ${binary} | tee hardening.log
    for target in "${targets[@]}"; do
        info "Checking whether '${target}' with ${binary}"
        if grep "${target}" hardening.log >/dev/null; then
            pass "${target}: ${binary}"
        else
            fail "Missing ${target}: ${binary}"
        fi
    done
    rm -f hardening.log
done
