Minor fixes, styles adaption

This commit is contained in:
Bjoern Kerler 2020-04-05 00:07:05 +02:00
commit 99838b958e

View file

@ -38,23 +38,25 @@ typedef enum {
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
static int SendDesfireCmd(uint8_t* c, int len, int flags, PacketResponseNG* response, int timeout)
{ static int SendDesfireCmd(uint8_t *c, size_t len, int p0, int p1, int p2, PacketResponseNG *response, int timeout) {
PacketResponseNG resp; PacketResponseNG resp;
if (response == NULL) if (response == NULL)
response = &resp; response = &resp;
SendCommandMIX(CMD_HF_DESFIRE_COMMAND, flags , len, 0, c, len); clearCommandBuffer();
SendCommandMIX(CMD_HF_DESFIRE_COMMAND, p0, p1, p2, c, len);
if (!WaitForResponseTimeout(CMD_ACK, response, timeout)) { if (!WaitForResponseTimeout(CMD_ACK, response, timeout)) {
PrintAndLogEx(WARNING, "[SendDesfireCmd] Timed-out: " _RED_("%s"), sprint_hex(c,sizeof(c))); PrintAndLogEx(WARNING, "[SendDesfireCmd] Timed-out: " _RED_("%s"), sprint_hex(c, len));
DropField(); DropField();
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
uint8_t isOK = response->oldarg[0] & 0xff; uint8_t isOK = response->data.asBytes[0] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, "[SendDesfireCmd] Unsuccessful: " _RED_("%s"), sprint_hex(c,sizeof(c))); PrintAndLogEx(WARNING, "[SendDesfireCmd] Unsuccessful: " _RED_("%s"), sprint_hex(c, len));
return PM3_ESOFT; return PM3_ESOFT;
} }
return PM3_SUCCESS; return PM3_SUCCESS;
@ -255,7 +257,7 @@ static int desfire_print_keysetting(uint8_t key_settings, uint8_t num_keys) {
static int get_desfire_keysettings(uint8_t *key_settings, uint8_t *num_keys) { static int get_desfire_keysettings(uint8_t *key_settings, uint8_t *num_keys) {
PacketResponseNG resp; PacketResponseNG resp;
uint8_t c[] = {MFDES_GET_KEY_SETTINGS, 0x00, 0x00, 0x00}; // 0x45 uint8_t c[] = {MFDES_GET_KEY_SETTINGS, 0x00, 0x00, 0x00}; // 0x45
int ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret != PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
if (resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0xae) { if (resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0xae) {
@ -278,7 +280,7 @@ static int desfire_print_keyversion(uint8_t key_idx, uint8_t key_version) {
static int get_desfire_keyversion(uint8_t curr_key, uint8_t *num_versions) { static int get_desfire_keyversion(uint8_t curr_key, uint8_t *num_versions) {
PacketResponseNG resp; PacketResponseNG resp;
uint8_t c[] = {MFDES_GET_KEY_VERSION, 0x00, 0x00, 0x01, curr_key, 0x00}; // 0x64 uint8_t c[] = {MFDES_GET_KEY_VERSION, 0x00, 0x00, 0x01, curr_key, 0x00}; // 0x64
int ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret != PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
if (resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0x40) { if (resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0x40) {
@ -296,11 +298,9 @@ static int get_desfire_select_application(uint8_t *aid) {
uint8_t c[] = {SELECT_APPLICATION, 0x00, 0x00, 0x03, aid[0], aid[1], aid[2], 0x00}; // 0x5a uint8_t c[] = {SELECT_APPLICATION, 0x00, 0x00, 0x03, aid[0], aid[1], aid[2], 0x00}; // 0x5a
PacketResponseNG resp; PacketResponseNG resp;
int ret=SendDesfireCmd(c, sizeof(c), INIT, &resp, 3000); int ret = SendDesfireCmd(c, sizeof(c), INIT, sizeof(c), 0, &resp, 3000);
if (ret!=PM3_SUCCESS) if (ret != PM3_SUCCESS) {
{ if (ret == PM3_ESOFT) {
if (ret==PM3_ESOFT)
{
PrintAndLogEx(WARNING, "[get_desfire_select_application] Can't select AID: " _RED_("%s"), sprint_hex(aid, 3)); PrintAndLogEx(WARNING, "[get_desfire_select_application] Can't select AID: " _RED_("%s"), sprint_hex(aid, 3));
} }
return ret; return ret;
@ -319,7 +319,7 @@ static int get_desfire_appids(uint8_t *dest, uint8_t *app_ids_len) {
uint8_t c[] = {GET_APPLICATION_IDS, 0x00, 0x00, 0x00}; //0x6a uint8_t c[] = {GET_APPLICATION_IDS, 0x00, 0x00, 0x00}; //0x6a
PacketResponseNG resp; PacketResponseNG resp;
int ret=SendDesfireCmd(c, sizeof(c), INIT | CLEARTRACE | DISCONNECT, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), INIT | CLEARTRACE | DISCONNECT, sizeof(c), 0, &resp, 1500);
if (ret != PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
*app_ids_len = resp.length - 5; *app_ids_len = resp.length - 5;
@ -330,7 +330,7 @@ static int get_desfire_appids(uint8_t *dest, uint8_t *app_ids_len) {
if (resp.data.asBytes[resp.length - 3] == MFDES_ADDITIONAL_FRAME) { if (resp.data.asBytes[resp.length - 3] == MFDES_ADDITIONAL_FRAME) {
c[0] = MFDES_ADDITIONAL_FRAME; //0xAF c[0] = MFDES_ADDITIONAL_FRAME; //0xAF
ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret != PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
memcpy(dest + *app_ids_len, resp.data.asBytes + 1, resp.length - 5); memcpy(dest + *app_ids_len, resp.data.asBytes + 1, resp.length - 5);
@ -345,7 +345,7 @@ static int get_desfire_appids(uint8_t *dest, uint8_t *app_ids_len) {
static int get_desfire_fileids(uint8_t *dest, uint8_t *file_ids_len) { static int get_desfire_fileids(uint8_t *dest, uint8_t *file_ids_len) {
uint8_t c[] = {MFDES_GET_FILE_IDS, 0x00, 0x00, 0x00}; // 0x6f uint8_t c[] = {MFDES_GET_FILE_IDS, 0x00, 0x00, 0x00}; // 0x6f
PacketResponseNG resp; PacketResponseNG resp;
int ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret != PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
if (resp.data.asBytes[resp.length - 4] == 0x91 && resp.data.asBytes[resp.length - 3] == 0x00) { if (resp.data.asBytes[resp.length - 4] == 0x91 && resp.data.asBytes[resp.length - 3] == 0x00) {