mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-10 18:24:27 +08:00
Merge pull request #1258 from aveao/emrtd
emrtd: Fix file reading and parsing
This commit is contained in:
commit
5cf6798b70
1 changed files with 10 additions and 13 deletions
|
@ -262,7 +262,7 @@ static int emrtd_get_asn1_data_length(uint8_t *datain, int datainlen, int offset
|
|||
// https://wf.lavatech.top/ave-but-random/emrtd-data-quirks#EF_SOD
|
||||
return datainlen;
|
||||
} else if (lenfield == 0x81) {
|
||||
int tmp = (*(datain + offset + 1) << 8);
|
||||
int tmp = (*(datain + offset + 1));
|
||||
return tmp;
|
||||
//return ((int) * (datain + offset + 1));
|
||||
} else if (lenfield == 0x82) {
|
||||
|
@ -1207,13 +1207,13 @@ static void emrtd_print_legal_sex(char *legal_sex) {
|
|||
|
||||
static int emrtd_mrz_determine_length(char *mrz, int offset, int max_length) {
|
||||
int i;
|
||||
for (i = max_length - 1; i >= 0; i--) {
|
||||
if (mrz[offset + i] != '<') {
|
||||
break;
|
||||
for (i = max_length; i >= 1; i--) {
|
||||
if (mrz[offset + i - 1] != '<') {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// if not found, it will return -1
|
||||
return i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int emrtd_mrz_determine_separator(char *mrz, int offset, int max_length) {
|
||||
|
@ -1237,14 +1237,11 @@ static void emrtd_mrz_replace_pad(char *data, int datalen, char newchar) {
|
|||
|
||||
static void emrtd_print_optional_elements(char *mrz, int offset, int length, bool verify_check_digit) {
|
||||
int i = emrtd_mrz_determine_length(mrz, offset, length);
|
||||
if (i == -1) {
|
||||
if (i == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only print optional elements if they're available
|
||||
if (i != 0) {
|
||||
PrintAndLogEx(SUCCESS, "Optional elements.....: " _YELLOW_("%.*s"), i, mrz + offset);
|
||||
}
|
||||
PrintAndLogEx(SUCCESS, "Optional elements.....: " _YELLOW_("%.*s"), i, mrz + offset);
|
||||
|
||||
if (verify_check_digit && !emrtd_mrz_verify_check_digit(mrz, offset, length)) {
|
||||
PrintAndLogEx(SUCCESS, _RED_("Optional element check digit is invalid."));
|
||||
|
@ -1253,7 +1250,7 @@ static void emrtd_print_optional_elements(char *mrz, int offset, int length, boo
|
|||
|
||||
static void emrtd_print_document_number(char *mrz, int offset) {
|
||||
int i = emrtd_mrz_determine_length(mrz, offset, 9);
|
||||
if (i == -1) {
|
||||
if (i == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1267,7 +1264,7 @@ static void emrtd_print_document_number(char *mrz, int offset) {
|
|||
static void emrtd_print_name(char *mrz, int offset, int max_length, bool localized) {
|
||||
char final_name[100] = { 0x00 };
|
||||
int namelen = emrtd_mrz_determine_length(mrz, offset, max_length);
|
||||
if (namelen == -1) {
|
||||
if (namelen == 0) {
|
||||
return;
|
||||
}
|
||||
int sep = emrtd_mrz_determine_separator(mrz, offset, namelen);
|
||||
|
|
Loading…
Reference in a new issue