-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakegadget.sh
97 lines (80 loc) · 2.63 KB
/
makegadget.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
90
91
92
93
94
95
96
97
#! /bin/sh
# pick from storage hid tty
config="hid"
if ! test -z "$1"; then
config=$1
fi
echo "Enabling $config"
enabled() {
echo $config | grep -q $1
}
# fails on the busybox shell, wrong number of \\ ?
#descriptor=05010906a101050719e029e71500250175019508810295017508810395057501050819012905910295017503910395067508150025650507190029658100c0
#echo -n $descriptor | sed 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI' | xargs printf > my_report_desc
#set -e
# kill arduino stuff
kill $(ps |grep launcher |grep -v grep | cut '-d ' -f 3)
systemctl stop [email protected]
sleep 1
rmmod g_serial
mydir=$(pwd)
modprobe libcomposite
mkdir cfg
mount none cfg -t configfs
mkdir cfg/usb_gadget/g1
cd cfg/usb_gadget/g1
mkdir configs/c.1
#echo 0xa4a2 > idProduct # ether
#echo 0x0525 > idVendor # ether
#echo 0xa4ac > idProduct
#echo 0x0525 > idVendor
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
mkdir strings/0x409
mkdir configs/c.1/strings/0x409
echo serial > strings/0x409/serialnumber
echo manufacturer > strings/0x409/manufacturer
echo HID Gadget > strings/0x409/product
echo "Conf 1" > configs/c.1/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower
# HID keyboard
if enabled hid; then
mkdir functions/hid.usb0
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/report_length
cat $mydir/my_report_desc > functions/hid.usb0/report_desc
ln -s functions/hid.usb0 configs/c.1
fi
# SERIAL
if enabled tty; then
mkdir -p functions/acm.usb0
ln -s functions/acm.usb0 configs/c.1/
fi
#ETHERNET
#mkdir -p functions/ecm.usb0
# first byte of address must be even
#HOST="48:6f:73:74:50:43" # "HostPC"
#SELF="42:61:64:55:53:42" # "BadUSB"
#echo "48:6f:73:74:50:43" > functions/ecm.usb0/host_addr
#echo "42:61:64:55:53:42" > functions/ecm.usb0/dev_addr
#ln -s functions/ecm.usb0 configs/c.1/
#MASS STORAGE
if enabled storage; then
mkdir -p functions/mass_storage.usb0
echo 1 > functions/mass_storage.usb0/stall
echo 0 > functions/mass_storage.usb0/lun.0/cdrom
echo 0 > functions/mass_storage.usb0/lun.0/ro
echo 0 > functions/mass_storage.usb0/lun.0/nofua
echo /media/realroot/keyboard/massstorage > functions/mass_storage.usb0/lun.0/file
ln -s functions/mass_storage.usb0 configs/c.1/
fi
# ENABLE
echo 20980000.usb > UDC #/sys/class/udc
# hmm, can we do this now before connection?
systemctl enable [email protected]
systemctl start [email protected]
# Start
#./mapping.i586 /dev/input/by-id/*-kbd target.xmodmap fr.xmodmap /dev/hidg0
# Info: mounting the massstorage
# mount -o loop,offset=4096 /media/realroot/keyboard/massstorage /media/hkrconfig