]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/proxmark3.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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
8 //-----------------------------------------------------------------------------
10 //-----------------------------------------------------------------------------
17 #include <readline/readline.h>
18 #include <readline/history.h>
20 #include "proxmark3.h"
24 struct usb_receiver_arg
32 char *script_cmds_file
;
35 static void *usb_receiver(void *targ
)
37 struct usb_receiver_arg
*arg
= (struct usb_receiver_arg
*)targ
;
41 if (ReceiveCommandPoll(&cmdbuf
)) {
42 UsbCommandReceived(&cmdbuf
);
51 static void *main_loop(void *targ
)
53 struct main_loop_arg
*arg
= (struct main_loop_arg
*)targ
;
54 struct usb_receiver_arg rarg
;
56 pthread_t reader_thread
;
58 if (arg
->usb_present
== 1) {
60 pthread_create(&reader_thread
, NULL
, &usb_receiver
, &rarg
);
63 FILE *script_file
= NULL
;
64 char script_cmd_buf
[256];
66 if (arg
->script_cmds_file
)
68 script_file
= fopen(arg
->script_cmds_file
, "r");
71 printf("using 'scripting' commands file %s\n", arg
->script_cmds_file
);
75 read_history(".history");
78 // If there is a script file
81 if (!fgets(script_cmd_buf
, sizeof(script_cmd_buf
), script_file
))
89 nl
= strrchr(script_cmd_buf
, '\r');
91 nl
= strrchr(script_cmd_buf
, '\n');
94 if ((cmd
= (char*) malloc(strlen(script_cmd_buf
))) != NULL
)
96 memset(cmd
, 0, strlen(script_cmd_buf
));
97 strcpy(cmd
, script_cmd_buf
);
105 cmd
= readline(PROXPROMPT
);
109 while(cmd
[strlen(cmd
) - 1] == ' ')
110 cmd
[strlen(cmd
) - 1] = 0x00;
112 if (cmd
[0] != 0x00) {
113 if (strncmp(cmd
, "quit", 4) == 0) {
117 CommandReceived(cmd
);
127 write_history(".history");
129 if (arg
->usb_present
== 1) {
131 pthread_join(reader_thread
, NULL
);
145 int main(int argc
, char **argv
)
147 // Make sure to initialize
148 struct main_loop_arg marg
= {
150 .script_cmds_file
= NULL
152 pthread_t main_loop_t
;
155 // If the user passed the filename of the 'script' to execute, get it
156 if (argc
> 1 && argv
[1])
158 marg
.script_cmds_file
= argv
[1];
161 if (!OpenProxmark(1)) {
162 fprintf(stderr
,"PROXMARK3: NOT FOUND!\n");
163 marg
.usb_present
= 0;
166 marg
.usb_present
= 1;
170 pthread_create(&main_loop_t
, NULL
, &main_loop
, &marg
);
171 InitGraphics(argc
, argv
);
175 pthread_join(main_loop_t
, NULL
);
177 if (marg
.usb_present
== 1) {