-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-ntnative.sh
38 lines (36 loc) · 1.13 KB
/
check-ntnative.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
FNAME="ntnative.h"
declare -a FCTNAMES=()
while read -r fctname; do
# echo "$fctname"
NO_T=${fctname%_t}
FCTNAMES+=("$NO_T")
COUNTX=$(grep -v "^#" "$FNAME"|grep -cP "$NO_T\\W")
COUNTY=$(grep -v "^#" "$FNAME"|grep -cP "$fctname\\W")
if ((COUNTX == 1)) && ((COUNTY == 1)); then
: # "balanced"
elif ((COUNTX == 0)) && ((COUNTY == 1)); then
if ! grep -P "$fctname\\W" "$FNAME"|grep -q '// winternl\.h'; then
printf "Type found, but not marked as winternl.h: %s exists %d/%d times\n" "$NO_T" "$COUNTX" "$COUNTY"
else
: # winternl.h-declared function for which we only declare the type!
fi
else
printf "UNICORN: %s exists %d/%d times\n" "$NO_T" "$COUNTX" "$COUNTY"
fi
done < <(set -x; grep -P 'typedef\s+?\w+?\s*?\(NTAPI\s*?\*\s*?(?:Rtl|Nt|Ldr)\w+?_t(?!>\))' "$FNAME"|grep -Po '(?:Rtl|Nt|Ldr)\w+?_t(?!>\))'|sort -u)
for fct in "${FCTNAMES[@]}"; do
case "$fct" in
Nt*)
printf "#define %s %s\n" "Zw${fct#Nt}" "$fct"
;;
esac
done
test -d "ntdll-stubs" || mkdir "ntdll-stubs"
(
echo -e "LIBRARY ntdll.dll\n"
echo "EXPORTS"
for fct in "${FCTNAMES[@]}"; do
echo " $fct"
done
) > "ntdll-stubs/ntdll.def"