├── VERSION ├── README ├── Makefile ├── nfc-utils.h ├── nfc-utils.c ├── mifare.h ├── mifare.c ├── nfc-mfdesfire-keysearch.c ├── nfc-mfdesfire.c ├── nfc-mfultralightc.c └── COPYING /VERSION: -------------------------------------------------------------------------------- 1 | 20150821 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | MIFARE SmartHack Utils - Tools to aid in attacking smarter MIFARE tags 2 | 3 | 4 | See COPYING for license information. Based on sources included in libnfc by 5 | Romuald Conty and libfreefare by Romain Tartiere. 6 | 7 | nfc-mfdesfire - Enumerate AIDs and other info on a DESFire tag 8 | nfc-mfdesfire-keysearch - Search for keys using an input data file against 9 | a specified AID and key index number. 10 | nfc-mfultralightc 11 | Read or write data to an Ultralight-C/Ultralight-X tag. 12 | 13 | INSTALL 14 | 15 | These tools require the libnfc and libfreefare libraries. Run "make" to build. 16 | 17 | CONTACT 18 | 19 | Joshua Wright 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ################################## 2 | # Well, I may be doing stupid things with make 3 | # OK, it was Makefile stupid'ness 4 | # I don't really understand what the hell I am doing with Make, I'm 5 | # just copying other files and seeing what works. 6 | # heh 7 | # i think thats all anyone does 8 | # make is a twisted beast 9 | ################################## 10 | LDLIBS = -lnfc -lfreefare 11 | CFLAGS = -std=gnu99 -ggdb -g3 12 | PROGOBJ = nfc-mfdesfire.o nfc-mfdesfire-keysearch.o nfc-mfultralightc.o nfc-utils.o mifare.o 13 | PROG = nfc-mfdesfire nfc-mfdesfire-keysearch nfc-mfultralightc 14 | 15 | all: $(PROG) $(PROGOBJ) 16 | 17 | nfc-utils: nfc-utils.c nfc-utils.h 18 | $(CC) $(CFLAGS) nfc-utils.c -c 19 | 20 | mifare: mifare.h mifare.c 21 | $(CC) $(CFLAGS) mifare.c -c 22 | 23 | nfc-mfdesfire: nfc-mfdesfire.c nfc-utils.o 24 | $(CC) $(CFLAGS) nfc-mfdesfire.c -o nfc-mfdesfire nfc-utils.o $(LDLIBS) 25 | 26 | nfc-mfdesfire-keysearch: nfc-mfdesfire-keysearch.c nfc-utils.o 27 | $(CC) $(CFLAGS) nfc-mfdesfire-keysearch.c -o nfc-mfdesfire-keysearch nfc-utils.o $(LDLIBS) 28 | 29 | nfc-mfultralightc: nfc-mfultralightc.c nfc-utils.o mifare.o mifare.h mifare.c 30 | $(CC) $(CFLAGS) nfc-mfultralightc.c -o nfc-mfultralightc nfc-utils.o mifare.o $(LDLIBS) 31 | 32 | clean: 33 | $(RM) $(PROGOBJ) $(PROG) *~ 34 | 35 | strip: 36 | @ls -l $(PROG) 37 | @strip $(PROG) 38 | @ls -l $(PROG) 39 | -------------------------------------------------------------------------------- /nfc-utils.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Free/Libre Near Field Communication (NFC) library 3 | * 4 | * Libnfc historical contributors: 5 | * Copyright (C) 2009 Roel Verdult 6 | * Copyright (C) 2009-2013 Romuald Conty 7 | * Copyright (C) 2010-2012 Romain Tartière 8 | * Copyright (C) 2010-2013 Philippe Teuwen 9 | * Copyright (C) 2012-2013 Ludovic Rousseau 10 | * Additional contributors of this file: 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 1) Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2 )Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Note that this license only applies on the examples, NFC library itself is under LGPL 33 | * 34 | */ 35 | 36 | /** 37 | * @file nfc-utils.h 38 | * @brief Provide some examples shared functions like print, parity calculation, options parsing. 39 | */ 40 | 41 | #ifndef _EXAMPLES_NFC_UTILS_H_ 42 | # define _EXAMPLES_NFC_UTILS_H_ 43 | 44 | # include 45 | # include 46 | # include 47 | 48 | /** 49 | * @macro DBG 50 | * @brief Print a message of standard output only in DEBUG mode 51 | */ 52 | #ifdef DEBUG 53 | # define DBG(...) do { \ 54 | warnx ("DBG %s:%d", __FILE__, __LINE__); \ 55 | warnx (" " __VA_ARGS__ ); \ 56 | } while (0) 57 | #else 58 | # define DBG(...) {} 59 | #endif 60 | 61 | /** 62 | * @macro WARN 63 | * @brief Print a warn message 64 | */ 65 | #ifdef DEBUG 66 | # define WARN(...) do { \ 67 | warnx ("WARNING %s:%d", __FILE__, __LINE__); \ 68 | warnx (" " __VA_ARGS__ ); \ 69 | } while (0) 70 | #else 71 | # define WARN(...) warnx ("WARNING: " __VA_ARGS__ ) 72 | #endif 73 | 74 | /** 75 | * @macro ERR 76 | * @brief Print a error message 77 | */ 78 | #ifdef DEBUG 79 | # define ERR(...) do { \ 80 | warnx ("ERROR %s:%d", __FILE__, __LINE__); \ 81 | warnx (" " __VA_ARGS__ ); \ 82 | } while (0) 83 | #else 84 | # define ERR(...) warnx ("ERROR: " __VA_ARGS__ ) 85 | #endif 86 | 87 | #ifndef MIN 88 | #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 89 | #endif 90 | #ifndef MAX 91 | #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 92 | #endif 93 | 94 | uint8_t oddparity(const uint8_t bt); 95 | void oddparity_bytes_ts(const uint8_t *pbtData, const size_t szLen, uint8_t *pbtPar); 96 | 97 | void print_hex(const uint8_t *pbtData, const size_t szLen); 98 | void print_hex_bits(const uint8_t *pbtData, const size_t szBits); 99 | void print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDataPar); 100 | 101 | void print_nfc_target(const nfc_target *pnt, bool verbose); 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /nfc-utils.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Free/Libre Near Field Communication (NFC) library 3 | * 4 | * Libnfc historical contributors: 5 | * Copyright (C) 2009 Roel Verdult 6 | * Copyright (C) 2009-2013 Romuald Conty 7 | * Copyright (C) 2010-2012 Romain Tartière 8 | * Copyright (C) 2010-2013 Philippe Teuwen 9 | * Copyright (C) 2012-2013 Ludovic Rousseau 10 | * Additional contributors of this file: 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 1) Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2 )Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Note that this license only applies on the examples, NFC library itself is under LGPL 33 | * 34 | */ 35 | /** 36 | * @file nfc-utils.c 37 | * @brief Provide some examples shared functions like print, parity calculation, options parsing. 38 | */ 39 | #include 40 | #include 41 | 42 | #include "nfc-utils.h" 43 | 44 | uint8_t oddparity(const uint8_t bt) 45 | { 46 | // cf http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel 47 | return (0x9669 >> ((bt ^ (bt >> 4)) & 0xF)) & 1; 48 | } 49 | 50 | void 51 | oddparity_bytes_ts(const uint8_t * pbtData, const size_t szLen, 52 | uint8_t * pbtPar) 53 | { 54 | size_t szByteNr; 55 | // Calculate the parity bits for the command 56 | for (szByteNr = 0; szByteNr < szLen; szByteNr++) { 57 | pbtPar[szByteNr] = oddparity(pbtData[szByteNr]); 58 | } 59 | } 60 | 61 | void print_hex(const uint8_t * pbtData, const size_t szBytes) 62 | { 63 | size_t szPos; 64 | 65 | for (szPos = 0; szPos < szBytes; szPos++) { 66 | printf("%02x ", pbtData[szPos]); 67 | } 68 | printf("\n"); 69 | } 70 | 71 | void print_hex_bits(const uint8_t * pbtData, const size_t szBits) 72 | { 73 | uint8_t uRemainder; 74 | size_t szPos; 75 | size_t szBytes = szBits / 8; 76 | 77 | for (szPos = 0; szPos < szBytes; szPos++) { 78 | printf("%02x ", pbtData[szPos]); 79 | } 80 | 81 | uRemainder = szBits % 8; 82 | // Print the rest bits 83 | if (uRemainder != 0) { 84 | if (uRemainder < 5) 85 | printf("%01x (%d bits)", pbtData[szBytes], uRemainder); 86 | else 87 | printf("%02x (%d bits)", pbtData[szBytes], uRemainder); 88 | } 89 | printf("\n"); 90 | } 91 | 92 | void 93 | print_hex_par(const uint8_t * pbtData, const size_t szBits, 94 | const uint8_t * pbtDataPar) 95 | { 96 | uint8_t uRemainder; 97 | size_t szPos; 98 | size_t szBytes = szBits / 8; 99 | 100 | for (szPos = 0; szPos < szBytes; szPos++) { 101 | printf("%02x", pbtData[szPos]); 102 | if (oddparity(pbtData[szPos]) != pbtDataPar[szPos]) { 103 | printf("! "); 104 | } else { 105 | printf(" "); 106 | } 107 | } 108 | 109 | uRemainder = szBits % 8; 110 | // Print the rest bits, these cannot have parity bit 111 | if (uRemainder != 0) { 112 | if (uRemainder < 5) 113 | printf("%01x (%d bits)", pbtData[szBytes], uRemainder); 114 | else 115 | printf("%02x (%d bits)", pbtData[szBytes], uRemainder); 116 | } 117 | printf("\n"); 118 | } 119 | 120 | void print_nfc_target(const nfc_target * pnt, bool verbose) 121 | { 122 | char *s; 123 | str_nfc_target(&s, pnt, verbose); 124 | printf("%s", s); 125 | nfc_free(s); 126 | } 127 | -------------------------------------------------------------------------------- /mifare.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Free/Libre Near Field Communication (NFC) library 3 | * 4 | * Libnfc historical contributors: 5 | * Copyright (C) 2009 Roel Verdult 6 | * Copyright (C) 2009-2013 Romuald Conty 7 | * Copyright (C) 2010-2012 Romain Tartière 8 | * Copyright (C) 2010-2013 Philippe Teuwen 9 | * Copyright (C) 2012-2013 Ludovic Rousseau 10 | * Additional contributors of this file: 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 1) Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2 )Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Note that this license only applies on the examples, NFC library itself is under LGPL 33 | * 34 | */ 35 | 36 | /** 37 | * @file mifare.h 38 | * @brief provide samples structs and functions to manipulate MIFARE Classic and Ultralight tags using libnfc 39 | */ 40 | 41 | #ifndef _LIBNFC_MIFARE_H_ 42 | # define _LIBNFC_MIFARE_H_ 43 | 44 | # include 45 | 46 | // Compiler directive, set struct alignment to 1 uint8_t for compatibility 47 | # pragma pack(1) 48 | 49 | typedef enum { 50 | MC_AUTH_A = 0x60, 51 | MC_AUTH_B = 0x61, 52 | MC_READ = 0x30, 53 | MC_WRITE = 0xA0, 54 | MC_TRANSFER = 0xB0, 55 | MC_DECREMENT = 0xC0, 56 | MC_INCREMENT = 0xC1, 57 | MC_STORE = 0xC2 58 | } mifare_cmd; 59 | 60 | // MIFARE command params 61 | struct mifare_param_auth { 62 | uint8_t abtKey[6]; 63 | uint8_t abtAuthUid[4]; 64 | }; 65 | 66 | struct mifare_param_data { 67 | uint8_t abtData[16]; 68 | }; 69 | 70 | struct mifare_param_value { 71 | uint8_t abtValue[4]; 72 | }; 73 | 74 | typedef union { 75 | struct mifare_param_auth mpa; 76 | struct mifare_param_data mpd; 77 | struct mifare_param_value mpv; 78 | } mifare_param; 79 | 80 | // Reset struct alignment to default 81 | # pragma pack() 82 | 83 | bool nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param *pmp); 84 | 85 | // Compiler directive, set struct alignment to 1 uint8_t for compatibility 86 | # pragma pack(1) 87 | 88 | // MIFARE Classic 89 | typedef struct { 90 | uint8_t abtUID[4]; 91 | uint8_t btBCC; 92 | uint8_t btUnknown; 93 | uint8_t abtATQA[2]; 94 | uint8_t abtUnknown[8]; 95 | } mifare_classic_block_manufacturer; 96 | 97 | typedef struct { 98 | uint8_t abtData[16]; 99 | } mifare_classic_block_data; 100 | 101 | typedef struct { 102 | uint8_t abtKeyA[6]; 103 | uint8_t abtAccessBits[4]; 104 | uint8_t abtKeyB[6]; 105 | } mifare_classic_block_trailer; 106 | 107 | typedef union { 108 | mifare_classic_block_manufacturer mbm; 109 | mifare_classic_block_data mbd; 110 | mifare_classic_block_trailer mbt; 111 | } mifare_classic_block; 112 | 113 | typedef struct { 114 | mifare_classic_block amb[256]; 115 | } mifare_classic_tag; 116 | 117 | // MIFARE Ultralight 118 | typedef struct { 119 | uint8_t sn0[3]; 120 | uint8_t btBCC0; 121 | uint8_t sn1[4]; 122 | uint8_t btBCC1; 123 | uint8_t internal; 124 | uint8_t lock[2]; 125 | uint8_t otp[4]; 126 | } mifareul_block_manufacturer; 127 | 128 | typedef struct { 129 | uint8_t abtData[16]; 130 | } mifareul_block_data; 131 | 132 | typedef union { 133 | mifareul_block_manufacturer mbm; 134 | mifareul_block_data mbd; 135 | } mifareul_block; 136 | 137 | typedef struct { 138 | mifareul_block amb[4]; 139 | } mifareul_tag; 140 | 141 | // Reset struct alignment to default 142 | # pragma pack() 143 | 144 | #endif // _LIBNFC_MIFARE_H_ 145 | -------------------------------------------------------------------------------- /mifare.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Free/Libre Near Field Communication (NFC) library 3 | * 4 | * Libnfc historical contributors: 5 | * Copyright (C) 2009 Roel Verdult 6 | * Copyright (C) 2009-2013 Romuald Conty 7 | * Copyright (C) 2010-2012 Romain Tartière 8 | * Copyright (C) 2010-2013 Philippe Teuwen 9 | * Copyright (C) 2012-2013 Ludovic Rousseau 10 | * Additional contributors of this file: 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 1) Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2 )Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Note that this license only applies on the examples, NFC library itself is under LGPL 33 | * 34 | */ 35 | /** 36 | * @file mifare.c 37 | * @brief provide samples structs and functions to manipulate MIFARE Classic and Ultralight tags using libnfc 38 | */ 39 | #include "mifare.h" 40 | 41 | #include 42 | 43 | #include 44 | 45 | /** 46 | * @brief Execute a MIFARE Classic Command 47 | * @return Returns true if action was successfully performed; otherwise returns false. 48 | * @param pmp Some commands need additional information. This information should be supplied in the mifare_param union. 49 | * 50 | * The specified MIFARE command will be executed on the tag. There are different commands possible, they all require the destination block number. 51 | * @note There are three different types of information (Authenticate, Data and Value). 52 | * 53 | * First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID. 54 | * They are both used to initialize the internal cipher-state of the PN53X chip. 55 | * After a successful authentication it will be possible to execute other commands (e.g. Read/Write). 56 | * The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process. 57 | */ 58 | bool 59 | nfc_initiator_mifare_cmd(nfc_device * pnd, const mifare_cmd mc, 60 | const uint8_t ui8Block, mifare_param * pmp) 61 | { 62 | uint8_t abtRx[265]; 63 | size_t szParamLen; 64 | uint8_t abtCmd[265]; 65 | //bool bEasyFraming; 66 | 67 | abtCmd[0] = mc; // The MIFARE Classic command 68 | abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff) 69 | 70 | switch (mc) { 71 | // Read and store command have no parameter 72 | case MC_READ: 73 | case MC_STORE: 74 | szParamLen = 0; 75 | break; 76 | 77 | // Authenticate command 78 | case MC_AUTH_A: 79 | case MC_AUTH_B: 80 | szParamLen = sizeof(struct mifare_param_auth); 81 | break; 82 | 83 | // Data command 84 | case MC_WRITE: 85 | szParamLen = sizeof(struct mifare_param_data); 86 | break; 87 | 88 | // Value command 89 | case MC_DECREMENT: 90 | case MC_INCREMENT: 91 | case MC_TRANSFER: 92 | szParamLen = sizeof(struct mifare_param_value); 93 | break; 94 | 95 | // Please fix your code, you never should reach this statement 96 | default: 97 | return false; 98 | break; 99 | } 100 | 101 | // When available, copy the parameter bytes 102 | if (szParamLen) 103 | memcpy(abtCmd + 2, (uint8_t *) pmp, szParamLen); 104 | 105 | // FIXME: Save and restore bEasyFraming 106 | // bEasyFraming = nfc_device_get_property_bool (pnd, NP_EASY_FRAMING, &bEasyFraming); 107 | if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true) < 0) { 108 | nfc_perror(pnd, "nfc_device_set_property_bool"); 109 | return false; 110 | } 111 | // Fire the mifare command 112 | int res; 113 | if ((res = 114 | nfc_initiator_transceive_bytes(pnd, abtCmd, 2 + szParamLen, abtRx, 115 | sizeof(abtRx), -1)) < 0) { 116 | if (res == NFC_ERFTRANS) { 117 | // "Invalid received frame", usual means we are 118 | // authenticated on a sector but the requested MIFARE cmd (read, write) 119 | // is not permitted by current acces bytes; 120 | // So there is nothing to do here. 121 | } else { 122 | nfc_perror(pnd, "nfc_initiator_transceive_bytes"); 123 | } 124 | // XXX nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming); 125 | return false; 126 | } 127 | /* XXX 128 | if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming) < 0) { 129 | nfc_perror (pnd, "nfc_device_set_property_bool"); 130 | return false; 131 | } 132 | */ 133 | 134 | // When we have executed a read command, copy the received bytes into the param 135 | if (mc == MC_READ) { 136 | if (res == 16) { 137 | memcpy(pmp->mpd.abtData, abtRx, 16); 138 | } else { 139 | return false; 140 | } 141 | } 142 | // Command succesfully executed 143 | return true; 144 | } 145 | -------------------------------------------------------------------------------- /nfc-mfdesfire-keysearch.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (C) 2010, Romain Tartiere. 3 | * 4 | * See AUTHORS file for a more comprehensive list of contributors. 5 | * Additional contributors of this file: 6 | * Copyright (C) 2014 Joshua Wright 7 | * 8 | * This program is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but WITHOUT 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 | * more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see 20 | * 21 | * $Id$ 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #define AUTH_DES 0 34 | #define AUTH_3DES 1 35 | #define AUTH_3K3DES 2 36 | #define AUTH_AES 3 37 | #define AUTH_DES_KEYLEN 8 38 | #define AUTH_3DES_KEYLEN 16 39 | #define AUTH_3K3DES_KEYLEN 24 40 | #define AUTH_AES_KEYLEN 16 41 | 42 | int bruteforce_key(uint16_t aidval, uint8_t key, uint8_t authtype, MifareTag tag, char *filename) 43 | { 44 | FILE *f; 45 | unsigned char *buffer; 46 | int n, filelen, res; 47 | size_t readlen; 48 | uint8_t *key_data = NULL; 49 | uint8_t key_len = 0; 50 | 51 | MifareDESFireAID aid; 52 | MifareDESFireKey key_guess; 53 | 54 | switch(authtype) { 55 | case AUTH_DES: 56 | key_len = AUTH_DES_KEYLEN; 57 | break; 58 | case AUTH_3DES: 59 | key_len = AUTH_3DES_KEYLEN; 60 | break; 61 | case AUTH_3K3DES: 62 | key_len = AUTH_3K3DES_KEYLEN; 63 | break; 64 | case AUTH_AES: 65 | key_len = AUTH_AES_KEYLEN; 66 | break; 67 | default: 68 | fprintf(stderr, "Invalid authentication type: %d\n", authtype); 69 | return -1; 70 | } 71 | 72 | key_data = malloc(key_len); 73 | if (key_data == NULL) { 74 | fprintf(stderr, "Unable to allocate memory.\n"); 75 | return -1; 76 | } 77 | 78 | f = fopen(filename, "rb"); 79 | if (!f) { 80 | fprintf(stderr, "Unable to open file.\n"); 81 | return -1; 82 | } 83 | 84 | fseek(f, 0L, SEEK_END); 85 | filelen = ftell(f); 86 | fseek(f, 0L, SEEK_SET); 87 | 88 | if (filelen < key_len) { 89 | fprintf(stderr, "File length too short for key material.\n"); 90 | return -1; 91 | } 92 | buffer = malloc(filelen + 1); 93 | if (buffer == NULL) { 94 | fprintf(stderr, "Unable to allocate memory, %d bytes.\n", 95 | filelen + 1); 96 | return -1; 97 | } 98 | 99 | readlen = fread(buffer, 1, filelen, f); 100 | if (readlen != filelen) { 101 | fprintf(stderr, 102 | "Read len (%zu) does not match file len (%d).\n", 103 | readlen, filelen); 104 | return -1; 105 | } 106 | 107 | /* Iterate through the file contents, using each key_len byte array as a potential key */ 108 | for (n = 0; n < filelen - (key_len - 1); n++) { 109 | memcpy(key_data, buffer+n, key_len); 110 | 111 | aid = mifare_desfire_aid_new(aidval); 112 | res = mifare_desfire_select_application(tag, aid); 113 | if (res < 0) { 114 | freefare_perror (tag, "mifare_desfire_select_application"); 115 | break; 116 | } 117 | 118 | switch(authtype) { 119 | case AUTH_DES: 120 | key_guess = mifare_desfire_des_key_new (key_data); 121 | break; 122 | case AUTH_3DES: 123 | key_guess = mifare_desfire_3des_key_new (key_data); 124 | break; 125 | case AUTH_3K3DES: 126 | key_guess = mifare_desfire_3k3des_key_new (key_data); 127 | break; 128 | case AUTH_AES: 129 | key_guess = mifare_desfire_aes_key_new (key_data); 130 | break; 131 | default: 132 | fprintf(stderr, "Invalid authentication type: %d\n", authtype); 133 | return -1; 134 | } 135 | 136 | res = mifare_desfire_authenticate (tag, key, key_guess); 137 | if (res >= 0) { 138 | printf("\nAuthentication AID 0x%x with key %d returned success!\n", aidval, key); 139 | mifare_desfire_key_free (key_guess); 140 | for (int i=0; i < key_len-1; i++) { 141 | printf("%02x:", key_data[i]); 142 | } 143 | printf("%02x\n",key_data[key_len-1]); 144 | return res; 145 | } 146 | 147 | 148 | /* Status monitor */ 149 | if ((n % 80) == 0) { 150 | printf("\n"); 151 | } 152 | printf("."); 153 | fflush(stdout); 154 | } 155 | 156 | return -1; 157 | } 158 | 159 | void usage(char *progname) { 160 | printf("usage: %s [AID] [key#] [auth type] [key search data source]\n", progname); 161 | printf("\nauth type is one of:\n"); 162 | printf("\tAUTH_DES\n"); 163 | printf("\tAUTH_3DES\n"); 164 | printf("\tAUTH_3K3DES\n"); 165 | printf("\tAUTH_AES\n"); 166 | return; 167 | } 168 | 169 | 170 | int main(int argc, char *argv[]) 171 | { 172 | int error = EXIT_SUCCESS; 173 | uint16_t aid = 0; 174 | uint8_t key = 0; 175 | uint8_t auth_type = -1; 176 | nfc_device *device = NULL; 177 | MifareTag *tags = NULL; 178 | char *p; 179 | 180 | if (argc != 5) { 181 | usage(argv[0]); 182 | return 1; 183 | } 184 | 185 | if (memcmp(argv[1], "0x", 2) == 0) { 186 | /* User specified AID as hex, convert appropriately */ 187 | aid = (uint16_t) strtoul(argv[1], &p + 2, 16); 188 | } else { 189 | aid = (uint16_t) strtoul(argv[1], &p, 10); 190 | } 191 | 192 | if (errno != 0) { 193 | errx(EXIT_FAILURE, 194 | "ERROR: Incorrect value for AID. Specify as decimal or hex with leading 0x."); 195 | } 196 | 197 | if (sscanf(argv[2], SCNd8, &key) == EOF || (key < 0 || key > 13)) { 198 | errx(EXIT_FAILURE, 199 | "ERROR: Incorrect value for key. Key must be in the range 0-13."); 200 | } 201 | 202 | if (memcmp(argv[3], "AUTH_DES", 8) == 0) { 203 | auth_type = AUTH_DES; 204 | } else if (memcmp(argv[3], "AUTH_3DES", 9) == 0) { 205 | auth_type = AUTH_3DES; 206 | } else if (memcmp(argv[3], "AUTH_3K3DES", 9) == 0) { 207 | auth_type = AUTH_3K3DES; 208 | } else if (memcmp(argv[3], "AUTH_AES", 9) == 0) { 209 | auth_type = AUTH_AES; 210 | } else { 211 | errx(EXIT_FAILURE, "ERROR: Invalid auth type specified."); 212 | } 213 | 214 | error = 0; 215 | nfc_connstring devices[8]; 216 | size_t device_count; 217 | 218 | nfc_context *context; 219 | nfc_init(&context); 220 | if (context == NULL) 221 | errx(EXIT_FAILURE, "Unable to init libnfc (malloc)"); 222 | 223 | device_count = nfc_list_devices(context, devices, 8); 224 | if (device_count <= 0) 225 | errx(EXIT_FAILURE, "No NFC device found."); 226 | 227 | for (size_t d = 0; d < device_count; d++) { 228 | device = nfc_open(context, devices[d]); 229 | if (!device) { 230 | warnx("nfc_open() failed."); 231 | error = EXIT_FAILURE; 232 | continue; 233 | } 234 | 235 | tags = freefare_get_tags(device); 236 | if (!tags) { 237 | nfc_close(device); 238 | errx(EXIT_FAILURE, "Error listing tags."); 239 | } 240 | 241 | for (int i = 0; (!error) && tags[i]; i++) { 242 | MifareTag tag = tags[i]; 243 | if (DESFIRE != freefare_get_tag_type(tags[i])) { 244 | fprintf(stderr, "Tag is not DESFIRE: %d\n", freefare_get_tag_type(tags[i])); 245 | continue; 246 | } 247 | 248 | int res; 249 | char *tag_uid = freefare_get_tag_uid(tags[i]); 250 | 251 | res = mifare_desfire_connect(tags[i]); 252 | if (res < 0) { 253 | warnx 254 | ("Can't connect to Mifare DESFire target."); 255 | error = 1; 256 | break; 257 | } 258 | 259 | res = bruteforce_key(aid, key, auth_type, tag, argv[4]); 260 | 261 | free(tag_uid); 262 | 263 | mifare_desfire_disconnect(tags[i]); 264 | } 265 | 266 | freefare_free_tags(tags); 267 | nfc_close(device); 268 | } 269 | nfc_exit(context); 270 | exit(error); 271 | } /* main() */ 272 | -------------------------------------------------------------------------------- /nfc-mfdesfire.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (C) 2010, Romain Tartiere. 3 | * See AUTHORS file for a more comprehensive list of contributors. 4 | * Additional contributors of this file: 5 | * Copyright (C) 2014 Joshua Wright 6 | * 7 | * This program is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 | * more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program. If not, see 19 | * 20 | * $Id$ 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | int error = EXIT_SUCCESS; 35 | nfc_device *device = NULL; 36 | MifareTag *tags = NULL; 37 | 38 | if (argc > 1) 39 | errx(EXIT_FAILURE, "usage: %s", argv[0]); 40 | 41 | nfc_connstring devices[8]; 42 | size_t device_count; 43 | 44 | nfc_context *context; 45 | nfc_init(&context); 46 | if (context == NULL) 47 | errx(EXIT_FAILURE, "Unable to init libnfc (malloc)"); 48 | 49 | device_count = nfc_list_devices(context, devices, 8); 50 | if (device_count <= 0) 51 | errx(EXIT_FAILURE, "No NFC device found."); 52 | 53 | for (size_t d = 0; d < device_count; d++) { 54 | device = nfc_open(context, devices[d]); 55 | if (!device) { 56 | warnx("nfc_open() failed."); 57 | error = EXIT_FAILURE; 58 | continue; 59 | } 60 | 61 | tags = freefare_get_tags(device); 62 | if (!tags) { 63 | nfc_close(device); 64 | errx(EXIT_FAILURE, "Error listing tags."); 65 | } 66 | 67 | for (int i = 0; (!error) && tags[i]; i++) { 68 | MifareTag tag = tags[i]; 69 | if (DESFIRE != freefare_get_tag_type(tags[i])) 70 | continue; 71 | 72 | int res; 73 | char *tag_uid = freefare_get_tag_uid(tags[i]); 74 | 75 | struct mifare_desfire_version_info info; 76 | 77 | res = mifare_desfire_connect(tags[i]); 78 | if (res < 0) { 79 | warnx 80 | ("Can't connect to Mifare DESFire target."); 81 | error = 1; 82 | break; 83 | } 84 | 85 | res = mifare_desfire_get_version(tags[i], &info); 86 | if (res < 0) { 87 | freefare_perror(tags[i], 88 | "mifare_desfire_get_version"); 89 | error = 1; 90 | break; 91 | } 92 | 93 | printf("===> Version information for tag %s:\n", 94 | tag_uid); 95 | printf 96 | ("UID: 0x%02x%02x%02x%02x%02x%02x%02x\n", 97 | info.uid[0], info.uid[1], info.uid[2], info.uid[3], 98 | info.uid[4], info.uid[5], info.uid[6]); 99 | printf 100 | ("Batch number: 0x%02x%02x%02x%02x%02x\n", 101 | info.batch_number[0], info.batch_number[1], 102 | info.batch_number[2], info.batch_number[3], 103 | info.batch_number[4]); 104 | printf("Production date: week %x, 20%02x\n", 105 | info.production_week, info.production_year); 106 | printf("Hardware Information:\n"); 107 | printf(" Vendor ID: 0x%02x\n", 108 | info.hardware.vendor_id); 109 | printf(" Type: 0x%02x\n", 110 | info.hardware.type); 111 | printf(" Subtype: 0x%02x\n", 112 | info.hardware.subtype); 113 | printf(" Version: %d.%d\n", 114 | info.hardware.version_major, 115 | info.hardware.version_minor); 116 | printf 117 | (" Storage size: 0x%02x (%s%d bytes)\n", 118 | info.hardware.storage_size, 119 | (info.hardware.storage_size & 1) ? ">" : "=", 120 | 1 << (info.hardware.storage_size >> 1)); 121 | printf(" Protocol: 0x%02x\n", 122 | info.hardware.protocol); 123 | printf("Software Information:\n"); 124 | printf(" Vendor ID: 0x%02x\n", 125 | info.software.vendor_id); 126 | printf(" Type: 0x%02x\n", 127 | info.software.type); 128 | printf(" Subtype: 0x%02x\n", 129 | info.software.subtype); 130 | printf(" Version: %d.%d\n", 131 | info.software.version_major, 132 | info.software.version_minor); 133 | printf 134 | (" Storage size: 0x%02x (%s%d bytes)\n", 135 | info.software.storage_size, 136 | (info.software.storage_size & 1) ? ">" : "=", 137 | 1 << (info.software.storage_size >> 1)); 138 | printf(" Protocol: 0x%02x\n", 139 | info.software.protocol); 140 | 141 | uint8_t settings; 142 | uint8_t max_keys; 143 | res = 144 | mifare_desfire_get_key_settings(tags[i], &settings, 145 | &max_keys); 146 | if (res == 0) { 147 | printf("Master Key settings (0x%02x):\n", 148 | settings); 149 | printf(" 0x%02x configuration changeable;\n", 150 | settings & 0x08); 151 | printf 152 | (" 0x%02x PICC Master Key not required for create / delete;\n", 153 | settings & 0x04); 154 | printf 155 | (" 0x%02x Free directory list access without PICC Master Key;\n", 156 | settings & 0x02); 157 | printf 158 | (" 0x%02x Allow changing the Master Key;\n", 159 | settings & 0x01); 160 | } else if (AUTHENTICATION_ERROR == 161 | mifare_desfire_last_picc_error(tags[i])) { 162 | printf("Master Key settings: LOCKED\n"); 163 | } else { 164 | freefare_perror(tags[i], 165 | "mifare_desfire_get_key_settings"); 166 | error = 1; 167 | break; 168 | } 169 | 170 | uint8_t version; 171 | mifare_desfire_get_key_version(tags[i], 0, &version); 172 | printf("Master Key version: %d (0x%02x)\n", version, 173 | version); 174 | 175 | uint32_t size; 176 | res = mifare_desfire_free_mem(tags[i], &size); 177 | printf("Free memory: "); 178 | if (0 == res) { 179 | printf("%d bytes\n", size); 180 | } else { 181 | printf("unknown\n"); 182 | } 183 | 184 | printf("Use random UID: %s\n", 185 | (strlen(tag_uid) / 2 == 4) ? "yes" : "no"); 186 | 187 | MifareDESFireAID *aids = NULL; 188 | size_t aid_count; 189 | res = 190 | mifare_desfire_get_application_ids(tag, &aids, 191 | &aid_count); 192 | printf("AIDs enumerated: %u\n", 193 | (unsigned int)aid_count); 194 | 195 | for (int aidindex = 0; aidindex < aid_count; aidindex++) { 196 | res = 197 | mifare_desfire_select_application(tag, 198 | aids 199 | [aidindex]); 200 | printf("\tSelected AID 0x%x\n", 201 | mifare_desfire_aid_get_aid(aids 202 | [aidindex])); 203 | if (res < 0) 204 | errx(EXIT_FAILURE, 205 | "Application selection failed"); 206 | 207 | // Get all files 208 | uint8_t *files; 209 | size_t file_count; 210 | res = 211 | mifare_desfire_get_file_ids(tag, &files, 212 | &file_count); 213 | printf("\tAID has %lu files\n", 214 | (unsigned long)file_count); 215 | 216 | char buffer[16]; 217 | for (size_t filenum = 0; filenum < file_count; 218 | filenum++) { 219 | printf("\t\tFile %u ", files[filenum]); 220 | res = 221 | mifare_desfire_read_data(tag, 222 | files 223 | [filenum], 224 | 0, 16, 225 | buffer); 226 | if (res < 0) { 227 | printf 228 | ("failed read (key required)\n"); 229 | continue; 230 | } 231 | 232 | for (int filebyte = 0; 233 | filebyte < (16 - 1); filebyte++) { 234 | printf("%02hhX:", 235 | buffer[filebyte]); 236 | } 237 | printf("%02hhX", buffer[15]); 238 | printf("\n"); 239 | } 240 | 241 | printf("\n"); 242 | 243 | } 244 | free(tag_uid); 245 | 246 | mifare_desfire_disconnect(tags[i]); 247 | } 248 | 249 | freefare_free_tags(tags); 250 | nfc_close(device); 251 | } 252 | nfc_exit(context); 253 | exit(error); 254 | } /* main() */ 255 | -------------------------------------------------------------------------------- /nfc-mfultralightc.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Free/Libre Near Field Communication (NFC) library 3 | * 4 | * Libnfc historical contributors: 5 | * Copyright (C) 2009 Roel Verdult 6 | * Copyright (C) 2009-2013 Romuald Conty 7 | * Copyright (C) 2010-2012 Romain Tartière 8 | * Copyright (C) 2010-2013 Philippe Teuwen 9 | * Copyright (C) 2012-2013 Ludovic Rousseau 10 | * See AUTHORS file for a more comprehensive list of contributors. 11 | * Additional contributors of this file: 12 | * Copyright (C) 2013 Adam Laurie 13 | * Copyright (C) 2014 Joshua Wright 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions are met: 17 | * 1) Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2 )Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in the 21 | * documentation and/or other materials provided with the distribution. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * Note that this license only applies on the examples, NFC library itself is under LGPL 36 | * 37 | */ 38 | 39 | /** 40 | * @file nfc-mfultralight.c 41 | * @brief MIFARE Ultralight dump/restore tool 42 | */ 43 | 44 | #ifdef HAVE_CONFIG_H 45 | #include "config.h" 46 | #endif // HAVE_CONFIG_H 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | #include "nfc-utils.h" 60 | #include "mifare.h" 61 | 62 | static nfc_device *pnd; 63 | static nfc_target nt; 64 | static mifare_param mp; 65 | static mifareul_tag mtDump; 66 | static uint32_t uiBlocks = 22; 67 | 68 | static const nfc_modulation nmMifare = { 69 | .nmt = NMT_ISO14443A, 70 | .nbr = NBR_106, 71 | }; 72 | 73 | static void print_success_or_failure(bool bFailure, uint32_t * uiCounter) 74 | { 75 | printf("%c", (bFailure) ? 'x' : '.'); 76 | if (uiCounter) 77 | *uiCounter += (bFailure) ? 0 : 1; 78 | } 79 | 80 | static bool read_card(void) 81 | { 82 | uint32_t page; 83 | bool bFailure = false; 84 | uint32_t uiReadPages = 0; 85 | 86 | printf("Reading %d pages |", uiBlocks); 87 | 88 | for (page = 0; page < uiBlocks; page += 4) { 89 | // Try to read out the data block 90 | if (nfc_initiator_mifare_cmd(pnd, MC_READ, page, &mp)) { 91 | memcpy(mtDump.amb[page / 4].mbd.abtData, mp.mpd.abtData, 92 | 16); 93 | } else { 94 | bFailure = true; 95 | break; 96 | } 97 | 98 | print_success_or_failure(bFailure, &uiReadPages); 99 | print_success_or_failure(bFailure, &uiReadPages); 100 | print_success_or_failure(bFailure, &uiReadPages); 101 | print_success_or_failure(bFailure, &uiReadPages); 102 | } 103 | printf("|\n"); 104 | printf("Done, %d of %d pages read.\n", uiReadPages - 2, uiBlocks); 105 | fflush(stdout); 106 | 107 | return (!bFailure); 108 | } 109 | 110 | static bool write_card(void) 111 | { 112 | uint32_t uiBlock = 0; 113 | bool bFailure = false; 114 | uint32_t uiWritenPages = 0; 115 | uint32_t uiSkippedPages = 0; 116 | 117 | char buffer[BUFSIZ]; 118 | bool write_otp; 119 | bool write_lock; 120 | bool write_uid; 121 | 122 | printf("Write OTP bytes ? [yN] "); 123 | if (!fgets(buffer, BUFSIZ, stdin)) { 124 | ERR("Unable to read standard input."); 125 | } 126 | write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y')); 127 | printf("Write Lock bytes ? [yN] "); 128 | if (!fgets(buffer, BUFSIZ, stdin)) { 129 | ERR("Unable to read standard input."); 130 | } 131 | write_lock = ((buffer[0] == 'y') || (buffer[0] == 'Y')); 132 | printf 133 | ("Write UID bytes (only for special writeable UID cards) ? [yN] "); 134 | if (!fgets(buffer, BUFSIZ, stdin)) { 135 | ERR("Unable to read standard input."); 136 | } 137 | write_uid = ((buffer[0] == 'y') || (buffer[0] == 'Y')); 138 | 139 | printf("Writing %d pages |", uiBlocks + 1); 140 | /* We may need to skip 2 first pages. */ 141 | if (!write_uid) { 142 | printf("ss"); 143 | uiSkippedPages = 2; 144 | } 145 | 146 | for (uint32_t page = uiSkippedPages; page <= uiBlocks; page++) { 147 | if ((page == 0x2) && (!write_lock)) { 148 | printf("s"); 149 | uiSkippedPages++; 150 | continue; 151 | } 152 | if ((page == 0x3) && (!write_otp)) { 153 | printf("s"); 154 | uiSkippedPages++; 155 | continue; 156 | } 157 | // Show if the readout went well 158 | if (bFailure) { 159 | // When a failure occured we need to redo the anti-collision 160 | if (nfc_initiator_select_passive_target 161 | (pnd, nmMifare, NULL, 0, &nt) <= 0) { 162 | ERR("tag was removed"); 163 | return false; 164 | } 165 | bFailure = false; 166 | } 167 | // For the Mifare Ultralight, this write command can be used 168 | // in compatibility mode, which only actually writes the first 169 | // page (4 bytes). The Ultralight-specific Write command only 170 | // writes one page at a time. 171 | uiBlock = page / 4; 172 | memcpy(mp.mpd.abtData, 173 | mtDump.amb[uiBlock].mbd.abtData + ((page % 4) * 4), 16); 174 | if (!nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp)) 175 | bFailure = true; 176 | 177 | print_success_or_failure(bFailure, &uiWritenPages); 178 | } 179 | printf("|\n"); 180 | printf("Done, %d of %d pages written (%d pages skipped).\n", 181 | uiWritenPages, uiBlocks + 1, uiSkippedPages); 182 | 183 | return true; 184 | } 185 | 186 | int main(int argc, const char *argv[]) 187 | { 188 | bool bReadAction; 189 | FILE *pfDump; 190 | 191 | if (argc < 3) { 192 | printf("\n"); 193 | printf("%s r|w \n", argv[0]); 194 | printf("\n"); 195 | printf("r|w - Perform read from or write to card\n"); 196 | printf 197 | (" - MiFare Dump (MFD) used to write (card to MFD) or (MFD to card)\n"); 198 | printf("\n"); 199 | exit(EXIT_FAILURE); 200 | } 201 | 202 | DBG("\nChecking arguments and settings\n"); 203 | 204 | bReadAction = tolower((int)((unsigned char)*(argv[1])) == 'r'); 205 | 206 | if (bReadAction) { 207 | memset(&mtDump, 0x00, sizeof(mtDump)); 208 | } else { 209 | pfDump = fopen(argv[2], "rb"); 210 | 211 | if (pfDump == NULL) { 212 | ERR("Could not open dump file: %s\n", argv[2]); 213 | exit(EXIT_FAILURE); 214 | } 215 | 216 | if (fread(&mtDump, 1, sizeof(mtDump), pfDump) != sizeof(mtDump)) { 217 | ERR("Could not read from dump file: %s\n", argv[2]); 218 | fclose(pfDump); 219 | exit(EXIT_FAILURE); 220 | } 221 | fclose(pfDump); 222 | } 223 | DBG("Successfully opened the dump file\n"); 224 | 225 | nfc_context *context; 226 | nfc_init(&context); 227 | if (context == NULL) { 228 | ERR("Unable to init libnfc (malloc)"); 229 | exit(EXIT_FAILURE); 230 | } 231 | // Try to open the NFC device 232 | pnd = nfc_open(context, NULL); 233 | if (pnd == NULL) { 234 | ERR("Error opening NFC device"); 235 | nfc_exit(context); 236 | exit(EXIT_FAILURE); 237 | } 238 | 239 | if (nfc_initiator_init(pnd) < 0) { 240 | nfc_perror(pnd, "nfc_initiator_init"); 241 | nfc_close(pnd); 242 | nfc_exit(context); 243 | exit(EXIT_FAILURE); 244 | } 245 | // Let the device only try once to find a tag 246 | if (nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, false) < 0) { 247 | nfc_perror(pnd, "nfc_device_set_property_bool"); 248 | nfc_close(pnd); 249 | nfc_exit(context); 250 | exit(EXIT_FAILURE); 251 | } 252 | 253 | printf("NFC device: %s opened\n", nfc_device_get_name(pnd)); 254 | 255 | // Try to find a MIFARE Ultralight tag 256 | if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 257 | 0) { 258 | ERR("no tag was found\n"); 259 | nfc_close(pnd); 260 | nfc_exit(context); 261 | exit(EXIT_FAILURE); 262 | } 263 | // Test if we are dealing with a MIFARE compatible tag 264 | 265 | if (nt.nti.nai.abtAtqa[1] != 0x44) { 266 | ERR("tag is not a MIFARE Ultralight card\n"); 267 | nfc_close(pnd); 268 | nfc_exit(context); 269 | exit(EXIT_FAILURE); 270 | } 271 | // Get the info from the current tag 272 | printf("Found MIFARE Ultralight card with UID: "); 273 | size_t szPos; 274 | for (szPos = 0; szPos < nt.nti.nai.szUidLen; szPos++) { 275 | printf("%02x", nt.nti.nai.abtUid[szPos]); 276 | } 277 | printf("\n"); 278 | 279 | if (bReadAction) { 280 | if (read_card()) { 281 | printf("Writing data to file: %s ... ", argv[2]); 282 | fflush(stdout); 283 | pfDump = fopen(argv[2], "wb"); 284 | if (pfDump == NULL) { 285 | printf("Could not open file: %s\n", argv[2]); 286 | nfc_close(pnd); 287 | nfc_exit(context); 288 | exit(EXIT_FAILURE); 289 | } 290 | if (fwrite(&mtDump, 1, uiBlocks * 4, pfDump) != 291 | uiBlocks * 4) { 292 | printf("Could not write to file: %s\n", 293 | argv[2]); 294 | fclose(pfDump); 295 | nfc_close(pnd); 296 | nfc_exit(context); 297 | exit(EXIT_FAILURE); 298 | } 299 | fclose(pfDump); 300 | printf("Done.\n"); 301 | } 302 | } else { 303 | write_card(); 304 | } 305 | 306 | nfc_close(pnd); 307 | nfc_exit(context); 308 | exit(EXIT_SUCCESS); 309 | } 310 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 19yy 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) 19yy name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | --------------------------------------------------------------------------------