├── COMPILING.TXT ├── CopyClass.cbproj ├── CopyClass.cpp ├── CopyClass.res ├── CopyClass_Icon.ico ├── FAQ.TXT ├── HOWTO.TXT ├── LICENSE.TXT ├── README.md ├── des.c ├── des.h ├── iClass_Capture.PNG ├── lib ├── scardsyn.def ├── scardsyn.dll └── scardsyn.lib ├── uMain.cpp ├── uMain.dfm └── uMain.h /COMPILING.TXT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/iClassReader/cf5c1e3d0ad328f606cc1c8e68e1e63b29493601/COMPILING.TXT -------------------------------------------------------------------------------- /CopyClass.cbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {CAFD0BD4-6AD1-4C08-842F-C1F38DF27A69} 4 | 15.3 5 | CopyClass.cpp 6 | True 7 | Release 8 | Application 9 | VCL 10 | True 11 | Win32 12 | 1 13 | 14 | 15 | true 16 | 17 | 18 | true 19 | Base 20 | true 21 | 22 | 23 | true 24 | Base 25 | true 26 | 27 | 28 | true 29 | Base 30 | true 31 | 32 | 33 | true 34 | Cfg_1 35 | true 36 | true 37 | 38 | 39 | true 40 | Cfg_1 41 | true 42 | true 43 | 44 | 45 | true 46 | Base 47 | true 48 | 49 | 50 | true 51 | Cfg_2 52 | true 53 | true 54 | 55 | 56 | true 57 | Cfg_2 58 | true 59 | true 60 | 61 | 62 | 1031 63 | CompanyName=;FileDescription=;FileVersion=0.1.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= 64 | true 65 | Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 66 | 0 67 | 1 68 | rtl.lib;vcl.lib 69 | vclimg.bpi;vcl.bpi;vclx.bpi;dbrtl.bpi;Rave90VCL.bpi;bdertl.bpi;rtl.bpi;bcbie.bpi;xmlrtl.bpi;vclactnband.bpi;bcbsmp.bpi;svnui.bpi;svn.bpi;TeeUI.bpi;TeeDB.bpi;Tee.bpi;vcldb.bpi;vcldbx.bpi;vcltouch.bpi;dsnap.bpi;dsnapcon.bpi;vclib.bpi;ibxpress.bpi;adortl.bpi;IndyCore.bpi;IndySystem.bpi;IndyProtocols.bpi;inet.bpi;intrawebdb_110_150.bpi;Intraweb_110_150.bpi;vclie.bpi;websnap.bpi;webdsnap.bpi;inetdb.bpi;inetdbbde.bpi;inetdbxpress.bpi;soaprtl.bpi;vclribbon.bpi;dbexpress.bpi;DbxCommonDriver.bpi;DataSnapIndy10ServerTransport.bpi;DataSnapProviderClient.bpi;DataSnapClient.bpi;dbxcds.bpi;DbxClientDriver.bpi;DataSnapServer.bpi;AzureCloud.bpi;DBXInterBaseDriver.bpi;DBXMySQLDriver.bpi;DBXFirebirdDriver.bpi;DBXSybaseASEDriver.bpi;DBXSybaseASADriver.bpi;DBXOracleDriver.bpi;DBXMSSQLDriver.bpi;DBXInformixDriver.bpi;DBXDb2Driver.bpi;CodeSiteExpressVcl.bpi;$(PackageImports) 70 | true 71 | CppVCLApplication 72 | <_TCHARMapping>wchar_t 73 | rtl.lib;vcl.lib 74 | exe 75 | JPHNE 76 | true 77 | .\$(Config)\$(Platform) 78 | .\$(Config)\$(Platform) 79 | false 80 | true 81 | true 82 | $(BDSLIB)\$(PLATFORM)\release\$(LANGDIR);$(ILINK_TranslatedLibraryPath) 83 | 84 | 85 | $(BDSINCLUDE)\windows\vcl;$(IncludePath) 86 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 87 | 1033 88 | CopyClass_Icon.ico 89 | $(BDS)\bin\default_app.manifest 90 | 91 | 92 | $(BDSINCLUDE)\windows\vcl;$(IncludePath) 93 | CopyClass_Icon.ico 94 | 95 | 96 | false 97 | true 98 | false 99 | true 100 | false 101 | None 102 | DEBUG 103 | true 104 | true 105 | true 106 | true 107 | Full 108 | true 109 | $(BDSLIB)\$(PLATFORM)\debug;$(ILINK_LibraryPath) 110 | $(BDSLIB)\$(PLATFORM)\debug\$(LANGDIR);$(ILINK_TranslatedLibraryPath) 111 | 112 | 113 | _DEBUG;$(Defines) 114 | 115 | 116 | _DEBUG;$(Defines) 117 | 118 | 119 | false 120 | None 121 | 122 | 123 | NDEBUG;$(Defines) 124 | 125 | 126 | NDEBUG;$(Defines) 127 | 128 | 129 | 130 | 0 131 | 132 | 133 | 1 134 | 135 | 136 | 3 137 | 138 | 139 | 4 140 | 141 | 142 |
FM_Main
143 | uMain.h 144 | 2 145 |
146 | 147 | 148 | Cfg_2 149 | Base 150 | 151 | 152 | Base 153 | 154 | 155 | Cfg_1 156 | Base 157 | 158 |
159 | 160 | 161 | 162 | CPlusPlusBuilder.Personality.12 163 | CppVCLApplication 164 | 165 | 166 | 167 | CopyClass.cpp 168 | 169 | 170 | True 171 | False 172 | 0 173 | 1 174 | 0 175 | 0 176 | False 177 | False 178 | False 179 | False 180 | False 181 | 1031 182 | 1252 183 | 184 | 185 | 186 | 187 | 0.1.0.0 188 | 189 | 190 | 191 | 192 | 193 | 1.0.0.0 194 | 195 | 196 | 197 | False 198 | True 199 | True 200 | 201 | 202 | Embarcadero C++Builder Office 2000 Servers Package 203 | Embarcadero C++Builder Office XP Servers Package 204 | 205 | 206 | 207 | True 208 | False 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 1 244 | .dylib 245 | 246 | 247 | 0 248 | .bpl 249 | 250 | 251 | Contents\MacOS 252 | 1 253 | .dylib 254 | 255 | 256 | 1 257 | .dylib 258 | 259 | 260 | 261 | 262 | 1 263 | .dylib 264 | 265 | 266 | 0 267 | .dll;.bpl 268 | 269 | 270 | Contents\MacOS 271 | 1 272 | .dylib 273 | 274 | 275 | 1 276 | .dylib 277 | 278 | 279 | 280 | 281 | 1 282 | 283 | 284 | 1 285 | 286 | 287 | 288 | 289 | Contents 290 | 1 291 | 292 | 293 | 294 | 295 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 296 | 1 297 | 298 | 299 | 300 | 301 | 1 302 | 303 | 304 | 1 305 | 306 | 307 | 308 | 309 | Contents 310 | 1 311 | 312 | 313 | 314 | 315 | library\lib\armeabi 316 | 1 317 | 318 | 319 | 320 | 321 | 1 322 | 323 | 324 | 1 325 | 326 | 327 | 328 | 329 | res\drawable-xhdpi 330 | 1 331 | 332 | 333 | 334 | 335 | 1 336 | 337 | 338 | 1 339 | 340 | 341 | 342 | 343 | res\drawable-xxhdpi 344 | 1 345 | 346 | 347 | 348 | 349 | Contents\MacOS 350 | 1 351 | 352 | 353 | 1 354 | 355 | 356 | 0 357 | 358 | 359 | 360 | 361 | Contents\MacOS 362 | 1 363 | .framework 364 | 365 | 366 | 0 367 | 368 | 369 | 370 | 371 | 1 372 | 373 | 374 | 375 | 376 | Contents\MacOS 377 | 1 378 | 379 | 380 | 1 381 | 382 | 383 | Contents\MacOS 384 | 0 385 | 386 | 387 | 388 | 389 | classes 390 | 1 391 | 392 | 393 | 394 | 395 | 1 396 | 397 | 398 | 399 | 400 | 1 401 | 402 | 403 | 1 404 | 405 | 406 | 407 | 408 | 1 409 | 410 | 411 | 412 | 413 | res\drawable 414 | 1 415 | 416 | 417 | 418 | 419 | Contents\Resources 420 | 1 421 | 422 | 423 | 424 | 425 | 1 426 | 427 | 428 | 429 | 430 | 1 431 | 432 | 433 | 1 434 | 435 | 436 | 437 | 438 | 1 439 | 440 | 441 | library\lib\armeabi 442 | 1 443 | 444 | 445 | 0 446 | 447 | 448 | Contents\MacOS 449 | 1 450 | 451 | 452 | 1 453 | 454 | 455 | 456 | 457 | 0 458 | 459 | 460 | 0 461 | 462 | 463 | 0 464 | 465 | 466 | Contents\MacOS 467 | 0 468 | 469 | 470 | 0 471 | 472 | 473 | 474 | 475 | 1 476 | 477 | 478 | 1 479 | 480 | 481 | 482 | 483 | res\drawable-ldpi 484 | 1 485 | 486 | 487 | 488 | 489 | 1 490 | 491 | 492 | 1 493 | 494 | 495 | 496 | 497 | res\drawable-mdpi 498 | 1 499 | 500 | 501 | 502 | 503 | res\drawable-hdpi 504 | 1 505 | 506 | 507 | 508 | 509 | 1 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | False 520 | 521 | 12 522 | 523 | 524 |
525 | -------------------------------------------------------------------------------- /CopyClass.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #pragma hdrstop 4 | #include 5 | //--------------------------------------------------------------------------- 6 | USEFORM ("uMain.cpp", FM_Main); 7 | //--------------------------------------------------------------------------- 8 | WINAPI 9 | _tWinMain (HINSTANCE, HINSTANCE, LPTSTR, int) 10 | { 11 | try 12 | { 13 | Application->Initialize (); 14 | Application->MainFormOnTaskBar = true; 15 | Application->Title = "CopyClass"; 16 | Application->CreateForm (__classid (TFM_Main), &FM_Main); 17 | Application->Run (); 18 | } 19 | catch (Exception & exception) 20 | { 21 | Application->ShowException (&exception); 22 | } 23 | catch ( ...) 24 | { 25 | try 26 | { 27 | throw Exception (""); 28 | } 29 | catch (Exception & exception) 30 | { 31 | Application->ShowException (&exception); 32 | } 33 | } 34 | return 0; 35 | } 36 | //--------------------------------------------------------------------------- 37 | -------------------------------------------------------------------------------- /CopyClass.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/iClassReader/cf5c1e3d0ad328f606cc1c8e68e1e63b29493601/CopyClass.res -------------------------------------------------------------------------------- /CopyClass_Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/iClassReader/cf5c1e3d0ad328f606cc1c8e68e1e63b29493601/CopyClass_Icon.ico -------------------------------------------------------------------------------- /FAQ.TXT: -------------------------------------------------------------------------------- 1 | FAQ 2 | ===== 3 | 4 | 1. It does not work? 5 | It does work I guarantee, I just stripped out HID's proprietary MASTER KEYS. 6 | 7 | If you get the error popup "Can not retrieve list of readers", its because you need the OmniKey 5xxx 8 | Reader for this software to correctly operate. Plug in the Reader, then execute the program. 9 | 10 | If you get the error "scardsyn.dll is missing", there is a copy in the lib/ folder, copy this dll 11 | to the same location as the compiled executable. 12 | 13 | 2. Why did you remove the MASTER KEYS? 14 | HID Global are rather protective over their MASTER KEYS, they dont want them publically published. 15 | 16 | 3. Where can I get the MASTER KEYS? 17 | Unfortunately, your going to have to either hack a RW300 Rev A Reader, or Sign HID Globals' NDA. 18 | 19 | 4. Can you Give me the MASTER KEYS, or can I buy them from you? 20 | Simple answer: NO. 21 | 22 | 5. I have the MASTER KEYS where do I put them in the code? 23 | Theres a place holder for the keys in uMain.cpp, simply replace the null placeholder with the MASTER KEYS 24 | and recompile. 25 | 26 | 6. How can I write to iClass Cards? 27 | This software only reads the cards, and dissects fields to help you get a better understanding of the 28 | formatting and structure. Currently the software has no write operations. 29 | -------------------------------------------------------------------------------- /HOWTO.TXT: -------------------------------------------------------------------------------- 1 | HOWTO 2 | ======= 3 | Once all the MASTER Keys have been added and the software has been compiled; you can read & decrypt iClass Cards. 4 | 5 | You also need an Omnikey 5xxx Reader. 6 | 7 | Plug in the Reader. 8 | Execute CopyClass.exe 9 | Enter Authentication Key (or choose default key for blank cards) 10 | Click Authenticate 11 | If authentication was sucessfull; Either: 12 | 1) Read Card 13 | 2) Choose Book Number 14 | Or try another Authentication Key. 15 | 16 | Keys 17 | ----- 18 | Kd = Debit Key (Application 1) 19 | Kc = Credit Key (Application 2) -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | License 2 | ======== 3 | 4 | Copyright (c) 2014 Pentura, (Andy Davies) 5 | All rights reserved. 6 | 7 | This program was built ontop of the original code by Meriac 2010, 8 | Available original source http://www.openpcd.org/git-view/iclass-security/ 9 | 10 | The original code has no license information, so this software is provided AS-IS. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions 14 | are met: 15 | 1. Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 2. Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 25 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | iClassReader 2 | ============ 3 | 4 | Improved version. Based off original CopyClass Code From Meriac http://www.openpcd.org/HID_iClass_demystified 5 | 6 | ![iClass Capture](iClass_Capture.PNG "CopyClass") 7 | -------------------------------------------------------------------------------- /des.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FIPS-46-3 compliant 3DES implementation 3 | * 4 | * Copyright (C) 2001-2003 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #include "memory.h" 22 | #include "des.h" 23 | 24 | /* the eight DES S-boxes */ 25 | 26 | static uint32 SB1[64] = { 27 | 0x01010400, 0x00000000, 0x00010000, 0x01010404, 28 | 0x01010004, 0x00010404, 0x00000004, 0x00010000, 29 | 0x00000400, 0x01010400, 0x01010404, 0x00000400, 30 | 0x01000404, 0x01010004, 0x01000000, 0x00000004, 31 | 0x00000404, 0x01000400, 0x01000400, 0x00010400, 32 | 0x00010400, 0x01010000, 0x01010000, 0x01000404, 33 | 0x00010004, 0x01000004, 0x01000004, 0x00010004, 34 | 0x00000000, 0x00000404, 0x00010404, 0x01000000, 35 | 0x00010000, 0x01010404, 0x00000004, 0x01010000, 36 | 0x01010400, 0x01000000, 0x01000000, 0x00000400, 37 | 0x01010004, 0x00010000, 0x00010400, 0x01000004, 38 | 0x00000400, 0x00000004, 0x01000404, 0x00010404, 39 | 0x01010404, 0x00010004, 0x01010000, 0x01000404, 40 | 0x01000004, 0x00000404, 0x00010404, 0x01010400, 41 | 0x00000404, 0x01000400, 0x01000400, 0x00000000, 42 | 0x00010004, 0x00010400, 0x00000000, 0x01010004 43 | }; 44 | 45 | static uint32 SB2[64] = { 46 | 0x80108020, 0x80008000, 0x00008000, 0x00108020, 47 | 0x00100000, 0x00000020, 0x80100020, 0x80008020, 48 | 0x80000020, 0x80108020, 0x80108000, 0x80000000, 49 | 0x80008000, 0x00100000, 0x00000020, 0x80100020, 50 | 0x00108000, 0x00100020, 0x80008020, 0x00000000, 51 | 0x80000000, 0x00008000, 0x00108020, 0x80100000, 52 | 0x00100020, 0x80000020, 0x00000000, 0x00108000, 53 | 0x00008020, 0x80108000, 0x80100000, 0x00008020, 54 | 0x00000000, 0x00108020, 0x80100020, 0x00100000, 55 | 0x80008020, 0x80100000, 0x80108000, 0x00008000, 56 | 0x80100000, 0x80008000, 0x00000020, 0x80108020, 57 | 0x00108020, 0x00000020, 0x00008000, 0x80000000, 58 | 0x00008020, 0x80108000, 0x00100000, 0x80000020, 59 | 0x00100020, 0x80008020, 0x80000020, 0x00100020, 60 | 0x00108000, 0x00000000, 0x80008000, 0x00008020, 61 | 0x80000000, 0x80100020, 0x80108020, 0x00108000 62 | }; 63 | 64 | static uint32 SB3[64] = { 65 | 0x00000208, 0x08020200, 0x00000000, 0x08020008, 66 | 0x08000200, 0x00000000, 0x00020208, 0x08000200, 67 | 0x00020008, 0x08000008, 0x08000008, 0x00020000, 68 | 0x08020208, 0x00020008, 0x08020000, 0x00000208, 69 | 0x08000000, 0x00000008, 0x08020200, 0x00000200, 70 | 0x00020200, 0x08020000, 0x08020008, 0x00020208, 71 | 0x08000208, 0x00020200, 0x00020000, 0x08000208, 72 | 0x00000008, 0x08020208, 0x00000200, 0x08000000, 73 | 0x08020200, 0x08000000, 0x00020008, 0x00000208, 74 | 0x00020000, 0x08020200, 0x08000200, 0x00000000, 75 | 0x00000200, 0x00020008, 0x08020208, 0x08000200, 76 | 0x08000008, 0x00000200, 0x00000000, 0x08020008, 77 | 0x08000208, 0x00020000, 0x08000000, 0x08020208, 78 | 0x00000008, 0x00020208, 0x00020200, 0x08000008, 79 | 0x08020000, 0x08000208, 0x00000208, 0x08020000, 80 | 0x00020208, 0x00000008, 0x08020008, 0x00020200 81 | }; 82 | 83 | static uint32 SB4[64] = { 84 | 0x00802001, 0x00002081, 0x00002081, 0x00000080, 85 | 0x00802080, 0x00800081, 0x00800001, 0x00002001, 86 | 0x00000000, 0x00802000, 0x00802000, 0x00802081, 87 | 0x00000081, 0x00000000, 0x00800080, 0x00800001, 88 | 0x00000001, 0x00002000, 0x00800000, 0x00802001, 89 | 0x00000080, 0x00800000, 0x00002001, 0x00002080, 90 | 0x00800081, 0x00000001, 0x00002080, 0x00800080, 91 | 0x00002000, 0x00802080, 0x00802081, 0x00000081, 92 | 0x00800080, 0x00800001, 0x00802000, 0x00802081, 93 | 0x00000081, 0x00000000, 0x00000000, 0x00802000, 94 | 0x00002080, 0x00800080, 0x00800081, 0x00000001, 95 | 0x00802001, 0x00002081, 0x00002081, 0x00000080, 96 | 0x00802081, 0x00000081, 0x00000001, 0x00002000, 97 | 0x00800001, 0x00002001, 0x00802080, 0x00800081, 98 | 0x00002001, 0x00002080, 0x00800000, 0x00802001, 99 | 0x00000080, 0x00800000, 0x00002000, 0x00802080 100 | }; 101 | 102 | static uint32 SB5[64] = { 103 | 0x00000100, 0x02080100, 0x02080000, 0x42000100, 104 | 0x00080000, 0x00000100, 0x40000000, 0x02080000, 105 | 0x40080100, 0x00080000, 0x02000100, 0x40080100, 106 | 0x42000100, 0x42080000, 0x00080100, 0x40000000, 107 | 0x02000000, 0x40080000, 0x40080000, 0x00000000, 108 | 0x40000100, 0x42080100, 0x42080100, 0x02000100, 109 | 0x42080000, 0x40000100, 0x00000000, 0x42000000, 110 | 0x02080100, 0x02000000, 0x42000000, 0x00080100, 111 | 0x00080000, 0x42000100, 0x00000100, 0x02000000, 112 | 0x40000000, 0x02080000, 0x42000100, 0x40080100, 113 | 0x02000100, 0x40000000, 0x42080000, 0x02080100, 114 | 0x40080100, 0x00000100, 0x02000000, 0x42080000, 115 | 0x42080100, 0x00080100, 0x42000000, 0x42080100, 116 | 0x02080000, 0x00000000, 0x40080000, 0x42000000, 117 | 0x00080100, 0x02000100, 0x40000100, 0x00080000, 118 | 0x00000000, 0x40080000, 0x02080100, 0x40000100 119 | }; 120 | 121 | static uint32 SB6[64] = { 122 | 0x20000010, 0x20400000, 0x00004000, 0x20404010, 123 | 0x20400000, 0x00000010, 0x20404010, 0x00400000, 124 | 0x20004000, 0x00404010, 0x00400000, 0x20000010, 125 | 0x00400010, 0x20004000, 0x20000000, 0x00004010, 126 | 0x00000000, 0x00400010, 0x20004010, 0x00004000, 127 | 0x00404000, 0x20004010, 0x00000010, 0x20400010, 128 | 0x20400010, 0x00000000, 0x00404010, 0x20404000, 129 | 0x00004010, 0x00404000, 0x20404000, 0x20000000, 130 | 0x20004000, 0x00000010, 0x20400010, 0x00404000, 131 | 0x20404010, 0x00400000, 0x00004010, 0x20000010, 132 | 0x00400000, 0x20004000, 0x20000000, 0x00004010, 133 | 0x20000010, 0x20404010, 0x00404000, 0x20400000, 134 | 0x00404010, 0x20404000, 0x00000000, 0x20400010, 135 | 0x00000010, 0x00004000, 0x20400000, 0x00404010, 136 | 0x00004000, 0x00400010, 0x20004010, 0x00000000, 137 | 0x20404000, 0x20000000, 0x00400010, 0x20004010 138 | }; 139 | 140 | static uint32 SB7[64] = { 141 | 0x00200000, 0x04200002, 0x04000802, 0x00000000, 142 | 0x00000800, 0x04000802, 0x00200802, 0x04200800, 143 | 0x04200802, 0x00200000, 0x00000000, 0x04000002, 144 | 0x00000002, 0x04000000, 0x04200002, 0x00000802, 145 | 0x04000800, 0x00200802, 0x00200002, 0x04000800, 146 | 0x04000002, 0x04200000, 0x04200800, 0x00200002, 147 | 0x04200000, 0x00000800, 0x00000802, 0x04200802, 148 | 0x00200800, 0x00000002, 0x04000000, 0x00200800, 149 | 0x04000000, 0x00200800, 0x00200000, 0x04000802, 150 | 0x04000802, 0x04200002, 0x04200002, 0x00000002, 151 | 0x00200002, 0x04000000, 0x04000800, 0x00200000, 152 | 0x04200800, 0x00000802, 0x00200802, 0x04200800, 153 | 0x00000802, 0x04000002, 0x04200802, 0x04200000, 154 | 0x00200800, 0x00000000, 0x00000002, 0x04200802, 155 | 0x00000000, 0x00200802, 0x04200000, 0x00000800, 156 | 0x04000002, 0x04000800, 0x00000800, 0x00200002 157 | }; 158 | 159 | static uint32 SB8[64] = { 160 | 0x10001040, 0x00001000, 0x00040000, 0x10041040, 161 | 0x10000000, 0x10001040, 0x00000040, 0x10000000, 162 | 0x00040040, 0x10040000, 0x10041040, 0x00041000, 163 | 0x10041000, 0x00041040, 0x00001000, 0x00000040, 164 | 0x10040000, 0x10000040, 0x10001000, 0x00001040, 165 | 0x00041000, 0x00040040, 0x10040040, 0x10041000, 166 | 0x00001040, 0x00000000, 0x00000000, 0x10040040, 167 | 0x10000040, 0x10001000, 0x00041040, 0x00040000, 168 | 0x00041040, 0x00040000, 0x10041000, 0x00001000, 169 | 0x00000040, 0x10040040, 0x00001000, 0x00041040, 170 | 0x10001000, 0x00000040, 0x10000040, 0x10040000, 171 | 0x10040040, 0x10000000, 0x00040000, 0x10001040, 172 | 0x00000000, 0x10041040, 0x00040040, 0x10000040, 173 | 0x10040000, 0x10001000, 0x10001040, 0x00000000, 174 | 0x10041040, 0x00041000, 0x00041000, 0x00001040, 175 | 0x00001040, 0x00040040, 0x10000000, 0x10041000 176 | }; 177 | 178 | /* PC1: left and right halves bit-swap */ 179 | 180 | static uint32 LHs[16] = { 181 | 0x00000000, 0x00000001, 0x00000100, 0x00000101, 182 | 0x00010000, 0x00010001, 0x00010100, 0x00010101, 183 | 0x01000000, 0x01000001, 0x01000100, 0x01000101, 184 | 0x01010000, 0x01010001, 0x01010100, 0x01010101 185 | }; 186 | 187 | static uint32 RHs[16] = { 188 | 0x00000000, 0x01000000, 0x00010000, 0x01010000, 189 | 0x00000100, 0x01000100, 0x00010100, 0x01010100, 190 | 0x00000001, 0x01000001, 0x00010001, 0x01010001, 191 | 0x00000101, 0x01000101, 0x00010101, 0x01010101, 192 | }; 193 | 194 | /* platform-independant 32-bit integer manipulation macros */ 195 | 196 | #define GET_UINT32(n,b,i) \ 197 | { \ 198 | (n) = ( (uint32) (b)[(i) ] << 24 ) \ 199 | | ( (uint32) (b)[(i) + 1] << 16 ) \ 200 | | ( (uint32) (b)[(i) + 2] << 8 ) \ 201 | | ( (uint32) (b)[(i) + 3] ); \ 202 | } 203 | 204 | #define PUT_UINT32(n,b,i) \ 205 | { \ 206 | (b)[(i) ] = (uint8) ( (n) >> 24 ); \ 207 | (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \ 208 | (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \ 209 | (b)[(i) + 3] = (uint8) ( (n) ); \ 210 | } 211 | 212 | /* Initial Permutation macro */ 213 | 214 | #define DES_IP(X,Y) \ 215 | { \ 216 | T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \ 217 | T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \ 218 | T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \ 219 | T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \ 220 | Y = ((Y << 1) | (Y >> 31)) & 0xFFFFFFFF; \ 221 | T = (X ^ Y) & 0xAAAAAAAA; Y ^= T; X ^= T; \ 222 | X = ((X << 1) | (X >> 31)) & 0xFFFFFFFF; \ 223 | } 224 | 225 | /* Final Permutation macro */ 226 | 227 | #define DES_FP(X,Y) \ 228 | { \ 229 | X = ((X << 31) | (X >> 1)) & 0xFFFFFFFF; \ 230 | T = (X ^ Y) & 0xAAAAAAAA; X ^= T; Y ^= T; \ 231 | Y = ((Y << 31) | (Y >> 1)) & 0xFFFFFFFF; \ 232 | T = ((Y >> 8) ^ X) & 0x00FF00FF; X ^= T; Y ^= (T << 8); \ 233 | T = ((Y >> 2) ^ X) & 0x33333333; X ^= T; Y ^= (T << 2); \ 234 | T = ((X >> 16) ^ Y) & 0x0000FFFF; Y ^= T; X ^= (T << 16); \ 235 | T = ((X >> 4) ^ Y) & 0x0F0F0F0F; Y ^= T; X ^= (T << 4); \ 236 | } 237 | 238 | /* DES round macro */ 239 | 240 | #define DES_ROUND(X,Y) \ 241 | { \ 242 | T = *SK++ ^ X; \ 243 | Y ^= SB8[ (T ) & 0x3F ] ^ \ 244 | SB6[ (T >> 8) & 0x3F ] ^ \ 245 | SB4[ (T >> 16) & 0x3F ] ^ \ 246 | SB2[ (T >> 24) & 0x3F ]; \ 247 | \ 248 | T = *SK++ ^ ((X << 28) | (X >> 4)); \ 249 | Y ^= SB7[ (T ) & 0x3F ] ^ \ 250 | SB5[ (T >> 8) & 0x3F ] ^ \ 251 | SB3[ (T >> 16) & 0x3F ] ^ \ 252 | SB1[ (T >> 24) & 0x3F ]; \ 253 | } 254 | 255 | /* DES key schedule */ 256 | 257 | static inline int 258 | des_main_ks (uint32 SK[32], const uint8 key[8]) 259 | { 260 | int i; 261 | uint32 X, Y, T; 262 | 263 | GET_UINT32 (X, key, 0); 264 | GET_UINT32 (Y, key, 4); 265 | 266 | /* Permuted Choice 1 */ 267 | 268 | T = ((Y >> 4) ^ X) & 0x0F0F0F0F; 269 | X ^= T; 270 | Y ^= (T << 4); 271 | T = ((Y) ^ X) & 0x10101010; 272 | X ^= T; 273 | Y ^= (T); 274 | 275 | X = (LHs[(X) & 0xF] << 3) | (LHs[(X >> 8) & 0xF] << 2) 276 | | (LHs[(X >> 16) & 0xF] << 1) | (LHs[(X >> 24) & 0xF]) 277 | | (LHs[(X >> 5) & 0xF] << 7) | (LHs[(X >> 13) & 0xF] << 6) 278 | | (LHs[(X >> 21) & 0xF] << 5) | (LHs[(X >> 29) & 0xF] << 4); 279 | 280 | Y = (RHs[(Y >> 1) & 0xF] << 3) | (RHs[(Y >> 9) & 0xF] << 2) 281 | | (RHs[(Y >> 17) & 0xF] << 1) | (RHs[(Y >> 25) & 0xF]) 282 | | (RHs[(Y >> 4) & 0xF] << 7) | (RHs[(Y >> 12) & 0xF] << 6) 283 | | (RHs[(Y >> 20) & 0xF] << 5) | (RHs[(Y >> 28) & 0xF] << 4); 284 | 285 | X &= 0x0FFFFFFF; 286 | Y &= 0x0FFFFFFF; 287 | 288 | /* calculate subkeys */ 289 | 290 | for (i = 0; i < 16; i++) 291 | { 292 | if (i < 2 || i == 8 || i == 15) 293 | { 294 | X = ((X << 1) | (X >> 27)) & 0x0FFFFFFF; 295 | Y = ((Y << 1) | (Y >> 27)) & 0x0FFFFFFF; 296 | } 297 | else 298 | { 299 | X = ((X << 2) | (X >> 26)) & 0x0FFFFFFF; 300 | Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF; 301 | } 302 | 303 | *SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000) 304 | | ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000) 305 | | ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000) 306 | | ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000) 307 | | ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000) 308 | | ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000) 309 | | ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400) 310 | | ((Y >> 14) & 0x00000200) | ((Y) & 0x00000100) 311 | | ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010) 312 | | ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004) 313 | | ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001); 314 | 315 | *SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000) 316 | | ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000) 317 | | ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000) 318 | | ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000) 319 | | ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000) 320 | | ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000) 321 | | ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000) 322 | | ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400) 323 | | ((Y) & 0x00000200) | ((Y << 7) & 0x00000100) 324 | | ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011) 325 | | ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002); 326 | } 327 | 328 | return (0); 329 | } 330 | 331 | 332 | int 333 | des_set_key (des_context * ctx, const uint8 key[8]) 334 | { 335 | int i; 336 | 337 | // setup encryption subkeys 338 | 339 | des_main_ks (ctx->esk, key); 340 | 341 | // setup decryption subkeys 342 | 343 | for (i = 0; i < 32; i += 2) 344 | { 345 | ctx->dsk[i] = ctx->esk[30 - i]; 346 | ctx->dsk[i + 1] = ctx->esk[31 - i]; 347 | } 348 | 349 | return (0); 350 | } 351 | 352 | 353 | // DES 64-bit block encryption/decryption 354 | 355 | static void 356 | des_crypt (const uint32 SK[32], const uint8 input[8], uint8 output[8]) 357 | { 358 | uint32 X, Y, T; 359 | 360 | GET_UINT32 (X, input, 0); 361 | GET_UINT32 (Y, input, 4); 362 | 363 | DES_IP (X, Y); 364 | 365 | DES_ROUND (Y, X); 366 | DES_ROUND (X, Y); 367 | DES_ROUND (Y, X); 368 | DES_ROUND (X, Y); 369 | DES_ROUND (Y, X); 370 | DES_ROUND (X, Y); 371 | DES_ROUND (Y, X); 372 | DES_ROUND (X, Y); 373 | DES_ROUND (Y, X); 374 | DES_ROUND (X, Y); 375 | DES_ROUND (Y, X); 376 | DES_ROUND (X, Y); 377 | DES_ROUND (Y, X); 378 | DES_ROUND (X, Y); 379 | DES_ROUND (Y, X); 380 | DES_ROUND (X, Y); 381 | 382 | DES_FP (Y, X); 383 | 384 | PUT_UINT32 (Y, output, 0); 385 | PUT_UINT32 (X, output, 4); 386 | } 387 | 388 | 389 | void 390 | des_encrypt (des_context * ctx, const uint8 input[8], uint8 output[8]) 391 | { 392 | des_crypt (ctx->esk, input, output); 393 | } 394 | 395 | void 396 | des_decrypt (des_context * ctx, const uint8 input[8], uint8 output[8]) 397 | { 398 | des_crypt (ctx->dsk, input, output); 399 | } 400 | 401 | // Triple-DES key schedule 402 | 403 | int 404 | des3_set_2keys (des3_context * ctx, const uint8 key1[8], const uint8 key2[8]) 405 | { 406 | int i; 407 | 408 | des_main_ks (ctx->esk, key1); 409 | des_main_ks (ctx->dsk + 32, key2); 410 | 411 | for (i = 0; i < 32; i += 2) 412 | { 413 | ctx->dsk[i] = ctx->esk[30 - i]; 414 | ctx->dsk[i + 1] = ctx->esk[31 - i]; 415 | 416 | ctx->esk[i + 32] = ctx->dsk[62 - i]; 417 | ctx->esk[i + 33] = ctx->dsk[63 - i]; 418 | 419 | ctx->esk[i + 64] = ctx->esk[i]; 420 | ctx->esk[i + 65] = ctx->esk[1 + i]; 421 | 422 | ctx->dsk[i + 64] = ctx->dsk[i]; 423 | ctx->dsk[i + 65] = ctx->dsk[1 + i]; 424 | } 425 | 426 | return (0); 427 | } 428 | 429 | // Triple-DES 64-bit block encryption/decryption 430 | 431 | void 432 | des3_crypt (uint32 SK[96], uint8 input[8], uint8 output[8]) 433 | { 434 | uint32 X, Y, T; 435 | 436 | GET_UINT32 (X, input, 0); 437 | GET_UINT32 (Y, input, 4); 438 | 439 | DES_IP (X, Y); 440 | 441 | // encrypt 442 | DES_ROUND (Y, X); 443 | DES_ROUND (X, Y); 444 | DES_ROUND (Y, X); 445 | DES_ROUND (X, Y); 446 | DES_ROUND (Y, X); 447 | DES_ROUND (X, Y); 448 | DES_ROUND (Y, X); 449 | DES_ROUND (X, Y); 450 | DES_ROUND (Y, X); 451 | DES_ROUND (X, Y); 452 | DES_ROUND (Y, X); 453 | DES_ROUND (X, Y); 454 | DES_ROUND (Y, X); 455 | DES_ROUND (X, Y); 456 | DES_ROUND (Y, X); 457 | DES_ROUND (X, Y); 458 | 459 | // decrypt 460 | DES_ROUND (X, Y); 461 | DES_ROUND (Y, X); 462 | DES_ROUND (X, Y); 463 | DES_ROUND (Y, X); 464 | DES_ROUND (X, Y); 465 | DES_ROUND (Y, X); 466 | DES_ROUND (X, Y); 467 | DES_ROUND (Y, X); 468 | DES_ROUND (X, Y); 469 | DES_ROUND (Y, X); 470 | DES_ROUND (X, Y); 471 | DES_ROUND (Y, X); 472 | DES_ROUND (X, Y); 473 | DES_ROUND (Y, X); 474 | DES_ROUND (X, Y); 475 | DES_ROUND (Y, X); 476 | 477 | // encrypt 478 | DES_ROUND (Y, X); 479 | DES_ROUND (X, Y); 480 | DES_ROUND (Y, X); 481 | DES_ROUND (X, Y); 482 | DES_ROUND (Y, X); 483 | DES_ROUND (X, Y); 484 | DES_ROUND (Y, X); 485 | DES_ROUND (X, Y); 486 | DES_ROUND (Y, X); 487 | DES_ROUND (X, Y); 488 | DES_ROUND (Y, X); 489 | DES_ROUND (X, Y); 490 | DES_ROUND (Y, X); 491 | DES_ROUND (X, Y); 492 | DES_ROUND (Y, X); 493 | DES_ROUND (X, Y); 494 | 495 | DES_FP (Y, X); 496 | 497 | PUT_UINT32 (Y, output, 0); 498 | PUT_UINT32 (X, output, 4); 499 | } 500 | 501 | void 502 | des3_encrypt (des3_context * ctx, uint8 input[8], uint8 output[8]) 503 | { 504 | des3_crypt (ctx->esk, input, output); 505 | } 506 | 507 | void 508 | des3_decrypt (des3_context * ctx, uint8 input[8], uint8 output[8]) 509 | { 510 | des3_crypt (ctx->dsk, input, output); 511 | } 512 | 513 | void 514 | encrypt_3des (const unsigned char *key, unsigned char *input, int inputLength, 515 | unsigned char **output, int *outputLength) 516 | { 517 | unsigned char in[8], out[8]; 518 | des3_context ctx3; 519 | int i; 520 | int j; 521 | unsigned char *temp; 522 | 523 | temp = *output; 524 | 525 | // Set encryption keys 526 | //des3_set_2keys( &ctx3, DES3_keys[0], DES3_keys[1] ); 527 | des3_set_2keys (&ctx3, &key[0], &key[8]); 528 | 529 | // clear buffers 530 | memset (in, 0x00, 8); 531 | memset (out, 0x00, 8); 532 | 533 | // do for each 8 byte block of input 534 | for (i = 0; i < inputLength / 8; i++) 535 | { 536 | // copy 8 bytes from input buffer to in 537 | memcpy (in, &input[i * 8], 8); 538 | 539 | // xor with ciphered block -1 540 | for (j = 0; j < 8; j++) 541 | in[j] = in[j] ^ out[j]; 542 | 543 | // 3DES encryption 544 | des3_encrypt (&ctx3, in, out); 545 | 546 | // copy encrypted block to output 547 | memcpy (&temp[i * 8], out, 8); 548 | } 549 | *outputLength = inputLength; 550 | } 551 | 552 | void 553 | decrypt_3des (const unsigned char *key, unsigned char *input, int inputLength, 554 | unsigned char **output, int *outputLength) 555 | { 556 | des3_context ctx3; 557 | unsigned char in[8], out[8], in2[8]; 558 | 559 | unsigned char *temp; 560 | 561 | int i; 562 | int j; 563 | 564 | temp = *output; 565 | 566 | // Set encryption keys 567 | //des3_set_2keys( &ctx3, DES3_keys[0], DES3_keys[1] ); 568 | des3_set_2keys (&ctx3, &key[0], &key[8]); 569 | 570 | // clear buffers 571 | memset (in, 0x00, 8); 572 | memset (out, 0x00, 8); 573 | memset (in2, 0x00, 8); 574 | 575 | // do for each 8 byte block of input 576 | for (i = 0; i < inputLength / 8; i++) 577 | { 578 | // copy 8 bytes from input buffer to in 579 | memcpy (in, &input[i * 8], 8); 580 | 581 | // 3DES encryption 582 | des3_decrypt (&ctx3, in, out); 583 | 584 | // xor with ciphered block -1 585 | for (j = 0; j < 8; j++) 586 | out[j] = out[j] ^ in2[j]; 587 | 588 | memcpy (in2, &input[i * 8], 8); 589 | 590 | // copy decrypted block to output 591 | memcpy (&temp[i * 8], out, 8); 592 | } 593 | } 594 | 595 | void 596 | encrypt_des (const unsigned char *key, unsigned char *input, int inputLength, 597 | unsigned char **output, int *outputLength) 598 | { 599 | unsigned char in[8], out[8]; 600 | des_context ctx; 601 | int i, j; 602 | unsigned char *temp; 603 | 604 | temp = *output; 605 | 606 | // Set encryption keys 607 | //des3_set_2keys( &ctx3, DES3_keys[0], DES3_keys[1] ); 608 | des_set_key (&ctx, &key[0]); 609 | 610 | // clear buffers 611 | memset (in, 0x00, 8); 612 | memset (out, 0x00, 8); 613 | 614 | // do for each 8 byte block of input 615 | for (i = 0; i < inputLength / 8; i++) 616 | { 617 | // copy 8 bytes from input buffer to in 618 | memcpy (in, &input[i * 8], 8); 619 | 620 | // xor with ciphered block -1 621 | for (j = 0; j < 8; j++) 622 | in[j] = in[j] ^ out[j]; 623 | 624 | // 3DES encryption 625 | des_encrypt (&ctx, in, out); 626 | 627 | // copy encrypted block to output 628 | memcpy (&temp[i * 8], out, 8); 629 | } 630 | *outputLength = inputLength; 631 | } 632 | 633 | void 634 | decrypt_des (const unsigned char *key, unsigned char *input, int inputLength, 635 | unsigned char **output, int *outputLength) 636 | { 637 | des_context ctx; 638 | unsigned char in[8], out[8], in2[8]; 639 | 640 | unsigned char *temp; 641 | 642 | int i, j; 643 | 644 | temp = *output; 645 | 646 | // Set encryption keys 647 | //des3_set_2keys( &ctx3, DES3_keys[0], DES3_keys[1] ); 648 | des_set_key (&ctx, &key[0]); 649 | 650 | // clear buffers 651 | memset (in, 0x00, 8); 652 | memset (out, 0x00, 8); 653 | memset (in2, 0x00, 8); 654 | 655 | // do for each 8 byte block of input 656 | for (i = 0; i < inputLength / 8; i++) 657 | { 658 | // copy 8 bytes from input buffer to in 659 | memcpy (in, &input[i * 8], 8); 660 | 661 | // 3DES encryption 662 | des_decrypt (&ctx, in, out); 663 | 664 | // xor with ciphered block -1 665 | for (j = 0; j < 8; j++) 666 | out[j] = out[j] ^ in2[j]; 667 | 668 | memcpy (in2, &input[i * 8], 8); 669 | 670 | // copy decrypted block to output 671 | memcpy (&temp[i * 8], out, 8); 672 | } 673 | } 674 | -------------------------------------------------------------------------------- /des.h: -------------------------------------------------------------------------------- 1 | #ifndef _DES_H 2 | #define _DES_H 3 | 4 | #ifndef uint8 5 | #define uint8 unsigned char 6 | #endif 7 | 8 | #ifndef uint32 9 | #define uint32 unsigned long int 10 | #endif 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | typedef struct 17 | { 18 | uint32 esk[32]; // DES encryption subkeys 19 | uint32 dsk[32]; // DES decryption subkeys 20 | } des_context; 21 | 22 | typedef struct 23 | { 24 | uint32 esk[96]; // Triple-DES encryption subkeys 25 | uint32 dsk[96]; // Triple-DES decryption subkeys 26 | } des3_context; 27 | 28 | int des_set_key (des_context * ctx, const uint8 key[8]); 29 | void des_encrypt (des_context * ctx, const uint8 input[8], uint8 output[8]); 30 | void des_decrypt (des_context * ctx, const uint8 input[8], uint8 output[8]); 31 | int des3_set_2keys (des3_context * ctx, const uint8 key1[8], 32 | const uint8 key2[8]); 33 | 34 | /* 35 | int des3_set_3keys( des3_context *ctx, uint8 key1[8], uint8 key2[8], 36 | uint8 key3[8] ); 37 | */ 38 | void des3_encrypt (des3_context * ctx, uint8 input[8], uint8 output[8]); 39 | void des3_decrypt (des3_context * ctx, uint8 input[8], uint8 output[8]); 40 | 41 | // Encrypt input data, using key, storing ciphered bytes to output 42 | // Using 3DES and Outer CBC 43 | // - length of key have to be 16 bytes 44 | // - length of input have to be a multiple of 8 bytes ! 45 | void encrypt_3des (const unsigned char *key, unsigned char *input, 46 | int inputLength, unsigned char **output, 47 | int *outputLength); 48 | 49 | // Decrypt input data, using key, storing ciphered bytes to output 50 | // Using 3DES and Outer CBC 51 | // - length of key have to be 16 bytes 52 | // - length of input have to be a multiple of 8 bytes ! 53 | void decrypt_3des (const unsigned char *key, unsigned char *input, 54 | int inputLength, unsigned char **output, 55 | int *outputLength); 56 | 57 | 58 | void encrypt_des (const unsigned char *key, unsigned char *input, 59 | int inputLength, unsigned char **output, 60 | int *outputLength); 61 | 62 | void decrypt_des (const unsigned char *key, unsigned char *input, 63 | int inputLength, unsigned char **output, 64 | int *outputLength); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | #endif /* des.h */ 70 | -------------------------------------------------------------------------------- /iClass_Capture.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/iClassReader/cf5c1e3d0ad328f606cc1c8e68e1e63b29493601/iClass_Capture.PNG -------------------------------------------------------------------------------- /lib/scardsyn.def: -------------------------------------------------------------------------------- 1 | LIBRARY SCARDSYN.DLL 2 | 3 | EXPORTS 4 | SCard2WBPChangePIN ; SCard2WBPChangePIN 5 | SCard2WBPCompareAndProtect ; SCard2WBPCompareAndProtect 6 | SCard2WBPIsPinPresented ; SCard2WBPIsPinPresented 7 | SCard2WBPPresentPIN ; SCard2WBPPresentPIN 8 | SCard2WBPReadData ; SCard2WBPReadData 9 | SCard2WBPReadProtectionMemory ; SCard2WBPReadProtectionMemory 10 | SCard2WBPWriteData ; SCard2WBPWriteData 11 | SCard3WBPChangePIN ; SCard3WBPChangePIN 12 | SCard3WBPCompareAndProtect ; SCard3WBPCompareAndProtect 13 | SCard3WBPIsPinPresented ; SCard3WBPIsPinPresented 14 | SCard3WBPPresentPIN ; SCard3WBPPresentPIN 15 | SCard3WBPReadData ; SCard3WBPReadData 16 | SCard3WBPVerifyProtectBit ; SCard3WBPVerifyProtectBit 17 | SCard3WBPVerifyProtectBitEx ; SCard3WBPVerifyProtectBitEx 18 | SCard3WBPWriteData ; SCard3WBPWriteData 19 | SCard4404ChangeUserCode ; SCard4404ChangeUserCode 20 | SCard4404EraseErrorCounter ; SCard4404EraseErrorCounter 21 | SCard4404EraseScratchPadMemory ; SCard4404EraseScratchPadMemory 22 | SCard4404EraseUserMemory ; SCard4404EraseUserMemory 23 | SCard4404ReadData ; SCard4404ReadData 24 | SCard4404VerifyUserCode ; SCard4404VerifyUserCode 25 | SCard4404WriteData ; SCard4404WriteData 26 | SCardCLGetUID ; SCardCLGetUID 27 | SCardCLICCTransmit ; SCardCLICCTransmit 28 | SCardCLMifareLightWrite ; SCardCLMifareLightWrite 29 | SCardCLMifareStdAuthent ; SCardCLMifareStdAuthent 30 | SCardCLMifareStdDecrementVal ; SCardCLMifareStdDecrementVal 31 | SCardCLMifareStdIncrementVal ; SCardCLMifareStdIncrementVal 32 | SCardCLMifareStdRead ; SCardCLMifareStdRead 33 | SCardCLMifareStdRestoreVal ; SCardCLMifareStdRestoreVal 34 | SCardCLMifareStdWrite ; SCardCLMifareStdWrite 35 | SCardCLWriteMifareKeyToReader ; SCardCLWriteMifareKeyToReader 36 | SCardDfAutoPageRewriteThroughBuffer ; SCardDfAutoPageRewriteThroughBuffer 37 | SCardDfBlockErase ; SCardDfBlockErase 38 | SCardDfBufferRead ; SCardDfBufferRead 39 | SCardDfBufferToMainMemoryPageProgram ; SCardDfBufferToMainMemoryPageProgram 40 | SCardDfBufferWrite ; SCardDfBufferWrite 41 | SCardDfContinuousArrayRead ; SCardDfContinuousArrayRead 42 | SCardDfInit ; SCardDfInit 43 | SCardDfMainMemoryPageProgramThroughBuffer ; SCardDfMainMemoryPageProgramThroughBuffer 44 | SCardDfMainMemoryPageRead ; SCardDfMainMemoryPageRead 45 | SCardDfMainMemoryPageToBufferCompare ; SCardDfMainMemoryPageToBufferCompare 46 | SCardDfMainMemoryPageToBufferTransfer ; SCardDfMainMemoryPageToBufferTransfer 47 | SCardDfPageErase ; SCardDfPageErase 48 | SCardDfStatusRegisterRead ; SCardDfStatusRegisterRead 49 | SCardI2CInit ; SCardI2CInit 50 | SCardI2CReadData ; SCardI2CReadData 51 | SCardI2CWriteData ; SCardI2CWriteData 52 | SCardSmAT88SC10xBlowFuse ; SCardSmAT88SC10xBlowFuse 53 | SCardSmAT88SC10xCompareSC ; SCardSmAT88SC10xCompareSC 54 | SCardSmAT88SC10xErase ; SCardSmAT88SC10xErase 55 | SCardSmAT88SC10xEraseAZ ; SCardSmAT88SC10xEraseAZ 56 | SCardSmAT88SC10xRead ; SCardSmAT88SC10xRead 57 | SCardSmAT88SC10xSetFusPin ; SCardSmAT88SC10xSetFusPin 58 | SCardSmAT88SC10xWrite ; SCardSmAT88SC10xWrite 59 | SCardSmInit ; SCardSmInit 60 | SCardSmInitializeAuthentication ; SCardSmInitializeAuthentication 61 | SCardSmReadConfigurationZone ; SCardSmReadConfigurationZone 62 | SCardSmReadFuses ; SCardSmReadFuses 63 | SCardSmReadUserZone ; SCardSmReadUserZone 64 | SCardSmSetUserZoneAddress ; SCardSmSetUserZoneAddress 65 | SCardSmUseSlaveAddress ; SCardSmUseSlaveAddress 66 | SCardSmVerifyAuthentication ; SCardSmVerifyAuthentication 67 | SCardSmVerifyPassword ; SCardSmVerifyPassword 68 | SCardSmWriteConfigurationZone ; SCardSmWriteConfigurationZone 69 | SCardSmWriteFuses ; SCardSmWriteFuses 70 | SCardSmWriteUserZone ; SCardSmWriteUserZone 71 | -------------------------------------------------------------------------------- /lib/scardsyn.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/iClassReader/cf5c1e3d0ad328f606cc1c8e68e1e63b29493601/lib/scardsyn.dll -------------------------------------------------------------------------------- /lib/scardsyn.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/iClassReader/cf5c1e3d0ad328f606cc1c8e68e1e63b29493601/lib/scardsyn.lib -------------------------------------------------------------------------------- /uMain.cpp: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #include 3 | #include 4 | #pragma hdrstop 5 | //--------------------------------------------------------------------------- 6 | #include "des.h" 7 | #include "uMain.h" 8 | //--------------------------------------------------------------------------- 9 | #pragma package(smart_init) 10 | #pragma resource "*.dfm" 11 | #pragma link "winscard.lib" 12 | #pragma link "lib/scardsyn.lib" 13 | //--------------------------------------------------------------------------- 14 | TFM_Main *FM_Main; 15 | //--------------------------------------------------------------------------- 16 | static const UCHAR hid_decryption_key[] = { 17 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 19 | }; 20 | static struct memory_t{ 21 | int k16; 22 | int book; 23 | int k2; 24 | int lockauth; 25 | int keyaccess; 26 | } memory; 27 | 28 | static struct fuse_t{ 29 | bool fpers; 30 | bool code1; 31 | bool code0; 32 | bool crypt1; 33 | bool crypt0; 34 | bool fprod1; 35 | bool fprod0; 36 | bool ra; 37 | } fuse; 38 | //--------------------------------------------------------------------------- 39 | extern "C" ULONG __stdcall SCardCLICCTransmit (IN SCARDHANDLE ulHandleCard, 40 | IN PUCHAR pucSendData, 41 | IN ULONG ulSendDataBufLen, 42 | IN OUT PUCHAR pucReceivedData, 43 | IN OUT PULONG 44 | pulReceivedDataBufLen); 45 | //--------------------------------------------------------------------------- 46 | __fastcall 47 | TFM_Main::TFM_Main (TComponent * Owner): 48 | TForm (Owner) 49 | { 50 | int i; 51 | wchar_t readers[1024], *wc; 52 | DWORD res, length = sizeof (readers) / sizeof (readers[0]); 53 | 54 | // set up resizing constraints 55 | Constraints->MinWidth = Width; 56 | Constraints->MinHeight = Height; 57 | 58 | // init random pool 59 | randomize (); 60 | 61 | hContext = hCard = NULL; 62 | m_PrevLines = NULL; 63 | 64 | res = SCardEstablishContext (SCARD_SCOPE_USER, NULL, NULL, &hContext); 65 | if (res != SCARD_S_SUCCESS) 66 | ShowMessage ("Can't establish RFID reader context"); 67 | else 68 | { 69 | res = SCardListReaders (hContext, NULL, readers, &length); 70 | if (res != SCARD_S_SUCCESS) 71 | ShowMessage ("Can't retrieve list of installed readers"); 72 | else 73 | { 74 | wc = readers; 75 | while (*wc) 76 | { 77 | i = CB_Readers->Items->Add (UnicodeString (wc)); 78 | if (wcsstr (wc, L"-CL")) 79 | CB_Readers->ItemIndex = i; 80 | wc += wcslen (wc) + 1; 81 | } 82 | if (CB_Readers->Items->Count) 83 | { 84 | BT_CardReload->Enabled = true; 85 | BT_CardReload->Click (); 86 | return; 87 | } 88 | else 89 | ShowMessage ("Can't find a single smart card reader"); 90 | } 91 | } 92 | Application->Terminate (); 93 | } 94 | 95 | //--------------------------------------------------------------------------- 96 | __fastcall 97 | TFM_Main::~ 98 | TFM_Main (void) 99 | { 100 | if (hCard) 101 | SCardReleaseContext (hCard); 102 | if (hContext) 103 | SCardReleaseContext (hContext); 104 | if (m_PrevLines) 105 | delete m_PrevLines; 106 | } 107 | 108 | //--------------------------------------------------------------------------- 109 | void __fastcall 110 | TFM_Main::FormKeyDown (TObject * Sender, WORD & Key, TShiftState Shift) 111 | { 112 | if (Key == VK_F5) 113 | BT_CardReload->Click (); 114 | } 115 | 116 | //--------------------------------------------------------------------------- 117 | 118 | void __fastcall 119 | TFM_Main::BT_CardReloadClick (TObject * Sender) 120 | { 121 | DWORD res; 122 | DWORD dwActiveProtocol; 123 | SCARD_READERSTATE state; 124 | bool done; 125 | 126 | if (hCard) 127 | BT_CardCloseClick (this); 128 | 129 | res = SCardConnect (hContext, 130 | CB_Readers->Text.c_str (), 131 | SCARD_SHARE_SHARED, 132 | SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, 133 | &hCard, &dwActiveProtocol); 134 | 135 | done = (res == SCARD_S_SUCCESS); 136 | 137 | ED_AuthKey->Enabled = done; 138 | BT_Auth->Enabled = done; 139 | RG_KeyType->Enabled = done; 140 | 141 | ED_Serial->Text = done ? CardSelect (0x04) : UnicodeString (); 142 | ED_ConfigBlock->Text = done ? CardSelect (0x08) : UnicodeString (); 143 | ED_AppIssuer->Text = done ? CardSelect (0x0C) : UnicodeString (); 144 | 145 | if (done) 146 | ActiveControl = BT_Auth; 147 | } 148 | 149 | //--------------------------------------------------------------------------- 150 | 151 | void __fastcall 152 | TFM_Main::BT_CardCloseClick (TObject * Sender) 153 | { 154 | if (hCard) 155 | { 156 | SCardReleaseContext (hCard); 157 | hCard = NULL; 158 | } 159 | } 160 | 161 | //--------------------------------------------------------------------------- 162 | UnicodeString __fastcall 163 | TFM_Main::CardSelect (UCHAR p2) 164 | { 165 | int res, i; 166 | UnicodeString hex; 167 | UCHAR ucReceivedData[64] = { 0 }; 168 | ULONG ulNoOfDataReceived = sizeof (ucReceivedData); 169 | UCHAR data[] = { 0x80, 0xA6, 0x00, p2, p2 ? 0x08 : 0x00 }; 170 | 171 | res = 172 | SCardCLICCTransmit (hCard, data, sizeof (data), ucReceivedData, 173 | &ulNoOfDataReceived); 174 | if ((res != SCARD_S_SUCCESS) || (ulNoOfDataReceived < 2)) 175 | ShowMessage ("Error in SCardCLICCTransmit"); 176 | else 177 | { 178 | res = ucReceivedData[ulNoOfDataReceived - 2]; 179 | if (res != 0x90) 180 | return Format ("APDU Error=0x%02X", OPENARRAY (TVarRec, (res))); 181 | else 182 | { 183 | res = ulNoOfDataReceived - 2; 184 | for (i = 0; i < res; i++) 185 | hex += IntToHex (ucReceivedData[i], 2); 186 | return hex; 187 | } 188 | } 189 | return "Error"; 190 | } 191 | 192 | //--------------------------------------------------------------------------- 193 | void __fastcall 194 | TFM_Main::BT_AuthClick (TObject * Sender) 195 | { 196 | const wchar_t *p; 197 | wchar_t nibble; 198 | __int64 k; 199 | 200 | k = 0; 201 | p = ED_AuthKey->Text.c_str (); 202 | while ((nibble = *p++) != 0) 203 | { 204 | if (nibble >= '0' && nibble <= '9') 205 | nibble -= '0'; 206 | else if (nibble >= 'a' && nibble <= 'f') 207 | nibble -= 'a' - 0xA; 208 | else if (nibble >= 'A' && nibble <= 'F') 209 | nibble -= 'A' - 0xA; 210 | else 211 | nibble = 0; 212 | 213 | k = (k << 4) | nibble; 214 | } 215 | 216 | ED_AuthKey->Text = IntToHex (k, 16); 217 | 218 | if (RG_KeyType->ItemIndex) 219 | BT_ReadCard->Enabled = CardAuth (k, RG_KeyType->ItemIndex - 1) > 0; 220 | else 221 | BT_ReadCard->Enabled = CardAuth (k, 0) || CardAuth (k, 1); 222 | 223 | if (BT_ReadCard->Enabled) 224 | ActiveControl = BT_ReadCard; 225 | } 226 | //--------------------------------------------------------------------------- 227 | void __fastcall 228 | TFM_Main::PageSelect (int P2){ 229 | int res; 230 | UCHAR ucReceivedData[64] = { 0 }; 231 | ULONG ulNoOfDataReceived = sizeof (ucReceivedData); 232 | UCHAR data[7] = { 0x80, 0xa6, 0x01, 0x00, 0x00, 0x00, 0x00 }; 233 | switch(P2){ 234 | case 1: 235 | data[4]=0x01; 236 | data[5]=0x01; 237 | break; 238 | case 2: 239 | data[4]=0x01; 240 | data[5]=0x02; 241 | break; 242 | case 3: 243 | data[4]=0x01; 244 | data[5]=0x03; 245 | break; 246 | case 4: 247 | data[4]=0x01; 248 | data[5]=0x04; 249 | break; 250 | case 5: 251 | data[4]=0x01; 252 | data[5]=0x05; 253 | break; 254 | case 6: 255 | data[4]=0x01; 256 | data[5]=0x06; 257 | break; 258 | case 7: 259 | data[4]=0x01; 260 | data[5]=0x07; 261 | break; 262 | case 8: 263 | data[4]=0x01; 264 | data[5]=0x10; 265 | break; 266 | case 9: 267 | data[4]=0x01; 268 | data[5]=0x11; 269 | break; 270 | case 10: 271 | data[4]=0x01; 272 | data[5]=0x12; 273 | break; 274 | case 11: 275 | data[4]=0x01; 276 | data[5]=0x13; 277 | break; 278 | case 12: 279 | data[4]=0x01; 280 | data[5]=0x14; 281 | break; 282 | case 13: 283 | data[4]=0x01; 284 | data[5]=0x15; 285 | break; 286 | case 14: 287 | data[4]=0x01; 288 | data[5]=0x16; 289 | break; 290 | case 15: 291 | data[4]=0x01; 292 | data[5]=0x17; 293 | break; 294 | default: 295 | break; 296 | } 297 | if(P2 != 0){ 298 | res = SCardCLICCTransmit (hCard, data, (sizeof (data)-1), ucReceivedData, 299 | &ulNoOfDataReceived); 300 | }else{ 301 | res = SCardCLICCTransmit (hCard, data, sizeof (data), ucReceivedData, 302 | &ulNoOfDataReceived); 303 | } 304 | if ((res != SCARD_S_SUCCESS) || (ulNoOfDataReceived < 2)){ 305 | StatusBar->SimpleText = "Error in Page Select SCardCLICCTransmit"; 306 | } 307 | } 308 | //--------------------------------------------------------------------------- 309 | int __fastcall 310 | TFM_Main::CardAuth (__int64 key, UCHAR type) 311 | { 312 | int res, i; 313 | UnicodeString hex; 314 | UCHAR ucReceivedData[64] = { 0 }; 315 | ULONG ulNoOfDataReceived = sizeof (ucReceivedData); 316 | UCHAR data[13] = { 0x80, 0x82, 0x00, 0xF0, 0x08 }; 317 | 318 | for (i = 0; i < 8; i++) 319 | { 320 | data[5 + 8 - 1 - i] = (UCHAR) key; 321 | key >>= 8; 322 | } 323 | 324 | res = 325 | SCardCLICCTransmit (hCard, data, sizeof (data), ucReceivedData, 326 | &ulNoOfDataReceived); 327 | if ((res != SCARD_S_SUCCESS) || (ulNoOfDataReceived < 2)) 328 | { 329 | StatusBar->SimpleText = "Error in LoadKey SCardCLICCTransmit"; 330 | return 0; 331 | } 332 | 333 | res = ucReceivedData[ulNoOfDataReceived - 2]; 334 | if (res != 0x90) 335 | { 336 | StatusBar->SimpleText = "APDU LoadKey error=0x" + IntToHex (res, 2); 337 | return 0; 338 | } 339 | 340 | data[1] = 0x88; 341 | data[2] = type; 342 | 343 | ulNoOfDataReceived = sizeof (ucReceivedData); 344 | res = 345 | SCardCLICCTransmit (hCard, data, 4, ucReceivedData, &ulNoOfDataReceived); 346 | if ((res != SCARD_S_SUCCESS) || (ulNoOfDataReceived < 2)) 347 | StatusBar->SimpleText = "Error in Authenticate SCardCLICCTransmit"; 348 | else 349 | { 350 | res = ucReceivedData[ulNoOfDataReceived - 2]; 351 | if (res != 0x90) 352 | { 353 | res = res << 8 | ucReceivedData[ulNoOfDataReceived - 1]; 354 | StatusBar->SimpleText = 355 | "APDU Authenticate error=0x" + IntToHex (res, 4); 356 | } 357 | else 358 | { 359 | if (type && CB_Decrypt->Checked) 360 | CB_Decrypt->Checked = false; 361 | 362 | StatusBar->SimpleText = 363 | "Authenticated with Key(" + IntToStr (type + 1) + ")"; 364 | return 1; 365 | } 366 | } 367 | 368 | return 0; 369 | } 370 | 371 | //--------------------------------------------------------------------------- 372 | 373 | void __fastcall 374 | TFM_Main::ClearStatusPanel (TObject * Sender, TMouseButton Button, 375 | TShiftState Shift, int X, int Y) 376 | { 377 | StatusBar->SimpleText = ""; 378 | } 379 | 380 | //--------------------------------------------------------------------------- 381 | void __fastcall 382 | TFM_Main::BT_ReadCardClick (TObject * Sender) 383 | { 384 | int i, sel; 385 | UnicodeString hex; 386 | UCHAR P2; 387 | const wchar_t *q; 388 | wchar_t nibble; 389 | __int8 r; 390 | 391 | // remember previous content and clear Memo 392 | if (!m_PrevLines) 393 | m_PrevLines = new TStringList (); 394 | m_PrevLines->Text = Memo->Lines->Text; 395 | Memo->Clear (); 396 | 397 | r = 0; 398 | q = PN_Select->Text.c_str(); 399 | while ((nibble = *q++) != 0) 400 | { 401 | if (nibble >= '0' && nibble <= '9') 402 | nibble -= '0'; 403 | else if (nibble >= 'a' && nibble <= 'f') 404 | nibble -= 'a' - 0xA; 405 | else if (nibble >= 'A' && nibble <= 'F') 406 | nibble -= 'A' - 0xA; 407 | else 408 | nibble = 0; 409 | 410 | r = (r << 4) | nibble; 411 | } 412 | 413 | PN_Select->Text = IntToHex (r, 2); 414 | 415 | if (PN_Select->Text == "00") { 416 | PageSelect(0); 417 | }else if(PN_Select->Text == "01") { 418 | PageSelect(1); 419 | }else if(PN_Select->Text == "02") { 420 | PageSelect(2); 421 | }else if(PN_Select->Text == "03") { 422 | PageSelect(3); 423 | }else if(PN_Select->Text == "04") { 424 | PageSelect(4); 425 | }else if(PN_Select->Text == "05") { 426 | PageSelect(5); 427 | }else if(PN_Select->Text == "06") { 428 | PageSelect(6); 429 | }else if(PN_Select->Text == "07") { 430 | PageSelect(7); 431 | }else if(PN_Select->Text == "10") { 432 | PageSelect(8); 433 | }else if(PN_Select->Text == "11") { 434 | PageSelect(9); 435 | }else if(PN_Select->Text == "12") { 436 | PageSelect(10); 437 | }else if(PN_Select->Text == "13") { 438 | PageSelect(11); 439 | }else if(PN_Select->Text == "14") { 440 | PageSelect(12); 441 | }else if(PN_Select->Text == "15") { 442 | PageSelect(13); 443 | }else if(PN_Select->Text == "16") { 444 | PageSelect(14); 445 | }else if(PN_Select->Text == "17") { 446 | PageSelect(15); 447 | }else{ 448 | PageSelect(0); 449 | } 450 | 451 | CardConfig(1); 452 | CardePurse(2); 453 | 454 | for (i = 0; i <= 0xFF; i++) 455 | { 456 | hex = CardRead (i); 457 | if (hex.IsEmpty ()) 458 | break; 459 | else 460 | { 461 | Memo->Lines->Add (IntToHex (i, 2) + ": " + hex); 462 | SetLineNumberColor (i, clBlue); 463 | } 464 | } 465 | 466 | // set memo active 467 | ActiveControl = Memo; 468 | } 469 | 470 | //--------------------------------------------------------------------------- 471 | UnicodeString __fastcall 472 | TFM_Main::HexDump (PUCHAR data, ULONG len) 473 | { 474 | ULONG t; 475 | UnicodeString hex = ""; 476 | 477 | for (t = 0; t < len; t++) 478 | hex += (t ? " " : "") + IntToHex (*data++, 2); 479 | 480 | return hex; 481 | } 482 | //--------------------------------------------------------------------------- 483 | void __fastcall TFM_Main::CardConfig (UCHAR block){ 484 | 485 | int res; 486 | static int app_limit,block_lock,chip,mem,eas,fuse_b; 487 | static uint16_t app_otp; 488 | UCHAR ucReceivedData[64] = { 0 }; 489 | UCHAR compare[64] = { 0 }; 490 | UCHAR ucDecryptedReceivedData[64] = { 0 }; 491 | ULONG ulNoOfDataReceived = sizeof (ucReceivedData); 492 | UCHAR data[] = { 0x80, 0xB0, 0x00, block, 0x08 }; 493 | UCHAR *output = ucDecryptedReceivedData; 494 | int outputLength; 495 | 496 | res = 497 | SCardCLICCTransmit (hCard, data, sizeof (data), ucReceivedData, 498 | &ulNoOfDataReceived); 499 | 500 | if ((res != SCARD_S_SUCCESS) || (ulNoOfDataReceived < 2)){ 501 | ShowMessage ("Error in CardRead SCardCLICCTransmit"); 502 | }else{ 503 | res = ucReceivedData[ulNoOfDataReceived - 2]; 504 | if (res == 0x90){ 505 | Memo1->Clear (); 506 | Memo1->Lines->Add("Configuration"); 507 | Memo1->Lines->Add("-----------------"); 508 | outputLength = ulNoOfDataReceived - 2; 509 | app_limit=(int)ucReceivedData[0]; 510 | app_otp=ucReceivedData[1]|(ucReceivedData[2] << 8); 511 | block_lock=(int)ucReceivedData[3]; 512 | chip=(int)ucReceivedData[4]; 513 | mem=(int)ucReceivedData[5]; 514 | eas=(int)ucReceivedData[6]; 515 | fuse_b=(int)ucReceivedData[7]; 516 | //------------------------- 517 | //ShowMessage(mem); 518 | memory.k16= (mem & 0x80); 519 | memory.book= (mem & 0x20); 520 | memory.k2 = (mem & 0x8); 521 | memory.lockauth = (mem & 0x2); 522 | memory.keyaccess= (mem & 0x1); 523 | //------------------------ 524 | fuse.fpers= (fuse_b & 0x80); 525 | fuse.code1= (fuse_b & 0x40); 526 | fuse.code0= (fuse_b & 0x20); 527 | fuse.crypt1 = (fuse_b & 0x10); 528 | fuse.crypt0 = (fuse_b & 0x8); 529 | fuse.fprod1 = (fuse_b & 0x4); 530 | fuse.fprod0 = (fuse_b & 0x2); 531 | fuse.ra = (fuse_b & 0x1); 532 | 533 | }//0x90 534 | } 535 | if (memory.k16) { 536 | Memo1->Lines->Add("16K Enabled. "); 537 | } 538 | if (memory.k2) { 539 | Memo1->Lines->Add("2K Enabled. "); 540 | } 541 | if (memory.book) { 542 | Memo1->Lines->Add("Book Enabled. "); 543 | } 544 | if (memory.book) { 545 | Memo1->Lines->Add("Lock Auth Enabled. "); 546 | } 547 | if (memory.book) { 548 | Memo1->Lines->Add("KeyAccess:"); 549 | Memo1->Lines->Add("\tRead A - Kd"); 550 | Memo1->Lines->Add("\tRead B - Kc"); 551 | Memo1->Lines->Add("\tWrite A - Kd"); 552 | Memo1->Lines->Add("\tWrite B - Kc"); 553 | Memo1->Lines->Add("\tDebit - Kd or Kc"); 554 | Memo1->Lines->Add("\tCredit - Kc"); 555 | } else{ 556 | Memo1->Lines->Add(" KeyAccess:"); 557 | Memo1->Lines->Add("\tRead A - Kd or Kc"); 558 | Memo1->Lines->Add("\tRead B - Kd or Kc"); 559 | Memo1->Lines->Add("\tWrite A - Kc"); 560 | Memo1->Lines->Add("\tWrite B - Kc"); 561 | Memo1->Lines->Add("\tDebit - Kd or Kc"); 562 | Memo1->Lines->Add("\tCredit - Kc"); 563 | } 564 | if (fuse.fpers) { 565 | Memo1->Lines->Add("Personalisation"); 566 | } else Memo1->Lines->Add("Application Mode"); 567 | if (fuse.crypt1 && fuse.crypt0) { 568 | Memo1->Lines->Add("Secure Mode"); 569 | }else{ 570 | if ((fuse.crypt1 ==1)&& (fuse.crypt0 ==0)){ 571 | Memo1->Lines->Add("Secured Page Key Values Locked"); 572 | } 573 | if ((fuse.crypt1 ==0)&& (fuse.crypt0 ==1)){ 574 | Memo1->Lines->Add("Non Secured Page"); 575 | } 576 | if ((fuse.crypt1 ==0)&& (fuse.crypt0 ==0)&& (fuse.ra==1)){ 577 | Memo1->Lines->Add("No authentication - Chip READ ONLY"); 578 | } 579 | if ((fuse.crypt1 ==0)&& (fuse.crypt0 ==0)&& (fuse.ra==0)){ 580 | Memo1->Lines->Add("No authentication - R/W Forbidden accpet Blocks 0 + 1"); 581 | } 582 | } 583 | ActiveControl = Memo1; 584 | } 585 | void __fastcall TFM_Main::CardePurse (UCHAR block){ 586 | 587 | int res; 588 | static uint16_t s1_charge, s1_recharge, s2_charge, s2_recharge; 589 | UCHAR ucReceivedData[64] = { 0 }; 590 | UCHAR compare[64] = { 0 }; 591 | UCHAR ucDecryptedReceivedData[64] = { 0 }; 592 | ULONG ulNoOfDataReceived = sizeof (ucReceivedData); 593 | UCHAR data[] = { 0x80, 0xB0, 0x00, block, 0x08 }; 594 | UCHAR *output = ucDecryptedReceivedData; 595 | int outputLength; 596 | 597 | res = 598 | SCardCLICCTransmit (hCard, data, sizeof (data), ucReceivedData, 599 | &ulNoOfDataReceived); 600 | 601 | if ((res != SCARD_S_SUCCESS) || (ulNoOfDataReceived < 2)){ 602 | ShowMessage ("Error in CardRead SCardCLICCTransmit"); 603 | }else{ 604 | res = ucReceivedData[ulNoOfDataReceived - 2]; 605 | if (res == 0x90){ 606 | Memo1->Lines->Add(""); 607 | Memo1->Lines->Add("ePurse"); 608 | Memo1->Lines->Add("-----------"); 609 | outputLength = ulNoOfDataReceived - 2; 610 | s1_charge =ucReceivedData[0]|(ucReceivedData[1] << 8); 611 | s1_recharge=ucReceivedData[2]|(ucReceivedData[3] << 8); 612 | s2_charge =ucReceivedData[4]|(ucReceivedData[5] << 8); 613 | s2_recharge=ucReceivedData[6]|(ucReceivedData[7] << 8); 614 | } 615 | } 616 | 617 | if ((s1_charge == 65535)&&(s1_recharge ==65535)) { 618 | Memo1->Lines->Add("Stage 2"); 619 | Memo1->Lines->Add("Charge Value: "); 620 | Memo1->Lines->Append(s2_charge); 621 | Memo1->Lines->Add("Recharge Value: "); 622 | Memo1->Lines->Append(s2_recharge); 623 | } 624 | if ((s2_charge == 65535)&&(s2_recharge ==65535)) { 625 | Memo1->Lines->Add("Stage 1"); 626 | Memo1->Lines->Add("Charge Value: "); 627 | Memo1->Lines->Append(s1_charge); 628 | Memo1->Lines->Add("Recharge Value: "); 629 | Memo1->Lines->Append(s1_recharge); 630 | } 631 | } 632 | //--------------------------------------------------------------------------- 633 | UnicodeString __fastcall 634 | TFM_Main::CardRead (UCHAR block) 635 | { 636 | int res; 637 | static int app_limit,block_lock,chip,mem,eas,fuse_b; 638 | static uint16_t app_otp; 639 | UCHAR ucReceivedData[64] = { 0 }; 640 | UCHAR compare[64] = { 0 }; 641 | UCHAR ucDecryptedReceivedData[64] = { 0 }; 642 | ULONG ulNoOfDataReceived = sizeof (ucReceivedData); 643 | UCHAR data[] = { 0x80, 0xB0, 0x00, block, 0x08 }; 644 | UCHAR *output = ucDecryptedReceivedData; 645 | int outputLength; 646 | int block_cap=255; 647 | 648 | res = 649 | SCardCLICCTransmit (hCard, data, sizeof (data), ucReceivedData, 650 | &ulNoOfDataReceived); 651 | 652 | if ((res != SCARD_S_SUCCESS) || (ulNoOfDataReceived < 2)){ 653 | ShowMessage ("Error in CardRead SCardCLICCTransmit"); 654 | return ""; 655 | }else{ 656 | res = ucReceivedData[ulNoOfDataReceived - 2]; 657 | if (res == 0x6A) return ""; 658 | 659 | if (res != 0x90) return Format ("APDU CardRead Error=0x%02X",OPENARRAY (TVarRec, (res))); 660 | else{ 661 | outputLength = ulNoOfDataReceived - 2; 662 | if (block==1) { 663 | app_limit=(int)ucReceivedData[0]; 664 | app_otp=(int)ucReceivedData[1]; 665 | block_lock=(int)ucReceivedData[3]; 666 | chip=(int)ucReceivedData[4]; 667 | mem=(int)ucReceivedData[5]; 668 | eas=(int)ucReceivedData[6]; 669 | fuse_b=(int)ucReceivedData[7]; 670 | } 671 | if ((memory.k16)) { 672 | block_cap=255; 673 | }else block_cap=31; 674 | if(block<=31){ 675 | //if (CB_Decrypt->Checked && (block >= 7) && (block <= 9)){ 676 | if (((ucReceivedData[0]==255)&&(ucReceivedData[1]==255)&&(ucReceivedData[2]==255)&&(ucReceivedData[3]==255))&& block>5) { 677 | return HexDump (ucReceivedData, outputLength); 678 | }else{ 679 | if (block>5) { 680 | decrypt_3des (hid_decryption_key, 681 | ucReceivedData, 682 | ulNoOfDataReceived, &output, &outputLength); 683 | 684 | return HexDump (output, outputLength); 685 | } else return HexDump (ucReceivedData, outputLength); 686 | } 687 | } 688 | } 689 | } 690 | } 691 | 692 | //--------------------------------------------------------------------------- 693 | 694 | 695 | void __fastcall 696 | TFM_Main::MemoKeyPress (TObject * Sender, wchar_t & Key) 697 | { 698 | if (Key >= ' ' && Key < 0x100) 699 | { 700 | if (Key >= 'a' && Key <= 'f') 701 | Key = (Key - 'a') + 'A'; 702 | else 703 | if (!((Key >= 'A' && Key <= 'F') || 704 | (Key >= '0') && (Key <= '9') || (Key == ' ') || (Key == ':'))) 705 | Key = NULL; 706 | } 707 | } 708 | 709 | //--------------------------------------------------------------------------- 710 | void __fastcall 711 | TFM_Main::MemoMouseDown (TObject * Sender, TMouseButton Button, 712 | TShiftState Shift, int X, int Y) 713 | { 714 | Caption = Memo->ActiveLineNo; 715 | 716 | } 717 | 718 | //--------------------------------------------------------------------------- 719 | void __fastcall 720 | TFM_Main::SetLineNumberColor (int Line, TColor Color) 721 | { 722 | if (Line < Memo->Lines->Count) 723 | { 724 | Memo->SelStart = SendMessage (Memo->Handle, EM_LINEINDEX, Line, 0); 725 | Memo->SelLength = 3; 726 | Memo->SelAttributes->Color = Color; 727 | Memo->SelLength = 0; 728 | } 729 | } 730 | 731 | //--------------------------------------------------------------------------- 732 | void __fastcall 733 | TFM_Main::PrettyPrint (void) 734 | { 735 | int lines, i, j, sel, len, sellen, selstart; 736 | UnicodeString prev, curr; 737 | wchar_t *c, *p; 738 | 739 | lines = Memo->Lines->Count; 740 | 741 | for (i = 0; i < lines; i++) 742 | { 743 | prev = m_PrevLines->Strings[i]; 744 | curr = Memo->Lines->Strings[i]; 745 | 746 | len = curr.Length (); 747 | if (prev.Length () < len) 748 | len = prev.Length (); 749 | 750 | c = curr.c_str (); 751 | p = prev.c_str (); 752 | 753 | sellen = selstart = 0; 754 | for (j = 0; j <= len; j++) 755 | { 756 | if ((j < len) && (*c++ != *p++)) 757 | { 758 | if (!sellen) 759 | selstart = j; 760 | sellen++; 761 | } 762 | else if (sellen) 763 | { 764 | Memo->SelStart = sel + selstart; 765 | Memo->SelLength = sellen; 766 | Memo->SelAttributes->Color = clRed; 767 | } 768 | } 769 | } 770 | Memo->SelLength = 0; 771 | } 772 | 773 | //--------------------------------------------------------------------------- 774 | 775 | void __fastcall 776 | TFM_Main::BT_CopyToClipboardClick (TObject * Sender) 777 | { 778 | bool deselected = Memo->SelLength == 0; 779 | 780 | if (deselected) 781 | Memo->SelectAll (); 782 | 783 | Memo->CopyToClipboard (); 784 | 785 | if (deselected) 786 | Memo->SelLength = 0; 787 | } 788 | 789 | //--------------------------------------------------------------------------- 790 | 791 | 792 | -------------------------------------------------------------------------------- /uMain.dfm: -------------------------------------------------------------------------------- 1 | object FM_Main: TFM_Main 2 | Left = 0 3 | Top = 0 4 | ActiveControl = BT_CardReload 5 | BorderStyle = bsDialog 6 | Caption = 'CopyClass' 7 | ClientHeight = 441 8 | ClientWidth = 727 9 | Color = clBtnFace 10 | Font.Charset = DEFAULT_CHARSET 11 | Font.Color = clWindowText 12 | Font.Height = -11 13 | Font.Name = 'Tahoma' 14 | Font.Style = [] 15 | Icon.Data = { 16 | 0000010001001010000001002000680400001600000028000000100000002000 17 | 0000010020000000000040040000000000000000000000000000000000000101 18 | 01FF010101FF010101FF010101FF010001FF010001FF010001FF010001FF0100 19 | 01FF010001FF010001FF010001FF010101FF010101FF010101FF010101FF0201 20 | 02FF020102FF020202FF010102FF031B03FF043004FF052C04FF030903FF030A 21 | 02FF052C05FF042B04FF041604FF020102FF020202FF020102FF020102FF0000 22 | 01FF000000FF000100FF000000FF028902FF04FF04FF04FF03FF023201FF0138 23 | 01FF04FF03FF04FF03FF038103FF000000FF000000FF000000FF010000FF03B6 24 | 03FF036203FF030203FF02B602FF037902FF043603FF033803FF020301FF0105 25 | 01FF033903FF033703FF037C02FF03B602FF030103FF036303FF03A403FF04FF 26 | 04FF048403FF030103FF03F803FF049603FF043903FF033903FF033F03FF033E 27 | 02FF043A04FF033304FF049D03FF03F703FF030003FF048B04FF04E203FF04F1 28 | 03FF048003FF040104FF03E303FF04FB04FF04FD03FF04FC03FF03FD03FF03FD 29 | 03FF04FA03FF04F503FF03FC02FF03E203FF030003FF048503FF04DA04FF03F0 30 | 04FF03E802FF04C402FF02EE02FF03FA02FF04FE03FF03F103FF03F302FF03F3 31 | 02FF04F003FF04F903FF03FB02FF02F001FF03C403FF03E803FF03DD03FF0479 32 | 03FF04C003FF04FF03FF03F602FF04AE03FF058D03FF05F303FF03F202FF04F2 33 | 03FF04F104FF048B03FF04B403FF02F602FF03FF02FF04C003FF046E03FF0100 34 | 01FF046A04FF04EE04FF04FA02FF046703FF042804FF04F904FF03F402FF04F4 35 | 02FF04F703FF051F03FF047103FF03FA02FF04EE03FF056104FF020001FF0000 36 | 00FF020902FF042504FF04F402FF03F003FF04E604FF04FF04FF03FF02FF03FF 37 | 03FF04FF04FF05DB04FF04F203FF05F203FF042304FF010801FF000000FF0000 38 | 00FF000000FF020501FF036502FF03C103FF04E903FF037303FF027502FF0375 39 | 03FF047203FF04E803FF04C103FF026702FF020302FF000000FF000000FF0000 40 | 00FF000000FF010201FF031802FF048903FF03B303FF010001FF000000FF0000 41 | 00FF010001FF04B604FF048103FF010E01FF010201FF000000FF000000FF0000 42 | 00FF000000FF031303FF04FF03FF047B04FF030402FF010101FF000000FF0000 43 | 00FF010001FF030603FF048603FF04F503FF041003FF000000FF000000FF0101 44 | 01FF010101FF030803FF045403FF032603FF020002FF010101FF010101FF0101 45 | 01FF010101FF020002FF042C03FF035502FF030703FF020101FF010101FF0202 46 | 02FF020202FF020102FF020002FF020002FF020202FF020202FF020202FF0202 47 | 02FF020202FF020202FF020002FF020002FF020102FF020202FF020202FF0101 48 | 01FF020202FF020202FF020202FF020202FF020202FF020202FF020202FF0202 49 | 02FF020202FF020202FF020202FF020202FF020202FF020202FF020202FF0000 50 | 0000000000000000000000000000000000000000000000000000000000000000 51 | 000000000000000000000000000000000000000000000000000000000000} 52 | KeyPreview = True 53 | OldCreateOrder = False 54 | Position = poScreenCenter 55 | ShowHint = True 56 | OnKeyDown = FormKeyDown 57 | PixelsPerInch = 96 58 | TextHeight = 13 59 | object GroupBox1: TGroupBox 60 | Left = 8 61 | Top = 8 62 | Width = 217 63 | Height = 241 64 | Caption = '&Card' 65 | TabOrder = 0 66 | object Label1: TLabel 67 | Left = 16 68 | Top = 51 69 | Width = 92 70 | Height = 13 71 | Caption = 'Card Serial &Number' 72 | FocusControl = ED_Serial 73 | end 74 | object Label2: TLabel 75 | Left = 16 76 | Top = 96 77 | Width = 118 78 | Height = 13 79 | Caption = 'Configuration &Block Data' 80 | FocusControl = ED_ConfigBlock 81 | end 82 | object Label3: TLabel 83 | Left = 16 84 | Top = 144 85 | Width = 108 86 | Height = 13 87 | Caption = 'Application issuer &data' 88 | FocusControl = ED_AppIssuer 89 | end 90 | object CB_Readers: TComboBox 91 | Left = 16 92 | Top = 24 93 | Width = 179 94 | Height = 21 95 | Style = csDropDownList 96 | TabOrder = 0 97 | end 98 | object ED_Serial: TEdit 99 | Left = 16 100 | Top = 67 101 | Width = 179 102 | Height = 24 103 | Color = clInfoBk 104 | Font.Charset = DEFAULT_CHARSET 105 | Font.Color = clWindowText 106 | Font.Height = -13 107 | Font.Name = 'Courier New' 108 | Font.Style = [] 109 | ParentFont = False 110 | ReadOnly = True 111 | TabOrder = 1 112 | end 113 | object ED_ConfigBlock: TEdit 114 | Left = 16 115 | Top = 115 116 | Width = 179 117 | Height = 24 118 | Color = clInfoBk 119 | Font.Charset = DEFAULT_CHARSET 120 | Font.Color = clWindowText 121 | Font.Height = -13 122 | Font.Name = 'Courier New' 123 | Font.Style = [] 124 | ParentFont = False 125 | ReadOnly = True 126 | TabOrder = 2 127 | end 128 | object ED_AppIssuer: TEdit 129 | Left = 16 130 | Top = 163 131 | Width = 179 132 | Height = 24 133 | Color = clInfoBk 134 | Font.Charset = DEFAULT_CHARSET 135 | Font.Color = clWindowText 136 | Font.Height = -13 137 | Font.Name = 'Courier New' 138 | Font.Style = [] 139 | ParentFont = False 140 | ReadOnly = True 141 | TabOrder = 3 142 | end 143 | object BT_CardReload: TBitBtn 144 | Left = 14 145 | Top = 205 146 | Width = 181 147 | Height = 25 148 | Hint = 'Press F5 to reload card info' 149 | Caption = '&Reload' 150 | Glyph.Data = { 151 | 42040000424D4204000000000000420000002800000010000000100000000100 152 | 200003000000000400006D0B00006D0B000000000000000000000000FF0000FF 153 | 0000FF000000DFDEDF00B4C6B8056CA675046EAA78046FAB79046FAB79056EAA 154 | 77056BA77405A1BDA605D2D6D301D6D8D701E0DEE000DFDEDF00DDDDDD00DDDD 155 | DD00DDDDDD00DFDEDF00B2C5B606219230050CB1240018C339001ECB45001DCA 156 | 43000CB2250155A05F04639A6E083F964C0479AD8104C1CCC303DFDEDF00DDDD 157 | DD00DDDDDD00DDDDDD00E0DEDF00A3BEA8061CA032041BCF3E0025DD500026DE 158 | 510016C736005EA96902B8C7BC05399A49070AA922012B9C3B04A1BDA604DFDE 159 | DE00DDDDDD00DEDDDE00D8D9D80174AB7C0613A2270318C9370020D5450020D5 160 | 460014C4330061AB6D04E2DEE100B9C8BC052AA7410415C83600259E3703B5C6 161 | B804E0DEDF00DDDCDD0179AD8007069A10020AB81C0015C630001ACE3B001ACE 162 | 3B0011BF2D0062AA6E06DFDDDE01DFDDDF0173AD7E0617C0370113C2320057A3 163 | 6205DADADB01A9C1AD0615951D0400A8060008B316000FBD26001BAB34031CA7 164 | 34030AB5210063A96E04DFDDDF00E0DFE000AAC2AF0419AC320216CC350021A1 165 | 3303B9C7BB044F9D580800A1070000A8070003AD0F001E9F2F039ABAA00596B9 166 | 9D071298240465A86E01DFDDDF00DFDEDF00B5C7B90418A42C0212C42A0010A9 167 | 24018DB393041A92260604AE110001AA0900059B0F0187B28E05E0DEE000DFDD 168 | DE018CB393078BB29205DFDEDF00E1DFE0009CBBA1050BA11B020BB91D0009AA 169 | 1B0071A879040F971F050CB91F0003AD0E002D973604CFD3D002DFDEDE00D4D8 170 | D501B2C4B604D8DAD902DEDEDE00DCDBDC0257A0600600A3090004AF0F0004A2 171 | 100173A97B041E9F330611C12A0005AE140058A26004DEDCDE01DFDEDF00B8C9 172 | BB0221852E0491B69705DFDDDF0190B496070C95150300A7050000A806000797 173 | 110195B69B0542A3540715C4320007B0190062A56A04DFDDDF00DFDEDF00B5C7 174 | B9020E9417011A9323035E9D670613941C0300A5050000A7060000A504002A94 175 | 3304C7CFC90383B38D0719BB39020CBC2300419B4A04D8D9D902E0DFE000B3C6 176 | B7070D97170400A40500009B060000A6050000A7060000A8050004960C0183AF 177 | 8A05DFDEDF00C9D1CB043EAA540614C73300149B2002ADC2B104E3E0E200B2C5 178 | B605119E200300A9070000A7060000A7060000A70600019A0A01599F6205D5D7 179 | D602DEDEDE00E0DEDF00A9C2AE062BAC46040AB42300449D4F04D1D5D202B3C6 180 | B70318A92E0204AF0F0002A90A0001AA09000099060047935107D2D6D303DEDE 181 | DE00DDDDDD00DDDDDD00DEDDDE00B0C5B4054DAA5F0717982B044E965A0698B6 182 | 9E0521B53F0115C8310012C12A000FBD240007AF160021962E03A4BFA903DEDD 183 | DE00DDDDDD00DDDDDD00DDDDDD00E0DEDF00D5D7D603AAC2AF067FAC870794B4 184 | 9B09209F3E0514AA350411A32E0612A02C04139E2A0109901C03418E4E08D5D8 185 | D602DEDDDE00} 186 | TabOrder = 4 187 | OnClick = BT_CardReloadClick 188 | end 189 | end 190 | object CB_Authenticate: TGroupBox 191 | Left = 8 192 | Top = 255 193 | Width = 217 194 | Height = 162 195 | Caption = '&Authenticate Key' 196 | TabOrder = 1 197 | object ED_AuthKey: TComboBox 198 | Left = 16 199 | Top = 36 200 | Width = 179 201 | Height = 24 202 | Enabled = False 203 | Font.Charset = DEFAULT_CHARSET 204 | Font.Color = clWindowText 205 | Font.Height = -13 206 | Font.Name = 'Courier New' 207 | Font.Style = [] 208 | MaxLength = 16 209 | ParentFont = False 210 | TabOrder = 0 211 | Text = 'Choose Key...' 212 | Items.Strings = ( 213 | 'F0E1D2C3B4A59687' 214 | '7665544332211000' 215 | '6EFD46EFCBB3C875' 216 | 'E033CA419AEE43F9') 217 | end 218 | object RG_KeyType: TRadioGroup 219 | Left = 16 220 | Top = 66 221 | Width = 179 222 | Height = 39 223 | Caption = 'Key &Type' 224 | Columns = 3 225 | Enabled = False 226 | ItemIndex = 0 227 | Items.Strings = ( 228 | 'Auto' 229 | 'Kd (&1)' 230 | 'Kc (&2)') 231 | TabOrder = 1 232 | end 233 | object ST_AuthKey: TStaticText 234 | Left = 16 235 | Top = 18 236 | Width = 29 237 | Height = 17 238 | Caption = '&Key' 239 | FocusControl = ED_AuthKey 240 | TabOrder = 2 241 | end 242 | object BT_Auth: TBitBtn 243 | Left = 16 244 | Top = 119 245 | Width = 179 246 | Height = 25 247 | Caption = '&Authenticate' 248 | Enabled = False 249 | Glyph.Data = { 250 | 42040000424D4204000000000000420000002800000010000000100000000100 251 | 200003000000000400006D0B00006D0B000000000000000000000000FF0000FF 252 | 0000FF000000DDDDDD00DDDDDD00DCDCDC01BCBCBC09C9C9C906DDDDDD01DDDD 253 | DD00DDDDDD00DDDDDD00DDDDDD00DEDDDD00E0DEDD00DEDEDD00DDDDDD00DDDD 254 | DD00DDDDDD00DDDDDD00DDDDDD00D8D8D803A9A9A906A9A9A905C8C8C806DDDD 255 | DD00DDDDDD00DDDDDD00DEDDDD00D3D7DB03B0C7D906C4D0D904DEDDDD00DDDD 256 | DD00DDDDDD00DDDDDD00DDDDDD00D8D8D802B4B4B405B0B0B000B8B8B806DDDD 257 | DD00DDDDDD00DDDDDD00D6D9DB0385B9DF084AACE1038FBCD505DFDEDD00DDDD 258 | DD00DDDDDD00DDDDDD00DDDDDD00DCDCDC01BFBFBF06B5B5B500B3B3B306DDDD 259 | DD01DDDDDD00DEDDDD00D1D5DA0466B3E60646B4E40094C4DA06DFDDDD00DDDD 260 | DD00DDDDDD00DDDDDD00DDDDDD00DDDDDD00C9C9C906C1C1C101B9B9B905D1D1 261 | D104DEDEDE00DEDDDD00BACBDA0753AEE5044EB8E102B6CFDA05DFDEDD00DDDD 262 | DD00DDDDDD00DDDDDD00DDDDDD00DEDEDE00D1D1D105CACACA02C7C7C702C8C8 263 | C706DEDEDD00DBDBDB0288BFE2094CBDE80062BDDF04D0D7DB03DEDDDD00DDDD 264 | DD00DDDDDD00DDDDDD00DDDDDD00DDDDDD00D6D6D604D0D0D004DDDDDD00BAC1 265 | C705C2C9CE06A8C3D70768C4EC044CBFE50081C5DC06DCDCDC01DDDDDD00DDDD 266 | DD00DDDDDD00DDDDDD00DDDDDD00DDDDDD00D4D4D405D6D5D505D4DCE50071BB 267 | EB0164CAE40368C5E50258D5F4004EC2E201A7CEDB05DFDDDD00DDDDDD00DDDD 268 | DD00DDDDDD00DDDDDD00DDDDDD00D5D5D504D6D6D606EDEDEC01AECFED0057C4 269 | FB0056DDFF005CE7FE005CE2F9005BD0EB02B5CFD805DEDDDD00DDDDDD00DDDD 270 | DD00DDDDDD00DDDDDD00DDDDDD00D5D5D504E5E5E504E4E8EB008AC5EF004EC4 271 | FE0059C0E6006DC9DE0061DFF2005DE4FB006CD4EB04BDD3DA04DFDDDD00DDDD 272 | DD00DDDDDD00DDDDDD00DDDDDD00D9D9D903E6E6E505CFDEE7006FBFF50040B7 273 | FE0063A8CB009FA7AB0095AFB3006AC9D8005BDEF702B0D1DB05DFDDDD00DDDD 274 | DD00DDDDDD00DDDDDD00DDDDDD00DBDBDB01D8D8D705CFDFE70080C6F50048B3 275 | FE0044B5F60053ADD80079A0B00094A9AC006ECCDD04C8D7DB04DEDDDD00DDDD 276 | DD00DDDDDD00DDDDDD00DDDDDD00DBDBDB01C8C8C706D0D2D200BACAD20197C5 277 | E1026CC0F40251C3FF0054BDEA0097A7AC008DB9C505D7DBDC02DDDDDD00DDDD 278 | DD00DDDDDD00DDDDDD00DDDDDD00DCDCDC01D2D2D207CACAC903C1C1C00ACBCD 279 | CD07C2D0D7089BC6E00884B6D0039FA9AE02ABBFC807DEDEDE00DDDDDD00DDDD 280 | DD00DDDDDD00DDDDDD00DDDDDD00DDDDDD00D9D9D903D6D6D607CECECE06C7C7 281 | C709C6C6C50AC1C1C107BABABA06BEC1C308D5D8DA03DEDDDD00DDDDDD00DDDD 282 | DD00DDDDDD00DDDDDD00DDDDDD00DDDDDD00DDDDDD00D9D9D903D3D3D307CECE 283 | CE07C9C9C907C8C8C807D0D0D006DCDCDC01DEDDDD00DDDDDD00DDDDDD00DDDD 284 | DD00DDDDDD00} 285 | ModalResult = 8 286 | TabOrder = 3 287 | OnClick = BT_AuthClick 288 | OnMouseDown = ClearStatusPanel 289 | end 290 | end 291 | object GroupBox3: TGroupBox 292 | Left = 237 293 | Top = 8 294 | Width = 484 295 | Height = 409 296 | Caption = 'Da&ta Blocks' 297 | TabOrder = 2 298 | object BT_ReadCard: TButton 299 | Left = 162 300 | Top = 22 301 | Width = 90 302 | Height = 25 303 | Caption = 'R&ead Card' 304 | Enabled = False 305 | TabOrder = 0 306 | OnClick = BT_ReadCardClick 307 | end 308 | object CB_Decrypt: TCheckBox 309 | Left = 274 310 | Top = 26 311 | Width = 87 312 | Height = 17 313 | Caption = 'Decrypt &ACA' 314 | Checked = True 315 | Enabled = False 316 | State = cbChecked 317 | TabOrder = 1 318 | end 319 | object Memo: TRichEdit 320 | Left = 18 321 | Top = 53 322 | Width = 247 323 | Height = 338 324 | Font.Charset = ANSI_CHARSET 325 | Font.Color = clWindowText 326 | Font.Height = -13 327 | Font.Name = 'Courier New' 328 | Font.Pitch = fpFixed 329 | Font.Style = [] 330 | ParentFont = False 331 | PopupMenu = PopupMenu 332 | ReadOnly = True 333 | ScrollBars = ssVertical 334 | TabOrder = 2 335 | OnMouseDown = MemoMouseDown 336 | end 337 | object PN_Select: TComboBox 338 | Left = 18 339 | Top = 26 340 | Width = 129 341 | Height = 21 342 | TabOrder = 3 343 | Text = 'Book Number' 344 | OnChange = BT_ReadCardClick 345 | Items.Strings = ( 346 | '00' 347 | '01' 348 | '02' 349 | '03' 350 | '04' 351 | '05' 352 | '06' 353 | '07' 354 | '10' 355 | '11' 356 | '12' 357 | '13' 358 | '14' 359 | '15' 360 | '16' 361 | '17') 362 | end 363 | object Memo1: TMemo 364 | Left = 271 365 | Top = 53 366 | Width = 199 367 | Height = 338 368 | Lines.Strings = ( 369 | 'Configuration' 370 | '-----------------') 371 | TabOrder = 4 372 | end 373 | end 374 | object StatusBar: TStatusBar 375 | Left = 0 376 | Top = 422 377 | Width = 727 378 | Height = 19 379 | Panels = <> 380 | SimplePanel = True 381 | end 382 | object Timer: TTimer 383 | Interval = 200 384 | Left = 424 385 | Top = 96 386 | end 387 | object PopupMenu: TPopupMenu 388 | Left = 424 389 | Top = 144 390 | object BT_CopyToClipboard: TMenuItem 391 | Caption = '&Copy to Clipboard' 392 | OnClick = BT_CopyToClipboardClick 393 | end 394 | end 395 | end 396 | -------------------------------------------------------------------------------- /uMain.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | #ifndef uMainH 3 | #define uMainH 4 | //--------------------------------------------------------------------------- 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | //--------------------------------------------------------------------------- 14 | class TFM_Main:public TForm 15 | { 16 | __published: // Von der IDE verwaltete Komponenten 17 | TGroupBox * GroupBox1; 18 | TComboBox *CB_Readers; 19 | TGroupBox *CB_Authenticate; 20 | TComboBox *ED_AuthKey; 21 | TRadioGroup *RG_KeyType; 22 | TStaticText *ST_AuthKey; 23 | TLabel *Label1; 24 | TEdit *ED_Serial; 25 | TLabel *Label2; 26 | TEdit *ED_ConfigBlock; 27 | TLabel *Label3; 28 | TEdit *ED_AppIssuer; 29 | TBitBtn *BT_CardReload; 30 | TBitBtn *BT_Auth; 31 | TGroupBox *GroupBox3; 32 | TButton *BT_ReadCard; 33 | TCheckBox *CB_Decrypt; 34 | TStatusBar *StatusBar; 35 | TRichEdit *Memo; 36 | TTimer *Timer; 37 | TPopupMenu *PopupMenu; 38 | TMenuItem *BT_CopyToClipboard; 39 | TComboBox *PN_Select; 40 | TMemo *Memo1; 41 | void __fastcall FormKeyDown (TObject * Sender, WORD & Key, 42 | TShiftState Shift); 43 | void __fastcall BT_CardReloadClick (TObject * Sender); 44 | void __fastcall BT_CardCloseClick (TObject * Sender); 45 | void __fastcall BT_AuthClick (TObject * Sender); 46 | void __fastcall ClearStatusPanel (TObject * Sender, TMouseButton Button, 47 | TShiftState Shift, int X, int Y); 48 | void __fastcall BT_ReadCardClick (TObject * Sender); 49 | void __fastcall MemoKeyPress (TObject * Sender, wchar_t & Key); 50 | void __fastcall MemoMouseDown (TObject * Sender, TMouseButton Button, 51 | TShiftState Shift, int X, int Y); 52 | void __fastcall BT_CopyToClipboardClick (TObject * Sender); 53 | void __fastcall PageSelect (int P2); 54 | void __fastcall CardConfig (UCHAR block); 55 | void __fastcall CardePurse (UCHAR block); 56 | private: // Anwender-Deklarationen 57 | SCARDCONTEXT hContext; 58 | SCARDHANDLE hCard; 59 | TStringList *m_PrevLines; 60 | UnicodeString __fastcall CardSelect (UCHAR p2); 61 | int __fastcall CardAuth (__int64 key, UCHAR type); 62 | UnicodeString __fastcall HexDump (PUCHAR data, ULONG len); 63 | UnicodeString __fastcall CardRead (UCHAR block); 64 | 65 | void __fastcall PrettyPrint (void); 66 | void __fastcall SetLineNumberColor (int Line, TColor Color); 67 | 68 | public: // Anwender-Deklarationen 69 | __fastcall TFM_Main (TComponent * Owner); 70 | __fastcall ~ TFM_Main (void); 71 | }; 72 | //--------------------------------------------------------------------------- 73 | extern PACKAGE TFM_Main *FM_Main; 74 | //--------------------------------------------------------------------------- 75 | #endif 76 | --------------------------------------------------------------------------------