X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/8f51ddb0bd8fb7536a07966433061f03d45f65e0..7847961b25c507b5a291c8ddb9aa1c1b222a4b11:/armsrc/mifareutil.c?ds=sidebyside diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index 89708135..a88f21bc 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -339,19 +339,73 @@ void emlGetMemBt(uint8_t *data, int bytePtr, int byteCount) { memcpy(data, emCARD + bytePtr, byteCount); } +int emlCheckValBl(int blockNum) { + uint8_t* emCARD = eml_get_bigbufptr_cardmem(); + uint8_t* data = emCARD + blockNum * 16; + + if ((data[0] != (data[4] ^ 0xff)) || (data[0] != data[8]) || + (data[1] != (data[5] ^ 0xff)) || (data[1] != data[9]) || + (data[2] != (data[6] ^ 0xff)) || (data[2] != data[10]) || + (data[3] != (data[7] ^ 0xff)) || (data[3] != data[11]) || + (data[12] != (data[13] ^ 0xff)) || (data[12] != data[14]) || + (data[12] != (data[15] ^ 0xff)) + ) + return 1; + return 0; +} + +int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum) { + uint8_t* emCARD = eml_get_bigbufptr_cardmem(); + uint8_t* data = emCARD + blockNum * 16; + + if (emlCheckValBl(blockNum)) { + return 1; + } + + memcpy(blReg, data, 4); + *blBlock = data[12]; + + return 0; +} + +int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum) { + uint8_t* emCARD = eml_get_bigbufptr_cardmem(); + uint8_t* data = emCARD + blockNum * 16; + + memcpy(data + 0, &blReg, 4); + memcpy(data + 8, &blReg, 4); + blReg = blReg ^ 0xffffffff; + memcpy(data + 4, &blReg, 4); + + data[12] = blBlock; + data[13] = blBlock ^ 0xff; + data[14] = blBlock; + data[15] = blBlock ^ 0xff; + + return 0; +} + +uint64_t emlGetKey(int sectorNum, int keyType) { + uint8_t key[6]; + uint8_t* emCARD = eml_get_bigbufptr_cardmem(); + + memcpy(key, emCARD + 3 * 16 + sectorNum * 4 * 16 + keyType * 10, 6); + return bytes_to_num(key, 6); +} + void emlClearMem(void) { - int i; + int b; const uint8_t trailer[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x80, 0x69, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - const uint8_t empty[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; const uint8_t uid[] = {0xe6, 0x84, 0x87, 0xf3, 0x16, 0x88, 0x04, 0x00, 0x46, 0x8e, 0x45, 0x55, 0x4d, 0x70, 0x41, 0x04}; - // fill sectors data - for(i = 0; i < 16; i++) { - emlSetMem((uint8_t *)empty, i * 4 + 0, 1); - emlSetMem((uint8_t *)empty, i * 4 + 1, 1); - emlSetMem((uint8_t *)empty, i * 4 + 2, 1); - emlSetMem((uint8_t *)trailer, i * 4 + 3, 1); - } + uint8_t* emCARD = eml_get_bigbufptr_cardmem(); + + memset(emCARD, 0, CARD_MEMORY_LEN); + + // fill sectors trailer data + for(b = 3; b < 256; b<127?(b+=4):(b+=16)) { + emlSetMem((uint8_t *)trailer, b , 1); + } // uid emlSetMem((uint8_t *)uid, 0, 1);