Minor bug fixes with help from Holiman.

FIX: sprint_hex, sprint_bin  has better length detection.
FIX: ui.c has removed all c99 array declarations, with malloc
FIX: hfmfmfu.c wrong length in one array caused crashes in CmdHF14AMfURdCard
FIX: cmdlft55xx.c CmdDump has now a correct pwd string.
This commit is contained in:
iceman1001 2014-10-26 21:25:06 +01:00
parent 081151eabb
commit 149aeadaa6
4 changed files with 56 additions and 53 deletions

View file

@ -24,9 +24,9 @@ static int CmdHelp(const char *Cmd);
// Mifare Ultralight Write Single Block
//
int CmdHF14AMfUWrBl(const char *Cmd){
uint8_t blockNo = 0;
bool chinese_card=0;
uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t blockNo = 0;
bool chinese_card = 0;
uint8_t bldata[16] = {0x00};
UsbCommand resp;
if (strlen(Cmd)<3) {
@ -173,10 +173,10 @@ int CmdHF14AMfURdCard(const char *Cmd){
uint8_t BlockNo = 0;
int Pages=16;
uint8_t *lockbytes_t=NULL;
uint8_t lockbytes[2]={0,0};
bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint8_t lockbytes[2]={0x00};
bool bit[16]={0x00};
bool dump=false;
uint8_t datatemp[5]={0,0,0,0,0};
uint8_t datatemp[7]= {0x00};
uint8_t isOK = 0;
uint8_t * data = NULL;
@ -327,19 +327,17 @@ int CmdHF14AMfURdCard(const char *Cmd){
int CmdHF14AMfUDump(const char *Cmd){
int i;
uint8_t BlockNo = 0;
int Pages=16;
uint8_t *lockbytes_t=NULL;
uint8_t lockbytes[2]={0,0};
bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool dump=false;
uint8_t datatemp[5]={0,0,0,0,0};
uint8_t isOK = 0;
uint8_t * data = NULL;
uint8_t BlockNo = 0;
int Pages = 16;
uint8_t *lockbytes_t = NULL;
uint8_t lockbytes[2] = {0x00};
bool bit[16] = {0x00};
uint8_t datatemp[5] = {0x00};
bool dump = true;
uint8_t isOK = 0;
uint8_t * data = NULL;
FILE *fout;
dump=true;
if ((fout = fopen("dump_ultralight_data.bin","wb")) == NULL) {
PrintAndLog("Could not create file name dumpdata.bin");
return 1;
@ -468,12 +466,12 @@ void rol (uint8_t *data, const size_t len){
int CmdHF14AMfucAuth(const char *Cmd){
uint8_t blockNo = 0, keyNo=0;
uint8_t e_RndB[8];
uint8_t e_RndB[8] = {0x00};
uint32_t cuid=0;
unsigned char RndARndB[16];
uint8_t key[16];
unsigned char RndARndB[16] = {0x00};
uint8_t key[16] = {0x00};
DES_cblock RndA, RndB;
DES_cblock iv={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
DES_cblock iv[8] = {0x00};
DES_key_schedule ks1,ks2;
DES_cblock key1,key2;
@ -566,7 +564,6 @@ int CmdHF14AMfucAuth(const char *Cmd){
//
int CmdHF14AMfUCRdBl(const char *Cmd)
{
uint8_t blockNo = 0;
if (strlen(Cmd)<1) {
@ -607,14 +604,13 @@ int CmdHF14AMfUCRdCard(const char *Cmd){
uint8_t BlockNo = 0;
int Pages=44;
uint8_t *lockbytes_t=NULL;
uint8_t lockbytes[2]={0,0};
uint8_t lockbytes[2]={0x00};
uint8_t *lockbytes_t2=NULL;
uint8_t lockbytes2[2]={0,0};
bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool bit2[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint8_t lockbytes2[2]={0x00};
bool bit[16]={0x00};
bool bit2[16]={0x00};
bool dump=false;
uint8_t datatemp[5]={0,0,0,0,0};
uint8_t datatemp[5]={0x00};
uint8_t isOK = 0;
uint8_t * data = NULL;
FILE *fout = NULL;
@ -817,19 +813,18 @@ int CmdHF14AMfUCDump(const char *Cmd){
uint8_t BlockNo = 0;
int Pages=44;
uint8_t *lockbytes_t=NULL;
uint8_t lockbytes[2]={0,0};
uint8_t lockbytes[2]={0x00};
uint8_t *lockbytes_t2=NULL;
uint8_t lockbytes2[2]={0,0};
bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool bit2[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool dump=false;
uint8_t datatemp[5]={0,0,0,0,0};
uint8_t lockbytes2[2]={0x00};
bool bit[16]={0x00};
bool bit2[16]={0x00};
bool dump=true;
uint8_t datatemp[5]={0x00};
uint8_t isOK = 0;
uint8_t * data = NULL;
FILE *fout;
dump=true;
if ((fout = fopen("dump_ultralightc_data.bin","wb")) == NULL) {
PrintAndLog("Could not create file name dumpdata.bin");
return 1;
@ -1024,8 +1019,8 @@ int CmdHF14AMfUCDump(const char *Cmd){
int CmdHF14AMfUCWrBl(const char *Cmd){
uint8_t blockNo = 0;
bool chinese_card=0;
uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
bool chinese_card = 0;
uint8_t bldata[16] = {0x00};
UsbCommand resp;
if (strlen(Cmd)<3) {

View file

@ -306,14 +306,13 @@ int CmdDump(const char *Cmd){
char cmdp = param_getchar(Cmd, 0);
char s[20];
uint8_t pwd[4] = {0x00};
if (strlen(Cmd)>1 || cmdp == 'h' || cmdp == 'H') {
bool hasPwd = ( strlen(Cmd) > 0);
if ( cmdp == 'h' || cmdp == 'H') {
PrintAndLog("Usage: lf t55xx dump <password>");
PrintAndLog(" sample: lf t55xx dump FFFFFFFF");
return 0;
}
bool hasPwd = ( strlen(Cmd) > 0);
if ( hasPwd ){
if (param_gethex(Cmd, 0, pwd, 4)) {
@ -323,9 +322,9 @@ int CmdDump(const char *Cmd){
}
for ( int i = 0; i <8; ++i){
*s = 0;
memset(s,0,sizeof(s));
if ( hasPwd ) {
sprintf(s,"%d %d", i, pwd);
sprintf(s,"%d %s", i, sprint_hex(pwd,4));
CmdReadBlkPWD(s);
} else {
sprintf(s,"%d", i);

View file

@ -101,8 +101,7 @@ int manchester_decode( int * data, const size_t len, uint8_t * dataout){
int i, clock, high, low, startindex;
low = startindex = 0;
high = 1;
uint8_t bitStream[len];
uint8_t * bitStream = (uint8_t* ) malloc(sizeof(uint8_t) * len);
memset(bitStream, 0x00, len);
/* Detect high and lows */
@ -118,14 +117,14 @@ int manchester_decode( int * data, const size_t len, uint8_t * dataout){
startindex = DetectFirstTransition(data, len, high);
PrintAndLog(" Clock : %d", clock);
//PrintAndLog(" startindex : %d", startindex);
if (high != 1)
bitlength = ManchesterConvertFrom255(data, len, bitStream, high, low, clock, startindex);
else
bitlength= ManchesterConvertFrom1(data, len, bitStream, clock, startindex);
memcpy(dataout, bitStream, bitlength);
free(bitStream);
return bitlength;
}
@ -398,8 +397,9 @@ void PrintPaddedManchester( uint8_t* bitStream, size_t len, size_t blocksize){
void iceFsk2(int * data, const size_t len){
int i, j;
int output[len];
int * output = (int* ) malloc(sizeof(int) * len);
memset(output, 0x00, len);
// for (i=0; i<len-5; ++i){
// for ( j=1; j <=5; ++j) {
// output[i] += data[i*j];
@ -419,13 +419,17 @@ void iceFsk2(int * data, const size_t len){
for (j=0; j<len; ++j)
data[j] = output[j];
free(output);
}
void iceFsk3(int * data, const size_t len){
int i,j;
int output[len];
float fc = 0.1125f; // center frequency
int * output = (int* ) malloc(sizeof(int) * len);
memset(output, 0x00, len);
float fc = 0.1125f; // center frequency
size_t adjustedLen = len;
// create very simple low-pass filter to remove images (2nd-order Butterworth)
@ -520,6 +524,7 @@ void iceFsk3(int * data, const size_t len){
printf("%d", bit ); }
printf("\n");
free(output);
}
float complex cexpf (float complex Z)

View file

@ -103,22 +103,26 @@ void print_hex(const uint8_t * data, const size_t len)
}
char * sprint_hex(const uint8_t * data, const size_t len) {
int maxLen = ( len > 1024/3) ? 1024/3 : len;
static char buf[1024];
char * tmp = buf;
size_t i;
for (i=0; i < len && i < 1024/3; i++, tmp += 3)
for (i=0; i < maxLen; ++i, tmp += 3)
sprintf(tmp, "%02x ", data[i]);
return buf;
}
char * sprint_bin(const uint8_t * data, const size_t len) {
int maxLen = ( len > 1024) ? 1024 : len;
static char buf[1024];
char * tmp = buf;
size_t i;
for (i=0; i < len && i < 1024; i++, tmp++)
for (i=0; i < maxLen; ++i, ++tmp)
sprintf(tmp, "%u", data[i]);
return buf;