T55xx Save and Restore

This commit is contained in:
mwalker33 2019-10-11 20:29:20 +11:00
commit f109915ebd
2 changed files with 28 additions and 21 deletions

View file

@ -52,10 +52,10 @@ t55xx_conf_block_t config = {
.Q5 = false, .Q5 = false,
.usepwd = false, .usepwd = false,
.downlink_mode = refFixedBit, .downlink_mode = refFixedBit,
.blockData = {0}, // array to hold data blocks
.blockValid = {0} // array to hold data valid status
}; };
t55xx_memory_item_t cardmem[T55x7_BLOCK_COUNT] = {0};
t55xx_conf_block_t Get_t55xx_Config() { t55xx_conf_block_t Get_t55xx_Config() {
return config; return config;
} }
@ -360,14 +360,14 @@ static int CmdHelp(const char *Cmd);
void T55x7_SaveBlockData (uint8_t idx,uint32_t data) { void T55x7_SaveBlockData (uint8_t idx,uint32_t data) {
if (idx < T55x7_BLOCK_COUNT) { if (idx < T55x7_BLOCK_COUNT) {
config.blockValid[idx] = true; cardmem[idx].valid = true;
config.blockData[idx] = data; cardmem[idx].blockdata = data;
} }
} }
void T55x7_ClearAllBlockData (void) { void T55x7_ClearAllBlockData (void) {
for (uint8_t idx = 0; idx < T55x7_BLOCK_COUNT; idx++) { for (uint8_t idx = 0; idx < T55x7_BLOCK_COUNT; idx++) {
config.blockValid[idx] = false; cardmem[idx].valid = false;
config.blockData[idx] = 0x00; cardmem[idx].blockdata = 0x00;
} }
} }
@ -2261,8 +2261,8 @@ static int CmdT55xxDump(const char *Cmd) {
if (strcmp (preferredName,"") == 0) { // Set default filename, if not set by user if (strcmp (preferredName,"") == 0) { // Set default filename, if not set by user
strcpy (preferredName,"lf-t55xx"); strcpy (preferredName,"lf-t55xx");
for (uint8_t i = 1; i <= 7; i++) { for (uint8_t i = 1; i <= 7; i++) {
if ((config.blockData[i] != 0x00) && (config.blockData[i] != 0xFFFFFFFF)) if ((cardmem[i].blockdata != 0x00) && (cardmem[i].blockdata != 0xFFFFFFFF))
sprintf (preferredName,"%s-%08X",preferredName,config.blockData[i]); sprintf (preferredName,"%s-%08X",preferredName,cardmem[i].blockdata);
else else
break; break;
} }
@ -2273,7 +2273,7 @@ static int CmdT55xxDump(const char *Cmd) {
uint32_t data[T55x7_BLOCK_COUNT]; uint32_t data[T55x7_BLOCK_COUNT];
for (int i = 0; i < T55x7_BLOCK_COUNT; i++) for (int i = 0; i < T55x7_BLOCK_COUNT; i++)
data[i] = BSWAP_32(config.blockData[i]); data[i] = BSWAP_32(cardmem[i].blockdata);
saveFileEML(preferredName, (uint8_t *)data, T55x7_BLOCK_COUNT*sizeof(uint32_t), sizeof(uint32_t)); saveFileEML(preferredName, (uint8_t *)data, T55x7_BLOCK_COUNT*sizeof(uint32_t), sizeof(uint32_t));
saveFile (preferredName, ".bin", data, sizeof(data)); saveFile (preferredName, ".bin", data, sizeof(data));
@ -2327,19 +2327,24 @@ static int CmdT55xxRestore(const char *Cmd) {
fnLength = strlen (preferredName); fnLength = strlen (preferredName);
if (fnLength > 4) { // Holds .EXT [.bin|.eml] success = PM3_ESOFT;
if (fnLength > 4) { // Holds extension [.bin|.eml]
memcpy (ext,&preferredName[fnLength - 4],4); memcpy (ext,&preferredName[fnLength - 4],4);
ext[5] = 0x00; ext[5] = 0x00;
// check if valid file extension and attempt to load data
if (memcmp (ext,".bin",4) == 0) { if (memcmp (ext,".bin",4) == 0) {
preferredName[fnLength-4] = 0x00; preferredName[fnLength-4] = 0x00;
success = loadFile (preferredName, ".bin", data, sizeof(data),&datalen); success = loadFile (preferredName, ".bin", data, sizeof(data),&datalen);
}
if (memcmp (ext,".eml",4) == 0) { } else if (memcmp (ext,".eml",4) == 0) {
preferredName[fnLength-4] = 0x00; preferredName[fnLength-4] = 0x00;
datalen = 12; datalen = 12;
success = loadFileEML(preferredName, (uint8_t *)data, &datalen); success = loadFileEML(preferredName, (uint8_t *)data, &datalen);
}
} else
PrintAndLogEx(WARNING,"\nWarning: invalid dump filename "_YELLOW_("%s")"to restore!\n",preferredName);
} }
if (success == PM3_SUCCESS) { // Got data, so write to cards if (success == PM3_SUCCESS) { // Got data, so write to cards
@ -2390,7 +2395,7 @@ static int CmdT55xxRestore(const char *Cmd) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
/*
static int CmdT55xxRestore(const char *Cmd) { static int CmdT55xxRestore(const char *Cmd) {
uint32_t password = 0; uint32_t password = 0;
@ -2443,7 +2448,7 @@ static int CmdT55xxRestore(const char *Cmd) {
return res; return res;
} }
*/
bool AcquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password, uint8_t downlink_mode) { bool AcquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password, uint8_t downlink_mode) {
// arg0 bitmodes: // arg0 bitmodes:
// b0 = pwdmode // b0 = pwdmode
@ -3494,7 +3499,6 @@ static int CmdT55xxSetDeviceConfig(const char *Cmd) {
downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10);
if (downlink_mode > 3) if (downlink_mode > 3)
downlink_mode = 0; downlink_mode = 0;
cmdp += 2; cmdp += 2;
break; break;
case 'p': case 'p':
@ -3636,13 +3640,13 @@ static command_t CommandTable[] = {
{"detect", CmdT55xxDetect, AlwaysAvailable, "[1] Try detecting the tag modulation from reading the configuration block."}, {"detect", CmdT55xxDetect, AlwaysAvailable, "[1] Try detecting the tag modulation from reading the configuration block."},
{"deviceconfig", CmdT55xxSetDeviceConfig, IfPm3Lf, "Set/Get T55XX device configuration (startgap, writegap, write0, write1, readgap"}, {"deviceconfig", CmdT55xxSetDeviceConfig, IfPm3Lf, "Set/Get T55XX device configuration (startgap, writegap, write0, write1, readgap"},
{"dump", CmdT55xxDump, IfPm3Lf, "[password] [o] Dump T55xx card Page 0 block 0-7. Optional [password], [override]"}, {"dump", CmdT55xxDump, IfPm3Lf, "[password] [o] Dump T55xx card Page 0 block 0-7. Optional [password], [override]"},
{"restore", CmdT55xxRestore, IfPm3Lf, "f <filename> [p <password>] -- Restore a dump file of a T55xx card"}, {"restore", CmdT55xxRestore, IfPm3Lf, "f <filename> [p <password>] Restore T55xx card Page 0 / Page 1 blocks"},
{"info", CmdT55xxInfo, AlwaysAvailable, "[1] Show T55x7 configuration data (page 0/ blk 0)"}, {"info", CmdT55xxInfo, AlwaysAvailable, "[1] Show T55x7 configuration data (page 0/ blk 0)"},
{"p1detect", CmdT55xxDetectPage1, IfPm3Lf, "[1] Try detecting if this is a t55xx tag by reading page 1"}, {"p1detect", CmdT55xxDetectPage1, IfPm3Lf, "[1] Try detecting if this is a t55xx tag by reading page 1"},
{"protect", CmdT55xxProtect, IfPm3Lf, "Password protect tag"}, {"protect", CmdT55xxProtect, IfPm3Lf, "Password protect tag"},
{"read", CmdT55xxReadBlock, IfPm3Lf, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"}, {"read", CmdT55xxReadBlock, IfPm3Lf, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
{"resetread", CmdResetRead, IfPm3Lf, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"}, {"resetread", CmdResetRead, IfPm3Lf, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},
{"restore", CmdT55xxRestore, IfPm3Lf, "[password] Restore T55xx card Page 0 / Page 1 blocks"}, // {"restore", CmdT55xxRestore, IfPm3Lf, "[password] Restore T55xx card Page 0 / Page 1 blocks"},
{"recoverpw", CmdT55xxRecoverPW, IfPm3Lf, "[password] Try to recover from bad password write from a cloner. Only use on PW protected chips!"}, {"recoverpw", CmdT55xxRecoverPW, IfPm3Lf, "[password] Try to recover from bad password write from a cloner. Only use on PW protected chips!"},
{"special", special, IfPm3Lf, "Show block changes with 64 different offsets"}, {"special", special, IfPm3Lf, "Show block changes with 64 different offsets"},
{"trace", CmdT55xxReadTrace, AlwaysAvailable, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"}, {"trace", CmdT55xxReadTrace, AlwaysAvailable, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},

View file

@ -126,10 +126,13 @@ typedef struct {
refLeading0 = 0x02, refLeading0 = 0x02,
ref1of4 = 0x03, ref1of4 = 0x03,
} downlink_mode; } downlink_mode;
uint32_t blockData [T55x7_BLOCK_COUNT]; // the dump/read will save data here.
bool blockValid [T55x7_BLOCK_COUNT]; // this will allow easy access to the data for display etc.
} t55xx_conf_block_t; } t55xx_conf_block_t;
typedef struct {
uint32_t blockdata;
bool valid;
} t55xx_memory_item_t ;
t55xx_conf_block_t Get_t55xx_Config(void); t55xx_conf_block_t Get_t55xx_Config(void);
void Set_t55xx_Config(t55xx_conf_block_t conf); void Set_t55xx_Config(t55xx_conf_block_t conf);