fix one too small
[RRG-proxmark3.git] / client / src / atrs.c
blobd8f11587f81efb597fac17b98f1ea531c66de40b
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // ATR information lookup
17 //-----------------------------------------------------------------------------
18 #include "atrs.h"
19 #include <string.h>
20 #include <stdlib.h>
21 #include "commonutil.h" // ARRAYLEN
22 #include "ui.h" // PrintAndLogEx
24 // get a ATR description based on the atr bytes
25 // returns description of the best match
26 const char *getAtrInfo(const char *atr_str) {
27 size_t slen = strlen(atr_str);
28 int match = -1;
29 // skip last element of AtrTable
30 for (int i = 0; i < ARRAYLEN(AtrTable) - 1; ++i) {
32 if (strlen(AtrTable[i].bytes) != slen)
33 continue;
35 if (strstr(AtrTable[i].bytes, ".") != NULL) {
36 char *tmp_atr = calloc(slen, sizeof(uint8_t));
37 if (tmp_atr == NULL) {
38 PrintAndLogEx(FAILED, "failed to allocate memory");
39 return NULL;
42 for (int j = 0; j < slen; j++) {
43 tmp_atr[j] = (AtrTable[i].bytes[j] == '.') ? '.' : atr_str[j];
46 if (strncmp(tmp_atr, AtrTable[i].bytes, slen) == 0) {
47 // record partial match but continue looking for full match
48 match = i;
50 free(tmp_atr);
52 } else {
53 if (strncmp(atr_str, AtrTable[i].bytes, slen) == 0) {
54 return AtrTable[i].desc;
59 if (match >= 0) {
60 return AtrTable[match].desc;
61 } else {
62 //No match, return default = last element of AtrTable
63 return AtrTable[ARRAYLEN(AtrTable) - 1].desc;