summaryrefslogtreecommitdiffhomepage
path: root/project/w32def/w32def.sh
blob: 3fca7c30665d4915f84b2cd380d7a10644eae124 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh

usage()
{
cat << EOF >&2

Usage:
  -h            show this HELP message
  -p  PERK      set pe parser utility
  -o  OUTPUT    set output file name
  -l  SYSLIB    set system library from which to extract symbols

EOF
exit 1
}


# one
perk=
caps=

workdir=$(pwd)
output=
syslib=


while getopts "hp:o:l:c" opt; do
	case $opt in
	h)
  		usage
		;;
	p)
    		perk="$OPTARG"
		;;
	o)
    		output="$OPTARG"
		;;
	l)
    		syslib="$OPTARG"
		;;
	c)
		caps='yes'
		;;
	\?)
    		printf "$0: Invalid option: -%s" "$OPTARG" >&2
    		usage
		;;
	esac
done


# two
if [ -z "$perk" ] || [ -z "$output" ] || [ -z "$syslib" ]; then
	usage
fi

tmpdef=`mktemp`

if [ -z "$tmpdef" ]; then
	printf "$0: Failed to create a temporary file!" >&2
	exit 1
fi

# three
if [ -z "$caps" ]; then
	"$perk" -e "$syslib"                   > "$tmpdef" || exit 1
else
	"$perk" -e "$syslib" | grep -e '[A-Z]' > "$tmpdef" || exit 1
fi

# four
grep -v                                      \
		-e 'DllMain'                 \
		-e 'DllCanUnloadNow'         \
		-e 'DllDebugObjectRPCHook'   \
		-e 'DllGetClassObject'       \
		-e 'DllRegisterServer'       \
		-e 'DllUnregisterServer'     \
		-e '?'                       \
	"$tmpdef" > "$output" || exit 1

# all done
exit 0