Advertisement
TheYellowBush

c_binaries_functions_script

Apr 29th, 2025 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.93 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. BINNAME="$1"
  4. SRCPATH="${2:-./src}"
  5.  
  6. YW="\e[33m"
  7. RD="\e[31m"
  8. NC="\e[0m"
  9.  
  10. if [ -z "$BINNAME" ]; then
  11.   echo -e "${YW}This little script will print out all the functions that you defined in your code, but you're not using in the final binary (yes the static ones too)."
  12.   echo -e "If you have done the bonuses and compiled the mandatory binary, this will probably flag functions that you do use in the bonus part. Watch out for false-positives.${NC}\n"
  13.   echo -e "${RD}Usage: $0 <binary-name> [source-path]${NC}" >&2
  14.   exit 1
  15. fi
  16.  
  17. if [ ! -d "$SRCPATH" ]; then
  18.   echo -e "${RD}Source path \`${SRCPATH}\` not found. Run without arguments for usage.${NC}"
  19.   exit 1
  20. fi
  21.  
  22. comm -23 \
  23.   <(ctags -R --languages=C --c-kinds=f --fields=+n --output-format=json "$SRCPATH" |
  24.     jq -r 'select(._type == "tag" and .kind == "function") | .name' |
  25.     sort -u) \
  26.   <(nm -g "$BINNAME" 2>/dev/null |
  27.     awk '{ print $3 }' |
  28.     sort -u)
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement