Skip to content

Commit

Permalink
Improve performance of API usage analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
crasowas committed Dec 31, 2024
1 parent 68727a0 commit 35169ef
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions fixer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,33 +174,35 @@ function get_dependency_name() {
function analyze_binary_file() {
local file_path="$1"
local -a results=()


# Check if the API symbol exists in the binary file using `nm` and `strings`
local nm_output=$(nm "$file_path" 2>/dev/null | xcrun swift-demangle)
local strings_output=$(strings "$file_path")
local combined_output="$nm_output"$'\n'"$strings_output"

for api_symbol in "${API_SYMBOLS[@]}"; do
local substrings=($(split_string_by_delimiter "$api_symbol"))
local category=${substrings[0]}
local api=${substrings[1]}

# Check if the API symbol exists in the binary file using `nm` and `strings`
for tool in "nm \"$file_path\" 2>/dev/null | xcrun swift-demangle" "strings \"$file_path\""; do
if eval "$tool | grep -E \"$api\$\" >/dev/null"; then
local index=-1
for ((i=0; i < ${#results[@]}; i++)); do
local result="${results[i]}"
local result_substrings=($(split_string_by_delimiter "$result"))
# If the category matches an existing result, update it
if [ "$category" == "${result_substrings[0]}" ]; then
index=i
results[i]="${result_substrings[0]}$DELIMITER${result_substrings[1]},$api$DELIMITER${result_substrings[2]}"
break
fi
done

# If no matching category found, add a new result
if [[ $index -eq -1 ]]; then
results+=("$category$DELIMITER$api$DELIMITER$(encode_path "$file_path")")

if echo "$combined_output" | grep -E "$api\$" >/dev/null; then
local index=-1
for ((i=0; i < ${#results[@]}; i++)); do
local result="${results[i]}"
local result_substrings=($(split_string_by_delimiter "$result"))
# If the category matches an existing result, update it
if [ "$category" == "${result_substrings[0]}" ]; then
index=i
results[i]="${result_substrings[0]}$DELIMITER${result_substrings[1]},$api$DELIMITER${result_substrings[2]}"
break
fi
done

# If no matching category found, add a new result
if [[ $index -eq -1 ]]; then
results+=("$category$DELIMITER$api$DELIMITER$(encode_path "$file_path")")
fi
done
fi
done

echo "${results[@]}"
Expand Down Expand Up @@ -480,12 +482,16 @@ function generate_report() {
echo ""
}

start_time=$(date +%s)

generate_report true
fix_frameworks
fix_app
generate_report false

echo "🎉 All fixed!"
end_time=$(date +%s)

echo "🎉 All fixed! ⏰ $((end_time - start_time)) seconds"
echo "🌟 If you found this script helpful, please consider giving it a star on GitHub. Your support is appreciated. Thank you!"
echo "🔗 Homepage: https://github.com/crasowas/app_privacy_manifest_fixer"
echo "🐛 Report issues: https://github.com/crasowas/app_privacy_manifest_fixer/issues"

0 comments on commit 35169ef

Please sign in to comment.