mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
make style
This commit is contained in:
parent
0d9223a547
commit
0373696662
483 changed files with 56514 additions and 52451 deletions
|
@ -25,20 +25,22 @@
|
|||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
size_t nbytes(size_t nbits) {
|
||||
return (nbits/8) + ((nbits%8) > 0);
|
||||
size_t nbytes(size_t nbits)
|
||||
{
|
||||
return (nbits / 8) + ((nbits % 8) > 0);
|
||||
}
|
||||
|
||||
int CmdLFHitagList(const char *Cmd) {
|
||||
int CmdLFHitagList(const char *Cmd)
|
||||
{
|
||||
uint8_t *got = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if ( !got ) {
|
||||
if (!got) {
|
||||
PrintAndLogEx(WARNING, "Cannot allocate memory for trace");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Query for the actual size of the trace
|
||||
UsbCommand response;
|
||||
if ( !GetFromDevice(BIG_BUF, got, USB_CMD_DATA_SIZE, 0, &response, 2500, false) ) {
|
||||
if (!GetFromDevice(BIG_BUF, got, USB_CMD_DATA_SIZE, 0, &response, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(got);
|
||||
return 2;
|
||||
|
@ -53,7 +55,7 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
return 2;
|
||||
}
|
||||
got = p;
|
||||
if ( !GetFromDevice(BIG_BUF, got, traceLen, 0, NULL, 2500, false) ) {
|
||||
if (!GetFromDevice(BIG_BUF, got, traceLen, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(got);
|
||||
return 2;
|
||||
|
@ -69,26 +71,26 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
int len = strlen(Cmd);
|
||||
|
||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||
FILE* f = NULL;
|
||||
FILE *f = NULL;
|
||||
|
||||
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
|
||||
|
||||
memcpy(filename, Cmd, len);
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
f = fopen(filename,"wb");
|
||||
f = fopen(filename, "wb");
|
||||
if (!f) {
|
||||
PrintAndLogEx(WARNING, "Error: Could not open file [%s]",filename);
|
||||
PrintAndLogEx(WARNING, "Error: Could not open file [%s]", filename);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
|
||||
if(i >= traceLen) { break; }
|
||||
if (i >= traceLen) { break; }
|
||||
|
||||
bool isResponse;
|
||||
int timestamp = *((uint32_t *)(got+i));
|
||||
int timestamp = *((uint32_t *)(got + i));
|
||||
if (timestamp & 0x80000000) {
|
||||
timestamp &= 0x7fffffff;
|
||||
isResponse = 1;
|
||||
|
@ -96,7 +98,7 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
isResponse = 0;
|
||||
}
|
||||
|
||||
int parityBits = *((uint32_t *)(got+i+4));
|
||||
int parityBits = *((uint32_t *)(got + i + 4));
|
||||
// 4 bytes of additional information...
|
||||
// maximum of 32 additional parity bit information
|
||||
//
|
||||
|
@ -104,15 +106,15 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
// at each quarter bit period we can send power level (16 levels)
|
||||
// or each half bit period in 256 levels.
|
||||
|
||||
int bits = got[i+8];
|
||||
int len = nbytes(got[i+8]);
|
||||
int bits = got[i + 8];
|
||||
int len = nbytes(got[i + 8]);
|
||||
|
||||
if (len > 100) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
if (i + len > traceLen) { break;}
|
||||
|
||||
uint8_t *frame = (got+i+9);
|
||||
uint8_t *frame = (got + i + 9);
|
||||
|
||||
// Break and stick with current result if buffer was not completely full
|
||||
if (frame[0] == 0x44 && frame[1] == 0x44 && frame[3] == 0x44) { break; }
|
||||
|
@ -121,27 +123,26 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
int j;
|
||||
for (j = 0; j < len; j++) {
|
||||
|
||||
//if((parityBits >> (len - j - 1)) & 0x01) {
|
||||
if (isResponse && (oddparity8(frame[j]) != ((parityBits >> (len - j - 1)) & 0x01))) {
|
||||
sprintf(line+(j*4), "%02x! ", frame[j]);
|
||||
}
|
||||
else {
|
||||
sprintf(line+(j*4), "%02x ", frame[j]);
|
||||
}
|
||||
//if((parityBits >> (len - j - 1)) & 0x01) {
|
||||
if (isResponse && (oddparity8(frame[j]) != ((parityBits >> (len - j - 1)) & 0x01))) {
|
||||
sprintf(line + (j * 4), "%02x! ", frame[j]);
|
||||
} else {
|
||||
sprintf(line + (j * 4), "%02x ", frame[j]);
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, " +%7d: %3d: %s %s",
|
||||
(prev < 0 ? 0 : (timestamp - prev)),
|
||||
bits,
|
||||
(isResponse ? "TAG" : " "),
|
||||
line);
|
||||
(prev < 0 ? 0 : (timestamp - prev)),
|
||||
bits,
|
||||
(isResponse ? "TAG" : " "),
|
||||
line);
|
||||
|
||||
if (f) {
|
||||
fprintf(f," +%7d: %3d: %s %s\n",
|
||||
(prev < 0 ? 0 : (timestamp - prev)),
|
||||
bits,
|
||||
(isResponse ? "TAG" : " "),
|
||||
line);
|
||||
fprintf(f, " +%7d: %3d: %s %s\n",
|
||||
(prev < 0 ? 0 : (timestamp - prev)),
|
||||
bits,
|
||||
(isResponse ? "TAG" : " "),
|
||||
line);
|
||||
}
|
||||
|
||||
prev = timestamp;
|
||||
|
@ -157,18 +158,20 @@ int CmdLFHitagList(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdLFHitagSnoop(const char *Cmd) {
|
||||
int CmdLFHitagSnoop(const char *Cmd)
|
||||
{
|
||||
UsbCommand c = {CMD_SNOOP_HITAG};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdLFHitagSim(const char *Cmd) {
|
||||
int CmdLFHitagSim(const char *Cmd)
|
||||
{
|
||||
|
||||
UsbCommand c = {CMD_SIMULATE_HITAG};
|
||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||
FILE* f;
|
||||
FILE *f;
|
||||
bool tag_mem_supplied;
|
||||
|
||||
int len = strlen(Cmd);
|
||||
|
@ -176,14 +179,14 @@ int CmdLFHitagSim(const char *Cmd) {
|
|||
memcpy(filename, Cmd, len);
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
f = fopen(filename,"rb+");
|
||||
f = fopen(filename, "rb+");
|
||||
if (!f) {
|
||||
PrintAndLogEx(WARNING, "Error: Could not open file [%s]",filename);
|
||||
PrintAndLogEx(WARNING, "Error: Could not open file [%s]", filename);
|
||||
return 1;
|
||||
}
|
||||
tag_mem_supplied = true;
|
||||
size_t bytes_read = fread(c.d.asBytes, 1, 48, f);
|
||||
if ( bytes_read == 48) {
|
||||
if (bytes_read == 48) {
|
||||
PrintAndLogEx(WARNING, "Error: File reading error");
|
||||
fclose(f);
|
||||
return 1;
|
||||
|
@ -200,32 +203,38 @@ int CmdLFHitagSim(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdLFHitagReader(const char *Cmd) {
|
||||
int CmdLFHitagReader(const char *Cmd)
|
||||
{
|
||||
|
||||
UsbCommand c = {CMD_READER_HITAG, {0,0,0} };//, {param_get32ex(Cmd,0,0,10),param_get32ex(Cmd,1,0,16),param_get32ex(Cmd,2,0,16),param_get32ex(Cmd,3,0,16)}};
|
||||
hitag_data* htd = (hitag_data*)c.d.asBytes;
|
||||
UsbCommand c = {CMD_READER_HITAG, {0, 0, 0} }; //, {param_get32ex(Cmd,0,0,10),param_get32ex(Cmd,1,0,16),param_get32ex(Cmd,2,0,16),param_get32ex(Cmd,3,0,16)}};
|
||||
hitag_data *htd = (hitag_data *)c.d.asBytes;
|
||||
hitag_function htf = param_get32ex(Cmd, 0, 0, 10);
|
||||
|
||||
switch (htf) {
|
||||
case 01: { //RHTSF_CHALLENGE
|
||||
c.cmd = CMD_READ_HITAG_S;
|
||||
num_to_bytes(param_get32ex(Cmd, 1, 0, 16), 4, htd->auth.NrAr);
|
||||
num_to_bytes(param_get32ex(Cmd, 2, 0, 16), 4, htd->auth.NrAr+4);
|
||||
} break;
|
||||
num_to_bytes(param_get32ex(Cmd, 2, 0, 16), 4, htd->auth.NrAr + 4);
|
||||
}
|
||||
break;
|
||||
case 02: { //RHTSF_KEY
|
||||
c.cmd = CMD_READ_HITAG_S;
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 6, htd->crypto.key);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case RHT2F_PASSWORD: {
|
||||
num_to_bytes(param_get32ex(Cmd, 1, 0, 16), 4, htd->pwd.password);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case RHT2F_AUTHENTICATE: {
|
||||
num_to_bytes(param_get32ex(Cmd, 1, 0, 16), 4, htd->auth.NrAr);
|
||||
num_to_bytes(param_get32ex(Cmd, 2, 0, 16), 4, htd->auth.NrAr+4);
|
||||
} break;
|
||||
num_to_bytes(param_get32ex(Cmd, 2, 0, 16), 4, htd->auth.NrAr + 4);
|
||||
}
|
||||
break;
|
||||
case RHT2F_CRYPTO: {
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 6, htd->crypto.key);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case RHT2F_TEST_AUTH_ATTEMPTS: {
|
||||
// No additional parameters needed
|
||||
} break;
|
||||
|
@ -248,7 +257,8 @@ int CmdLFHitagReader(const char *Cmd) {
|
|||
PrintAndLogEx(NORMAL, " 25 (test recorded authentications)");
|
||||
PrintAndLogEx(NORMAL, " 26 just read UID");
|
||||
return 1;
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Copy the hitag2 function into the first argument
|
||||
|
@ -256,7 +266,7 @@ int CmdLFHitagReader(const char *Cmd) {
|
|||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 4000) ) {
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||
return 1;
|
||||
}
|
||||
|
@ -269,11 +279,11 @@ int CmdLFHitagReader(const char *Cmd) {
|
|||
|
||||
uint32_t id = bytes_to_num(resp.d.asBytes, 4);
|
||||
|
||||
if (htf == RHT2F_UID_ONLY){
|
||||
if (htf == RHT2F_UID_ONLY) {
|
||||
PrintAndLogEx(NORMAL, "Valid Hitag2 tag found - UID: %08x", id);
|
||||
} else {
|
||||
char filename[FILE_PATH_SIZE];
|
||||
FILE* f = NULL;
|
||||
FILE *f = NULL;
|
||||
sprintf(filename, "%08x_%04x.ht2", id, (rand() & 0xffff));
|
||||
f = fopen(filename, "wb");
|
||||
if (!f) {
|
||||
|
@ -289,10 +299,11 @@ int CmdLFHitagReader(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdLFHitagSimS(const char *Cmd) {
|
||||
int CmdLFHitagSimS(const char *Cmd)
|
||||
{
|
||||
UsbCommand c = { CMD_SIMULATE_HITAG_S };
|
||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||
FILE* f;
|
||||
FILE *f;
|
||||
bool tag_mem_supplied;
|
||||
int len = strlen(Cmd);
|
||||
if (len > FILE_PATH_SIZE)
|
||||
|
@ -306,8 +317,8 @@ int CmdLFHitagSimS(const char *Cmd) {
|
|||
return 1;
|
||||
}
|
||||
tag_mem_supplied = true;
|
||||
size_t bytes_read = fread(c.d.asBytes, 1, 4*64, f);
|
||||
if ( bytes_read == 4*64) {
|
||||
size_t bytes_read = fread(c.d.asBytes, 1, 4 * 64, f);
|
||||
if (bytes_read == 4 * 64) {
|
||||
PrintAndLogEx(WARNING, "Error: File reading error");
|
||||
fclose(f);
|
||||
return 1;
|
||||
|
@ -324,10 +335,11 @@ int CmdLFHitagSimS(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdLFHitagCheckChallenges(const char *Cmd) {
|
||||
int CmdLFHitagCheckChallenges(const char *Cmd)
|
||||
{
|
||||
UsbCommand c = { CMD_TEST_HITAGS_TRACES };
|
||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
||||
FILE* f;
|
||||
FILE *f;
|
||||
bool file_given;
|
||||
int len = strlen(Cmd);
|
||||
if (len > FILE_PATH_SIZE)
|
||||
|
@ -335,14 +347,14 @@ int CmdLFHitagCheckChallenges(const char *Cmd) {
|
|||
memcpy(filename, Cmd, len);
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
f = fopen(filename,"rb+");
|
||||
if ( !f ) {
|
||||
f = fopen(filename, "rb+");
|
||||
if (!f) {
|
||||
PrintAndLogEx(WARNING, "Error: Could not open file [%s]", filename);
|
||||
return 1;
|
||||
}
|
||||
file_given = true;
|
||||
size_t bytes_read = fread(c.d.asBytes, 1, 8*60, f);
|
||||
if ( bytes_read == 8*60) {
|
||||
size_t bytes_read = fread(c.d.asBytes, 1, 8 * 60, f);
|
||||
if (bytes_read == 8 * 60) {
|
||||
PrintAndLogEx(WARNING, "Error: File reading error");
|
||||
fclose(f);
|
||||
return 1;
|
||||
|
@ -359,24 +371,27 @@ int CmdLFHitagCheckChallenges(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CmdLFHitagWP(const char *Cmd) {
|
||||
int CmdLFHitagWP(const char *Cmd)
|
||||
{
|
||||
UsbCommand c = { CMD_WR_HITAG_S };
|
||||
hitag_data* htd = (hitag_data*)c.d.asBytes;
|
||||
hitag_data *htd = (hitag_data *)c.d.asBytes;
|
||||
hitag_function htf = param_get32ex(Cmd, 0, 0, 10);
|
||||
switch (htf) {
|
||||
case 03: { //WHTSF_CHALLENGE
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 8, htd->auth.NrAr);
|
||||
c.arg[2]= param_get32ex(Cmd, 2, 0, 10);
|
||||
c.arg[2] = param_get32ex(Cmd, 2, 0, 10);
|
||||
num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd->auth.data);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case 04:
|
||||
case 24:
|
||||
{ //WHTSF_KEY
|
||||
case 24: {
|
||||
//WHTSF_KEY
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 6, htd->crypto.key);
|
||||
c.arg[2]= param_get32ex(Cmd, 2, 0, 10);
|
||||
c.arg[2] = param_get32ex(Cmd, 2, 0, 10);
|
||||
num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd->crypto.data);
|
||||
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
PrintAndLogEx(WARNING, "Error: unkown writer function %d", htf);
|
||||
PrintAndLogEx(NORMAL, "Hitag writer functions");
|
||||
|
@ -386,7 +401,8 @@ int CmdLFHitagWP(const char *Cmd) {
|
|||
PrintAndLogEx(NORMAL, " Hitag1 (1*)");
|
||||
PrintAndLogEx(NORMAL, " Hitag2 (2*)");
|
||||
return 1;
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Copy the hitag function into the first argument
|
||||
c.arg[0] = htf;
|
||||
|
@ -410,16 +426,18 @@ static command_t CommandTable[] = {
|
|||
{"snoop", CmdLFHitagSnoop, 1, "Eavesdrop Hitag communication"},
|
||||
{"writer", CmdLFHitagWP, 1, "Act like a Hitag Writer" },
|
||||
{"check_challenges", CmdLFHitagCheckChallenges, 1, "<challenges.cc> test all challenges" },
|
||||
{ NULL,NULL, 0, NULL }
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
int CmdLFHitag(const char *Cmd) {
|
||||
int CmdLFHitag(const char *Cmd)
|
||||
{
|
||||
clearCommandBuffer();
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd) {
|
||||
int CmdHelp(const char *Cmd)
|
||||
{
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue