diff --git a/client/resources/mad.json b/client/resources/mad.json index 6b8465f55..840c2ad8f 100644 --- a/client/resources/mad.json +++ b/client/resources/mad.json @@ -6224,6 +6224,13 @@ "service_provider": "NORALSY", "system_integrator": "NORALSY" }, + { + "application": "(access control and security) VIGIK", + "company": "PROAC", + "mad": "0x4982", + "service_provider": "PROAC", + "system_integrator": "PROAC" + }, { "application": "Card Administration, cardholder administration, access control & security, company services, miscellaneous applications", "company": "Ministry of Defense", diff --git a/client/src/mifare/mad.c b/client/src/mifare/mad.c index ff3980687..64b54f5eb 100644 --- a/client/src/mifare/mad.c +++ b/client/src/mifare/mad.c @@ -499,19 +499,37 @@ bool HasMADKey(const mad1_sector_t *s0) { return (memcmp(s0->trailer.key_a, g_mifare_mad_key, sizeof(g_mifare_mad_key)) == 0); } -int DetectHID(const mad1_sector_t *s0, uint16_t manufacture) { +int mad_find_aid(const mad1_sector_t *s0, uint16_t aid) { if (s0 == NULL) { return -1; } for (int i = 0; i < MAD1_NUM_AIDS; i++) { - if (madGetAID(s0->mad.aid[i], false) == manufacture) { + if (madGetAID(s0->mad.aid[i], false) == aid) { return i + 1; } } return -1; } +int mad_count_aid(const mad1_sector_t *s0, uint16_t aid) { + if (s0 == NULL) { + return 0; + } + + int n = 0; + for (int i = 0; i < MAD1_NUM_AIDS; i++) { + if (madGetAID(s0->mad.aid[i], false) == aid) { + n++; + } + } + return n; +} + +int DetectHID(const mad1_sector_t *s0, uint16_t manufacture) { + return mad_find_aid(s0, manufacture); +} + int convert_mad_to_arr(const mad1_sector_t *s0, const mad2_sector_t *s16, size_t dump_len, uint8_t *out, size_t omax, size_t *olen, bool override) { if (s0 == NULL || out == NULL || olen == NULL || dump_len < sizeof(mad1_sector_t) || omax == 0) { diff --git a/client/src/mifare/mad.h b/client/src/mifare/mad.h index 8d018aacb..e2714b6fc 100644 --- a/client/src/mifare/mad.h +++ b/client/src/mifare/mad.h @@ -114,6 +114,14 @@ int MADDFDecodeAndPrint(uint32_t short_aid, bool verbose); int MADCardHolderInfoDecode(const uint8_t *data, size_t datalen, bool verbose); void MADPrintHeader(void); bool HasMADKey(const mad1_sector_t *s0); +// First sector carrying this AID, 1..15, or -1. The MAD is how an application +// says which sectors are its own, so every dump parser that keys off an AID +// wants this. +int mad_find_aid(const mad1_sector_t *s0, uint16_t aid); + +// Count of sectors carrying this AID +int mad_count_aid(const mad1_sector_t *s0, uint16_t aid); + int DetectHID(const mad1_sector_t *s0, uint16_t manufacture); int convert_mad_to_arr(const mad1_sector_t *s0, const mad2_sector_t *s16, size_t dump_len,