-
Notifications
You must be signed in to change notification settings - Fork 0
/
mystery-char-devices.sh
executable file
·89 lines (80 loc) · 1.92 KB
/
mystery-char-devices.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
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
84
85
86
87
88
89
#!/bin/bash
# Uncover mysterious character devices
# Based on https://www.kernel.org/doc/Documentation/admin-guide/devices.txt
[[ $(uname) != "Linux" ]] && exit 0
declare -A expected_major=(
[1]="memory"
[2]="pty master"
[3]="pty slave"
[4]="tty"
[5]="alt tty"
[6]="parallel"
[7]="vcs"
# [8]="scsi tape"
[9]="md"
[10]="misc"
[13]="input"
[21]="scsi"
[29]="fb"
[81]="v4l"
[180]="usb"
[90]="memorydev"
[108]="ppp"
[116]="alsa"
[189]="usb serial"
[202]="msr"
[203]="cpu"
[204]="ttyAMA"
[226]="dri"
[229]="hvc"
)
declare -A expected_low=(
["bsg/"]=1
["cec"]=1
["dma_heap/system"]=1
["drm_dp_aux"]=1
["gpiochip"]=1
["hidraw"]=1
["iio"]=1
["iiodevice"]=1
["media"]=1
["mei"]=1
["ngn"]=1
["nvme"]=1
["pps"]=1
["psp"]=1
["ptp"]=1
["rtc"]=1
["tpmrm"]=1
["usbmon"]=1
["vportp"]=1
["watchdog"]=1
)
declare -A expected_high=(
["drm_dp_aux"]=1
["media"]=1
["mei"]=1
)
for path in $(find /dev -type c); do
hex=$(stat -c '%t' $path)
major=$(( 16#${hex} ))
pattern=$(echo $path | cut -d/ -f3- | tr -d '[:0-9]')
# Unix98 PTY Slaves
(( major >= 136 && major <= 143 )) && continue
[[ ${expected_major[$major]} != "" ]] && continue
class="UNKNOWN"
(( major >= 60 && major <= 63 )) && class="LOCAL/EXPERIMENTAL"
(( major >= 120 && major <= 127 )) && class="LOCAL/EXPERIMENTAL"
if (( major >= 234 && major <= 254 )); then
class="low dynamic"
[[ ${expected_low[$pattern]} == 1 ]] && continue
fi
if (( major >= 384 && major <= 511 )); then
class="high dynamic"
[[ ${expected_high[$pattern]} == 1 ]] && continue
fi
echo "${class} major device ${pattern}[${major}]"
echo "* $(ls -lad $path)"
echo "* /proc/devices: $(sed -n '/Block devices:/q;p' /proc/devices | grep -e "^ *${major}")"
echo ""
done