]>
Commit | Line | Data |
---|---|---|
a553f267 | 1 | //----------------------------------------------------------------------------- |
212ef3a0 | 2 | // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net> |
a553f267 | 3 | // Copyright (C) 2010 iZsh <izsh at fail0verflow.com> |
4 | // | |
5 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
6 | // at your option, any later version. See the LICENSE.txt file for the text of | |
7 | // the license. | |
8 | //----------------------------------------------------------------------------- | |
9 | // Main binary | |
10 | //----------------------------------------------------------------------------- | |
11 | ||
6658905f | 12 | #include <stdio.h> |
590f8ff9 | 13 | #include <stdlib.h> |
6658905f | 14 | #include <string.h> |
7fe9b0b7 | 15 | #include <pthread.h> |
6658905f | 16 | #include <readline/readline.h> |
17 | #include <readline/history.h> | |
7fe9b0b7 | 18 | #include "proxusb.h" |
6658905f | 19 | #include "proxmark3.h" |
20 | #include "proxgui.h" | |
7fe9b0b7 | 21 | #include "cmdmain.h" |
6658905f | 22 | |
7fe9b0b7 | 23 | struct usb_receiver_arg |
24 | { | |
25 | int run; | |
6658905f | 26 | }; |
27 | ||
7fe9b0b7 | 28 | struct main_loop_arg |
29 | { | |
30 | int usb_present; | |
a60612db | 31 | }; |
32 | ||
7fe9b0b7 | 33 | static void *usb_receiver(void *targ) |
34 | { | |
35 | struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ; | |
36 | UsbCommand cmdbuf; | |
37 | ||
38 | while (arg->run) { | |
39 | if (ReceiveCommandPoll(&cmdbuf)) { | |
40 | for (int i = 0; i < strlen(PROXPROMPT); i++) | |
41 | putchar(0x08); | |
42 | UsbCommandReceived(&cmdbuf); | |
43 | printf(PROXPROMPT); | |
44 | fflush(NULL); | |
45 | } | |
46 | } | |
47 | ||
48 | pthread_exit(NULL); | |
4cd41f34 | 49 | return NULL; |
6658905f | 50 | } |
51 | ||
52 | static void *main_loop(void *targ) | |
53 | { | |
7fe9b0b7 | 54 | struct main_loop_arg *arg = (struct main_loop_arg*)targ; |
55 | struct usb_receiver_arg rarg; | |
56 | char *cmd = NULL; | |
57 | pthread_t reader_thread; | |
58 | ||
59 | if (arg->usb_present == 1) { | |
60 | rarg.run=1; | |
61 | pthread_create(&reader_thread, NULL, &usb_receiver, &rarg); | |
62 | } | |
63 | ||
64 | while(1) { | |
65 | cmd = readline(PROXPROMPT); | |
66 | if (cmd) { | |
23e5d20e | 67 | while(cmd[strlen(cmd) - 1] == ' ') |
68 | cmd[strlen(cmd) - 1] = 0x00; | |
7fe9b0b7 | 69 | if (cmd[0] != 0x00) { |
70 | CommandReceived(cmd); | |
71 | add_history(cmd); | |
72 | } | |
73 | free(cmd); | |
74 | } else { | |
75 | printf("\n"); | |
76 | break; | |
77 | } | |
78 | } | |
79 | ||
80 | if (arg->usb_present == 1) { | |
81 | rarg.run = 0; | |
82 | pthread_join(reader_thread, NULL); | |
83 | } | |
84 | ||
85 | ExitGraphics(); | |
86 | pthread_exit(NULL); | |
4cd41f34 | 87 | return NULL; |
6658905f | 88 | } |
89 | ||
90 | int main(int argc, char **argv) | |
91 | { | |
7fe9b0b7 | 92 | struct main_loop_arg marg; |
93 | pthread_t main_loop_t; | |
94 | usb_init(); | |
95 | ||
96 | if (!OpenProxmark(1)) { | |
97 | fprintf(stderr,"PROXMARK3: NOT FOUND!\n"); | |
98 | marg.usb_present = 0; | |
99 | offline = 1; | |
100 | } else { | |
101 | marg.usb_present = 1; | |
102 | offline = 0; | |
103 | } | |
104 | ||
105 | pthread_create(&main_loop_t, NULL, &main_loop, &marg); | |
106 | InitGraphics(argc, argv); | |
107 | ||
108 | MainGraphics(); | |
109 | ||
110 | pthread_join(main_loop_t, NULL); | |
111 | ||
112 | if (marg.usb_present == 1) { | |
113 | CloseProxmark(); | |
114 | } | |
115 | return 0; | |
6658905f | 116 | } |