43 #endif // HAVE_CONFIG_H
61 static mifare_param mp;
62 static mifareul_tag mtDump;
63 static uint32_t uiBlocks = 0xF;
71 print_success_or_failure(
bool bFailure, uint32_t *uiCounter)
73 printf(
"%c", (bFailure) ?
'x' :
'.');
75 *uiCounter += (bFailure) ? 0 : 1;
82 bool bFailure =
false;
83 uint32_t uiReadedPages = 0;
85 printf(
"Reading %d pages |", uiBlocks + 1);
87 for (page = 0; page <= uiBlocks; page += 4) {
90 memcpy(mtDump.amb[page / 4].mbd.abtData, mp.mpd.abtData, 16);
96 print_success_or_failure(bFailure, &uiReadedPages);
97 print_success_or_failure(bFailure, &uiReadedPages);
98 print_success_or_failure(bFailure, &uiReadedPages);
99 print_success_or_failure(bFailure, &uiReadedPages);
102 printf(
"Done, %d of %d pages readed.\n", uiReadedPages, uiBlocks + 1);
111 uint32_t uiBlock = 0;
112 bool bFailure =
false;
113 uint32_t uiWritenPages = 0;
114 uint32_t uiSkippedPages;
120 printf(
"Write OTP bytes ? [yN] ");
121 if (!fgets(buffer, BUFSIZ, stdin)) {
122 ERR(
"Unable to read standard input.");
124 write_otp = ((buffer[0] ==
'y') || (buffer[0] ==
'Y'));
125 printf(
"Write Lock bytes ? [yN] ");
126 if (!fgets(buffer, BUFSIZ, stdin)) {
127 ERR(
"Unable to read standard input.");
129 write_lock = ((buffer[0] ==
'y') || (buffer[0] ==
'Y'));
131 printf(
"Writing %d pages |", uiBlocks + 1);
136 for (
int page = 0x2; page <= 0xF; page++) {
137 if ((page == 0x2) && (!write_lock)) {
142 if ((page == 0x3) && (!write_otp)) {
151 ERR(
"tag was removed");
161 memcpy(mp.mpd.abtData, mtDump.amb[uiBlock].mbd.abtData + ((page % 4) * 4), 16);
165 print_success_or_failure(bFailure, &uiWritenPages);
168 printf(
"Done, %d of %d pages written (%d pages skipped).\n", uiWritenPages, uiBlocks + 1, uiSkippedPages);
174 main(
int argc,
const char *argv[])
181 printf(
"%s r|w <dump.mfd>\n", argv[0]);
183 printf(
"r|w - Perform read from or write to card\n");
184 printf(
"<dump.mfd> - MiFare Dump (MFD) used to write (card to MFD) or (MFD to card)\n");
189 DBG(
"\nChecking arguments and settings\n");
191 bReadAction = tolower((
int)((
unsigned char) * (argv[1])) ==
'r');
194 memset(&mtDump, 0x00,
sizeof(mtDump));
196 pfDump = fopen(argv[2],
"rb");
198 if (pfDump == NULL) {
199 ERR(
"Could not open dump file: %s\n", argv[2]);
203 if (fread(&mtDump, 1,
sizeof(mtDump), pfDump) !=
sizeof(mtDump)) {
204 ERR(
"Could not read from dump file: %s\n", argv[2]);
210 DBG(
"Successfully opened the dump file\n");
214 if (context == NULL) {
215 ERR(
"Unable to init libnfc (malloc)");
222 ERR(
"Error opening NFC device");
236 nfc_perror(pnd,
"nfc_device_set_property_bool");
246 ERR(
"no tag was found\n");
253 if (nt.nti.nai.abtAtqa[1] != 0x44) {
254 ERR(
"tag is not a MIFARE Ultralight card\n");
260 printf(
"Found MIFARE Ultralight card with UID: ");
262 for (szPos = 0; szPos < nt.nti.nai.szUidLen; szPos++) {
263 printf(
"%02x", nt.nti.nai.abtUid[szPos]);
269 printf(
"Writing data to file: %s ... ", argv[2]);
271 pfDump = fopen(argv[2],
"wb");
272 if (pfDump == NULL) {
273 printf(
"Could not open file: %s\n", argv[2]);
278 if (fwrite(&mtDump, 1,
sizeof(mtDump), pfDump) !=
sizeof(mtDump)) {
279 printf(
"Could not write to file: %s\n", argv[2]);