Skip to content

Commit

Permalink
denote MAD sectors as decimal since public documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
iceman1001 committed Feb 21, 2025
1 parent 1cf9809 commit 717ceec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
7 changes: 0 additions & 7 deletions client/src/cmdhfmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ static char *GenerateFilename(const char *prefix, const char *suffix) {
// Each entry also stores whether the key was "found", defaults to false (0)
static int initSectorTable(sector_t **src, size_t items) {


// typedef struct {
// uint64_t Key[2];
// uint8_t foundKey[2];
// } sector_t;

// This allocates based on the size of a single item
(*src) = calloc(items, sizeof(sector_t));
if (*src == NULL) {
return PM3_EMALLOC;
Expand Down
13 changes: 12 additions & 1 deletion client/src/cmdhfmfdes.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,21 @@ typedef struct {
const char *comment;
} mfdesCommonAID_t;

/*
PACS application id(s) - HID Factory, CP1000 Standard, Mobile, Custom and Elite
We have HID Factory, Field Encoder == CP1000 (?)
No mobile, Custom or Elite
*/

static const mfdesCommonAID_t commonAids[] = {
// AID, name/comment
{ 0x53494F, "\x53\x49\x4F", "SIO DESFire EV1 - HID Factory" },
{ 0xD3494F, "\xD3\x49\x4F", "SIO DESFire EV1 - Field Encoder" },
{ 0xD9494F, "\xD9\x49\x4F", "SIO DESFire EV1 - Field Encoder" },
{ 0xF484E3, "\xF4\x84\xE3", "SE Enhanced" },
{ 0xF484E4, "\xF4\x84\xE4", "SE Enhanced" },
{ 0xF4812F, "\xf4\x81\x2f", "Gallagher card data application" },
{ 0xF48120, "\xf4\x81\x20", "Gallagher card application directory" }, // Can be 0xF48120 - 0xF4812B, but I've only ever seen 0xF48120
{ 0xF47300, "\xf4\x73\x00", "Inner Range card application" },
};

static int CmdHelp(const char *Cmd);
Expand Down
14 changes: 7 additions & 7 deletions client/src/cmdhfmfp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ static int CmdHFMFPMAD(const char *Cmd) {
}

uint8_t sector0[16 * 4] = {0};
uint8_t sector10[16 * 4] = {0};
uint8_t sector16[16 * 4] = {0};

if (mfpReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector0, verbose)) {
PrintAndLogEx(NORMAL, "");
Expand All @@ -1832,19 +1832,19 @@ static int CmdHFMFPMAD(const char *Cmd) {
MAD1DecodeAndPrint(sector0, swapmad, verbose, &haveMAD2);

if (haveMAD2) {
if (mfpReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector10, verbose)) {
if (mfpReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector16, verbose)) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(ERR, "error, read sector " _YELLOW_("0x10") ". Card doesn't have MAD or doesn't have MAD on default keys");
return PM3_ESOFT;
}

MAD2DecodeAndPrint(sector10, swapmad, verbose);
MAD2DecodeAndPrint(sector16, swapmad, verbose);
}

if (aidlen == 2 || decodeholder) {
uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};
size_t madlen = 0;
if (MADDecode(sector0, sector10, mad, &madlen, swapmad)) {
if (MADDecode(sector0, sector16, mad, &madlen, swapmad)) {
PrintAndLogEx(ERR, "can't decode MAD");
return PM3_EWRONGANSWER;
}
Expand Down Expand Up @@ -1990,7 +1990,7 @@ int CmdHFMFPNDEFRead(const char *Cmd) {
}

uint8_t sector0[MIFARE_1K_MAXBLOCK] = {0};
uint8_t sector10[MIFARE_1K_MAXBLOCK] = {0};
uint8_t sector16[MIFARE_1K_MAXBLOCK] = {0};
uint8_t data[MIFARE_4K_MAX_BYTES] = {0};
int datalen = 0;

Expand All @@ -2015,7 +2015,7 @@ int CmdHFMFPNDEFRead(const char *Cmd) {
if (verbose)
PrintAndLogEx(INFO, "reading MAD v2 sector");

if (mfpReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector10, verbose)) {
if (mfpReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector16, verbose)) {
PrintAndLogEx(ERR, "error, read sector 0x10. card doesn't have MAD or doesn't have MAD on default keys");
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfp ndefread -k `") " with your custom key");
return PM3_ESOFT;
Expand All @@ -2024,7 +2024,7 @@ int CmdHFMFPNDEFRead(const char *Cmd) {

uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};
size_t madlen = 0;
res = MADDecode(sector0, (haveMAD2 ? sector10 : NULL), mad, &madlen, false);
res = MADDecode(sector0, (haveMAD2 ? sector16 : NULL), mad, &madlen, false);
if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "can't decode MAD");
return res;
Expand Down

0 comments on commit 717ceec

Please # to comment.