├── .gitignore ├── LICENSE ├── README.md ├── compiled ├── libnfc.dll ├── libusb0.dll ├── mfocGUI.exe ├── mfocGUI.pdb ├── sqlite3.dll └── stations.db3 ├── src ├── LibNFC │ ├── bin │ │ ├── nfc-list.exe │ │ ├── nfc-mfclassic.exe │ │ ├── nfc-mfultralight.exe │ │ ├── nfc-poll.exe │ │ └── nfc-relay.exe │ ├── include │ │ ├── nfc │ │ │ ├── nfc-emulation.h │ │ │ ├── nfc-messages.h │ │ │ ├── nfc-types.h │ │ │ └── nfc.h │ │ ├── stdbool.h │ │ └── stdint.h │ └── lib │ │ ├── libnfc.lib │ │ └── nfc.lib ├── mfocGUI.sln ├── mfocGUI │ ├── OVData.cpp │ ├── OVData.h │ ├── OVStations.cpp │ ├── OVStations.h │ ├── crapto1.cpp │ ├── crapto1.h │ ├── crypto1.cpp │ ├── libnfc.dll │ ├── libusb0.dll │ ├── mfoc.cpp │ ├── mfoc.h │ ├── mfocGUI.aps │ ├── mfocGUI.rc │ ├── mfocGUI.vcxproj │ ├── mfocGUI.vcxproj.filters │ ├── mfocGUI.vcxproj.user │ ├── mfocMainWindow.cpp │ ├── mfocMainWindow.h │ ├── mifare.cpp │ ├── mifare.h │ ├── nfc-utils.cpp │ ├── nfc-utils.h │ ├── nfc.dll │ ├── ov.ico │ ├── ov_128.png │ ├── resource.h │ ├── sqlite3.dll │ └── stations.db3 └── sqlite │ ├── shell.c │ ├── sqlite3.c │ ├── sqlite3.def │ ├── sqlite3.dll │ ├── sqlite3.exp │ ├── sqlite3.h │ ├── sqlite3.lib │ └── sqlite3ext.h └── untitled folder ├── 20160806193711.png ├── mfocGUI_v29.rar └── mfocGUI_v30_For_PN532.rar /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | 198 | *.VC.db 199 | *.VC.VC.opendb 200 | *.dump -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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 | {description} 294 | Copyright (C) {year} {fullname} 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 along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mfocGUI-For_PN532 2 | =================== 3 | 4 | ``` 5 | This is only for pn532 6 | mfocGUI是mfoc的Windows版本,主要用途为Mifare卡的破解,饭卡,热水卡,等等。。。 7 | 8 | https://www.lastfighting.com/archives/8 9 | ``` 10 | 11 | ---------- 12 | 13 | 14 | 界面预览 15 | ------------- 16 | ![界面](https://github.com/NullYing/mfocGUI_For_PN532/raw/master/untitled%20folder/20160806193711.png) 17 | 18 | ---------- 19 | 20 | 21 | #### Change LOG 22 | 23 | **本次更新** 24 | 25 | - 升级libnfc为1.5.1,更新了部分api函数 26 | - 更新附带的libnfc文件,1.7.1版本 27 | - 修改默认key 28 | - 没去折腾acr122的驱动 29 | 30 | **未完成的开发:** 31 | 32 | - 由于libnfc版本过老,更新需要修改所有libnfc api函数。该版本libnfc为1.5.1,未编译进去acr122驱动(没设备),故只支持pn532 33 | 34 | ---------- 35 | 36 | -------------------------------------------------------------------------------- /compiled/libnfc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/compiled/libnfc.dll -------------------------------------------------------------------------------- /compiled/libusb0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/compiled/libusb0.dll -------------------------------------------------------------------------------- /compiled/mfocGUI.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/compiled/mfocGUI.exe -------------------------------------------------------------------------------- /compiled/mfocGUI.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/compiled/mfocGUI.pdb -------------------------------------------------------------------------------- /compiled/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/compiled/sqlite3.dll -------------------------------------------------------------------------------- /compiled/stations.db3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/compiled/stations.db3 -------------------------------------------------------------------------------- /src/LibNFC/bin/nfc-list.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/bin/nfc-list.exe -------------------------------------------------------------------------------- /src/LibNFC/bin/nfc-mfclassic.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/bin/nfc-mfclassic.exe -------------------------------------------------------------------------------- /src/LibNFC/bin/nfc-mfultralight.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/bin/nfc-mfultralight.exe -------------------------------------------------------------------------------- /src/LibNFC/bin/nfc-poll.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/bin/nfc-poll.exe -------------------------------------------------------------------------------- /src/LibNFC/bin/nfc-relay.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/bin/nfc-relay.exe -------------------------------------------------------------------------------- /src/LibNFC/include/nfc/nfc-emulation.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Public platform independent Near Field Communication (NFC) library 3 | * 4 | * Copyright (C) 2011, Romuald Conty, Romain Tartière 5 | * 6 | * This program is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as published by the 8 | * Free Software Foundation, either version 3 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see 18 | */ 19 | 20 | #ifndef __NFC_EMULATION_H__ 21 | #define __NFC_EMULATION_H__ 22 | 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /* __cplusplus */ 29 | 30 | struct nfc_emulator; 31 | struct nfc_emulation_state_machine; 32 | 33 | 34 | struct nfc_emulator { 35 | nfc_target_t *target; 36 | struct nfc_emulation_state_machine *state_machine; 37 | void *user_data; 38 | }; 39 | 40 | struct nfc_emulation_state_machine { 41 | int (*io)(struct nfc_emulator *emulator, const byte_t *data_in, const size_t data_in_len, byte_t *data_out, const size_t data_out_len); 42 | void *data; 43 | }; 44 | 45 | NFC_EXPORT int nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulator *emulator); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif /* __cplusplus */ 50 | 51 | 52 | #endif /* __NFC_EMULATION_H__ */ 53 | -------------------------------------------------------------------------------- /src/LibNFC/include/nfc/nfc-messages.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Public platform independent Near Field Communication (NFC) library 3 | * 4 | * Copyright (C) 2009, Roel Verdult 5 | * 6 | * This program is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as published by the 8 | * Free Software Foundation, either version 3 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see 18 | * 19 | * 20 | * @file messages.h 21 | * @brief 22 | */ 23 | 24 | #ifndef _LIBNFC_MESSAGES_H_ 25 | # define _LIBNFC_MESSAGES_H_ 26 | 27 | # include 28 | 29 | // #define DEBUG /* DEBUG flag can also be enabled using ./configure --enable-debug */ 30 | 31 | // Useful macros 32 | # ifdef DEBUG 33 | // #define DBG(x, args...) printf("DBG %s:%d: " x "\n", __FILE__, __LINE__,## args ) 34 | # define DBG(...) do { \ 35 | warnx ("DBG %s:%d", __FILE__, __LINE__); \ 36 | warnx (" " __VA_ARGS__ ); \ 37 | } while (0) 38 | # else 39 | # define DBG(...) {} 40 | # endif 41 | 42 | # define INFO(...) warnx ("INFO: " __VA_ARGS__ ) 43 | # define WARN(...) warnx ("WARNING: " __VA_ARGS__ ) 44 | # define ERR(...) warnx ("ERROR: " __VA_ARGS__ ) 45 | 46 | #endif // _LIBNFC_MESSAGES_H_ 47 | -------------------------------------------------------------------------------- /src/LibNFC/include/nfc/nfc-types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Public platform independent Near Field Communication (NFC) library 3 | * 4 | * Copyright (C) 2009, Roel Verdult 5 | * Copyright (C) 2010, Romain Tartière, Romuald Conty 6 | * Copyright (C) 2011, Romain Tartière, Romuald Conty 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 | 22 | /** 23 | * @file nfc-types.h 24 | * @brief Define NFC types 25 | */ 26 | 27 | #ifndef __NFC_TYPES_H__ 28 | # define __NFC_TYPES_H__ 29 | 30 | # include 31 | # include 32 | # include 33 | # include 34 | 35 | typedef uint8_t byte_t; 36 | 37 | # define DEVICE_NAME_LENGTH 256 38 | # define DEVICE_PORT_LENGTH 64 39 | 40 | /** 41 | * @struct nfc_device_t 42 | * @brief NFC device information 43 | */ 44 | typedef struct { 45 | /** Driver's functions for handling device specific wrapping */ 46 | const struct nfc_driver_t *driver; 47 | void* driver_data; 48 | void* chip_data; 49 | 50 | /** Device name string, including device wrapper firmware */ 51 | char acName[DEVICE_NAME_LENGTH]; 52 | /** Is the crc automaticly added, checked and removed from the frames */ 53 | bool bCrc; 54 | /** Does the chip handle parity bits, all parities are handled as data */ 55 | bool bPar; 56 | /** Should the chip handle frames encapsulation and chaining */ 57 | bool bEasyFraming; 58 | /** Should the chip switch automatically activate ISO14443-4 when 59 | selecting tags supporting it? */ 60 | bool bAutoIso14443_4; 61 | /** Supported modulation encoded in a byte */ 62 | byte_t btSupportByte; 63 | /** Last error reported by the PCD / encountered by the PCD driver 64 | * MSB LSB 65 | * | 00 | 00 | 66 | * || || 67 | * || ++----- Chip-level error (as reported by the PCD) 68 | * |+---------- Driver-level specific error 69 | * +----------- Driver-level general error (common to all drivers) 70 | */ 71 | int iLastError; 72 | } nfc_device_t; 73 | 74 | /** 75 | * @struct nfc_device_desc_t 76 | * @brief NFC device description 77 | * 78 | * This struct is used to try to connect to a specified nfc device when nfc_connect(...) 79 | */ 80 | typedef struct { 81 | /** Device name (e.g. "ACS ACR 38U-CCID 00 00") */ 82 | char acDevice[DEVICE_NAME_LENGTH]; 83 | /** Driver name (e.g. "PN532_UART")*/ 84 | char *pcDriver; 85 | /** Port (e.g. "/dev/ttyUSB0") */ 86 | char acPort[DEVICE_PORT_LENGTH]; 87 | /** Port speed (e.g. "115200") */ 88 | uint32_t uiSpeed; 89 | /** Device index for backward compatibility (used to choose one specific device in USB or PSCS devices list) */ 90 | uint32_t uiBusIndex; 91 | } nfc_device_desc_t; 92 | 93 | // Compiler directive, set struct alignment to 1 byte_t for compatibility 94 | # pragma pack(1) 95 | 96 | /** 97 | * @enum nfc_device_option_t 98 | * @brief NFC device option 99 | */ 100 | typedef enum { 101 | /** Let the PN53X chip handle the CRC bytes. This means that the chip appends 102 | * the CRC bytes to the frames that are transmitted. It will parse the last 103 | * bytes from received frames as incoming CRC bytes. They will be verified 104 | * against the used modulation and protocol. If an frame is expected with 105 | * incorrect CRC bytes this option should be disabled. Example frames where 106 | * this is useful are the ATQA and UID+BCC that are transmitted without CRC 107 | * bytes during the anti-collision phase of the ISO14443-A protocol. */ 108 | NDO_HANDLE_CRC = 0x00, 109 | /** Parity bits in the network layer of ISO14443-A are by default generated and 110 | * validated in the PN53X chip. This is a very convenient feature. On certain 111 | * times though it is useful to get full control of the transmitted data. The 112 | * proprietary MIFARE Classic protocol uses for example custom (encrypted) 113 | * parity bits. For interoperability it is required to be completely 114 | * compatible, including the arbitrary parity bits. When this option is 115 | * disabled, the functions to communicating bits should be used. */ 116 | NDO_HANDLE_PARITY = 0x01, 117 | /** This option can be used to enable or disable the electronic field of the 118 | * NFC device. */ 119 | NDO_ACTIVATE_FIELD = 0x10, 120 | /** The internal CRYPTO1 co-processor can be used to transmit messages 121 | * encrypted. This option is automatically activated after a successful MIFARE 122 | * Classic authentication. */ 123 | NDO_ACTIVATE_CRYPTO1 = 0x11, 124 | /** The default configuration defines that the PN53X chip will try indefinitely 125 | * to invite a tag in the field to respond. This could be desired when it is 126 | * certain a tag will enter the field. On the other hand, when this is 127 | * uncertain, it will block the application. This option could best be compared 128 | * to the (NON)BLOCKING option used by (socket)network programming. */ 129 | NDO_INFINITE_SELECT = 0x20, 130 | /** If this option is enabled, frames that carry less than 4 bits are allowed. 131 | * According to the standards these frames should normally be handles as 132 | * invalid frames. */ 133 | NDO_ACCEPT_INVALID_FRAMES = 0x30, 134 | /** If the NFC device should only listen to frames, it could be useful to let 135 | * it gather multiple frames in a sequence. They will be stored in the internal 136 | * FIFO of the PN53X chip. This could be retrieved by using the receive data 137 | * functions. Note that if the chip runs out of bytes (FIFO = 64 bytes long), 138 | * it will overwrite the first received frames, so quick retrieving of the 139 | * received data is desirable. */ 140 | NDO_ACCEPT_MULTIPLE_FRAMES = 0x31, 141 | /** This option can be used to enable or disable the auto-switching mode to 142 | * ISO14443-4 is device is compliant. 143 | * In initiator mode, it means that NFC chip will send RATS automatically when 144 | * select and it will automatically poll for ISO14443-4 card when ISO14443A is 145 | * requested. 146 | * In target mode, with a NFC chip compiliant (ie. PN532), the chip will 147 | * emulate a 14443-4 PICC using hardware capability */ 148 | NDO_AUTO_ISO14443_4 = 0x40, 149 | /** Use automatic frames encapsulation and chaining. */ 150 | NDO_EASY_FRAMING = 0x41, 151 | /** Force the chip to switch in ISO14443-A */ 152 | NDO_FORCE_ISO14443_A = 0x42, 153 | /** Force the chip to switch in ISO14443-B */ 154 | NDO_FORCE_ISO14443_B = 0x43, 155 | /** Force the chip to run at 106 kbps */ 156 | NDO_FORCE_SPEED_106 = 0x50, 157 | } nfc_device_option_t; 158 | 159 | /** 160 | * @enum nfc_dep_mode_t 161 | * @brief NFC D.E.P. (Data Exchange Protocol) active/passive mode 162 | */ 163 | typedef enum { 164 | NDM_UNDEFINED = 0, 165 | NDM_PASSIVE, 166 | NDM_ACTIVE, 167 | } nfc_dep_mode_t; 168 | 169 | /** 170 | * @struct nfc_dep_info_t 171 | * @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 (NFCIP-1) 172 | */ 173 | typedef struct { 174 | /** NFCID3 */ 175 | byte_t abtNFCID3[10]; 176 | /** DID */ 177 | byte_t btDID; 178 | /** Supported send-bit rate */ 179 | byte_t btBS; 180 | /** Supported receive-bit rate */ 181 | byte_t btBR; 182 | /** Timeout value */ 183 | byte_t btTO; 184 | /** PP Parameters */ 185 | byte_t btPP; 186 | /** General Bytes */ 187 | byte_t abtGB[48]; 188 | size_t szGB; 189 | /** DEP mode */ 190 | nfc_dep_mode_t ndm; 191 | } nfc_dep_info_t; 192 | 193 | /** 194 | * @struct nfc_iso14443a_info_t 195 | * @brief NFC ISO14443A tag (MIFARE) information 196 | */ 197 | typedef struct { 198 | byte_t abtAtqa[2]; 199 | byte_t btSak; 200 | size_t szUidLen; 201 | byte_t abtUid[10]; 202 | size_t szAtsLen; 203 | byte_t abtAts[254]; // Maximal theoretical ATS is FSD-2, FSD=256 for FSDI=8 in RATS 204 | } nfc_iso14443a_info_t; 205 | 206 | /** 207 | * @struct nfc_felica_info_t 208 | * @brief NFC FeLiCa tag information 209 | */ 210 | typedef struct { 211 | size_t szLen; 212 | byte_t btResCode; 213 | byte_t abtId[8]; 214 | byte_t abtPad[8]; 215 | byte_t abtSysCode[2]; 216 | } nfc_felica_info_t; 217 | 218 | /** 219 | * @struct nfc_iso14443b_info_t 220 | * @brief NFC ISO14443B tag information 221 | */ 222 | typedef struct { 223 | /** abtPupi store PUPI contained in ATQB (Answer To reQuest of type B) (see ISO14443-3) */ 224 | byte_t abtPupi[4]; 225 | /** abtApplicationData store Application Data contained in ATQB (see ISO14443-3) */ 226 | byte_t abtApplicationData[4]; 227 | /** abtProtocolInfo store Protocol Info contained in ATQB (see ISO14443-3) */ 228 | byte_t abtProtocolInfo[3]; 229 | /** ui8CardIdentifier store CID (Card Identifier) attributted by PCD to the PICC */ 230 | uint8_t ui8CardIdentifier; 231 | } nfc_iso14443b_info_t; 232 | 233 | /** 234 | * @struct nfc_iso14443bi_info_t 235 | * @brief NFC ISO14443B' tag information 236 | */ 237 | typedef struct { 238 | /** DIV: 4 LSBytes of tag serial number */ 239 | byte_t abtDIV[4]; 240 | /** Software version & type of REPGEN */ 241 | byte_t btVerLog; 242 | /** Config Byte, present if long REPGEN */ 243 | byte_t btConfig; 244 | /** ATR, if any */ 245 | size_t szAtrLen; 246 | byte_t abtAtr[33]; 247 | } nfc_iso14443bi_info_t; 248 | 249 | /** 250 | * @struct nfc_iso14443b2sr_info_t 251 | * @brief NFC ISO14443-2B ST SRx tag information 252 | */ 253 | typedef struct { 254 | byte_t abtUID[8]; 255 | } nfc_iso14443b2sr_info_t; 256 | 257 | /** 258 | * @struct nfc_iso14443b2ct_info_t 259 | * @brief NFC ISO14443-2B ASK CTx tag information 260 | */ 261 | typedef struct { 262 | byte_t abtUID[4]; 263 | byte_t btProdCode; 264 | byte_t btFabCode; 265 | } nfc_iso14443b2ct_info_t; 266 | 267 | /** 268 | * @struct nfc_jewel_info_t 269 | * @brief NFC Jewel tag information 270 | */ 271 | typedef struct { 272 | byte_t btSensRes[2]; 273 | byte_t btId[4]; 274 | } nfc_jewel_info_t; 275 | 276 | /** 277 | * @union nfc_target_info_t 278 | * @brief Union between all kind of tags information structures. 279 | */ 280 | typedef union { 281 | nfc_iso14443a_info_t nai; 282 | nfc_felica_info_t nfi; 283 | nfc_iso14443b_info_t nbi; 284 | nfc_iso14443bi_info_t nii; 285 | nfc_iso14443b2sr_info_t nsi; 286 | nfc_iso14443b2ct_info_t nci; 287 | nfc_jewel_info_t nji; 288 | nfc_dep_info_t ndi; 289 | } nfc_target_info_t; 290 | 291 | /** 292 | * @enum nfc_baud_rate_t 293 | * @brief NFC baud rate enumeration 294 | */ 295 | typedef enum { 296 | NBR_UNDEFINED = 0, 297 | NBR_106, 298 | NBR_212, 299 | NBR_424, 300 | NBR_847, 301 | } nfc_baud_rate_t; 302 | 303 | /** 304 | * @enum nfc_modulation_type_t 305 | * @brief NFC modulation type enumeration 306 | */ 307 | typedef enum { 308 | NMT_ISO14443A, 309 | NMT_JEWEL, 310 | NMT_ISO14443B, 311 | NMT_ISO14443BI, // pre-ISO14443B aka ISO/IEC 14443 B' or Type B' 312 | NMT_ISO14443B2SR, // ISO14443-2B ST SRx 313 | NMT_ISO14443B2CT, // ISO14443-2B ASK CTx 314 | NMT_FELICA, 315 | NMT_DEP, 316 | } nfc_modulation_type_t; 317 | 318 | /** 319 | * @struct nfc_modulation_t 320 | * @brief NFC modulation structure 321 | */ 322 | typedef struct { 323 | nfc_modulation_type_t nmt; 324 | nfc_baud_rate_t nbr; 325 | } nfc_modulation_t; 326 | 327 | /** 328 | * @struct nfc_target_t 329 | * @brief NFC target structure 330 | */ 331 | typedef struct { 332 | nfc_target_info_t nti; 333 | nfc_modulation_t nm; 334 | } nfc_target_t; 335 | 336 | // Reset struct alignment to default 337 | # pragma pack() 338 | 339 | #endif // _LIBNFC_TYPES_H_ 340 | -------------------------------------------------------------------------------- /src/LibNFC/include/nfc/nfc.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Public platform independent Near Field Communication (NFC) library 3 | * 4 | * Copyright (C) 2009, Roel Verdult 5 | * Copyright (C) 2010, Romuald Conty 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 | 21 | /** 22 | * @file nfc.h 23 | * @brief libnfc interface 24 | * 25 | * Provide all usefull functions (API) to handle NFC devices. 26 | */ 27 | 28 | #ifndef _LIBNFC_H_ 29 | # define _LIBNFC_H_ 30 | 31 | # include 32 | # include 33 | 34 | # ifdef _WIN32 35 | /* Windows platform */ 36 | # ifndef _WINDLL 37 | /* CMake compilation */ 38 | # ifdef nfc_EXPORTS 39 | # define NFC_EXPORT __declspec(dllexport) 40 | # else 41 | /* nfc_EXPORTS */ 42 | # define NFC_EXPORT __declspec(dllimport) 43 | # endif 44 | /* nfc_EXPORTS */ 45 | # else 46 | /* _WINDLL */ 47 | /* Manual makefile */ 48 | # define NFC_EXPORT 49 | # endif 50 | /* _WINDLL */ 51 | # else 52 | /* _WIN32 */ 53 | # define NFC_EXPORT 54 | # endif 55 | /* _WIN32 */ 56 | 57 | # include 58 | 59 | # ifdef __cplusplus 60 | extern "C" { 61 | # endif // __cplusplus 62 | 63 | /* NFC Device/Hardware manipulation */ 64 | NFC_EXPORT nfc_device_t *nfc_connect (nfc_device_desc_t * pndd); 65 | NFC_EXPORT void nfc_disconnect (nfc_device_t * pnd); 66 | NFC_EXPORT bool nfc_abort_command (nfc_device_t * pnd); 67 | NFC_EXPORT void nfc_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound); 68 | NFC_EXPORT bool nfc_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable); 69 | NFC_EXPORT bool nfc_idle (nfc_device_t * pnd); 70 | 71 | /* NFC initiator: act as "reader" */ 72 | NFC_EXPORT bool nfc_initiator_init (nfc_device_t * pnd); 73 | NFC_EXPORT bool nfc_initiator_select_passive_target (nfc_device_t * pnd, const nfc_modulation_t nm, const byte_t * pbtInitData, const size_t szInitData, nfc_target_t * pnt); 74 | NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device_t * pnd, const nfc_modulation_t nm, nfc_target_t ant[], const size_t szTargets, size_t * pszTargetFound); 75 | NFC_EXPORT bool nfc_initiator_poll_target (nfc_device_t * pnd, const nfc_modulation_t * pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target_t * pnt); 76 | NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr, const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt); 77 | NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd); 78 | NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, struct timeval *timeout); 79 | NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); 80 | NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx, uint32_t * cycles); 81 | NFC_EXPORT bool nfc_initiator_transceive_bits_timed (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar, uint32_t * cycles); 82 | 83 | /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ 84 | NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_t * pszRx); 85 | NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, struct timeval *timout); 86 | NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx, struct timeval *timout); 87 | NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, const byte_t * pbtTxPar); 88 | NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar); 89 | 90 | /* Error reporting */ 91 | NFC_EXPORT const char *nfc_strerror (const nfc_device_t * pnd); 92 | NFC_EXPORT int nfc_strerror_r (const nfc_device_t * pnd, char *pcStrErrBuf, size_t szBufLen); 93 | NFC_EXPORT void nfc_perror (const nfc_device_t * pnd, const char *pcString); 94 | 95 | /* Special data accessors */ 96 | NFC_EXPORT const char *nfc_device_name (nfc_device_t * pnd); 97 | 98 | /* Misc. functions */ 99 | NFC_EXPORT void iso14443a_crc (byte_t * pbtData, size_t szLen, byte_t * pbtCrc); 100 | NFC_EXPORT void iso14443a_crc_append (byte_t * pbtData, size_t szLen); 101 | NFC_EXPORT byte_t * iso14443a_locate_historical_bytes (byte_t * pbtAts, size_t szAts, size_t * pszTk); 102 | NFC_EXPORT const char *nfc_version (void); 103 | 104 | /* PN53x specific errors */ 105 | // TODO: Be not PN53x-specific here 106 | #define ETIMEOUT 0x01 107 | #define ECRC 0x02 108 | #define EPARITY 0x03 109 | #define EBITCOUNT 0x04 110 | #define EFRAMING 0x05 111 | #define EBITCOLL 0x06 112 | #define ESMALLBUF 0x07 113 | #define EBUFOVF 0x09 114 | #define ERFTIMEOUT 0x0a 115 | #define ERFPROTO 0x0b 116 | #define EOVHEAT 0x0d 117 | #define EINBUFOVF 0x0e 118 | #define EINVPARAM 0x10 119 | #define EDEPUNKCMD 0x12 120 | #define EINVRXFRAM 0x13 121 | #define EMFAUTH 0x14 122 | #define ENSECNOTSUPP 0x18 // PN533 only 123 | #define EBCC 0x23 124 | #define EDEPINVSTATE 0x25 125 | #define EOPNOTALL 0x26 126 | #define ECMD 0x27 127 | #define ETGREL 0x29 128 | #define ECID 0x2a 129 | #define ECDISCARDED 0x2b 130 | #define ENFCID3 0x2c 131 | #define EOVCURRENT 0x2d 132 | #define ENAD 0x2e 133 | 134 | /* PN53x framing-level errors */ 135 | #define EFRAACKMISMATCH 0x0100 /* Unexpected data */ 136 | #define EFRAISERRFRAME 0x0101 /* Error frame */ 137 | 138 | /* Communication-level errors */ 139 | #define ECOMIO 0x1000 /* Input/output error */ 140 | #define ECOMTIMEOUT 0x1001 /* Operation timeout */ 141 | 142 | /* Software level errors */ 143 | #define ETGUIDNOTSUP 0xFF00 /* Target UID not supported */ 144 | #define EOPABORT 0xFF01 /* Operation aborted */ 145 | #define EINVALARG 0xFF02 /* Invalid argument */ 146 | #define EDEVNOTSUP 0xFF03 /* Not supported by device */ 147 | #define ENOTIMPL 0xFF04 /* Not (yet) implemented in libnfc */ 148 | 149 | # ifdef __cplusplus 150 | } 151 | # endif // __cplusplus 152 | #endif // _LIBNFC_H_ 153 | -------------------------------------------------------------------------------- /src/LibNFC/include/stdbool.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/include/stdbool.h -------------------------------------------------------------------------------- /src/LibNFC/include/stdint.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant stdint.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2008 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. The name of the author may be used to endorse or promote products 17 | // derived from this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 22 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef _MSC_VER // [ 33 | #error "Use this header only with Microsoft Visual C++ compilers!" 34 | #endif // _MSC_VER ] 35 | 36 | #ifndef _MSC_STDINT_H_ // [ 37 | #define _MSC_STDINT_H_ 38 | 39 | #if _MSC_VER > 1000 40 | #pragma once 41 | #endif 42 | 43 | #include 44 | 45 | // For Visual Studio 6 in C++ mode and for many Visual Studio versions when 46 | // compiling for ARM we should wrap include with 'extern "C++" {}' 47 | // or compiler give many errors like this: 48 | // error C2733: second C linkage of overloaded function 'wmemchr' not allowed 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | # include 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | // Define _W64 macros to mark types changing their size, like intptr_t. 58 | #ifndef _W64 59 | # if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 60 | # define _W64 __w64 61 | # else 62 | # define _W64 63 | # endif 64 | #endif 65 | 66 | 67 | // 7.18.1 Integer types 68 | 69 | // 7.18.1.1 Exact-width integer types 70 | 71 | // Visual Studio 6 and Embedded Visual C++ 4 doesn't 72 | // realize that, e.g. char has the same size as __int8 73 | // so we give up on __intX for them. 74 | #if (_MSC_VER < 1300) 75 | typedef signed char int8_t; 76 | typedef signed short int16_t; 77 | typedef signed int int32_t; 78 | typedef unsigned char uint8_t; 79 | typedef unsigned short uint16_t; 80 | typedef unsigned int uint32_t; 81 | #else 82 | typedef signed __int8 int8_t; 83 | typedef signed __int16 int16_t; 84 | typedef signed __int32 int32_t; 85 | typedef unsigned __int8 uint8_t; 86 | typedef unsigned __int16 uint16_t; 87 | typedef unsigned __int32 uint32_t; 88 | #endif 89 | typedef signed __int64 int64_t; 90 | typedef unsigned __int64 uint64_t; 91 | 92 | 93 | // 7.18.1.2 Minimum-width integer types 94 | typedef int8_t int_least8_t; 95 | typedef int16_t int_least16_t; 96 | typedef int32_t int_least32_t; 97 | typedef int64_t int_least64_t; 98 | typedef uint8_t uint_least8_t; 99 | typedef uint16_t uint_least16_t; 100 | typedef uint32_t uint_least32_t; 101 | typedef uint64_t uint_least64_t; 102 | 103 | // 7.18.1.3 Fastest minimum-width integer types 104 | typedef int8_t int_fast8_t; 105 | typedef int16_t int_fast16_t; 106 | typedef int32_t int_fast32_t; 107 | typedef int64_t int_fast64_t; 108 | typedef uint8_t uint_fast8_t; 109 | typedef uint16_t uint_fast16_t; 110 | typedef uint32_t uint_fast32_t; 111 | typedef uint64_t uint_fast64_t; 112 | 113 | // 7.18.1.4 Integer types capable of holding object pointers 114 | #ifdef _WIN64 // [ 115 | typedef signed __int64 intptr_t; 116 | typedef unsigned __int64 uintptr_t; 117 | #else // _WIN64 ][ 118 | typedef _W64 signed int intptr_t; 119 | typedef _W64 unsigned int uintptr_t; 120 | #endif // _WIN64 ] 121 | 122 | // 7.18.1.5 Greatest-width integer types 123 | typedef int64_t intmax_t; 124 | typedef uint64_t uintmax_t; 125 | 126 | 127 | // 7.18.2 Limits of specified-width integer types 128 | 129 | #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 130 | 131 | // 7.18.2.1 Limits of exact-width integer types 132 | #define INT8_MIN ((int8_t)_I8_MIN) 133 | #define INT8_MAX _I8_MAX 134 | #define INT16_MIN ((int16_t)_I16_MIN) 135 | #define INT16_MAX _I16_MAX 136 | #define INT32_MIN ((int32_t)_I32_MIN) 137 | #define INT32_MAX _I32_MAX 138 | #define INT64_MIN ((int64_t)_I64_MIN) 139 | #define INT64_MAX _I64_MAX 140 | #define UINT8_MAX _UI8_MAX 141 | #define UINT16_MAX _UI16_MAX 142 | #define UINT32_MAX _UI32_MAX 143 | #define UINT64_MAX _UI64_MAX 144 | 145 | // 7.18.2.2 Limits of minimum-width integer types 146 | #define INT_LEAST8_MIN INT8_MIN 147 | #define INT_LEAST8_MAX INT8_MAX 148 | #define INT_LEAST16_MIN INT16_MIN 149 | #define INT_LEAST16_MAX INT16_MAX 150 | #define INT_LEAST32_MIN INT32_MIN 151 | #define INT_LEAST32_MAX INT32_MAX 152 | #define INT_LEAST64_MIN INT64_MIN 153 | #define INT_LEAST64_MAX INT64_MAX 154 | #define UINT_LEAST8_MAX UINT8_MAX 155 | #define UINT_LEAST16_MAX UINT16_MAX 156 | #define UINT_LEAST32_MAX UINT32_MAX 157 | #define UINT_LEAST64_MAX UINT64_MAX 158 | 159 | // 7.18.2.3 Limits of fastest minimum-width integer types 160 | #define INT_FAST8_MIN INT8_MIN 161 | #define INT_FAST8_MAX INT8_MAX 162 | #define INT_FAST16_MIN INT16_MIN 163 | #define INT_FAST16_MAX INT16_MAX 164 | #define INT_FAST32_MIN INT32_MIN 165 | #define INT_FAST32_MAX INT32_MAX 166 | #define INT_FAST64_MIN INT64_MIN 167 | #define INT_FAST64_MAX INT64_MAX 168 | #define UINT_FAST8_MAX UINT8_MAX 169 | #define UINT_FAST16_MAX UINT16_MAX 170 | #define UINT_FAST32_MAX UINT32_MAX 171 | #define UINT_FAST64_MAX UINT64_MAX 172 | 173 | // 7.18.2.4 Limits of integer types capable of holding object pointers 174 | #ifdef _WIN64 // [ 175 | # define INTPTR_MIN INT64_MIN 176 | # define INTPTR_MAX INT64_MAX 177 | # define UINTPTR_MAX UINT64_MAX 178 | #else // _WIN64 ][ 179 | # define INTPTR_MIN INT32_MIN 180 | # define INTPTR_MAX INT32_MAX 181 | # define UINTPTR_MAX UINT32_MAX 182 | #endif // _WIN64 ] 183 | 184 | // 7.18.2.5 Limits of greatest-width integer types 185 | #define INTMAX_MIN INT64_MIN 186 | #define INTMAX_MAX INT64_MAX 187 | #define UINTMAX_MAX UINT64_MAX 188 | 189 | // 7.18.3 Limits of other integer types 190 | 191 | #ifdef _WIN64 // [ 192 | # define PTRDIFF_MIN _I64_MIN 193 | # define PTRDIFF_MAX _I64_MAX 194 | #else // _WIN64 ][ 195 | # define PTRDIFF_MIN _I32_MIN 196 | # define PTRDIFF_MAX _I32_MAX 197 | #endif // _WIN64 ] 198 | 199 | #define SIG_ATOMIC_MIN INT_MIN 200 | #define SIG_ATOMIC_MAX INT_MAX 201 | 202 | #ifndef SIZE_MAX // [ 203 | # ifdef _WIN64 // [ 204 | # define SIZE_MAX _UI64_MAX 205 | # else // _WIN64 ][ 206 | # define SIZE_MAX _UI32_MAX 207 | # endif // _WIN64 ] 208 | #endif // SIZE_MAX ] 209 | 210 | // WCHAR_MIN and WCHAR_MAX are also defined in 211 | #ifndef WCHAR_MIN // [ 212 | # define WCHAR_MIN 0 213 | #endif // WCHAR_MIN ] 214 | #ifndef WCHAR_MAX // [ 215 | # define WCHAR_MAX _UI16_MAX 216 | #endif // WCHAR_MAX ] 217 | 218 | #define WINT_MIN 0 219 | #define WINT_MAX _UI16_MAX 220 | 221 | #endif // __STDC_LIMIT_MACROS ] 222 | 223 | 224 | // 7.18.4 Limits of other integer types 225 | 226 | #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 227 | 228 | // 7.18.4.1 Macros for minimum-width integer constants 229 | 230 | #define INT8_C(val) val##i8 231 | #define INT16_C(val) val##i16 232 | #define INT32_C(val) val##i32 233 | #define INT64_C(val) val##i64 234 | 235 | #define UINT8_C(val) val##ui8 236 | #define UINT16_C(val) val##ui16 237 | #define UINT32_C(val) val##ui32 238 | #define UINT64_C(val) val##ui64 239 | 240 | // 7.18.4.2 Macros for greatest-width integer constants 241 | #define INTMAX_C INT64_C 242 | #define UINTMAX_C UINT64_C 243 | 244 | #endif // __STDC_CONSTANT_MACROS ] 245 | 246 | 247 | #endif // _MSC_STDINT_H_ ] -------------------------------------------------------------------------------- /src/LibNFC/lib/libnfc.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/lib/libnfc.lib -------------------------------------------------------------------------------- /src/LibNFC/lib/nfc.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/LibNFC/lib/nfc.lib -------------------------------------------------------------------------------- /src/mfocGUI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mfocGUI", "mfocGUI\mfocGUI.vcxproj", "{8C770BD4-C5CD-4743-93C4-BEB3D52EDC10}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {8C770BD4-C5CD-4743-93C4-BEB3D52EDC10}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {8C770BD4-C5CD-4743-93C4-BEB3D52EDC10}.Debug|Win32.Build.0 = Debug|Win32 14 | {8C770BD4-C5CD-4743-93C4-BEB3D52EDC10}.Release|Win32.ActiveCfg = Release|Win32 15 | {8C770BD4-C5CD-4743-93C4-BEB3D52EDC10}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /src/mfocGUI/OVData.cpp: -------------------------------------------------------------------------------- 1 | #include "OVData.h" 2 | #include 3 | #include 4 | #include 5 | 6 | //Number of days in a month 7 | int DaysInMonth[12] = { 8 | 31, //Jan 9 | 28, //feb 10 | 31, //mar 11 | 30, //apr 12 | 31, //may 13 | 30, //jun 14 | 31, //jul 15 | 31, //aug 16 | 30, //sep 17 | 31, //oct 18 | 30, //nov 19 | 31, //dec 20 | }; 21 | 22 | //! Is the given year a leap year? 23 | int is_leapyear(unsigned int year) { 24 | return (year % 4) ? 0 : (!(year % 400)) ? 1 : (!(year % 100)) ? 0 : 1; 25 | } 26 | 27 | //! Add days since 1997-1-1 28 | void GetDateSince1997(unsigned int days, char *out) { 29 | unsigned int iYear = 1997; 30 | unsigned int iLeap = 0; 31 | unsigned int iMonth = 0; 32 | 33 | while (days >= 365 + iLeap) { 34 | days -= 365 + iLeap; 35 | iYear++; 36 | iLeap = is_leapyear(iYear); 37 | } 38 | 39 | while (days >= DaysInMonth[iMonth] + ((iMonth == 2 && iLeap)?1:0)) { 40 | days -= DaysInMonth[iMonth] + ((iMonth == 2 && iLeap)?1:0); 41 | iMonth++; 42 | } 43 | 44 | sprintf(out, "%04u-%02u-%02u", iYear, iMonth + 1, days + 1); 45 | } 46 | 47 | //! Get the company name 48 | void GetCompanyName(unsigned int company, char *out) { 49 | switch (company) { 50 | case 0: sprintf(out, "TLS"); return; 51 | case 1: sprintf(out, "Connexxion"); return; 52 | case 2: sprintf(out, "GVB"); return; 53 | case 3: sprintf(out, "HTM"); return; 54 | case 4: sprintf(out, "NS"); return; 55 | case 5: sprintf(out, "RET"); return; 56 | case 7: sprintf(out, "Veolia"); return; 57 | case 8: sprintf(out, "Arriva"); return; 58 | case 9: sprintf(out, "Syntus"); return; 59 | case 12: sprintf(out, "DUO"); return; 60 | default: sprintf(out, "Unknown %i", company); return; 61 | } 62 | } 63 | 64 | //! Get the transfer action 65 | void GetTransfer(unsigned int transfer, char *out) { 66 | switch (transfer) { 67 | case 0: sprintf(out, "purchase"); return; 68 | case 1: sprintf(out, "check-in"); return; 69 | case 2: sprintf(out, "check-out"); return; 70 | case 6: sprintf(out, "transfer"); return; 71 | case -2: sprintf(out, "credit"); return; 72 | case -3: sprintf(out, "no-data"); return; 73 | default: sprintf(out, "Unknown %i", transfer); return; 74 | } 75 | } 76 | 77 | unsigned int GetBitsFromBuffer(unsigned char * buffer, int iStartBit, int iLength) { 78 | int iEndBit = iStartBit + iLength - 1; 79 | int iSByte = iStartBit / 8; 80 | int iSBit = iStartBit % 8; 81 | int iEByte = iEndBit / 8; 82 | int iEBit = iEndBit % 8; 83 | if (iSByte == iEByte) { 84 | return (unsigned int)((buffer[iEByte] >> (7 - iEBit)) & (0xFF >> (8 - iLength))); 85 | } 86 | else { 87 | unsigned int uRet = ((buffer[iSByte] & (0xFF >> iSBit)) << (((iEByte - iSByte - 1) * 8) + (iEBit + 1))); 88 | for (int i = iSByte + 1; i < iEByte; i++) { 89 | uRet |= ((buffer[i] & 0xFF) << (((iEByte - i - 1) * 8) + (iEBit + 1))); 90 | } 91 | uRet |= (buffer[iEByte] >> (7 - iEBit)); 92 | return uRet; 93 | } 94 | } 95 | 96 | void OvcSubscription(unsigned char * buffer, int offset, int start, int length, ov_Subscription *ovSubscription) { 97 | ovSubscription->valid = 1; 98 | ovSubscription->location = offset; 99 | ovSubscription->validFrom = 0; 100 | ovSubscription->validTo = 0; 101 | if (buffer[0] == 0x0a && buffer[1] == 0x00 && buffer[2] == 0xe0 && ((buffer[3] & 0xF0) == 0x00)) { 102 | ovSubscription->id = ((buffer[9] & 0xFF) << 4) | ((buffer[10] >> 4) & 0x0F); 103 | ovSubscription->company = ((buffer[4] >> 4) & 0x0F); 104 | ovSubscription->subscription = ((buffer[4] & 0x0F) << 12) | ((buffer[5] & 0xFF) << 4) | ((buffer[6] >> 4) & 0x0F); 105 | ovSubscription->validFrom = ((buffer[11] & 0x07) << 11) | ((buffer[12] & 0xFF) << 3) | ((buffer[13] >> 5) & 0x07); 106 | ovSubscription->validTo = ((buffer[13] & 0x1F) << 9) | ((buffer[14] & 0xFF) << 1) | ((buffer[15] >> 7) & 0x01); 107 | } else if (buffer[0] == 0x0a && buffer[1] == 0x02 && buffer[2] == 0xe0 && ((buffer[3] & 0xF0) == 0x00)) { 108 | ovSubscription->id = ((buffer[9] & 0xFF) << 4) | ((buffer[10] >> 4) & 0x0F); 109 | ovSubscription->company = ((buffer[4] >> 4) & 0x0F); 110 | ovSubscription->subscription = ((buffer[4] & 0x0F) << 12) | ((buffer[5] & 0xFF) << 4) | ((buffer[6] >> 4) & 0x0F); 111 | ovSubscription->validFrom = ((buffer[12] & 0x01) << 13) | ((buffer[13] & 0xFF) << 5) | ((buffer[14] >> 3) & 0x1F); 112 | if ((((buffer[11] & 0x1F) << 7) | ((buffer[12] >> 1) & 0x7F)) == 31) { 113 | ovSubscription->validTo = ((buffer[16] & 0xFF) << 6) | ((buffer[17] >> 2) & 0x3F); 114 | } 115 | if ((((buffer[11] & 0x1F) << 7) | ((buffer[12] >> 1) & 0x7F)) == 21) { 116 | ovSubscription->validTo = ((buffer[14] & 0x07) << 11) | ((buffer[15] & 0xFF) << 3) | ((buffer[16] >> 5) & 0x07); 117 | } 118 | } else { 119 | ovSubscription->valid = 1; 120 | } 121 | } 122 | 123 | //! Interpertate a Classic Transaction 124 | void OvcClassicTransaction(unsigned char * buffer, int offset, int start, int length, ov_data *ovTrans) { 125 | bool bKnown = true; 126 | int iBitOffset = 53; //Ident, Date, Time 127 | 128 | memset(ovTrans, 0, sizeof(ov_data)); 129 | ovTrans->transfer = -3; 130 | if (buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0x00 && (buffer[3] & 0xF0) == 0x00) { 131 | ovTrans->valid = 0; 132 | return; 133 | } 134 | ovTrans->valid = 1; 135 | ovTrans->location = offset; 136 | ovTrans->vehicleId = 0; 137 | ovTrans->date = ((buffer[3] & 0x0F) << 10) | ((buffer[4] & 0xFF) << 2) | ((buffer[5] >> 6) & 0x03); 138 | ovTrans->time = ((buffer[5] & 0x3F) << 5) | ((buffer[6] >> 3) & 0x1F); 139 | if (buffer[3] & 0x10) return; 140 | if (buffer[3] & 0x20) { 141 | ovTrans->unknownConstant = GetBitsFromBuffer(buffer, iBitOffset, 24); 142 | iBitOffset += 24; 143 | } 144 | if (buffer[3] & 0x40) { 145 | ovTrans->transfer = GetBitsFromBuffer(buffer, iBitOffset, 7); 146 | iBitOffset += 7; 147 | } 148 | if (buffer[3] & 0x80) return; 149 | if (buffer[2] & 0x01) { 150 | ovTrans->company = GetBitsFromBuffer(buffer, iBitOffset, 16); 151 | iBitOffset += 16; 152 | } 153 | if (buffer[2] & 0x02) return; 154 | if (buffer[2] & 0x04) { 155 | ovTrans->id = GetBitsFromBuffer(buffer, iBitOffset, 24); 156 | iBitOffset += 24; 157 | } 158 | if (buffer[2] & 0x08) return; 159 | if (buffer[2] & 0x10) { 160 | ovTrans->station = GetBitsFromBuffer(buffer, iBitOffset, 16); 161 | iBitOffset += 16; 162 | } 163 | if (buffer[2] & 0x20) return; 164 | if (buffer[2] & 0x40) { 165 | ovTrans->poleid = GetBitsFromBuffer(buffer, iBitOffset, 24); 166 | iBitOffset += 24; 167 | } 168 | if (buffer[2] & 0x80) return; 169 | if (buffer[1] & 0x01) return; 170 | if (buffer[1] & 0x02) return; 171 | if (buffer[1] & 0x04) { 172 | ovTrans->vehicleId = GetBitsFromBuffer(buffer, iBitOffset, 16); 173 | iBitOffset += 16; 174 | } 175 | if (buffer[1] & 0x08) return; 176 | if (buffer[1] & 0x10) { 177 | ovTrans->productId = GetBitsFromBuffer(buffer, iBitOffset, 5); 178 | iBitOffset += 5; 179 | } 180 | if (buffer[1] & 0x20) return; 181 | if (buffer[1] & 0x40) return; 182 | if (buffer[1] & 0x80) return; 183 | if (buffer[0] & 0x01) { 184 | ovTrans->unknownConstant2 = GetBitsFromBuffer(buffer, iBitOffset, 16); 185 | iBitOffset += 16; 186 | } 187 | if (buffer[0] & 0x02) return; 188 | if (buffer[0] & 0x04) return; 189 | if (buffer[0] & 0x08) { 190 | ovTrans->amount = GetBitsFromBuffer(buffer, iBitOffset, 16); 191 | iBitOffset += 16; 192 | } 193 | } 194 | 195 | void GetSubscription(unsigned int company, unsigned int subscription, char *out) { 196 | if (company == 4 && subscription == 5) { 197 | sprintf(out, "OV-jaarkaart"); 198 | } else if (company == 4 && subscription == 7) { 199 | sprintf(out, "OV-Bijkaart 1e klas"); 200 | } else if (company == 4 && subscription == 17) { 201 | sprintf(out, "NS Businesscard"); 202 | } else if (company == 4 && subscription == 25) { 203 | sprintf(out, "Voordeelurenabonnement (twee jaar)"); 204 | } else if (company == 4 && subscription == 175) { 205 | sprintf(out, "Studenten OV-chipkaart week (2009)"); 206 | } else if (company == 4 && subscription == 176) { 207 | sprintf(out, "Studenten OV-chipkaart weekend (2009)"); 208 | } else if (company == 4 && subscription == 177) { 209 | sprintf(out, "Studentenkaart korting week (2009)"); 210 | } else if (company == 4 && subscription == 178) { 211 | sprintf(out, "Studentenkaart korting weekend (2009)"); 212 | } else if (company == 4 && subscription == 201) { 213 | sprintf(out, "Reizen op saldo bij NS, 1e klasse"); 214 | } else if (company == 4 && subscription == 202) { 215 | sprintf(out, "Reizen op saldo bij NS, 2de klasse"); 216 | } else if (company == 4 && subscription == 206) { 217 | sprintf(out, "Voordeelurenabonnement reizen op saldo"); 218 | } else if (company == 4 && subscription == 229) { 219 | sprintf(out, "Reizen op saldo (tijdelijk eerste klas)"); 220 | } else if (company == 7 && subscription == 1574) { 221 | sprintf(out, "DALU Dalkorting"); 222 | } else if (company == 1 && subscription == 1682) { 223 | sprintf(out, "Daluren Oost-Nederland"); 224 | } else if (company == 12 && subscription == 2502) { 225 | sprintf(out, "Student weekend-vrij"); 226 | } else if (company == 12 && subscription == 2503) { 227 | sprintf(out, "Student week-korting"); 228 | } else if (company == 12 && subscription == 2505) { 229 | sprintf(out, "Student week-vrij"); 230 | } else if (company == 12 && subscription == 2506) { 231 | sprintf(out, "Student weekend-korting"); 232 | } else if (company == 2 && subscription == 3005) { 233 | sprintf(out, "Fietssupplement"); 234 | } else { 235 | sprintf(out, "%u", subscription); 236 | } 237 | } -------------------------------------------------------------------------------- /src/mfocGUI/OVData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef struct { 5 | unsigned char valid; 6 | int location; 7 | unsigned int date; 8 | unsigned int time; 9 | unsigned int unknownConstant; 10 | unsigned int transfer; 11 | unsigned int company; 12 | unsigned int id; 13 | unsigned int station; 14 | unsigned int poleid; 15 | unsigned int vehicleId; 16 | unsigned int productId; 17 | unsigned int unknownConstant2; 18 | unsigned int amount; 19 | 20 | }ov_data; 21 | 22 | typedef struct { 23 | unsigned char valid; 24 | int location; 25 | char company; 26 | unsigned int id; 27 | unsigned int subscription; 28 | unsigned int validFrom; 29 | unsigned int validTo; 30 | } ov_Subscription; 31 | 32 | void GetDateSince1997(unsigned int days, char *out); 33 | void GetCompanyName(unsigned int company, char *out); 34 | void GetTransfer(unsigned int transfer, char *out); 35 | void OvcClassicTransaction(unsigned char * buffer, int offset, int start, int length, ov_data *ovTrans); 36 | void OvcSubscription(unsigned char * buffer, int offset, int start, int length, ov_Subscription *ovSubscription); 37 | void GetSubscription(unsigned int company, unsigned int subscription, char *out); -------------------------------------------------------------------------------- /src/mfocGUI/OVStations.cpp: -------------------------------------------------------------------------------- 1 | #include "OVStations.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #pragma comment(lib, "sqlite3.lib") 8 | 9 | void GetStationInfo(char *databaseFile, unsigned int company, unsigned int station, char *out) { 10 | sqlite3* db; 11 | char* db_err; 12 | char sqlComm[100]; 13 | int result; 14 | 15 | sprintf(out, "Unknown: %u", station); 16 | 17 | sqlite3_open(databaseFile, &db); 18 | 19 | sprintf(sqlComm, "SELECT longname FROM stations_data WHERE company='%i' AND ovcid='%i'", company, station); 20 | sqlite3_stmt *statement; 21 | if (sqlite3_prepare_v2(db, sqlComm, -1, &statement, 0) == SQLITE_OK) { 22 | result = sqlite3_step(statement); 23 | if (result == SQLITE_ROW) { 24 | sprintf(out, "%s", sqlite3_column_text(statement, 0)); 25 | } 26 | } 27 | sqlite3_finalize(statement); 28 | sqlite3_close(db); 29 | } -------------------------------------------------------------------------------- /src/mfocGUI/OVStations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void GetStationInfo(char *databaseFile, unsigned int company, unsigned int station, char *out); 4 | -------------------------------------------------------------------------------- /src/mfocGUI/crapto1.cpp: -------------------------------------------------------------------------------- 1 | /* crapto1.c 2 | 3 | This program is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU General Public License 5 | as published by the Free Software Foundation; either version 2 6 | of the License, or (at your option) any later version. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 | Boston, MA 02110-1301, US$ 17 | 18 | Copyright (C) 2008-2008 bla 19 | */ 20 | #include "crapto1.h" 21 | #include 22 | 23 | #if !defined LOWMEM && defined __GNUC__ 24 | static uint8_t filterlut[1 << 20]; 25 | static void __attribute__((constructor)) fill_lut() 26 | { 27 | uint32_t i; 28 | for(i = 0; i < 1 << 20; ++i) 29 | filterlut[i] = filter(i); 30 | } 31 | #define filter(x) (filterlut[(x) & 0xfffff]) 32 | #endif 33 | 34 | static void quicksort(uint32_t* const start, uint32_t* const stop) 35 | { 36 | uint32_t *it = start + 1, *rit = stop; 37 | 38 | if(it > rit) 39 | return; 40 | 41 | while(it < rit) 42 | if(*it <= *start) 43 | ++it; 44 | else if(*rit > *start) 45 | --rit; 46 | else 47 | *it ^= (*it ^= *rit, *rit ^= *it); 48 | 49 | if(*rit >= *start) 50 | --rit; 51 | if(rit != start) 52 | *rit ^= (*rit ^= *start, *start ^= *rit); 53 | 54 | quicksort(start, rit - 1); 55 | quicksort(rit + 1, stop); 56 | } 57 | /** binsearch 58 | * Binary search for the first occurence of *stop's MSB in sorted [start,stop] 59 | */ 60 | static inline uint32_t* binsearch(uint32_t *start, uint32_t *stop) 61 | { 62 | uint32_t mid, val = *stop & 0xff000000; 63 | while(start != stop) 64 | if(start[mid = (stop - start) >> 1] > val) 65 | stop = &start[mid]; 66 | else 67 | start += mid + 1; 68 | 69 | return start; 70 | } 71 | 72 | /** update_contribution 73 | * helper, calculates the partial linear feedback contributions and puts in MSB 74 | */ 75 | static inline void 76 | update_contribution(uint32_t *item, const uint32_t mask1, const uint32_t mask2) 77 | { 78 | uint32_t p = *item >> 25; 79 | 80 | p = p << 1 | parity(*item & mask1); 81 | p = p << 1 | parity(*item & mask2); 82 | *item = p << 24 | (*item & 0xffffff); 83 | } 84 | 85 | /** extend_table 86 | * using a bit of the keystream extend the table of possible lfsr states 87 | */ 88 | static inline void 89 | extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in) 90 | { 91 | in <<= 24; 92 | for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1) 93 | if(filter(*tbl) ^ filter(*tbl | 1)) { 94 | *tbl |= filter(*tbl) ^ bit; 95 | update_contribution(tbl, m1, m2); 96 | *tbl ^= in; 97 | } else if(filter(*tbl) == bit) { 98 | *++*end = tbl[1]; 99 | tbl[1] = tbl[0] | 1; 100 | update_contribution(tbl, m1, m2); 101 | *tbl++ ^= in; 102 | update_contribution(tbl, m1, m2); 103 | *tbl ^= in; 104 | } else 105 | *tbl-- = *(*end)--; 106 | } 107 | /** extend_table_simple 108 | * using a bit of the keystream extend the table of possible lfsr states 109 | */ 110 | static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit) 111 | { 112 | for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1) 113 | if(filter(*tbl) ^ filter(*tbl | 1)) 114 | *tbl |= filter(*tbl) ^ bit; 115 | else if(filter(*tbl) == bit) { 116 | *++*end = *++tbl; 117 | *tbl = tbl[-1] | 1; 118 | } else 119 | *tbl-- = *(*end)--; 120 | } 121 | /** recover 122 | * recursively narrow down the search space, 4 bits of keystream at a time 123 | */ 124 | static struct Crypto1State* 125 | recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks, 126 | uint32_t *e_head, uint32_t *e_tail, uint32_t eks, int rem, 127 | struct Crypto1State *sl, uint32_t in) 128 | { 129 | uint32_t *o, *e, i; 130 | 131 | if(rem == -1) { 132 | for(e = e_head; e <= e_tail; ++e) { 133 | *e = *e << 1 ^ parity(*e & LF_POLY_EVEN) ^ !!(in & 4); 134 | for(o = o_head; o <= o_tail; ++o, ++sl) { 135 | sl->even = *o; 136 | sl->odd = *e ^ parity(*o & LF_POLY_ODD); 137 | sl[1].odd = sl[1].even = 0; 138 | } 139 | } 140 | return sl; 141 | } 142 | 143 | for(i = 0; i < 4 && rem--; i++) { 144 | oks >>= 1; 145 | eks >>= 1; 146 | in >>= 2; 147 | extend_table(o_head, &o_tail, oks & 1, LF_POLY_EVEN << 1 | 1, 148 | LF_POLY_ODD << 1, 0); 149 | if(o_head > o_tail) 150 | return sl; 151 | 152 | extend_table(e_head, &e_tail, eks & 1, LF_POLY_ODD, 153 | LF_POLY_EVEN << 1 | 1, in & 3); 154 | if(e_head > e_tail) 155 | return sl; 156 | } 157 | 158 | quicksort(o_head, o_tail); 159 | quicksort(e_head, e_tail); 160 | 161 | while(o_tail >= o_head && e_tail >= e_head) 162 | if(((*o_tail ^ *e_tail) >> 24) == 0) { 163 | o_tail = binsearch(o_head, o = o_tail); 164 | e_tail = binsearch(e_head, e = e_tail); 165 | sl = recover(o_tail--, o, oks, 166 | e_tail--, e, eks, rem, sl, in); 167 | } 168 | else if(*o_tail > *e_tail) 169 | o_tail = binsearch(o_head, o_tail) - 1; 170 | else 171 | e_tail = binsearch(e_head, e_tail) - 1; 172 | 173 | return sl; 174 | } 175 | /** lfsr_recovery 176 | * recover the state of the lfsr given 32 bits of the keystream 177 | * additionally you can use the in parameter to specify the value 178 | * that was fed into the lfsr at the time the keystream was generated 179 | */ 180 | struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in) 181 | { 182 | struct Crypto1State *statelist; 183 | uint32_t *odd_head = 0, *odd_tail = 0, oks = 0; 184 | uint32_t *even_head = 0, *even_tail = 0, eks = 0; 185 | int i; 186 | 187 | for(i = 31; i >= 0; i -= 2) 188 | oks = oks << 1 | BEBIT(ks2, i); 189 | for(i = 30; i >= 0; i -= 2) 190 | eks = eks << 1 | BEBIT(ks2, i); 191 | 192 | odd_head = odd_tail = (uint32_t*)malloc(sizeof(uint32_t) << 21); 193 | even_head = even_tail = (uint32_t*)malloc(sizeof(uint32_t) << 21); 194 | statelist = (Crypto1State*)malloc(sizeof(struct Crypto1State) << 18); 195 | if(!odd_tail-- || !even_tail-- || !statelist) { 196 | free(statelist); 197 | statelist = 0; 198 | goto out; 199 | } 200 | 201 | statelist->odd = statelist->even = 0; 202 | 203 | for(i = 1 << 20; i >= 0; --i) { 204 | if(filter(i) == (oks & 1)) 205 | *++odd_tail = i; 206 | if(filter(i) == (eks & 1)) 207 | *++even_tail = i; 208 | } 209 | 210 | for(i = 0; i < 4; i++) { 211 | extend_table_simple(odd_head, &odd_tail, (oks >>= 1) & 1); 212 | extend_table_simple(even_head, &even_tail, (eks >>= 1) & 1); 213 | } 214 | 215 | in = (in >> 16 & 0xff) | (in << 16) | (in & 0xff00); 216 | recover(odd_head, odd_tail, oks, 217 | even_head, even_tail, eks, 11, statelist, in << 1); 218 | 219 | out: 220 | free(odd_head); 221 | free(even_head); 222 | return statelist; 223 | } 224 | 225 | static const uint32_t S1[] = { 0x62141, 0x310A0, 0x18850, 0x0C428, 0x06214, 226 | 0x0310A, 0x85E30, 0xC69AD, 0x634D6, 0xB5CDE, 0xDE8DA, 0x6F46D, 0xB3C83, 227 | 0x59E41, 0xA8995, 0xD027F, 0x6813F, 0x3409F, 0x9E6FA}; 228 | static const uint32_t S2[] = { 0x3A557B00, 0x5D2ABD80, 0x2E955EC0, 0x174AAF60, 229 | 0x0BA557B0, 0x05D2ABD8, 0x0449DE68, 0x048464B0, 0x42423258, 0x278192A8, 230 | 0x156042D0, 0x0AB02168, 0x43F89B30, 0x61FC4D98, 0x765EAD48, 0x7D8FDD20, 231 | 0x7EC7EE90, 0x7F63F748, 0x79117020}; 232 | static const uint32_t T1[] = { 233 | 0x4F37D, 0x279BE, 0x97A6A, 0x4BD35, 0x25E9A, 0x12F4D, 0x097A6, 0x80D66, 234 | 0xC4006, 0x62003, 0xB56B4, 0x5AB5A, 0xA9318, 0xD0F39, 0x6879C, 0xB057B, 235 | 0x582BD, 0x2C15E, 0x160AF, 0x8F6E2, 0xC3DC4, 0xE5857, 0x72C2B, 0x39615, 236 | 0x98DBF, 0xC806A, 0xE0680, 0x70340, 0x381A0, 0x98665, 0x4C332, 0xA272C}; 237 | static const uint32_t T2[] = { 0x3C88B810, 0x5E445C08, 0x2982A580, 0x14C152C0, 238 | 0x4A60A960, 0x253054B0, 0x52982A58, 0x2FEC9EA8, 0x1156C4D0, 0x08AB6268, 239 | 0x42F53AB0, 0x217A9D58, 0x161DC528, 0x0DAE6910, 0x46D73488, 0x25CB11C0, 240 | 0x52E588E0, 0x6972C470, 0x34B96238, 0x5CFC3A98, 0x28DE96C8, 0x12CFC0E0, 241 | 0x4967E070, 0x64B3F038, 0x74F97398, 0x7CDC3248, 0x38CE92A0, 0x1C674950, 242 | 0x0E33A4A8, 0x01B959D0, 0x40DCACE8, 0x26CEDDF0}; 243 | static const uint32_t C1[] = { 0x846B5, 0x4235A, 0x211AD}; 244 | static const uint32_t C2[] = { 0x1A822E0, 0x21A822E0, 0x21A822E0}; 245 | /** Reverse 64 bits of keystream into possible cipher states 246 | * Variation mentioned in the paper. Somewhat optimized version 247 | */ 248 | struct Crypto1State* lfsr_recovery64(uint32_t ks2, uint32_t ks3) 249 | { 250 | struct Crypto1State *statelist, *sl; 251 | uint8_t oks[32], eks[32], hi[32]; 252 | uint32_t low = 0, win = 0; 253 | uint32_t *tail, table[1 << 16]; 254 | int i, j; 255 | 256 | sl = statelist = (Crypto1State*)malloc(sizeof(struct Crypto1State) << 4); 257 | if(!sl) 258 | return 0; 259 | sl->odd = sl->even = 0; 260 | 261 | for(i = 30; i >= 0; i -= 2) { 262 | oks[i >> 1] = BEBIT(ks2, i); 263 | oks[16 + (i >> 1)] = BEBIT(ks3, i); 264 | } 265 | for(i = 31; i >= 0; i -= 2) { 266 | eks[i >> 1] = BEBIT(ks2, i); 267 | eks[16 + (i >> 1)] = BEBIT(ks3, i); 268 | } 269 | 270 | for(i = 0xfffff; i >= 0; --i) { 271 | if (filter(i) != oks[0]) 272 | continue; 273 | 274 | *(tail = table) = i; 275 | for(j = 1; tail >= table && j < 29; ++j) 276 | extend_table_simple(table, &tail, oks[j]); 277 | 278 | if(tail < table) 279 | continue; 280 | 281 | for(j = 0; j < 19; ++j) 282 | low = low << 1 | parity(i & S1[j]); 283 | for(j = 0; j < 32; ++j) 284 | hi[j] = parity(i & T1[j]); 285 | 286 | for(; tail >= table; --tail) { 287 | for(j = 0; j < 3; ++j) { 288 | *tail = *tail << 1; 289 | *tail |= parity((i & C1[j]) ^ (*tail & C2[j])); 290 | if(filter(*tail) != oks[29 + j]) 291 | goto continue2; 292 | } 293 | 294 | for(j = 0; j < 19; ++j) 295 | win = win << 1 | parity(*tail & S2[j]); 296 | 297 | win ^= low; 298 | for(j = 0; j < 32; ++j) { 299 | win = win << 1 ^ hi[j] ^ parity(*tail & T2[j]); 300 | if(filter(win) != eks[j]) 301 | goto continue2; 302 | } 303 | 304 | *tail = *tail << 1 | parity(LF_POLY_EVEN & *tail); 305 | sl->odd = *tail ^ parity(LF_POLY_ODD & win); 306 | sl->even = win; 307 | ++sl; 308 | sl->odd = sl->even = 0; 309 | continue2:; 310 | } 311 | } 312 | return statelist; 313 | } 314 | 315 | /** lfsr_rollback_bit 316 | * Rollback the shift register in order to get previous states 317 | */ 318 | uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb) 319 | { 320 | int out; 321 | uint8_t ret; 322 | 323 | s->odd &= 0xffffff; 324 | s->odd ^= (s->odd ^= s->even, s->even ^= s->odd); 325 | 326 | out = s->even & 1; 327 | out ^= LF_POLY_EVEN & (s->even >>= 1); 328 | out ^= LF_POLY_ODD & s->odd; 329 | out ^= !!in; 330 | out ^= (ret = filter(s->odd)) & !!fb; 331 | 332 | s->even |= parity(out) << 23; 333 | return ret; 334 | } 335 | /** lfsr_rollback_byte 336 | * Rollback the shift register in order to get previous states 337 | */ 338 | uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb) 339 | { 340 | int i, ret = 0; 341 | for (i = 7; i >= 0; --i) 342 | ret |= lfsr_rollback_bit(s, BIT(in, i), fb) << i; 343 | return ret; 344 | } 345 | /** lfsr_rollback_word 346 | * Rollback the shift register in order to get previous states 347 | */ 348 | uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) 349 | { 350 | int i; 351 | uint32_t ret = 0; 352 | for (i = 31; i >= 0; --i) 353 | ret |= lfsr_rollback_bit(s, BEBIT(in, i), fb) << (i ^ 24); 354 | return ret; 355 | } 356 | 357 | /** nonce_distance 358 | * x,y valid tag nonces, then prng_successor(x, nonce_distance(x, y)) = y 359 | */ 360 | static uint16_t *dist = 0; 361 | int nonce_distance(uint32_t from, uint32_t to) 362 | { 363 | uint16_t x, i; 364 | if(!dist) { 365 | dist = (uint16_t*)malloc(2 << 16); 366 | if(!dist) 367 | return -1; 368 | for (x = i = 1; i; ++i) { 369 | dist[(x & 0xff) << 8 | x >> 8] = i; 370 | x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15; 371 | } 372 | } 373 | return (65535 + dist[to >> 16] - dist[from >> 16]) % 65535; 374 | } 375 | 376 | 377 | static uint32_t fastfwd[2][8] = { 378 | { 0, 0x4BC53, 0xECB1, 0x450E2, 0x25E29, 0x6E27A, 0x2B298, 0x60ECB}, 379 | { 0, 0x1D962, 0x4BC53, 0x56531, 0xECB1, 0x135D3, 0x450E2, 0x58980}}; 380 | /** lfsr_prefix_ks 381 | * 382 | * Is an exported helper function from the common prefix attack 383 | * Described in the "dark side" paper. It returns an -1 terminated array 384 | * of possible partial(21 bit) secret state. 385 | * The required keystream(ks) needs to contain the keystream that was used to 386 | * encrypt the NACK which is observed when varying only the 3 last bits of Nr 387 | * only correct iff [NR_3] ^ NR_3 does not depend on Nr_3 388 | */ 389 | uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) 390 | { 391 | uint32_t c, entry, *candidates = (uint32_t*)malloc(4 << 10); 392 | int i, size = 0, good; 393 | 394 | if(!candidates) 395 | return 0; 396 | 397 | for(i = 0; i < 1 << 21; ++i) { 398 | for(c = 0, good = 1; good && c < 8; ++c) { 399 | entry = i ^ fastfwd[isodd][c]; 400 | good &= (BIT(ks[c], isodd) == filter(entry >> 1)); 401 | good &= (BIT(ks[c], isodd + 2) == filter(entry)); 402 | } 403 | if(good) 404 | candidates[size++] = i; 405 | } 406 | 407 | candidates[size] = -1; 408 | 409 | return candidates; 410 | } 411 | 412 | /** check_pfx_parity 413 | * helper function which eliminates possible secret states using parity bits 414 | */ 415 | static struct Crypto1State* 416 | check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8], 417 | uint32_t odd, uint32_t even, struct Crypto1State* sl) 418 | { 419 | uint32_t ks1, nr, ks2, rr, ks3, c, good = 1; 420 | 421 | for(c = 0; good && c < 8; ++c) { 422 | sl->odd = odd ^ fastfwd[1][c]; 423 | sl->even = even ^ fastfwd[0][c]; 424 | 425 | lfsr_rollback_bit(sl, 0, 0); 426 | lfsr_rollback_bit(sl, 0, 0); 427 | 428 | ks3 = lfsr_rollback_bit(sl, 0, 0); 429 | ks2 = lfsr_rollback_word(sl, 0, 0); 430 | ks1 = lfsr_rollback_word(sl, prefix | c << 5, 1); 431 | 432 | nr = ks1 ^ (prefix | c << 5); 433 | rr = ks2 ^ rresp; 434 | 435 | good &= parity(nr & 0x000000ff) ^ parities[c][3] ^ BIT(ks2, 24); 436 | good &= parity(rr & 0xff000000) ^ parities[c][4] ^ BIT(ks2, 16); 437 | good &= parity(rr & 0x00ff0000) ^ parities[c][5] ^ BIT(ks2, 8); 438 | good &= parity(rr & 0x0000ff00) ^ parities[c][6] ^ BIT(ks2, 0); 439 | good &= parity(rr & 0x000000ff) ^ parities[c][7] ^ ks3; 440 | } 441 | 442 | return sl + good; 443 | } 444 | 445 | 446 | /** lfsr_common_prefix 447 | * Implentation of the common prefix attack. 448 | */ 449 | struct Crypto1State* 450 | lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]) 451 | { 452 | struct Crypto1State *statelist, *s; 453 | uint32_t *odd, *even, *o, *e, top; 454 | 455 | odd = lfsr_prefix_ks(ks, 1); 456 | even = lfsr_prefix_ks(ks, 0); 457 | 458 | s = statelist = (Crypto1State*)malloc((sizeof *statelist) << 20); 459 | if(!s || !odd || !even) { 460 | free(statelist); 461 | statelist = 0; 462 | goto out; 463 | } 464 | 465 | for(o = odd; *o + 1; ++o) 466 | for(e = even; *e + 1; ++e) 467 | for(top = 0; top < 64; ++top) { 468 | *o += 1 << 21; 469 | *e += (!(top & 7) + 1) << 21; 470 | s = check_pfx_parity(pfx, rr, par, *o, *e, s); 471 | } 472 | 473 | s->odd = s->even = 0; 474 | out: 475 | free(odd); 476 | free(even); 477 | return statelist; 478 | } 479 | -------------------------------------------------------------------------------- /src/mfocGUI/crapto1.h: -------------------------------------------------------------------------------- 1 | /* crapto1.h 2 | 3 | This program is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU General Public License 5 | as published by the Free Software Foundation; either version 2 6 | of the License, or (at your option) any later version. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 16 | MA 02110-1301, US$ 17 | 18 | Copyright (C) 2008-2008 bla 19 | */ 20 | #ifndef CRAPTO1_INCLUDED 21 | #define CRAPTO1_INCLUDED 22 | #include 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | struct Crypto1State {uint32_t odd, even;}; 28 | struct Crypto1State* crypto1_create(uint64_t); 29 | void crypto1_destroy(struct Crypto1State*); 30 | void crypto1_get_lfsr(struct Crypto1State*, uint64_t*); 31 | uint8_t crypto1_bit(struct Crypto1State*, uint8_t, int); 32 | uint8_t crypto1_byte(struct Crypto1State*, uint8_t, int); 33 | uint32_t crypto1_word(struct Crypto1State*, uint32_t, int); 34 | uint32_t prng_successor(uint32_t x, uint32_t n); 35 | 36 | struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in); 37 | struct Crypto1State* lfsr_recovery64(uint32_t ks2, uint32_t ks3); 38 | uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd); 39 | struct Crypto1State* 40 | lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]); 41 | 42 | uint8_t lfsr_rollback_bit(struct Crypto1State* s, uint32_t in, int fb); 43 | uint8_t lfsr_rollback_byte(struct Crypto1State* s, uint32_t in, int fb); 44 | uint32_t lfsr_rollback_word(struct Crypto1State* s, uint32_t in, int fb); 45 | int nonce_distance(uint32_t from, uint32_t to); 46 | #define FOREACH_VALID_NONCE(N, FILTER, FSIZE)\ 47 | uint32_t __n = 0,__M = 0, N = 0;\ 48 | int __i;\ 49 | for(; __n < 1 << 16; N = prng_successor(__M = ++__n, 16))\ 50 | for(__i = FSIZE - 1; __i >= 0; __i--)\ 51 | if(BIT(FILTER, __i) ^ parity(__M & 0xFF01))\ 52 | break;\ 53 | else if(__i)\ 54 | __M = prng_successor(__M, (__i == 7) ? 48 : 8);\ 55 | else 56 | 57 | #define LF_POLY_ODD (0x29CE5C) 58 | #define LF_POLY_EVEN (0x870804) 59 | #define BIT(x, n) ((x) >> (n) & 1) 60 | #define BEBIT(x, n) BIT(x, (n) ^ 24) 61 | static inline int parity(uint32_t x) 62 | { 63 | #if !defined __i386__ || !defined __GNUC__ 64 | x ^= x >> 16; 65 | x ^= x >> 8; 66 | x ^= x >> 4; 67 | return BIT(0x6996, x & 0xf); 68 | #else 69 | asm( "movl %1, %%eax\n" 70 | "mov %%ax, %%cx\n" 71 | "shrl $0x10, %%eax\n" 72 | "xor %%ax, %%cx\n" 73 | "xor %%ch, %%cl\n" 74 | "setpo %%al\n" 75 | "movzx %%al, %0\n": "=r"(x) : "r"(x): "eax","ecx"); 76 | return x; 77 | #endif 78 | } 79 | static inline int filter(uint32_t const x) 80 | { 81 | uint32_t f; 82 | 83 | f = 0xf22c0 >> (x & 0xf) & 16; 84 | f |= 0x6c9c0 >> (x >> 4 & 0xf) & 8; 85 | f |= 0x3c8b0 >> (x >> 8 & 0xf) & 4; 86 | f |= 0x1e458 >> (x >> 12 & 0xf) & 2; 87 | f |= 0x0d938 >> (x >> 16 & 0xf) & 1; 88 | return BIT(0xEC57E80A, f); 89 | } 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | #endif 94 | -------------------------------------------------------------------------------- /src/mfocGUI/crypto1.cpp: -------------------------------------------------------------------------------- 1 | /* crypto1.c 2 | 3 | This program is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU General Public License 5 | as published by the Free Software Foundation; either version 2 6 | of the License, or (at your option) any later version. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with this program; if not, write to the Free Software 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 16 | MA 02110-1301, US 17 | 18 | Copyright (C) 2008-2008 bla 19 | */ 20 | #include "crapto1.h" 21 | #include 22 | 23 | #define SWAPENDIAN(x)\ 24 | (x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16) 25 | 26 | struct Crypto1State * crypto1_create(uint64_t key) 27 | { 28 | struct Crypto1State *s = (Crypto1State*)malloc(sizeof(*s)); 29 | int i; 30 | 31 | for(i = 47;s && i > 0; i -= 2) { 32 | s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7); 33 | s->even = s->even << 1 | BIT(key, i ^ 7); 34 | } 35 | return s; 36 | } 37 | void crypto1_destroy(struct Crypto1State *state) 38 | { 39 | free(state); 40 | } 41 | void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) 42 | { 43 | int i; 44 | for(*lfsr = 0, i = 23; i >= 0; --i) { 45 | *lfsr = *lfsr << 1 | BIT(state->odd, i ^ 3); 46 | *lfsr = *lfsr << 1 | BIT(state->even, i ^ 3); 47 | } 48 | } 49 | uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted) 50 | { 51 | uint32_t feedin; 52 | uint8_t ret = filter(s->odd); 53 | 54 | feedin = ret & !!is_encrypted; 55 | feedin ^= !!in; 56 | feedin ^= LF_POLY_ODD & s->odd; 57 | feedin ^= LF_POLY_EVEN & s->even; 58 | s->even = s->even << 1 | parity(feedin); 59 | 60 | s->odd ^= (s->odd ^= s->even, s->even ^= s->odd); 61 | 62 | return ret; 63 | } 64 | uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted) 65 | { 66 | uint8_t i, ret = 0; 67 | 68 | for (i = 0; i < 8; ++i) 69 | ret |= crypto1_bit(s, BIT(in, i), is_encrypted) << i; 70 | 71 | return ret; 72 | } 73 | uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted) 74 | { 75 | uint32_t i, ret = 0; 76 | 77 | for (i = 0; i < 32; ++i) 78 | ret |= crypto1_bit(s, BEBIT(in, i), is_encrypted) << (i ^ 24); 79 | 80 | return ret; 81 | } 82 | 83 | /* prng_successor 84 | * helper used to obscure the keystream during authentication 85 | */ 86 | uint32_t prng_successor(uint32_t x, uint32_t n) 87 | { 88 | SWAPENDIAN(x); 89 | while(n--) 90 | x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31; 91 | 92 | return SWAPENDIAN(x); 93 | } 94 | -------------------------------------------------------------------------------- /src/mfocGUI/libnfc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/libnfc.dll -------------------------------------------------------------------------------- /src/mfocGUI/libusb0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/libusb0.dll -------------------------------------------------------------------------------- /src/mfocGUI/mfoc.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "mfoc.h" 3 | #include 4 | #include 5 | #include 6 | #include "crapto1.h" 7 | #include "mifare.h" 8 | #include "nfc-utils.h" 9 | 10 | bool stopreadingcard = false; 11 | 12 | long long unsigned int bytes_to_num(byte_t* src, uint32_t len); 13 | int compar_int(const void * a, const void * b); 14 | int compar_special_int(const void * a, const void * b); 15 | uint32_t median(denonce d); 16 | void mf_anticollision(nfc_device_desc_t *device, mftag *t, mfreader *r, void (*UpdateStatusMessage)(char *status)); 17 | void mf_configure(nfc_device_t* pdi); 18 | int mf_enhanced_auth(int e_sector, int a_sector, mftag t, mfreader r, denonce *d, pKeys *pk, char mode, bool dumpKeysA, void (*UpdateStatusMessage)(char *status)); 19 | void mf_init(nfc_device_desc_t *device, mftag *t, mfreader *r, void (*UpdateStatusMessage)(char *status)); 20 | void mf_select_tag(nfc_device_t* pdi, nfc_target_t* ti, void (*UpdateStatusMessage)(char *status)); 21 | int trailer_block(uint32_t block); 22 | void reset(nfc_device_desc_t *device, mftag *t, mfreader *r, void (*UpdateStatusMessage)(char *status)); 23 | int find_exploit_sector(mftag t, void (*UpdateStatusMessage)(char *status)); 24 | void num_to_bytes(uint64_t n, uint32_t len, byte_t* dest); 25 | countKeys * uniqsort(uint64_t * possibleKeys, uint32_t size, void (*UpdateStatusMessage)(char *status)); 26 | void readSector(nfc_device_desc_t *device,nfc_device_t * pnd, mifare_sector* sector,nfc_target_t *t, bool onlyA, mftag *a, mfreader *r, void (*UpdateStatusMessage)(char *status)); 27 | uint8_t sectorToFirstBlock(uint8_t sector); 28 | unsigned int numberOfBlocks(uint8_t sector); 29 | bool read_mifare_ul_card (nfc_device_t *pnd, mifareul_tag *mtDump, void (*UpdateStatusMessage)(char *status)); 30 | 31 | 32 | //! Read mifare ultralight card 33 | /** @param pnd The NFC Device information 34 | * @param mtDump Mifare ultralight tag information 35 | * @return true if the read succeeded 36 | */ 37 | bool read_mifare_ul_card (nfc_device_t *pnd, mifareul_tag *mtDump, void (*UpdateStatusMessage)(char *status)) { 38 | uint32_t uiBlocks = 0xF; 39 | uint32_t page; 40 | bool bFailure = false; 41 | uint32_t uiReadedPages = 0; 42 | mifare_param mp; 43 | char StatusBuffer[600]; 44 | 45 | sprintf(StatusBuffer, "Reading %d pages |", uiBlocks + 1); 46 | UpdateStatusMessage(StatusBuffer); 47 | 48 | for (page = 0; page <= uiBlocks; page += 4) { 49 | // Try to read out the data block 50 | if (nfc_initiator_mifare_cmd (pnd, MC_READ, page, &mp)) { 51 | memcpy (mtDump->amb[page / 4].mbd.abtData, mp.mpd.abtData, 16); 52 | } else { 53 | bFailure = true; 54 | break; 55 | } 56 | sprintf(StatusBuffer, "%s%s", StatusBuffer, bFailure ? "xxxx":"...."); 57 | uiReadedPages += bFailure ? 0 : 4; 58 | } 59 | sprintf(StatusBuffer, "Done, %d of %d pages readed.\n", uiReadedPages, uiBlocks + 1); 60 | UpdateStatusMessage(StatusBuffer); 61 | 62 | return (!bFailure); 63 | } 64 | 65 | //! Get the number of blocks in a sector 66 | /** @param sector The sector where you want the number of blocks from 67 | * @return The number of blocks 68 | */ 69 | unsigned int numberOfBlocks(uint8_t sector){ 70 | return sector<32 ? 4:16; 71 | } 72 | 73 | //! Convert a sector to the first block of a sector 74 | /** @param sector The sector to convert 75 | * @return the block 76 | */ 77 | uint8_t sectorToFirstBlock(uint8_t sector) { 78 | return (sector <= 32) ? (sector * 4) : (32 * 4 + (16*(sector-32))); 79 | } 80 | 81 | //! Read a sector from a card 82 | /** @param pnd NFC device information 83 | * @param sector Sector to verify 84 | * @param t The target info 85 | * @param onlyA Only use key A to read 86 | * @param a The tag anticollision info 87 | * @param r The reader handle 88 | */ 89 | void readSector(nfc_device_desc_t *device, nfc_device_t * pnd, mifare_sector* sector, nfc_target_t *t, bool onlyA, mftag *a, mfreader *r, void (*UpdateStatusMessage)(char *status)) { 90 | static mifare_param mp; 91 | const nfc_modulation_t nm = {NMT_ISO14443A,NBR_106}; 92 | char Buffer[150]; 93 | uint8_t block = sectorToFirstBlock(sector->sector)+numberOfBlocks(sector->sector) - 1; 94 | memcpy(mp.mpa.abtKey,sector->KeyA, sizeof(sector->KeyA)); 95 | memcpy(mp.mpa.abtUid, t->nti.nai.abtUid,4); 96 | if (nfc_initiator_mifare_cmd(pnd, MC_AUTH_A, block, &mp)) { 97 | int i; 98 | for (i=numberOfBlocks(sector->sector)-1; i>=0; i--) { 99 | if (nfc_initiator_mifare_cmd(pnd, MC_READ, block, &mp)) { 100 | sprintf(Buffer, "Block %02d, type %c, key %012llx :", block, 'A', bytes_to_num(sector->KeyA, 6)); 101 | UpdateStatusMessage(Buffer); 102 | memcpy(sector->Data[i],mp.mpd.abtData,16); 103 | } else { 104 | mf_configure(pnd); 105 | nfc_initiator_select_passive_target(pnd, nm, NULL, 0, t); 106 | sprintf(Buffer, "Error Reading: Block %02d, type %c, key %012llx", block, 'A', bytes_to_num(sector->KeyA, 6)); 107 | UpdateStatusMessage(Buffer); 108 | break; 109 | } 110 | block--; 111 | } 112 | } else { 113 | mf_configure(pnd); 114 | mf_anticollision(device, a, r, UpdateStatusMessage); 115 | if (stopreadingcard) return; 116 | memcpy(mp.mpa.abtKey,sector->KeyB, sizeof(sector->KeyB)); 117 | memcpy(mp.mpa.abtUid, t->nti.nai.abtUid,4); 118 | if (nfc_initiator_mifare_cmd(pnd, MC_AUTH_B, block, &mp)) { 119 | int i; 120 | for (i=numberOfBlocks(sector->sector)-1;i>=0;i--) { 121 | if (nfc_initiator_mifare_cmd(pnd, MC_READ, block, &mp)) { 122 | sprintf(Buffer, "Block %02d, type %c, key %012llx :", block, 'B', bytes_to_num(sector->KeyB, 6)); 123 | UpdateStatusMessage(Buffer); 124 | memcpy(sector->Data[i],mp.mpd.abtData,16); 125 | } else { 126 | mf_configure(pnd); 127 | nfc_initiator_select_passive_target(pnd, nm, NULL, 0, t); 128 | sprintf(Buffer, "Error Reading: Block %02d, type %c, key %012llx", block, 'B', bytes_to_num(sector->KeyB, 6)); 129 | UpdateStatusMessage(Buffer); 130 | break; 131 | } 132 | block--; 133 | } 134 | } else { 135 | sprintf(Buffer, "Error Reading: Block %02d, type %c, key %012llx :", block, 'B', bytes_to_num(sector->KeyB, 6)); 136 | UpdateStatusMessage(Buffer); 137 | mf_configure(pnd); 138 | nfc_initiator_select_passive_target(pnd, nm, NULL, 0, t); 139 | } 140 | } 141 | } 142 | 143 | //! Compare countKeys structure 144 | /** @param a First countkey 145 | * @param b Second countkey 146 | * @param b->count - a->count; 147 | */ 148 | int compar_special_int(const void * a, const void * b) { 149 | return (((countKeys *)b)->count - ((countKeys *)a)->count); 150 | } 151 | 152 | //! Order a list and put the number of occurences in the list 153 | /** @param possibleKeys the unsorted list of keys 154 | * @param size The number of keys 155 | * @return The sorted list 156 | */ 157 | countKeys * uniqsort(uint64_t * possibleKeys, uint32_t size, void (*UpdateStatusMessage)(char *status)) { 158 | int i, j = 0; 159 | int count = 0; 160 | countKeys *our_counts; 161 | 162 | qsort(possibleKeys, size, sizeof (uint64_t), compar_int); 163 | 164 | our_counts = (countKeys *)calloc(size, sizeof(countKeys)); 165 | if (NULL == our_counts) { 166 | UpdateStatusMessage("Memory allocation error for our_counts"); 167 | stopreadingcard = TRUE; 168 | return NULL; 169 | } 170 | 171 | for (i = 0; i < size; i++) { 172 | if (possibleKeys[i+1] == possibleKeys[i]) { 173 | count++; 174 | } else { 175 | our_counts[j].key = possibleKeys[i]; 176 | our_counts[j].count = count; 177 | j++; 178 | count=0; 179 | } 180 | } 181 | 182 | qsort(our_counts, j, sizeof(countKeys), compar_special_int); 183 | return (our_counts); 184 | } 185 | 186 | //! Compare two integers for sorting 187 | /** @param a First int 188 | * @param b Second int 189 | * @param b - a; 190 | */ 191 | int compar_int(const void * a, const void * b) { 192 | return (*(uint64_t*)b - *(uint64_t*)a); 193 | } 194 | 195 | //! Return the median value from the nonce distances array 196 | /** @param d Revealed information about the nonce 197 | * @return The median of the received nonces 198 | */ 199 | uint32_t median(denonce d) { 200 | int middle = (int) d.num_distances / 2; 201 | qsort(d.distances, d.num_distances, sizeof(u_int32_t), compar_int); 202 | 203 | if (1 == (d.num_distances % 2)) { 204 | // Odd number of elements 205 | return d.distances[middle]; 206 | } else { 207 | // Even number of elements, return the smaller value 208 | return (uint32_t) (d.distances[middle-1]); 209 | } 210 | } 211 | 212 | //! MiFare cracking, nested authentication, recover key, distance keys 213 | /** @param e_sector Exploit sector (where the key is known from) 214 | * @param a_sector The sector to crack 215 | * @param t The mifare tag 216 | * @param r The mifare reader 217 | * @param d Revealed information about the nonce 218 | * @param pk Possible Keys 219 | * @param mode 'r' for recovery, 'd' for distance 220 | * @param dumpKeysA Crack key A 221 | * @return 0 222 | */ 223 | int mf_enhanced_auth(int e_sector, int a_sector, mftag t, mfreader r, denonce *d, pKeys *pk, char mode, bool dumpKeysA, void (*UpdateStatusMessage)(char *status)) { 224 | struct Crypto1State* pcs; 225 | struct Crypto1State* revstate; 226 | struct Crypto1State* revstate_start; 227 | 228 | uint64_t lfsr; 229 | 230 | // Possible key counter, just continue with a previous "session" 231 | uint32_t kcount = pk->size; 232 | 233 | byte_t Nr[4] = { 0x00,0x00,0x00,0x00 }; // Reader nonce 234 | byte_t Auth[4] = { 0x00, t.sectors[e_sector].trailer, 0x00, 0x00 }; 235 | byte_t AuthEnc[4] = { 0x00, t.sectors[e_sector].trailer, 0x00, 0x00 }; 236 | byte_t AuthEncPar[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; 237 | 238 | byte_t ArEnc[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; 239 | byte_t ArEncPar[8] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; 240 | 241 | byte_t Rx[MAX_FRAME_LEN]; // Tag response 242 | byte_t RxPar[MAX_FRAME_LEN]; // Tag response 243 | size_t RxLen; 244 | 245 | u_int32_t Nt, NtLast, NtProbe, NtEnc, Ks1; 246 | 247 | int i, m; 248 | 249 | // Prepare AUTH command 250 | Auth[0] = (t.sectors[e_sector].foundKeyA) ? 0x60 : 0x61; 251 | iso14443a_crc_append(Auth,2); 252 | 253 | // We need full control over the CRC 254 | if (!nfc_configure(r.pdi, NDO_HANDLE_CRC, false)) { 255 | nfc_perror (r.pdi, "nfc_configure"); 256 | stopreadingcard = TRUE; 257 | return 0; 258 | } 259 | 260 | // Request plain tag-nonce 261 | 262 | if (!nfc_configure (r.pdi, NDO_EASY_FRAMING, false)) { 263 | nfc_perror (r.pdi, "nfc_configure"); 264 | stopreadingcard = TRUE; 265 | return 0; 266 | } 267 | 268 | if (!nfc_initiator_transceive_bytes(r.pdi, Auth, 4, Rx, &RxLen,0)) { 269 | UpdateStatusMessage("Error while requesting plain tag-nonce."); 270 | stopreadingcard = TRUE; 271 | return 0; 272 | } 273 | 274 | if (!nfc_configure (r.pdi, NDO_EASY_FRAMING, true)) { 275 | nfc_perror (r.pdi, "nfc_configure"); 276 | stopreadingcard = TRUE; 277 | return 0; 278 | } 279 | 280 | // Save the tag nonce (Nt) 281 | Nt = bytes_to_num(Rx, 4); 282 | 283 | // Init the cipher with key {0..47} bits 284 | if (t.sectors[e_sector].foundKeyA) 285 | pcs = crypto1_create(bytes_to_num(t.sectors[e_sector].KeyA, 6)); 286 | else 287 | pcs = crypto1_create(bytes_to_num(t.sectors[e_sector].KeyB, 6)); 288 | 289 | // Load (plain) uid^nt into the cipher {48..79} bits 290 | crypto1_word(pcs, bytes_to_num(Rx, 4) ^ t.uid, 0); 291 | 292 | // Generate (encrypted) nr+parity by loading it into the cipher 293 | for (i = 0; i < 4; i++) { 294 | // Load in, and encrypt the reader nonce (Nr) 295 | ArEnc[i] = crypto1_byte(pcs, Nr[i], 0) ^ Nr[i]; 296 | ArEncPar[i] = filter(pcs->odd) ^ oddparity(Nr[i]); 297 | } 298 | // Skip 32 bits in the pseudo random generator 299 | Nt = prng_successor(Nt, 32); 300 | // Generate reader-answer from tag-nonce 301 | for (i = 4; i < 8; i++) { 302 | // Get the next random byte 303 | Nt = prng_successor(Nt, 8); 304 | // Encrypt the reader-answer (Nt' = suc2(Nt)) 305 | ArEnc[i] = crypto1_byte(pcs, 0x00, 0) ^ (Nt&0xff); 306 | ArEncPar[i] = filter(pcs->odd) ^ oddparity(Nt); 307 | } 308 | 309 | // Finally we want to send arbitrary parity bits 310 | nfc_configure(r.pdi, NDO_HANDLE_PARITY, false); 311 | 312 | // Transmit reader-answer 313 | if ((!nfc_initiator_transceive_bits(r.pdi, ArEnc, 64, ArEncPar, Rx, &RxLen, RxPar)) || (32 != RxLen)) { 314 | UpdateStatusMessage("Reader-answer transfer error, exiting.."); 315 | stopreadingcard = TRUE; 316 | return 0; 317 | } 318 | 319 | // Decrypt the tag answer and verify that suc3(Nt) is At 320 | Nt = prng_successor(Nt, 32); 321 | if (!((crypto1_word(pcs, 0x00, 0) ^ bytes_to_num(Rx, 4)) == (Nt&0xFFFFFFFF))) { 322 | UpdateStatusMessage("[At] is not Suc3(Nt), something is wrong, exiting.."); 323 | stopreadingcard = TRUE; 324 | return 0; 325 | } 326 | 327 | // If we are in "Get Recovery" mode 328 | if ('r' == mode) { 329 | // Again, prepare the Auth command with MC_AUTH_A, recover the block and CRC 330 | Auth[0] = dumpKeysA ? 0x60 : 0x61; 331 | Auth[1] = a_sector; 332 | iso14443a_crc_append(Auth,2); 333 | 334 | // Encryption of the Auth command, sending the Auth command 335 | for (i = 0; i < 4; i++) { 336 | AuthEnc[i] = crypto1_byte(pcs,0x00,0) ^ Auth[i]; 337 | // Encrypt the parity bits with the 4 plaintext bytes 338 | AuthEncPar[i] = filter(pcs->odd) ^ oddparity(Auth[i]); 339 | } 340 | if (!nfc_initiator_transceive_bits(r.pdi, AuthEnc, 32, AuthEncPar,Rx, &RxLen, RxPar)) { 341 | UpdateStatusMessage("Error requesting encrypted tag-nonce."); 342 | stopreadingcard = TRUE; 343 | return 0; 344 | } 345 | 346 | // Save the encrypted nonce 347 | NtEnc = bytes_to_num(Rx, 4); 348 | 349 | // Parity validity check 350 | for (i = 0; i < 3; ++i) 351 | d->parity[i] = (oddparity(Rx[i]) != RxPar[i]); 352 | 353 | 354 | // Iterate over Nt-x, Nt+x 355 | // fprintf(stdout, "Iterate from %d to %d\n", d->median-TOLERANCE, d->median+TOLERANCE); 356 | NtProbe = prng_successor(Nt, d->median-d->tolerance); 357 | for (m = d->median-d->tolerance; m <= d->median+d->tolerance; m +=2) { 358 | 359 | // Try to recover the keystream1 360 | Ks1 = NtEnc ^ NtProbe; 361 | 362 | // Skip this nonce after invalid 3b parity check 363 | revstate_start = NULL; 364 | //int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, byte_t * parity) { 365 | if ((odd_parity((NtProbe >> 24) & 0xFF) == ((d->parity[0]) ^ odd_parity((NtEnc >> 24) & 0xFF) ^ BIT(Ks1,16))) & \ 366 | (odd_parity((NtProbe >> 16) & 0xFF) == ((d->parity[1]) ^ odd_parity((NtEnc >> 16) & 0xFF) ^ BIT(Ks1,8))) & \ 367 | (odd_parity((NtProbe >> 8) & 0xFF) == ((d->parity[2]) ^ odd_parity((NtEnc >> 8) & 0xFF) ^ BIT(Ks1,0)))) { 368 | //if (valid_nonce(NtProbe, NtEnc, Ks1, d->parity)) { 369 | // And finally recover the first 32 bits of the key 370 | revstate = lfsr_recovery32(Ks1, NtProbe ^ t.uid); 371 | if (NULL == revstate_start) 372 | revstate_start = revstate; 373 | 374 | while ((revstate->odd != 0x0) || (revstate->even != 0x0)) { 375 | lfsr_rollback_word(revstate, NtProbe ^ t.uid, 0); 376 | crypto1_get_lfsr(revstate, &lfsr); 377 | // Allocate a new space for keys 378 | if (((kcount % MEM_CHUNK) == 0) || (kcount >= pk->size)) { 379 | pk->size += MEM_CHUNK; 380 | // fprintf(stdout, "New chunk by %d, sizeof %lu\n", kcount, pk->size * sizeof(uint64_t)); 381 | pk->possibleKeys = (uint64_t *) realloc((void *)pk->possibleKeys, pk->size * sizeof(uint64_t)); 382 | if (NULL == pk->possibleKeys) { 383 | UpdateStatusMessage("Memory allocation error for pk->possibleKeys."); 384 | stopreadingcard = TRUE; 385 | return 0; 386 | } 387 | } 388 | pk->possibleKeys[kcount] = lfsr; 389 | kcount++; 390 | revstate++; 391 | } 392 | free(revstate_start); 393 | } 394 | NtProbe = prng_successor(NtProbe, 2); 395 | } 396 | // Truncate 397 | if (0 != kcount) { 398 | pk->size = --kcount; 399 | if (NULL == (pk->possibleKeys = (uint64_t *) realloc((void *)pk->possibleKeys, pk->size * sizeof(uint64_t)))) { 400 | UpdateStatusMessage("Memory allocation error for pk->possibleKeys."); 401 | stopreadingcard = TRUE; 402 | return 0; 403 | } 404 | } 405 | } // If we are in recovery mode 406 | 407 | // If we are in "Get Distances" mode 408 | else if ('d' == mode) { 409 | for (m = 0; m < d->num_distances; m++) { 410 | // Encrypt Auth command with the current keystream 411 | for (i = 0; i < 4; i++) { 412 | AuthEnc[i] = crypto1_byte(pcs,0x00,0) ^ Auth[i]; 413 | // Encrypt the parity bits with the 4 plaintext bytes 414 | AuthEncPar[i] = filter(pcs->odd) ^ oddparity(Auth[i]); 415 | } 416 | 417 | // Sending the encrypted Auth command 418 | if (!nfc_initiator_transceive_bits(r.pdi, AuthEnc, 32, AuthEncPar,Rx, &RxLen, RxPar)) { 419 | UpdateStatusMessage("Error requesting encrypted tag-nonce."); 420 | stopreadingcard = TRUE; 421 | return 0; 422 | } 423 | 424 | // Decrypt the encrypted auth 425 | if (t.sectors[e_sector].foundKeyA) { 426 | pcs = crypto1_create(bytes_to_num(t.sectors[e_sector].KeyA, 6)); 427 | } else { 428 | pcs = crypto1_create(bytes_to_num(t.sectors[e_sector].KeyB, 6)); 429 | } 430 | NtLast = bytes_to_num(Rx, 4) ^ crypto1_word(pcs, bytes_to_num(Rx, 4) ^ t.uid, 1); 431 | 432 | // Save the determined nonces distance 433 | d->distances[m] = nonce_distance(Nt, NtLast); 434 | 435 | // Again, prepare and send {At} 436 | for (i = 0; i < 4; i++) { 437 | ArEnc[i] = crypto1_byte(pcs, Nr[i], 0) ^ Nr[i]; 438 | ArEncPar[i] = filter(pcs->odd) ^ oddparity(Nr[i]); 439 | } 440 | Nt = prng_successor(NtLast, 32); 441 | for (i = 4; i < 8; i++) { 442 | Nt = prng_successor(Nt, 8); 443 | ArEnc[i] = crypto1_byte(pcs, 0x00, 0) ^ (Nt&0xFF); 444 | ArEncPar[i] = filter(pcs->odd) ^ oddparity(Nt); 445 | } 446 | nfc_configure(r.pdi,NDO_HANDLE_PARITY,false); 447 | if ((!nfc_initiator_transceive_bits(r.pdi, ArEnc, 64, ArEncPar, Rx, &RxLen, RxPar)) || (RxLen != 32)) { 448 | UpdateStatusMessage("Reader-answer transfer error, exiting.."); 449 | stopreadingcard = TRUE; 450 | return 0; 451 | } 452 | Nt = prng_successor(Nt, 32); 453 | if (!((crypto1_word(pcs, 0x00, 0) ^ bytes_to_num(Rx, 4)) == (Nt&0xFFFFFFFF))) { 454 | UpdateStatusMessage("[At] is not Suc3(Nt), something is wrong, exiting.."); 455 | stopreadingcard = TRUE; 456 | return 0; 457 | } 458 | } // Next auth probe 459 | 460 | // Find median from all distances 461 | d->median = median(*d); 462 | //fprintf(stdout, "Median: %05d\n", d->median); 463 | } // The end of Get Distances mode 464 | 465 | crypto1_destroy(pcs); 466 | return 0; 467 | } 468 | 469 | //! Convert a number to byte[] 470 | /** @param n Number to convert 471 | * @param len Length of the number 472 | * @param dest Where to store the number as byteform 473 | */ 474 | void num_to_bytes(uint64_t n, uint32_t len, byte_t* dest) { 475 | while (len--) { 476 | dest[len] = (byte_t) n; 477 | n >>= 8; 478 | } 479 | } 480 | //! Return position of sector if it is encrypted with the default key otherwise exit.. 481 | /** @param t The tag information 482 | * @return The sector that has a key 483 | */ 484 | int find_exploit_sector(mftag t, void (*UpdateStatusMessage)(char *status)) { 485 | unsigned int i; 486 | bool interesting = false; 487 | char buffer[50]; 488 | 489 | for (i = 0; i < t.num_sectors; i++) 490 | if (!t.sectors[i].foundKeyA || !t.sectors[i].foundKeyB) { 491 | interesting = true; 492 | break; 493 | } 494 | 495 | if (!interesting) { 496 | UpdateStatusMessage("Status: We have all sectors encrypted with the default keys.."); 497 | return -1; 498 | } 499 | 500 | for (i = 1; i < t.num_sectors; i++) 501 | if ((t.sectors[i].foundKeyA) || (t.sectors[i].foundKeyB)) { 502 | sprintf(buffer, "Statis: Using sector %02d as an exploit sector", i); 503 | UpdateStatusMessage(buffer); 504 | return i; 505 | } 506 | 507 | if ((t.sectors[0].foundKeyA) || (t.sectors[0].foundKeyB)) { 508 | sprintf(buffer, "Statis: Using sector %02d as an exploit sector", 0); 509 | UpdateStatusMessage(buffer); 510 | return 0; 511 | } 512 | 513 | UpdateStatusMessage("No sector encrypted with the default key has been found, exiting."); 514 | stopreadingcard = TRUE; 515 | } 516 | 517 | //! Reset the reader 518 | /** @param t The mifare tag 519 | * @param r Handle to the reader 520 | */ 521 | void reset(nfc_device_desc_t *device, mftag *t, mfreader *r, void (*UpdateStatusMessage)(char *status)){ 522 | UpdateStatusMessage("Status: Reconnecting to reader."); 523 | nfc_configure(r->pdi, NDO_HANDLE_CRC, true); 524 | nfc_configure(r->pdi, NDO_HANDLE_PARITY, true); 525 | nfc_disconnect(r->pdi); 526 | mf_init(device, t,r, UpdateStatusMessage); 527 | if (stopreadingcard) return; 528 | mf_configure(r->pdi); 529 | mf_select_tag(r->pdi, &t->ti, UpdateStatusMessage); 530 | } 531 | 532 | //! Mifare anticollision 533 | /** @param t The mifare tag 534 | * @param r Handle to the reader 535 | */ 536 | void mf_anticollision(nfc_device_desc_t *device, mftag *t, mfreader *r, void (*UpdateStatusMessage)(char *status)) { 537 | const nfc_modulation_t nm = { NMT_ISO14443A,NBR_106 }; 538 | if (!nfc_initiator_select_passive_target(r->pdi, nm, NULL, 0, &t->ti)) 539 | reset(device, t, r, UpdateStatusMessage); 540 | } 541 | 542 | //! Check if the given block is a trailer block 543 | /** @param block The block to check 544 | * @return true if it's the trailer block 545 | */ 546 | int trailer_block(uint32_t block) { 547 | // Test if we are in the small or big sectors 548 | return (block < 128) ? ((block + 1) % 4 == 0) : ((block + 1) % 16 == 0); 549 | } 550 | 551 | //! Converts a byte[] to an number 552 | /** @param src The byte[] source 553 | * @param len Length of the byte array 554 | * @return The converted number 555 | */ 556 | long long unsigned int bytes_to_num(byte_t* src, uint32_t len) { 557 | uint64_t num = 0; 558 | while (len--) { 559 | num = (num << 8) | (*src); 560 | src++; 561 | } 562 | return num; 563 | } 564 | 565 | 566 | //! Select a mifare card 567 | /** @param pdi The NFC Device information 568 | * @param ti Information about the card 569 | * @param UpdateStatusMessage a message for the user 570 | */ 571 | void mf_select_tag(nfc_device_t* pdi, nfc_target_t* ti, void (*UpdateStatusMessage)(char *status)) { 572 | // Poll for a ISO14443A (MIFARE) tag 573 | const nfc_modulation_t nm = { NMT_ISO14443A,NBR_106 }; 574 | if (!nfc_initiator_select_passive_target(pdi, nm,NULL,0,ti)) { 575 | UpdateStatusMessage("Status: !Error connecting to the MIFARE Classic tag."); 576 | nfc_disconnect(pdi); 577 | stopreadingcard = TRUE; 578 | } 579 | } 580 | 581 | //! Configure the mifare device 582 | /** @param pdi The NFC Device information 583 | */ 584 | void mf_configure(nfc_device_t* pdi) { 585 | nfc_initiator_init(pdi); 586 | // Drop the field for a while, so can be reset 587 | nfc_configure(pdi,NDO_ACTIVATE_FIELD,false); 588 | 589 | // Let the reader only try once to find a tag 590 | nfc_configure(pdi,NDO_INFINITE_SELECT,false); 591 | // Configure the CRC and Parity settings 592 | nfc_configure(pdi,NDO_HANDLE_CRC,true); 593 | nfc_configure(pdi,NDO_HANDLE_PARITY,true); 594 | // Enable the field so more power consuming cards can power themselves up 595 | nfc_configure(pdi,NDO_ACTIVATE_FIELD,true); 596 | } 597 | 598 | //! Initialise the mifare reader, connect to the reader 599 | /** @param t The mifare tag 600 | * @param r Handle to the reader 601 | * @param UpdateStatusMessage a message for the user 602 | */ 603 | void mf_init(nfc_device_desc_t *device, mftag *t, mfreader *r, void (*UpdateStatusMessage)(char *status)) { 604 | // Connect to the first NFC device 605 | r->pdi = nfc_connect(device); 606 | if (!r->pdi) { 607 | UpdateStatusMessage("Status: !Error connecting to the NFC reader. Make sure you closed all help programs"); 608 | stopreadingcard = TRUE; 609 | } 610 | } 611 | 612 | void WriteCurrentKeys(char *keyDir, bool skipA, bool skipB, mftag t) { 613 | char fileName[1000]; 614 | FILE *keyFileA; 615 | FILE *keyFileB; 616 | byte_t keyBuffer[40][6]; 617 | char found[40]; 618 | int keyPlace; 619 | 620 | if (!skipA) { 621 | sprintf(fileName, "%s/keys/Ta%08x.dump", keyDir, t.uid); 622 | if (keyFileA = fopen(fileName, "wb")) { 623 | for (keyPlace = 0;keyPlace *performanceData, int sets, char *keyDir, unsigned char *buffer, int buffersize, int skipToSector, bool keyA, bool keyB, void (*UpdateSectorStatus)(char, int, byte_t), void (*UpdateStatusMessage)(char *status), void (*SetCardInfo)(char *status)) { 701 | 702 | //Set all sectors to no information 703 | char StatusBuffer[600]; 704 | int ch, k, n; 705 | int iFoundKeys = 0; 706 | unsigned int i, j, m, o; 707 | int key, block; 708 | int succeed = 1; 709 | char *data; 710 | 711 | // Exploit sector 712 | int e_sector; 713 | int probes = DEFAULT_PROBES_NR; 714 | int tryKeys = 0; 715 | 716 | // By default, dump 'A' keys 717 | bool dumpKeysA = true; 718 | bool skip = false; 719 | bool keysFound = false; 720 | bool skipB = !keyB; 721 | bool skipA = !keyA; 722 | bool useKeyFile = true; 723 | bool foundAFile = false; 724 | bool foundBFile = false; 725 | 726 | stopreadingcard = false; 727 | 728 | char fileName[1000]; 729 | FILE * keyFileA; 730 | FILE * keyFileB; 731 | byte_t keyBuffer[40][6]; 732 | 733 | // Next default key specified as option (-k) 734 | byte_t * defKey = NULL; 735 | 736 | // Array with default Mifare Classic keys 737 | byte_t defaultKeys[][6] = { 738 | { 0x8f, 0xd0, 0xa4, 0xf2, 0x56, 0xe9 }, 739 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // Default key (first key used by program if no user defined key) 740 | {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // NFCForum MAD key 741 | {0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // NFCForum content key 742 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Blank key 743 | {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, 744 | {0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, 745 | {0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, 746 | {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, 747 | {0x71, 0x4c, 0x5c, 0x88, 0x6e, 0x97}, 748 | {0x58, 0x7e, 0xe5, 0xf9, 0x35, 0x0f}, 749 | {0xa0, 0x47, 0x8c, 0xc3, 0x90, 0x91}, 750 | {0x53, 0x3c, 0xb6, 0xc7, 0x23, 0xf6}, 751 | {0x8f, 0xd0, 0xa4, 0xf2, 0x56, 0xe9} 752 | 753 | }; 754 | 755 | mftag t; 756 | mfreader r; 757 | denonce d = {NULL, 0, DEFAULT_DIST_NR, DEFAULT_TOLERANCE, {0x00, 0x00, 0x00}}; 758 | 759 | // Pointers to possible keys 760 | pKeys *pk; 761 | countKeys *ck; 762 | 763 | // Pointer to already broken keys, except defaults 764 | bKeys *bk; 765 | 766 | static mifare_param mp; 767 | static mifare_classic_tag mtDump; 768 | 769 | mifare_cmd mc; 770 | 771 | i=1; 772 | 773 | for (i = 0; i < 40; i++) { 774 | UpdateSectorStatus('A', i, 0); 775 | UpdateSectorStatus('B', i, 0); 776 | } 777 | 778 | 779 | // Initialize reader/tag structures 780 | mf_init(device, &t, &r, UpdateStatusMessage); 781 | if (stopreadingcard) return 0; 782 | // Configure reader settings 783 | mf_configure(r.pdi); 784 | if (stopreadingcard) { return 0; } 785 | mf_select_tag(r.pdi, &t.ti, UpdateStatusMessage); 786 | if (stopreadingcard) { return 0; } 787 | //Check if it's a mifare classic tag 788 | if (0 != (t.ti.nti.nai.btSak & 0x08)) { 789 | // Save tag uid and info about block size (b4K) 790 | t.b4K = (t.ti.nti.nai.abtAtqa[1] == 0x02); 791 | t.uid = (uint32_t) bytes_to_num(t.ti.nti.nai.abtUid, 4); 792 | 793 | t.num_blocks = (t.b4K) ? 0xff : 0x3f; 794 | t.num_sectors = t.b4K ? NR_TRAILERS_4k : NR_TRAILERS_1k; 795 | 796 | t.sectors = (sector *) calloc(t.num_sectors, sizeof(sector)); 797 | 798 | if (t.b4K && buffersize < 4096) { 799 | UpdateStatusMessage("Buffersize must be at least 4096 bytes"); 800 | return 0; 801 | } 802 | else if (t.b4K && buffersize < 1024) { 803 | UpdateStatusMessage("Buffersize must be at least 1024 bytes"); 804 | return 0; 805 | } 806 | 807 | 808 | if (NULL == t.sectors) { 809 | UpdateStatusMessage("Status: Error! Cannot allocate memory for t.sectors."); 810 | return 0; 811 | } 812 | 813 | if (NULL == (pk = (pKeys *) malloc(sizeof(pKeys)))) { 814 | UpdateStatusMessage("Status: Error! Cannot allocate memory for pk."); 815 | return 0; 816 | } 817 | 818 | if (NULL == (bk = (bKeys *) malloc(sizeof(bKeys)))) { 819 | UpdateStatusMessage("Status: Error! Cannot allocate memory for bk."); 820 | return 0; 821 | } else { 822 | bk->brokenKeys = NULL; 823 | bk->size = 0; 824 | } 825 | 826 | d.distances = (uint32_t *) calloc(d.num_distances, sizeof(u_int32_t)); 827 | if (NULL == d.distances) { 828 | UpdateStatusMessage("Status: Error! Cannot allocate memory for t.distances."); 829 | return 0; 830 | } 831 | 832 | 833 | // Initialize t.sectors, keys are not known yet 834 | for (i = 0; i < (t.num_sectors); ++i) { 835 | t.sectors[i].foundKeyA = t.sectors[i].foundKeyB = false; 836 | } 837 | 838 | sprintf(StatusBuffer,"Card: MIFARE Classic %cK, uid: %08x\n", (t.b4K ? '4' : '1'), t.uid); 839 | SetCardInfo(StatusBuffer); 840 | 841 | if (useKeyFile) { 842 | sprintf(fileName, "%s/keys/a%08x.dump", keyDir, t.uid); 843 | if ((!skipA) && (keyFileA = fopen(fileName, "rb"))) { 844 | foundAFile = true; 845 | UpdateStatusMessage("A-key file found."); 846 | if (t.num_sectors == fread(keyBuffer, 6, t.num_sectors, keyFileA)) { 847 | int keyPlace; 848 | for (keyPlace = 0;keyPlacesize && !stopreadingcard; o++) { 977 | num_to_bytes(bk->brokenKeys[o], 6, mp.mpa.abtKey); 978 | mc = dumpKeysA ? MC_AUTH_A : MC_AUTH_B; 979 | if (!nfc_initiator_mifare_cmd(r.pdi,mc,t.sectors[j].trailer,&mp)) { 980 | mf_anticollision(device, &t, &r, UpdateStatusMessage); 981 | if (stopreadingcard) { free(t.sectors); free(d.distances); return 0; } 982 | } else { 983 | // Save all information about successfull authentization 984 | if (dumpKeysA) { 985 | memcpy(t.sectors[j].KeyA, mp.mpa.abtKey, sizeof(mp.mpa.abtKey)); 986 | UpdateSectorStatus('A', j, 2); 987 | t.sectors[j].foundKeyA = true; 988 | WriteCurrentKeys(keyDir, skipA, skipB, t); 989 | } else if(!skipB){ 990 | memcpy(t.sectors[j].KeyB, mp.mpa.abtKey, sizeof(mp.mpa.abtKey)); 991 | UpdateSectorStatus('B', j, 2); 992 | t.sectors[j].foundKeyB = true; 993 | WriteCurrentKeys(keyDir, skipA, skipB, t); 994 | } 995 | 996 | sprintf(StatusBuffer,"Sector: %d, type %c, key [%012llx]", j, (dumpKeysA ? 'A' : 'B'), bytes_to_num(mp.mpa.abtKey, 6)); 997 | UpdateStatusMessage(StatusBuffer); 998 | 999 | mf_configure(r.pdi); 1000 | mf_anticollision(device, &t, &r, UpdateStatusMessage); 1001 | if (stopreadingcard) { free(t.sectors); free(d.distances); return 0; } 1002 | skip = true; 1003 | break; 1004 | } 1005 | } 1006 | if (skip) continue; // We have already revealed key, go to the next iteration 1007 | 1008 | // Max probes for auth for each sector 1009 | for (k = 0; k < probes && !stopreadingcard; ++k) { 1010 | performance pProbe; 1011 | pProbe.duration = GetTickCount(); 1012 | // Try to authenticate to exploit sector and determine distances (filling denonce.distances) 1013 | 1014 | mf_enhanced_auth(e_sector, 0, t, r, &d, pk, 'd', dumpKeysA, UpdateStatusMessage); // AUTH + Get Distances mode 1015 | if (stopreadingcard) { free(t.sectors); free(d.distances); return 0; } 1016 | sprintf(StatusBuffer,"Sector: %d, type %c, probe %d, distance %d", j, (dumpKeysA ? 'A' : 'B'), k, d.median); 1017 | UpdateStatusMessage(StatusBuffer); 1018 | 1019 | // Configure device to the previous state 1020 | mf_configure(r.pdi); 1021 | mf_anticollision(device, &t, &r, UpdateStatusMessage); 1022 | if (stopreadingcard) { free(t.sectors); free(d.distances); return 0; } 1023 | 1024 | pk->possibleKeys = NULL; 1025 | pk->size = 0; 1026 | // We have 'sets' * 32b keystream of potential keys 1027 | for (n = 0; n < sets; n++) { 1028 | performance pSet; 1029 | pSet.duration = GetTickCount(); 1030 | sprintf(StatusBuffer,"Sector: %d, type %c, probe %d, distance %d, set %d", j, (dumpKeysA ? 'A' : 'B'), k, d.median, (n + 1)); 1031 | UpdateStatusMessage(StatusBuffer); 1032 | 1033 | // AUTH + Recovery key mode (for a_sector), repeat 5 times 1034 | mf_enhanced_auth(e_sector, t.sectors[j].trailer, t, r, &d, pk, 'r', dumpKeysA, UpdateStatusMessage); 1035 | if (stopreadingcard) { free(t.sectors); free(d.distances); return 0; } 1036 | mf_configure(r.pdi); 1037 | mf_anticollision(device, &t, &r, UpdateStatusMessage); 1038 | if (stopreadingcard) { free(t.sectors); free(d.distances); return 0; } 1039 | 1040 | pSet.duration = GetTickCount() - pSet.duration; 1041 | pSet.keyType = dumpKeysA ? 'A' : 'B'; 1042 | pSet.sector = j; 1043 | pSet.probe = k; 1044 | pSet.set = n; 1045 | performanceData->push_back(pSet); 1046 | } 1047 | // Get first 15 grouped keys 1048 | ck = uniqsort(pk->possibleKeys, pk->size, UpdateStatusMessage); 1049 | if (stopreadingcard) { free(t.sectors); free(d.distances); return 0; } 1050 | sprintf(StatusBuffer,"Possible Keys: %d", pk->size); 1051 | UpdateStatusMessage(StatusBuffer); 1052 | tryKeys = pk->size > TRY_KEYS ? TRY_KEYS : pk->size; 1053 | for (i = 0; i < tryKeys && !stopreadingcard ; i++) { 1054 | // We don't known this key, try to break it 1055 | // This key can be found here two or more times 1056 | if (ck[i].count > 0) { 1057 | sprintf(StatusBuffer,"Possible Key: %llx", ck[i].key); 1058 | UpdateStatusMessage(StatusBuffer); 1059 | 1060 | // Set required authetication method 1061 | num_to_bytes(ck[i].key, 6, mp.mpa.abtKey); 1062 | mc = dumpKeysA ? MC_AUTH_A : MC_AUTH_B; 1063 | if (!nfc_initiator_mifare_cmd(r.pdi,mc,t.sectors[j].trailer,&mp)) { 1064 | mf_anticollision(device, &t, &r, UpdateStatusMessage); 1065 | if (stopreadingcard) { free(pk->possibleKeys); free(ck); free(t.sectors); free(d.distances); return 0; } 1066 | } else { 1067 | // Save all information about successfull authentization 1068 | bk->size++; 1069 | bk->brokenKeys = (uint64_t *) realloc((void *)bk->brokenKeys, bk->size * sizeof(uint64_t)); 1070 | bk->brokenKeys[bk->size-1] = bytes_to_num(mp.mpa.abtKey, 6); 1071 | if (dumpKeysA) { 1072 | memcpy(t.sectors[j].KeyA, mp.mpa.abtKey, sizeof(mp.mpa.abtKey)); 1073 | t.sectors[j].foundKeyA = true; 1074 | UpdateSectorStatus('A', j, 2); 1075 | WriteCurrentKeys(keyDir, skipA, skipB, t); 1076 | } else { 1077 | memcpy(t.sectors[j].KeyB, mp.mpa.abtKey, sizeof(mp.mpa.abtKey)); 1078 | t.sectors[j].foundKeyB = true; 1079 | UpdateSectorStatus('B', j, 2); 1080 | WriteCurrentKeys(keyDir, skipA, skipB, t); 1081 | } 1082 | 1083 | sprintf(StatusBuffer, "Found Key: %c [%012llx]\n", (dumpKeysA ? 'A' : 'B'), bytes_to_num(mp.mpa.abtKey, 6)); 1084 | UpdateStatusMessage(StatusBuffer); 1085 | 1086 | mf_configure(r.pdi); 1087 | mf_anticollision(device, &t, &r, UpdateStatusMessage); 1088 | if (stopreadingcard) { free(pk->possibleKeys); free(ck); free(t.sectors); free(d.distances); return 0; } 1089 | break; 1090 | } 1091 | } 1092 | } 1093 | free(pk->possibleKeys); 1094 | free(ck); 1095 | pProbe.duration = GetTickCount() - pProbe.duration; 1096 | pProbe.keyType = dumpKeysA ? 'A' : 'B'; 1097 | pProbe.sector = j; 1098 | pProbe.probe = k; 1099 | pProbe.set = -1; 1100 | performanceData->push_back(pProbe); 1101 | // Success, try the next sector 1102 | if ((dumpKeysA && t.sectors[j].foundKeyA) || (!dumpKeysA && t.sectors[j].foundKeyB)) break; 1103 | } 1104 | // We haven't found any key, exiting 1105 | if ((dumpKeysA && !t.sectors[j].foundKeyA) || (!dumpKeysA && !t.sectors[j].foundKeyB)) { 1106 | UpdateStatusMessage("No success, maybe you should increase the probes."); 1107 | return 0; 1108 | } 1109 | } 1110 | pSector.duration = GetTickCount() - pSector.duration; 1111 | pSector.keyType = dumpKeysA ? 'A' : 'B'; 1112 | pSector.sector = j; 1113 | pSector.probe = -1; 1114 | pSector.set = -1; 1115 | performanceData->push_back(pSector); 1116 | } 1117 | 1118 | } 1119 | } 1120 | 1121 | 1122 | for (i = 0; i < (t.num_sectors); ++i) { 1123 | if ((!skipA&&(dumpKeysA && !t.sectors[i].foundKeyA)) || (!skipB&&(!dumpKeysA && !t.sectors[i].foundKeyB))) { 1124 | UpdateStatusMessage("Try again, there are still some encrypted blocks."); 1125 | succeed = 0; 1126 | break; 1127 | } 1128 | } 1129 | 1130 | if (succeed) { 1131 | i = t.num_sectors; // Sector counter 1132 | UpdateStatusMessage("Auth with all sectors succeeded, dumping keys to a file!"); 1133 | // Read all blocks 1134 | uint8_t sec; 1135 | mifare_sector mfs; 1136 | mfs.sector = 0; 1137 | memcpy(skipA ? mfs.KeyB : mfs.KeyA, skipA ? t.sectors[0].KeyB : t.sectors[0].KeyA, sizeof(t.sectors[0].KeyA)); 1138 | readSector(device, r.pdi, &mfs, &t.ti,false, &t, &r, UpdateStatusMessage); 1139 | memcpy(&mtDump.amb[sectorToFirstBlock(mfs.sector)],mfs.Data,numberOfBlocks(mfs.sector)*16); 1140 | memcpy(mtDump.amb[sectorToFirstBlock(0)+numberOfBlocks(0)-1].mbt.abtKeyA, t.sectors[0].KeyA,6); 1141 | memcpy(mtDump.amb[sectorToFirstBlock(0)+numberOfBlocks(0)-1].mbt.abtKeyB, t.sectors[0].KeyB,6); 1142 | 1143 | memset(mfs.Data, 0, sizeof(mfs.Data)); 1144 | for (sec = skipToSector;secsector)+numberOfBlocks(sector->sector)-1; 1243 | bool auth = false; 1244 | memcpy(mp.mpa.abtUid,t->nti.nai.abtUid,4); 1245 | 1246 | if (keyB) { 1247 | memcpy(mp.mpa.abtKey,sector->KeyB, sizeof(sector->KeyB)); 1248 | if (nfc_initiator_mifare_cmd(pnd, MC_AUTH_B, block, &mp)) { 1249 | auth = true; 1250 | } 1251 | } 1252 | 1253 | if (!auth && keyA) { 1254 | memcpy(mp.mpa.abtKey,sector->KeyA, sizeof(sector->KeyA)); 1255 | if (nfc_initiator_mifare_cmd(pnd, MC_AUTH_A, block, &mp)) { 1256 | auth = true; 1257 | } 1258 | } 1259 | return auth; 1260 | } 1261 | 1262 | void writeSector(nfc_device_t * pnd, mifare_sector* sector,nfc_target_t *t, bool keyA, bool keyB, bool writeKeys, void (*UpdateStatusMessage)(char *status)) { 1263 | static mifare_param mp; 1264 | const nfc_modulation_t nm = { NMT_ISO14443A,NBR_106 }; 1265 | char Buffer[150]; 1266 | uint8_t block = sectorToFirstBlock(sector->sector)+numberOfBlocks(sector->sector)-1; 1267 | memcpy(mp.mpa.abtKey,sector->KeyB, sizeof(sector->KeyB)); 1268 | memcpy(mp.mpa.abtUid,t->nti.nai.abtUid,4); 1269 | if (Authenticate(pnd, sector, t, keyA, keyB)) { 1270 | int i; 1271 | for (i=numberOfBlocks(sector->sector)-1;i>=0;i--) { 1272 | if (trailer_block(block) && !writeKeys) { 1273 | } else { 1274 | memcpy(mp.mpd.abtData, sector->Data[i], 16); 1275 | if (nfc_initiator_mifare_cmd(pnd, MC_WRITE, block, &mp)) { 1276 | sprintf(Buffer, "Block %02d, type %c, key %012llx :", block, 'B', bytes_to_num(sector->KeyB, 6)); 1277 | UpdateStatusMessage(Buffer); 1278 | } else { 1279 | mf_configure(pnd); 1280 | nfc_initiator_select_passive_target(pnd, nm, NULL, 0, t); 1281 | sprintf(Buffer, "Error Writing: Block %02d, type %c, key %012llx", block, 'B', bytes_to_num(sector->KeyB, 6)); 1282 | UpdateStatusMessage(Buffer); 1283 | break; 1284 | } 1285 | } 1286 | block--; 1287 | } 1288 | } else { 1289 | sprintf(Buffer, "Error Writing: Block %02d, type %c, key %012llx :", block, 'B', bytes_to_num(sector->KeyB, 6)); 1290 | UpdateStatusMessage(Buffer); 1291 | mf_configure(pnd); 1292 | nfc_initiator_select_passive_target(pnd, nm, NULL, 0, t); 1293 | } 1294 | } 1295 | 1296 | int WriteCard(nfc_device_desc_t *device, char *keyDir, unsigned char *buffer, int buffersize, bool keyA, bool keyB, bool writeKeys, void (*UpdateSectorStatus)(char, int, byte_t), void (*UpdateStatusMessage)(char *status), void (*SetCardInfo)(char *status)) { 1297 | 1298 | //Set all sectors to no information 1299 | char StatusBuffer[600]; 1300 | int ch, k, n; 1301 | int iFoundKeys = 0; 1302 | unsigned int i, j, m, o; 1303 | int key, block; 1304 | int succeed = 1; 1305 | char *data; 1306 | 1307 | // Exploit sector 1308 | int e_sector; 1309 | int probes = DEFAULT_PROBES_NR; 1310 | int tryKeys = 0; 1311 | 1312 | // By default, dump 'A' keys 1313 | bool dumpKeysA = true; 1314 | bool skip = false; 1315 | bool keysFound = false; 1316 | bool skipB = !keyB; 1317 | bool skipA = !keyA; 1318 | bool useKeyFile = true; 1319 | bool foundAFile = false; 1320 | bool foundBFile = false; 1321 | 1322 | stopreadingcard = false; 1323 | 1324 | char fileName[1000]; 1325 | FILE * keyFileA; 1326 | FILE * keyFileB; 1327 | byte_t keyBuffer[40][6]; 1328 | 1329 | // Next default key specified as option (-k) 1330 | byte_t * defKey = NULL; 1331 | 1332 | // Array with default Mifare Classic keys 1333 | byte_t defaultKeys[][6] = { 1334 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // User defined key slot 1335 | //{0x, 0x, 0x, 0x, 0x, 0x}, 1336 | 1337 | {0xb5, 0xff, 0x67, 0xcb, 0xa9, 0x51}, 1338 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 1339 | 1340 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 1341 | {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, 1342 | {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, 1343 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 1344 | {0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, 1345 | {0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, 1346 | {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff} 1347 | 1348 | }; 1349 | 1350 | mftag t; 1351 | mfreader r; 1352 | denonce d = {NULL, 0, DEFAULT_DIST_NR, DEFAULT_TOLERANCE, {0x00, 0x00, 0x00}}; 1353 | 1354 | // Pointers to possible keys 1355 | pKeys *pk; 1356 | countKeys *ck; 1357 | 1358 | // Pointer to already broken keys, except defaults 1359 | bKeys *bk; 1360 | 1361 | static mifare_param mp; 1362 | static mifare_classic_tag mtDump; 1363 | 1364 | mifare_cmd mc; 1365 | 1366 | i=1; 1367 | 1368 | for (i = 0; i < 40; i++) { 1369 | UpdateSectorStatus('A', i, 0); 1370 | UpdateSectorStatus('B', i, 0); 1371 | } 1372 | 1373 | 1374 | // Initialize reader/tag structures 1375 | mf_init(device, &t, &r, UpdateStatusMessage); 1376 | if (stopreadingcard) return 0; 1377 | // Configure reader settings 1378 | mf_configure(r.pdi); 1379 | if (stopreadingcard) return 0; 1380 | mf_select_tag(r.pdi, &t.ti, UpdateStatusMessage); 1381 | if (stopreadingcard) return 0; 1382 | //Check if it's a mifare classic tag 1383 | if (0 != (t.ti.nti.nai.btSak & 0x08)) { 1384 | 1385 | // Save tag uid and info about block size (b4K) 1386 | t.b4K = (t.ti.nti.nai.abtAtqa[1] == 0x02); 1387 | t.uid = (uint32_t) bytes_to_num(t.ti.nti.nai.abtUid, 4); 1388 | 1389 | t.num_blocks = (t.b4K) ? 0xff : 0x3f; 1390 | t.num_sectors = t.b4K ? NR_TRAILERS_4k : NR_TRAILERS_1k; 1391 | 1392 | t.sectors = (sector *) calloc(t.num_sectors, sizeof(sector)); 1393 | 1394 | if (t.b4K && buffersize < 4096) { 1395 | UpdateStatusMessage("Buffersize must be at least 4096 bytes"); 1396 | return 0; 1397 | } 1398 | else if (t.b4K && buffersize < 1024) { 1399 | UpdateStatusMessage("Buffersize must be at least 1024 bytes"); 1400 | return 0; 1401 | } 1402 | 1403 | 1404 | if (NULL == t.sectors) { 1405 | UpdateStatusMessage("Status: Error! Cannot allocate memory for t.sectors."); 1406 | return 0; 1407 | } 1408 | 1409 | if (NULL == (pk = (pKeys *) malloc(sizeof(pKeys)))) { 1410 | UpdateStatusMessage("Status: Error! Cannot allocate memory for pk."); 1411 | return 0; 1412 | } 1413 | 1414 | if (NULL == (bk = (bKeys *) malloc(sizeof(bKeys)))) { 1415 | UpdateStatusMessage("Status: Error! Cannot allocate memory for bk."); 1416 | return 0; 1417 | } else { 1418 | bk->brokenKeys = NULL; 1419 | bk->size = 0; 1420 | } 1421 | 1422 | d.distances = (uint32_t *) calloc(d.num_distances, sizeof(u_int32_t)); 1423 | if (NULL == d.distances) { 1424 | UpdateStatusMessage("Status: Error! Cannot allocate memory for t.distances."); 1425 | return 0; 1426 | } 1427 | 1428 | 1429 | // Initialize t.sectors, keys are not known yet 1430 | for (i = 0; i < (t.num_sectors); ++i) { 1431 | t.sectors[i].foundKeyA = t.sectors[i].foundKeyB = false; 1432 | } 1433 | 1434 | sprintf(StatusBuffer,"Card: MIFARE Classic %cK card with uid: %08x\n", (t.b4K ? '4' : '1'), t.uid); 1435 | SetCardInfo(StatusBuffer); 1436 | 1437 | if (useKeyFile) { 1438 | sprintf(fileName, "%s/keys/a%08x.dump", keyDir, t.uid); 1439 | if ((!skipA) && (keyFileA = fopen(fileName, "rb"))) { 1440 | foundAFile = true; 1441 | UpdateStatusMessage("A-key file found."); 1442 | if (t.num_sectors == fread(keyBuffer, 6, t.num_sectors, keyFileA)) { 1443 | int keyPlace; 1444 | for (keyPlace = 0;keyPlace 6 | 7 | #include 8 | 9 | #include 10 | 11 | #define u_int32_t uint32_t 12 | 13 | #define MEM_CHUNK 10000 14 | #define TRY_KEYS 150 15 | 16 | // Number of trailers == number of sectors 17 | // 16x64b = 16 18 | #define NR_TRAILERS_1k (16) 19 | // 32x64b + 8*256b = 40 20 | #define NR_TRAILERS_4k (40) 21 | 22 | #define MAX_FRAME_LEN 264 23 | 24 | // Used for counting nonce distances, explore [nd-value, nd+value] 25 | #define DEFAULT_TOLERANCE 20 26 | 27 | // Default number of distance probes 28 | #define DEFAULT_DIST_NR 15 29 | 30 | // Default number of probes for a key recovery for one sector 31 | #define DEFAULT_PROBES_NR 600 32 | 33 | // Number of sets with 32b keys 34 | #define DEFAULT_SETS_NR 2 35 | 36 | #define odd_parity(i) (( (i) ^ (i)>>1 ^ (i)>>2 ^ (i)>>3 ^ (i)>>4 ^ (i)>>5 ^ (i)>>6 ^ (i)>>7 ^ 1) & 0x01) 37 | 38 | typedef struct { 39 | byte_t KeyA[6]; 40 | byte_t KeyB[6]; 41 | bool foundKeyA; 42 | bool foundKeyB; 43 | byte_t trailer; // Value of a trailer block 44 | } sector; 45 | 46 | typedef struct { 47 | uint32_t *distances; 48 | uint32_t median; 49 | uint32_t num_distances; 50 | uint32_t tolerance; 51 | byte_t parity[3]; // used for 3 bits of parity information 52 | } denonce; // Revealed information about nonce 53 | 54 | typedef struct { 55 | nfc_target_t ti; 56 | sector * sectors; // Allocate later, we do not know the number of sectors yet 57 | sector e_sector; // Exploit sector 58 | uint32_t num_sectors; 59 | uint32_t num_blocks; 60 | uint32_t uid; 61 | bool b4K; 62 | } mftag; 63 | 64 | typedef struct { 65 | uint64_t *possibleKeys; 66 | uint32_t size; 67 | } pKeys; 68 | 69 | typedef struct { 70 | uint64_t *brokenKeys; 71 | uint32_t size; 72 | } bKeys; 73 | 74 | typedef struct { 75 | nfc_device_t *pdi; 76 | } mfreader; 77 | 78 | typedef struct { 79 | uint64_t key; 80 | int count; 81 | } countKeys; 82 | 83 | typedef struct{ 84 | uint8_t sector; 85 | byte_t KeyA[6]; 86 | byte_t KeyB[6]; 87 | byte_t Data[16][16]; 88 | }mifare_sector; 89 | 90 | typedef struct{ 91 | char keyType; 92 | int sector; 93 | int probe; 94 | int set; 95 | unsigned __int64 duration; 96 | }performance; 97 | 98 | extern bool stopreadingcard; 99 | 100 | //! Retreive the keys and read a card 101 | /** @param sets the number of times that there should be information collected from the card 102 | * @param keyDir the folder where the keys are stored 103 | * @param buffer the output where the card data will be stored 104 | * @param bufferszie the size of the buffer 105 | * @param skipToSector when the reading starts, at which sector does the reading start 106 | * @param keyA Use A keys 107 | * @param keyB Use B keys 108 | * @param UpdateSectorStatus Sector status changed, char = key type, int = sector, byte_t = status 0 = no info, 1 = busy retreiving key, 2 = has key 109 | * @param UpdateStatusMessage a message for the user 110 | * @param SetCardInfo Set found card information 111 | * @return the number of bytes retreived from the card 112 | */ 113 | int ReadCard(nfc_device_desc_t *device, std::list *performanceData, int sets, char *keyDir, unsigned char *buffer, int buffersize, int skipToSector, bool keyA, bool keyB, void (*UpdateSectorStatus)(char, int, byte_t), void (*UpdateStatusMessage)(char *status), void (*SetCardInfo)(char *status)); 114 | int WriteCard(nfc_device_desc_t *device, char *keyDir, unsigned char *buffer, int buffersize, bool keyA, bool keyB, bool writeKeys, void (*UpdateSectorStatus)(char, int, byte_t), void (*UpdateStatusMessage)(char *status), void (*SetCardInfo)(char *status)); 115 | #endif -------------------------------------------------------------------------------- /src/mfocGUI/mfocGUI.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/mfocGUI.aps -------------------------------------------------------------------------------- /src/mfocGUI/mfocGUI.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/mfocGUI.rc -------------------------------------------------------------------------------- /src/mfocGUI/mfocGUI.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {8C770BD4-C5CD-4743-93C4-BEB3D52EDC10} 15 | Win32Proj 16 | mfocGUI 17 | 8.1 18 | 19 | 20 | 21 | Application 22 | true 23 | NotSet 24 | v140 25 | 26 | 27 | Application 28 | false 29 | true 30 | NotSet 31 | v140 32 | Static 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | $(ProjectDir)..\LibNFC\include;$(ProjectDir)..\sqlite;$(IncludePath) 47 | $(ProjectDir)..\LibNFC\lib;$(ProjectDir)..\sqlite;$(LibraryPath) 48 | 49 | 50 | false 51 | $(ProjectDir)..\LibNFC\include;$(ProjectDir)..\sqlite;$(IncludePath) 52 | $(ProjectDir)..\LibNFC\lib;$(ProjectDir)..\sqlite;$(LibraryPath) 53 | 54 | 55 | 56 | 57 | 58 | Level3 59 | Disabled 60 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 61 | 62 | 63 | Windows 64 | true 65 | 66 | 67 | 68 | 69 | Level3 70 | 71 | 72 | MaxSpeed 73 | true 74 | true 75 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 76 | MultiThreaded 77 | 78 | 79 | Windows 80 | true 81 | true 82 | true 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /src/mfocGUI/mfocGUI.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | 70 | 71 | Resource Files 72 | 73 | 74 | 75 | 76 | Resource Files 77 | 78 | 79 | Resource Files 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/mfocGUI/mfocGUI.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /src/mfocGUI/mfocMainWindow.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/mfocMainWindow.cpp -------------------------------------------------------------------------------- /src/mfocGUI/mfocMainWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #define u_int32_t uint32_t 5 | 6 | #define MAX_DEVICE_COUNT 16 7 | 8 | const char g_szClassName[] = "mfocWindowClass"; 9 | HINSTANCE ghInstance; 10 | -------------------------------------------------------------------------------- /src/mfocGUI/mifare.cpp: -------------------------------------------------------------------------------- 1 | #include "mifare.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | /** 8 | * @brief Execute a MIFARE Classic Command 9 | * @return Returns true if action was successfully performed; otherwise returns false. 10 | * @param pmp Some commands need additional information. This information should be supplied in the mifare_param union. 11 | * 12 | * The specified MIFARE command will be executed on the tag. There are different commands possible, they all require the destination block number. 13 | * @note There are three different types of information (Authenticate, Data and Value). 14 | * 15 | * First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID. 16 | * They are both used to initialize the internal cipher-state of the PN53X chip (http://libnfc.org/hardware/pn53x-chip). 17 | * After a successful authentication it will be possible to execute other commands (e.g. Read/Write). 18 | * The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process. 19 | */ 20 | bool 21 | nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp) 22 | { 23 | byte_t abtRx[265]; 24 | size_t szRxLen; 25 | size_t szParamLen; 26 | byte_t abtCmd[265]; 27 | 28 | // Make sure we are dealing with a active device 29 | if (!pnd->bPar) 30 | return false; 31 | 32 | abtCmd[0] = mc; // The MIFARE Classic command 33 | abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff) 34 | 35 | switch (mc) { 36 | // Read and store command have no parameter 37 | case MC_READ: 38 | case MC_STORE: 39 | szParamLen = 0; 40 | break; 41 | 42 | // Authenticate command 43 | case MC_AUTH_A: 44 | case MC_AUTH_B: 45 | szParamLen = sizeof (mifare_param_auth); 46 | break; 47 | 48 | // Data command 49 | case MC_WRITE: 50 | szParamLen = sizeof (mifare_param_data); 51 | break; 52 | 53 | // Value command 54 | case MC_DECREMENT: 55 | case MC_INCREMENT: 56 | case MC_TRANSFER: 57 | szParamLen = sizeof (mifare_param_value); 58 | break; 59 | 60 | // Please fix your code, you never should reach this statement 61 | default: 62 | return false; 63 | break; 64 | } 65 | 66 | // When available, copy the parameter bytes 67 | if (szParamLen) 68 | memcpy (abtCmd + 2, (byte_t *) pmp, szParamLen); 69 | 70 | // Fire the mifare command 71 | if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRxLen,0)) { 72 | /*if (pnd->iLastError != 0x14) 73 | nfc_perror (pnd, "nfc_initiator_transceive_bytes");*/ 74 | return false; 75 | } 76 | // When we have executed a read command, copy the received bytes into the param 77 | if (mc == MC_READ) { 78 | if (szRxLen == 16) { 79 | memcpy (pmp->mpd.abtData, abtRx, 16); 80 | } else { 81 | //printf("\n-----------------------------------------\n"); 82 | return false; 83 | } 84 | } 85 | // Command succesfully executed 86 | return true; 87 | } 88 | -------------------------------------------------------------------------------- /src/mfocGUI/mifare.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Public platform independent Near Field Communication (NFC) library 3 | * 4 | * Copyright (C) 2009, Roel Verdult, 2010, Romuald Conty 5 | * 6 | * This program is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as published by the 8 | * Free Software Foundation, either version 3 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see 18 | * 19 | * 20 | * @file mifaretag.h 21 | * @brief provide samples structs and functions to manipulate MIFARE Classic and Ultralight tags using libnfc 22 | */ 23 | 24 | #ifndef _LIBNFC_MIFARE_H_ 25 | # define _LIBNFC_MIFARE_H_ 26 | 27 | # include 28 | 29 | // Compiler directive, set struct alignment to 1 byte_t for compatibility 30 | # pragma pack(1) 31 | 32 | typedef enum { 33 | MC_AUTH_A = 0x60, 34 | MC_AUTH_B = 0x61, 35 | MC_READ = 0x30, 36 | MC_WRITE = 0xA0, 37 | MC_TRANSFER = 0xB0, 38 | MC_DECREMENT = 0xC0, 39 | MC_INCREMENT = 0xC1, 40 | MC_STORE = 0xC2 41 | } mifare_cmd; 42 | 43 | // MIFARE command params 44 | typedef struct { 45 | byte_t abtKey[6]; 46 | byte_t abtUid[4]; 47 | } mifare_param_auth; 48 | 49 | typedef struct { 50 | byte_t abtData[16]; 51 | } mifare_param_data; 52 | 53 | typedef struct { 54 | byte_t abtValue[4]; 55 | } mifare_param_value; 56 | 57 | typedef union { 58 | mifare_param_auth mpa; 59 | mifare_param_data mpd; 60 | mifare_param_value mpv; 61 | } mifare_param; 62 | 63 | // Reset struct alignment to default 64 | # pragma pack() 65 | 66 | bool nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp); 67 | 68 | // Compiler directive, set struct alignment to 1 byte_t for compatibility 69 | # pragma pack(1) 70 | 71 | // MIFARE Classic 72 | typedef struct { 73 | byte_t abtUID[4]; 74 | byte_t btBCC; 75 | byte_t btUnknown; 76 | byte_t abtATQA[2]; 77 | byte_t abtUnknown[8]; 78 | } mifare_classic_block_manufacturer; 79 | 80 | typedef struct { 81 | byte_t abtData[16]; 82 | } mifare_classic_block_data; 83 | 84 | typedef struct { 85 | byte_t abtKeyA[6]; 86 | byte_t abtAccessBits[4]; 87 | byte_t abtKeyB[6]; 88 | } mifare_classic_block_trailer; 89 | 90 | typedef union { 91 | mifare_classic_block_manufacturer mbm; 92 | mifare_classic_block_data mbd; 93 | mifare_classic_block_trailer mbt; 94 | } mifare_classic_block; 95 | 96 | typedef struct { 97 | mifare_classic_block amb[256]; 98 | } mifare_classic_tag; 99 | 100 | // MIFARE Ultralight 101 | typedef struct { 102 | byte_t sn0[3]; 103 | byte_t btBCC0; 104 | byte_t sn1[4]; 105 | byte_t btBCC1; 106 | byte_t internal; 107 | byte_t lock[2]; 108 | byte_t otp[4]; 109 | } mifareul_block_manufacturer; 110 | 111 | typedef struct { 112 | byte_t abtData[16]; 113 | } mifareul_block_data; 114 | 115 | typedef union { 116 | mifareul_block_manufacturer mbm; 117 | mifareul_block_data mbd; 118 | } mifareul_block; 119 | 120 | typedef struct { 121 | mifareul_block amb[4]; 122 | } mifareul_tag; 123 | 124 | // Reset struct alignment to default 125 | # pragma pack() 126 | 127 | #endif // _LIBNFC_MIFARE_H_ 128 | -------------------------------------------------------------------------------- /src/mfocGUI/nfc-utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "nfc-utils.h" 4 | 5 | static const byte_t OddParity[256] = { 6 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 7 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 8 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 9 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 10 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 11 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 12 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 13 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 14 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 15 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 16 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 17 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 18 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 19 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 20 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 21 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 22 | }; 23 | 24 | byte_t 25 | oddparity (const byte_t bt) 26 | { 27 | return OddParity[bt]; 28 | } 29 | 30 | void 31 | oddparity_bytes_ts (const byte_t * pbtData, const size_t szLen, byte_t * pbtPar) 32 | { 33 | size_t szByteNr; 34 | // Calculate the parity bits for the command 35 | for (szByteNr = 0; szByteNr < szLen; szByteNr++) { 36 | pbtPar[szByteNr] = OddParity[pbtData[szByteNr]]; 37 | } 38 | } 39 | 40 | void 41 | print_hex (const byte_t * pbtData, const size_t szBytes) 42 | { 43 | size_t szPos; 44 | 45 | for (szPos = 0; szPos < szBytes; szPos++) { 46 | //printf ("%02x ", pbtData[szPos]); 47 | } 48 | //printf ("\n"); 49 | } 50 | 51 | void 52 | print_hex_bits (const byte_t * pbtData, const size_t szBits) 53 | { 54 | uint8_t uRemainder; 55 | size_t szPos; 56 | size_t szBytes = szBits / 8; 57 | 58 | for (szPos = 0; szPos < szBytes; szPos++) { 59 | //printf ("%02x ", pbtData[szPos]); 60 | } 61 | 62 | uRemainder = szBits % 8; 63 | // Print the rest bits 64 | if (uRemainder != 0) { 65 | //if (uRemainder < 5) 66 | //printf ("%01x (%d bits)", pbtData[szBytes], uRemainder); 67 | //else 68 | //printf ("%02x (%d bits)", pbtData[szBytes], uRemainder); 69 | } 70 | //printf ("\n"); 71 | } 72 | 73 | void 74 | print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t * pbtDataPar) 75 | { 76 | /*uint8_t uRemainder; 77 | size_t szPos; 78 | size_t szBytes = szBits / 8; 79 | 80 | for (szPos = 0; szPos < szBytes; szPos++) { 81 | printf ("%02x", pbtData[szPos]); 82 | if (OddParity[pbtData[szPos]] != pbtDataPar[szPos]) { 83 | printf ("! "); 84 | } else { 85 | printf (" "); 86 | } 87 | } 88 | 89 | uRemainder = szBits % 8; 90 | // Print the rest bits, these cannot have parity bit 91 | if (uRemainder != 0) { 92 | if (uRemainder < 5) 93 | printf ("%01x (%d bits)", pbtData[szBytes], uRemainder); 94 | else 95 | printf ("%02x (%d bits)", pbtData[szBytes], uRemainder); 96 | } 97 | printf ("\n");*/ 98 | } 99 | 100 | #define SAK_ISO14443_4_COMPLIANT 0x20 101 | #define SAK_ISO18092_COMPLIANT 0x40 102 | 103 | void 104 | print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai) 105 | { 106 | /*printf (" ATQA (SENS_RES): "); 107 | print_hex (nai.abtAtqa, 2); 108 | printf (" UID (NFCID%c): ", (nai.abtUid[0] == 0x08 ? '3' : '1')); 109 | print_hex (nai.abtUid, nai.szUidLen); 110 | printf (" SAK (SEL_RES): "); 111 | print_hex (&nai.btSak, 1); 112 | if (nai.szAtsLen) { 113 | printf (" ATS (ATR): "); 114 | print_hex (nai.abtAts, nai.szAtsLen); 115 | } 116 | if ((nai.btSak & SAK_ISO14443_4_COMPLIANT) || (nai.btSak & SAK_ISO18092_COMPLIANT)) { 117 | printf (" Compliant with: "); 118 | if (nai.btSak & SAK_ISO14443_4_COMPLIANT) 119 | printf ("ISO/IEC 14443-4 "); 120 | if (nai.btSak & SAK_ISO18092_COMPLIANT) 121 | printf ("ISO/IEC 18092"); 122 | printf ("\n"); 123 | }*/ 124 | } 125 | 126 | void 127 | print_nfc_felica_info (const nfc_felica_info_t nfi) 128 | { 129 | /*printf (" ID (NFCID2): "); 130 | print_hex (nfi.abtId, 8); 131 | printf (" Parameter (PAD): "); 132 | print_hex (nfi.abtPad, 8);*/ 133 | } 134 | 135 | void 136 | print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi) 137 | { 138 | /*printf (" ATQB: "); 139 | print_hex (nbi.abtAtqb, 12); 140 | printf (" ID: "); 141 | print_hex (nbi.abtId, 4); 142 | printf (" CID: %02x\n", nbi.btCid); 143 | if (nbi.szInfLen > 0) { 144 | printf (" INF: "); 145 | print_hex (nbi.abtInf, nbi.szInfLen); 146 | } 147 | printf (" PARAMS: %02x %02x %02x %02x\n", nbi.btParam1, nbi.btParam2, nbi.btParam3, nbi.btParam4);*/ 148 | } 149 | 150 | /** 151 | * @brief Tries to parse arguments to find device descriptions. 152 | * @return Returns the list of found device descriptions. 153 | */ 154 | nfc_device_desc_t * 155 | parse_device_desc (int argc, const char *argv[], size_t * szFound) 156 | { 157 | nfc_device_desc_t *pndd = 0; 158 | int arg; 159 | *szFound = 0; 160 | 161 | // Get commandline options 162 | for (arg = 1; arg < argc; arg++) { 163 | 164 | if (0 == strcmp (argv[arg], "--device")) { 165 | 166 | if (argc > arg + 1) { 167 | char buffer[256]; 168 | 169 | pndd = (nfc_device_desc_t *)malloc (sizeof (nfc_device_desc_t)); 170 | 171 | strncpy (buffer, argv[++arg], 256); 172 | 173 | // Driver. 174 | //pndd->pcDriver = (char *) malloc (256); 175 | strcpy (pndd->pcDriver, strtok (buffer, ":")); 176 | 177 | // Port. 178 | //pndd->acPort = (char *) malloc (256); 179 | strcpy (pndd->acPort, strtok (NULL, ":")); 180 | 181 | // Speed. 182 | sscanf (strtok (NULL, ":"), "%u", &pndd->uiSpeed); 183 | 184 | *szFound = 1; 185 | } 186 | break; 187 | } 188 | } 189 | 190 | return pndd; 191 | } 192 | -------------------------------------------------------------------------------- /src/mfocGUI/nfc-utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Public platform independent Near Field Communication (NFC) library 3 | * 4 | * Copyright (C) 2010, Romuald Conty 5 | * 6 | * This program is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as published by the 8 | * Free Software Foundation, either version 3 of the License, or (at your 9 | * option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see 18 | * 19 | * 20 | * @file nfc-utils.h 21 | * @brief Provide some examples shared functions like print, parity calculation, options parsing. 22 | */ 23 | 24 | #ifndef _EXAMPLES_NFC_UTILS_H_ 25 | # define _EXAMPLES_NFC_UTILS_H_ 26 | 27 | # include 28 | # include 29 | 30 | byte_t oddparity (const byte_t bt); 31 | void oddparity_byte_ts (const byte_t * pbtData, const size_t szLen, byte_t * pbtPar); 32 | 33 | void print_hex (const byte_t * pbtData, const size_t szLen); 34 | void print_hex_bits (const byte_t * pbtData, const size_t szBits); 35 | void print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t * pbtDataPar); 36 | 37 | void print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai); 38 | void print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi); 39 | void print_nfc_felica_info (const nfc_felica_info_t nfi); 40 | 41 | nfc_device_desc_t *parse_device_desc (int argc, const char *argv[], size_t * szFound); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/mfocGUI/nfc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/nfc.dll -------------------------------------------------------------------------------- /src/mfocGUI/ov.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/ov.ico -------------------------------------------------------------------------------- /src/mfocGUI/ov_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/ov_128.png -------------------------------------------------------------------------------- /src/mfocGUI/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by mfocGUI.rc 4 | // 5 | #define IDI_MAIN_ICON 101 6 | #define IDB_PNG1 102 7 | 8 | // Next default values for new objects 9 | // 10 | #ifdef APSTUDIO_INVOKED 11 | #ifndef APSTUDIO_READONLY_SYMBOLS 12 | #define _APS_NEXT_RESOURCE_VALUE 103 13 | #define _APS_NEXT_COMMAND_VALUE 40001 14 | #define _APS_NEXT_CONTROL_VALUE 1001 15 | #define _APS_NEXT_SYMED_VALUE 101 16 | #endif 17 | #endif 18 | -------------------------------------------------------------------------------- /src/mfocGUI/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/sqlite3.dll -------------------------------------------------------------------------------- /src/mfocGUI/stations.db3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/mfocGUI/stations.db3 -------------------------------------------------------------------------------- /src/sqlite/sqlite3.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | sqlite3_aggregate_context 3 | sqlite3_aggregate_count 4 | sqlite3_auto_extension 5 | sqlite3_backup_finish 6 | sqlite3_backup_init 7 | sqlite3_backup_pagecount 8 | sqlite3_backup_remaining 9 | sqlite3_backup_step 10 | sqlite3_bind_blob 11 | sqlite3_bind_double 12 | sqlite3_bind_int 13 | sqlite3_bind_int64 14 | sqlite3_bind_null 15 | sqlite3_bind_parameter_count 16 | sqlite3_bind_parameter_index 17 | sqlite3_bind_parameter_name 18 | sqlite3_bind_text 19 | sqlite3_bind_text16 20 | sqlite3_bind_value 21 | sqlite3_bind_zeroblob 22 | sqlite3_blob_bytes 23 | sqlite3_blob_close 24 | sqlite3_blob_open 25 | sqlite3_blob_read 26 | sqlite3_blob_write 27 | sqlite3_busy_handler 28 | sqlite3_busy_timeout 29 | sqlite3_changes 30 | sqlite3_clear_bindings 31 | sqlite3_close 32 | sqlite3_collation_needed 33 | sqlite3_collation_needed16 34 | sqlite3_column_blob 35 | sqlite3_column_bytes 36 | sqlite3_column_bytes16 37 | sqlite3_column_count 38 | sqlite3_column_database_name 39 | sqlite3_column_database_name16 40 | sqlite3_column_decltype 41 | sqlite3_column_decltype16 42 | sqlite3_column_double 43 | sqlite3_column_int 44 | sqlite3_column_int64 45 | sqlite3_column_name 46 | sqlite3_column_name16 47 | sqlite3_column_origin_name 48 | sqlite3_column_origin_name16 49 | sqlite3_column_table_name 50 | sqlite3_column_table_name16 51 | sqlite3_column_text 52 | sqlite3_column_text16 53 | sqlite3_column_type 54 | sqlite3_column_value 55 | sqlite3_commit_hook 56 | sqlite3_compileoption_get 57 | sqlite3_compileoption_used 58 | sqlite3_complete 59 | sqlite3_complete16 60 | sqlite3_config 61 | sqlite3_context_db_handle 62 | sqlite3_create_collation 63 | sqlite3_create_collation16 64 | sqlite3_create_collation_v2 65 | sqlite3_create_function 66 | sqlite3_create_function16 67 | sqlite3_create_function_v2 68 | sqlite3_create_module 69 | sqlite3_create_module_v2 70 | sqlite3_data_count 71 | sqlite3_db_config 72 | sqlite3_db_handle 73 | sqlite3_db_mutex 74 | sqlite3_db_status 75 | sqlite3_declare_vtab 76 | sqlite3_enable_load_extension 77 | sqlite3_enable_shared_cache 78 | sqlite3_errcode 79 | sqlite3_errmsg 80 | sqlite3_errmsg16 81 | sqlite3_exec 82 | sqlite3_expired 83 | sqlite3_extended_errcode 84 | sqlite3_extended_result_codes 85 | sqlite3_file_control 86 | sqlite3_finalize 87 | sqlite3_free 88 | sqlite3_free_table 89 | sqlite3_get_autocommit 90 | sqlite3_get_auxdata 91 | sqlite3_get_table 92 | sqlite3_global_recover 93 | sqlite3_initialize 94 | sqlite3_interrupt 95 | sqlite3_last_insert_rowid 96 | sqlite3_libversion 97 | sqlite3_libversion_number 98 | sqlite3_limit 99 | sqlite3_load_extension 100 | sqlite3_log 101 | sqlite3_malloc 102 | sqlite3_memory_alarm 103 | sqlite3_memory_highwater 104 | sqlite3_memory_used 105 | sqlite3_mprintf 106 | sqlite3_mutex_alloc 107 | sqlite3_mutex_enter 108 | sqlite3_mutex_free 109 | sqlite3_mutex_leave 110 | sqlite3_mutex_try 111 | sqlite3_next_stmt 112 | sqlite3_open 113 | sqlite3_open16 114 | sqlite3_open_v2 115 | sqlite3_os_end 116 | sqlite3_os_init 117 | sqlite3_overload_function 118 | sqlite3_prepare 119 | sqlite3_prepare16 120 | sqlite3_prepare16_v2 121 | sqlite3_prepare_v2 122 | sqlite3_profile 123 | sqlite3_progress_handler 124 | sqlite3_randomness 125 | sqlite3_realloc 126 | sqlite3_release_memory 127 | sqlite3_reset 128 | sqlite3_reset_auto_extension 129 | sqlite3_result_blob 130 | sqlite3_result_double 131 | sqlite3_result_error 132 | sqlite3_result_error16 133 | sqlite3_result_error_code 134 | sqlite3_result_error_nomem 135 | sqlite3_result_error_toobig 136 | sqlite3_result_int 137 | sqlite3_result_int64 138 | sqlite3_result_null 139 | sqlite3_result_text 140 | sqlite3_result_text16 141 | sqlite3_result_text16be 142 | sqlite3_result_text16le 143 | sqlite3_result_value 144 | sqlite3_result_zeroblob 145 | sqlite3_rollback_hook 146 | sqlite3_rtree_geometry_callback 147 | sqlite3_set_authorizer 148 | sqlite3_set_auxdata 149 | sqlite3_shutdown 150 | sqlite3_sleep 151 | sqlite3_snprintf 152 | sqlite3_soft_heap_limit 153 | sqlite3_soft_heap_limit64 154 | sqlite3_sourceid 155 | sqlite3_sql 156 | sqlite3_status 157 | sqlite3_step 158 | sqlite3_stmt_status 159 | sqlite3_strnicmp 160 | sqlite3_table_column_metadata 161 | sqlite3_test_control 162 | sqlite3_thread_cleanup 163 | sqlite3_threadsafe 164 | sqlite3_total_changes 165 | sqlite3_trace 166 | sqlite3_transfer_bindings 167 | sqlite3_update_hook 168 | sqlite3_user_data 169 | sqlite3_value_blob 170 | sqlite3_value_bytes 171 | sqlite3_value_bytes16 172 | sqlite3_value_double 173 | sqlite3_value_int 174 | sqlite3_value_int64 175 | sqlite3_value_numeric_type 176 | sqlite3_value_text 177 | sqlite3_value_text16 178 | sqlite3_value_text16be 179 | sqlite3_value_text16le 180 | sqlite3_value_type 181 | sqlite3_version 182 | sqlite3_vfs_find 183 | sqlite3_vfs_register 184 | sqlite3_vfs_unregister 185 | sqlite3_vmprintf 186 | sqlite3_wal_autocheckpoint 187 | sqlite3_wal_checkpoint 188 | sqlite3_wal_hook 189 | sqlite3_win32_mbcs_to_utf8 190 | -------------------------------------------------------------------------------- /src/sqlite/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/sqlite/sqlite3.dll -------------------------------------------------------------------------------- /src/sqlite/sqlite3.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/sqlite/sqlite3.exp -------------------------------------------------------------------------------- /src/sqlite/sqlite3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/src/sqlite/sqlite3.lib -------------------------------------------------------------------------------- /src/sqlite/sqlite3ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 2006 June 7 3 | ** 4 | ** The author disclaims copyright to this source code. In place of 5 | ** a legal notice, here is a blessing: 6 | ** 7 | ** May you do good and not evil. 8 | ** May you find forgiveness for yourself and forgive others. 9 | ** May you share freely, never taking more than you give. 10 | ** 11 | ************************************************************************* 12 | ** This header file defines the SQLite interface for use by 13 | ** shared libraries that want to be imported as extensions into 14 | ** an SQLite instance. Shared libraries that intend to be loaded 15 | ** as extensions by SQLite should #include this file instead of 16 | ** sqlite3.h. 17 | */ 18 | #ifndef _SQLITE3EXT_H_ 19 | #define _SQLITE3EXT_H_ 20 | #include "sqlite3.h" 21 | 22 | typedef struct sqlite3_api_routines sqlite3_api_routines; 23 | 24 | /* 25 | ** The following structure holds pointers to all of the SQLite API 26 | ** routines. 27 | ** 28 | ** WARNING: In order to maintain backwards compatibility, add new 29 | ** interfaces to the end of this structure only. If you insert new 30 | ** interfaces in the middle of this structure, then older different 31 | ** versions of SQLite will not be able to load each others' shared 32 | ** libraries! 33 | */ 34 | struct sqlite3_api_routines { 35 | void * (*aggregate_context)(sqlite3_context*,int nBytes); 36 | int (*aggregate_count)(sqlite3_context*); 37 | int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*)); 38 | int (*bind_double)(sqlite3_stmt*,int,double); 39 | int (*bind_int)(sqlite3_stmt*,int,int); 40 | int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64); 41 | int (*bind_null)(sqlite3_stmt*,int); 42 | int (*bind_parameter_count)(sqlite3_stmt*); 43 | int (*bind_parameter_index)(sqlite3_stmt*,const char*zName); 44 | const char * (*bind_parameter_name)(sqlite3_stmt*,int); 45 | int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*)); 46 | int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*)); 47 | int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*); 48 | int (*busy_handler)(sqlite3*,int(*)(void*,int),void*); 49 | int (*busy_timeout)(sqlite3*,int ms); 50 | int (*changes)(sqlite3*); 51 | int (*close)(sqlite3*); 52 | int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,int eTextRep,const char*)); 53 | int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,int eTextRep,const void*)); 54 | const void * (*column_blob)(sqlite3_stmt*,int iCol); 55 | int (*column_bytes)(sqlite3_stmt*,int iCol); 56 | int (*column_bytes16)(sqlite3_stmt*,int iCol); 57 | int (*column_count)(sqlite3_stmt*pStmt); 58 | const char * (*column_database_name)(sqlite3_stmt*,int); 59 | const void * (*column_database_name16)(sqlite3_stmt*,int); 60 | const char * (*column_decltype)(sqlite3_stmt*,int i); 61 | const void * (*column_decltype16)(sqlite3_stmt*,int); 62 | double (*column_double)(sqlite3_stmt*,int iCol); 63 | int (*column_int)(sqlite3_stmt*,int iCol); 64 | sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol); 65 | const char * (*column_name)(sqlite3_stmt*,int); 66 | const void * (*column_name16)(sqlite3_stmt*,int); 67 | const char * (*column_origin_name)(sqlite3_stmt*,int); 68 | const void * (*column_origin_name16)(sqlite3_stmt*,int); 69 | const char * (*column_table_name)(sqlite3_stmt*,int); 70 | const void * (*column_table_name16)(sqlite3_stmt*,int); 71 | const unsigned char * (*column_text)(sqlite3_stmt*,int iCol); 72 | const void * (*column_text16)(sqlite3_stmt*,int iCol); 73 | int (*column_type)(sqlite3_stmt*,int iCol); 74 | sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol); 75 | void * (*commit_hook)(sqlite3*,int(*)(void*),void*); 76 | int (*complete)(const char*sql); 77 | int (*complete16)(const void*sql); 78 | int (*create_collation)(sqlite3*,const char*,int,void*,int(*)(void*,int,const void*,int,const void*)); 79 | int (*create_collation16)(sqlite3*,const void*,int,void*,int(*)(void*,int,const void*,int,const void*)); 80 | int (*create_function)(sqlite3*,const char*,int,int,void*,void (*xFunc)(sqlite3_context*,int,sqlite3_value**),void (*xStep)(sqlite3_context*,int,sqlite3_value**),void (*xFinal)(sqlite3_context*)); 81 | int (*create_function16)(sqlite3*,const void*,int,int,void*,void (*xFunc)(sqlite3_context*,int,sqlite3_value**),void (*xStep)(sqlite3_context*,int,sqlite3_value**),void (*xFinal)(sqlite3_context*)); 82 | int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); 83 | int (*data_count)(sqlite3_stmt*pStmt); 84 | sqlite3 * (*db_handle)(sqlite3_stmt*); 85 | int (*declare_vtab)(sqlite3*,const char*); 86 | int (*enable_shared_cache)(int); 87 | int (*errcode)(sqlite3*db); 88 | const char * (*errmsg)(sqlite3*); 89 | const void * (*errmsg16)(sqlite3*); 90 | int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**); 91 | int (*expired)(sqlite3_stmt*); 92 | int (*finalize)(sqlite3_stmt*pStmt); 93 | void (*free)(void*); 94 | void (*free_table)(char**result); 95 | int (*get_autocommit)(sqlite3*); 96 | void * (*get_auxdata)(sqlite3_context*,int); 97 | int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**); 98 | int (*global_recover)(void); 99 | void (*interruptx)(sqlite3*); 100 | sqlite_int64 (*last_insert_rowid)(sqlite3*); 101 | const char * (*libversion)(void); 102 | int (*libversion_number)(void); 103 | void *(*malloc)(int); 104 | char * (*mprintf)(const char*,...); 105 | int (*open)(const char*,sqlite3**); 106 | int (*open16)(const void*,sqlite3**); 107 | int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 108 | int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 109 | void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); 110 | void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); 111 | void *(*realloc)(void*,int); 112 | int (*reset)(sqlite3_stmt*pStmt); 113 | void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); 114 | void (*result_double)(sqlite3_context*,double); 115 | void (*result_error)(sqlite3_context*,const char*,int); 116 | void (*result_error16)(sqlite3_context*,const void*,int); 117 | void (*result_int)(sqlite3_context*,int); 118 | void (*result_int64)(sqlite3_context*,sqlite_int64); 119 | void (*result_null)(sqlite3_context*); 120 | void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*)); 121 | void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*)); 122 | void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*)); 123 | void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*)); 124 | void (*result_value)(sqlite3_context*,sqlite3_value*); 125 | void * (*rollback_hook)(sqlite3*,void(*)(void*),void*); 126 | int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,const char*,const char*),void*); 127 | void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*)); 128 | char * (*snprintf)(int,char*,const char*,...); 129 | int (*step)(sqlite3_stmt*); 130 | int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,char const**,char const**,int*,int*,int*); 131 | void (*thread_cleanup)(void); 132 | int (*total_changes)(sqlite3*); 133 | void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); 134 | int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); 135 | void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,sqlite_int64),void*); 136 | void * (*user_data)(sqlite3_context*); 137 | const void * (*value_blob)(sqlite3_value*); 138 | int (*value_bytes)(sqlite3_value*); 139 | int (*value_bytes16)(sqlite3_value*); 140 | double (*value_double)(sqlite3_value*); 141 | int (*value_int)(sqlite3_value*); 142 | sqlite_int64 (*value_int64)(sqlite3_value*); 143 | int (*value_numeric_type)(sqlite3_value*); 144 | const unsigned char * (*value_text)(sqlite3_value*); 145 | const void * (*value_text16)(sqlite3_value*); 146 | const void * (*value_text16be)(sqlite3_value*); 147 | const void * (*value_text16le)(sqlite3_value*); 148 | int (*value_type)(sqlite3_value*); 149 | char *(*vmprintf)(const char*,va_list); 150 | /* Added ??? */ 151 | int (*overload_function)(sqlite3*, const char *zFuncName, int nArg); 152 | /* Added by 3.3.13 */ 153 | int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); 154 | int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); 155 | int (*clear_bindings)(sqlite3_stmt*); 156 | /* Added by 3.4.1 */ 157 | int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,void (*xDestroy)(void *)); 158 | /* Added by 3.5.0 */ 159 | int (*bind_zeroblob)(sqlite3_stmt*,int,int); 160 | int (*blob_bytes)(sqlite3_blob*); 161 | int (*blob_close)(sqlite3_blob*); 162 | int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,int,sqlite3_blob**); 163 | int (*blob_read)(sqlite3_blob*,void*,int,int); 164 | int (*blob_write)(sqlite3_blob*,const void*,int,int); 165 | int (*create_collation_v2)(sqlite3*,const char*,int,void*,int(*)(void*,int,const void*,int,const void*),void(*)(void*)); 166 | int (*file_control)(sqlite3*,const char*,int,void*); 167 | sqlite3_int64 (*memory_highwater)(int); 168 | sqlite3_int64 (*memory_used)(void); 169 | sqlite3_mutex *(*mutex_alloc)(int); 170 | void (*mutex_enter)(sqlite3_mutex*); 171 | void (*mutex_free)(sqlite3_mutex*); 172 | void (*mutex_leave)(sqlite3_mutex*); 173 | int (*mutex_try)(sqlite3_mutex*); 174 | int (*open_v2)(const char*,sqlite3**,int,const char*); 175 | int (*release_memory)(int); 176 | void (*result_error_nomem)(sqlite3_context*); 177 | void (*result_error_toobig)(sqlite3_context*); 178 | int (*sleep)(int); 179 | void (*soft_heap_limit)(int); 180 | sqlite3_vfs *(*vfs_find)(const char*); 181 | int (*vfs_register)(sqlite3_vfs*,int); 182 | int (*vfs_unregister)(sqlite3_vfs*); 183 | int (*xthreadsafe)(void); 184 | void (*result_zeroblob)(sqlite3_context*,int); 185 | void (*result_error_code)(sqlite3_context*,int); 186 | int (*test_control)(int, ...); 187 | void (*randomness)(int,void*); 188 | sqlite3 *(*context_db_handle)(sqlite3_context*); 189 | int (*extended_result_codes)(sqlite3*,int); 190 | int (*limit)(sqlite3*,int,int); 191 | sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); 192 | const char *(*sql)(sqlite3_stmt*); 193 | int (*status)(int,int*,int*,int); 194 | }; 195 | 196 | /* 197 | ** The following macros redefine the API routines so that they are 198 | ** redirected throught the global sqlite3_api structure. 199 | ** 200 | ** This header file is also used by the loadext.c source file 201 | ** (part of the main SQLite library - not an extension) so that 202 | ** it can get access to the sqlite3_api_routines structure 203 | ** definition. But the main library does not want to redefine 204 | ** the API. So the redefinition macros are only valid if the 205 | ** SQLITE_CORE macros is undefined. 206 | */ 207 | #ifndef SQLITE_CORE 208 | #define sqlite3_aggregate_context sqlite3_api->aggregate_context 209 | #ifndef SQLITE_OMIT_DEPRECATED 210 | #define sqlite3_aggregate_count sqlite3_api->aggregate_count 211 | #endif 212 | #define sqlite3_bind_blob sqlite3_api->bind_blob 213 | #define sqlite3_bind_double sqlite3_api->bind_double 214 | #define sqlite3_bind_int sqlite3_api->bind_int 215 | #define sqlite3_bind_int64 sqlite3_api->bind_int64 216 | #define sqlite3_bind_null sqlite3_api->bind_null 217 | #define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count 218 | #define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index 219 | #define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name 220 | #define sqlite3_bind_text sqlite3_api->bind_text 221 | #define sqlite3_bind_text16 sqlite3_api->bind_text16 222 | #define sqlite3_bind_value sqlite3_api->bind_value 223 | #define sqlite3_busy_handler sqlite3_api->busy_handler 224 | #define sqlite3_busy_timeout sqlite3_api->busy_timeout 225 | #define sqlite3_changes sqlite3_api->changes 226 | #define sqlite3_close sqlite3_api->close 227 | #define sqlite3_collation_needed sqlite3_api->collation_needed 228 | #define sqlite3_collation_needed16 sqlite3_api->collation_needed16 229 | #define sqlite3_column_blob sqlite3_api->column_blob 230 | #define sqlite3_column_bytes sqlite3_api->column_bytes 231 | #define sqlite3_column_bytes16 sqlite3_api->column_bytes16 232 | #define sqlite3_column_count sqlite3_api->column_count 233 | #define sqlite3_column_database_name sqlite3_api->column_database_name 234 | #define sqlite3_column_database_name16 sqlite3_api->column_database_name16 235 | #define sqlite3_column_decltype sqlite3_api->column_decltype 236 | #define sqlite3_column_decltype16 sqlite3_api->column_decltype16 237 | #define sqlite3_column_double sqlite3_api->column_double 238 | #define sqlite3_column_int sqlite3_api->column_int 239 | #define sqlite3_column_int64 sqlite3_api->column_int64 240 | #define sqlite3_column_name sqlite3_api->column_name 241 | #define sqlite3_column_name16 sqlite3_api->column_name16 242 | #define sqlite3_column_origin_name sqlite3_api->column_origin_name 243 | #define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16 244 | #define sqlite3_column_table_name sqlite3_api->column_table_name 245 | #define sqlite3_column_table_name16 sqlite3_api->column_table_name16 246 | #define sqlite3_column_text sqlite3_api->column_text 247 | #define sqlite3_column_text16 sqlite3_api->column_text16 248 | #define sqlite3_column_type sqlite3_api->column_type 249 | #define sqlite3_column_value sqlite3_api->column_value 250 | #define sqlite3_commit_hook sqlite3_api->commit_hook 251 | #define sqlite3_complete sqlite3_api->complete 252 | #define sqlite3_complete16 sqlite3_api->complete16 253 | #define sqlite3_create_collation sqlite3_api->create_collation 254 | #define sqlite3_create_collation16 sqlite3_api->create_collation16 255 | #define sqlite3_create_function sqlite3_api->create_function 256 | #define sqlite3_create_function16 sqlite3_api->create_function16 257 | #define sqlite3_create_module sqlite3_api->create_module 258 | #define sqlite3_create_module_v2 sqlite3_api->create_module_v2 259 | #define sqlite3_data_count sqlite3_api->data_count 260 | #define sqlite3_db_handle sqlite3_api->db_handle 261 | #define sqlite3_declare_vtab sqlite3_api->declare_vtab 262 | #define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache 263 | #define sqlite3_errcode sqlite3_api->errcode 264 | #define sqlite3_errmsg sqlite3_api->errmsg 265 | #define sqlite3_errmsg16 sqlite3_api->errmsg16 266 | #define sqlite3_exec sqlite3_api->exec 267 | #ifndef SQLITE_OMIT_DEPRECATED 268 | #define sqlite3_expired sqlite3_api->expired 269 | #endif 270 | #define sqlite3_finalize sqlite3_api->finalize 271 | #define sqlite3_free sqlite3_api->free 272 | #define sqlite3_free_table sqlite3_api->free_table 273 | #define sqlite3_get_autocommit sqlite3_api->get_autocommit 274 | #define sqlite3_get_auxdata sqlite3_api->get_auxdata 275 | #define sqlite3_get_table sqlite3_api->get_table 276 | #ifndef SQLITE_OMIT_DEPRECATED 277 | #define sqlite3_global_recover sqlite3_api->global_recover 278 | #endif 279 | #define sqlite3_interrupt sqlite3_api->interruptx 280 | #define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid 281 | #define sqlite3_libversion sqlite3_api->libversion 282 | #define sqlite3_libversion_number sqlite3_api->libversion_number 283 | #define sqlite3_malloc sqlite3_api->malloc 284 | #define sqlite3_mprintf sqlite3_api->mprintf 285 | #define sqlite3_open sqlite3_api->open 286 | #define sqlite3_open16 sqlite3_api->open16 287 | #define sqlite3_prepare sqlite3_api->prepare 288 | #define sqlite3_prepare16 sqlite3_api->prepare16 289 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 290 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 291 | #define sqlite3_profile sqlite3_api->profile 292 | #define sqlite3_progress_handler sqlite3_api->progress_handler 293 | #define sqlite3_realloc sqlite3_api->realloc 294 | #define sqlite3_reset sqlite3_api->reset 295 | #define sqlite3_result_blob sqlite3_api->result_blob 296 | #define sqlite3_result_double sqlite3_api->result_double 297 | #define sqlite3_result_error sqlite3_api->result_error 298 | #define sqlite3_result_error16 sqlite3_api->result_error16 299 | #define sqlite3_result_int sqlite3_api->result_int 300 | #define sqlite3_result_int64 sqlite3_api->result_int64 301 | #define sqlite3_result_null sqlite3_api->result_null 302 | #define sqlite3_result_text sqlite3_api->result_text 303 | #define sqlite3_result_text16 sqlite3_api->result_text16 304 | #define sqlite3_result_text16be sqlite3_api->result_text16be 305 | #define sqlite3_result_text16le sqlite3_api->result_text16le 306 | #define sqlite3_result_value sqlite3_api->result_value 307 | #define sqlite3_rollback_hook sqlite3_api->rollback_hook 308 | #define sqlite3_set_authorizer sqlite3_api->set_authorizer 309 | #define sqlite3_set_auxdata sqlite3_api->set_auxdata 310 | #define sqlite3_snprintf sqlite3_api->snprintf 311 | #define sqlite3_step sqlite3_api->step 312 | #define sqlite3_table_column_metadata sqlite3_api->table_column_metadata 313 | #define sqlite3_thread_cleanup sqlite3_api->thread_cleanup 314 | #define sqlite3_total_changes sqlite3_api->total_changes 315 | #define sqlite3_trace sqlite3_api->trace 316 | #ifndef SQLITE_OMIT_DEPRECATED 317 | #define sqlite3_transfer_bindings sqlite3_api->transfer_bindings 318 | #endif 319 | #define sqlite3_update_hook sqlite3_api->update_hook 320 | #define sqlite3_user_data sqlite3_api->user_data 321 | #define sqlite3_value_blob sqlite3_api->value_blob 322 | #define sqlite3_value_bytes sqlite3_api->value_bytes 323 | #define sqlite3_value_bytes16 sqlite3_api->value_bytes16 324 | #define sqlite3_value_double sqlite3_api->value_double 325 | #define sqlite3_value_int sqlite3_api->value_int 326 | #define sqlite3_value_int64 sqlite3_api->value_int64 327 | #define sqlite3_value_numeric_type sqlite3_api->value_numeric_type 328 | #define sqlite3_value_text sqlite3_api->value_text 329 | #define sqlite3_value_text16 sqlite3_api->value_text16 330 | #define sqlite3_value_text16be sqlite3_api->value_text16be 331 | #define sqlite3_value_text16le sqlite3_api->value_text16le 332 | #define sqlite3_value_type sqlite3_api->value_type 333 | #define sqlite3_vmprintf sqlite3_api->vmprintf 334 | #define sqlite3_overload_function sqlite3_api->overload_function 335 | #define sqlite3_prepare_v2 sqlite3_api->prepare_v2 336 | #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 337 | #define sqlite3_clear_bindings sqlite3_api->clear_bindings 338 | #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob 339 | #define sqlite3_blob_bytes sqlite3_api->blob_bytes 340 | #define sqlite3_blob_close sqlite3_api->blob_close 341 | #define sqlite3_blob_open sqlite3_api->blob_open 342 | #define sqlite3_blob_read sqlite3_api->blob_read 343 | #define sqlite3_blob_write sqlite3_api->blob_write 344 | #define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 345 | #define sqlite3_file_control sqlite3_api->file_control 346 | #define sqlite3_memory_highwater sqlite3_api->memory_highwater 347 | #define sqlite3_memory_used sqlite3_api->memory_used 348 | #define sqlite3_mutex_alloc sqlite3_api->mutex_alloc 349 | #define sqlite3_mutex_enter sqlite3_api->mutex_enter 350 | #define sqlite3_mutex_free sqlite3_api->mutex_free 351 | #define sqlite3_mutex_leave sqlite3_api->mutex_leave 352 | #define sqlite3_mutex_try sqlite3_api->mutex_try 353 | #define sqlite3_open_v2 sqlite3_api->open_v2 354 | #define sqlite3_release_memory sqlite3_api->release_memory 355 | #define sqlite3_result_error_nomem sqlite3_api->result_error_nomem 356 | #define sqlite3_result_error_toobig sqlite3_api->result_error_toobig 357 | #define sqlite3_sleep sqlite3_api->sleep 358 | #define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit 359 | #define sqlite3_vfs_find sqlite3_api->vfs_find 360 | #define sqlite3_vfs_register sqlite3_api->vfs_register 361 | #define sqlite3_vfs_unregister sqlite3_api->vfs_unregister 362 | #define sqlite3_threadsafe sqlite3_api->xthreadsafe 363 | #define sqlite3_result_zeroblob sqlite3_api->result_zeroblob 364 | #define sqlite3_result_error_code sqlite3_api->result_error_code 365 | #define sqlite3_test_control sqlite3_api->test_control 366 | #define sqlite3_randomness sqlite3_api->randomness 367 | #define sqlite3_context_db_handle sqlite3_api->context_db_handle 368 | #define sqlite3_extended_result_codes sqlite3_api->extended_result_codes 369 | #define sqlite3_limit sqlite3_api->limit 370 | #define sqlite3_next_stmt sqlite3_api->next_stmt 371 | #define sqlite3_sql sqlite3_api->sql 372 | #define sqlite3_status sqlite3_api->status 373 | #endif /* SQLITE_CORE */ 374 | 375 | #define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0; 376 | #define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v; 377 | 378 | #endif /* _SQLITE3EXT_H_ */ 379 | -------------------------------------------------------------------------------- /untitled folder/20160806193711.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/untitled folder/20160806193711.png -------------------------------------------------------------------------------- /untitled folder/mfocGUI_v29.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/untitled folder/mfocGUI_v29.rar -------------------------------------------------------------------------------- /untitled folder/mfocGUI_v30_For_PN532.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NullYing/mfocGUI/9620aefd7a0cfd085618926d5500f54f959204ea/untitled folder/mfocGUI_v30_For_PN532.rar --------------------------------------------------------------------------------