This repository was archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcode.ino
More file actions
510 lines (462 loc) · 11 KB
/
code.ino
File metadata and controls
510 lines (462 loc) · 11 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RCSwitch.h>
#include <Encoder.h>
/*
* Pinout
* -------------------------------------------------------
* -------------------------------------------------------
* Receiver D5
* Transmitter D6
* Jammer D8
*
* SCL D3
* SDA D4
*
* CLK D1
* DT D2
* SW D7
*
*/
Adafruit_SSD1306 display(-1);
Encoder encoder(D1, D2);
RCSwitch receiver = RCSwitch();
RCSwitch transmitter = RCSwitch();
RCSwitch jammer = RCSwitch();
long oldPosition = -999;
boolean isButtonPressed = false;
long lastUpdateMillis = 0;
#define menuLength 5
String menuOptions[] = {"||Wmk433||", "Jammer", "Sniffer", "Spoofer", "Hacker", "Transmit"};
int menuPosition = 0;
void handleKey()
{
isButtonPressed = true;
}
void printLine(String message, int line, bool inverted)
{
display.setTextSize(2);
if (!inverted)
display.setTextColor(WHITE);
else
display.setTextColor(BLACK, WHITE);
display.setCursor(0, 20 * line + 4);
display.println(message);
}
void displayMenu()
{
display.clearDisplay();
display.display();
if (menuPosition == 0)
{
printLine(menuOptions[0], 0, false);
printLine(menuOptions[1], 1, false);
printLine(menuOptions[2], 2, false);
}
else if (menuPosition == menuLength)
{
printLine(menuOptions[menuLength - 2], 0, false);
printLine(menuOptions[menuLength - 1], 1, false);
printLine(menuOptions[menuLength], 2, true);
}
else
{
printLine(menuOptions[menuPosition - 1], 0, false);
printLine(menuOptions[menuPosition], 1, true);
printLine(menuOptions[menuPosition + 1], 2, false);
}
display.display();
}
//return true if button is pressed and return the main-menu
bool exitOption()
{
if (isButtonPressed)
{
delay(10);
isButtonPressed = false;
displayMenu();
return true;
}
return false;
}
void initJammer()
{
//Init Display
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Jammer");
display.setTextSize(2);
display.setTextColor(BLACK, WHITE);
display.setCursor(115, 0);
display.println("X");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 25);
display.println("Jamming ...");
display.display();
//Start jamming
while (!exitOption())
{
delay(30);
}
}
//Display the Sniffer Headline on the Display
void displaySniffer()
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Sniffer");
display.setTextSize(2);
display.setTextColor(BLACK, WHITE);
display.setCursor(115, 0);
display.println("X");
display.display();
}
void initSniffer()
{
displaySniffer();
//Receiving and displaying data in this loop
while (!exitOption())
{
if (receiver.available())
{
display.clearDisplay();
displaySniffer();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 22);
display.println(receiver.getReceivedValue());
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 42);
display.println(receiver.getReceivedBitlength());
display.setCursor(12, 42);
display.println("bit");
display.setCursor(40, 42);
display.println(receiver.getReceivedDelay());
display.setCursor(58, 42);
display.println("us");
display.display();
receiver.resetAvailable();
}
delay(5);
}
}
void spoofer()
{
//Received Signal is stored here
long receivedValue = 0;
int receivedBitlength = 0;
int receivedDelay = 0;
int receivedProtocol = 0;
//Init Display
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Spoofer");
display.setTextSize(2);
display.setTextColor(BLACK, WHITE);
display.setCursor(115, 0);
display.println("X");
display.display();
//Listen for signals
receiver.resetAvailable();
bool scanning = true;
bool transmitting = false;
while (scanning)
{
if (receiver.available())
{
receivedValue = receiver.getReceivedValue();
receivedBitlength = receiver.getReceivedBitlength();
receivedDelay = receiver.getReceivedDelay();
receivedProtocol = receiver.getReceivedProtocol();
receiver.resetAvailable();
scanning = false;
//Signal is received and stored
}
if (isButtonPressed) //Abort Sacanning
{
delay(30);
isButtonPressed = false;
displayMenu();
return;
}
delay(10);
}
//Display Signal
int selectedOption = 0;
bool update = true;
while (!scanning)
{
long newPosition = encoder.read(); //Handle menu ooptions
if (newPosition != oldPosition)
{
if ((newPosition % 4 == 0) && ((newPosition - oldPosition) > 0))
{
if (selectedOption < 2)
{
selectedOption += 1;
update = true;
}
else
selectedOption = 0;
}
else if ((newPosition % 4 == 0) && ((newPosition - oldPosition) < 0))
{
if (selectedOption > 0)
{
selectedOption -= 1;
update = true;
}
else
selectedOption = 2;
}
oldPosition = newPosition;
}
if (update) //Display Signal
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 7);
display.println(receivedValue);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 27);
display.println(receivedBitlength);
display.setCursor(12, 27);
display.println("bit");
display.setCursor(40, 27);
display.println(receivedDelay);
display.setCursor(58, 27);
display.println("us");
if (selectedOption == 0)
display.setTextColor(BLACK, WHITE);
else
display.setTextColor(WHITE);
display.setCursor(0, 50);
display.println("Send");
if (selectedOption == 1)
display.setTextColor(BLACK, WHITE);
else
display.setTextColor(WHITE);
display.setCursor(42, 50);
display.println("Search");
if (selectedOption == 2)
display.setTextColor(BLACK, WHITE);
else
display.setTextColor(WHITE);
display.setCursor(95, 50);
display.println("Exit");
display.display();
}
if (isButtonPressed)
{
isButtonPressed = false;
scanning = true;
delay(30);
if (selectedOption == 0)
transmitting = true;
if (selectedOption == 1)
spoofer();
if (selectedOption == 2)
{
displayMenu();
}
}
delay(10);
}
//Transnmit signal
if (transmitting)
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 15);
display.println("Transmitting ...");
display.display();
while (!exitOption())
{
jammer.setPulseLength(receivedDelay);
jammer.setProtocol(receivedProtocol);
delay(50);
}
}
displayMenu();
}
void initHacker() //brute-force attack
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Hacker");
display.setTextSize(2);
display.setTextColor(BLACK, WHITE);
display.setCursor(115, 0);
display.println("X");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 25);
display.println("Hacking...");
display.display();
jammer.setRepeatTransmit(2);
int bitlength = 8;
int maxlength = 256; //2^8
for (int i = 0; i <= maxlength; i++)
{
delay(10);
Serial.println(i);
if (exitOption())
break;
}
displayMenu();
}
int readSerialInt()
{
int value = 0;
while (!exitOption())
{
while (Serial.available())
{
char inChar = (char)Serial.read();
if ((inChar >= '0') && (inChar <= '9'))
{
Serial.print(inChar);
value = value * 10 + inChar - '0';
}
if (inChar == '\n')
{
return value;
}
}
}
return 0;
}
void initTransmit()
{
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Transmit");
display.setTextSize(2);
display.setTextColor(BLACK, WHITE);
display.setCursor(115, 0);
display.println("X");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 25);
display.println("Connect your PC and open the Serial Monitor!");
display.display();
Serial.println("Welcome to the wmk433");
Serial.println("Please enter the binary code");
unsigned long code = 0;
int pulseLength = 0;
int protocol = 0;
int bitlength = 0;
Serial.println("\nCode in dezimal: ");
code = readSerialInt();
if (!(code))
return;
Serial.println("\nNumber of bits: ");
bitlength = readSerialInt();
if (!(bitlength))
return;
Serial.println("\nDelay per bit: ");
pulseLength = readSerialInt();
if (!(pulseLength))
return;
Serial.println("\nProtocol: ");
protocol = readSerialInt();
if (!(protocol))
return;
jammer.setProtocol(protocol);
jammer.setPulseLength(pulseLength);
jammer.setRepeatTransmit(60);
Serial.println("\nTransmitting ...");
}
void setup()
{
Wire.begin(D4, D3); //Init communications standards
Serial.begin(9600);
jammer.enableTransmit(D8); //Init 433MHz equipment
transmitter.enableTransmit(D6);
receiver.enableReceive(D5);
pinMode(D7, INPUT_PULLUP); //Init Encoder
attachInterrupt(D7, handleKey, RISING);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Init Display with the I2C addr 0x3C (128x64) //SSD1306_SWITCHCAPVCC
display.clearDisplay();
display.display();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("@code_byter");
display.display();
display.setTextSize(1);
display.setTextColor(BLACK, WHITE);
display.setCursor(0, 8);
display.println("@code_byter");
display.display();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 24);
display.println("@code_byter");
display.display();
Serial.println("RF-Hacker connected ...");
displayMenu();
}
void loop()
{
long newPosition = encoder.read();
if (newPosition != oldPosition)
{
if ((newPosition % 4 == 0) && ((newPosition - oldPosition) > 0))
{
if (menuPosition < menuLength)
menuPosition += 1;
displayMenu();
}
else if ((newPosition % 4 == 0) && ((newPosition - oldPosition) < 0))
{
if (menuPosition > 0)
menuPosition -= 1;
displayMenu();
}
oldPosition = newPosition;
}
if (isButtonPressed)
{
isButtonPressed = false;
delay(30);
if (menuPosition == 2)
{
initSniffer();
}
else if (menuPosition == 1)
{
initJammer();
}
else if (menuPosition == 3)
{
spoofer();
}
else if (menuPosition == 4)
{
initHacker();
}
else if (menuPosition == 5)
{
initTransmit();
}
}
}