corrected comments

used param_gethex(...) and param_getdec(...) instead of scanf and strncpy constructs
This commit is contained in:
tharexde 2020-06-19 01:19:01 +02:00
commit d8d56d9e74

View file

@ -391,7 +391,6 @@ int CmdEM4x50Info(const char *Cmd) {
// decoding is done by the device (not on client side) // decoding is done by the device (not on client side)
bool errors = false, verbose = false; bool errors = false, verbose = false;
char password[20] = {0x00}, tmpbuff[3];
uint8_t cmdp = 0; uint8_t cmdp = 0;
em4x50_data_t etd; em4x50_data_t etd;
PacketResponseNG resp; PacketResponseNG resp;
@ -406,21 +405,11 @@ int CmdEM4x50Info(const char *Cmd) {
return usage_lf_em4x50_info(); return usage_lf_em4x50_info();
case 'p': case 'p':
param_getstr(Cmd, cmdp + 1, password, sizeof(password)); if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
// validation return PM3_EINVARG;
if (strlen(password) != 8) {
PrintAndLogEx(WARNING, "\n error, password has to be 4 bytes\n");
errors = true;
break;
} }
// prepare given password
etd.pwd_given = true; etd.pwd_given = true;
for (int i = 0; i < 4; i++)
sscanf(strncpy(tmpbuff, password+2*i, 2), "%2hhx", &etd.password[i]);
cmdp += 2; cmdp += 2;
break; break;
@ -437,9 +426,8 @@ int CmdEM4x50Info(const char *Cmd) {
} }
// validation // validation
if (errors) { if (errors)
return usage_lf_em4x50_info(); return usage_lf_em4x50_info();
}
// call info command // call info command
clearCommandBuffer(); clearCommandBuffer();
@ -508,9 +496,7 @@ int CmdEM4x50Write(const char *Cmd) {
// envoke writing a single word (32 bit) to a EM4x50 tag // envoke writing a single word (32 bit) to a EM4x50 tag
bool errors = false, baddress = false, bword = false; bool errors = false, bword = false, baddr = false;
char password[20] = {0x00}, word[20] = {0x00}, tmpbuff[3];
int address = 0;
uint8_t cmdp = 0; uint8_t cmdp = 0;
em4x50_data_t etd; em4x50_data_t etd;
PacketResponseNG resp; PacketResponseNG resp;
@ -525,57 +511,32 @@ int CmdEM4x50Write(const char *Cmd) {
return usage_lf_em4x50_write(); return usage_lf_em4x50_write();
case 'p': case 'p':
param_getstr(Cmd, cmdp + 1, password, sizeof(password)); if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
// validation return PM3_EINVARG;
if (strlen(password) != 8) {
PrintAndLogEx(WARNING, "\n error, password has to be 4 bytes\n");
errors = true;
break;
} }
// prepare given password
etd.pwd_given = true; etd.pwd_given = true;
for (int i = 0; i < 4; i++)
sscanf(strncpy(tmpbuff, password+2*i, 2), "%2hhx", &etd.password[i]);
cmdp += 2; cmdp += 2;
break; break;
case 'w': case 'w':
param_getstr(Cmd, cmdp + 1, word, sizeof(word)); if (param_gethex(Cmd, cmdp + 1, etd.word, 8)) {
PrintAndLogEx(FAILED, "\n word has to be 8 hex symbols\n");
// validation return PM3_EINVARG;
if (strlen(word) != 8) {
PrintAndLogEx(WARNING, "\n error, word has to be 4 bytes\n");
errors = true;
break;
} else {
bword = true;
} }
bword = true;
// prepare given word
for (int i = 0; i < 4; i++)
sscanf(strncpy(tmpbuff, word+2*i, 2), "%2hhx", &etd.word[i]);
cmdp += 2; cmdp += 2;
break; break;
case 'a': case 'a':
param_getstr(Cmd, cmdp + 1, tmpbuff, sizeof(address)); param_getdec(Cmd, cmdp + 1, &etd.address);
address = atoi(tmpbuff);
// validation // validation
if (address < 1 || address > 31) { if (etd.address < 1 || etd.address > 31) {
PrintAndLogEx(WARNING, "\n error, address has to be in range [1-31]\n"); PrintAndLogEx(FAILED, "\n error, address has to be in range [1-31]\n");
errors = true; return PM3_EINVARG;
break;
} else {
baddress = true;
} }
baddr = true;
etd.address = address;
cmdp += 2; cmdp += 2;
break; break;
@ -586,7 +547,7 @@ int CmdEM4x50Write(const char *Cmd) {
} }
} }
if (errors || !baddress || !bword) if (errors || !bword || !baddr)
return usage_lf_em4x50_write(); return usage_lf_em4x50_write();
clearCommandBuffer(); clearCommandBuffer();
@ -630,8 +591,7 @@ int CmdEM4x50WritePassword(const char *Cmd) {
// envokes changing the password of EM4x50 tag // envokes changing the password of EM4x50 tag
bool errors = false, bpwd = false, bnewpwd = false; bool errors = false, bpwd = false, bnpwd = false;
char password[20] = {0x00}, new_password[20] = {0x00}, tmpbuff[3];
uint8_t cmdp = 0; uint8_t cmdp = 0;
em4x50_data_t etd; em4x50_data_t etd;
PacketResponseNG resp; PacketResponseNG resp;
@ -647,42 +607,22 @@ int CmdEM4x50WritePassword(const char *Cmd) {
return usage_lf_em4x50_write_password(); return usage_lf_em4x50_write_password();
case 'p': case 'p':
param_getstr(Cmd, cmdp + 1, password, sizeof(password)); if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
// validation return PM3_EINVARG;
if (strlen(password) != 8) {
PrintAndLogEx(WARNING, "\n error, passwords has to be 4 bytes\n");
errors = true;
break;
} else {
bpwd = true;
} }
bpwd = true;
// prepare given password
etd.pwd_given = true; etd.pwd_given = true;
for (int i = 0; i < 4; i++)
sscanf(strncpy(tmpbuff, password+2*i, 2), "%2hhx", &etd.password[i]);
cmdp += 2; cmdp += 2;
break; break;
case 'n': case 'n':
param_getstr(Cmd, cmdp + 1, new_password, sizeof(new_password)); if (param_gethex(Cmd, cmdp + 1, etd.new_password, 8)) {
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
// validation return PM3_EINVARG;
if (strlen(new_password) != 8) {
PrintAndLogEx(WARNING, "\n error, passwords have to be 4 bytes\n");
errors = true;
break;
} else {
bnewpwd = true;
} }
bnpwd = true;
// prepare given password
etd.newpwd_given = true; etd.newpwd_given = true;
for (int i = 0; i < 4; i++)
sscanf(strncpy(tmpbuff, new_password+2*i, 2), "%2hhx", &etd.new_password[i]);
cmdp += 2; cmdp += 2;
break; break;
@ -693,7 +633,7 @@ int CmdEM4x50WritePassword(const char *Cmd) {
} }
} }
if (errors || !bpwd || !bnewpwd) if (errors || !bpwd || !bnpwd)
return usage_lf_em4x50_write_password(); return usage_lf_em4x50_write_password();
clearCommandBuffer(); clearCommandBuffer();