mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-20 21:33:19 -07:00
major USB update
This commit is contained in:
parent
8b39fed4e5
commit
902cb3c00b
44 changed files with 649 additions and 513 deletions
|
@ -67,12 +67,13 @@ CMDSRCS = \
|
|||
cmdlfhitag.c \
|
||||
cmdlfti.c \
|
||||
cmdparser.c \
|
||||
cmdmain.c
|
||||
cmdmain.c \
|
||||
uart.c
|
||||
|
||||
CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
|
||||
|
||||
RM = rm -f
|
||||
BINS = proxmark3 snooper cli flasher
|
||||
BINS = proxmark3 flasher #snooper cli
|
||||
CLEAN = cli cli.exe flasher flasher.exe proxmark3 proxmark3.exe snooper snooper.exe $(CMDOBJS) $(OBJDIR)/*.o *.o *.moc.cpp
|
||||
|
||||
all: $(BINS)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
|
@ -158,7 +159,7 @@ int CmdBitsamples(const char *Cmd)
|
|||
for (int i = 0; i < n; i += 12) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
|
||||
|
||||
for (int j = 0; j < 48; j++) {
|
||||
for (int k = 0; k < 8; k++) {
|
||||
|
@ -418,7 +419,7 @@ int CmdHexsamples(const char *Cmd)
|
|||
for (int i = offset; i < n+offset; i += 12) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
|
||||
for (int j = 0; j < 48; j += 8) {
|
||||
PrintAndLog("%02x %02x %02x %02x %02x %02x %02x %02x",
|
||||
sample_buf[j+0],
|
||||
|
@ -475,7 +476,7 @@ int CmdSamples(const char *Cmd)
|
|||
for (int i = 0; i < n; i += 12) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
|
||||
for (int j = 0; j < 48; j++) {
|
||||
GraphBuffer[cnt++] = ((int)sample_buf[j]) - 128;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "graph.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
#include "iso14443crc.h"
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdhf14a.h"
|
||||
#include "common.h"
|
||||
#include "cmdmain.h"
|
||||
#include "mifare.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
|
@ -29,6 +31,7 @@ int CmdHF14AList(const char *Cmd)
|
|||
{
|
||||
uint8_t got[1920];
|
||||
GetFromBigBuf(got,sizeof(got),0);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
|
||||
PrintAndLog("recorded activity:");
|
||||
PrintAndLog(" ETU :rssi: who bytes");
|
||||
|
@ -161,18 +164,21 @@ int CmdHF14AReader(const char *Cmd)
|
|||
{
|
||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
|
||||
SendCommand(&c);
|
||||
UsbCommand * resp = WaitForResponse(CMD_ACK);
|
||||
uint8_t * uid = resp->d.asBytes;
|
||||
|
||||
UsbCommand resp;
|
||||
WaitForResponse(CMD_ACK,&resp);
|
||||
|
||||
uint8_t * uid = resp.d.asBytes;
|
||||
iso14a_card_select_t * card = (iso14a_card_select_t *)(uid + 12);
|
||||
|
||||
if(resp->arg[0] == 0) {
|
||||
if(resp.arg[0] == 0) {
|
||||
PrintAndLog("iso14443a card select failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PrintAndLog("ATQA : %02x %02x", card->atqa[0], card->atqa[1]);
|
||||
PrintAndLog(" UID : %s", sprint_hex(uid, 12));
|
||||
PrintAndLog(" SAK : %02x [%d]", card->sak, resp->arg[0]);
|
||||
PrintAndLog(" SAK : %02x [%d]", card->sak, resp.arg[0]);
|
||||
|
||||
switch (card->sak) {
|
||||
case 0x00: PrintAndLog(" SAK : NXP MIFARE Ultralight | Ultralight C"); break;
|
||||
|
@ -191,7 +197,7 @@ int CmdHF14AReader(const char *Cmd)
|
|||
case 0x98: PrintAndLog(" SAK : Gemplus MPCOS"); break;
|
||||
default: ;
|
||||
}
|
||||
if(resp->arg[0] == 1) {
|
||||
if(resp.arg[0] == 1) {
|
||||
bool ta1 = 0, tb1 = 0, tc1 = 0;
|
||||
int pos;
|
||||
|
||||
|
@ -312,7 +318,7 @@ int CmdHF14AReader(const char *Cmd)
|
|||
else
|
||||
PrintAndLog("proprietary non-iso14443a card found, RATS not supported");
|
||||
|
||||
return resp->arg[0];
|
||||
return resp.arg[0];
|
||||
}
|
||||
|
||||
// Collect ISO14443 Type A UIDs
|
||||
|
@ -330,12 +336,15 @@ int CmdHF14ACUIDs(const char *Cmd)
|
|||
// execute anticollision procedure
|
||||
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
|
||||
SendCommand(&c);
|
||||
UsbCommand *resp = WaitForResponse(CMD_ACK);
|
||||
uint8_t *uid = resp->d.asBytes;
|
||||
|
||||
UsbCommand resp;
|
||||
WaitForResponse(CMD_ACK,&resp);
|
||||
|
||||
uint8_t *uid = resp.d.asBytes;
|
||||
iso14a_card_select_t *card = (iso14a_card_select_t *)(uid + 12);
|
||||
|
||||
// check if command failed
|
||||
if (resp->arg[0] == 0) {
|
||||
if (resp.arg[0] == 0) {
|
||||
PrintAndLog("Card select failed.");
|
||||
} else {
|
||||
// check if UID is 4 bytes
|
||||
|
@ -472,10 +481,9 @@ static command_t CommandTable[] =
|
|||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdHF14A(const char *Cmd)
|
||||
{
|
||||
int CmdHF14A(const char *Cmd) {
|
||||
// flush
|
||||
while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
|
||||
WaitForResponseTimeout(CMD_ACK,NULL,100);
|
||||
|
||||
// parse
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <stdint.h>
|
||||
#include "iso14443crc.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
#include "ui.h"
|
||||
|
|
115
client/cmdhf15.c
115
client/cmdhf15.c
|
@ -27,6 +27,7 @@
|
|||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
#include "ui.h"
|
||||
|
@ -94,7 +95,7 @@ const productName uidmapping[] = {
|
|||
// returns 1 if suceeded
|
||||
int getUID(uint8_t *buf)
|
||||
{
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
uint8_t *req=c.d.asBytes;
|
||||
|
@ -111,11 +112,9 @@ int getUID(uint8_t *buf)
|
|||
|
||||
SendCommand(&c);
|
||||
|
||||
r=WaitForResponseTimeout(CMD_ACK,1000);
|
||||
|
||||
if (r!=NULL) {
|
||||
recv = r->d.asBytes;
|
||||
if (r->arg[0]>=12 && ISO15_CRC_CHECK==Crc(recv,12)) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
recv = resp.d.asBytes;
|
||||
if (resp.arg[0]>=12 && ISO15_CRC_CHECK==Crc(recv,12)) {
|
||||
memcpy(buf,&recv[2],8);
|
||||
return 1;
|
||||
}
|
||||
|
@ -292,7 +291,7 @@ int CmdHF15Afi(const char *Cmd)
|
|||
|
||||
// Reads all memory pages
|
||||
int CmdHF15DumpMem(const char*Cmd) {
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t uid[8];
|
||||
uint8_t *recv=NULL;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
|
@ -321,20 +320,18 @@ int CmdHF15DumpMem(const char*Cmd) {
|
|||
|
||||
SendCommand(&c);
|
||||
|
||||
r=WaitForResponseTimeout(CMD_ACK,1000);
|
||||
|
||||
if (r!=NULL) {
|
||||
recv = r->d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
recv = resp.d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
|
||||
if (!(recv[0] & ISO15_RES_ERROR)) {
|
||||
retry=0;
|
||||
*output=0; // reset outputstring
|
||||
sprintf(output, "Block %2i ",blocknum);
|
||||
for ( int i=1; i<r->arg[0]-2; i++) { // data in hex
|
||||
for ( int i=1; i<resp.arg[0]-2; i++) { // data in hex
|
||||
sprintf(output+strlen(output),"%02hX ",recv[i]);
|
||||
}
|
||||
strcat(output," ");
|
||||
for ( int i=1; i<r->arg[0]-2; i++) { // data in cleaned ascii
|
||||
for ( int i=1; i<resp.arg[0]-2; i++) { // data in cleaned ascii
|
||||
sprintf(output+strlen(output),"%c",(recv[i]>31 && recv[i]<127)?recv[i]:'.');
|
||||
}
|
||||
PrintAndLog("%s",output);
|
||||
|
@ -346,14 +343,14 @@ int CmdHF15DumpMem(const char*Cmd) {
|
|||
}
|
||||
} // else PrintAndLog("crc");
|
||||
} // else PrintAndLog("r null");
|
||||
|
||||
} // retry
|
||||
if (r && r->arg[0]<3)
|
||||
PrintAndLog("Lost Connection");
|
||||
else if (r && ISO15_CRC_CHECK!=Crc(r->d.asBytes,r->arg[0]))
|
||||
PrintAndLog("CRC Failed");
|
||||
else
|
||||
PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
|
||||
// TODO: need fix
|
||||
// if (resp.arg[0]<3)
|
||||
// PrintAndLog("Lost Connection");
|
||||
// else if (ISO15_CRC_CHECK!=Crc(resp.d.asBytes,resp.arg[0]))
|
||||
// PrintAndLog("CRC Failed");
|
||||
// else
|
||||
// PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -392,7 +389,7 @@ int CmdHF15Help(const char *Cmd)
|
|||
|
||||
int CmdHF15CmdInquiry(const char *Cmd)
|
||||
{
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
uint8_t *req=c.d.asBytes;
|
||||
|
@ -407,15 +404,13 @@ int CmdHF15CmdInquiry(const char *Cmd)
|
|||
|
||||
SendCommand(&c);
|
||||
|
||||
r=WaitForResponseTimeout(CMD_ACK,1000);
|
||||
|
||||
if (r!=NULL) {
|
||||
if (r->arg[0]>=12) {
|
||||
recv = r->d.asBytes;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
if (resp.arg[0]>=12) {
|
||||
recv = resp.d.asBytes;
|
||||
PrintAndLog("UID=%s",sprintUID(NULL,&recv[2]));
|
||||
PrintAndLog("Tag Info: %s",getTagInfo(&recv[2]));
|
||||
} else {
|
||||
PrintAndLog("Response to short, just %i bytes. No tag?\n",r->arg[0]);
|
||||
PrintAndLog("Response to short, just %i bytes. No tag?\n",resp.arg[0]);
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("timeout.");
|
||||
|
@ -440,7 +435,7 @@ int CmdHF15CmdDebug( const char *cmd) {
|
|||
|
||||
|
||||
int CmdHF15CmdRaw (const char *cmd) {
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
int reply=1;
|
||||
|
@ -515,14 +510,12 @@ int CmdHF15CmdRaw (const char *cmd) {
|
|||
SendCommand(&c);
|
||||
|
||||
if (reply) {
|
||||
r=WaitForResponseTimeout(CMD_ACK,1000);
|
||||
|
||||
if (r!=NULL) {
|
||||
recv = r->d.asBytes;
|
||||
PrintAndLog("received %i octets",r->arg[0]);
|
||||
hexout = (char *)malloc(r->arg[0] * 3 + 1);
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
|
||||
recv = resp.d.asBytes;
|
||||
PrintAndLog("received %i octets",resp.arg[0]);
|
||||
hexout = (char *)malloc(resp.arg[0] * 3 + 1);
|
||||
if (hexout != NULL) {
|
||||
for (int i = 0; i < r->arg[0]; i++) { // data in hex
|
||||
for (int i = 0; i < resp.arg[0]; i++) { // data in hex
|
||||
sprintf(&hexout[i * 3], "%02hX ", recv[i]);
|
||||
}
|
||||
PrintAndLog("%s", hexout);
|
||||
|
@ -635,7 +628,7 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdle
|
|||
* get system information from tag/VICC
|
||||
*/
|
||||
int CmdHF15CmdSysinfo(const char *Cmd) {
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
uint8_t *req=c.d.asBytes;
|
||||
|
@ -670,14 +663,12 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
|
|||
|
||||
SendCommand(&c);
|
||||
|
||||
r=WaitForResponseTimeout(CMD_ACK,1000);
|
||||
|
||||
if (r!=NULL && r->arg[0]>2) {
|
||||
recv = r->d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
|
||||
recv = resp.d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
|
||||
if (!(recv[0] & ISO15_RES_ERROR)) {
|
||||
*output=0; // reset outputstring
|
||||
for ( i=1; i<r->arg[0]-2; i++) {
|
||||
for ( i=1; i<resp.arg[0]-2; i++) {
|
||||
sprintf(output+strlen(output),"%02hX ",recv[i]);
|
||||
}
|
||||
strcat(output,"\n\r");
|
||||
|
@ -725,7 +716,7 @@ int CmdHF15CmdSysinfo(const char *Cmd) {
|
|||
* Read multiple blocks at once (not all tags support this)
|
||||
*/
|
||||
int CmdHF15CmdReadmulti(const char *Cmd) {
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
uint8_t *req=c.d.asBytes;
|
||||
|
@ -773,18 +764,16 @@ int CmdHF15CmdReadmulti(const char *Cmd) {
|
|||
|
||||
SendCommand(&c);
|
||||
|
||||
r=WaitForResponseTimeout(CMD_ACK,1000);
|
||||
|
||||
if (r!=NULL && r->arg[0]>2) {
|
||||
recv = r->d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
|
||||
recv = resp.d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
|
||||
if (!(recv[0] & ISO15_RES_ERROR)) {
|
||||
*output=0; // reset outputstring
|
||||
for ( int i=1; i<r->arg[0]-2; i++) {
|
||||
for ( int i=1; i<resp.arg[0]-2; i++) {
|
||||
sprintf(output+strlen(output),"%02hX ",recv[i]);
|
||||
}
|
||||
strcat(output," ");
|
||||
for ( int i=1; i<r->arg[0]-2; i++) {
|
||||
for ( int i=1; i<resp.arg[0]-2; i++) {
|
||||
sprintf(output+strlen(output),"%c",recv[i]>31 && recv[i]<127?recv[i]:'.');
|
||||
}
|
||||
PrintAndLog("%s",output);
|
||||
|
@ -806,7 +795,7 @@ int CmdHF15CmdReadmulti(const char *Cmd) {
|
|||
* Reads a single Block
|
||||
*/
|
||||
int CmdHF15CmdRead(const char *Cmd) {
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
uint8_t *req=c.d.asBytes;
|
||||
|
@ -848,19 +837,17 @@ int CmdHF15CmdRead(const char *Cmd) {
|
|||
|
||||
SendCommand(&c);
|
||||
|
||||
r=WaitForResponseTimeout(CMD_ACK,1000);
|
||||
|
||||
if (r!=NULL && r->arg[0]>2) {
|
||||
recv = r->d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) {
|
||||
recv = resp.d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
|
||||
if (!(recv[0] & ISO15_RES_ERROR)) {
|
||||
*output=0; // reset outputstring
|
||||
//sprintf(output, "Block %2i ",blocknum);
|
||||
for ( int i=1; i<r->arg[0]-2; i++) {
|
||||
for ( int i=1; i<resp.arg[0]-2; i++) {
|
||||
sprintf(output+strlen(output),"%02hX ",recv[i]);
|
||||
}
|
||||
strcat(output," ");
|
||||
for ( int i=1; i<r->arg[0]-2; i++) {
|
||||
for ( int i=1; i<resp.arg[0]-2; i++) {
|
||||
sprintf(output+strlen(output),"%c",recv[i]>31 && recv[i]<127?recv[i]:'.');
|
||||
}
|
||||
PrintAndLog("%s",output);
|
||||
|
@ -883,7 +870,7 @@ int CmdHF15CmdRead(const char *Cmd) {
|
|||
* Writes a single Block - might run into timeout, even when successful
|
||||
*/
|
||||
int CmdHF15CmdWrite(const char *Cmd) {
|
||||
UsbCommand *r;
|
||||
UsbCommand resp;
|
||||
uint8_t *recv;
|
||||
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
|
||||
uint8_t *req=c.d.asBytes;
|
||||
|
@ -943,11 +930,9 @@ int CmdHF15CmdWrite(const char *Cmd) {
|
|||
|
||||
SendCommand(&c);
|
||||
|
||||
r=WaitForResponseTimeout(CMD_ACK,2000);
|
||||
|
||||
if (r!=NULL && r->arg[0]>2) {
|
||||
recv = r->d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,r->arg[0])) {
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,2000) && resp.arg[0]>2) {
|
||||
recv = resp.d.asBytes;
|
||||
if (ISO15_CRC_CHECK==Crc(recv,resp.arg[0])) {
|
||||
if (!(recv[0] & ISO15_RES_ERROR)) {
|
||||
PrintAndLog("OK");
|
||||
} else {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "util.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "common.h"
|
||||
|
@ -42,22 +43,21 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
|
|||
// execute PACE
|
||||
UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}};
|
||||
SendCommand(&c);
|
||||
UsbCommand *resp = WaitForResponse(CMD_ACK);
|
||||
UsbCommand resp;
|
||||
|
||||
WaitForResponse(CMD_ACK,&resp);
|
||||
|
||||
// check if command failed
|
||||
if (resp->arg[0] != 0) {
|
||||
PrintAndLog("Error in step %d, Return code: %d",
|
||||
resp->arg[0],
|
||||
(int)resp->arg[1]);
|
||||
if (resp.arg[0] != 0) {
|
||||
PrintAndLog("Error in step %d, Return code: %d",resp.arg[0],(int)resp.arg[1]);
|
||||
} else {
|
||||
size_t nonce_length = resp->arg[1];
|
||||
size_t nonce_length = resp.arg[1];
|
||||
char *nonce = (char *) malloc(2 * nonce_length + 1);
|
||||
for(int j = 0; j < nonce_length; j++) {
|
||||
snprintf(nonce + (2 * j), 3, "%02X", resp->d.asBytes[j]);
|
||||
snprintf(nonce + (2 * j), 3, "%02X", resp.d.asBytes[j]);
|
||||
}
|
||||
// print nonce
|
||||
PrintAndLog("Length: %d, Nonce: %s",
|
||||
resp->arg[1], nonce);
|
||||
PrintAndLog("Length: %d, Nonce: %s",resp.arg[1], nonce);
|
||||
}
|
||||
if (i < n - 1) {
|
||||
sleep(d);
|
||||
|
@ -87,7 +87,7 @@ int CmdHelp(const char *Cmd)
|
|||
int CmdHFEPA(const char *Cmd)
|
||||
{
|
||||
// flush
|
||||
while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
|
||||
while (!WaitForResponseTimeout(CMD_ACK,NULL,500));
|
||||
|
||||
// parse
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "iso14443crc.h" // Can also be used for iClass, using 0xE012 as CRC-type
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdhficlass.h"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
|
@ -69,7 +70,7 @@ int CmdLegicDecode(const char *Cmd)
|
|||
for (i = 0; i < 256; i += 12, h += 48) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
|
||||
|
||||
for (j = 0; j < 48; j += 8) {
|
||||
for (k = 0; k < 8; k++) {
|
||||
|
@ -253,7 +254,7 @@ int CmdLegicLoad(const char *Cmd)
|
|||
c.d.asBytes[j] = data[j];
|
||||
}
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_ACK);
|
||||
WaitForResponse(CMD_ACK, NULL);
|
||||
offset += 8;
|
||||
}
|
||||
fclose(f);
|
||||
|
@ -292,7 +293,7 @@ int CmdLegicSave(const char *Cmd)
|
|||
for (int i = offset; i < n+offset; i += 12) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, NULL);
|
||||
for (int j = 0; j < 48; j += 8) {
|
||||
fprintf(f, "%02x %02x %02x %02x %02x %02x %02x %02x\n",
|
||||
sample_buf[j+0],
|
||||
|
@ -357,7 +358,7 @@ int CmdLegicRfFill(const char *Cmd)
|
|||
for(i = 0; i < 22; i++) {
|
||||
c.arg[0] = i*48;
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_ACK);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
}
|
||||
SendCommand(&cmd);
|
||||
return 0;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "cmdhfmf.h"
|
||||
#include "proxmark3.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
|
@ -50,14 +49,14 @@ start:
|
|||
break;
|
||||
}
|
||||
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 2000);
|
||||
if (resp != NULL) {
|
||||
isOK = resp->arg[0] & 0xff;
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,2000)) {
|
||||
isOK = resp.arg[0] & 0xff;
|
||||
|
||||
uid = (uint32_t)bytes_to_num(resp->d.asBytes + 0, 4);
|
||||
nt = (uint32_t)bytes_to_num(resp->d.asBytes + 4, 4);
|
||||
par_list = bytes_to_num(resp->d.asBytes + 8, 8);
|
||||
ks_list = bytes_to_num(resp->d.asBytes + 16, 8);
|
||||
uid = (uint32_t)bytes_to_num(resp.d.asBytes + 0, 4);
|
||||
nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4);
|
||||
par_list = bytes_to_num(resp.d.asBytes + 8, 8);
|
||||
ks_list = bytes_to_num(resp.d.asBytes + 16, 8);
|
||||
|
||||
printf("\n\n");
|
||||
PrintAndLog("isOk:%02x", isOK);
|
||||
|
@ -131,11 +130,10 @@ int CmdHF14AMfWrBl(const char *Cmd)
|
|||
memcpy(c.d.asBytes, key, 6);
|
||||
memcpy(c.d.asBytes + 10, bldata, 16);
|
||||
SendCommand(&c);
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp != NULL) {
|
||||
uint8_t isOK = resp->arg[0] & 0xff;
|
||||
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
uint8_t isOK = resp.arg[0] & 0xff;
|
||||
PrintAndLog("isOk:%02x", isOK);
|
||||
} else {
|
||||
PrintAndLog("Command execute timeout");
|
||||
|
@ -175,11 +173,11 @@ int CmdHF14AMfRdBl(const char *Cmd)
|
|||
UsbCommand c = {CMD_MIFARE_READBL, {blockNo, keyType, 0}};
|
||||
memcpy(c.d.asBytes, key, 6);
|
||||
SendCommand(&c);
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp != NULL) {
|
||||
uint8_t isOK = resp->arg[0] & 0xff;
|
||||
uint8_t * data = resp->d.asBytes;
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
uint8_t isOK = resp.arg[0] & 0xff;
|
||||
uint8_t * data = resp.d.asBytes;
|
||||
|
||||
if (isOK)
|
||||
PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 16));
|
||||
|
@ -230,12 +228,12 @@ int CmdHF14AMfRdSc(const char *Cmd)
|
|||
UsbCommand c = {CMD_MIFARE_READSC, {sectorNo, keyType, 0}};
|
||||
memcpy(c.d.asBytes, key, 6);
|
||||
SendCommand(&c);
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
PrintAndLog(" ");
|
||||
|
||||
if (resp != NULL) {
|
||||
isOK = resp->arg[0] & 0xff;
|
||||
data = resp->d.asBytes;
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
isOK = resp.arg[0] & 0xff;
|
||||
data = resp.d.asBytes;
|
||||
|
||||
PrintAndLog("isOk:%02x", isOK);
|
||||
if (isOK)
|
||||
|
@ -246,13 +244,11 @@ int CmdHF14AMfRdSc(const char *Cmd)
|
|||
PrintAndLog("Command1 execute timeout");
|
||||
}
|
||||
|
||||
// response2
|
||||
resp = WaitForResponseTimeout(CMD_ACK, 500);
|
||||
// response2
|
||||
PrintAndLog(" ");
|
||||
|
||||
if (resp != NULL) {
|
||||
isOK = resp->arg[0] & 0xff;
|
||||
data = resp->d.asBytes;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
isOK = resp.arg[0] & 0xff;
|
||||
data = resp.d.asBytes;
|
||||
|
||||
if (isOK)
|
||||
for (i = 0; i < 2; i++) {
|
||||
|
@ -276,7 +272,7 @@ int CmdHF14AMfDump(const char *Cmd)
|
|||
FILE *fin;
|
||||
FILE *fout;
|
||||
|
||||
UsbCommand *resp;
|
||||
UsbCommand resp;
|
||||
|
||||
if ((fin = fopen("dumpkeys.bin","rb")) == NULL) {
|
||||
PrintAndLog("Could not find file dumpkeys.bin");
|
||||
|
@ -307,11 +303,10 @@ int CmdHF14AMfDump(const char *Cmd)
|
|||
UsbCommand c = {CMD_MIFARE_READBL, {4*i + 3, 0, 0}};
|
||||
memcpy(c.d.asBytes, keyA[i], 6);
|
||||
SendCommand(&c);
|
||||
resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp != NULL) {
|
||||
uint8_t isOK = resp->arg[0] & 0xff;
|
||||
uint8_t *data = resp->d.asBytes;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
uint8_t isOK = resp.arg[0] & 0xff;
|
||||
uint8_t *data = resp.d.asBytes;
|
||||
if (isOK){
|
||||
rights[i][0] = ((data[7] & 0x10)>>4) | ((data[8] & 0x1)<<1) | ((data[8] & 0x10)>>2);
|
||||
rights[i][1] = ((data[7] & 0x20)>>5) | ((data[8] & 0x2)<<0) | ((data[8] & 0x20)>>3);
|
||||
|
@ -333,20 +328,23 @@ int CmdHF14AMfDump(const char *Cmd)
|
|||
PrintAndLog("|----- Dumping all blocks to file... -----|");
|
||||
PrintAndLog("|-----------------------------------------|");
|
||||
|
||||
|
||||
for (i=0 ; i<16 ; i++) {
|
||||
for (j=0 ; j<4 ; j++) {
|
||||
if (j == 3){
|
||||
bool received = false;
|
||||
|
||||
if (j == 3){
|
||||
UsbCommand c = {CMD_MIFARE_READBL, {i*4 + j, 0, 0}};
|
||||
memcpy(c.d.asBytes, keyA[i], 6);
|
||||
SendCommand(&c);
|
||||
resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
received = WaitForResponseTimeout(CMD_ACK,&resp,1500);
|
||||
}
|
||||
else{
|
||||
if ((rights[i][j] == 6) | (rights[i][j] == 5)) {
|
||||
UsbCommand c = {CMD_MIFARE_READBL, {i*4+j, 1, 0}};
|
||||
memcpy(c.d.asBytes, keyB[i], 6);
|
||||
SendCommand(&c);
|
||||
resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
received = WaitForResponseTimeout(CMD_ACK,&resp,1500);
|
||||
}
|
||||
else if (rights[i][j] == 7) {
|
||||
PrintAndLog("Access rights do not allow reading of sector %d block %d",i,j);
|
||||
|
@ -355,13 +353,13 @@ int CmdHF14AMfDump(const char *Cmd)
|
|||
UsbCommand c = {CMD_MIFARE_READBL, {i*4+j, 0, 0}};
|
||||
memcpy(c.d.asBytes, keyA[i], 6);
|
||||
SendCommand(&c);
|
||||
resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
received = WaitForResponseTimeout(CMD_ACK,&resp,1500);
|
||||
}
|
||||
}
|
||||
|
||||
if (resp != NULL) {
|
||||
uint8_t isOK = resp->arg[0] & 0xff;
|
||||
uint8_t *data = resp->d.asBytes;
|
||||
if (received) {
|
||||
uint8_t isOK = resp.arg[0] & 0xff;
|
||||
uint8_t *data = resp.d.asBytes;
|
||||
if (j == 3) {
|
||||
data[0] = (keyA[i][0]);
|
||||
data[1] = (keyA[i][1]);
|
||||
|
@ -462,10 +460,10 @@ int CmdHF14AMfRestore(const char *Cmd)
|
|||
|
||||
memcpy(c.d.asBytes + 10, bldata, 16);
|
||||
SendCommand(&c);
|
||||
UsbCommand *resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp != NULL) {
|
||||
uint8_t isOK = resp->arg[0] & 0xff;
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
uint8_t isOK = resp.arg[0] & 0xff;
|
||||
PrintAndLog("isOk:%02x", isOK);
|
||||
} else {
|
||||
PrintAndLog("Command execute timeout");
|
||||
|
@ -1591,11 +1589,11 @@ int CmdHF14AMfSniff(const char *Cmd){
|
|||
break;
|
||||
}
|
||||
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 2000);
|
||||
if (resp != NULL) {
|
||||
res = resp->arg[0] & 0xff;
|
||||
len = resp->arg[1];
|
||||
num = resp->arg[2];
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,2000)) {
|
||||
res = resp.arg[0] & 0xff;
|
||||
len = resp.arg[1];
|
||||
num = resp.arg[2];
|
||||
|
||||
if (res == 0) return 0;
|
||||
if (res == 1) {
|
||||
|
@ -1603,7 +1601,7 @@ int CmdHF14AMfSniff(const char *Cmd){
|
|||
bufPtr = buf;
|
||||
memset(buf, 0x00, 3000);
|
||||
}
|
||||
memcpy(bufPtr, resp->d.asBytes, len);
|
||||
memcpy(bufPtr, resp.d.asBytes, len);
|
||||
bufPtr += len;
|
||||
pckNum++;
|
||||
}
|
||||
|
@ -1678,7 +1676,7 @@ static command_t CommandTable[] =
|
|||
int CmdHFMF(const char *Cmd)
|
||||
{
|
||||
// flush
|
||||
while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
|
||||
while (!WaitForResponseTimeout(CMD_ACK,NULL,500));
|
||||
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <limits.h>
|
||||
#include "ui.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdhw.h"
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "graph.h"
|
||||
#include "ui.h"
|
||||
|
@ -364,7 +365,7 @@ int CmdLFRead(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_ACK);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -401,7 +402,7 @@ int CmdLFSim(const char *Cmd)
|
|||
c.d.asBytes[j] = GraphBuffer[i+j];
|
||||
}
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_ACK);
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
}
|
||||
|
||||
PrintAndLog("Starting simulator...");
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
#include "cmdparser.h"
|
||||
|
|
|
@ -13,11 +13,14 @@
|
|||
#include <string.h>
|
||||
#include "data.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "common.h"
|
||||
#include "util.h"
|
||||
#include "hitag2.h"
|
||||
#include "sleep.h"
|
||||
#include "cmdmain.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
|
@ -25,16 +28,18 @@ int CmdLFHitagList(const char *Cmd)
|
|||
{
|
||||
uint8_t got[3000];
|
||||
GetFromBigBuf(got,sizeof(got),0);
|
||||
char filename[256];
|
||||
FILE* pf;
|
||||
WaitForResponse(CMD_ACK,NULL);
|
||||
|
||||
param_getstr(Cmd,0,filename);
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
char filename[256];
|
||||
FILE* pf = NULL;
|
||||
|
||||
if (param_getstr(Cmd,0,filename)) {
|
||||
if (strlen(filename) > 0) {
|
||||
if ((pf = fopen(filename,"w")) == NULL) {
|
||||
PrintAndLog("Error: Could not open file [%s]",filename);
|
||||
return 1;
|
||||
}
|
||||
PrintAndLog("Error: Could not open file [%s]",filename);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLog("recorded activity:");
|
||||
|
@ -114,7 +119,7 @@ int CmdLFHitagList(const char *Cmd)
|
|||
line);
|
||||
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
if (pf) {
|
||||
fprintf(pf," +%7d: %s: %s %s %s",
|
||||
(prev < 0 ? 0 : (timestamp - prev)),
|
||||
metricString,
|
||||
|
@ -127,7 +132,7 @@ int CmdLFHitagList(const char *Cmd)
|
|||
i += (len + 9);
|
||||
}
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
if (pf) {
|
||||
PrintAndLog("Recorded activity succesfully written to file: %s", filename);
|
||||
fclose(pf);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "crc16.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "graph.h"
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <string.h>
|
||||
#include "sleep.h"
|
||||
#include "cmdparser.h"
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "usb_cmd.h"
|
||||
#include "ui.h"
|
||||
|
@ -55,37 +56,40 @@ int CmdQuit(const char *Cmd)
|
|||
return 0;
|
||||
}
|
||||
|
||||
UsbCommand * WaitForResponseTimeout(uint32_t response_type, uint32_t ms_timeout) {
|
||||
UsbCommand * ret = NULL;
|
||||
int i=0;
|
||||
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout) {
|
||||
|
||||
for(i=0; received_command != response_type && i < ms_timeout / 10; i++) {
|
||||
msleep(10); // XXX ugh
|
||||
// Wait until the command is received
|
||||
for(size_t i=0; received_command != cmd && i < ms_timeout; i++) {
|
||||
msleep(1); // XXX ugh
|
||||
if (i == 2000) {
|
||||
PrintAndLog("Waiting for a response from the proxmark...");
|
||||
PrintAndLog("Don't forget to cancel its operation first by pressing on the button");
|
||||
}
|
||||
}
|
||||
|
||||
// There was an evil BUG
|
||||
memcpy(¤t_response_user, ¤t_response, sizeof(UsbCommand));
|
||||
ret = ¤t_response_user;
|
||||
// Check if timeout occured
|
||||
if(received_command != cmd) return false;
|
||||
|
||||
if(received_command != response_type)
|
||||
ret = NULL;
|
||||
// Copy the received response (if supplied)
|
||||
if (response) {
|
||||
memcpy(response, ¤t_response, sizeof(UsbCommand));
|
||||
}
|
||||
|
||||
received_command = CMD_UNKNOWN;
|
||||
// Reset the received command
|
||||
received_command = CMD_UNKNOWN;
|
||||
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
UsbCommand * WaitForResponse(uint32_t response_type)
|
||||
{
|
||||
return WaitForResponseTimeout(response_type, -1);
|
||||
bool WaitForResponse(uint32_t cmd, UsbCommand* response) {
|
||||
return WaitForResponseTimeout(cmd,response,-1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Entry point into our code: called whenever the user types a command and
|
||||
// then presses Enter, which the full command line that they typed.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CommandReceived(char *Cmd)
|
||||
{
|
||||
void CommandReceived(char *Cmd) {
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
}
|
||||
|
||||
|
@ -138,6 +142,19 @@ void UsbCommandReceived(UsbCommand *UC)
|
|||
PrintAndLog("# Your HF antenna is marginal.");
|
||||
} break;
|
||||
|
||||
case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K: {
|
||||
// printf("received samples: ");
|
||||
// print_hex(UC->d.asBytes,512);
|
||||
sample_buf_len += UC->arg[1];
|
||||
// printf("samples: %zd offset: %d\n",sample_buf_len,UC->arg[0]);
|
||||
memcpy(sample_buf+(UC->arg[0]),UC->d.asBytes,UC->arg[1]);
|
||||
} break;
|
||||
|
||||
|
||||
// case CMD_ACK: {
|
||||
// PrintAndLog("Receive ACK\n");
|
||||
// } break;
|
||||
|
||||
default: {
|
||||
// Maybe it's a response
|
||||
switch(current_command) {
|
||||
|
@ -146,19 +163,24 @@ void UsbCommandReceived(UsbCommand *UC)
|
|||
PrintAndLog("unrecognized command %08x\n", UC->cmd);
|
||||
break;
|
||||
}
|
||||
int i;
|
||||
for(i=0; i<48; i++) sample_buf[i] = UC->d.asBytes[i];
|
||||
// int i;
|
||||
PrintAndLog("received samples %d\n",UC->arg[0]);
|
||||
memcpy(sample_buf+UC->arg[0],UC->d.asBytes,48);
|
||||
sample_buf_len += 48;
|
||||
// for(i=0; i<48; i++) sample_buf[i] = UC->d.asBytes[i];
|
||||
received_command = UC->cmd;
|
||||
} break;
|
||||
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
// Store the last received command
|
||||
received_command = UC->cmd;
|
||||
memcpy(¤t_response, UC, sizeof(UsbCommand));
|
||||
// // Store the last received command
|
||||
// memcpy(¤t_response, UC, sizeof(UsbCommand));
|
||||
// received_command = UC->cmd;
|
||||
} break;
|
||||
}
|
||||
// Store the last received command
|
||||
memcpy(¤t_response, UC, sizeof(UsbCommand));
|
||||
received_command = UC->cmd;
|
||||
/*
|
||||
// Maybe it's a response:
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
void UsbCommandReceived(UsbCommand *UC);
|
||||
void CommandReceived(char *Cmd);
|
||||
UsbCommand * WaitForResponseTimeout(uint32_t response_type, uint32_t ms_timeout);
|
||||
UsbCommand * WaitForResponse(uint32_t response_type);
|
||||
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
|
||||
bool WaitForResponse(uint32_t cmd, UsbCommand* response);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <string.h>
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "proxmark3.h"
|
||||
|
||||
void CmdsHelp(const command_t Commands[])
|
||||
{
|
||||
|
|
|
@ -13,24 +13,32 @@
|
|||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "cmdmain.h"
|
||||
|
||||
uint8_t sample_buf[SAMPLE_BUFFER_SIZE];
|
||||
uint8_t* sample_buf;
|
||||
size_t sample_buf_len;
|
||||
|
||||
void GetFromBigBuf(uint8_t *dest, int bytes, int start_index)
|
||||
{
|
||||
start_index = ((start_index/12)*12);
|
||||
int n = (((bytes/4)/48)*48) + start_index;
|
||||
sample_buf_len = 0;
|
||||
sample_buf = dest;
|
||||
// start_index = ((start_index/12)*12);
|
||||
// int n = start_index + bytes;
|
||||
/*
|
||||
if (n % 48 != 0) {
|
||||
PrintAndLog("bad len in GetFromBigBuf");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
for (int i = start_index; i < n; i += 12) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {start_index, bytes, 0}};
|
||||
SendCommand(&c);
|
||||
/*
|
||||
for (int i = start_index; i < n; i += 48) {
|
||||
UsbCommand c = {CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K, {i, 0, 0}};
|
||||
SendCommand(&c);
|
||||
WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
memcpy(dest+(i*4), sample_buf, 48);
|
||||
// WaitForResponse(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K);
|
||||
// memcpy(dest+(i*4), sample_buf, 48);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
|
||||
#define SAMPLE_BUFFER_SIZE 64
|
||||
|
||||
extern uint8_t sample_buf[SAMPLE_BUFFER_SIZE];
|
||||
extern uint8_t* sample_buf;
|
||||
extern size_t sample_buf_len;
|
||||
#define arraylen(x) (sizeof(x)/sizeof((x)[0]))
|
||||
|
||||
void GetFromBigBuf(uint8_t *dest, int bytes, int start_index);
|
||||
|
|
|
@ -267,11 +267,11 @@ fail:
|
|||
// Get the state of the proxmark, backwards compatible
|
||||
static int get_proxmark_state(uint32_t *state)
|
||||
{
|
||||
UsbCommand c;
|
||||
HidCommand c;
|
||||
c.cmd = CMD_DEVICE_INFO;
|
||||
SendCommand(&c);
|
||||
SendCommand_(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
HidCommand resp;
|
||||
ReceiveCommand(&resp);
|
||||
|
||||
// Three outcomes:
|
||||
|
@ -313,7 +313,7 @@ static int enter_bootloader(void)
|
|||
|
||||
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
|
||||
fprintf(stderr,"Entering bootloader...\n");
|
||||
UsbCommand c;
|
||||
HidCommand c;
|
||||
memset(&c, 0, sizeof (c));
|
||||
|
||||
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
|
||||
|
@ -322,12 +322,12 @@ static int enter_bootloader(void)
|
|||
// New style handover: Send CMD_START_FLASH, which will reset the board
|
||||
// and enter the bootrom on the next boot.
|
||||
c.cmd = CMD_START_FLASH;
|
||||
SendCommand(&c);
|
||||
SendCommand_(&c);
|
||||
fprintf(stderr,"(Press and release the button only to abort)\n");
|
||||
} else {
|
||||
// Old style handover: Ask the user to press the button, then reset the board
|
||||
c.cmd = CMD_HARDWARE_RESET;
|
||||
SendCommand(&c);
|
||||
SendCommand_(&c);
|
||||
fprintf(stderr,"Press and hold down button NOW if your bootloader requires it.\n");
|
||||
}
|
||||
fprintf(stderr,"Waiting for Proxmark to reappear on USB...");
|
||||
|
@ -349,7 +349,7 @@ static int enter_bootloader(void)
|
|||
|
||||
static int wait_for_ack(void)
|
||||
{
|
||||
UsbCommand ack;
|
||||
HidCommand ack;
|
||||
ReceiveCommand(&ack);
|
||||
if (ack.cmd != CMD_ACK) {
|
||||
printf("Error: Unexpected reply 0x%04x (expected ACK)\n", ack.cmd);
|
||||
|
@ -372,7 +372,7 @@ int flash_start_flashing(int enable_bl_writes)
|
|||
if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
|
||||
// This command is stupid. Why the heck does it care which area we're
|
||||
// flashing, as long as it's not the bootloader area? The mind boggles.
|
||||
UsbCommand c = {CMD_START_FLASH};
|
||||
HidCommand c = {CMD_START_FLASH};
|
||||
|
||||
if (enable_bl_writes) {
|
||||
c.arg[0] = FLASH_START;
|
||||
|
@ -383,7 +383,7 @@ int flash_start_flashing(int enable_bl_writes)
|
|||
c.arg[1] = FLASH_END;
|
||||
c.arg[2] = 0;
|
||||
}
|
||||
SendCommand(&c);
|
||||
SendCommand_(&c);
|
||||
return wait_for_ack();
|
||||
} else {
|
||||
fprintf(stderr, "Note: Your bootloader does not understand the new START_FLASH command\n");
|
||||
|
@ -400,11 +400,11 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length)
|
|||
memset(block_buf, 0xFF, BLOCK_SIZE);
|
||||
memcpy(block_buf, data, length);
|
||||
|
||||
UsbCommand c = {CMD_SETUP_WRITE};
|
||||
HidCommand c = {CMD_SETUP_WRITE};
|
||||
for (int i = 0; i < 240; i += 48) {
|
||||
memcpy(c.d.asBytes, block_buf + i, 48);
|
||||
c.arg[0] = i / 4;
|
||||
SendCommand(&c);
|
||||
SendCommand_(&c);
|
||||
if (wait_for_ack() < 0)
|
||||
return -1;
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length)
|
|||
c.cmd = CMD_FINISH_WRITE;
|
||||
c.arg[0] = address;
|
||||
memcpy(c.d.asBytes, block_buf+240, 16);
|
||||
SendCommand(&c);
|
||||
SendCommand_(&c);
|
||||
return wait_for_ack();
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,7 @@ void flash_free(flash_file_t *ctx)
|
|||
|
||||
// just reset the unit
|
||||
int flash_stop_flashing(void) {
|
||||
UsbCommand c = {CMD_HARDWARE_RESET};
|
||||
SendCommand(&c);
|
||||
HidCommand c = {CMD_HARDWARE_RESET};
|
||||
SendCommand_(&c);
|
||||
return 0;
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -12,6 +12,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mifarehost.h"
|
||||
#include "proxmark3.h"
|
||||
|
||||
// MIFARE
|
||||
|
||||
|
@ -59,12 +60,12 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
|
|||
fnVector * vector = NULL;
|
||||
countKeys *ck;
|
||||
int lenVector = 0;
|
||||
UsbCommand * resp = NULL;
|
||||
UsbCommand resp;
|
||||
|
||||
memset(resultKeys, 0x00, 16 * 6);
|
||||
|
||||
// flush queue
|
||||
while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
|
||||
while (!WaitForResponseTimeout(CMD_ACK,NULL,500));
|
||||
|
||||
UsbCommand c = {CMD_MIFARE_NESTED, {blockNo, keyType, trgBlockNo + trgKeyType * 0x100}};
|
||||
memcpy(c.d.asBytes, key, 6);
|
||||
|
@ -81,18 +82,16 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
|
|||
break;
|
||||
}
|
||||
|
||||
resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp != NULL) {
|
||||
isEOF = resp->arg[0] & 0xff;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
isEOF = resp.arg[0] & 0xff;
|
||||
|
||||
if (isEOF) break;
|
||||
|
||||
len = resp->arg[1] & 0xff;
|
||||
len = resp.arg[1] & 0xff;
|
||||
if (len == 0) continue;
|
||||
|
||||
memcpy(&uid, resp->d.asBytes, 4);
|
||||
PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, resp->arg[2] & 0xff, (resp->arg[2] >> 8) & 0xff);
|
||||
memcpy(&uid, resp.d.asBytes, 4);
|
||||
PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, resp.arg[2] & 0xff, (resp.arg[2] >> 8) & 0xff);
|
||||
vector = (fnVector *) realloc((void *)vector, (lenVector + len) * sizeof(fnVector) + 200);
|
||||
if (vector == NULL) {
|
||||
PrintAndLog("Memory allocation error for fnVector. len: %d bytes: %d", lenVector + len, (lenVector + len) * sizeof(fnVector));
|
||||
|
@ -100,12 +99,12 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
|
|||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
vector[lenVector + i].blockNo = resp->arg[2] & 0xff;
|
||||
vector[lenVector + i].keyType = (resp->arg[2] >> 8) & 0xff;
|
||||
vector[lenVector + i].blockNo = resp.arg[2] & 0xff;
|
||||
vector[lenVector + i].keyType = (resp.arg[2] >> 8) & 0xff;
|
||||
vector[lenVector + i].uid = uid;
|
||||
|
||||
memcpy(&vector[lenVector + i].nt, (void *)(resp->d.asBytes + 8 + i * 8 + 0), 4);
|
||||
memcpy(&vector[lenVector + i].ks1, (void *)(resp->d.asBytes + 8 + i * 8 + 4), 4);
|
||||
memcpy(&vector[lenVector + i].nt, (void *)(resp.d.asBytes + 8 + i * 8 + 0), 4);
|
||||
memcpy(&vector[lenVector + i].ks1, (void *)(resp.d.asBytes + 8 + i * 8 + 4), 4);
|
||||
}
|
||||
|
||||
lenVector += len;
|
||||
|
@ -187,14 +186,12 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * key
|
|||
|
||||
UsbCommand c = {CMD_MIFARE_CHKKEYS, {blockNo, keyType, keycnt}};
|
||||
memcpy(c.d.asBytes, keyBlock, 6 * keycnt);
|
||||
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 3000);
|
||||
|
||||
if (resp == NULL) return 1;
|
||||
if ((resp->arg[0] & 0xff) != 0x01) return 2;
|
||||
*key = bytes_to_num(resp->d.asBytes, 6);
|
||||
UsbCommand resp;
|
||||
if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;
|
||||
if ((resp.arg[0] & 0xff) != 0x01) return 2;
|
||||
*key = bytes_to_num(resp.d.asBytes, 6);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -202,13 +199,11 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * key
|
|||
|
||||
int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {
|
||||
UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}};
|
||||
|
||||
SendCommand(&c);
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp == NULL) return 1;
|
||||
memcpy(data, resp->d.asBytes, blocksCount * 16);
|
||||
UsbCommand resp;
|
||||
if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1;
|
||||
memcpy(data, resp.d.asBytes, blocksCount * 16);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -241,11 +236,10 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe, uint
|
|||
memcpy(c.d.asBytes, data, 16);
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp != NULL) {
|
||||
isOK = resp->arg[0] & 0xff;
|
||||
if (uid != NULL) memcpy(uid, resp->d.asBytes, 4);
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
isOK = resp.arg[0] & 0xff;
|
||||
if (uid != NULL) memcpy(uid, resp.d.asBytes, 4);
|
||||
if (!isOK) return 2;
|
||||
} else {
|
||||
PrintAndLog("Command execute timeout");
|
||||
|
@ -260,11 +254,10 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {
|
|||
UsbCommand c = {CMD_MIFARE_EML_CGETBLOCK, {params, 0, blockNo}};
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500);
|
||||
|
||||
if (resp != NULL) {
|
||||
isOK = resp->arg[0] & 0xff;
|
||||
memcpy(data, resp->d.asBytes, 16);
|
||||
UsbCommand resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||
isOK = resp.arg[0] & 0xff;
|
||||
memcpy(data, resp.d.asBytes, 16);
|
||||
if (!isOK) return 2;
|
||||
} else {
|
||||
PrintAndLog("Command execute timeout");
|
||||
|
|
|
@ -16,98 +16,135 @@
|
|||
#include <unistd.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#include "proxusb.h"
|
||||
//#include "proxusb.h"
|
||||
#include "proxmark3.h"
|
||||
#include "proxgui.h"
|
||||
#include "cmdmain.h"
|
||||
#include "uart.h"
|
||||
#include "messages.h"
|
||||
#include "ui.h"
|
||||
|
||||
struct usb_receiver_arg
|
||||
{
|
||||
static serial_port sp;
|
||||
|
||||
void SendCommand(UsbCommand *c) {
|
||||
#if 0
|
||||
printf("Sending %d bytes\n", sizeof(UsbCommand));
|
||||
#endif
|
||||
if (!uart_send(sp,(byte_t*)c,sizeof(UsbCommand))) {
|
||||
ERR("Sending bytes to proxmark failed");
|
||||
}
|
||||
}
|
||||
|
||||
struct receiver_arg {
|
||||
int run;
|
||||
};
|
||||
|
||||
struct main_loop_arg
|
||||
{
|
||||
struct main_loop_arg {
|
||||
int usb_present;
|
||||
char *script_cmds_file;
|
||||
};
|
||||
|
||||
static void *usb_receiver(void *targ)
|
||||
{
|
||||
struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ;
|
||||
UsbCommand cmdbuf;
|
||||
//static void *usb_receiver(void *targ) {
|
||||
// struct receiver_arg *arg = (struct receiver_arg*)targ;
|
||||
// UsbCommand cmdbuf;
|
||||
//
|
||||
// while (arg->run) {
|
||||
// if (ReceiveCommandPoll(&cmdbuf)) {
|
||||
// UsbCommandReceived(&cmdbuf);
|
||||
// fflush(NULL);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pthread_exit(NULL);
|
||||
// return NULL;
|
||||
//}
|
||||
|
||||
byte_t rx[0x1000000];
|
||||
|
||||
static void *uart_receiver(void *targ) {
|
||||
struct receiver_arg *arg = (struct receiver_arg*)targ;
|
||||
size_t rxlen;
|
||||
size_t cmd_count;
|
||||
|
||||
while (arg->run) {
|
||||
if (ReceiveCommandPoll(&cmdbuf)) {
|
||||
UsbCommandReceived(&cmdbuf);
|
||||
fflush(NULL);
|
||||
if (uart_receive(sp,rx,&rxlen)) {
|
||||
if ((rxlen % sizeof(UsbCommand)) != 0) {
|
||||
PrintAndLog("ERROR: received %zd bytes, which does not seem to be one or more command(s)\n",rxlen);
|
||||
continue;
|
||||
}
|
||||
cmd_count = rxlen / sizeof(UsbCommand);
|
||||
// printf("received %zd bytes, which represents %zd commands\n",rxlen, cmd_count);
|
||||
for (size_t i=0; i<cmd_count; i++) {
|
||||
UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *main_loop(void *targ)
|
||||
{
|
||||
struct main_loop_arg *arg = (struct main_loop_arg*)targ;
|
||||
struct usb_receiver_arg rarg;
|
||||
char *cmd = NULL;
|
||||
pthread_t reader_thread;
|
||||
|
||||
if (arg->usb_present == 1) {
|
||||
rarg.run=1;
|
||||
pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
|
||||
}
|
||||
|
||||
FILE *script_file = NULL;
|
||||
char script_cmd_buf[256];
|
||||
|
||||
if (arg->script_cmds_file)
|
||||
static void *main_loop(void *targ) {
|
||||
struct main_loop_arg *arg = (struct main_loop_arg*)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, &usb_receiver, &rarg);
|
||||
pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
|
||||
}
|
||||
|
||||
FILE *script_file = NULL;
|
||||
char script_cmd_buf[256];
|
||||
|
||||
if (arg->script_cmds_file)
|
||||
{
|
||||
script_file = fopen(arg->script_cmds_file, "r");
|
||||
if (script_file)
|
||||
{
|
||||
script_file = fopen(arg->script_cmds_file, "r");
|
||||
if (script_file)
|
||||
{
|
||||
printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
|
||||
}
|
||||
printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
|
||||
}
|
||||
}
|
||||
|
||||
read_history(".history");
|
||||
while(1)
|
||||
{
|
||||
// If there is a script file
|
||||
if (script_file)
|
||||
{
|
||||
if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file))
|
||||
{
|
||||
fclose(script_file);
|
||||
script_file = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *nl;
|
||||
nl = strrchr(script_cmd_buf, '\r');
|
||||
if (nl) *nl = '\0';
|
||||
nl = strrchr(script_cmd_buf, '\n');
|
||||
if (nl) *nl = '\0';
|
||||
|
||||
if ((cmd = (char*) malloc(strlen(script_cmd_buf))) != NULL)
|
||||
{
|
||||
// If there is a script file
|
||||
if (script_file)
|
||||
{
|
||||
if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file))
|
||||
{
|
||||
fclose(script_file);
|
||||
script_file = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *nl;
|
||||
nl = strrchr(script_cmd_buf, '\r');
|
||||
if (nl) *nl = '\0';
|
||||
nl = strrchr(script_cmd_buf, '\n');
|
||||
if (nl) *nl = '\0';
|
||||
|
||||
if ((cmd = (char*) malloc(strlen(script_cmd_buf))) != NULL)
|
||||
{
|
||||
memset(cmd, 0, strlen(script_cmd_buf));
|
||||
strcpy(cmd, script_cmd_buf);
|
||||
printf("%s\n", cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
memset(cmd, 0, strlen(script_cmd_buf));
|
||||
strcpy(cmd, script_cmd_buf);
|
||||
printf("%s\n", cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!script_file)
|
||||
{
|
||||
cmd = readline(PROXPROMPT);
|
||||
cmd = readline(PROXPROMPT);
|
||||
}
|
||||
|
||||
if (cmd) {
|
||||
while(cmd[strlen(cmd) - 1] == ' ')
|
||||
cmd[strlen(cmd) - 1] = 0x00;
|
||||
cmd[strlen(cmd) - 1] = 0x00;
|
||||
|
||||
if (cmd[0] != 0x00) {
|
||||
if (strncmp(cmd, "quit", 4) == 0) {
|
||||
|
@ -123,41 +160,41 @@ static void *main_loop(void *targ)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
write_history(".history");
|
||||
|
||||
if (arg->usb_present == 1) {
|
||||
rarg.run = 0;
|
||||
pthread_join(reader_thread, NULL);
|
||||
}
|
||||
|
||||
if (script_file)
|
||||
{
|
||||
fclose(script_file);
|
||||
script_file = NULL;
|
||||
}
|
||||
|
||||
ExitGraphics();
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
|
||||
if (arg->usb_present == 1) {
|
||||
rarg.run = 0;
|
||||
pthread_join(reader_thread, NULL);
|
||||
}
|
||||
|
||||
if (script_file)
|
||||
{
|
||||
fclose(script_file);
|
||||
script_file = NULL;
|
||||
}
|
||||
|
||||
ExitGraphics();
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
if (argc < 2) {
|
||||
printf("syntax: %s <port>\n\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Make sure to initialize
|
||||
struct main_loop_arg marg = {
|
||||
.usb_present = 0,
|
||||
.script_cmds_file = NULL
|
||||
};
|
||||
pthread_t main_loop_t;
|
||||
|
||||
/*
|
||||
usb_init();
|
||||
|
||||
// If the user passed the filename of the 'script' to execute, get it
|
||||
if (argc > 1 && argv[1])
|
||||
{
|
||||
marg.script_cmds_file = argv[1];
|
||||
}
|
||||
|
||||
if (!OpenProxmark(1)) {
|
||||
fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
|
||||
marg.usb_present = 0;
|
||||
|
@ -166,7 +203,22 @@ int main(int argc, char **argv)
|
|||
marg.usb_present = 1;
|
||||
offline = 0;
|
||||
}
|
||||
*/
|
||||
sp = uart_open(argv[1]);
|
||||
if (sp == INVALID_SERIAL_PORT) {
|
||||
printf("ERROR: invalid serial port\n");
|
||||
marg.usb_present = 0;
|
||||
offline = 1;
|
||||
} else {
|
||||
marg.usb_present = 1;
|
||||
offline = 0;
|
||||
}
|
||||
|
||||
// If the user passed the filename of the 'script' to execute, get it
|
||||
if (argc > 2 && argv[2]) {
|
||||
marg.script_cmds_file = argv[2];
|
||||
}
|
||||
|
||||
pthread_create(&main_loop_t, NULL, &main_loop, &marg);
|
||||
InitGraphics(argc, argv);
|
||||
|
||||
|
@ -174,8 +226,12 @@ int main(int argc, char **argv)
|
|||
|
||||
pthread_join(main_loop_t, NULL);
|
||||
|
||||
if (marg.usb_present == 1) {
|
||||
CloseProxmark();
|
||||
}
|
||||
// if (marg.usb_present == 1) {
|
||||
// CloseProxmark();
|
||||
// }
|
||||
|
||||
// Clean up the port
|
||||
uart_close(sp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
#ifndef PROXMARK3_H__
|
||||
#define PROXMARK3_H__
|
||||
|
||||
#include <usb.h>
|
||||
#include "usb_cmd.h"
|
||||
|
||||
#define PROXPROMPT "proxmark3> "
|
||||
|
||||
void SendCommand(UsbCommand *c);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,15 +34,15 @@ unsigned char return_on_error = 0;
|
|||
unsigned char error_occured = 0;
|
||||
extern unsigned int current_command;
|
||||
|
||||
void SendCommand(UsbCommand *c)
|
||||
void SendCommand_(HidCommand *c)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#if 0
|
||||
printf("Sending %d bytes\n", sizeof(UsbCommand));
|
||||
printf("Sending %d bytes\n", sizeof(HidCommand));
|
||||
#endif
|
||||
current_command = c->cmd;
|
||||
ret = usb_bulk_write(devh, 0x01, (char*)c, sizeof(UsbCommand), 1000);
|
||||
ret = usb_bulk_write(devh, 0x01, (char*)c, sizeof(HidCommand), 1000);
|
||||
if (ret<0) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
|
@ -63,12 +63,12 @@ void SendCommand(UsbCommand *c)
|
|||
}
|
||||
}
|
||||
|
||||
bool ReceiveCommandPoll(UsbCommand *c)
|
||||
bool ReceiveCommandPoll(HidCommand *c)
|
||||
{
|
||||
int ret;
|
||||
|
||||
memset(c, 0, sizeof (UsbCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char*)c, sizeof(UsbCommand), 500);
|
||||
memset(c, 0, sizeof (HidCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char*)c, sizeof(HidCommand), 500);
|
||||
if (ret<0) {
|
||||
if (ret != -ETIMEDOUT) {
|
||||
error_occured = 1;
|
||||
|
@ -89,16 +89,16 @@ bool ReceiveCommandPoll(UsbCommand *c)
|
|||
return false;
|
||||
}
|
||||
} else {
|
||||
if (ret && (ret < sizeof(UsbCommand))) {
|
||||
if (ret && (ret < sizeof(HidCommand))) {
|
||||
fprintf(stderr, "Read only %d instead of requested %d bytes!\n",
|
||||
ret, (int)sizeof(UsbCommand));
|
||||
ret, (int)sizeof(HidCommand));
|
||||
}
|
||||
}
|
||||
|
||||
return ret > 0;
|
||||
}
|
||||
|
||||
void ReceiveCommand(UsbCommand *c)
|
||||
void ReceiveCommand(HidCommand *c)
|
||||
{
|
||||
// printf("%s()\n", __FUNCTION__);
|
||||
int retval = 0;
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
extern unsigned char return_on_error;
|
||||
extern unsigned char error_occured;
|
||||
|
||||
void SendCommand(UsbCommand *c);
|
||||
bool ReceiveCommandPoll(UsbCommand *c);
|
||||
void ReceiveCommand(UsbCommand *c);
|
||||
void SendCommand_(HidCommand *c);
|
||||
bool ReceiveCommandPoll(HidCommand *c);
|
||||
void ReceiveCommand(HidCommand *c);
|
||||
struct usb_dev_handle* FindProxmark(int verbose, unsigned int *iface);
|
||||
struct usb_dev_handle* OpenProxmark(int verbose);
|
||||
void CloseProxmark(void);
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
int ukbhit(void);
|
||||
|
||||
void AddLogLine(char *fileName, char *extData, char *c);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue