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
00001 /* Copyright (c) 2010 iZsh - izsh at fail0verflow.com 00002 * 00003 * This program is free software: you can redistribute it and/or modify 00004 * it under the terms of the GNU General Public License as published by 00005 * the Free Software Foundation, either version 3 of the License, or 00006 * (at your option) any later version. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // Based on 00017 // http://www.irongeek.com/i.php?page=security/barcode-flashing-led-fuzzer-bruteforcer-injector 00018 00019 #include "mbed.h" 00020 #include "BarcodeLED.h" 00021 00022 typedef struct 00023 { 00024 const char * str; 00025 const char * descr; 00026 } str_t; 00027 00028 void readline(char Buffer[], int Size) 00029 { 00030 int i = 0; 00031 char c; 00032 00033 while ((c = fgetc(stdin)) != '\r' && i < Size - 1) { 00034 putc(c, stdout); 00035 Buffer[i++] = c; 00036 } 00037 Buffer[i] = '\0'; 00038 } 00039 00040 void prompt(const str_t Barcodes[]) 00041 { 00042 printf("\r\n"); 00043 printf("=============\r\n"); 00044 printf("command list:\r\n"); 00045 printf("=============\r\n"); 00046 printf("code <39 | 128a | 128b | 128c>\r\n"); 00047 printf("preset <num>\r\n"); 00048 for (int i = 0; i < 6; ++i) 00049 printf("\t%d: %s\r\n", i, Barcodes[i].descr); 00050 printf("send <string>\r\n"); 00051 printf("> "); 00052 } 00053 00054 // Very primitive parsing... 00055 void parse(const char Line[], const str_t Barcodes[], BarcodeLED & Barcode) 00056 { 00057 printf("\r\n"); 00058 if (!strcmp(Line, "code 39")) { 00059 Barcode.SetCodetype(BarcodeLED::Code39); 00060 printf("Setting barcode to Code39\r\n"); 00061 } else if (!strcmp(Line, "code 128a")) { 00062 Barcode.SetCodetype(BarcodeLED::Code128a); 00063 printf("Setting barcode to Code128a\r\n"); 00064 } else if (!strcmp(Line, "code 128b")) { 00065 Barcode.SetCodetype(BarcodeLED::Code128b); 00066 printf("Setting barcode to Code128b\r\n"); 00067 } else if (!strcmp(Line, "code 128c")) { 00068 Barcode.SetCodetype(BarcodeLED::Code128c); 00069 printf("Setting barcode to Code128c\r\n"); 00070 } else if (!strncmp(Line, "preset ", 7)) { 00071 int num = -1; 00072 sscanf(Line, "preset %d", &num); 00073 if (num != -1 && num < 6) 00074 Barcode.Emit(Barcodes[num].str); 00075 else 00076 printf("=> Unknown string ID!\r\n"); 00077 } else if (!strncmp(Line, "send ", 5)) { 00078 Barcode.Emit(Line + 5); 00079 } else { 00080 printf("=> Command not found!\r\n"); 00081 } 00082 } 00083 00084 int main() 00085 { 00086 BarcodeLED barcode(LED1, BarcodeLED::Code39); 00087 DigitalOut led(LED4); 00088 00089 str_t barcodes[] = { 00090 {"0123456789", "numeric"}, 00091 {"abc123", "simple alphanum"}, 00092 {"<script>alert(\"Hello World!\")</script>", "XSS"}, 00093 {"' or 1=1 -- ", "SQL injection"}, 00094 {"X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*", "EICAR test string"}, 00095 {"TRY TO PASTE v", "Ctrl-V in 128a"}, 00096 }; 00097 00098 barcode.SetVerbose(true); 00099 00100 while(1) { 00101 char buffer[512]; 00102 memset(buffer, '\0', 512); 00103 prompt(barcodes); 00104 readline(buffer, 512); 00105 parse(buffer, barcodes, barcode); 00106 led = 1; 00107 wait(0.2); 00108 led = 0; 00109 wait(0.2); 00110 } 00111 }
Generated on Fri Jul 15 2022 20:45:35 by
1.7.2