]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/proxmark3.c
Update BigBuf.c
[proxmark3-svn] / client / proxmark3.c
index 059cc345ef8f670bee72bbe650236672c7d3816c..460aea29d65a9484d01006c10a62c2a2a9c9f0b5 100644 (file)
 #include "cmdmain.h"
 #include "uart.h"
 #include "ui.h"
 #include "cmdmain.h"
 #include "uart.h"
 #include "ui.h"
-#include "sleep.h"
 #include "cmdparser.h"
 #include "cmdparser.h"
-#include "cmdmain.h"
+#include "cmdhw.h"
+#include "whereami.h"
+
 
 // a global mutex to prevent interlaced printing from different threads
 pthread_mutex_t print_lock;
 
 // a global mutex to prevent interlaced printing from different threads
 pthread_mutex_t print_lock;
@@ -56,11 +57,6 @@ struct receiver_arg {
        int run;
 };
 
        int run;
 };
 
-struct main_loop_arg {
-       int usb_present;
-       char *script_cmds_file;
-};
-
 byte_t rx[0x1000000];
 byte_t* prx = rx;
 
 byte_t rx[0x1000000];
 byte_t* prx = rx;
 
@@ -96,24 +92,26 @@ static void *uart_receiver(void *targ) {
        return NULL;
 }
 
        return NULL;
 }
 
-static void *main_loop(void *targ) {
-       struct main_loop_arg *arg = (struct main_loop_arg*)targ;
+
+void main_loop(char *script_cmds_file, bool usb_present) {
        struct receiver_arg rarg;
        char *cmd = NULL;
        pthread_t reader_thread;
        struct receiver_arg rarg;
        char *cmd = NULL;
        pthread_t reader_thread;
-  
-       if (arg->usb_present == 1) {
+
+       if (usb_present) {
                rarg.run = 1;
                pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
                rarg.run = 1;
                pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
+               // cache Version information now:
+               CmdVersion(NULL);
        }
 
        FILE *script_file = NULL;
        char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
 
        }
 
        FILE *script_file = NULL;
        char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
 
-       if (arg->script_cmds_file) {
-               script_file = fopen(arg->script_cmds_file, "r");
+       if (script_cmds_file) {
+               script_file = fopen(script_cmds_file, "r");
                if (script_file) {
                if (script_file) {
-                       printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
+                       printf("using 'scripting' commands file %s\n", script_cmds_file);
                }
        }
 
                }
        }
 
@@ -144,24 +142,20 @@ static void *main_loop(void *targ) {
                }
                
                if (!script_file) {
                }
                
                if (!script_file) {
-                       PrintAndLog("FOO!!");
                        cmd = readline(PROXPROMPT);
                        cmd = readline(PROXPROMPT);
-                       PrintAndLog("BAR!!");
                }
                
                }
                
-               PrintAndLog("SNAFU!!");
                if (cmd) {
 
                        while(cmd[strlen(cmd) - 1] == ' ')
                                cmd[strlen(cmd) - 1] = 0x00;
                        
                        if (cmd[0] != 0x00) {
                if (cmd) {
 
                        while(cmd[strlen(cmd) - 1] == ' ')
                                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;
                                }
                                        break;
                                }
-                               CommandReceived(cmd);
-                               add_history(cmd);
                        }
                        free(cmd);
                } else {
                        }
                        free(cmd);
                } else {
@@ -172,19 +166,16 @@ static void *main_loop(void *targ) {
   
        write_history(".history");
   
   
        write_history(".history");
   
-       if (arg->usb_present == 1) {
+       if (usb_present) {
                rarg.run = 0;
                pthread_join(reader_thread, NULL);
        }
                rarg.run = 0;
                pthread_join(reader_thread, NULL);
        }
-
+       
        if (script_file) {
                fclose(script_file);
                script_file = NULL;
        }
 
        if (script_file) {
                fclose(script_file);
                script_file = NULL;
        }
 
-       ExitGraphics();
-       pthread_exit(NULL);
-       return NULL;
 }
 
 static void dumpAllHelp(int markdown)
 }
 
 static void dumpAllHelp(int markdown)
@@ -197,6 +188,35 @@ static void dumpAllHelp(int markdown)
   dumpCommandsRecursive(cmds, 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));
   
 int main(int argc, char* argv[]) {
        srand(time(0));
   
@@ -219,25 +239,23 @@ int main(int argc, char* argv[]) {
                dumpAllHelp(1);
                return 0;
        }
                dumpAllHelp(1);
                return 0;
        }
-       // Make sure to initialize
-       struct main_loop_arg marg = {
-               .usb_present = 0,
-               .script_cmds_file = NULL
-       };
-       pthread_t main_loop_t;
 
 
+       set_my_executable_path();
+       
+       bool usb_present = false;
+       char *script_cmds_file = NULL;
   
        sp = uart_open(argv[1]);
        if (sp == INVALID_SERIAL_PORT) {
                printf("ERROR: invalid serial port\n");
   
        sp = uart_open(argv[1]);
        if (sp == INVALID_SERIAL_PORT) {
                printf("ERROR: invalid serial port\n");
-               marg.usb_present = 0;
+               usb_present = false;
                offline = 1;
        } else if (sp == CLAIMED_SERIAL_PORT) {
                printf("ERROR: serial port is claimed by another process\n");
                offline = 1;
        } else if (sp == CLAIMED_SERIAL_PORT) {
                printf("ERROR: serial port is claimed by another process\n");
-               marg.usb_present = 0;
+               usb_present = false;
                offline = 1;
        } else {
                offline = 1;
        } else {
-               marg.usb_present = 1;
+               usb_present = true;
                offline = 0;
        }
 
                offline = 0;
        }
 
@@ -253,24 +271,26 @@ int main(int argc, char* argv[]) {
                        flushAfterWrite = 1;
                }
                else
                        flushAfterWrite = 1;
                }
                else
-               marg.script_cmds_file = argv[2];
+               script_cmds_file = argv[2];
        }
 
        // create a mutex to avoid interlacing print commands from our different threads
        pthread_mutex_init(&print_lock, NULL);
 
        }
 
        // create a mutex to avoid interlacing print commands from our different threads
        pthread_mutex_init(&print_lock, NULL);
 
-       pthread_create(&main_loop_t, NULL, &main_loop, &marg);
-       InitGraphics(argc, argv);
-
+#ifdef HAVE_GUI
+       InitGraphics(argc, argv, script_cmds_file, usb_present);
        MainGraphics();
        MainGraphics();
-
-       pthread_join(main_loop_t, NULL);
+#else
+       main_loop(script_cmds_file, usb_present);
+#endif 
 
        // Clean up the port
 
        // Clean up the port
-       uart_close(sp);
-  
+       if (usb_present) {
+               uart_close(sp);
+       }
+
        // clean up mutex
        pthread_mutex_destroy(&print_lock);
        // clean up mutex
        pthread_mutex_destroy(&print_lock);
-  
-  return 0;
+
+       exit(0);
 }
 }
Impressum, Datenschutz