Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:3b5e1025cbd6, 2010-09-13 (annotated)
- Committer:
- iZsh
- Date:
- Mon Sep 13 22:19:39 2010 +0000
- Revision:
- 0:3b5e1025cbd6
Not tested IRL yet
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| iZsh | 0:3b5e1025cbd6 | 1 | /* Copyright (c) 2010 iZsh - izsh at fail0verflow.com |
| iZsh | 0:3b5e1025cbd6 | 2 | * |
| iZsh | 0:3b5e1025cbd6 | 3 | * This program is free software: you can redistribute it and/or modify |
| iZsh | 0:3b5e1025cbd6 | 4 | * it under the terms of the GNU General Public License as published by |
| iZsh | 0:3b5e1025cbd6 | 5 | * the Free Software Foundation, either version 3 of the License, or |
| iZsh | 0:3b5e1025cbd6 | 6 | * (at your option) any later version. |
| iZsh | 0:3b5e1025cbd6 | 7 | * |
| iZsh | 0:3b5e1025cbd6 | 8 | * This program is distributed in the hope that it will be useful, |
| iZsh | 0:3b5e1025cbd6 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| iZsh | 0:3b5e1025cbd6 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| iZsh | 0:3b5e1025cbd6 | 11 | * GNU General Public License for more details. |
| iZsh | 0:3b5e1025cbd6 | 12 | * |
| iZsh | 0:3b5e1025cbd6 | 13 | * You should have received a copy of the GNU General Public License |
| iZsh | 0:3b5e1025cbd6 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| iZsh | 0:3b5e1025cbd6 | 15 | */ |
| iZsh | 0:3b5e1025cbd6 | 16 | // Based on |
| iZsh | 0:3b5e1025cbd6 | 17 | // http://www.irongeek.com/i.php?page=security/barcode-flashing-led-fuzzer-bruteforcer-injector |
| iZsh | 0:3b5e1025cbd6 | 18 | |
| iZsh | 0:3b5e1025cbd6 | 19 | #include "mbed.h" |
| iZsh | 0:3b5e1025cbd6 | 20 | #include "BarcodeLED.h" |
| iZsh | 0:3b5e1025cbd6 | 21 | |
| iZsh | 0:3b5e1025cbd6 | 22 | typedef struct |
| iZsh | 0:3b5e1025cbd6 | 23 | { |
| iZsh | 0:3b5e1025cbd6 | 24 | const char * str; |
| iZsh | 0:3b5e1025cbd6 | 25 | const char * descr; |
| iZsh | 0:3b5e1025cbd6 | 26 | } str_t; |
| iZsh | 0:3b5e1025cbd6 | 27 | |
| iZsh | 0:3b5e1025cbd6 | 28 | void readline(char Buffer[], int Size) |
| iZsh | 0:3b5e1025cbd6 | 29 | { |
| iZsh | 0:3b5e1025cbd6 | 30 | int i = 0; |
| iZsh | 0:3b5e1025cbd6 | 31 | char c; |
| iZsh | 0:3b5e1025cbd6 | 32 | |
| iZsh | 0:3b5e1025cbd6 | 33 | while ((c = fgetc(stdin)) != '\r' && i < Size - 1) { |
| iZsh | 0:3b5e1025cbd6 | 34 | putc(c, stdout); |
| iZsh | 0:3b5e1025cbd6 | 35 | Buffer[i++] = c; |
| iZsh | 0:3b5e1025cbd6 | 36 | } |
| iZsh | 0:3b5e1025cbd6 | 37 | Buffer[i] = '\0'; |
| iZsh | 0:3b5e1025cbd6 | 38 | } |
| iZsh | 0:3b5e1025cbd6 | 39 | |
| iZsh | 0:3b5e1025cbd6 | 40 | void prompt(const str_t Barcodes[]) |
| iZsh | 0:3b5e1025cbd6 | 41 | { |
| iZsh | 0:3b5e1025cbd6 | 42 | printf("\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 43 | printf("=============\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 44 | printf("command list:\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 45 | printf("=============\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 46 | printf("code <39 | 128a | 128b | 128c>\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 47 | printf("preset <num>\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 48 | for (int i = 0; i < 6; ++i) |
| iZsh | 0:3b5e1025cbd6 | 49 | printf("\t%d: %s\r\n", i, Barcodes[i].descr); |
| iZsh | 0:3b5e1025cbd6 | 50 | printf("send <string>\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 51 | printf("> "); |
| iZsh | 0:3b5e1025cbd6 | 52 | } |
| iZsh | 0:3b5e1025cbd6 | 53 | |
| iZsh | 0:3b5e1025cbd6 | 54 | // Very primitive parsing... |
| iZsh | 0:3b5e1025cbd6 | 55 | void parse(const char Line[], const str_t Barcodes[], BarcodeLED & Barcode) |
| iZsh | 0:3b5e1025cbd6 | 56 | { |
| iZsh | 0:3b5e1025cbd6 | 57 | printf("\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 58 | if (!strcmp(Line, "code 39")) { |
| iZsh | 0:3b5e1025cbd6 | 59 | Barcode.SetCodetype(BarcodeLED::Code39); |
| iZsh | 0:3b5e1025cbd6 | 60 | printf("Setting barcode to Code39\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 61 | } else if (!strcmp(Line, "code 128a")) { |
| iZsh | 0:3b5e1025cbd6 | 62 | Barcode.SetCodetype(BarcodeLED::Code128a); |
| iZsh | 0:3b5e1025cbd6 | 63 | printf("Setting barcode to Code128a\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 64 | } else if (!strcmp(Line, "code 128b")) { |
| iZsh | 0:3b5e1025cbd6 | 65 | Barcode.SetCodetype(BarcodeLED::Code128b); |
| iZsh | 0:3b5e1025cbd6 | 66 | printf("Setting barcode to Code128b\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 67 | } else if (!strcmp(Line, "code 128c")) { |
| iZsh | 0:3b5e1025cbd6 | 68 | Barcode.SetCodetype(BarcodeLED::Code128c); |
| iZsh | 0:3b5e1025cbd6 | 69 | printf("Setting barcode to Code128c\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 70 | } else if (!strncmp(Line, "preset ", 7)) { |
| iZsh | 0:3b5e1025cbd6 | 71 | int num = -1; |
| iZsh | 0:3b5e1025cbd6 | 72 | sscanf(Line, "preset %d", &num); |
| iZsh | 0:3b5e1025cbd6 | 73 | if (num != -1 && num < 6) |
| iZsh | 0:3b5e1025cbd6 | 74 | Barcode.Emit(Barcodes[num].str); |
| iZsh | 0:3b5e1025cbd6 | 75 | else |
| iZsh | 0:3b5e1025cbd6 | 76 | printf("=> Unknown string ID!\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 77 | } else if (!strncmp(Line, "send ", 5)) { |
| iZsh | 0:3b5e1025cbd6 | 78 | Barcode.Emit(Line + 5); |
| iZsh | 0:3b5e1025cbd6 | 79 | } else { |
| iZsh | 0:3b5e1025cbd6 | 80 | printf("=> Command not found!\r\n"); |
| iZsh | 0:3b5e1025cbd6 | 81 | } |
| iZsh | 0:3b5e1025cbd6 | 82 | } |
| iZsh | 0:3b5e1025cbd6 | 83 | |
| iZsh | 0:3b5e1025cbd6 | 84 | int main() |
| iZsh | 0:3b5e1025cbd6 | 85 | { |
| iZsh | 0:3b5e1025cbd6 | 86 | BarcodeLED barcode(LED1, BarcodeLED::Code39); |
| iZsh | 0:3b5e1025cbd6 | 87 | DigitalOut led(LED4); |
| iZsh | 0:3b5e1025cbd6 | 88 | |
| iZsh | 0:3b5e1025cbd6 | 89 | str_t barcodes[] = { |
| iZsh | 0:3b5e1025cbd6 | 90 | {"0123456789", "numeric"}, |
| iZsh | 0:3b5e1025cbd6 | 91 | {"abc123", "simple alphanum"}, |
| iZsh | 0:3b5e1025cbd6 | 92 | {"<script>alert(\"Hello World!\")</script>", "XSS"}, |
| iZsh | 0:3b5e1025cbd6 | 93 | {"' or 1=1 -- ", "SQL injection"}, |
| iZsh | 0:3b5e1025cbd6 | 94 | {"X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*", "EICAR test string"}, |
| iZsh | 0:3b5e1025cbd6 | 95 | {"TRY TO PASTE v", "Ctrl-V in 128a"}, |
| iZsh | 0:3b5e1025cbd6 | 96 | }; |
| iZsh | 0:3b5e1025cbd6 | 97 | |
| iZsh | 0:3b5e1025cbd6 | 98 | barcode.SetVerbose(true); |
| iZsh | 0:3b5e1025cbd6 | 99 | |
| iZsh | 0:3b5e1025cbd6 | 100 | while(1) { |
| iZsh | 0:3b5e1025cbd6 | 101 | char buffer[512]; |
| iZsh | 0:3b5e1025cbd6 | 102 | memset(buffer, '\0', 512); |
| iZsh | 0:3b5e1025cbd6 | 103 | prompt(barcodes); |
| iZsh | 0:3b5e1025cbd6 | 104 | readline(buffer, 512); |
| iZsh | 0:3b5e1025cbd6 | 105 | parse(buffer, barcodes, barcode); |
| iZsh | 0:3b5e1025cbd6 | 106 | led = 1; |
| iZsh | 0:3b5e1025cbd6 | 107 | wait(0.2); |
| iZsh | 0:3b5e1025cbd6 | 108 | led = 0; |
| iZsh | 0:3b5e1025cbd6 | 109 | wait(0.2); |
| iZsh | 0:3b5e1025cbd6 | 110 | } |
| iZsh | 0:3b5e1025cbd6 | 111 | } |