Skip to content

Instantly share code, notes, and snippets.

@iTrooz
Created May 25, 2024 00:16
Show Gist options
  • Save iTrooz/740f00f0935e365534f5a76dab0e7738 to your computer and use it in GitHub Desktop.
Save iTrooz/740f00f0935e365534f5a76dab0e7738 to your computer and use it in GitHub Desktop.
Print the size of sections in a ELF object file/binary
#!/bin/sh
# Print the size of sections in a ELF object file/binary. Thx ChatGPT
size -A -d $1 | awk 'NR > 2 {print $2, $1}' | sort -n | awk '{
size=$1;
if (size >= 1024*1024*1024) {
printf "%7.2f GB %-20s\n", size / (1024*1024*1024), $2;
} else if (size >= 1024*1024) {
printf "%7.2f MB %-20s\n", size / (1024*1024), $2;
} else if (size >= 1024) {
printf "%7.2f KB %-20s\n", size / 1024, $2;
} else {
printf "%7d B %-20s\n", size, $2;
}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment