new files

This commit is contained in:
tharexde 2020-09-24 23:05:11 +02:00
parent 5665de56e9
commit 9df747c3e1
2 changed files with 147 additions and 147 deletions

View file

@ -17,7 +17,7 @@
#include "crc16.h" #include "crc16.h"
#include "cmdhf14a.h" #include "cmdhf14a.h"
#include "protocols.h" // definitions of ISO14A/7816 protocol #include "protocols.h" // definitions of ISO14A/7816 protocol
#include "emv/apduinfo.h" // GetAPDUCodeDescription #include "emv/apduinfo.h" // GetAPDUCodeDescription
#include "mifare/ndef.h" // NDEFRecordsDecodeAndPrint #include "mifare/ndef.h" // NDEFRecordsDecodeAndPrint
#define TIMEOUT 2000 #define TIMEOUT 2000
@ -116,7 +116,7 @@ static char *get_st_chip_model(uint8_t pc) {
case 0xE3: case 0xE3:
sprintf(s, "ST25TA02KB"); sprintf(s, "ST25TA02KB");
break; break;
case 0xE4: case 0xE4:
sprintf(s, "ST25TA512B"); sprintf(s, "ST25TA512B");
break; break;
case 0xA3: case 0xA3:
@ -150,19 +150,19 @@ static void print_st_cc_info(uint8_t *d, uint8_t n) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "------------ " _CYAN_("Capability Container file") " ------------"); PrintAndLogEx(SUCCESS, "------------ " _CYAN_("Capability Container file") " ------------");
PrintAndLogEx(SUCCESS, " len %u bytes (" _GREEN_("0x%02X") ")", d[1],d[1]); PrintAndLogEx(SUCCESS, " len %u bytes (" _GREEN_("0x%02X") ")", d[1], d[1]);
PrintAndLogEx(SUCCESS, " version %s (" _GREEN_("0x%02X") ")", (d[2] == 0x20) ? "v2.0" : "v1.0", d[2]); PrintAndLogEx(SUCCESS, " version %s (" _GREEN_("0x%02X") ")", (d[2] == 0x20) ? "v2.0" : "v1.0", d[2]);
uint16_t maxr = (d[3] << 8 | d[4]); uint16_t maxr = (d[3] << 8 | d[4]);
PrintAndLogEx(SUCCESS, " max bytes read %u bytes ( 0x%04X )", maxr, maxr); PrintAndLogEx(SUCCESS, " max bytes read %u bytes ( 0x%04X )", maxr, maxr);
uint16_t maxw = (d[5] << 8 | d[6]); uint16_t maxw = (d[5] << 8 | d[6]);
PrintAndLogEx(SUCCESS, " max bytes write %u bytes ( 0x%04X )", maxw, maxw); PrintAndLogEx(SUCCESS, " max bytes write %u bytes ( 0x%04X )", maxw, maxw);
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, " NDEF file control TLV {"); PrintAndLogEx(SUCCESS, " NDEF file control TLV {");
PrintAndLogEx(SUCCESS, " (t) type of file ( %02X )", d[7]); PrintAndLogEx(SUCCESS, " (t) type of file ( %02X )", d[7]);
PrintAndLogEx(SUCCESS, " (v) ( %02X )", d[8]); PrintAndLogEx(SUCCESS, " (v) ( %02X )", d[8]);
PrintAndLogEx(SUCCESS, " file id ( %02X%02X )", d[9], d[10]); PrintAndLogEx(SUCCESS, " file id ( %02X%02X )", d[9], d[10]);
uint16_t maxndef = (d[11] << 8 | d[12]); uint16_t maxndef = (d[11] << 8 | d[12]);
PrintAndLogEx(SUCCESS, " max NDEF filesize %u bytes ( 0x%04X )", maxndef, maxndef); PrintAndLogEx(SUCCESS, " max NDEF filesize %u bytes ( 0x%04X )", maxndef, maxndef);
PrintAndLogEx(SUCCESS, " ----- " _CYAN_("access rights") " -------"); PrintAndLogEx(SUCCESS, " ----- " _CYAN_("access rights") " -------");
@ -178,11 +178,11 @@ static void print_st_system_info(uint8_t *d, uint8_t n) {
PrintAndLogEx(WARNING, "Not enought bytes read from system file"); PrintAndLogEx(WARNING, "Not enought bytes read from system file");
return; return;
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "------------ " _CYAN_("ST System file") " ------------"); PrintAndLogEx(SUCCESS, "------------ " _CYAN_("ST System file") " ------------");
uint16_t len = (d[0] << 8 | d[1]); uint16_t len = (d[0] << 8 | d[1]);
PrintAndLogEx(SUCCESS, " len %u bytes (" _GREEN_("0x%04X") ")", len, len); PrintAndLogEx(SUCCESS, " len %u bytes (" _GREEN_("0x%04X") ")", len, len);
if (d[2] == 0x80) { if (d[2] == 0x80) {
@ -191,29 +191,29 @@ static void print_st_system_info(uint8_t *d, uint8_t n) {
PrintAndLogEx(SUCCESS, " GPO Config ( 0x%02X )", d[2]); PrintAndLogEx(SUCCESS, " GPO Config ( 0x%02X )", d[2]);
PrintAndLogEx(SUCCESS, " config lock bit ( %s )", ((d[2] & 0x80) == 0x80) ? _RED_("locked") : _GREEN_("unlocked")); PrintAndLogEx(SUCCESS, " config lock bit ( %s )", ((d[2] & 0x80) == 0x80) ? _RED_("locked") : _GREEN_("unlocked"));
uint8_t conf = (d[2] & 0x70) >> 4; uint8_t conf = (d[2] & 0x70) >> 4;
switch(conf) { switch (conf) {
case 0: case 0:
PrintAndLogEx(SUCCESS, ""); PrintAndLogEx(SUCCESS, "");
break; break;
case 1: case 1:
PrintAndLogEx(SUCCESS, "Session opened"); PrintAndLogEx(SUCCESS, "Session opened");
break; break;
case 2: case 2:
PrintAndLogEx(SUCCESS, "WIP"); PrintAndLogEx(SUCCESS, "WIP");
break; break;
case 3: case 3:
PrintAndLogEx(SUCCESS, "MIP"); PrintAndLogEx(SUCCESS, "MIP");
break; break;
case 4: case 4:
PrintAndLogEx(SUCCESS, "Interrupt"); PrintAndLogEx(SUCCESS, "Interrupt");
break; break;
case 5: case 5:
PrintAndLogEx(SUCCESS, "State Control"); PrintAndLogEx(SUCCESS, "State Control");
break; break;
case 6: case 6:
PrintAndLogEx(SUCCESS, "RF Busy"); PrintAndLogEx(SUCCESS, "RF Busy");
break; break;
case 7: case 7:
PrintAndLogEx(SUCCESS, "Field Detect"); PrintAndLogEx(SUCCESS, "Field Detect");
break; break;
} }
@ -224,25 +224,25 @@ static void print_st_system_info(uint8_t *d, uint8_t n) {
PrintAndLogEx(SUCCESS, " counter ( %s )", ((d[3] & 0x02) == 0x02) ? _RED_("enabled") : _GREEN_("disable")); PrintAndLogEx(SUCCESS, " counter ( %s )", ((d[3] & 0x02) == 0x02) ? _RED_("enabled") : _GREEN_("disable"));
PrintAndLogEx(SUCCESS, " counter increment on ( %s )", ((d[3] & 0x01) == 0x01) ? _YELLOW_("write") : _YELLOW_("read")); PrintAndLogEx(SUCCESS, " counter increment on ( %s )", ((d[3] & 0x01) == 0x01) ? _YELLOW_("write") : _YELLOW_("read"));
uint32_t counter = (d[4] << 16 | d[5] << 8 | d[6]); uint32_t counter = (d[4] << 16 | d[5] << 8 | d[6]);
PrintAndLogEx(SUCCESS, " 20bit counter ( 0x%05X )", counter & 0xFFFFF); PrintAndLogEx(SUCCESS, " 20bit counter ( 0x%05X )", counter & 0xFFFFF);
PrintAndLogEx(SUCCESS, " Product version ( 0x%02X )", d[7]); PrintAndLogEx(SUCCESS, " Product version ( 0x%02X )", d[7]);
PrintAndLogEx(SUCCESS, " UID " _GREEN_("%s"), sprint_hex_inrow(d + 8, 7)); PrintAndLogEx(SUCCESS, " UID " _GREEN_("%s"), sprint_hex_inrow(d + 8, 7));
PrintAndLogEx(SUCCESS, " MFG 0x%02X, " _YELLOW_("%s"), d[8], getTagInfo(d[8])); PrintAndLogEx(SUCCESS, " MFG 0x%02X, " _YELLOW_("%s"), d[8], getTagInfo(d[8]));
PrintAndLogEx(SUCCESS, " Product Code 0x%02X, " _YELLOW_("%s"), d[9], get_st_chip_model(d[9])); PrintAndLogEx(SUCCESS, " Product Code 0x%02X, " _YELLOW_("%s"), d[9], get_st_chip_model(d[9]));
PrintAndLogEx(SUCCESS, " Device# " _YELLOW_("%s"), sprint_hex_inrow(d + 10, 5)); PrintAndLogEx(SUCCESS, " Device# " _YELLOW_("%s"), sprint_hex_inrow(d + 10, 5));
uint16_t mem = (d[0xF] << 8 | d[0x10]); uint16_t mem = (d[0xF] << 8 | d[0x10]);
PrintAndLogEx(SUCCESS, " Memory Size - 1 %u bytes (" _GREEN_("0x%04X") ")", mem, mem); PrintAndLogEx(SUCCESS, " Memory Size - 1 %u bytes (" _GREEN_("0x%04X") ")", mem, mem);
PrintAndLogEx(SUCCESS, " IC Reference code %u ( 0x%02X )", d[0x12], d[0x12]); PrintAndLogEx(SUCCESS, " IC Reference code %u ( 0x%02X )", d[0x12], d[0x12]);
PrintAndLogEx(SUCCESS, "----------------- " _CYAN_("raw") " -----------------"); PrintAndLogEx(SUCCESS, "----------------- " _CYAN_("raw") " -----------------");
PrintAndLogEx(SUCCESS, "%s", sprint_hex_inrow(d, n)); PrintAndLogEx(SUCCESS, "%s", sprint_hex_inrow(d, n));
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
/* /*
0012 0012
80000000001302E2007D0E8DCC 80000000001302E2007D0E8DCC
@ -252,7 +252,7 @@ static void print_st_system_info(uint8_t *d, uint8_t n) {
static uint16_t get_sw(uint8_t *d, uint8_t n) { static uint16_t get_sw(uint8_t *d, uint8_t n) {
if (n < 2) if (n < 2)
return 0; return 0;
n -= 2; n -= 2;
return d[n] * 0x0100 + d[n + 1]; return d[n] * 0x0100 + d[n + 1];
} }
@ -265,10 +265,10 @@ int infoHF_ST(void) {
uint8_t response[PM3_CMD_DATA_SIZE]; uint8_t response[PM3_CMD_DATA_SIZE];
int resplen = 0; int resplen = 0;
// --------------- Select NDEF Tag application ---------------- // --------------- Select NDEF Tag application ----------------
uint8_t aSELECT_AID[80]; uint8_t aSELECT_AID[80];
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -285,10 +285,10 @@ int infoHF_ST(void) {
activate_field = false; activate_field = false;
keep_field_on = true; keep_field_on = true;
// --------------- CC file reading ---------------- // --------------- CC file reading ----------------
uint8_t aSELECT_FILE_CC[30]; uint8_t aSELECT_FILE_CC[30];
int aSELECT_FILE_CC_n = 0; int aSELECT_FILE_CC_n = 0;
param_gethex_to_eol("00a4000c02e103", 0, aSELECT_FILE_CC, sizeof(aSELECT_FILE_CC), &aSELECT_FILE_CC_n); param_gethex_to_eol("00a4000c02e103", 0, aSELECT_FILE_CC, sizeof(aSELECT_FILE_CC), &aSELECT_FILE_CC_n);
res = ExchangeAPDU14a(aSELECT_FILE_CC, aSELECT_FILE_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_CC, aSELECT_FILE_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -298,10 +298,10 @@ int infoHF_ST(void) {
PrintAndLogEx(ERR, "Selecting CC file failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); PrintAndLogEx(ERR, "Selecting CC file failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return PM3_ESOFT; return PM3_ESOFT;
} }
uint8_t aREAD_CC[30]; uint8_t aREAD_CC[30];
int aREAD_CC_n = 0; int aREAD_CC_n = 0;
param_gethex_to_eol("00b000000f", 0, aREAD_CC, sizeof(aREAD_CC), &aREAD_CC_n); param_gethex_to_eol("00b000000f", 0, aREAD_CC, sizeof(aREAD_CC), &aREAD_CC_n);
res = ExchangeAPDU14a(aREAD_CC, aREAD_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aREAD_CC, aREAD_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -315,10 +315,10 @@ int infoHF_ST(void) {
print_st_cc_info(response, resplen - 2); print_st_cc_info(response, resplen - 2);
// --------------- System file reading ---------------- // --------------- System file reading ----------------
uint8_t aSELECT_FILE_SYS[30]; uint8_t aSELECT_FILE_SYS[30];
int aSELECT_FILE_SYS_n = 0; int aSELECT_FILE_SYS_n = 0;
param_gethex_to_eol("00a4000c02e101", 0, aSELECT_FILE_SYS, sizeof(aSELECT_FILE_SYS), &aSELECT_FILE_SYS_n); param_gethex_to_eol("00a4000c02e101", 0, aSELECT_FILE_SYS, sizeof(aSELECT_FILE_SYS), &aSELECT_FILE_SYS_n);
res = ExchangeAPDU14a(aSELECT_FILE_SYS, aSELECT_FILE_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_SYS, aSELECT_FILE_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -330,10 +330,10 @@ int infoHF_ST(void) {
} }
keep_field_on = false; keep_field_on = false;
uint8_t aREAD_SYS[30]; uint8_t aREAD_SYS[30];
int aREAD_SYS_n = 0; int aREAD_SYS_n = 0;
param_gethex_to_eol("00b0000012", 0, aREAD_SYS, sizeof(aREAD_SYS), &aREAD_SYS_n); param_gethex_to_eol("00b0000012", 0, aREAD_SYS, sizeof(aREAD_SYS), &aREAD_SYS_n);
res = ExchangeAPDU14a(aREAD_SYS, aREAD_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aREAD_SYS, aREAD_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -359,17 +359,17 @@ static int cmd_hf_st_sim(const char *Cmd) {
char c = tolower(param_getchar(Cmd, 0)); char c = tolower(param_getchar(Cmd, 0));
if (c == 'h' || c == 0x00) return usage_hf_st_sim(); if (c == 'h' || c == 0x00) return usage_hf_st_sim();
int uidlen = 0; int uidlen = 0;
uint8_t cmdp = 0; uint8_t cmdp = 0;
uint8_t uid[7] = {0}; uint8_t uid[7] = {0};
if (c == 'u') { if (c == 'u') {
param_gethex_ex(Cmd, cmdp + 1, uid, &uidlen); param_gethex_ex(Cmd, cmdp + 1, uid, &uidlen);
uidlen >>= 1; uidlen >>= 1;
if (uidlen != 7) { if (uidlen != 7) {
return usage_hf_st_sim(); return usage_hf_st_sim();
} }
} }
char param[40]; char param[40];
snprintf(param, sizeof(param), "t 10 u %s", sprint_hex_inrow(uid, uidlen)); snprintf(param, sizeof(param), "t 10 u %s", sprint_hex_inrow(uid, uidlen));
return CmdHF14ASim(param); return CmdHF14ASim(param);
@ -379,14 +379,14 @@ static int cmd_hf_st_ndef(const char *Cmd) {
char c = tolower(param_getchar(Cmd, 0)); char c = tolower(param_getchar(Cmd, 0));
if (c == 'h' || c == 0x00) return usage_hf_st_ndef(); if (c == 'h' || c == 0x00) return usage_hf_st_ndef();
int pwdlen = 0; int pwdlen = 0;
uint8_t cmdp = 0; uint8_t cmdp = 0;
uint8_t pwd[16] = {0}; uint8_t pwd[16] = {0};
if (c == 'p') { if (c == 'p') {
param_gethex_ex(Cmd, cmdp + 1, pwd, &pwdlen); param_gethex_ex(Cmd, cmdp + 1, pwd, &pwdlen);
pwdlen >>= 1; pwdlen >>= 1;
if (pwdlen != 16) { if (pwdlen != 16) {
return usage_hf_st_ndef(); return usage_hf_st_ndef();
} }
} }
@ -395,10 +395,10 @@ static int cmd_hf_st_ndef(const char *Cmd) {
uint8_t response[PM3_CMD_DATA_SIZE]; uint8_t response[PM3_CMD_DATA_SIZE];
int resplen = 0; int resplen = 0;
// --------------- Select NDEF Tag application ---------------- // --------------- Select NDEF Tag application ----------------
uint8_t aSELECT_AID[80]; uint8_t aSELECT_AID[80];
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -418,7 +418,7 @@ static int cmd_hf_st_ndef(const char *Cmd) {
// --------------- NDEF file reading ---------------- // --------------- NDEF file reading ----------------
uint8_t aSELECT_FILE_NDEF[30]; uint8_t aSELECT_FILE_NDEF[30];
int aSELECT_FILE_NDEF_n = 0; int aSELECT_FILE_NDEF_n = 0;
param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n); param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n);
res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -429,7 +429,7 @@ static int cmd_hf_st_ndef(const char *Cmd) {
return PM3_ESOFT; return PM3_ESOFT;
} }
// --------------- VERIFY ---------------- // --------------- VERIFY ----------------
uint8_t aVERIFY[30]; uint8_t aVERIFY[30];
int aVERIFY_n = 0; int aVERIFY_n = 0;
param_gethex_to_eol("0020000100", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n); param_gethex_to_eol("0020000100", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n);
@ -446,17 +446,17 @@ static int cmd_hf_st_ndef(const char *Cmd) {
if (res) if (res)
return res; return res;
sw = get_sw(response, resplen); sw = get_sw(response, resplen);
if (sw != 0x9000) { if (sw != 0x9000) {
PrintAndLogEx(ERR, "Verify password failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); PrintAndLogEx(ERR, "Verify password failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return PM3_ESOFT; return PM3_ESOFT;
} }
} }
keep_field_on = false; keep_field_on = false;
uint8_t aREAD_NDEF[30]; uint8_t aREAD_NDEF[30];
int aREAD_NDEF_n = 0; int aREAD_NDEF_n = 0;
param_gethex_to_eol("00b000001d", 0, aREAD_NDEF, sizeof(aREAD_NDEF), &aREAD_NDEF_n); param_gethex_to_eol("00b000001d", 0, aREAD_NDEF, sizeof(aREAD_NDEF), &aREAD_NDEF_n);
res = ExchangeAPDU14a(aREAD_NDEF, aREAD_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aREAD_NDEF, aREAD_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -472,23 +472,23 @@ static int cmd_hf_st_ndef(const char *Cmd) {
} }
static int cmd_hf_st_protect(const char *Cmd) { static int cmd_hf_st_protect(const char *Cmd) {
uint8_t cmdp = 0; uint8_t cmdp = 0;
bool errors = false; bool errors = false;
int pwdlen = 0; int pwdlen = 0;
uint8_t pwd[16] = {0}; uint8_t pwd[16] = {0};
int statelen = 3; int statelen = 3;
uint8_t state[3] = {0x26, 0, 0}; uint8_t state[3] = {0x26, 0, 0};
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) { switch (tolower(param_getchar(Cmd, cmdp))) {
case 'h': case 'h':
return usage_hf_st_protect(); return usage_hf_st_protect();
case '0': case '0':
state[0] = 0x26; //Disable protection state[0] = 0x26; //Disable protection
cmdp++; cmdp++;
break; break;
case '1': case '1':
state[0] = 0x28; //Enable protection state[0] = 0x28; //Enable protection
cmdp++; cmdp++;
break; break;
@ -515,14 +515,14 @@ static int cmd_hf_st_protect(const char *Cmd) {
//Validations //Validations
if (state[2] == 0x00) { if (state[2] == 0x00) {
PrintAndLogEx(WARNING, "Missing action (r)ead or (w)rite"); PrintAndLogEx(WARNING, "Missing action (r)ead or (w)rite");
errors = true; errors = true;
} }
if (pwdlen != 16) { if (pwdlen != 16) {
PrintAndLogEx(WARNING, "Missing 16 byte password"); PrintAndLogEx(WARNING, "Missing 16 byte password");
errors = true; errors = true;
} }
if (errors || cmdp == 0) return usage_hf_st_protect(); if (errors || cmdp == 0) return usage_hf_st_protect();
bool activate_field = true; bool activate_field = true;
@ -530,10 +530,10 @@ static int cmd_hf_st_protect(const char *Cmd) {
uint8_t response[PM3_CMD_DATA_SIZE]; uint8_t response[PM3_CMD_DATA_SIZE];
int resplen = 0; int resplen = 0;
// --------------- Select NDEF Tag application ---------------- // --------------- Select NDEF Tag application ----------------
uint8_t aSELECT_AID[80]; uint8_t aSELECT_AID[80];
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -553,7 +553,7 @@ static int cmd_hf_st_protect(const char *Cmd) {
// --------------- Select NDEF file ---------------- // --------------- Select NDEF file ----------------
uint8_t aSELECT_FILE_NDEF[30]; uint8_t aSELECT_FILE_NDEF[30];
int aSELECT_FILE_NDEF_n = 0; int aSELECT_FILE_NDEF_n = 0;
param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n); param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n);
res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -564,7 +564,7 @@ static int cmd_hf_st_protect(const char *Cmd) {
return PM3_ESOFT; return PM3_ESOFT;
} }
// --------------- VERIFY ---------------- // --------------- VERIFY ----------------
uint8_t aVERIFY[30]; uint8_t aVERIFY[30];
int aVERIFY_n = 0; int aVERIFY_n = 0;
// need to provide 16byte password // need to provide 16byte password
@ -574,12 +574,12 @@ static int cmd_hf_st_protect(const char *Cmd) {
if (res) if (res)
return res; return res;
sw = get_sw(response, resplen); sw = get_sw(response, resplen);
if (sw != 0x9000) { if (sw != 0x9000) {
PrintAndLogEx(ERR, "Verify password failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); PrintAndLogEx(ERR, "Verify password failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return PM3_ESOFT; return PM3_ESOFT;
} }
// --------------- Change protection ---------------- // --------------- Change protection ----------------
keep_field_on = false; keep_field_on = false;
uint8_t aPROTECT[30]; uint8_t aPROTECT[30];
@ -595,9 +595,9 @@ static int cmd_hf_st_protect(const char *Cmd) {
PrintAndLogEx(ERR, "changing protection failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); PrintAndLogEx(ERR, "changing protection failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintAndLogEx(SUCCESS, " %s protection ( %s )", ((state[2] & 0x01) == 0x01) ? _YELLOW_("read") : _YELLOW_("write"), PrintAndLogEx(SUCCESS, " %s protection ( %s )", ((state[2] & 0x01) == 0x01) ? _YELLOW_("read") : _YELLOW_("write"),
((state[0] & 0x28) == 0x28) ? _RED_("enabled") : _GREEN_("disabled")); ((state[0] & 0x28) == 0x28) ? _RED_("enabled") : _GREEN_("disabled"));
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -608,9 +608,9 @@ static int cmd_hf_st_pwd(const char *Cmd) {
uint8_t cmdp = 0; uint8_t cmdp = 0;
bool errors = false; bool errors = false;
int pwdlen = 0; int pwdlen = 0;
uint8_t pwd[16] = {0}; uint8_t pwd[16] = {0};
int newpwdlen = 0; int newpwdlen = 0;
uint8_t newpwd[16] = {0}; uint8_t newpwd[16] = {0};
int changePwdlen = 4; int changePwdlen = 4;
uint8_t changePwd[4] = {0x24, 0x00, 0x00, 0x10}; uint8_t changePwd[4] = {0x24, 0x00, 0x00, 0x10};
@ -647,17 +647,17 @@ static int cmd_hf_st_pwd(const char *Cmd) {
//Validations //Validations
if (changePwd[2] == 0x00) { if (changePwd[2] == 0x00) {
PrintAndLogEx(WARNING, "Missing password specification: (r)ead or (w)rite"); PrintAndLogEx(WARNING, "Missing password specification: (r)ead or (w)rite");
errors = true; errors = true;
} }
if (pwdlen != 16) { if (pwdlen != 16) {
PrintAndLogEx(WARNING, "Missing original 16 byte password"); PrintAndLogEx(WARNING, "Missing original 16 byte password");
errors = true; errors = true;
} }
if (newpwdlen != 16) { if (newpwdlen != 16) {
PrintAndLogEx(WARNING, "Missing new 16 byte password"); PrintAndLogEx(WARNING, "Missing new 16 byte password");
errors = true; errors = true;
} }
if (errors || cmdp == 0) return usage_hf_st_pwd(); if (errors || cmdp == 0) return usage_hf_st_pwd();
bool activate_field = true; bool activate_field = true;
@ -665,10 +665,10 @@ static int cmd_hf_st_pwd(const char *Cmd) {
uint8_t response[PM3_CMD_DATA_SIZE]; uint8_t response[PM3_CMD_DATA_SIZE];
int resplen = 0; int resplen = 0;
// --------------- Select NDEF Tag application ---------------- // --------------- Select NDEF Tag application ----------------
uint8_t aSELECT_AID[80]; uint8_t aSELECT_AID[80];
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -688,7 +688,7 @@ static int cmd_hf_st_pwd(const char *Cmd) {
// --------------- Select NDEF file ---------------- // --------------- Select NDEF file ----------------
uint8_t aSELECT_FILE_NDEF[30]; uint8_t aSELECT_FILE_NDEF[30];
int aSELECT_FILE_NDEF_n = 0; int aSELECT_FILE_NDEF_n = 0;
param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n); param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n);
res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) if (res)
return res; return res;
@ -699,7 +699,7 @@ static int cmd_hf_st_pwd(const char *Cmd) {
return PM3_ESOFT; return PM3_ESOFT;
} }
// --------------- VERIFY ---------------- // --------------- VERIFY ----------------
uint8_t aVERIFY[30]; uint8_t aVERIFY[30];
int aVERIFY_n = 0; int aVERIFY_n = 0;
// need to provide 16byte password // need to provide 16byte password
@ -709,7 +709,7 @@ static int cmd_hf_st_pwd(const char *Cmd) {
if (res) if (res)
return res; return res;
sw = get_sw(response, resplen); sw = get_sw(response, resplen);
if (sw != 0x9000) { if (sw != 0x9000) {
PrintAndLogEx(ERR, "Verify password failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); PrintAndLogEx(ERR, "Verify password failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return PM3_ESOFT; return PM3_ESOFT;
@ -720,7 +720,7 @@ static int cmd_hf_st_pwd(const char *Cmd) {
keep_field_on = false; keep_field_on = false;
uint8_t aCHG_PWD[30]; uint8_t aCHG_PWD[30];
int aCHG_PWD_n = 0; int aCHG_PWD_n = 0;
param_gethex_to_eol("00", 0, aCHG_PWD, sizeof(aCHG_PWD), &aCHG_PWD_n); param_gethex_to_eol("00", 0, aCHG_PWD, sizeof(aCHG_PWD), &aCHG_PWD_n);
memcpy(aCHG_PWD + aCHG_PWD_n, changePwd, changePwdlen); memcpy(aCHG_PWD + aCHG_PWD_n, changePwd, changePwdlen);
memcpy(aCHG_PWD + aCHG_PWD_n + changePwdlen, newpwd, newpwdlen); memcpy(aCHG_PWD + aCHG_PWD_n + changePwdlen, newpwd, newpwdlen);
res = ExchangeAPDU14a(aCHG_PWD, aCHG_PWD_n + changePwdlen + newpwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aCHG_PWD, aCHG_PWD_n + changePwdlen + newpwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen);

View file

@ -97,7 +97,7 @@ static int usage_hf_waveshare_loadbmp(void) {
PrintAndLogEx(NORMAL, " f <fn> : " _YELLOW_("filename[.bmp]") " to upload to tag"); PrintAndLogEx(NORMAL, " f <fn> : " _YELLOW_("filename[.bmp]") " to upload to tag");
PrintAndLogEx(NORMAL, " m <nr> : " _YELLOW_("model number") " of your tag"); PrintAndLogEx(NORMAL, " m <nr> : " _YELLOW_("model number") " of your tag");
PrintAndLogEx(NORMAL, " s : save dithered version in filename-[n].bmp, only for RGB BMP"); PrintAndLogEx(NORMAL, " s : save dithered version in filename-[n].bmp, only for RGB BMP");
for (uint8_t i=0; i< MEND; i++) { for (uint8_t i = 0; i < MEND; i++) {
PrintAndLogEx(NORMAL, " m %2i : %s", i, models[i].desc); PrintAndLogEx(NORMAL, " m %2i : %s", i, models[i].desc);
} }
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
@ -168,8 +168,8 @@ static int read_bmp_bitmap(const uint8_t *bmp, const size_t bmpsize, uint8_t mod
} }
static void rgb_to_gray(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height, int16_t *chanGrey) { static void rgb_to_gray(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height, int16_t *chanGrey) {
for (uint16_t Y=0; Y<height; Y++) { for (uint16_t Y = 0; Y < height; Y++) {
for (uint16_t X=0; X<width; X++) { for (uint16_t X = 0; X < width; X++) {
// greyscale conversion // greyscale conversion
float Clinear = 0.2126 * chanR[X + Y * width] + 0.7152 * chanG[X + Y * width] + 0.0722 * chanB[X + Y * width]; float Clinear = 0.2126 * chanR[X + Y * width] + 0.7152 * chanG[X + Y * width] + 0.0722 * chanB[X + Y * width];
// Csrgb = 12.92 Clinear when Clinear <= 0.0031308 // Csrgb = 12.92 Clinear when Clinear <= 0.0031308
@ -181,24 +181,24 @@ static void rgb_to_gray(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t
// Floyd-Steinberg dithering // Floyd-Steinberg dithering
static void dither_chan_inplace(int16_t *chan, uint16_t width, uint16_t height) { static void dither_chan_inplace(int16_t *chan, uint16_t width, uint16_t height) {
for (uint16_t Y=0; Y<height; Y++) { for (uint16_t Y = 0; Y < height; Y++) {
for (uint16_t X=0; X<width; X++) { for (uint16_t X = 0; X < width; X++) {
int16_t oldp = chan[X + Y * width]; int16_t oldp = chan[X + Y * width];
int16_t newp = oldp > 127 ? 255 : 0; int16_t newp = oldp > 127 ? 255 : 0;
chan[X + Y * width] = newp; chan[X + Y * width] = newp;
int16_t err = oldp - newp; int16_t err = oldp - newp;
float m[] = {7,3,5,1}; float m[] = {7, 3, 5, 1};
if (X < width - 1){ if (X < width - 1) {
chan[X + 1 + Y * width] = chan[X + 1 + Y * width] + m[0]/16 * err; chan[X + 1 + Y * width] = chan[X + 1 + Y * width] + m[0] / 16 * err;
} }
if (Y < height - 1) { if (Y < height - 1) {
chan[X - 1 + (Y + 1) * width] = chan[X - 1 + (Y + 1) * width] + m[1]/16 * err; chan[X - 1 + (Y + 1) * width] = chan[X - 1 + (Y + 1) * width] + m[1] / 16 * err;
} }
if (Y < height - 1){ if (Y < height - 1) {
chan[X + (Y + 1) * width] = chan[X + (Y + 1) * width] + m[2]/16 * err; chan[X + (Y + 1) * width] = chan[X + (Y + 1) * width] + m[2] / 16 * err;
} }
if ((X < width - 1) && (Y < height - 1)){ if ((X < width - 1) && (Y < height - 1)) {
chan[X + 1 + (Y + 1) * width] = chan[X + 1 + (Y + 1) * width] + m[3]/16 * err; chan[X + 1 + (Y + 1) * width] = chan[X + 1 + (Y + 1) * width] + m[3] / 16 * err;
} }
} }
} }
@ -210,16 +210,16 @@ static uint32_t color_compare(int16_t r1, int16_t g1, int16_t b1, int16_t r2, in
int16_t inG = g1 - g2; int16_t inG = g1 - g2;
int16_t inB = b1 - b2; int16_t inB = b1 - b2;
// use RGB-to-grey weighting // use RGB-to-grey weighting
float dist = 0.2126 *inR*inR + 0.7152 *inG*inG + 0.0722 *inB*inB; float dist = 0.2126 * inR * inR + 0.7152 * inG * inG + 0.0722 * inB * inB;
return dist; return dist;
} }
static void nearest_color(int16_t oldR, int16_t oldG, int16_t oldB, uint8_t *palette, uint16_t palettelen, uint8_t *newR, uint8_t *newG, uint8_t *newB) { static void nearest_color(int16_t oldR, int16_t oldG, int16_t oldB, uint8_t *palette, uint16_t palettelen, uint8_t *newR, uint8_t *newG, uint8_t *newB) {
uint32_t bestdist=0x7FFFFFFF; uint32_t bestdist = 0x7FFFFFFF;
for (uint16_t i=0; i < palettelen; i++) { for (uint16_t i = 0; i < palettelen; i++) {
uint8_t R = palette[i*3+0]; uint8_t R = palette[i * 3 + 0];
uint8_t G = palette[i*3+1]; uint8_t G = palette[i * 3 + 1];
uint8_t B = palette[i*3+2]; uint8_t B = palette[i * 3 + 2];
uint32_t dist = color_compare(oldR, oldG, oldB, R, G, B); uint32_t dist = color_compare(oldR, oldG, oldB, R, G, B);
if (dist < bestdist) { if (dist < bestdist) {
bestdist = dist; bestdist = dist;
@ -231,8 +231,8 @@ static void nearest_color(int16_t oldR, int16_t oldG, int16_t oldB, uint8_t *pal
} }
static void dither_rgb_inplace(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height, uint8_t *palette, uint16_t palettelen) { static void dither_rgb_inplace(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height, uint8_t *palette, uint16_t palettelen) {
for (uint16_t Y=0; Y<height; Y++) { for (uint16_t Y = 0; Y < height; Y++) {
for (uint16_t X=0; X<width; X++) { for (uint16_t X = 0; X < width; X++) {
// scan odd lines in the opposite direction // scan odd lines in the opposite direction
uint16_t XX = X; uint16_t XX = X;
if (Y % 2) { if (Y % 2) {
@ -249,48 +249,48 @@ static void dither_rgb_inplace(int16_t *chanR, int16_t *chanG, int16_t *chanB, u
int16_t errR = oldR - newR; int16_t errR = oldR - newR;
int16_t errG = oldG - newG; int16_t errG = oldG - newG;
int16_t errB = oldB - newB; int16_t errB = oldB - newB;
float m[]={7,3,5,1}; float m[] = {7, 3, 5, 1};
if (Y % 2) { if (Y % 2) {
if (XX > 0) { if (XX > 0) {
chanR[XX - 1 + Y * width] = (chanR[XX - 1 + Y * width] + m[0]/16 * errR); chanR[XX - 1 + Y * width] = (chanR[XX - 1 + Y * width] + m[0] / 16 * errR);
chanG[XX - 1 + Y * width] = (chanG[XX - 1 + Y * width] + m[0]/16 * errG); chanG[XX - 1 + Y * width] = (chanG[XX - 1 + Y * width] + m[0] / 16 * errG);
chanB[XX - 1 + Y * width] = (chanB[XX - 1 + Y * width] + m[0]/16 * errB); chanB[XX - 1 + Y * width] = (chanB[XX - 1 + Y * width] + m[0] / 16 * errB);
} }
if (Y < height - 1) { if (Y < height - 1) {
chanR[XX - 1 + (Y + 1) * width] = (chanR[XX - 1 + (Y + 1) * width] + m[3]/16 * errR); chanR[XX - 1 + (Y + 1) * width] = (chanR[XX - 1 + (Y + 1) * width] + m[3] / 16 * errR);
chanG[XX - 1 + (Y + 1) * width] = (chanG[XX - 1 + (Y + 1) * width] + m[3]/16 * errG); chanG[XX - 1 + (Y + 1) * width] = (chanG[XX - 1 + (Y + 1) * width] + m[3] / 16 * errG);
chanB[XX - 1 + (Y + 1) * width] = (chanB[XX - 1 + (Y + 1) * width] + m[3]/16 * errB); chanB[XX - 1 + (Y + 1) * width] = (chanB[XX - 1 + (Y + 1) * width] + m[3] / 16 * errB);
} }
if (Y < height - 1) { if (Y < height - 1) {
chanR[XX + (Y + 1) * width] = (chanR[XX + (Y + 1) * width] + m[2]/16 * errR); chanR[XX + (Y + 1) * width] = (chanR[XX + (Y + 1) * width] + m[2] / 16 * errR);
chanG[XX + (Y + 1) * width] = (chanG[XX + (Y + 1) * width] + m[2]/16 * errG); chanG[XX + (Y + 1) * width] = (chanG[XX + (Y + 1) * width] + m[2] / 16 * errG);
chanB[XX + (Y + 1) * width] = (chanB[XX + (Y + 1) * width] + m[2]/16 * errB); chanB[XX + (Y + 1) * width] = (chanB[XX + (Y + 1) * width] + m[2] / 16 * errB);
} }
if ((XX < width - 1) && (Y < height - 1)) { if ((XX < width - 1) && (Y < height - 1)) {
chanR[XX + 1 + (Y + 1) * width] = (chanR[XX + 1 + (Y + 1) * width] + m[1]/16 * errR); chanR[XX + 1 + (Y + 1) * width] = (chanR[XX + 1 + (Y + 1) * width] + m[1] / 16 * errR);
chanG[XX + 1 + (Y + 1) * width] = (chanG[XX + 1 + (Y + 1) * width] + m[1]/16 * errG); chanG[XX + 1 + (Y + 1) * width] = (chanG[XX + 1 + (Y + 1) * width] + m[1] / 16 * errG);
chanB[XX + 1 + (Y + 1) * width] = (chanB[XX + 1 + (Y + 1) * width] + m[1]/16 * errB); chanB[XX + 1 + (Y + 1) * width] = (chanB[XX + 1 + (Y + 1) * width] + m[1] / 16 * errB);
} }
} else { } else {
if (XX < width - 1) { if (XX < width - 1) {
chanR[XX + 1 + Y * width] = (chanR[XX + 1 + Y * width] + m[0]/16 * errR); chanR[XX + 1 + Y * width] = (chanR[XX + 1 + Y * width] + m[0] / 16 * errR);
chanG[XX + 1 + Y * width] = (chanG[XX + 1 + Y * width] + m[0]/16 * errG); chanG[XX + 1 + Y * width] = (chanG[XX + 1 + Y * width] + m[0] / 16 * errG);
chanB[XX + 1 + Y * width] = (chanB[XX + 1 + Y * width] + m[0]/16 * errB); chanB[XX + 1 + Y * width] = (chanB[XX + 1 + Y * width] + m[0] / 16 * errB);
} }
if (Y < height - 1) { if (Y < height - 1) {
chanR[XX - 1 + (Y + 1) * width] = (chanR[XX - 1 + (Y + 1) * width] + m[1]/16 * errR); chanR[XX - 1 + (Y + 1) * width] = (chanR[XX - 1 + (Y + 1) * width] + m[1] / 16 * errR);
chanG[XX - 1 + (Y + 1) * width] = (chanG[XX - 1 + (Y + 1) * width] + m[1]/16 * errG); chanG[XX - 1 + (Y + 1) * width] = (chanG[XX - 1 + (Y + 1) * width] + m[1] / 16 * errG);
chanB[XX - 1 + (Y + 1) * width] = (chanB[XX - 1 + (Y + 1) * width] + m[1]/16 * errB); chanB[XX - 1 + (Y + 1) * width] = (chanB[XX - 1 + (Y + 1) * width] + m[1] / 16 * errB);
} }
if (Y < height - 1) { if (Y < height - 1) {
chanR[XX + (Y + 1) * width] = (chanR[XX + (Y + 1) * width] + m[2]/16 * errR); chanR[XX + (Y + 1) * width] = (chanR[XX + (Y + 1) * width] + m[2] / 16 * errR);
chanG[XX + (Y + 1) * width] = (chanG[XX + (Y + 1) * width] + m[2]/16 * errG); chanG[XX + (Y + 1) * width] = (chanG[XX + (Y + 1) * width] + m[2] / 16 * errG);
chanB[XX + (Y + 1) * width] = (chanB[XX + (Y + 1) * width] + m[2]/16 * errB); chanB[XX + (Y + 1) * width] = (chanB[XX + (Y + 1) * width] + m[2] / 16 * errB);
} }
if ((XX < width - 1) && (Y < height - 1)) { if ((XX < width - 1) && (Y < height - 1)) {
chanR[XX + 1 + (Y + 1) * width] = (chanR[XX + 1 + (Y + 1) * width] + m[3]/16 * errR); chanR[XX + 1 + (Y + 1) * width] = (chanR[XX + 1 + (Y + 1) * width] + m[3] / 16 * errR);
chanG[XX + 1 + (Y + 1) * width] = (chanG[XX + 1 + (Y + 1) * width] + m[3]/16 * errG); chanG[XX + 1 + (Y + 1) * width] = (chanG[XX + 1 + (Y + 1) * width] + m[3] / 16 * errG);
chanB[XX + 1 + (Y + 1) * width] = (chanB[XX + 1 + (Y + 1) * width] + m[3]/16 * errB); chanB[XX + 1 + (Y + 1) * width] = (chanB[XX + 1 + (Y + 1) * width] + m[3] / 16 * errB);
} }
} }
} }
@ -298,8 +298,8 @@ static void dither_rgb_inplace(int16_t *chanR, int16_t *chanG, int16_t *chanB, u
} }
static void rgb_to_gray_red_inplace(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height) { static void rgb_to_gray_red_inplace(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height) {
for (uint16_t Y=0; Y<height; Y++) { for (uint16_t Y = 0; Y < height; Y++) {
for (uint16_t X=0; X<width; X++) { for (uint16_t X = 0; X < width; X++) {
float Clinear = 0.2126 * chanR[X + Y * width] + 0.7152 * chanG[X + Y * width] + 0.0722 * chanB[X + Y * width]; float Clinear = 0.2126 * chanR[X + Y * width] + 0.7152 * chanG[X + Y * width] + 0.0722 * chanB[X + Y * width];
if ((chanR[X + Y * width] < chanG[X + Y * width] && chanR[X + Y * width] < chanB[X + Y * width])) { if ((chanR[X + Y * width] < chanG[X + Y * width] && chanR[X + Y * width] < chanB[X + Y * width])) {
chanR[X + Y * width] = Clinear; chanR[X + Y * width] = Clinear;
@ -311,16 +311,16 @@ static void rgb_to_gray_red_inplace(int16_t *chanR, int16_t *chanG, int16_t *cha
} }
static void threshold_chan(int16_t *colorchan, uint16_t width, uint16_t height, uint8_t threshold, uint8_t *colormap) { static void threshold_chan(int16_t *colorchan, uint16_t width, uint16_t height, uint8_t threshold, uint8_t *colormap) {
for (uint16_t Y=0; Y<height; Y++) { for (uint16_t Y = 0; Y < height; Y++) {
for (uint16_t X=0; X<width; X++) { for (uint16_t X = 0; X < width; X++) {
colormap[X + Y * width] = colorchan[X + Y * width] < threshold; colormap[X + Y * width] = colorchan[X + Y * width] < threshold;
} }
} }
} }
static void threshold_rgb_black_red(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height, uint8_t threshold_black, uint8_t threshold_red, uint8_t *blackmap, uint8_t *redmap) { static void threshold_rgb_black_red(int16_t *chanR, int16_t *chanG, int16_t *chanB, uint16_t width, uint16_t height, uint8_t threshold_black, uint8_t threshold_red, uint8_t *blackmap, uint8_t *redmap) {
for (uint16_t Y=0; Y<height; Y++) { for (uint16_t Y = 0; Y < height; Y++) {
for (uint16_t X=0; X<width; X++) { for (uint16_t X = 0; X < width; X++) {
if ((chanR[X + Y * width] < threshold_black) && (chanG[X + Y * width] < threshold_black) && (chanB[X + Y * width] < threshold_black)) { if ((chanR[X + Y * width] < threshold_black) && (chanG[X + Y * width] < threshold_black) && (chanB[X + Y * width] < threshold_black)) {
blackmap[X + Y * width] = 1; blackmap[X + Y * width] = 1;
redmap[X + Y * width] = 0; redmap[X + Y * width] = 0;
@ -344,16 +344,16 @@ static void map8to1(uint8_t *colormap, uint16_t width, uint16_t height, uint8_t
} }
uint8_t data = 0; uint8_t data = 0;
uint8_t count = 0; uint8_t count = 0;
for (uint16_t Y=0; Y<height; Y++) { for (uint16_t Y = 0; Y < height; Y++) {
for (uint16_t X=0; X<width; X++) { for (uint16_t X = 0; X < width; X++) {
data = data | colormap[X + Y * width]; data = data | colormap[X + Y * width];
count+=1; count += 1;
if ((count >= 8) || (X == width - 1)) { if ((count >= 8) || (X == width - 1)) {
colormap8[X / 8 + Y * width8] = (~data)&0xFF; colormap8[X / 8 + Y * width8] = (~data) & 0xFF;
count = 0; count = 0;
data = 0; data = 0;
} }
data = (data << 1)&0xFF; data = (data << 1) & 0xFF;
} }
} }
} }
@ -430,8 +430,8 @@ static int read_bmp_rgb(uint8_t *bmp, const size_t bmpsize, uint8_t model_nr, ui
} }
rgb_to_gray_red_inplace(chanR, chanG, chanB, width, height); rgb_to_gray_red_inplace(chanR, chanG, chanB, width, height);
uint8_t palette[] ={0x00,0x00,0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}; // black, white, red uint8_t palette[] = {0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}; // black, white, red
dither_rgb_inplace(chanR, chanG, chanB, width, height, palette, sizeof(palette)/3); dither_rgb_inplace(chanR, chanG, chanB, width, height, palette, sizeof(palette) / 3);
threshold_rgb_black_red(chanR, chanG, chanB, width, height, 128, 128, mapBlack, mapRed); threshold_rgb_black_red(chanR, chanG, chanB, width, height, 128, 128, mapBlack, mapRed);
if (save_conversions) { if (save_conversions) {
@ -552,7 +552,7 @@ static void read_red(uint32_t i, uint8_t *l, uint8_t model_nr, uint8_t *red) {
} }
} }
static int transceive_blocking( uint8_t* txBuf, uint16_t txBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* actLen, bool retransmit ){ static int transceive_blocking(uint8_t *txBuf, uint16_t txBufLen, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *actLen, bool retransmit) {
uint8_t fail_num = 0; uint8_t fail_num = 0;
if (rxBufLen < 2) { if (rxBufLen < 2) {
return PM3_EINVARG; return PM3_EINVARG;
@ -863,7 +863,7 @@ static int start_drawing(uint8_t model_nr, uint8_t *black, uint8_t *red) {
} else if (model_nr == M2in7) { //2.7inch } else if (model_nr == M2in7) { //2.7inch
for (i = 0; i < 48; i++) { for (i = 0; i < 48; i++) {
//read_black(i,step8, model_nr, black); //read_black(i,step8, model_nr, black);
memset(&step8[3], 0xFF, sizeof(step8)-3); memset(&step8[3], 0xFF, sizeof(step8) - 3);
ret = transceive_blocking(step8, 124, rx, 20, actrxlen, true); // cd 08 ret = transceive_blocking(step8, 124, rx, 20, actrxlen, true); // cd 08
if (ret != PM3_SUCCESS) { if (ret != PM3_SUCCESS) {
return ret; return ret;