Skip to content

Instantly share code, notes, and snippets.

@Daniel-Abrecht
Created November 21, 2025 21:44
Show Gist options
  • Select an option

  • Save Daniel-Abrecht/e5758e093c5375272a31f619c1d1fd0c to your computer and use it in GitHub Desktop.

Select an option

Save Daniel-Abrecht/e5758e093c5375272a31f619c1d1fd0c to your computer and use it in GitHub Desktop.
edkguidgrep
#!/bin/bash
SOURCES=( "$@" )
find_c(){
grep --exclude-dir='.*' --exclude='.*' -rh '#define.*_GUID ' -A 6 "${SOURCES[@]}" |
sed 's/^--$\| *#define */\x01/g' |
tr -d '\n\r\\' |
tr '\1' '\n' |
sed 's /\*.*\?\*/ g' |
sed -n 's/\([^}]*{[^}]*{[^}]*}[^}]*}\).*/\1/p'
echo
}
find_dec(){
grep --include="*.dec" --exclude-dir='.*' --exclude='.*' -rh 'g.*Guid *= ' "${SOURCES[@]}" |
sed 's/#.*//' |
while read -r name _ guid
do
name="$(sed 's/[A-Z]/_\0/g;s/.*/\U\0/;s/^G_//' <<<"$name")"
echo "$name" "$guid"
done
}
find_guids(){
find_c
find_dec
}
c2guid(){
while read -r name guid
do
if [ -z "$name" ]; then continue; fi
guid2="$(echo "${guid}" | sed 's/[^0-9a-fA-FxX]\+/ /g')"
read a b c x0 x1 x2 x3 x4 x5 x6 x7 <<<"$guid2"
printf "$name %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n" "$a" "$b" "$c" "$x0" "$x1" "$x2" "$x3" "$x4" "$x5" "$x6" "$x7"
if [ "$?" != 0 ]
then echo "Failed to process input: $name $guid" >&2
fi
done
}
format(){
awk '{ print $1 " = {" $2 "}"; }'
}
entries="$(find_guids | c2guid)"
declare -A known_guid
declare -A known_name
while read -r name guid
do
if [ -n "${known_guid["$guid"]}" ]
then continue;
fi
if [ -n "${known_name["$name"]}" ]
then
printf "Multiple GUIDs found for $name: $guid ${known_name["$name"]}" >&2
i=1
while true
do
i=$((i + 1))
if [ -z "${known_name["${name}_$i"]}" ]
then break;
fi
printf " %s" "${known_name["${name}_$i"]}" >&2
done
echo >&2
name="${name}_$i"
fi
known_guid["$guid"]="$name"
known_name["$name"]="$guid"
done <<<"$entries"
for guid in "${!known_guid[@]}"
do
echo "${known_guid[$guid]}" "$guid"
done | format | column -t | sort -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment