From: roel@libnfc.org Date: Sun, 9 Dec 2012 13:00:19 +0000 (+0000) Subject: fixed 64-bit cmd/arg for windows X-Git-Tag: v1.0.0~130^2~19 X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/9440213d6b05ca9f5c7b1158f91654708448d776?ds=sidebyside;hp=80501bad5b7155e77374ca56ce50e35ebd64c1a4 fixed 64-bit cmd/arg for windows --- diff --git a/armsrc/appmain.c b/armsrc/appmain.c index a7c830fa..bdd04757 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -79,7 +79,8 @@ void ToSendStuffBit(int b) void DbpString(char *str) { - cmd_send(CMD_DEBUG_PRINT_STRING,strlen(str),0,0,(byte_t*)str,strlen(str)); + byte_t len = strlen(str); + cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(byte_t*)str,len); // /* this holds up stuff unless we're connected to usb */ // if (!UsbConnected()) // return; diff --git a/armsrc/cmd.c b/armsrc/cmd.c index f64b4e40..c414bc39 100644 --- a/armsrc/cmd.c +++ b/armsrc/cmd.c @@ -58,13 +58,13 @@ bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, byte_t* // Compose the outgoing command frame txcmd.cmd = cmd; txcmd.arg[0] = arg0; - txcmd.arg[1] = arg1; + txcmd.arg[1] = arg1; txcmd.arg[2] = arg2; // Add the (optional) content to the frame, with a maximum size of USB_CMD_DATA_SIZE if (data && len) { memcpy(txcmd.d.asBytes,data,MIN(len,USB_CMD_DATA_SIZE)); - } + } // Send frame and make sure all bytes are transmitted if (usb_write((byte_t*)&txcmd,sizeof(UsbCommand)) != 0) return false; diff --git a/client/cmdmain.c b/client/cmdmain.c index 434f9e6e..2fdaabc1 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -23,6 +23,7 @@ #include "cmdhw.h" #include "cmdlf.h" #include "cmdmain.h" +#include "util.h" unsigned int current_command = CMD_UNKNOWN; unsigned int received_command = CMD_UNKNOWN; @@ -99,17 +100,23 @@ void CommandReceived(char *Cmd) { //----------------------------------------------------------------------------- void UsbCommandReceived(UsbCommand *UC) { + // Debug + // printf("UsbCommand length[len=%d]\n",sizeof(UsbCommand)); + // printf(" cmd[len=%d]: %x\n",sizeof(UC->cmd),UC->cmd); + // printf(" arg0[len=%d]: %x\n",sizeof(UC->arg[0]),UC->arg[0]); + // printf(" arg1[len=%d]: %x\n",sizeof(UC->arg[1]),UC->arg[1]); + // printf(" arg2[len=%d]: %x\n",sizeof(UC->arg[2]),UC->arg[2]); + // printf(" data[len=%d]: %02x%02x%02x...\n",sizeof(UC->d.asBytes),UC->d.asBytes[0],UC->d.asBytes[1],UC->d.asBytes[2]); + // printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command); - /* If we recognize a response, return to avoid further processing */ + // If we recognize a response, return to avoid further processing switch(UC->cmd) { - // First check if we are handling a debug message + // First check if we are handling a debug message case CMD_DEBUG_PRINT_STRING: { - char s[100]; - if(UC->arg[0] > 70 || UC->arg[0] < 0) { - UC->arg[0] = 0; - } - memcpy(s, UC->d.asBytes, UC->arg[0]); - s[UC->arg[0]] = '\0'; + char s[USB_CMD_DATA_SIZE+1]; + size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE); + memcpy(s,UC->d.asBytes,len); + s[len] = 0x00; PrintAndLog("#db# %s ", s); return; } break; diff --git a/include/usb_cmd.h b/include/usb_cmd.h index 45acfe42..62c0acd7 100644 --- a/include/usb_cmd.h +++ b/include/usb_cmd.h @@ -35,10 +35,10 @@ typedef struct { #define USB_CMD_DATA_SIZE 512 typedef struct { - uint32_t cmd; + uint64_t cmd; uint64_t arg[3]; union { - uint8_t asBytes[USB_CMD_DATA_SIZE]; + uint8_t asBytes[USB_CMD_DATA_SIZE]; uint32_t asDwords[USB_CMD_DATA_SIZE/4]; } d; } PACKED UsbCommand;