<commit_before>#!/bin/bash

if [[ "$1" == "" ]]
then
        echo ""
        echo " Usage: iOSBinaryAnalyzer.sh <binary>"
        echo ""
        exit 1
fi

echo '   _ ____  ____  ___  _                      ___             __                '
echo '  (_) __ \/ __/ / _ )(_)__  ___  ______ __  / _ | ___  ___ _/ /_ _____ ___ ____'
echo ' / / /_/ /\ \  / _  / / _ \/ _ `/ __/ // / / __ |/ _ \/ _ `/ / // (_-</ -_) __/'
echo '/_/\____/___/ /____/_/_//_/\_,_/_/  \_, / /_/ |_/_//_/\_,_/_/\_, /___/\__/_/   '
echo '                                   /___/                    /___/              '

echo ""
echo "==[ Target ]==================================================================="
echo ""
echo " $1"

entitlements=$(sed -n "/<dict>/,/<\/dict>/p" "$1" | sed -n "/<array>/,/<\/array>/p" | grep string | cut -d">" -f2 | cut -d"<" -f1 | sort -u)

echo ""
echo "==[ Entitlements ]============================================================="
echo ""
echo " $entitlements"

echo ""
echo "==[ Binary Analysis Results ]=================================================="

hds_n=$(otool -hV "$1" | grep -c "Mach header")

if [[ $hds_n -gt 1 ]]
then
        archs=$(otool -hV "$1" | grep architecture | cut -d"(" -f2 | cut -d" " -f2 | sed 's/)://')
        echo ""
        echo " This is a Fat binary with $hds_n architectures:" $archs
else
        archs="all"
fi

details=""

for a in $archs
do
        if [[ $hds_n -gt 1 ]]
        then
                echo ""
                echo "@ $a"
        fi

        echo ""

        encrypt=$(otool -l -arch $a "$1" | grep cryptid)

        if [[ "$(echo $encrypt | sed 's/ //g')" == "cryptid1" ]]
        then
                echo " Encrypted?                                    Yes"
        else
                echo " Encrypted?                                    No"
        fi
        
        pie=$(otool -hV -arch $a "$1" | grep PIE)

        if [[ "$pie" == "" ]]
        then
                echo " PIE enabled?                                  No"
        else
                echo " PIE enabled?                                  Yes"
        fi

        canaries=$(otool -IV -arch $a "$1" | grep stack)

        if [[ "$canaries" == "" ]]
        then
                echo " Stack Smashing Protection enabled?            No"
        else
                echo " Stack Smashing Protection enabled?            Yes"
        fi

        arc=$(otool -IV -arch $a "$1" | grep _objc_release)

        if [[ "$arc" == "" ]]
        then
                echo " Automatic Reference Counting (ARC) enabled?   No"
        else
                echo " Automatic Reference Counting (ARC) enabled?   Yes"
        fi

        details="$details otool -l -arch $a '$1' | grep cryptid\n$encrypt\n otool -hV -arch $a '$1' | grep PIE\n$pie\n otool -IV -arch $a '$1' | grep stack\n$canaries\n otool -IV -arch $a '$1' | grep _objc_release\n$arc\n"
done

echo ""
echo "==[ Details ]=================================================================="
echo ""
echo -e "$details"
<commit_msg>some checks<commit_after>#!/bin/bash

if [[ "$1" == "" ]]
then
        echo " Usage: iOSBinaryAnalyzer.sh <binary>"
        exit 1
fi

if [[ ! -f "$1" ]]
then
        echo " Error: file does not exist"
        exit 1
fi

type otool &>/dev/null

if [[ "$?" -ne "0" ]]
then
        echo " Error: otool is not installed. Using Cydia, otool can be found in the following package: Darwin CC Tools"
        exit 1
fi

echo '   _ ____  ____  ___  _                      ___             __                '
echo '  (_) __ \/ __/ / _ )(_)__  ___ _______ __  / _ | ___  ___ _/ /_ _____ ___ ____'
echo ' / / /_/ /\ \  / _  / / _ \/ _ `/ __/ // / / __ |/ _ \/ _ `/ / // /_ // -_) __/'
echo '/_/\____/___/ /____/_/_//_/\_,_/_/  \_, / /_/ |_/_//_/\_,_/_/\_, //__/\__/_/   '
echo '                                   /___/                    /___/              '

echo ""
echo "==[ Target ]==================================================================="
echo ""
echo " $1"

entitlements=$(sed -n "/<dict>/,/<\/dict>/p" "$1" | sed -n "/<array>/,/<\/array>/p" | grep string | cut -d">" -f2 | cut -d"<" -f1 | sort -u)

echo ""
echo "==[ Entitlements ]============================================================="
echo ""
echo " $entitlements"

echo ""
echo "==[ Binary Analysis Results ]=================================================="

hds_n=$(otool -hV "$1" | grep -c "Mach header")

if [[ $hds_n -gt 1 ]]
then
        archs=$(otool -hV "$1" | grep architecture | cut -d"(" -f2 | cut -d" " -f2 | sed 's/)://')
        echo ""
        echo " This is a Fat binary with $hds_n architectures:" $archs
else
        archs="all"
fi

details=""

for a in $archs
do
        if [[ $hds_n -gt 1 ]]
        then
                echo ""
                echo "@ $a"
        fi

        echo ""

        encrypt=$(otool -l -arch $a "$1" | grep cryptid)

        if [[ "$(echo $encrypt | sed 's/ //g')" == "cryptid1" ]]
        then
                echo " Encrypted?                                    Yes"
        else
                echo " Encrypted?                                    No"
        fi
        
        pie=$(otool -hV -arch $a "$1" | grep PIE)

        if [[ "$pie" == "" ]]
        then
                echo " PIE enabled?                                  No"
        else
                echo " PIE enabled?                                  Yes"
        fi

        canaries=$(otool -IV -arch $a "$1" | grep stack)

        if [[ "$canaries" == "" ]]
        then
                echo " Stack Smashing Protection enabled?            No"
        else
                echo " Stack Smashing Protection enabled?            Yes"
        fi

        arc=$(otool -IV -arch $a "$1" | grep _objc_release)

        if [[ "$arc" == "" ]]
        then
                echo " Automatic Reference Counting (ARC) enabled?   No"
        else
                echo " Automatic Reference Counting (ARC) enabled?   Yes"
        fi

        details="$details otool -l -arch $a '$1' | grep cryptid\n$encrypt\n otool -hV -arch $a '$1' | grep PIE\n$pie\n otool -IV -arch $a '$1' | grep stack\n$canaries\n otool -IV -arch $a '$1' | grep _objc_release\n$arc\n"
done

echo ""
echo "==[ Details ]=================================================================="
echo ""
echo -e "$details"

{'fraction_non_alphanumeric': 0.23148000637247093, 'fraction_numerical': 0.007328341564441612, 'mean_word_length': 1.418335901386749, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2056257', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1936, 'n_words': 515}