X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/2da2e9283771f20e4fb809709ea1c97c0636e455..b62b5e2527e36cdbfda2e3d2a7ce8a46e45969e1:/client/proxmark3.c diff --git a/client/proxmark3.c b/client/proxmark3.c index 2f370308..d00af5cc 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -22,9 +22,10 @@ #include "cmdmain.h" #include "uart.h" #include "ui.h" -#include "sleep.h" #include "cmdparser.h" #include "cmdhw.h" +#include "whereami.h" + // a global mutex to prevent interlaced printing from different threads pthread_mutex_t print_lock; @@ -101,7 +102,7 @@ static void *main_loop(void *targ) { struct receiver_arg rarg; char *cmd = NULL; pthread_t reader_thread; - + if (arg->usb_present == 1) { rarg.run = 1; pthread_create(&reader_thread, NULL, &uart_receiver, &rarg); @@ -155,12 +156,11 @@ static void *main_loop(void *targ) { cmd[strlen(cmd) - 1] = 0x00; if (cmd[0] != 0x00) { - if (strncmp(cmd, "quit", 4) == 0) { - exit(0); + int ret = CommandReceived(cmd); + add_history(cmd); + if (ret == 99) { // exit or quit break; } - CommandReceived(cmd); - add_history(cmd); } free(cmd); } else { @@ -175,13 +175,13 @@ static void *main_loop(void *targ) { rarg.run = 0; pthread_join(reader_thread, NULL); } - + + ExitGraphics(); + if (script_file) { fclose(script_file); script_file = NULL; } - - ExitGraphics(); pthread_exit(NULL); return NULL; } @@ -196,6 +196,34 @@ static void dumpAllHelp(int markdown) dumpCommandsRecursive(cmds, markdown); } +static char *my_executable_path = NULL; +static char *my_executable_directory = NULL; + +const char *get_my_executable_path(void) +{ + return my_executable_path; +} + +const char *get_my_executable_directory(void) +{ + return my_executable_directory; +} + +static void set_my_executable_path(void) +{ + int path_length = wai_getExecutablePath(NULL, 0, NULL); + if (path_length != -1) { + my_executable_path = (char*)malloc(path_length + 1); + int dirname_length = 0; + if (wai_getExecutablePath(my_executable_path, path_length, &dirname_length) != -1) { + my_executable_path[path_length] = '\0'; + my_executable_directory = (char *)malloc(dirname_length + 2); + strncpy(my_executable_directory, my_executable_path, dirname_length+1); + my_executable_directory[dirname_length+1] = '\0'; + } + } +} + int main(int argc, char* argv[]) { srand(time(0)); @@ -218,12 +246,15 @@ int main(int argc, char* argv[]) { dumpAllHelp(1); return 0; } + + set_my_executable_path(); + // Make sure to initialize struct main_loop_arg marg = { .usb_present = 0, .script_cmds_file = NULL }; - pthread_t main_loop_t; + pthread_t main_loop_thread; sp = uart_open(argv[1]); @@ -257,19 +288,24 @@ int main(int argc, char* argv[]) { // create a mutex to avoid interlacing print commands from our different threads pthread_mutex_init(&print_lock, NULL); + pthread_create(&main_loop_thread, NULL, &main_loop, &marg); - pthread_create(&main_loop_t, NULL, &main_loop, &marg); + // build ui/graph forms on separate thread (killed on main_loop_thread); InitGraphics(argc, argv); - MainGraphics(); + //this won't return until ExitGraphics() is called - pthread_join(main_loop_t, NULL); + //wait for thread to finish + pthread_join(main_loop_thread, NULL); + // Clean up the port - uart_close(sp); - + if (offline == 0) { + uart_close(sp); + } + // clean up mutex pthread_mutex_destroy(&print_lock); - - return 0; + + exit(0); }