-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffr
executable file
·159 lines (119 loc) · 5.39 KB
/
ffr
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
VER="0.1.3"
REQUIRED_PROGRAMS=("sed" "tr" "screen")
LINE="―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――"
CONN_ERR="Is your Flipper Zero connected via USB?"
PRESS_ANY_KEY="Press any key to continue..."
SCREEN_IDLE="16"
CONF_FILE="screen.conf"
CURRENT_TIME=$(date +"%Y-%m-%d_%H-%M")
OUTPUT_FILE="random.$CURRENT_TIME"
OUTPUT_FILE_IR="$OUTPUT_FILE.ir"
OUTPUT_FILE_TXT="$OUTPUT_FILE.txt"
USAGE="Usage: $0 <NUMBER>\nWhere NUMBER is the desired duration of the experiment in seconds."
#================================================================================================
# Check whether the user provided duration of the experiment
#================================================================================================
if [ -n "$1" ]; then
# Check for numeric
if [[ "$1" =~ ^[0-9]+$ ]]; then
SCREEN_IDLE=$1
else
echo -e $USAGE
exit 1
fi
fi
#================================================================================================
# Check whether all the needed programs are present
#================================================================================================
# Function to check if a program is installed
check_program() {
command -v "$1" &>/dev/null
}
# Array for missing programs
missing_programs=()
# Check whether programs are installed...
for program in "${REQUIRED_PROGRAMS[@]}"; do
if ! check_program "$program"; then
missing_programs+=("$program")
fi
done
# Some programs not found, meh... quit.
if [ ${#missing_programs[@]} -gt 0 ]; then
echo "Oops... The following programs are missing on your machine: ${missing_programs[*]}"
echo "Please install them using your package manager, e.g.:"
echo "sudo apt update && sudo apt install ${missing_programs[*]}"
exit 1
fi
#================================================================================================
# Welcome splash
#================================================================================================
echo -e "flipper-fire-rng v$VER"
echo -e "\n$LINE"
echo -e " [🔥] C0113CT TRU3 R4ND0MN3SS 0F TH3 CH40S [🔥]"
echo -e "$LINE\n"
echo -e " ⚠️ Make sure qFlipper is not running\n"
echo -e " You'll need:"
echo -e " \t- Your Flipper Zero (connected via USB)"
echo -e " \t- A lighter\n"
echo -e " $PRESS_ANY_KEY"
read -n 1
#================================================================================================
# Make sure Flipper Zero is connected
#================================================================================================
# Device directory path
DIR="/dev/serial/by-id/"
# Check if the device directory exists (if not, Flipper is definitely not attached)
if [ ! -d "$DIR" ]; then
echo "Error: Directory $DIR does not exist."
echo $CONN_ERR
exit 1
fi
# Search for a Filler device (name starts with "usb-Flipper_Devices_Inc")
DEVICE=$(ls "$DIR" | grep -m 1 "^usb-Flipper_Devices_Inc")
# Check if a matching device was found
if [ -z "$DEVICE" ]; then
echo "Error: No Flipper device found ('usb-Flipper_Devices_Inc......')."
echo $CONN_ERR
exit 1
fi
# Did we find the Flipper?
# echo " Flipper Zero device found .... $DEVICE"
DEVICE=$DIR$DEVICE
#================================================================================================
# Show instructions
#================================================================================================
echo -e "$LINE\n"
echo -e " On the next screen you'll be connected to the Flipper."
echo -e " When you see an empty screen, start flicking your lighter "
echo -e " one hand away from the Flipper's IR receiver.\n\n"
echo -e " ⚠️ \033[31;1;4mKeep a sane distance between the lighter and the Flipper!\033[0m\n"
echo -e " ⚠️ \e[4mRemember!\e[0m Only you are responsible for any potential damage!\n\n"
echo -e " The infrared radiation of the sparks and flame will become"
echo -e " digitised RANDOMNESS. You have $SCREEN_IDLE seconds for flicking.\n"
echo -e " $PRESS_ANY_KEY"
read -n 1
#================================================================================================
# Write configuration file for `screen`
#================================================================================================
echo -e "screen $DEVICE 230400" > $CONF_FILE
echo -e "reset" >> $CONF_FILE
echo -e "idle $SCREEN_IDLE quit" >> $CONF_FILE
echo -e "logfile $OUTPUT_FILE_IR" >> $CONF_FILE
echo -e "log on" >> $CONF_FILE
echo stuff '"ir rx raw\r"' >> $CONF_FILE
#================================================================================================
# Capture randomness
#================================================================================================
screen -c $CONF_FILE
#================================================================================================
# Process the data, clean up, and display the result
#================================================================================================
# Remove "RAW <number> sample". Filter out all non-digits. Remove new lines.
sed '/RAW, [0-9]\+ sample/d' < $OUTPUT_FILE_IR | sed 's/[^0-9]//g' | tr -d '\n' > $OUTPUT_FILE_TXT
echo -e "$LINE"
echo -e " Result saved to $OUTPUT_FILE_TXT"
echo -e "$LINE"
cat $OUTPUT_FILE_TXT
echo -e "\n$LINE\n"
unlink $OUTPUT_FILE_IR