CHG: 'lf search' - hitag/cotag wrong return values
CHG: is_justnoise - safety checks CHG: 'hitag reader' - debug printing
This commit is contained in:
@@ -849,7 +849,7 @@ int CheckChipType(bool getDeviceData) {
|
||||
//by marshmellow
|
||||
int CmdLFfind(const char *Cmd) {
|
||||
int ans = 0;
|
||||
size_t minLength = 1000;
|
||||
size_t minLength = 2000;
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
char testRaw = param_getchar(Cmd, 1);
|
||||
|
||||
@@ -873,18 +873,17 @@ int CmdLFfind(const char *Cmd) {
|
||||
|
||||
// only run these tests if device is online
|
||||
if (isOnline) {
|
||||
|
||||
// only run if graphbuffer is just noise as it should be for hitag/cotag
|
||||
// only run if graphbuffer is just noise as it should be for hitag
|
||||
// The improved noise detection will find Cotag.
|
||||
if (is_justnoise(GraphBuffer, minLength)) {
|
||||
|
||||
if (CheckChipType(isOnline) ) return 1;
|
||||
if (CmdLFHitagReader("26")) { PrintAndLog("\nValid Hitag Found!"); return 1;}
|
||||
if (CmdCOTAGRead("")) { PrintAndLog("\nValid COTAG ID Found!"); return 1;}
|
||||
|
||||
PrintAndLog("Signal looks just like noise. Quitting.");
|
||||
PrintAndLog("Signal looks just like noise. Looking for Hitag signal now.");
|
||||
if (CmdLFHitagReader("26") == 0) { PrintAndLog("\nValid Hitag Found!"); return 1;}
|
||||
if (CmdCOTAGRead("") > 0) { PrintAndLog("\nValid COTAG ID Found!"); return 1;}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (EM4x50Read("", false)) { PrintAndLog("\nValid EM4x50 ID Found!"); return 1;}
|
||||
if (CmdAWIDDemod("")) { PrintAndLog("\nValid AWID ID Found!"); goto out;}
|
||||
if (CmdEM410xDemod("")) { PrintAndLog("\nValid EM410x ID Found!"); goto out;}
|
||||
@@ -906,6 +905,7 @@ int CmdLFfind(const char *Cmd) {
|
||||
if (CmdVikingDemod("")) { PrintAndLog("\nValid Viking ID Found!"); goto out;}
|
||||
if (CmdVisa2kDemod("")) { PrintAndLog("\nValid Visa2000 ID Found!"); goto out;}
|
||||
|
||||
//if (CmdFermaxDemod("")) { PrintAndLog("\nValid Fermax ID Found!"); goto out;}
|
||||
// TIdemod? flexdemod?
|
||||
|
||||
PrintAndLog("\nNo Known Tags Found!\n");
|
||||
|
||||
@@ -22,15 +22,20 @@
|
||||
#include "hitagS.h"
|
||||
#include "util_posix.h"
|
||||
#include "cmdmain.h"
|
||||
#include "cmddata.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
size_t nbytes(size_t nbits) {
|
||||
return (nbits/8)+((nbits%8)>0);
|
||||
return (nbits/8) + ((nbits%8) > 0);
|
||||
}
|
||||
|
||||
int CmdLFHitagList(const char *Cmd) {
|
||||
uint8_t *got = malloc(USB_CMD_DATA_SIZE);
|
||||
if ( !got ) {
|
||||
PrintAndLog("Cannot allocate memory for trace");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Query for the actual size of the trace
|
||||
UsbCommand response;
|
||||
@@ -197,22 +202,22 @@ int CmdLFHitagReader(const char *Cmd) {
|
||||
switch (htf) {
|
||||
case 01: { //RHTSF_CHALLENGE
|
||||
c = (UsbCommand){ 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);
|
||||
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;
|
||||
case 02: { //RHTSF_KEY
|
||||
c = (UsbCommand){ CMD_READ_HITAG_S };
|
||||
num_to_bytes(param_get64ex(Cmd,1,0,16),6,htd->crypto.key);
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 6, htd->crypto.key);
|
||||
} break;
|
||||
case RHT2F_PASSWORD: {
|
||||
num_to_bytes(param_get32ex(Cmd,1,0,16),4,htd->pwd.password);
|
||||
num_to_bytes(param_get32ex(Cmd, 1, 0, 16), 4, htd->pwd.password);
|
||||
} 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);
|
||||
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;
|
||||
case RHT2F_CRYPTO: {
|
||||
num_to_bytes(param_get64ex(Cmd,1,0,16),6,htd->crypto.key);
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 6, htd->crypto.key);
|
||||
} break;
|
||||
case RHT2F_TEST_AUTH_ATTEMPTS: {
|
||||
// No additional parameters needed
|
||||
@@ -221,7 +226,7 @@ int CmdLFHitagReader(const char *Cmd) {
|
||||
// No additional parameters needed
|
||||
} break;
|
||||
default: {
|
||||
PrintAndLog("\nError: unkown reader function %d",htf);
|
||||
PrintAndLog("\nError: unkown reader function %d", htf);
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Usage: hitag reader <Reader Function #>");
|
||||
PrintAndLog("Reader Functions:");
|
||||
@@ -243,30 +248,36 @@ int CmdLFHitagReader(const char *Cmd) {
|
||||
c.arg[0] = htf;
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
WaitForResponse(CMD_ACK, &resp);
|
||||
UsbCommand resp;
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, &resp, 4000) ) {
|
||||
PrintAndLog("timeout while waiting for reply.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check the return status, stored in the first argument
|
||||
if (resp.arg[0] == false) return 1;
|
||||
if (resp.arg[0] == false) {
|
||||
if (g_debugMode) PrintAndLog("DEBUG: Error - hitag failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t id = bytes_to_num(resp.d.asBytes,4);
|
||||
uint32_t id = bytes_to_num(resp.d.asBytes, 4);
|
||||
|
||||
if (htf == RHT2F_UID_ONLY){
|
||||
PrintAndLog("Valid Hitag2 tag found - UID: %08x",id);
|
||||
PrintAndLog("Valid Hitag2 tag found - UID: %08x", id);
|
||||
} else {
|
||||
char filename[FILE_PATH_SIZE];
|
||||
FILE* f = NULL;
|
||||
sprintf(filename,"%08x_%04x.ht2",id,(rand() & 0xffff));
|
||||
f = fopen(filename,"wb");
|
||||
sprintf(filename, "%08x_%04x.ht2", id, (rand() & 0xffff));
|
||||
f = fopen(filename, "wb");
|
||||
if (!f) {
|
||||
PrintAndLog("Error: Could not open file [%s]",filename);
|
||||
PrintAndLog("Error: Could not open file [%s]", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write the 48 tag memory bytes to file and finalize
|
||||
fwrite(resp.d.asBytes, 1, 48, f);
|
||||
fclose(f);
|
||||
PrintAndLog("Succesfully saved tag memory to [%s]",filename);
|
||||
PrintAndLog("Succesfully saved tag memory to [%s]", filename);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -312,12 +323,13 @@ int CmdLFHitagCheckChallenges(const char *Cmd) {
|
||||
FILE* f;
|
||||
bool file_given;
|
||||
int len = strlen(Cmd);
|
||||
if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;
|
||||
if (len > FILE_PATH_SIZE)
|
||||
len = FILE_PATH_SIZE;
|
||||
memcpy(filename, Cmd, len);
|
||||
|
||||
if (strlen(filename) > 0) {
|
||||
f = fopen(filename,"rb+");
|
||||
if( !f ) {
|
||||
if ( !f ) {
|
||||
PrintAndLog("Error: Could not open file [%s]", filename);
|
||||
return 1;
|
||||
}
|
||||
@@ -343,23 +355,23 @@ int CmdLFHitagCheckChallenges(const char *Cmd) {
|
||||
int CmdLFHitagWP(const char *Cmd) {
|
||||
UsbCommand c = { CMD_WR_HITAG_S };
|
||||
hitag_data* htd = (hitag_data*)c.d.asBytes;
|
||||
hitag_function htf = param_get32ex(Cmd,0,0,10);
|
||||
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);
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 8, htd->auth.NrAr);
|
||||
c.arg[2]= param_get32ex(Cmd, 2, 0, 10);
|
||||
num_to_bytes(param_get32ex(Cmd,3,0,16),4,htd->auth.data);
|
||||
num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd->auth.data);
|
||||
} break;
|
||||
case 04:
|
||||
case 24:
|
||||
{ //WHTSF_KEY
|
||||
num_to_bytes(param_get64ex(Cmd,1,0,16),6,htd->crypto.key);
|
||||
num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 6, htd->crypto.key);
|
||||
c.arg[2]= param_get32ex(Cmd, 2, 0, 10);
|
||||
num_to_bytes(param_get32ex(Cmd,3,0,16),4,htd->crypto.data);
|
||||
num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd->crypto.data);
|
||||
|
||||
} break;
|
||||
default: {
|
||||
PrintAndLog("Error: unkown writer function %d",htf);
|
||||
PrintAndLog("Error: unkown writer function %d", htf);
|
||||
PrintAndLog("Hitag writer functions");
|
||||
PrintAndLog(" HitagS (0*)");
|
||||
PrintAndLog(" 03 <nr,ar> (Challenge) <page> <byte0...byte3> write page on a Hitag S tag");
|
||||
@@ -375,7 +387,7 @@ int CmdLFHitagWP(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
WaitForResponse(CMD_ACK,&resp);
|
||||
WaitForResponse(CMD_ACK, &resp);
|
||||
|
||||
// Check the return status, stored in the first argument
|
||||
if (resp.arg[0] == false) return 1;
|
||||
|
||||
@@ -1292,7 +1292,7 @@ int CmdT55xxDump(const char *Cmd){
|
||||
return 1;
|
||||
}
|
||||
|
||||
int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
|
||||
bool AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
|
||||
// arg0 bitmodes:
|
||||
// bit0 = pwdmode
|
||||
// bit1 = page to read from
|
||||
@@ -1304,7 +1304,7 @@ int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
|
||||
SendCommand(&c);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2500) ) {
|
||||
PrintAndLog("command execution time out");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
//uint8_t got[12288];
|
||||
@@ -1312,14 +1312,14 @@ int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
|
||||
GetFromBigBuf(got, sizeof(got), 0);
|
||||
if ( !WaitForResponseTimeout(CMD_ACK, NULL, 8000) ) {
|
||||
PrintAndLog("command execution time out");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
setGraphBuf(got, sizeof(got));
|
||||
|
||||
if (is_justnoise(GraphBuffer, sizeof(got)))
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
char * GetBitRateStr(uint32_t id, bool xmode) {
|
||||
|
||||
@@ -155,7 +155,7 @@ bool testKnownConfigBlock(uint32_t block0);
|
||||
extern bool tryDetectP1(bool getData);
|
||||
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5);
|
||||
int special(const char *Cmd);
|
||||
int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password );
|
||||
bool AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password );
|
||||
|
||||
bool detectPassword(int password);
|
||||
|
||||
|
||||
@@ -269,6 +269,10 @@ uint8_t fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, bool verbose, int *f
|
||||
// By measuring mean and look at amplitude of signal from HIGH / LOW,
|
||||
// we can detect noise
|
||||
bool is_justnoise(int *bits, uint32_t size) {
|
||||
|
||||
if ( bits == NULL ) return true;
|
||||
if ( size < 100 ) return true;
|
||||
|
||||
//might not be high enough for noisy environments
|
||||
#define NOICE_AMPLITUDE_THRESHOLD 10;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user