mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
added some helper functions
This commit is contained in:
parent
7320f0dd16
commit
bb5d61dca7
11 changed files with 111 additions and 28 deletions
|
@ -60,13 +60,14 @@ bool IsCardHelperPresent(bool verbose) {
|
|||
bool IsHIDSamPresent(bool verbose) {
|
||||
|
||||
if (IfPm3Smartcard() == false) {
|
||||
PrintAndLogEx(WARNING, "Proxmark3 does not have SMARTCARD support enabled, exiting");
|
||||
return false;
|
||||
}
|
||||
|
||||
// detect SAM
|
||||
smart_card_atr_t card;
|
||||
smart_select(verbose, &card);
|
||||
if (!card.atr_len) {
|
||||
if (card.atr_len == 0) {
|
||||
PrintAndLogEx(ERR, "Can't get ATR from a smart card");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -485,3 +485,45 @@ void reverse_array_copy(const uint8_t *src, int src_len, uint8_t *dest) {
|
|||
dest[i] = src[(src_len - 1) - i];
|
||||
}
|
||||
}
|
||||
|
||||
static int hexchar_to_dec(char ch) {
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
return ch - '0';
|
||||
}
|
||||
if (ch >= 'a' && ch <= 'f') {
|
||||
return ch - 'a' + 10;
|
||||
}
|
||||
if (ch >= 'A' && ch <= 'F') {
|
||||
return ch - 'A' + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// no spaces allowed for input hex string
|
||||
bool hexstr_to_byte_array(const char *hexstr, uint8_t *d, size_t *n) {
|
||||
|
||||
size_t hexstr_len = strlen(hexstr);
|
||||
if (hexstr_len & 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*n = (hexstr_len >> 1);
|
||||
|
||||
for (int i = 0; i < *n; i++) {
|
||||
|
||||
char c1 = *hexstr++;
|
||||
char c2 = *hexstr++;
|
||||
|
||||
if (c1 == '\0' || c2 == '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
int b = (hexchar_to_dec(c1) << 4) | hexchar_to_dec(c2);
|
||||
if (b < 0) {
|
||||
// Error: invalid hex character
|
||||
return false;
|
||||
}
|
||||
d[i] = (uint8_t) b;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -109,4 +109,5 @@ uint16_t get_sw(const uint8_t *d, uint16_t n);
|
|||
void reverse_array(uint8_t *d, size_t n);
|
||||
void reverse_array_copy(const uint8_t *src, int src_len, uint8_t *dest);
|
||||
|
||||
bool hexstr_to_byte_array(const char *hexstr, uint8_t *d, size_t *n);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue