]> git.zerfleddert.de Git - proxmark3-svn/blame - client/proxmark3.c
added functionality: dump card memory, save|load card memory.
[proxmark3-svn] / client / proxmark3.c
CommitLineData
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>
8556b852 16#include <unistd.h>
6658905f 17#include <readline/readline.h>
18#include <readline/history.h>
7fe9b0b7 19#include "proxusb.h"
6658905f 20#include "proxmark3.h"
21#include "proxgui.h"
7fe9b0b7 22#include "cmdmain.h"
6658905f 23
7fe9b0b7 24struct usb_receiver_arg
25{
26 int run;
6658905f 27};
28
7fe9b0b7 29struct main_loop_arg
30{
31 int usb_present;
a60612db 32};
33
7fe9b0b7 34static void *usb_receiver(void *targ)
35{
36 struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ;
37 UsbCommand cmdbuf;
38
39 while (arg->run) {
40 if (ReceiveCommandPoll(&cmdbuf)) {
41 for (int i = 0; i < strlen(PROXPROMPT); i++)
42 putchar(0x08);
43 UsbCommandReceived(&cmdbuf);
8556b852 44 // there is a big bug )
ab8b654e
M
45 if (cmdbuf.cmd >= 0x0100 && cmdbuf.cmd <= 0x0110) { // debug commands
46 printf(">");
47// rl_on_new_line_with_prompt();
48// rl_forced_update_display();
8556b852 49 }
7fe9b0b7 50 fflush(NULL);
51 }
52 }
53
54 pthread_exit(NULL);
4cd41f34 55 return NULL;
6658905f 56}
57
58static void *main_loop(void *targ)
59{
7fe9b0b7 60 struct main_loop_arg *arg = (struct main_loop_arg*)targ;
61 struct usb_receiver_arg rarg;
62 char *cmd = NULL;
63 pthread_t reader_thread;
64
65 if (arg->usb_present == 1) {
66 rarg.run=1;
67 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
68 }
69
8556b852
M
70 read_history(".history");
71 while(1) {
72 cmd = readline(PROXPROMPT);
73 if (cmd) {
74 while(cmd[strlen(cmd) - 1] == ' ')
75 cmd[strlen(cmd) - 1] = 0x00;
76
77 if (cmd[0] != 0x00) {
78 if (strncmp(cmd, "quit", 4) == 0) {
79 write_history(".history");
80 break;
81 }
82
83 CommandReceived(cmd);
84 add_history(cmd);
85 }
86 free(cmd);
87 } else {
88 printf("\n");
89 break;
90 }
91 }
7fe9b0b7 92
93 if (arg->usb_present == 1) {
94 rarg.run = 0;
95 pthread_join(reader_thread, NULL);
96 }
97
98 ExitGraphics();
99 pthread_exit(NULL);
4cd41f34 100 return NULL;
6658905f 101}
102
103int main(int argc, char **argv)
104{
7fe9b0b7 105 struct main_loop_arg marg;
106 pthread_t main_loop_t;
107 usb_init();
108
109 if (!OpenProxmark(1)) {
110 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
111 marg.usb_present = 0;
112 offline = 1;
113 } else {
114 marg.usb_present = 1;
115 offline = 0;
116 }
117
118 pthread_create(&main_loop_t, NULL, &main_loop, &marg);
119 InitGraphics(argc, argv);
120
121 MainGraphics();
122
123 pthread_join(main_loop_t, NULL);
124
125 if (marg.usb_present == 1) {
126 CloseProxmark();
127 }
128 return 0;
6658905f 129}
Impressum, Datenschutz