diff --git a/.gitignore b/.gitignore index bad050e8f..e37ce9534 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ .history .bash_history +.bash_profile +.bash_logout +.bashrc +.inputrc +.profile *.log *.eml *.o diff --git a/CHANGELOG.md b/CHANGELOG.md index de1f4f293..c78d813db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,35 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Add 'hw standalone' to jump to standalone mode from command line or script (@doegox) + - Add to 'hf 14a apdu' print apdu and compose apdu (@merlokk) + - Change: buggy 'mem read' removed, 'mem save' renamed 'mem dump', can now display too (@doegox) + - Fix: timeout for mem wipe was too short, thanks @cjbrigato (@doegox) + - Fix 'hf mf sim' - Mifare Classic simulation more flexible anti-collision check (@McEloff) + - Change: 'hf mf sim' - Mifare Classic simulation not respond NACK on invalid authentication request (@McEloff) + - Change: 'read_pwd_mem.lua' now handles Mifare Classic dictionaries large than 4096 bytes (@iceman) + - Change: Don't clear trace log during 'hf mf chk', to save whole process history (@McEloff) + - Add 'msleep' command, for pauses in scripts (@doegox) + - Add support for WSL in proxmark.sh (@doegox) + - Add documentation for usage of Proxmark3 under WSL (@doegox) + - Change: replace aes.c with mbedtls version (@slurdge) + - Change: replace ukbhit by kbd_enter_pressed, not requiring tcgetattr (@xianglin1998/@doegox) + - Add config for RaspberryPi in JTAG tools (@doegox) + - Add config for FTDI C232HM-DDHSL-0 in JTAG tools (@doegox) + - Fix compilation under MacOSX with binutils (@matrix) + - Add dynamic report of the chipID for flashing purposes (@slurdge) + - Fix Clang warnings (@matrix) + - Fix EMVGPO bug (@matrix) + - Add hitag2 write password auth (@ViRb3) + - Add check if bootloader segment is within bounds (@slurdge) + - Add 'hf 15 csetuid' - set UID on ISO-15693 Magic tags (@t0m4-null) + - Change: Print help if unknown arg for hitag reader/writer (@ViRb3) + - Fix clock deadlock in hitag sniff (@ViRb3) + - Add compiler info in client & ARM sections (@slurdge) + - Add support for automatic COM detection on Windows (@slurdge) + - Add support for compilation on RaspberryPiZero (armv6) (@doegox) - Change: updates to README (@iceman) - - Change: hf mf/mfu dbg => hw dbg (@doegox) + - Change: 'hf mf/mfu dbg' => 'hw dbg' (@doegox) - Change: replace usb_poll_validate_length() by data_available() that supports USART too (@doegox) - Make sure standalone modes can be launched when connected on USB without client (@doegox) - Change: cleaner makefile execution, use 'make V=1' if you want to see full lines (@doegox) diff --git a/Makefile b/Makefile index 910aa62f6..64dbea4eb 100644 --- a/Makefile +++ b/Makefile @@ -145,12 +145,12 @@ style: # Make sure astyle is installed @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 ) # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile - find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ + find . \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ -exec perl -pi -e 's/[ \t]+$$//' {} \; \ -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \ -exec sh -c "echo >> {}" \; # Apply astyle on *.c, *.h, *.cpp - find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \ + find . \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) \) -exec astyle --formatted --mode=c --suffix=none \ --indent=spaces=4 --indent-switches \ --keep-one-line-blocks --max-instatement-indent=60 \ --style=google --pad-oper --unpad-paren --pad-header \ diff --git a/README.md b/README.md index b61ec89f7..a1e7ad76c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,11 @@ # Proxmark3 RDV4.0 Dedicated Github -This repo is based on iceman fork for proxmark3. It is dedicated to bringing the most out of the new features for proxmark3 RDV4.0 new hardware and design. +This repo is based on iceman fork for Proxmark3. It is dedicated to bringing the most out of the new features for Proxmark3 RDV4.0 new hardware and design. +Note that it also supports other Proxmark3 platforms as well! [![Build status](https://ci.appveyor.com/api/projects/status/ct5blik2wa96bv0x/branch/master?svg=true)](https://ci.appveyor.com/project/iceman1001/proxmark3-ji4wj/branch/master) [![Latest release](https://img.shields.io/github/release/RfidResearchGroup/proxmark3.svg)](https://github.com/RfidResearchGroup/proxmark3/releases/latest) - - --- # PROXMARK INSTALLATION AND OVERVIEW @@ -19,9 +16,11 @@ alt="Yuotube" width="100%" height="auto" border="10" /> |[Development](#development) | [Important notes on ModemManager for Linux users](/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md) | [Validating proxmark client functionality](/doc/md/Use_of_Proxmark/1_Validation.md) | |[Why didn't you base it on official PM3 Master?](#why-didnt-you-base-it-on-official-pm3-master)| [Homebrew (Mac OS X) & Upgrading HomeBrew Tap Formula](/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md) | [First Use and Verification](/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md)| |[PM3 GUI](#pm3-gui)|[Setup and build for Windows](/doc/md/Installation_Instructions/Windows-Installation-Instructions.md)|[Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| -|[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) || +|[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) |[Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md)| |[Notes on UART](/doc/uart_notes.md)||| |[Notes on Frame format](/doc/new_frame_format.md)||| +|[Notes on Termux / Android](/doc/termux_notes.md)||| +|[Developing standalone mode](/armsrc/Standalone/readme.md)|[Wiki about standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) || |[Donations](#Donations)||| ## What has changed? @@ -45,17 +44,20 @@ This fork now compiles just fine on If you intend to contribute to the code, please read the [coding style notes](HACKING.md) first. -Internal notes on [Coverity Scan Config & Run](/doc/md/Development/Coverity-Scan-Config-%26-Run.md). +- Internal notes on [Coverity Scan Config & Run](/doc/md/Development/Coverity-Scan-Config-%26-Run.md). +- Internal notes on UART +- Internal notes on Frame format +- Internal notes on standalone mode ---- -## Why didn't you base it on official PM3 Master? -The separation from official pm3 repo gives us a lot of freedom to create a firmware/client that suits the RDV40 features. We don't want to mess up the official pm3 repo with RDV40 specific code. +## Why didn't you base it on official Proxmark3 Master? -## PM3 GUI +The separation from official Proxmark3 repo gives us a lot of freedom to create a firmware/client that suits the RDV40 features. We don't want to mess up the official Proxmark3 repo with RDV40 specific code. + +## Proxmark3 GUI The official PM3-GUI from Gaucho will not work. -The new universal GUI will work. [Proxmark3 Universal GUI](https://github.com/burma69/PM3UniversalGUI) +The new universal GUI will work. [Proxmark3 Universal GUI](https://github.com/burma69/PM3UniversalGUI) Almost, change needed in order to show helptext when client isn't connected to a device. ## Issues @@ -69,4 +71,8 @@ It's needed to have a good USB cable to connect Proxmark3 to USB. If you have st - updated Feb 2019 [@5w0rdfish](https://mobile.twitter.com/5w0rdFish) # Donations -Nothing says thank you as much as a donation, https://www.patreon.com/iceman1001 +Nothing says thank you as much as a donation. So if you feel the love, do feel free to become a iceman patron. For some tiers it comes with rewards. + +https://www.patreon.com/iceman1001 + +All support is welcome! diff --git a/armsrc/Makefile b/armsrc/Makefile index 7fda76b99..6d3921084 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -30,7 +30,7 @@ SRC_ISO15693 = iso15693.c iso15693tools.c SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c SRC_ISO14443b = iso14443b.c SRC_FELICA = felica.c -SRC_CRAPTO1 = crypto1.c des.c aes.c desfire_key.c desfire_crypto.c mifaredesfire.c +SRC_CRAPTO1 = crypto1.c des.c desfire_key.c desfire_crypto.c mifaredesfire.c aes.c platform_util.c SRC_CRC = crc.c crc16.c crc32.c SRC_ICLASS = iclass.c optimized_cipher.c SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c @@ -68,41 +68,7 @@ else endif # Generic standalone Mode injection of source code - - -SRC_STANDALONE = placeholder.c -# WITH_STANDALONE_LF_ICERUN -ifneq (,$(findstring WITH_STANDALONE_LF_ICERUN,$(APP_CFLAGS))) - SRC_STANDALONE = lf_icerun.c -endif -# WITH_STANDALONE_LF_SAMYRUN -ifneq (,$(findstring WITH_STANDALONE_LF_SAMYRUN,$(APP_CFLAGS))) - SRC_STANDALONE = lf_samyrun.c -endif -# WITH_STANDALONE_LF_PROXBRUTE -ifneq (,$(findstring WITH_STANDALONE_LF_PROXBRUTE,$(APP_CFLAGS))) - SRC_STANDALONE = lf_proxbrute.c -endif -# WITH_STANDALONE_LF_HIDBRUTE -ifneq (,$(findstring WITH_STANDALONE_LF_HIDBRUTE,$(APP_CFLAGS))) - SRC_STANDALONE = lf_hidbrute.c -endif -# WITH_STANDALONE_HF_YOUNG -ifneq (,$(findstring WITH_STANDALONE_HF_YOUNG,$(APP_CFLAGS))) - SRC_STANDALONE = hf_young.c -endif -# WITH_STANDALONE_HF_MATTYRUN -ifneq (,$(findstring WITH_STANDALONE_HF_MATTYRUN,$(APP_CFLAGS))) - SRC_STANDALONE = hf_mattyrun.c -endif -# WITH_STANDALONE_HF_COLIN -ifneq (,$(findstring WITH_STANDALONE_HF_COLIN,$(APP_CFLAGS))) - SRC_STANDALONE = vtsend.c hf_colin.c -endif -# WITH_STANDALONE_HF_BOG -ifneq (,$(findstring WITH_STANDALONE_HF_BOG,$(APP_CFLAGS))) - SRC_STANDALONE = hf_bog.c -endif +include Standalone/Makefile.inc #the FPGA bitstream files. Note: order matters! FPGA_BITSTREAMS = fpga_lf.bit fpga_hf.bit diff --git a/armsrc/Standalone/Makefile.hal b/armsrc/Standalone/Makefile.hal new file mode 100644 index 000000000..6181b5072 --- /dev/null +++ b/armsrc/Standalone/Makefile.hal @@ -0,0 +1,46 @@ +# Default standalone if no standalone specified +DEFAULT_STANDALONE=LF_SAMYRUN +HELP_EXAMPLE_STANDALONE=HF_COLIN +# (you can set explicitly STANDALONE= to disable standalone modes) +STANDALONE?=$(DEFAULT_STANDALONE) + +define KNOWN_STANDALONE_DEFINITIONS ++==========================================================+ +| STANDALONE | DESCRIPTION | ++==========================================================+ +| | No standalone mode | ++----------------------------------------------------------+ +| LF_SAMYRUN (def)| HID26 read/clone/sim | +| | - Samy Kamkar | ++----------------------------------------------------------+ +| LF_ICERUN | standalone mode skeleton | +| | - iceman | ++----------------------------------------------------------+ +| LF_PROXBRUTE | HID ProxII bruteforce | +| | - Brad Antoniewicz | ++----------------------------------------------------------+ +| LF_HIDBRUTE | HID corporate 1000 bruteforce | +| | - Federico dotta & Maurizio Agazzini | ++----------------------------------------------------------+ +| HF_YOUNG | Mifare sniff/simulation | +| | - Craig Young | ++----------------------------------------------------------+ +| HF_MATTYRUN | Mifare sniff/clone | +| | - Matías A. Ré Medina | ++----------------------------------------------------------+ +| HF_COLIN | Mifare ultra fast sniff/sim/clone | +| | - Colin Brigato | ++----------------------------------------------------------+ +| HF_BOG | 14a sniff with ULC/ULEV1/NTAG auth | +| | storing in flashmem - Bogito | ++----------------------------------------------------------+ + +endef + +STANDALONE_MODES := LF_SAMYRUN LF_ICERUN LF_PROXBRUTE LF_HIDBRUTE +STANDALONE_MODES += HF_YOUNG HF_MATTYRUN HF_COLIN HF_BOG +ifneq ($(filter $(STANDALONE),$(STANDALONE_MODES)),) + STANDALONE_PLATFORM_DEFS += -DWITH_STANDALONE_$(STANDALONE) +else ifneq ($(STANDALONE),) + $(error Invalid STANDALONE: $(STANDALONE). $(KNOWN_DEFINITIONS)) +endif diff --git a/armsrc/Standalone/Makefile.inc b/armsrc/Standalone/Makefile.inc new file mode 100644 index 000000000..cc7221a73 --- /dev/null +++ b/armsrc/Standalone/Makefile.inc @@ -0,0 +1,36 @@ +# Generic standalone Mode injection of source code + +SRC_STANDALONE = placeholder.c +# WITH_STANDALONE_LF_ICERUN +ifneq (,$(findstring WITH_STANDALONE_LF_ICERUN,$(APP_CFLAGS))) + SRC_STANDALONE = lf_icerun.c +endif +# WITH_STANDALONE_LF_SAMYRUN +ifneq (,$(findstring WITH_STANDALONE_LF_SAMYRUN,$(APP_CFLAGS))) + SRC_STANDALONE = lf_samyrun.c +endif +# WITH_STANDALONE_LF_PROXBRUTE +ifneq (,$(findstring WITH_STANDALONE_LF_PROXBRUTE,$(APP_CFLAGS))) + SRC_STANDALONE = lf_proxbrute.c +endif +# WITH_STANDALONE_LF_HIDBRUTE +ifneq (,$(findstring WITH_STANDALONE_LF_HIDBRUTE,$(APP_CFLAGS))) + SRC_STANDALONE = lf_hidbrute.c +endif +# WITH_STANDALONE_HF_YOUNG +ifneq (,$(findstring WITH_STANDALONE_HF_YOUNG,$(APP_CFLAGS))) + SRC_STANDALONE = hf_young.c +endif +# WITH_STANDALONE_HF_MATTYRUN +ifneq (,$(findstring WITH_STANDALONE_HF_MATTYRUN,$(APP_CFLAGS))) + SRC_STANDALONE = hf_mattyrun.c +endif +# WITH_STANDALONE_HF_COLIN +ifneq (,$(findstring WITH_STANDALONE_HF_COLIN,$(APP_CFLAGS))) + SRC_STANDALONE = vtsend.c hf_colin.c +endif +# WITH_STANDALONE_HF_BOG +ifneq (,$(findstring WITH_STANDALONE_HF_BOG,$(APP_CFLAGS))) + SRC_STANDALONE = hf_bog.c +endif + diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index 0ee0a9066..ca0b0eeeb 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -15,7 +15,7 @@ The retrieved sniffing session can be acquired by connecting the device to a client that supports the reconnect capability and issue 'hf 14a list'. In order to view the grabbed authentication attempts in the flash mem, -you can simply run 'script run read_pwd_mem' or just 'mem read l 256' +you can simply run 'script run read_pwd_mem' or just 'mem dump p l 256' from the client to view the stored quadlets. */ @@ -282,7 +282,7 @@ void RAMFUNC SniffAndStore(uint8_t param) { } void ModInfo(void) { - DbpString(" HF 14a sniff standalone with ULC/ULEV1/NTAG auth storing in flashmem - aka BogitoRun (Bogito)"); + DbpString(" HF 14a sniff standalone with ULC/ULEV1/NTAG auth storing in flashmem - aka BogitoRun (Bogito)"); } void RunMod() { diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 76eefcc14..d74eaeb95 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -101,6 +101,8 @@ void ReadLastTagFromFlash() { size_t size = len; uint8_t *mem = BigBuf_malloc(size); + FlashmemSetSpiBaudrate(24000000); + if (!FlashInit()) { return; } @@ -148,6 +150,9 @@ void WriteTagToFlash(uint8_t index, size_t size) { emlGetMem(data, 0, (size * 64) / 1024); + + FlashmemSetSpiBaudrate(48000000); + if (!FlashInit()) { return; } @@ -197,7 +202,7 @@ void WriteTagToFlash(uint8_t index, size_t size) { } void ModInfo(void) { - DbpString(" HF Mifare ultra fast sniff/sim/clone - aka VIGIKPWN (Colin Brigato)"); + DbpString(" HF Mifare ultra fast sniff/sim/clone - aka VIGIKPWN (Colin Brigato)"); } void RunMod() { @@ -424,7 +429,7 @@ failtag: //----------------------------------------------------------------------------- // also we could avoid first UID check for every block - // then let’s expose this “optimal case” of “well known vigik schemes” : + // then let's expose this “optimal case” of “well known vigik schemes” : for (uint8_t type = 0; type < 2 && !err && !trapped; type++) { for (int sec = 0; sec < sectorsCnt && !err && !trapped; ++sec) { key = cjat91_saMifareChkKeys(sec * 4, type, NULL, size, &keyBlock[0], &key64); @@ -783,10 +788,18 @@ readysim: case 7: flags = FLAG_7B_UID_IN_DATA; break; - default: + case 4: flags = FLAG_4B_UID_IN_DATA; break; + default: + flags = FLAG_UID_IN_EMUL; + break; } + + // Use UID, SAK, ATQA from EMUL, if uid not defined + //if ((flags & (FLAG_4B_UID_IN_DATA | FLAG_7B_UID_IN_DATA | FLAG_10B_UID_IN_DATA)) == 0) { + flags |= FLAG_UID_IN_EMUL; + //} Mifare1ksim(flags | FLAG_MF_1K, 0, cjuid); LED_C_OFF(); SpinOff(50); @@ -902,7 +915,7 @@ int e_MifareECardLoad(uint32_t numofsectors, uint8_t keytype) { return (isOK) ? PM3_SUCCESS : PM3_EUNDEF; } -/* the chk function is a piwi’ed(tm) check that will try all keys for +/* the chk function is a piwi'ed(tm) check that will try all keys for a particular sector. also no tracing no dbg */ int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) { DBGLEVEL = DBG_NONE; diff --git a/armsrc/Standalone/hf_colin.h b/armsrc/Standalone/hf_colin.h index 8c8e391e1..9068e2d09 100644 --- a/armsrc/Standalone/hf_colin.h +++ b/armsrc/Standalone/hf_colin.h @@ -22,6 +22,7 @@ #include "iso14443a.h" #include "protocols.h" #include "util.h" +#include "pmflash.h" #include "standalone.h" // standalone definitions #include // for bool #include diff --git a/armsrc/Standalone/hf_mattyrun.c b/armsrc/Standalone/hf_mattyrun.c index 66147c2fb..9ea0ba524 100644 --- a/armsrc/Standalone/hf_mattyrun.c +++ b/armsrc/Standalone/hf_mattyrun.c @@ -193,7 +193,7 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui } void ModInfo(void) { - DbpString(" HF Mifare sniff/clone - aka MattyRun (Matías A. Ré Medina)"); + DbpString(" HF Mifare sniff/clone - aka MattyRun (Matías A. Ré Medina)"); } void RunMod() { @@ -223,6 +223,7 @@ void RunMod() { */ bool printKeys = false; // Prints keys bool transferToEml = true; // Transfer keys to emulator memory + bool ecfill = true; // Fill emulator memory with cards content. bool simulation = true; // Simulates an exact copy of the target tag bool fillFromEmulator = false; // Dump emulator memory. diff --git a/armsrc/Standalone/hf_young.c b/armsrc/Standalone/hf_young.c index 6b56935bd..906d0b36c 100644 --- a/armsrc/Standalone/hf_young.c +++ b/armsrc/Standalone/hf_young.c @@ -8,18 +8,20 @@ //----------------------------------------------------------------------------- // main code for HF standalone mode Mifare /sniff/emulation by Craig Young //----------------------------------------------------------------------------- + #include "hf_young.h" +#include "common.h" typedef struct { uint8_t uid[10]; uint8_t uidlen; uint8_t atqa[2]; uint8_t sak; -} __attribute__((__packed__)) card_clone_t; +} PACKED card_clone_t; void ModInfo(void) { - DbpString(" HF Mifare sniff/simulation - (Craig Young)"); + DbpString(" HF Mifare sniff/simulation - (Craig Young)"); } void RunMod() { diff --git a/armsrc/Standalone/lf_hidbrute.c b/armsrc/Standalone/lf_hidbrute.c index 06b0049ad..2c784c31a 100644 --- a/armsrc/Standalone/lf_hidbrute.c +++ b/armsrc/Standalone/lf_hidbrute.c @@ -27,7 +27,7 @@ #include "lf_hidbrute.h" void ModInfo(void) { - DbpString(" LF HID corporate 1000 bruteforce - aka Corporatebrute (Federico dotta & Maurizio Agazzini)"); + DbpString(" LF HID corporate 1000 bruteforce - aka Corporatebrute (Federico dotta & Maurizio Agazzini)"); } // samy's sniff and repeat routine for LF diff --git a/armsrc/Standalone/lf_icerun.c b/armsrc/Standalone/lf_icerun.c index e62c79329..eafd4ca7d 100644 --- a/armsrc/Standalone/lf_icerun.c +++ b/armsrc/Standalone/lf_icerun.c @@ -10,10 +10,9 @@ #include "lf_icerun.h" void ModInfo(void) { - DbpString(" LF skeleton mode - aka IceRun (iceman)"); + DbpString(" LF skeleton mode - aka IceRun (iceman)"); } -// samy's sniff and repeat routine for LF void RunMod() { StandAloneMode(); Dbprintf("[=] LF skeleton code a.k.a IceRun started"); diff --git a/armsrc/Standalone/lf_proxbrute.c b/armsrc/Standalone/lf_proxbrute.c index d10a1fbfe..09ddb1989 100644 --- a/armsrc/Standalone/lf_proxbrute.c +++ b/armsrc/Standalone/lf_proxbrute.c @@ -12,7 +12,7 @@ #include "lf_proxbrute.h" void ModInfo(void) { - DbpString(" LF HID ProxII bruteforce - aka Proxbrute (Brad Antoniewicz)"); + DbpString(" LF HID ProxII bruteforce - aka Proxbrute (Brad Antoniewicz)"); } // samy's sniff and repeat routine for LF diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index 03c2ddd12..07fe8bae5 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -11,7 +11,7 @@ #include "lf_samyrun.h" void ModInfo(void) { - DbpString(" LF HID26 standalone - aka SamyRun (Samy Kamkar)"); + DbpString(" LF HID26 standalone - aka SamyRun (Samy Kamkar)"); } // samy's sniff and repeat routine for LF diff --git a/armsrc/Standalone/placeholder.c b/armsrc/Standalone/placeholder.c index e179bc876..b8a426e37 100644 --- a/armsrc/Standalone/placeholder.c +++ b/armsrc/Standalone/placeholder.c @@ -2,7 +2,7 @@ #include "apps.h" // debug statements void ModInfo(void) { - DbpString(" No standalone mode present"); + DbpString(" No standalone mode present"); } void RunMod() { diff --git a/armsrc/Standalone/readme.md b/armsrc/Standalone/readme.md index 529bc7f70..4ff83b9fd 100644 --- a/armsrc/Standalone/readme.md +++ b/armsrc/Standalone/readme.md @@ -1,6 +1,6 @@ -# StandAlone Modes +# Standalone Modes -This contains functionality for different StandAlone modes. The fullimage will be built given the correct compiler flags used. Build targets for these files are contained in `armsrc/Makefile` and `common/Makefile.hal` +This contains functionality for different StandAlone modes. The fullimage will be built given the correct compiler flags used. Build targets for these files are contained in `Makefile.inc` and `Makefile.hal` If you want to implement a new standalone mode, you need to implement the methods provided in `standalone.h`. Have a look at the skeleton standalone mode called IceRun, in the files `lf_icerun.c lf_icerun.h`. @@ -19,7 +19,7 @@ The RunMod function, which is your "main" function when running. You need to ch ```` void ModInfo(void) { - DbpString(" LF good description of your mode - aka FooRun (your name)"); + DbpString(" LF good description of your mode - aka FooRun (your name)"); } void RunMod(void) { @@ -40,8 +40,6 @@ void RunMod(void) { } ```` -Each standalone mode needs to have its own compiler flag to be added in `armsrc/Makefile`. - ## Naming your standalone mode We suggest that you follow these guidelines: @@ -58,9 +56,9 @@ This leads to your next step, your DEFINE name needed in Makefile. `WITH_STANDALONE_LF_FOO` -## Update COMMON/MAKEFILE.HAL +## Update MAKEFILE.HAL -Add your mode to the `common/Makefile.hal` help and modes list: +Add your mode to the `Makefile.hal` help and modes list: ``` +==========================================================+ | STANDALONE | DESCRIPTION | @@ -74,13 +72,13 @@ STANDALONE_MODES := LF_SAMYRUN LF_ICERUN LF_PROXBRUTE LF_HIDBRUTE LF_FOO STANDALONE_MODES += HF_YOUNG HF_MATTYRUN HF_COLIN HF_BOG ``` -## Update ARMSRC/MAKEFILE -Add your source code files like the following sample in the `armsrc/Makefile` +## Update MAKEFILE.INC +Add your source code files like the following sample in the `Makefile.inc` ``` # WITH_STANDALONE_LF_ICERUN ifneq (,$(findstring WITH_STANDALONE_LF_ICERUN,$(APP_CFLAGS))) - SRC_STANDALONE = lf_icerun.c + SRC_STANDALONE = lf_icerun.c endif # WITH_STANDALONE_LF_FOO @@ -95,15 +93,44 @@ This will enable an easy way to detect on client side which standalone mode has ```` void ModInfo(void) { - DbpString(" LF good description of your mode - aka FooRun (your name)"); + DbpString(" LF good description of your mode - aka FooRun (your name)"); } ```` ## Compiling your standalone mode -Once all this is done, you and others can now easily compile different standalone modes by just selecting one of the standalone modes in `common/Makefile.hal`, e.g.: +Once all this is done, you and others can now easily compile different standalone modes by just selecting one of the standalone modes (list in `Makefile.hal` or ) , e.g.: +- rename Makefile.platform.sample -> Makefile.platform +- edit the "STANDALONE" row inside Makefile.platform. You need to uncomment it and add your standalone mode name + +Makefile.platform.sample ``` -PLATFORM_DEFS += -DWITH_STANDALONE_LF_FOO +# If you want to use it, copy this file as Makefile.platform and adjust it to your needs +PLATFORM=PM3RDV4 +#PLATFORM_EXTRAS=BTADDON +#STANDALONE=LF_SAMYRUN +``` + becomes + + Makefile.platform + ``` +# If you want to use it, copy this file as Makefile.platform and adjust it to your needs +PLATFORM=PM3RDV4 +#PLATFORM_EXTRAS=BTADDON +STANDALONE=LF_FOO ``` Remember only one can be selected at a time for now. + +The final steps is to +- force recompilation of all code. ```make clean``` +- compile ```make -j8``` +- flash your device +- connect to your device +- press button long time to trigger ledshow and enter your new standalone mode +- if connected with usb / fpc , you can also see debug statements from your device in standalone mode. Useful for debugging :) + +When compiling you will see a header showing what configurations your project compiled with. +Make sure it says your standalone mode name. + +Happy hacking! diff --git a/armsrc/aes.c b/armsrc/aes.c deleted file mode 100644 index f8a36f28c..000000000 --- a/armsrc/aes.c +++ /dev/null @@ -1,1170 +0,0 @@ -#include "aes.h" - -static const unsigned int Te0[256] = { - 0xc66363a5UL, 0xf87c7c84UL, 0xee777799UL, 0xf67b7b8dUL, - 0xfff2f20dUL, 0xd66b6bbdUL, 0xde6f6fb1UL, 0x91c5c554UL, - 0x60303050UL, 0x02010103UL, 0xce6767a9UL, 0x562b2b7dUL, - 0xe7fefe19UL, 0xb5d7d762UL, 0x4dababe6UL, 0xec76769aUL, - 0x8fcaca45UL, 0x1f82829dUL, 0x89c9c940UL, 0xfa7d7d87UL, - 0xeffafa15UL, 0xb25959ebUL, 0x8e4747c9UL, 0xfbf0f00bUL, - 0x41adadecUL, 0xb3d4d467UL, 0x5fa2a2fdUL, 0x45afafeaUL, - 0x239c9cbfUL, 0x53a4a4f7UL, 0xe4727296UL, 0x9bc0c05bUL, - 0x75b7b7c2UL, 0xe1fdfd1cUL, 0x3d9393aeUL, 0x4c26266aUL, - 0x6c36365aUL, 0x7e3f3f41UL, 0xf5f7f702UL, 0x83cccc4fUL, - 0x6834345cUL, 0x51a5a5f4UL, 0xd1e5e534UL, 0xf9f1f108UL, - 0xe2717193UL, 0xabd8d873UL, 0x62313153UL, 0x2a15153fUL, - 0x0804040cUL, 0x95c7c752UL, 0x46232365UL, 0x9dc3c35eUL, - 0x30181828UL, 0x379696a1UL, 0x0a05050fUL, 0x2f9a9ab5UL, - 0x0e070709UL, 0x24121236UL, 0x1b80809bUL, 0xdfe2e23dUL, - 0xcdebeb26UL, 0x4e272769UL, 0x7fb2b2cdUL, 0xea75759fUL, - 0x1209091bUL, 0x1d83839eUL, 0x582c2c74UL, 0x341a1a2eUL, - 0x361b1b2dUL, 0xdc6e6eb2UL, 0xb45a5aeeUL, 0x5ba0a0fbUL, - 0xa45252f6UL, 0x763b3b4dUL, 0xb7d6d661UL, 0x7db3b3ceUL, - 0x5229297bUL, 0xdde3e33eUL, 0x5e2f2f71UL, 0x13848497UL, - 0xa65353f5UL, 0xb9d1d168UL, 0x00000000UL, 0xc1eded2cUL, - 0x40202060UL, 0xe3fcfc1fUL, 0x79b1b1c8UL, 0xb65b5bedUL, - 0xd46a6abeUL, 0x8dcbcb46UL, 0x67bebed9UL, 0x7239394bUL, - 0x944a4adeUL, 0x984c4cd4UL, 0xb05858e8UL, 0x85cfcf4aUL, - 0xbbd0d06bUL, 0xc5efef2aUL, 0x4faaaae5UL, 0xedfbfb16UL, - 0x864343c5UL, 0x9a4d4dd7UL, 0x66333355UL, 0x11858594UL, - 0x8a4545cfUL, 0xe9f9f910UL, 0x04020206UL, 0xfe7f7f81UL, - 0xa05050f0UL, 0x783c3c44UL, 0x259f9fbaUL, 0x4ba8a8e3UL, - 0xa25151f3UL, 0x5da3a3feUL, 0x804040c0UL, 0x058f8f8aUL, - 0x3f9292adUL, 0x219d9dbcUL, 0x70383848UL, 0xf1f5f504UL, - 0x63bcbcdfUL, 0x77b6b6c1UL, 0xafdada75UL, 0x42212163UL, - 0x20101030UL, 0xe5ffff1aUL, 0xfdf3f30eUL, 0xbfd2d26dUL, - 0x81cdcd4cUL, 0x180c0c14UL, 0x26131335UL, 0xc3ecec2fUL, - 0xbe5f5fe1UL, 0x359797a2UL, 0x884444ccUL, 0x2e171739UL, - 0x93c4c457UL, 0x55a7a7f2UL, 0xfc7e7e82UL, 0x7a3d3d47UL, - 0xc86464acUL, 0xba5d5de7UL, 0x3219192bUL, 0xe6737395UL, - 0xc06060a0UL, 0x19818198UL, 0x9e4f4fd1UL, 0xa3dcdc7fUL, - 0x44222266UL, 0x542a2a7eUL, 0x3b9090abUL, 0x0b888883UL, - 0x8c4646caUL, 0xc7eeee29UL, 0x6bb8b8d3UL, 0x2814143cUL, - 0xa7dede79UL, 0xbc5e5ee2UL, 0x160b0b1dUL, 0xaddbdb76UL, - 0xdbe0e03bUL, 0x64323256UL, 0x743a3a4eUL, 0x140a0a1eUL, - 0x924949dbUL, 0x0c06060aUL, 0x4824246cUL, 0xb85c5ce4UL, - 0x9fc2c25dUL, 0xbdd3d36eUL, 0x43acacefUL, 0xc46262a6UL, - 0x399191a8UL, 0x319595a4UL, 0xd3e4e437UL, 0xf279798bUL, - 0xd5e7e732UL, 0x8bc8c843UL, 0x6e373759UL, 0xda6d6db7UL, - 0x018d8d8cUL, 0xb1d5d564UL, 0x9c4e4ed2UL, 0x49a9a9e0UL, - 0xd86c6cb4UL, 0xac5656faUL, 0xf3f4f407UL, 0xcfeaea25UL, - 0xca6565afUL, 0xf47a7a8eUL, 0x47aeaee9UL, 0x10080818UL, - 0x6fbabad5UL, 0xf0787888UL, 0x4a25256fUL, 0x5c2e2e72UL, - 0x381c1c24UL, 0x57a6a6f1UL, 0x73b4b4c7UL, 0x97c6c651UL, - 0xcbe8e823UL, 0xa1dddd7cUL, 0xe874749cUL, 0x3e1f1f21UL, - 0x964b4bddUL, 0x61bdbddcUL, 0x0d8b8b86UL, 0x0f8a8a85UL, - 0xe0707090UL, 0x7c3e3e42UL, 0x71b5b5c4UL, 0xcc6666aaUL, - 0x904848d8UL, 0x06030305UL, 0xf7f6f601UL, 0x1c0e0e12UL, - 0xc26161a3UL, 0x6a35355fUL, 0xae5757f9UL, 0x69b9b9d0UL, - 0x17868691UL, 0x99c1c158UL, 0x3a1d1d27UL, 0x279e9eb9UL, - 0xd9e1e138UL, 0xebf8f813UL, 0x2b9898b3UL, 0x22111133UL, - 0xd26969bbUL, 0xa9d9d970UL, 0x078e8e89UL, 0x339494a7UL, - 0x2d9b9bb6UL, 0x3c1e1e22UL, 0x15878792UL, 0xc9e9e920UL, - 0x87cece49UL, 0xaa5555ffUL, 0x50282878UL, 0xa5dfdf7aUL, - 0x038c8c8fUL, 0x59a1a1f8UL, 0x09898980UL, 0x1a0d0d17UL, - 0x65bfbfdaUL, 0xd7e6e631UL, 0x844242c6UL, 0xd06868b8UL, - 0x824141c3UL, 0x299999b0UL, 0x5a2d2d77UL, 0x1e0f0f11UL, - 0x7bb0b0cbUL, 0xa85454fcUL, 0x6dbbbbd6UL, 0x2c16163aUL, -}; -static const unsigned int Te1[256] = { - 0xa5c66363UL, 0x84f87c7cUL, 0x99ee7777UL, 0x8df67b7bUL, - 0x0dfff2f2UL, 0xbdd66b6bUL, 0xb1de6f6fUL, 0x5491c5c5UL, - 0x50603030UL, 0x03020101UL, 0xa9ce6767UL, 0x7d562b2bUL, - 0x19e7fefeUL, 0x62b5d7d7UL, 0xe64dababUL, 0x9aec7676UL, - 0x458fcacaUL, 0x9d1f8282UL, 0x4089c9c9UL, 0x87fa7d7dUL, - 0x15effafaUL, 0xebb25959UL, 0xc98e4747UL, 0x0bfbf0f0UL, - 0xec41adadUL, 0x67b3d4d4UL, 0xfd5fa2a2UL, 0xea45afafUL, - 0xbf239c9cUL, 0xf753a4a4UL, 0x96e47272UL, 0x5b9bc0c0UL, - 0xc275b7b7UL, 0x1ce1fdfdUL, 0xae3d9393UL, 0x6a4c2626UL, - 0x5a6c3636UL, 0x417e3f3fUL, 0x02f5f7f7UL, 0x4f83ccccUL, - 0x5c683434UL, 0xf451a5a5UL, 0x34d1e5e5UL, 0x08f9f1f1UL, - 0x93e27171UL, 0x73abd8d8UL, 0x53623131UL, 0x3f2a1515UL, - 0x0c080404UL, 0x5295c7c7UL, 0x65462323UL, 0x5e9dc3c3UL, - 0x28301818UL, 0xa1379696UL, 0x0f0a0505UL, 0xb52f9a9aUL, - 0x090e0707UL, 0x36241212UL, 0x9b1b8080UL, 0x3ddfe2e2UL, - 0x26cdebebUL, 0x694e2727UL, 0xcd7fb2b2UL, 0x9fea7575UL, - 0x1b120909UL, 0x9e1d8383UL, 0x74582c2cUL, 0x2e341a1aUL, - 0x2d361b1bUL, 0xb2dc6e6eUL, 0xeeb45a5aUL, 0xfb5ba0a0UL, - 0xf6a45252UL, 0x4d763b3bUL, 0x61b7d6d6UL, 0xce7db3b3UL, - 0x7b522929UL, 0x3edde3e3UL, 0x715e2f2fUL, 0x97138484UL, - 0xf5a65353UL, 0x68b9d1d1UL, 0x00000000UL, 0x2cc1ededUL, - 0x60402020UL, 0x1fe3fcfcUL, 0xc879b1b1UL, 0xedb65b5bUL, - 0xbed46a6aUL, 0x468dcbcbUL, 0xd967bebeUL, 0x4b723939UL, - 0xde944a4aUL, 0xd4984c4cUL, 0xe8b05858UL, 0x4a85cfcfUL, - 0x6bbbd0d0UL, 0x2ac5efefUL, 0xe54faaaaUL, 0x16edfbfbUL, - 0xc5864343UL, 0xd79a4d4dUL, 0x55663333UL, 0x94118585UL, - 0xcf8a4545UL, 0x10e9f9f9UL, 0x06040202UL, 0x81fe7f7fUL, - 0xf0a05050UL, 0x44783c3cUL, 0xba259f9fUL, 0xe34ba8a8UL, - 0xf3a25151UL, 0xfe5da3a3UL, 0xc0804040UL, 0x8a058f8fUL, - 0xad3f9292UL, 0xbc219d9dUL, 0x48703838UL, 0x04f1f5f5UL, - 0xdf63bcbcUL, 0xc177b6b6UL, 0x75afdadaUL, 0x63422121UL, - 0x30201010UL, 0x1ae5ffffUL, 0x0efdf3f3UL, 0x6dbfd2d2UL, - 0x4c81cdcdUL, 0x14180c0cUL, 0x35261313UL, 0x2fc3ececUL, - 0xe1be5f5fUL, 0xa2359797UL, 0xcc884444UL, 0x392e1717UL, - 0x5793c4c4UL, 0xf255a7a7UL, 0x82fc7e7eUL, 0x477a3d3dUL, - 0xacc86464UL, 0xe7ba5d5dUL, 0x2b321919UL, 0x95e67373UL, - 0xa0c06060UL, 0x98198181UL, 0xd19e4f4fUL, 0x7fa3dcdcUL, - 0x66442222UL, 0x7e542a2aUL, 0xab3b9090UL, 0x830b8888UL, - 0xca8c4646UL, 0x29c7eeeeUL, 0xd36bb8b8UL, 0x3c281414UL, - 0x79a7dedeUL, 0xe2bc5e5eUL, 0x1d160b0bUL, 0x76addbdbUL, - 0x3bdbe0e0UL, 0x56643232UL, 0x4e743a3aUL, 0x1e140a0aUL, - 0xdb924949UL, 0x0a0c0606UL, 0x6c482424UL, 0xe4b85c5cUL, - 0x5d9fc2c2UL, 0x6ebdd3d3UL, 0xef43acacUL, 0xa6c46262UL, - 0xa8399191UL, 0xa4319595UL, 0x37d3e4e4UL, 0x8bf27979UL, - 0x32d5e7e7UL, 0x438bc8c8UL, 0x596e3737UL, 0xb7da6d6dUL, - 0x8c018d8dUL, 0x64b1d5d5UL, 0xd29c4e4eUL, 0xe049a9a9UL, - 0xb4d86c6cUL, 0xfaac5656UL, 0x07f3f4f4UL, 0x25cfeaeaUL, - 0xafca6565UL, 0x8ef47a7aUL, 0xe947aeaeUL, 0x18100808UL, - 0xd56fbabaUL, 0x88f07878UL, 0x6f4a2525UL, 0x725c2e2eUL, - 0x24381c1cUL, 0xf157a6a6UL, 0xc773b4b4UL, 0x5197c6c6UL, - 0x23cbe8e8UL, 0x7ca1ddddUL, 0x9ce87474UL, 0x213e1f1fUL, - 0xdd964b4bUL, 0xdc61bdbdUL, 0x860d8b8bUL, 0x850f8a8aUL, - 0x90e07070UL, 0x427c3e3eUL, 0xc471b5b5UL, 0xaacc6666UL, - 0xd8904848UL, 0x05060303UL, 0x01f7f6f6UL, 0x121c0e0eUL, - 0xa3c26161UL, 0x5f6a3535UL, 0xf9ae5757UL, 0xd069b9b9UL, - 0x91178686UL, 0x5899c1c1UL, 0x273a1d1dUL, 0xb9279e9eUL, - 0x38d9e1e1UL, 0x13ebf8f8UL, 0xb32b9898UL, 0x33221111UL, - 0xbbd26969UL, 0x70a9d9d9UL, 0x89078e8eUL, 0xa7339494UL, - 0xb62d9b9bUL, 0x223c1e1eUL, 0x92158787UL, 0x20c9e9e9UL, - 0x4987ceceUL, 0xffaa5555UL, 0x78502828UL, 0x7aa5dfdfUL, - 0x8f038c8cUL, 0xf859a1a1UL, 0x80098989UL, 0x171a0d0dUL, - 0xda65bfbfUL, 0x31d7e6e6UL, 0xc6844242UL, 0xb8d06868UL, - 0xc3824141UL, 0xb0299999UL, 0x775a2d2dUL, 0x111e0f0fUL, - 0xcb7bb0b0UL, 0xfca85454UL, 0xd66dbbbbUL, 0x3a2c1616UL, -}; -static const unsigned int Te2[256] = { - 0x63a5c663UL, 0x7c84f87cUL, 0x7799ee77UL, 0x7b8df67bUL, - 0xf20dfff2UL, 0x6bbdd66bUL, 0x6fb1de6fUL, 0xc55491c5UL, - 0x30506030UL, 0x01030201UL, 0x67a9ce67UL, 0x2b7d562bUL, - 0xfe19e7feUL, 0xd762b5d7UL, 0xabe64dabUL, 0x769aec76UL, - 0xca458fcaUL, 0x829d1f82UL, 0xc94089c9UL, 0x7d87fa7dUL, - 0xfa15effaUL, 0x59ebb259UL, 0x47c98e47UL, 0xf00bfbf0UL, - 0xadec41adUL, 0xd467b3d4UL, 0xa2fd5fa2UL, 0xafea45afUL, - 0x9cbf239cUL, 0xa4f753a4UL, 0x7296e472UL, 0xc05b9bc0UL, - 0xb7c275b7UL, 0xfd1ce1fdUL, 0x93ae3d93UL, 0x266a4c26UL, - 0x365a6c36UL, 0x3f417e3fUL, 0xf702f5f7UL, 0xcc4f83ccUL, - 0x345c6834UL, 0xa5f451a5UL, 0xe534d1e5UL, 0xf108f9f1UL, - 0x7193e271UL, 0xd873abd8UL, 0x31536231UL, 0x153f2a15UL, - 0x040c0804UL, 0xc75295c7UL, 0x23654623UL, 0xc35e9dc3UL, - 0x18283018UL, 0x96a13796UL, 0x050f0a05UL, 0x9ab52f9aUL, - 0x07090e07UL, 0x12362412UL, 0x809b1b80UL, 0xe23ddfe2UL, - 0xeb26cdebUL, 0x27694e27UL, 0xb2cd7fb2UL, 0x759fea75UL, - 0x091b1209UL, 0x839e1d83UL, 0x2c74582cUL, 0x1a2e341aUL, - 0x1b2d361bUL, 0x6eb2dc6eUL, 0x5aeeb45aUL, 0xa0fb5ba0UL, - 0x52f6a452UL, 0x3b4d763bUL, 0xd661b7d6UL, 0xb3ce7db3UL, - 0x297b5229UL, 0xe33edde3UL, 0x2f715e2fUL, 0x84971384UL, - 0x53f5a653UL, 0xd168b9d1UL, 0x00000000UL, 0xed2cc1edUL, - 0x20604020UL, 0xfc1fe3fcUL, 0xb1c879b1UL, 0x5bedb65bUL, - 0x6abed46aUL, 0xcb468dcbUL, 0xbed967beUL, 0x394b7239UL, - 0x4ade944aUL, 0x4cd4984cUL, 0x58e8b058UL, 0xcf4a85cfUL, - 0xd06bbbd0UL, 0xef2ac5efUL, 0xaae54faaUL, 0xfb16edfbUL, - 0x43c58643UL, 0x4dd79a4dUL, 0x33556633UL, 0x85941185UL, - 0x45cf8a45UL, 0xf910e9f9UL, 0x02060402UL, 0x7f81fe7fUL, - 0x50f0a050UL, 0x3c44783cUL, 0x9fba259fUL, 0xa8e34ba8UL, - 0x51f3a251UL, 0xa3fe5da3UL, 0x40c08040UL, 0x8f8a058fUL, - 0x92ad3f92UL, 0x9dbc219dUL, 0x38487038UL, 0xf504f1f5UL, - 0xbcdf63bcUL, 0xb6c177b6UL, 0xda75afdaUL, 0x21634221UL, - 0x10302010UL, 0xff1ae5ffUL, 0xf30efdf3UL, 0xd26dbfd2UL, - 0xcd4c81cdUL, 0x0c14180cUL, 0x13352613UL, 0xec2fc3ecUL, - 0x5fe1be5fUL, 0x97a23597UL, 0x44cc8844UL, 0x17392e17UL, - 0xc45793c4UL, 0xa7f255a7UL, 0x7e82fc7eUL, 0x3d477a3dUL, - 0x64acc864UL, 0x5de7ba5dUL, 0x192b3219UL, 0x7395e673UL, - 0x60a0c060UL, 0x81981981UL, 0x4fd19e4fUL, 0xdc7fa3dcUL, - 0x22664422UL, 0x2a7e542aUL, 0x90ab3b90UL, 0x88830b88UL, - 0x46ca8c46UL, 0xee29c7eeUL, 0xb8d36bb8UL, 0x143c2814UL, - 0xde79a7deUL, 0x5ee2bc5eUL, 0x0b1d160bUL, 0xdb76addbUL, - 0xe03bdbe0UL, 0x32566432UL, 0x3a4e743aUL, 0x0a1e140aUL, - 0x49db9249UL, 0x060a0c06UL, 0x246c4824UL, 0x5ce4b85cUL, - 0xc25d9fc2UL, 0xd36ebdd3UL, 0xacef43acUL, 0x62a6c462UL, - 0x91a83991UL, 0x95a43195UL, 0xe437d3e4UL, 0x798bf279UL, - 0xe732d5e7UL, 0xc8438bc8UL, 0x37596e37UL, 0x6db7da6dUL, - 0x8d8c018dUL, 0xd564b1d5UL, 0x4ed29c4eUL, 0xa9e049a9UL, - 0x6cb4d86cUL, 0x56faac56UL, 0xf407f3f4UL, 0xea25cfeaUL, - 0x65afca65UL, 0x7a8ef47aUL, 0xaee947aeUL, 0x08181008UL, - 0xbad56fbaUL, 0x7888f078UL, 0x256f4a25UL, 0x2e725c2eUL, - 0x1c24381cUL, 0xa6f157a6UL, 0xb4c773b4UL, 0xc65197c6UL, - 0xe823cbe8UL, 0xdd7ca1ddUL, 0x749ce874UL, 0x1f213e1fUL, - 0x4bdd964bUL, 0xbddc61bdUL, 0x8b860d8bUL, 0x8a850f8aUL, - 0x7090e070UL, 0x3e427c3eUL, 0xb5c471b5UL, 0x66aacc66UL, - 0x48d89048UL, 0x03050603UL, 0xf601f7f6UL, 0x0e121c0eUL, - 0x61a3c261UL, 0x355f6a35UL, 0x57f9ae57UL, 0xb9d069b9UL, - 0x86911786UL, 0xc15899c1UL, 0x1d273a1dUL, 0x9eb9279eUL, - 0xe138d9e1UL, 0xf813ebf8UL, 0x98b32b98UL, 0x11332211UL, - 0x69bbd269UL, 0xd970a9d9UL, 0x8e89078eUL, 0x94a73394UL, - 0x9bb62d9bUL, 0x1e223c1eUL, 0x87921587UL, 0xe920c9e9UL, - 0xce4987ceUL, 0x55ffaa55UL, 0x28785028UL, 0xdf7aa5dfUL, - 0x8c8f038cUL, 0xa1f859a1UL, 0x89800989UL, 0x0d171a0dUL, - 0xbfda65bfUL, 0xe631d7e6UL, 0x42c68442UL, 0x68b8d068UL, - 0x41c38241UL, 0x99b02999UL, 0x2d775a2dUL, 0x0f111e0fUL, - 0xb0cb7bb0UL, 0x54fca854UL, 0xbbd66dbbUL, 0x163a2c16UL, -}; -static const unsigned int Te3[256] = { - 0x6363a5c6UL, 0x7c7c84f8UL, 0x777799eeUL, 0x7b7b8df6UL, - 0xf2f20dffUL, 0x6b6bbdd6UL, 0x6f6fb1deUL, 0xc5c55491UL, - 0x30305060UL, 0x01010302UL, 0x6767a9ceUL, 0x2b2b7d56UL, - 0xfefe19e7UL, 0xd7d762b5UL, 0xababe64dUL, 0x76769aecUL, - 0xcaca458fUL, 0x82829d1fUL, 0xc9c94089UL, 0x7d7d87faUL, - 0xfafa15efUL, 0x5959ebb2UL, 0x4747c98eUL, 0xf0f00bfbUL, - 0xadadec41UL, 0xd4d467b3UL, 0xa2a2fd5fUL, 0xafafea45UL, - 0x9c9cbf23UL, 0xa4a4f753UL, 0x727296e4UL, 0xc0c05b9bUL, - 0xb7b7c275UL, 0xfdfd1ce1UL, 0x9393ae3dUL, 0x26266a4cUL, - 0x36365a6cUL, 0x3f3f417eUL, 0xf7f702f5UL, 0xcccc4f83UL, - 0x34345c68UL, 0xa5a5f451UL, 0xe5e534d1UL, 0xf1f108f9UL, - 0x717193e2UL, 0xd8d873abUL, 0x31315362UL, 0x15153f2aUL, - 0x04040c08UL, 0xc7c75295UL, 0x23236546UL, 0xc3c35e9dUL, - 0x18182830UL, 0x9696a137UL, 0x05050f0aUL, 0x9a9ab52fUL, - 0x0707090eUL, 0x12123624UL, 0x80809b1bUL, 0xe2e23ddfUL, - 0xebeb26cdUL, 0x2727694eUL, 0xb2b2cd7fUL, 0x75759feaUL, - 0x09091b12UL, 0x83839e1dUL, 0x2c2c7458UL, 0x1a1a2e34UL, - 0x1b1b2d36UL, 0x6e6eb2dcUL, 0x5a5aeeb4UL, 0xa0a0fb5bUL, - 0x5252f6a4UL, 0x3b3b4d76UL, 0xd6d661b7UL, 0xb3b3ce7dUL, - 0x29297b52UL, 0xe3e33eddUL, 0x2f2f715eUL, 0x84849713UL, - 0x5353f5a6UL, 0xd1d168b9UL, 0x00000000UL, 0xeded2cc1UL, - 0x20206040UL, 0xfcfc1fe3UL, 0xb1b1c879UL, 0x5b5bedb6UL, - 0x6a6abed4UL, 0xcbcb468dUL, 0xbebed967UL, 0x39394b72UL, - 0x4a4ade94UL, 0x4c4cd498UL, 0x5858e8b0UL, 0xcfcf4a85UL, - 0xd0d06bbbUL, 0xefef2ac5UL, 0xaaaae54fUL, 0xfbfb16edUL, - 0x4343c586UL, 0x4d4dd79aUL, 0x33335566UL, 0x85859411UL, - 0x4545cf8aUL, 0xf9f910e9UL, 0x02020604UL, 0x7f7f81feUL, - 0x5050f0a0UL, 0x3c3c4478UL, 0x9f9fba25UL, 0xa8a8e34bUL, - 0x5151f3a2UL, 0xa3a3fe5dUL, 0x4040c080UL, 0x8f8f8a05UL, - 0x9292ad3fUL, 0x9d9dbc21UL, 0x38384870UL, 0xf5f504f1UL, - 0xbcbcdf63UL, 0xb6b6c177UL, 0xdada75afUL, 0x21216342UL, - 0x10103020UL, 0xffff1ae5UL, 0xf3f30efdUL, 0xd2d26dbfUL, - 0xcdcd4c81UL, 0x0c0c1418UL, 0x13133526UL, 0xecec2fc3UL, - 0x5f5fe1beUL, 0x9797a235UL, 0x4444cc88UL, 0x1717392eUL, - 0xc4c45793UL, 0xa7a7f255UL, 0x7e7e82fcUL, 0x3d3d477aUL, - 0x6464acc8UL, 0x5d5de7baUL, 0x19192b32UL, 0x737395e6UL, - 0x6060a0c0UL, 0x81819819UL, 0x4f4fd19eUL, 0xdcdc7fa3UL, - 0x22226644UL, 0x2a2a7e54UL, 0x9090ab3bUL, 0x8888830bUL, - 0x4646ca8cUL, 0xeeee29c7UL, 0xb8b8d36bUL, 0x14143c28UL, - 0xdede79a7UL, 0x5e5ee2bcUL, 0x0b0b1d16UL, 0xdbdb76adUL, - 0xe0e03bdbUL, 0x32325664UL, 0x3a3a4e74UL, 0x0a0a1e14UL, - 0x4949db92UL, 0x06060a0cUL, 0x24246c48UL, 0x5c5ce4b8UL, - 0xc2c25d9fUL, 0xd3d36ebdUL, 0xacacef43UL, 0x6262a6c4UL, - 0x9191a839UL, 0x9595a431UL, 0xe4e437d3UL, 0x79798bf2UL, - 0xe7e732d5UL, 0xc8c8438bUL, 0x3737596eUL, 0x6d6db7daUL, - 0x8d8d8c01UL, 0xd5d564b1UL, 0x4e4ed29cUL, 0xa9a9e049UL, - 0x6c6cb4d8UL, 0x5656faacUL, 0xf4f407f3UL, 0xeaea25cfUL, - 0x6565afcaUL, 0x7a7a8ef4UL, 0xaeaee947UL, 0x08081810UL, - 0xbabad56fUL, 0x787888f0UL, 0x25256f4aUL, 0x2e2e725cUL, - 0x1c1c2438UL, 0xa6a6f157UL, 0xb4b4c773UL, 0xc6c65197UL, - 0xe8e823cbUL, 0xdddd7ca1UL, 0x74749ce8UL, 0x1f1f213eUL, - 0x4b4bdd96UL, 0xbdbddc61UL, 0x8b8b860dUL, 0x8a8a850fUL, - 0x707090e0UL, 0x3e3e427cUL, 0xb5b5c471UL, 0x6666aaccUL, - 0x4848d890UL, 0x03030506UL, 0xf6f601f7UL, 0x0e0e121cUL, - 0x6161a3c2UL, 0x35355f6aUL, 0x5757f9aeUL, 0xb9b9d069UL, - 0x86869117UL, 0xc1c15899UL, 0x1d1d273aUL, 0x9e9eb927UL, - 0xe1e138d9UL, 0xf8f813ebUL, 0x9898b32bUL, 0x11113322UL, - 0x6969bbd2UL, 0xd9d970a9UL, 0x8e8e8907UL, 0x9494a733UL, - 0x9b9bb62dUL, 0x1e1e223cUL, 0x87879215UL, 0xe9e920c9UL, - 0xcece4987UL, 0x5555ffaaUL, 0x28287850UL, 0xdfdf7aa5UL, - 0x8c8c8f03UL, 0xa1a1f859UL, 0x89898009UL, 0x0d0d171aUL, - 0xbfbfda65UL, 0xe6e631d7UL, 0x4242c684UL, 0x6868b8d0UL, - 0x4141c382UL, 0x9999b029UL, 0x2d2d775aUL, 0x0f0f111eUL, - 0xb0b0cb7bUL, 0x5454fca8UL, 0xbbbbd66dUL, 0x16163a2cUL, -}; -static const unsigned int Te4[256] = { - 0x63636363UL, 0x7c7c7c7cUL, 0x77777777UL, 0x7b7b7b7bUL, - 0xf2f2f2f2UL, 0x6b6b6b6bUL, 0x6f6f6f6fUL, 0xc5c5c5c5UL, - 0x30303030UL, 0x01010101UL, 0x67676767UL, 0x2b2b2b2bUL, - 0xfefefefeUL, 0xd7d7d7d7UL, 0xababababUL, 0x76767676UL, - 0xcacacacaUL, 0x82828282UL, 0xc9c9c9c9UL, 0x7d7d7d7dUL, - 0xfafafafaUL, 0x59595959UL, 0x47474747UL, 0xf0f0f0f0UL, - 0xadadadadUL, 0xd4d4d4d4UL, 0xa2a2a2a2UL, 0xafafafafUL, - 0x9c9c9c9cUL, 0xa4a4a4a4UL, 0x72727272UL, 0xc0c0c0c0UL, - 0xb7b7b7b7UL, 0xfdfdfdfdUL, 0x93939393UL, 0x26262626UL, - 0x36363636UL, 0x3f3f3f3fUL, 0xf7f7f7f7UL, 0xccccccccUL, - 0x34343434UL, 0xa5a5a5a5UL, 0xe5e5e5e5UL, 0xf1f1f1f1UL, - 0x71717171UL, 0xd8d8d8d8UL, 0x31313131UL, 0x15151515UL, - 0x04040404UL, 0xc7c7c7c7UL, 0x23232323UL, 0xc3c3c3c3UL, - 0x18181818UL, 0x96969696UL, 0x05050505UL, 0x9a9a9a9aUL, - 0x07070707UL, 0x12121212UL, 0x80808080UL, 0xe2e2e2e2UL, - 0xebebebebUL, 0x27272727UL, 0xb2b2b2b2UL, 0x75757575UL, - 0x09090909UL, 0x83838383UL, 0x2c2c2c2cUL, 0x1a1a1a1aUL, - 0x1b1b1b1bUL, 0x6e6e6e6eUL, 0x5a5a5a5aUL, 0xa0a0a0a0UL, - 0x52525252UL, 0x3b3b3b3bUL, 0xd6d6d6d6UL, 0xb3b3b3b3UL, - 0x29292929UL, 0xe3e3e3e3UL, 0x2f2f2f2fUL, 0x84848484UL, - 0x53535353UL, 0xd1d1d1d1UL, 0x00000000UL, 0xededededUL, - 0x20202020UL, 0xfcfcfcfcUL, 0xb1b1b1b1UL, 0x5b5b5b5bUL, - 0x6a6a6a6aUL, 0xcbcbcbcbUL, 0xbebebebeUL, 0x39393939UL, - 0x4a4a4a4aUL, 0x4c4c4c4cUL, 0x58585858UL, 0xcfcfcfcfUL, - 0xd0d0d0d0UL, 0xefefefefUL, 0xaaaaaaaaUL, 0xfbfbfbfbUL, - 0x43434343UL, 0x4d4d4d4dUL, 0x33333333UL, 0x85858585UL, - 0x45454545UL, 0xf9f9f9f9UL, 0x02020202UL, 0x7f7f7f7fUL, - 0x50505050UL, 0x3c3c3c3cUL, 0x9f9f9f9fUL, 0xa8a8a8a8UL, - 0x51515151UL, 0xa3a3a3a3UL, 0x40404040UL, 0x8f8f8f8fUL, - 0x92929292UL, 0x9d9d9d9dUL, 0x38383838UL, 0xf5f5f5f5UL, - 0xbcbcbcbcUL, 0xb6b6b6b6UL, 0xdadadadaUL, 0x21212121UL, - 0x10101010UL, 0xffffffffUL, 0xf3f3f3f3UL, 0xd2d2d2d2UL, - 0xcdcdcdcdUL, 0x0c0c0c0cUL, 0x13131313UL, 0xececececUL, - 0x5f5f5f5fUL, 0x97979797UL, 0x44444444UL, 0x17171717UL, - 0xc4c4c4c4UL, 0xa7a7a7a7UL, 0x7e7e7e7eUL, 0x3d3d3d3dUL, - 0x64646464UL, 0x5d5d5d5dUL, 0x19191919UL, 0x73737373UL, - 0x60606060UL, 0x81818181UL, 0x4f4f4f4fUL, 0xdcdcdcdcUL, - 0x22222222UL, 0x2a2a2a2aUL, 0x90909090UL, 0x88888888UL, - 0x46464646UL, 0xeeeeeeeeUL, 0xb8b8b8b8UL, 0x14141414UL, - 0xdedededeUL, 0x5e5e5e5eUL, 0x0b0b0b0bUL, 0xdbdbdbdbUL, - 0xe0e0e0e0UL, 0x32323232UL, 0x3a3a3a3aUL, 0x0a0a0a0aUL, - 0x49494949UL, 0x06060606UL, 0x24242424UL, 0x5c5c5c5cUL, - 0xc2c2c2c2UL, 0xd3d3d3d3UL, 0xacacacacUL, 0x62626262UL, - 0x91919191UL, 0x95959595UL, 0xe4e4e4e4UL, 0x79797979UL, - 0xe7e7e7e7UL, 0xc8c8c8c8UL, 0x37373737UL, 0x6d6d6d6dUL, - 0x8d8d8d8dUL, 0xd5d5d5d5UL, 0x4e4e4e4eUL, 0xa9a9a9a9UL, - 0x6c6c6c6cUL, 0x56565656UL, 0xf4f4f4f4UL, 0xeaeaeaeaUL, - 0x65656565UL, 0x7a7a7a7aUL, 0xaeaeaeaeUL, 0x08080808UL, - 0xbabababaUL, 0x78787878UL, 0x25252525UL, 0x2e2e2e2eUL, - 0x1c1c1c1cUL, 0xa6a6a6a6UL, 0xb4b4b4b4UL, 0xc6c6c6c6UL, - 0xe8e8e8e8UL, 0xddddddddUL, 0x74747474UL, 0x1f1f1f1fUL, - 0x4b4b4b4bUL, 0xbdbdbdbdUL, 0x8b8b8b8bUL, 0x8a8a8a8aUL, - 0x70707070UL, 0x3e3e3e3eUL, 0xb5b5b5b5UL, 0x66666666UL, - 0x48484848UL, 0x03030303UL, 0xf6f6f6f6UL, 0x0e0e0e0eUL, - 0x61616161UL, 0x35353535UL, 0x57575757UL, 0xb9b9b9b9UL, - 0x86868686UL, 0xc1c1c1c1UL, 0x1d1d1d1dUL, 0x9e9e9e9eUL, - 0xe1e1e1e1UL, 0xf8f8f8f8UL, 0x98989898UL, 0x11111111UL, - 0x69696969UL, 0xd9d9d9d9UL, 0x8e8e8e8eUL, 0x94949494UL, - 0x9b9b9b9bUL, 0x1e1e1e1eUL, 0x87878787UL, 0xe9e9e9e9UL, - 0xcecececeUL, 0x55555555UL, 0x28282828UL, 0xdfdfdfdfUL, - 0x8c8c8c8cUL, 0xa1a1a1a1UL, 0x89898989UL, 0x0d0d0d0dUL, - 0xbfbfbfbfUL, 0xe6e6e6e6UL, 0x42424242UL, 0x68686868UL, - 0x41414141UL, 0x99999999UL, 0x2d2d2d2dUL, 0x0f0f0f0fUL, - 0xb0b0b0b0UL, 0x54545454UL, 0xbbbbbbbbUL, 0x16161616UL, -}; -static const unsigned int Td0[256] = { - 0x51f4a750UL, 0x7e416553UL, 0x1a17a4c3UL, 0x3a275e96UL, - 0x3bab6bcbUL, 0x1f9d45f1UL, 0xacfa58abUL, 0x4be30393UL, - 0x2030fa55UL, 0xad766df6UL, 0x88cc7691UL, 0xf5024c25UL, - 0x4fe5d7fcUL, 0xc52acbd7UL, 0x26354480UL, 0xb562a38fUL, - 0xdeb15a49UL, 0x25ba1b67UL, 0x45ea0e98UL, 0x5dfec0e1UL, - 0xc32f7502UL, 0x814cf012UL, 0x8d4697a3UL, 0x6bd3f9c6UL, - 0x038f5fe7UL, 0x15929c95UL, 0xbf6d7aebUL, 0x955259daUL, - 0xd4be832dUL, 0x587421d3UL, 0x49e06929UL, 0x8ec9c844UL, - 0x75c2896aUL, 0xf48e7978UL, 0x99583e6bUL, 0x27b971ddUL, - 0xbee14fb6UL, 0xf088ad17UL, 0xc920ac66UL, 0x7dce3ab4UL, - 0x63df4a18UL, 0xe51a3182UL, 0x97513360UL, 0x62537f45UL, - 0xb16477e0UL, 0xbb6bae84UL, 0xfe81a01cUL, 0xf9082b94UL, - 0x70486858UL, 0x8f45fd19UL, 0x94de6c87UL, 0x527bf8b7UL, - 0xab73d323UL, 0x724b02e2UL, 0xe31f8f57UL, 0x6655ab2aUL, - 0xb2eb2807UL, 0x2fb5c203UL, 0x86c57b9aUL, 0xd33708a5UL, - 0x302887f2UL, 0x23bfa5b2UL, 0x02036abaUL, 0xed16825cUL, - 0x8acf1c2bUL, 0xa779b492UL, 0xf307f2f0UL, 0x4e69e2a1UL, - 0x65daf4cdUL, 0x0605bed5UL, 0xd134621fUL, 0xc4a6fe8aUL, - 0x342e539dUL, 0xa2f355a0UL, 0x058ae132UL, 0xa4f6eb75UL, - 0x0b83ec39UL, 0x4060efaaUL, 0x5e719f06UL, 0xbd6e1051UL, - 0x3e218af9UL, 0x96dd063dUL, 0xdd3e05aeUL, 0x4de6bd46UL, - 0x91548db5UL, 0x71c45d05UL, 0x0406d46fUL, 0x605015ffUL, - 0x1998fb24UL, 0xd6bde997UL, 0x894043ccUL, 0x67d99e77UL, - 0xb0e842bdUL, 0x07898b88UL, 0xe7195b38UL, 0x79c8eedbUL, - 0xa17c0a47UL, 0x7c420fe9UL, 0xf8841ec9UL, 0x00000000UL, - 0x09808683UL, 0x322bed48UL, 0x1e1170acUL, 0x6c5a724eUL, - 0xfd0efffbUL, 0x0f853856UL, 0x3daed51eUL, 0x362d3927UL, - 0x0a0fd964UL, 0x685ca621UL, 0x9b5b54d1UL, 0x24362e3aUL, - 0x0c0a67b1UL, 0x9357e70fUL, 0xb4ee96d2UL, 0x1b9b919eUL, - 0x80c0c54fUL, 0x61dc20a2UL, 0x5a774b69UL, 0x1c121a16UL, - 0xe293ba0aUL, 0xc0a02ae5UL, 0x3c22e043UL, 0x121b171dUL, - 0x0e090d0bUL, 0xf28bc7adUL, 0x2db6a8b9UL, 0x141ea9c8UL, - 0x57f11985UL, 0xaf75074cUL, 0xee99ddbbUL, 0xa37f60fdUL, - 0xf701269fUL, 0x5c72f5bcUL, 0x44663bc5UL, 0x5bfb7e34UL, - 0x8b432976UL, 0xcb23c6dcUL, 0xb6edfc68UL, 0xb8e4f163UL, - 0xd731dccaUL, 0x42638510UL, 0x13972240UL, 0x84c61120UL, - 0x854a247dUL, 0xd2bb3df8UL, 0xaef93211UL, 0xc729a16dUL, - 0x1d9e2f4bUL, 0xdcb230f3UL, 0x0d8652ecUL, 0x77c1e3d0UL, - 0x2bb3166cUL, 0xa970b999UL, 0x119448faUL, 0x47e96422UL, - 0xa8fc8cc4UL, 0xa0f03f1aUL, 0x567d2cd8UL, 0x223390efUL, - 0x87494ec7UL, 0xd938d1c1UL, 0x8ccaa2feUL, 0x98d40b36UL, - 0xa6f581cfUL, 0xa57ade28UL, 0xdab78e26UL, 0x3fadbfa4UL, - 0x2c3a9de4UL, 0x5078920dUL, 0x6a5fcc9bUL, 0x547e4662UL, - 0xf68d13c2UL, 0x90d8b8e8UL, 0x2e39f75eUL, 0x82c3aff5UL, - 0x9f5d80beUL, 0x69d0937cUL, 0x6fd52da9UL, 0xcf2512b3UL, - 0xc8ac993bUL, 0x10187da7UL, 0xe89c636eUL, 0xdb3bbb7bUL, - 0xcd267809UL, 0x6e5918f4UL, 0xec9ab701UL, 0x834f9aa8UL, - 0xe6956e65UL, 0xaaffe67eUL, 0x21bccf08UL, 0xef15e8e6UL, - 0xbae79bd9UL, 0x4a6f36ceUL, 0xea9f09d4UL, 0x29b07cd6UL, - 0x31a4b2afUL, 0x2a3f2331UL, 0xc6a59430UL, 0x35a266c0UL, - 0x744ebc37UL, 0xfc82caa6UL, 0xe090d0b0UL, 0x33a7d815UL, - 0xf104984aUL, 0x41ecdaf7UL, 0x7fcd500eUL, 0x1791f62fUL, - 0x764dd68dUL, 0x43efb04dUL, 0xccaa4d54UL, 0xe49604dfUL, - 0x9ed1b5e3UL, 0x4c6a881bUL, 0xc12c1fb8UL, 0x4665517fUL, - 0x9d5eea04UL, 0x018c355dUL, 0xfa877473UL, 0xfb0b412eUL, - 0xb3671d5aUL, 0x92dbd252UL, 0xe9105633UL, 0x6dd64713UL, - 0x9ad7618cUL, 0x37a10c7aUL, 0x59f8148eUL, 0xeb133c89UL, - 0xcea927eeUL, 0xb761c935UL, 0xe11ce5edUL, 0x7a47b13cUL, - 0x9cd2df59UL, 0x55f2733fUL, 0x1814ce79UL, 0x73c737bfUL, - 0x53f7cdeaUL, 0x5ffdaa5bUL, 0xdf3d6f14UL, 0x7844db86UL, - 0xcaaff381UL, 0xb968c43eUL, 0x3824342cUL, 0xc2a3405fUL, - 0x161dc372UL, 0xbce2250cUL, 0x283c498bUL, 0xff0d9541UL, - 0x39a80171UL, 0x080cb3deUL, 0xd8b4e49cUL, 0x6456c190UL, - 0x7bcb8461UL, 0xd532b670UL, 0x486c5c74UL, 0xd0b85742UL, -}; -static const unsigned int Td1[256] = { - 0x5051f4a7UL, 0x537e4165UL, 0xc31a17a4UL, 0x963a275eUL, - 0xcb3bab6bUL, 0xf11f9d45UL, 0xabacfa58UL, 0x934be303UL, - 0x552030faUL, 0xf6ad766dUL, 0x9188cc76UL, 0x25f5024cUL, - 0xfc4fe5d7UL, 0xd7c52acbUL, 0x80263544UL, 0x8fb562a3UL, - 0x49deb15aUL, 0x6725ba1bUL, 0x9845ea0eUL, 0xe15dfec0UL, - 0x02c32f75UL, 0x12814cf0UL, 0xa38d4697UL, 0xc66bd3f9UL, - 0xe7038f5fUL, 0x9515929cUL, 0xebbf6d7aUL, 0xda955259UL, - 0x2dd4be83UL, 0xd3587421UL, 0x2949e069UL, 0x448ec9c8UL, - 0x6a75c289UL, 0x78f48e79UL, 0x6b99583eUL, 0xdd27b971UL, - 0xb6bee14fUL, 0x17f088adUL, 0x66c920acUL, 0xb47dce3aUL, - 0x1863df4aUL, 0x82e51a31UL, 0x60975133UL, 0x4562537fUL, - 0xe0b16477UL, 0x84bb6baeUL, 0x1cfe81a0UL, 0x94f9082bUL, - 0x58704868UL, 0x198f45fdUL, 0x8794de6cUL, 0xb7527bf8UL, - 0x23ab73d3UL, 0xe2724b02UL, 0x57e31f8fUL, 0x2a6655abUL, - 0x07b2eb28UL, 0x032fb5c2UL, 0x9a86c57bUL, 0xa5d33708UL, - 0xf2302887UL, 0xb223bfa5UL, 0xba02036aUL, 0x5ced1682UL, - 0x2b8acf1cUL, 0x92a779b4UL, 0xf0f307f2UL, 0xa14e69e2UL, - 0xcd65daf4UL, 0xd50605beUL, 0x1fd13462UL, 0x8ac4a6feUL, - 0x9d342e53UL, 0xa0a2f355UL, 0x32058ae1UL, 0x75a4f6ebUL, - 0x390b83ecUL, 0xaa4060efUL, 0x065e719fUL, 0x51bd6e10UL, - 0xf93e218aUL, 0x3d96dd06UL, 0xaedd3e05UL, 0x464de6bdUL, - 0xb591548dUL, 0x0571c45dUL, 0x6f0406d4UL, 0xff605015UL, - 0x241998fbUL, 0x97d6bde9UL, 0xcc894043UL, 0x7767d99eUL, - 0xbdb0e842UL, 0x8807898bUL, 0x38e7195bUL, 0xdb79c8eeUL, - 0x47a17c0aUL, 0xe97c420fUL, 0xc9f8841eUL, 0x00000000UL, - 0x83098086UL, 0x48322bedUL, 0xac1e1170UL, 0x4e6c5a72UL, - 0xfbfd0effUL, 0x560f8538UL, 0x1e3daed5UL, 0x27362d39UL, - 0x640a0fd9UL, 0x21685ca6UL, 0xd19b5b54UL, 0x3a24362eUL, - 0xb10c0a67UL, 0x0f9357e7UL, 0xd2b4ee96UL, 0x9e1b9b91UL, - 0x4f80c0c5UL, 0xa261dc20UL, 0x695a774bUL, 0x161c121aUL, - 0x0ae293baUL, 0xe5c0a02aUL, 0x433c22e0UL, 0x1d121b17UL, - 0x0b0e090dUL, 0xadf28bc7UL, 0xb92db6a8UL, 0xc8141ea9UL, - 0x8557f119UL, 0x4caf7507UL, 0xbbee99ddUL, 0xfda37f60UL, - 0x9ff70126UL, 0xbc5c72f5UL, 0xc544663bUL, 0x345bfb7eUL, - 0x768b4329UL, 0xdccb23c6UL, 0x68b6edfcUL, 0x63b8e4f1UL, - 0xcad731dcUL, 0x10426385UL, 0x40139722UL, 0x2084c611UL, - 0x7d854a24UL, 0xf8d2bb3dUL, 0x11aef932UL, 0x6dc729a1UL, - 0x4b1d9e2fUL, 0xf3dcb230UL, 0xec0d8652UL, 0xd077c1e3UL, - 0x6c2bb316UL, 0x99a970b9UL, 0xfa119448UL, 0x2247e964UL, - 0xc4a8fc8cUL, 0x1aa0f03fUL, 0xd8567d2cUL, 0xef223390UL, - 0xc787494eUL, 0xc1d938d1UL, 0xfe8ccaa2UL, 0x3698d40bUL, - 0xcfa6f581UL, 0x28a57adeUL, 0x26dab78eUL, 0xa43fadbfUL, - 0xe42c3a9dUL, 0x0d507892UL, 0x9b6a5fccUL, 0x62547e46UL, - 0xc2f68d13UL, 0xe890d8b8UL, 0x5e2e39f7UL, 0xf582c3afUL, - 0xbe9f5d80UL, 0x7c69d093UL, 0xa96fd52dUL, 0xb3cf2512UL, - 0x3bc8ac99UL, 0xa710187dUL, 0x6ee89c63UL, 0x7bdb3bbbUL, - 0x09cd2678UL, 0xf46e5918UL, 0x01ec9ab7UL, 0xa8834f9aUL, - 0x65e6956eUL, 0x7eaaffe6UL, 0x0821bccfUL, 0xe6ef15e8UL, - 0xd9bae79bUL, 0xce4a6f36UL, 0xd4ea9f09UL, 0xd629b07cUL, - 0xaf31a4b2UL, 0x312a3f23UL, 0x30c6a594UL, 0xc035a266UL, - 0x37744ebcUL, 0xa6fc82caUL, 0xb0e090d0UL, 0x1533a7d8UL, - 0x4af10498UL, 0xf741ecdaUL, 0x0e7fcd50UL, 0x2f1791f6UL, - 0x8d764dd6UL, 0x4d43efb0UL, 0x54ccaa4dUL, 0xdfe49604UL, - 0xe39ed1b5UL, 0x1b4c6a88UL, 0xb8c12c1fUL, 0x7f466551UL, - 0x049d5eeaUL, 0x5d018c35UL, 0x73fa8774UL, 0x2efb0b41UL, - 0x5ab3671dUL, 0x5292dbd2UL, 0x33e91056UL, 0x136dd647UL, - 0x8c9ad761UL, 0x7a37a10cUL, 0x8e59f814UL, 0x89eb133cUL, - 0xeecea927UL, 0x35b761c9UL, 0xede11ce5UL, 0x3c7a47b1UL, - 0x599cd2dfUL, 0x3f55f273UL, 0x791814ceUL, 0xbf73c737UL, - 0xea53f7cdUL, 0x5b5ffdaaUL, 0x14df3d6fUL, 0x867844dbUL, - 0x81caaff3UL, 0x3eb968c4UL, 0x2c382434UL, 0x5fc2a340UL, - 0x72161dc3UL, 0x0cbce225UL, 0x8b283c49UL, 0x41ff0d95UL, - 0x7139a801UL, 0xde080cb3UL, 0x9cd8b4e4UL, 0x906456c1UL, - 0x617bcb84UL, 0x70d532b6UL, 0x74486c5cUL, 0x42d0b857UL, -}; -static const unsigned int Td2[256] = { - 0xa75051f4UL, 0x65537e41UL, 0xa4c31a17UL, 0x5e963a27UL, - 0x6bcb3babUL, 0x45f11f9dUL, 0x58abacfaUL, 0x03934be3UL, - 0xfa552030UL, 0x6df6ad76UL, 0x769188ccUL, 0x4c25f502UL, - 0xd7fc4fe5UL, 0xcbd7c52aUL, 0x44802635UL, 0xa38fb562UL, - 0x5a49deb1UL, 0x1b6725baUL, 0x0e9845eaUL, 0xc0e15dfeUL, - 0x7502c32fUL, 0xf012814cUL, 0x97a38d46UL, 0xf9c66bd3UL, - 0x5fe7038fUL, 0x9c951592UL, 0x7aebbf6dUL, 0x59da9552UL, - 0x832dd4beUL, 0x21d35874UL, 0x692949e0UL, 0xc8448ec9UL, - 0x896a75c2UL, 0x7978f48eUL, 0x3e6b9958UL, 0x71dd27b9UL, - 0x4fb6bee1UL, 0xad17f088UL, 0xac66c920UL, 0x3ab47dceUL, - 0x4a1863dfUL, 0x3182e51aUL, 0x33609751UL, 0x7f456253UL, - 0x77e0b164UL, 0xae84bb6bUL, 0xa01cfe81UL, 0x2b94f908UL, - 0x68587048UL, 0xfd198f45UL, 0x6c8794deUL, 0xf8b7527bUL, - 0xd323ab73UL, 0x02e2724bUL, 0x8f57e31fUL, 0xab2a6655UL, - 0x2807b2ebUL, 0xc2032fb5UL, 0x7b9a86c5UL, 0x08a5d337UL, - 0x87f23028UL, 0xa5b223bfUL, 0x6aba0203UL, 0x825ced16UL, - 0x1c2b8acfUL, 0xb492a779UL, 0xf2f0f307UL, 0xe2a14e69UL, - 0xf4cd65daUL, 0xbed50605UL, 0x621fd134UL, 0xfe8ac4a6UL, - 0x539d342eUL, 0x55a0a2f3UL, 0xe132058aUL, 0xeb75a4f6UL, - 0xec390b83UL, 0xefaa4060UL, 0x9f065e71UL, 0x1051bd6eUL, - 0x8af93e21UL, 0x063d96ddUL, 0x05aedd3eUL, 0xbd464de6UL, - 0x8db59154UL, 0x5d0571c4UL, 0xd46f0406UL, 0x15ff6050UL, - 0xfb241998UL, 0xe997d6bdUL, 0x43cc8940UL, 0x9e7767d9UL, - 0x42bdb0e8UL, 0x8b880789UL, 0x5b38e719UL, 0xeedb79c8UL, - 0x0a47a17cUL, 0x0fe97c42UL, 0x1ec9f884UL, 0x00000000UL, - 0x86830980UL, 0xed48322bUL, 0x70ac1e11UL, 0x724e6c5aUL, - 0xfffbfd0eUL, 0x38560f85UL, 0xd51e3daeUL, 0x3927362dUL, - 0xd9640a0fUL, 0xa621685cUL, 0x54d19b5bUL, 0x2e3a2436UL, - 0x67b10c0aUL, 0xe70f9357UL, 0x96d2b4eeUL, 0x919e1b9bUL, - 0xc54f80c0UL, 0x20a261dcUL, 0x4b695a77UL, 0x1a161c12UL, - 0xba0ae293UL, 0x2ae5c0a0UL, 0xe0433c22UL, 0x171d121bUL, - 0x0d0b0e09UL, 0xc7adf28bUL, 0xa8b92db6UL, 0xa9c8141eUL, - 0x198557f1UL, 0x074caf75UL, 0xddbbee99UL, 0x60fda37fUL, - 0x269ff701UL, 0xf5bc5c72UL, 0x3bc54466UL, 0x7e345bfbUL, - 0x29768b43UL, 0xc6dccb23UL, 0xfc68b6edUL, 0xf163b8e4UL, - 0xdccad731UL, 0x85104263UL, 0x22401397UL, 0x112084c6UL, - 0x247d854aUL, 0x3df8d2bbUL, 0x3211aef9UL, 0xa16dc729UL, - 0x2f4b1d9eUL, 0x30f3dcb2UL, 0x52ec0d86UL, 0xe3d077c1UL, - 0x166c2bb3UL, 0xb999a970UL, 0x48fa1194UL, 0x642247e9UL, - 0x8cc4a8fcUL, 0x3f1aa0f0UL, 0x2cd8567dUL, 0x90ef2233UL, - 0x4ec78749UL, 0xd1c1d938UL, 0xa2fe8ccaUL, 0x0b3698d4UL, - 0x81cfa6f5UL, 0xde28a57aUL, 0x8e26dab7UL, 0xbfa43fadUL, - 0x9de42c3aUL, 0x920d5078UL, 0xcc9b6a5fUL, 0x4662547eUL, - 0x13c2f68dUL, 0xb8e890d8UL, 0xf75e2e39UL, 0xaff582c3UL, - 0x80be9f5dUL, 0x937c69d0UL, 0x2da96fd5UL, 0x12b3cf25UL, - 0x993bc8acUL, 0x7da71018UL, 0x636ee89cUL, 0xbb7bdb3bUL, - 0x7809cd26UL, 0x18f46e59UL, 0xb701ec9aUL, 0x9aa8834fUL, - 0x6e65e695UL, 0xe67eaaffUL, 0xcf0821bcUL, 0xe8e6ef15UL, - 0x9bd9bae7UL, 0x36ce4a6fUL, 0x09d4ea9fUL, 0x7cd629b0UL, - 0xb2af31a4UL, 0x23312a3fUL, 0x9430c6a5UL, 0x66c035a2UL, - 0xbc37744eUL, 0xcaa6fc82UL, 0xd0b0e090UL, 0xd81533a7UL, - 0x984af104UL, 0xdaf741ecUL, 0x500e7fcdUL, 0xf62f1791UL, - 0xd68d764dUL, 0xb04d43efUL, 0x4d54ccaaUL, 0x04dfe496UL, - 0xb5e39ed1UL, 0x881b4c6aUL, 0x1fb8c12cUL, 0x517f4665UL, - 0xea049d5eUL, 0x355d018cUL, 0x7473fa87UL, 0x412efb0bUL, - 0x1d5ab367UL, 0xd25292dbUL, 0x5633e910UL, 0x47136dd6UL, - 0x618c9ad7UL, 0x0c7a37a1UL, 0x148e59f8UL, 0x3c89eb13UL, - 0x27eecea9UL, 0xc935b761UL, 0xe5ede11cUL, 0xb13c7a47UL, - 0xdf599cd2UL, 0x733f55f2UL, 0xce791814UL, 0x37bf73c7UL, - 0xcdea53f7UL, 0xaa5b5ffdUL, 0x6f14df3dUL, 0xdb867844UL, - 0xf381caafUL, 0xc43eb968UL, 0x342c3824UL, 0x405fc2a3UL, - 0xc372161dUL, 0x250cbce2UL, 0x498b283cUL, 0x9541ff0dUL, - 0x017139a8UL, 0xb3de080cUL, 0xe49cd8b4UL, 0xc1906456UL, - 0x84617bcbUL, 0xb670d532UL, 0x5c74486cUL, 0x5742d0b8UL, -}; -static const unsigned int Td3[256] = { - 0xf4a75051UL, 0x4165537eUL, 0x17a4c31aUL, 0x275e963aUL, - 0xab6bcb3bUL, 0x9d45f11fUL, 0xfa58abacUL, 0xe303934bUL, - 0x30fa5520UL, 0x766df6adUL, 0xcc769188UL, 0x024c25f5UL, - 0xe5d7fc4fUL, 0x2acbd7c5UL, 0x35448026UL, 0x62a38fb5UL, - 0xb15a49deUL, 0xba1b6725UL, 0xea0e9845UL, 0xfec0e15dUL, - 0x2f7502c3UL, 0x4cf01281UL, 0x4697a38dUL, 0xd3f9c66bUL, - 0x8f5fe703UL, 0x929c9515UL, 0x6d7aebbfUL, 0x5259da95UL, - 0xbe832dd4UL, 0x7421d358UL, 0xe0692949UL, 0xc9c8448eUL, - 0xc2896a75UL, 0x8e7978f4UL, 0x583e6b99UL, 0xb971dd27UL, - 0xe14fb6beUL, 0x88ad17f0UL, 0x20ac66c9UL, 0xce3ab47dUL, - 0xdf4a1863UL, 0x1a3182e5UL, 0x51336097UL, 0x537f4562UL, - 0x6477e0b1UL, 0x6bae84bbUL, 0x81a01cfeUL, 0x082b94f9UL, - 0x48685870UL, 0x45fd198fUL, 0xde6c8794UL, 0x7bf8b752UL, - 0x73d323abUL, 0x4b02e272UL, 0x1f8f57e3UL, 0x55ab2a66UL, - 0xeb2807b2UL, 0xb5c2032fUL, 0xc57b9a86UL, 0x3708a5d3UL, - 0x2887f230UL, 0xbfa5b223UL, 0x036aba02UL, 0x16825cedUL, - 0xcf1c2b8aUL, 0x79b492a7UL, 0x07f2f0f3UL, 0x69e2a14eUL, - 0xdaf4cd65UL, 0x05bed506UL, 0x34621fd1UL, 0xa6fe8ac4UL, - 0x2e539d34UL, 0xf355a0a2UL, 0x8ae13205UL, 0xf6eb75a4UL, - 0x83ec390bUL, 0x60efaa40UL, 0x719f065eUL, 0x6e1051bdUL, - 0x218af93eUL, 0xdd063d96UL, 0x3e05aeddUL, 0xe6bd464dUL, - 0x548db591UL, 0xc45d0571UL, 0x06d46f04UL, 0x5015ff60UL, - 0x98fb2419UL, 0xbde997d6UL, 0x4043cc89UL, 0xd99e7767UL, - 0xe842bdb0UL, 0x898b8807UL, 0x195b38e7UL, 0xc8eedb79UL, - 0x7c0a47a1UL, 0x420fe97cUL, 0x841ec9f8UL, 0x00000000UL, - 0x80868309UL, 0x2bed4832UL, 0x1170ac1eUL, 0x5a724e6cUL, - 0x0efffbfdUL, 0x8538560fUL, 0xaed51e3dUL, 0x2d392736UL, - 0x0fd9640aUL, 0x5ca62168UL, 0x5b54d19bUL, 0x362e3a24UL, - 0x0a67b10cUL, 0x57e70f93UL, 0xee96d2b4UL, 0x9b919e1bUL, - 0xc0c54f80UL, 0xdc20a261UL, 0x774b695aUL, 0x121a161cUL, - 0x93ba0ae2UL, 0xa02ae5c0UL, 0x22e0433cUL, 0x1b171d12UL, - 0x090d0b0eUL, 0x8bc7adf2UL, 0xb6a8b92dUL, 0x1ea9c814UL, - 0xf1198557UL, 0x75074cafUL, 0x99ddbbeeUL, 0x7f60fda3UL, - 0x01269ff7UL, 0x72f5bc5cUL, 0x663bc544UL, 0xfb7e345bUL, - 0x4329768bUL, 0x23c6dccbUL, 0xedfc68b6UL, 0xe4f163b8UL, - 0x31dccad7UL, 0x63851042UL, 0x97224013UL, 0xc6112084UL, - 0x4a247d85UL, 0xbb3df8d2UL, 0xf93211aeUL, 0x29a16dc7UL, - 0x9e2f4b1dUL, 0xb230f3dcUL, 0x8652ec0dUL, 0xc1e3d077UL, - 0xb3166c2bUL, 0x70b999a9UL, 0x9448fa11UL, 0xe9642247UL, - 0xfc8cc4a8UL, 0xf03f1aa0UL, 0x7d2cd856UL, 0x3390ef22UL, - 0x494ec787UL, 0x38d1c1d9UL, 0xcaa2fe8cUL, 0xd40b3698UL, - 0xf581cfa6UL, 0x7ade28a5UL, 0xb78e26daUL, 0xadbfa43fUL, - 0x3a9de42cUL, 0x78920d50UL, 0x5fcc9b6aUL, 0x7e466254UL, - 0x8d13c2f6UL, 0xd8b8e890UL, 0x39f75e2eUL, 0xc3aff582UL, - 0x5d80be9fUL, 0xd0937c69UL, 0xd52da96fUL, 0x2512b3cfUL, - 0xac993bc8UL, 0x187da710UL, 0x9c636ee8UL, 0x3bbb7bdbUL, - 0x267809cdUL, 0x5918f46eUL, 0x9ab701ecUL, 0x4f9aa883UL, - 0x956e65e6UL, 0xffe67eaaUL, 0xbccf0821UL, 0x15e8e6efUL, - 0xe79bd9baUL, 0x6f36ce4aUL, 0x9f09d4eaUL, 0xb07cd629UL, - 0xa4b2af31UL, 0x3f23312aUL, 0xa59430c6UL, 0xa266c035UL, - 0x4ebc3774UL, 0x82caa6fcUL, 0x90d0b0e0UL, 0xa7d81533UL, - 0x04984af1UL, 0xecdaf741UL, 0xcd500e7fUL, 0x91f62f17UL, - 0x4dd68d76UL, 0xefb04d43UL, 0xaa4d54ccUL, 0x9604dfe4UL, - 0xd1b5e39eUL, 0x6a881b4cUL, 0x2c1fb8c1UL, 0x65517f46UL, - 0x5eea049dUL, 0x8c355d01UL, 0x877473faUL, 0x0b412efbUL, - 0x671d5ab3UL, 0xdbd25292UL, 0x105633e9UL, 0xd647136dUL, - 0xd7618c9aUL, 0xa10c7a37UL, 0xf8148e59UL, 0x133c89ebUL, - 0xa927eeceUL, 0x61c935b7UL, 0x1ce5ede1UL, 0x47b13c7aUL, - 0xd2df599cUL, 0xf2733f55UL, 0x14ce7918UL, 0xc737bf73UL, - 0xf7cdea53UL, 0xfdaa5b5fUL, 0x3d6f14dfUL, 0x44db8678UL, - 0xaff381caUL, 0x68c43eb9UL, 0x24342c38UL, 0xa3405fc2UL, - 0x1dc37216UL, 0xe2250cbcUL, 0x3c498b28UL, 0x0d9541ffUL, - 0xa8017139UL, 0x0cb3de08UL, 0xb4e49cd8UL, 0x56c19064UL, - 0xcb84617bUL, 0x32b670d5UL, 0x6c5c7448UL, 0xb85742d0UL, -}; -static const unsigned int Td4[256] = { - 0x52525252UL, 0x09090909UL, 0x6a6a6a6aUL, 0xd5d5d5d5UL, - 0x30303030UL, 0x36363636UL, 0xa5a5a5a5UL, 0x38383838UL, - 0xbfbfbfbfUL, 0x40404040UL, 0xa3a3a3a3UL, 0x9e9e9e9eUL, - 0x81818181UL, 0xf3f3f3f3UL, 0xd7d7d7d7UL, 0xfbfbfbfbUL, - 0x7c7c7c7cUL, 0xe3e3e3e3UL, 0x39393939UL, 0x82828282UL, - 0x9b9b9b9bUL, 0x2f2f2f2fUL, 0xffffffffUL, 0x87878787UL, - 0x34343434UL, 0x8e8e8e8eUL, 0x43434343UL, 0x44444444UL, - 0xc4c4c4c4UL, 0xdedededeUL, 0xe9e9e9e9UL, 0xcbcbcbcbUL, - 0x54545454UL, 0x7b7b7b7bUL, 0x94949494UL, 0x32323232UL, - 0xa6a6a6a6UL, 0xc2c2c2c2UL, 0x23232323UL, 0x3d3d3d3dUL, - 0xeeeeeeeeUL, 0x4c4c4c4cUL, 0x95959595UL, 0x0b0b0b0bUL, - 0x42424242UL, 0xfafafafaUL, 0xc3c3c3c3UL, 0x4e4e4e4eUL, - 0x08080808UL, 0x2e2e2e2eUL, 0xa1a1a1a1UL, 0x66666666UL, - 0x28282828UL, 0xd9d9d9d9UL, 0x24242424UL, 0xb2b2b2b2UL, - 0x76767676UL, 0x5b5b5b5bUL, 0xa2a2a2a2UL, 0x49494949UL, - 0x6d6d6d6dUL, 0x8b8b8b8bUL, 0xd1d1d1d1UL, 0x25252525UL, - 0x72727272UL, 0xf8f8f8f8UL, 0xf6f6f6f6UL, 0x64646464UL, - 0x86868686UL, 0x68686868UL, 0x98989898UL, 0x16161616UL, - 0xd4d4d4d4UL, 0xa4a4a4a4UL, 0x5c5c5c5cUL, 0xccccccccUL, - 0x5d5d5d5dUL, 0x65656565UL, 0xb6b6b6b6UL, 0x92929292UL, - 0x6c6c6c6cUL, 0x70707070UL, 0x48484848UL, 0x50505050UL, - 0xfdfdfdfdUL, 0xededededUL, 0xb9b9b9b9UL, 0xdadadadaUL, - 0x5e5e5e5eUL, 0x15151515UL, 0x46464646UL, 0x57575757UL, - 0xa7a7a7a7UL, 0x8d8d8d8dUL, 0x9d9d9d9dUL, 0x84848484UL, - 0x90909090UL, 0xd8d8d8d8UL, 0xababababUL, 0x00000000UL, - 0x8c8c8c8cUL, 0xbcbcbcbcUL, 0xd3d3d3d3UL, 0x0a0a0a0aUL, - 0xf7f7f7f7UL, 0xe4e4e4e4UL, 0x58585858UL, 0x05050505UL, - 0xb8b8b8b8UL, 0xb3b3b3b3UL, 0x45454545UL, 0x06060606UL, - 0xd0d0d0d0UL, 0x2c2c2c2cUL, 0x1e1e1e1eUL, 0x8f8f8f8fUL, - 0xcacacacaUL, 0x3f3f3f3fUL, 0x0f0f0f0fUL, 0x02020202UL, - 0xc1c1c1c1UL, 0xafafafafUL, 0xbdbdbdbdUL, 0x03030303UL, - 0x01010101UL, 0x13131313UL, 0x8a8a8a8aUL, 0x6b6b6b6bUL, - 0x3a3a3a3aUL, 0x91919191UL, 0x11111111UL, 0x41414141UL, - 0x4f4f4f4fUL, 0x67676767UL, 0xdcdcdcdcUL, 0xeaeaeaeaUL, - 0x97979797UL, 0xf2f2f2f2UL, 0xcfcfcfcfUL, 0xcecececeUL, - 0xf0f0f0f0UL, 0xb4b4b4b4UL, 0xe6e6e6e6UL, 0x73737373UL, - 0x96969696UL, 0xacacacacUL, 0x74747474UL, 0x22222222UL, - 0xe7e7e7e7UL, 0xadadadadUL, 0x35353535UL, 0x85858585UL, - 0xe2e2e2e2UL, 0xf9f9f9f9UL, 0x37373737UL, 0xe8e8e8e8UL, - 0x1c1c1c1cUL, 0x75757575UL, 0xdfdfdfdfUL, 0x6e6e6e6eUL, - 0x47474747UL, 0xf1f1f1f1UL, 0x1a1a1a1aUL, 0x71717171UL, - 0x1d1d1d1dUL, 0x29292929UL, 0xc5c5c5c5UL, 0x89898989UL, - 0x6f6f6f6fUL, 0xb7b7b7b7UL, 0x62626262UL, 0x0e0e0e0eUL, - 0xaaaaaaaaUL, 0x18181818UL, 0xbebebebeUL, 0x1b1b1b1bUL, - 0xfcfcfcfcUL, 0x56565656UL, 0x3e3e3e3eUL, 0x4b4b4b4bUL, - 0xc6c6c6c6UL, 0xd2d2d2d2UL, 0x79797979UL, 0x20202020UL, - 0x9a9a9a9aUL, 0xdbdbdbdbUL, 0xc0c0c0c0UL, 0xfefefefeUL, - 0x78787878UL, 0xcdcdcdcdUL, 0x5a5a5a5aUL, 0xf4f4f4f4UL, - 0x1f1f1f1fUL, 0xddddddddUL, 0xa8a8a8a8UL, 0x33333333UL, - 0x88888888UL, 0x07070707UL, 0xc7c7c7c7UL, 0x31313131UL, - 0xb1b1b1b1UL, 0x12121212UL, 0x10101010UL, 0x59595959UL, - 0x27272727UL, 0x80808080UL, 0xececececUL, 0x5f5f5f5fUL, - 0x60606060UL, 0x51515151UL, 0x7f7f7f7fUL, 0xa9a9a9a9UL, - 0x19191919UL, 0xb5b5b5b5UL, 0x4a4a4a4aUL, 0x0d0d0d0dUL, - 0x2d2d2d2dUL, 0xe5e5e5e5UL, 0x7a7a7a7aUL, 0x9f9f9f9fUL, - 0x93939393UL, 0xc9c9c9c9UL, 0x9c9c9c9cUL, 0xefefefefUL, - 0xa0a0a0a0UL, 0xe0e0e0e0UL, 0x3b3b3b3bUL, 0x4d4d4d4dUL, - 0xaeaeaeaeUL, 0x2a2a2a2aUL, 0xf5f5f5f5UL, 0xb0b0b0b0UL, - 0xc8c8c8c8UL, 0xebebebebUL, 0xbbbbbbbbUL, 0x3c3c3c3cUL, - 0x83838383UL, 0x53535353UL, 0x99999999UL, 0x61616161UL, - 0x17171717UL, 0x2b2b2b2bUL, 0x04040404UL, 0x7e7e7e7eUL, - 0xbabababaUL, 0x77777777UL, 0xd6d6d6d6UL, 0x26262626UL, - 0xe1e1e1e1UL, 0x69696969UL, 0x14141414UL, 0x63636363UL, - 0x55555555UL, 0x21212121UL, 0x0c0c0c0cUL, 0x7d7d7d7dUL, -}; -static const unsigned int rcon[] = { - 0x01000000UL, 0x02000000UL, 0x04000000UL, 0x08000000UL, - 0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL, - 0x1B000000UL, 0x36000000UL, -}; - -#define GETU32(pt) (((unsigned int)(pt)[0] << 24) ^ \ - ((unsigned int)(pt)[1] << 16) ^ \ - ((unsigned int)(pt)[2] << 8) ^ \ - ((unsigned int)(pt)[3])) - -#define PUTU32(ct, st) { (ct)[0] = (unsigned char)((st) >> 24); \ - (ct)[1] = (unsigned char)((st) >> 16); \ - (ct)[2] = (unsigned char)((st) >> 8); \ - (ct)[3] = (unsigned char)(st); } - -/* -* Expand the cipher key into the encryption key schedule and return the -* number of rounds for the given cipher key size. -*/ -int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBytes) { - int i = 0; - unsigned int temp; - - rk[0] = GETU32(cipherKey); - rk[1] = GETU32(cipherKey + 4); - rk[2] = GETU32(cipherKey + 8); - rk[3] = GETU32(cipherKey + 12); - if (keyBytes == 16) { // 128 bits - for (;;) { - temp = rk[3]; - rk[4] = rk[0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[5] = rk[1] ^ rk[4]; - rk[6] = rk[2] ^ rk[5]; - rk[7] = rk[3] ^ rk[6]; - if (++i == 10) { - return 10; - } - rk += 4; - } - } - rk[4] = GETU32(cipherKey + 16); - rk[5] = GETU32(cipherKey + 20); - if (keyBytes == 24) { // 192 bits - for (;;) { - temp = rk[ 5]; - rk[ 6] = rk[ 0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[ 7] = rk[ 1] ^ rk[ 6]; - rk[ 8] = rk[ 2] ^ rk[ 7]; - rk[ 9] = rk[ 3] ^ rk[ 8]; - if (++i == 8) { - return 12; - } - rk[10] = rk[ 4] ^ rk[ 9]; - rk[11] = rk[ 5] ^ rk[10]; - rk += 6; - } - } - rk[6] = GETU32(cipherKey + 24); - rk[7] = GETU32(cipherKey + 28); - if (keyBytes == 32) { // 256 bits - for (;;) { - temp = rk[ 7]; - rk[ 8] = rk[ 0] ^ - (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ - (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ - (Te4[(temp) & 0xff] & 0x0000ff00) ^ - (Te4[(temp >> 24) ] & 0x000000ff) ^ - rcon[i]; - rk[ 9] = rk[ 1] ^ rk[ 8]; - rk[10] = rk[ 2] ^ rk[ 9]; - rk[11] = rk[ 3] ^ rk[10]; - if (++i == 7) { - return 14; - } - temp = rk[11]; - rk[12] = rk[ 4] ^ - (Te4[(temp >> 24) ] & 0xff000000) ^ - (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(temp) & 0xff] & 0x000000ff); - rk[13] = rk[ 5] ^ rk[12]; - rk[14] = rk[ 6] ^ rk[13]; - rk[15] = rk[ 7] ^ rk[14]; - - rk += 8; - } - } - return 0; -} - -/* -* Expand the cipher key into encryption and decryption key schedule and -* return the number of rounds for the given cipher key size. -*/ -int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char cipherKey[], int keyBytes) { - int Nr, i; - - // expand the cipher key - Nr = aes_setkey_enc(rk, cipherKey, keyBytes); - // invert the order of the first round keys - rrk += Nr * 4; - rrk[0] = rk[0]; - rrk[1] = rk[1]; - rrk[2] = rk[2]; - rrk[3] = rk[3]; - - /* - * apply the inverse MixColumn transform to all round keys but the first - * and the last - */ - for (i = 1; i < Nr; i++) { - rrk -= 4; - rk += 4; - rrk[0] = - Td0[Te4[(rk[0] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[0]) & 0xff] & 0xff]; - rrk[1] = - Td0[Te4[(rk[1] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[1]) & 0xff] & 0xff]; - rrk[2] = - Td0[Te4[(rk[2] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[2]) & 0xff] & 0xff]; - rrk[3] = - Td0[Te4[(rk[3] >> 24) ] & 0xff] ^ - Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^ - Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^ - Td3[Te4[(rk[3]) & 0xff] & 0xff]; - } - // invert the order of the last round keys - rrk -= 4; - rk += 4; - rrk[0] = rk[0]; - rrk[1] = rk[1]; - rrk[2] = rk[2]; - rrk[3] = rk[3]; - - return Nr; -} - -/* -* Encrypt the plain text into cipher -*/ -void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[]) { - unsigned int s0, s1, s2, s3, t0, t1, t2, t3, *iv; - const unsigned int *rk; - int r; - - rk = pCtx->Ek; - iv = pCtx->Iv; - /* - * map byte array block to cipher state - * and add initial round key: - */ - s0 = GETU32(pt) ^ rk[0]; - s1 = GETU32(pt + 4) ^ rk[1]; - s2 = GETU32(pt + 8) ^ rk[2]; - s3 = GETU32(pt + 12) ^ rk[3]; - if (pCtx->Mode) { - s0 = s0 ^ iv[0]; - s1 = s1 ^ iv[1]; - s2 = s2 ^ iv[2]; - s3 = s3 ^ iv[3]; - } - /* - * Nr - 1 full rounds: - */ - r = pCtx->Nr >> 1; - for (;;) { - t0 = - Te0[(s0 >> 24) ] ^ - Te1[(s1 >> 16) & 0xff] ^ - Te2[(s2 >> 8) & 0xff] ^ - Te3[(s3) & 0xff] ^ - rk[4]; - t1 = - Te0[(s1 >> 24) ] ^ - Te1[(s2 >> 16) & 0xff] ^ - Te2[(s3 >> 8) & 0xff] ^ - Te3[(s0) & 0xff] ^ - rk[5]; - t2 = - Te0[(s2 >> 24) ] ^ - Te1[(s3 >> 16) & 0xff] ^ - Te2[(s0 >> 8) & 0xff] ^ - Te3[(s1) & 0xff] ^ - rk[6]; - t3 = - Te0[(s3 >> 24) ] ^ - Te1[(s0 >> 16) & 0xff] ^ - Te2[(s1 >> 8) & 0xff] ^ - Te3[(s2) & 0xff] ^ - rk[7]; - - rk += 8; - if (--r == 0) { - break; - } - - s0 = - Te0[(t0 >> 24) ] ^ - Te1[(t1 >> 16) & 0xff] ^ - Te2[(t2 >> 8) & 0xff] ^ - Te3[(t3) & 0xff] ^ - rk[0]; - s1 = - Te0[(t1 >> 24) ] ^ - Te1[(t2 >> 16) & 0xff] ^ - Te2[(t3 >> 8) & 0xff] ^ - Te3[(t0) & 0xff] ^ - rk[1]; - s2 = - Te0[(t2 >> 24) ] ^ - Te1[(t3 >> 16) & 0xff] ^ - Te2[(t0 >> 8) & 0xff] ^ - Te3[(t1) & 0xff] ^ - rk[2]; - s3 = - Te0[(t3 >> 24) ] ^ - Te1[(t0 >> 16) & 0xff] ^ - Te2[(t1 >> 8) & 0xff] ^ - Te3[(t2) & 0xff] ^ - rk[3]; - } - /* - * apply last round and - * map cipher state to byte array block: - */ - s0 = - (Te4[(t0 >> 24) ] & 0xff000000) ^ - (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t3) & 0xff] & 0x000000ff) ^ - rk[0]; - PUTU32(ct, s0); - s1 = - (Te4[(t1 >> 24) ] & 0xff000000) ^ - (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t0) & 0xff] & 0x000000ff) ^ - rk[1]; - PUTU32(ct + 4, s1); - s2 = - (Te4[(t2 >> 24) ] & 0xff000000) ^ - (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t1) & 0xff] & 0x000000ff) ^ - rk[2]; - PUTU32(ct + 8, s2); - s3 = - (Te4[(t3 >> 24) ] & 0xff000000) ^ - (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ - (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ - (Te4[(t2) & 0xff] & 0x000000ff) ^ - rk[3]; - PUTU32(ct + 12, s3); - - if (pCtx->Mode) { - iv[0] = s0; - iv[1] = s1; - iv[2] = s2; - iv[3] = s3; - } -} - -/* -* Decrypt the cipher into plain text -*/ -void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[]) { - unsigned int s0, s1, s2, s3, t0, t1, t2, t3, v0, v1, v2, v3, *iv; - const unsigned int *rk; - int r; - - rk = pCtx->Dk; - iv = pCtx->Iv; - /* - * map byte array block to cipher state - * and add initial round key: - */ - v0 = GETU32(ct); - s0 = v0 ^ rk[0]; - v1 = GETU32(ct + 4); - s1 = v1 ^ rk[1]; - v2 = GETU32(ct + 8); - s2 = v2 ^ rk[2]; - v3 = GETU32(ct + 12); - s3 = v3 ^ rk[3]; - /* - * Nr - 1 full rounds: - */ - r = pCtx->Nr >> 1; - for (;;) { - t0 = - Td0[(s0 >> 24) ] ^ - Td1[(s3 >> 16) & 0xff] ^ - Td2[(s2 >> 8) & 0xff] ^ - Td3[(s1) & 0xff] ^ - rk[4]; - t1 = - Td0[(s1 >> 24) ] ^ - Td1[(s0 >> 16) & 0xff] ^ - Td2[(s3 >> 8) & 0xff] ^ - Td3[(s2) & 0xff] ^ - rk[5]; - t2 = - Td0[(s2 >> 24) ] ^ - Td1[(s1 >> 16) & 0xff] ^ - Td2[(s0 >> 8) & 0xff] ^ - Td3[(s3) & 0xff] ^ - rk[6]; - t3 = - Td0[(s3 >> 24) ] ^ - Td1[(s2 >> 16) & 0xff] ^ - Td2[(s1 >> 8) & 0xff] ^ - Td3[(s0) & 0xff] ^ - rk[7]; - - rk += 8; - if (--r == 0) { - break; - } - - s0 = - Td0[(t0 >> 24) ] ^ - Td1[(t3 >> 16) & 0xff] ^ - Td2[(t2 >> 8) & 0xff] ^ - Td3[(t1) & 0xff] ^ - rk[0]; - s1 = - Td0[(t1 >> 24) ] ^ - Td1[(t0 >> 16) & 0xff] ^ - Td2[(t3 >> 8) & 0xff] ^ - Td3[(t2) & 0xff] ^ - rk[1]; - s2 = - Td0[(t2 >> 24) ] ^ - Td1[(t1 >> 16) & 0xff] ^ - Td2[(t0 >> 8) & 0xff] ^ - Td3[(t3) & 0xff] ^ - rk[2]; - s3 = - Td0[(t3 >> 24) ] ^ - Td1[(t2 >> 16) & 0xff] ^ - Td2[(t1 >> 8) & 0xff] ^ - Td3[(t0) & 0xff] ^ - rk[3]; - } - /* - * apply last round and - * map cipher state to byte array block: - */ - s0 = - (Td4[(t0 >> 24) ] & 0xff000000) ^ - (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t1) & 0xff] & 0x000000ff) ^ - rk[0]; - s1 = - (Td4[(t1 >> 24) ] & 0xff000000) ^ - (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t2) & 0xff] & 0x000000ff) ^ - rk[1]; - s2 = - (Td4[(t2 >> 24) ] & 0xff000000) ^ - (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t3) & 0xff] & 0x000000ff) ^ - rk[2]; - s3 = - (Td4[(t3 >> 24) ] & 0xff000000) ^ - (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ - (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ - (Td4[(t0) & 0xff] & 0x000000ff) ^ - rk[3]; - - if (pCtx->Mode) { - s0 = s0 ^ iv[0]; - iv[0] = v0; - s1 = s1 ^ iv[1]; - iv[1] = v1; - s2 = s2 ^ iv[2]; - iv[2] = v2; - s3 = s3 ^ iv[3]; - iv[3] = v3; - } - - PUTU32(pt, s0); - PUTU32(pt + 4, s1); - PUTU32(pt + 8, s2); - PUTU32(pt + 12, s3); -} - -////////////////////////////////////////////////////////////////////////////// -// API functions // -////////////////////////////////////////////////////////////////////////////// - -/* -* initialize AES context -*/ -int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode) { - if (pKey == 0 || pCtx == 0 || (KeyLen != KEY128 && KeyLen != KEY192 && KeyLen != KEY256)) - return -1; - - // generate key schedule - pCtx->Nr = AesGenKeySched(pCtx->Ek, pCtx->Dk, pKey, KeyLen); - - // initialize IV - if (pIV != 0) { - pCtx->Iv[0] = GETU32(pIV); - pCtx->Iv[1] = GETU32(pIV + 4); - pCtx->Iv[2] = GETU32(pIV + 8); - pCtx->Iv[3] = GETU32(pIV + 12); - } - - // mode - pCtx->Mode = Mode; - - return 0; -} - -/* -* Encrypt plain text -*/ -int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen) { - int i; - - if (pData == 0 || pCipher == 0 || pCtx == 0 || (DataLen & 0xf) != 0) - return -1; - - for (i = 0; i < DataLen; i += BLOCKSZ) { - // encrypt block by block - AesEncBlk(pCtx, pData, pCipher); - pCipher += BLOCKSZ; - pData += BLOCKSZ; - } - return DataLen; -} - -/* -* Decrypt cipher -*/ -int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen) { - int i; - - if (pData == 0 || pCipher == 0 || pCtx == 0 || (CipherLen & 0xf) != 0) - return -1; - - for (i = 0; i < CipherLen; i += BLOCKSZ) { - // decrypt block by block - AesDecBlk(pCtx, pCipher, pData); - pCipher += BLOCKSZ; - pData += BLOCKSZ; - } - return CipherLen; -} - -////////////////////////////////////////////////////////////////////////////// -// Sample main program // -////////////////////////////////////////////////////////////////////////////// - -#ifndef EMBEDDED - -#include - -int main() { - AesCtx ctx; - unsigned char iv[] = "INI VECTINI VECT"; - unsigned char key[] = "This is a sample AESKey"; - unsigned char databuf[] = "Data : AES Test"; // must be in multiple of 16 - - // initialize context and encrypt data at one end - - if (AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0) - printf("init error\n"); - - if (AesEncrypt(&ctx, databuf, databuf, sizeof(databuf)) < 0) - printf("error in encryption\n"); - - // initialize context and decrypt cipher at other end - - if (AesCtxIni(&ctx, iv, key, KEY128, CBC) < 0) - printf("init error\n"); - - if (AesDecrypt(&ctx, databuf, databuf, sizeof(databuf)) < 0) - printf("error in decryption\n"); - - printf("%s\n", databuf); - - return 0; -} -#endif diff --git a/armsrc/aes.h b/armsrc/aes.h deleted file mode 100644 index aa9f0c582..000000000 --- a/armsrc/aes.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* AES Cryptographic Algorithm Header File. Include this header file in -* your source which uses these given APIs. (This source is kept under -* public domain) -*/ -#ifndef __AES_H -#define __AES_H - -// AES context structure -typedef struct { - unsigned int Ek[60]; - unsigned int Dk[60]; - unsigned int Iv[4]; - unsigned char Nr; - unsigned char Mode; -} AesCtx; - -// key length in bytes -#define KEY128 16 -#define KEY192 24 -#define KEY256 32 -// block size in bytes -#define BLOCKSZ 16 -// mode -#define EBC 0 -#define CBC 1 - -// AES API function prototype - -int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode); -int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen); -int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen); - -#endif diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 23b55a23b..d9c17e3b3 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -13,6 +13,7 @@ #include #include "usb_cdc.h" #include "proxmark3.h" +#include "pmflash.h" #include "apps.h" #include "fpga.h" #include "util.h" @@ -339,19 +340,25 @@ void SendVersion(void) { if (bootrom_version < &_flash_start || bootrom_version >= &_flash_end) { strcat(VersionString, "bootrom version information appears invalid\n"); } else { - FormatVersionInformation(temp, sizeof(temp), " bootrom: ", bootrom_version); + FormatVersionInformation(temp, sizeof(temp), " bootrom: ", bootrom_version); strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); } - FormatVersionInformation(temp, sizeof(temp), " os: ", &version_information); + FormatVersionInformation(temp, sizeof(temp), " os: ", &version_information); strncat(VersionString, temp, sizeof(VersionString) - strlen(VersionString) - 1); - strncat(VersionString, "\n [ FPGA ]\n", sizeof(VersionString) - strlen(VersionString) - 1); +#if defined(__clang__) + strncat(VersionString, " compiled with Clang/LLVM "__VERSION__"\n", sizeof(VersionString) - strlen(VersionString) - 1); +#elif defined(__GNUC__) || defined(__GNUG__) + strncat(VersionString, " compiled with GCC "__VERSION__"\n", sizeof(VersionString) - strlen(VersionString) - 1); +#endif + + strncat(VersionString, "\n [ FPGA ]\n ", sizeof(VersionString) - strlen(VersionString) - 1); for (int i = 0; i < fpga_bitstream_num; i++) { strncat(VersionString, fpga_version_information[i], sizeof(VersionString) - strlen(VersionString) - 1); if (i < fpga_bitstream_num - 1) { - strncat(VersionString, "\n", sizeof(VersionString) - strlen(VersionString) - 1); + strncat(VersionString, "\n ", sizeof(VersionString) - strlen(VersionString) - 1); } } // Send Chip ID and used flash memory @@ -368,10 +375,10 @@ void SendVersion(void) { struct p payload; payload.id = *(AT91C_DBGU_CIDR); payload.section_size = text_and_rodata_section_size + compressed_data_section_size; - payload.versionstr_len = strlen(VersionString); - memcpy(payload.versionstr, VersionString, strlen(VersionString)); + payload.versionstr_len = strlen(VersionString) + 1; + memcpy(payload.versionstr, VersionString, payload.versionstr_len); - reply_ng(CMD_VERSION, PM3_SUCCESS, (uint8_t *)&payload, 12 + strlen(VersionString)); + reply_ng(CMD_VERSION, PM3_SUCCESS, (uint8_t *)&payload, 12 + payload.versionstr_len); } // measure the Connection Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time. @@ -1586,38 +1593,6 @@ static void PacketReceived(PacketCommandNG *packet) { FlashmemSetSpiBaudrate(packet->oldarg[0]); break; } - case CMD_FLASHMEM_READ: { - LED_B_ON(); - uint32_t startidx = packet->oldarg[0]; - uint16_t len = packet->oldarg[1]; - - Dbprintf("FlashMem read | %d - %d | ", startidx, len); - - size_t size = MIN(PM3_CMD_DATA_SIZE, len); - - if (!FlashInit()) { - break; - } - - uint8_t *mem = BigBuf_malloc(size); - - for (size_t i = 0; i < len; i += size) { - len = MIN((len - i), size); - - Dbprintf("FlashMem reading | %d | %d | %d |", startidx + i, i, len); - uint16_t isok = Flash_ReadDataCont(startidx + i, mem, len); - if (isok == len) { - print_result("Chunk: ", mem, len); - } else { - Dbprintf("FlashMem reading failed | %d | %d", len, isok); - break; - } - } - BigBuf_free(); - FlashStop(); - LED_B_OFF(); - break; - } case CMD_FLASHMEM_WRITE: { LED_B_ON(); uint8_t isok = 0; @@ -1783,6 +1758,10 @@ static void PacketReceived(PacketCommandNG *packet) { SendStatus(); break; } + case CMD_STANDALONE: { + RunMod(); + break; + } case CMD_CAPABILITIES: { SendCapabilities(); break; diff --git a/armsrc/desfire_crypto.c b/armsrc/desfire_crypto.c index 10ddf4162..2e9d5a8d3 100644 --- a/armsrc/desfire_crypto.c +++ b/armsrc/desfire_crypto.c @@ -571,15 +571,19 @@ void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, case T_AES: switch (operation) { case MCO_ENCYPHER: { - AesCtx ctx; - AesCtxIni(&ctx, ivect, key->data, KEY128, CBC); - AesEncrypt(&ctx, data, edata, sizeof(edata)); + mbedtls_aes_context ctx; + mbedtls_aes_init(&ctx); + mbedtls_aes_setkey_enc(&ctx, key->data, 128); + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, sizeof(edata), ivect, data, edata); + mbedtls_aes_free(&ctx); break; } case MCO_DECYPHER: { - AesCtx ctx; - AesCtxIni(&ctx, ivect, key->data, KEY128, CBC); - AesDecrypt(&ctx, edata, data, sizeof(edata)); + mbedtls_aes_context ctx; + mbedtls_aes_init(&ctx); + mbedtls_aes_setkey_dec(&ctx, key->data, 128); + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, sizeof(edata), ivect, edata, data); + mbedtls_aes_free(&ctx); break; } } diff --git a/armsrc/flashmem.c b/armsrc/flashmem.c index 4584d41b2..ad4861ce3 100644 --- a/armsrc/flashmem.c +++ b/armsrc/flashmem.c @@ -1,4 +1,5 @@ #include "flashmem.h" +#include "pmflash.h" /* here: use NCPS2 @ PA10: */ #define SPI_CSR_NUM 2 diff --git a/armsrc/flashmem.h b/armsrc/flashmem.h index 4016e66bd..59d3bef9c 100644 --- a/armsrc/flashmem.h +++ b/armsrc/flashmem.h @@ -62,7 +62,7 @@ #define RESUME 0x7A // Flash busy timeout: 20ms is the strict minimum when writing 256kb -#define BUSY_TIMEOUT 50000L +#define BUSY_TIMEOUT 200000L #define WINBOND_MANID 0xEF #define WINBOND_DEVID 0x11 diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 2a7cf2859..682dd950a 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -331,64 +331,6 @@ size_t blocknr; // Hitag2 operations //----------------------------------------------------------------------------- -static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { - // Reset the transmission frame length - *txlen = 0; - - // Try to find out which command was send by selecting on length (in bits) - switch (rxlen) { - // No answer, try to resurrect - case 0: { - // Stop if there is no answer (after sending password) - if (bPwd) { - DbpString("Password failed!"); - return false; - } - *txlen = 5; - memcpy(tx, "\xC0", nbytes(*txlen)); - } - break; - - // Received UID, tag password - case 32: { - if (!bPwd) { - *txlen = 32; - memcpy(tx, password, 4); - bPwd = true; - memcpy(tag.sectors[blocknr], rx, 4); - blocknr++; - } else { - - if (blocknr == 1) { - //store password in block1, the TAG answers with Block3, but we need the password in memory - memcpy(tag.sectors[blocknr], tx, 4); - } else { - memcpy(tag.sectors[blocknr], rx, 4); - } - - blocknr++; - if (blocknr > 7) { - DbpString("Read succesful!"); - bSuccessful = true; - return false; - } - *txlen = 10; - tx[0] = 0xC0 | (blocknr << 3) | ((blocknr ^ 7) >> 2); - tx[1] = ((blocknr ^ 7) << 6); - } - } - break; - - // Unexpected response - default: { - Dbprintf("Uknown frame length: %d", rxlen); - return false; - } - break; - } - return true; -} - static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) { switch (writestate) { case WRITE_STATE_START: @@ -431,6 +373,71 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size return true; } +static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool write) { + // Reset the transmission frame length + *txlen = 0; + + if (bPwd && write) { + if (!hitag2_write_page(rx, rxlen, tx, txlen)) { + return false; + } + } else { + // Try to find out which command was send by selecting on length (in bits) + switch (rxlen) { + // No answer, try to resurrect + case 0: { + // Stop if there is no answer (after sending password) + if (bPwd) { + DbpString("Password failed!"); + return false; + } + *txlen = 5; + memcpy(tx, "\xC0", nbytes(*txlen)); + } + break; + + // Received UID, tag password + case 32: { + if (!bPwd) { + *txlen = 32; + memcpy(tx, password, 4); + bPwd = true; + memcpy(tag.sectors[blocknr], rx, 4); + blocknr++; + } else { + + if (blocknr == 1) { + //store password in block1, the TAG answers with Block3, but we need the password in memory + memcpy(tag.sectors[blocknr], tx, 4); + } else { + memcpy(tag.sectors[blocknr], rx, 4); + } + + blocknr++; + if (blocknr > 7) { + DbpString("Read succesful!"); + bSuccessful = true; + return false; + } + *txlen = 10; + tx[0] = 0xC0 | (blocknr << 3) | ((blocknr ^ 7) >> 2); + tx[1] = ((blocknr ^ 7) << 6); + } + } + break; + + // Unexpected response + default: { + Dbprintf("Uknown frame length: %d", rxlen); + return false; + } + break; + } + } + + return true; +} + static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool write) { // Reset the transmission frame length *txlen = 0; @@ -739,7 +746,7 @@ void SniffHitag(void) { AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // synchronized startup procedure - while (AT91C_BASE_TC0->TC_CV > 0) {}; // wait until TC0 returned to zero + while (AT91C_BASE_TC1->TC_CV > 0) {}; // wait until TC1 returned to zero // Reset the received frame, frame count and timing info memset(rx, 0x00, sizeof(rx)); @@ -887,7 +894,6 @@ void SniffHitag(void) { set_tracing(false); AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; - AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // release allocated memory from BigBuff. BigBuf_free(); @@ -1218,7 +1224,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) { tx = txbuf; switch (htf) { case RHT2F_PASSWORD: { - bStop = !hitag2_password(rx, rxlen, tx, &txlen); + bStop = !hitag2_password(rx, rxlen, tx, &txlen, false); break; } case RHT2F_AUTHENTICATE: { @@ -1392,6 +1398,16 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) { writestate = WRITE_STATE_START; } break; + case WHT2F_PASSWORD: { + DbpString("Authenticating using password:"); + memcpy(password, htd->pwd.password, 4); + memcpy(writedata, htd->crypto.data, 4); + Dbhexdump(4, password, false); + blocknr = page; + bPwd = false; + writestate = WRITE_STATE_START; + } + break; default: { Dbprintf("Error, unknown function: %d", htf); StartTicks(); @@ -1481,6 +1497,10 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) { bStop = !hitag2_crypto(rx, rxlen, tx, &txlen, true); } break; + case WHT2F_PASSWORD: { + bStop = !hitag2_password(rx, rxlen, tx, &txlen, true); + } + break; default: { Dbprintf("Error, unknown function: %d", htf); return; diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 09a1632cb..96fd3ae37 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -19,6 +19,7 @@ #include "protocols.h" #include "usb_cdc.h" // for usb_poll_validate_length #include "common.h" +#include "pmflash.h" #include "flashmem.h" // persistence on mem //#define START_GAP 31*8 // was 250 // SPEC: 1*8 to 50*8 - typ 15*8 (15fc) diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index c5a075e7a..c88401229 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -136,11 +136,11 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag uint32_t sample_total_numbers = 0; uint32_t sample_total_saved = 0; uint32_t cancel_counter = 0; - + uint16_t checker = 0; - + while (true) { - if ( checker == 1000 ) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else @@ -148,7 +148,7 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag } else { ++checker; } - + WDT_HIT(); if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) { @@ -293,11 +293,11 @@ void doT55x7Acquisition(size_t sample_size) { bool startFound = false; bool highFound = false; bool lowFound = false; - + uint16_t checker = 0; - - while ( skipCnt < 1000 && (i < bufsize)) { - if ( checker == 1000 ) { + + while (skipCnt < 1000 && (i < bufsize)) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else @@ -371,9 +371,9 @@ void doCotagAcquisition(size_t sample_size) { uint16_t noise_counter = 0; uint16_t checker = 0; - + while ((i < bufsize) && (noise_counter < (COTAG_T1 << 1))) { - if ( checker == 1000 ) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else @@ -431,9 +431,9 @@ uint32_t doCotagAcquisitionManchester() { uint8_t curr = 0, prev = 0; uint16_t noise_counter = 0; uint16_t checker = 0; - + while ((sample_counter < bufsize) && (noise_counter < (COTAG_T1 << 1))) { - if ( checker == 1000 ) { + if (checker == 1000) { if (BUTTON_PRESS() || data_available()) break; else diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 26b6583fc..2d56a8a37 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -14,8 +14,11 @@ //----------------------------------------------------------------------------- #include "mifarecmd.h" + #include +#include "pmflash.h" + #ifndef HARDNESTED_AUTHENTICATION_TIMEOUT # define HARDNESTED_AUTHENTICATION_TIMEOUT 848 // card times out 1ms after wrong authentication (according to NXP documentation) #endif diff --git a/armsrc/mifaredesfire.c b/armsrc/mifaredesfire.c index bda31790d..c57fed866 100644 --- a/armsrc/mifaredesfire.c +++ b/armsrc/mifaredesfire.c @@ -433,15 +433,9 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) desfirekey_t key = &defaultkey; Desfire_aes_key_new(keybytes, key); - AesCtx ctx; + mbedtls_aes_context ctx; uint8_t IV[16] = {0x00}; - if (AesCtxIni(&ctx, IV, key->data, KEY128, CBC) < 0) { - if (DBGLEVEL >= 4) { - DbpString("AES context failed to init"); - } - OnError(7); - return; - } + mbedtls_aes_init(&ctx); cmd[0] = AUTHENTICATE_AES; cmd[1] = 0x00; //keynumber @@ -457,13 +451,27 @@ void MifareDES_Auth1(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) memcpy(encRndB, resp + 3, 16); // dekryptera tagnonce. - AesDecrypt(&ctx, encRndB, decRndB, 16); + if (mbedtls_aes_setkey_dec(&ctx, key->data, 128) != 0) { + if (DBGLEVEL >= 4) { + DbpString("mbedtls_aes_setkey_dec failed"); + } + OnError(7); + return; + } + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, 16, IV, encRndB, decRndB); rol(decRndB, 16); uint8_t nonce[16] = {0x00}; memcpy(both, nonce, 16); memcpy(both + 16, decRndB, 16); uint8_t encBoth[32] = {0x00}; - AesEncrypt(&ctx, both, encBoth, 32); + if (mbedtls_aes_setkey_enc(&ctx, key->data, 128) != 0) { + if (DBGLEVEL >= 4) { + DbpString("mbedtls_aes_setkey_enc failed"); + } + OnError(7); + return; + } + mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 32, IV, both, encBoth); cmd[0] = ADDITIONAL_FRAME; memcpy(cmd + 1, encBoth, 32); diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 714beb284..d211b543b 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -606,8 +606,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { if (receivedCmd_len == 9 && receivedCmd[1] == 0x70) { if (memcmp(&receivedCmd[2], responses[uid_index].response, 4) == 0) { bool cl_finished = (uid_len == 4 && uid_index == UIDBCC1) || - (uid_len == 7 && uid_index == UIDBCC2) || - (uid_len == 10 && uid_index == UIDBCC3); + (uid_len == 7 && uid_index == UIDBCC2) || + (uid_len == 10 && uid_index == UIDBCC3); EmSendPrecompiledCmd(&responses[cl_finished ? SAK : SAKuid]); if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]); if (cl_finished) { @@ -625,7 +625,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { } // Incoming anti-collision frame - if (receivedCmd_len >= 2 && receivedCmd_len <= 6 && receivedCmd[1] == 0x50) { + // receivedCmd[1] indicates number of byte and bit collision, supports only for bit collision is zero + if (receivedCmd_len >= 3 && receivedCmd_len <= 6 && (receivedCmd[1] & 0x0f) == 0) { // we can process only full-byte frame anti-collision procedure if (memcmp(&receivedCmd[2], responses[uid_index].response, receivedCmd_len - 2) == 0) { // response missing part of UID via relative array index @@ -1036,8 +1037,9 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { ); } cardAUTHKEY = AUTHKEYNONE; // not authenticated - EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); cardSTATE_TO_IDLE(); + // Really tags not respond NACK on invalid authentication + LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); break; } diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index b2811cc6d..4e92bc95b 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -122,8 +122,10 @@ void UsbPacketReceived(uint8_t *packet, int len) { switch (c->cmd) { case CMD_DEVICE_INFO: { dont_ack = 1; - arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM | - DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH; + arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | + DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM | + DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH | + DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO; if (common_area.flags.osimage_present) arg0 |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT; @@ -131,6 +133,13 @@ void UsbPacketReceived(uint8_t *packet, int len) { } break; + case CMD_CHIP_INFO: { + dont_ack = 1; + arg0 = *(AT91C_DBGU_CIDR); + reply_old(CMD_CHIP_INFO, arg0, 0, 0, 0, 0); + } + break; + case CMD_SETUP_WRITE: { /* The temporary write buffer of the embedded flash controller is mapped to the * whole memory region, only the last 8 bits are decoded. diff --git a/client/Makefile b/client/Makefile index c3300b0cd..a1109a497 100644 --- a/client/Makefile +++ b/client/Makefile @@ -31,7 +31,19 @@ platform = $(shell uname) VPATH = ../common ../zlib ../uart OBJDIR = obj -LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread -lm +LDLIBS = +ifneq ($(platform),Darwin) + LDLIBS += -L/opt/local/lib +endif +LDLIBS += -L/usr/local/lib -lreadline -lpthread -lm + +# RPi Zero gcc requires -latomic +# but MacOSX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld +# doesn't recognize option --as-needed +ifneq ($(platform),Darwin) + LDLIBS += -Wl,--as-needed -latomic -Wl,--no-as-needed +endif + LUALIB = ../liblua/liblua.a JANSSONLIBPATH = ./jansson JANSSONLIB = $(JANSSONLIBPATH)/libjansson.a diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 1eee47c78..0821cc4d1 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -623,8 +623,7 @@ static int CmdAnalyseA(const char *Cmd) { for (uint8_t k=0; k<4; k = (k+1) % 4 ) { PrintAndLogEx(NORMAL, "\e[s%c\e[u", star[k]); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); (void)gc; + if (kbd_enter_pressed()) { break; } } diff --git a/client/cmdcrc.c b/client/cmdcrc.c index 58cab45e5..af4baae45 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -248,7 +248,7 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res //set model c = mbynam(&model, inModel); if (!c) { - PrintAndLogEx(WARNING, "error: preset model '%s' not found. Use reveng -D to list presets. [%d]", inModel, c); + PrintAndLogEx(ERR, "error: preset model '%s' not found. Use reveng -D to list presets. [%d]", inModel, c); return 0; } if (c < 0) { diff --git a/client/cmddata.c b/client/cmddata.c index d6a4e8e73..ba6790c93 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -602,7 +602,7 @@ static int Cmdmandecoderaw(const char *Cmd) { } if (high > 7 || low < 0) { - PrintAndLogEx(WARNING, "Error: please raw demod the wave first then manchester raw decode"); + PrintAndLogEx(ERR, "Error: please raw demod the wave first then manchester raw decode"); return PM3_ESOFT; } @@ -611,7 +611,7 @@ static int Cmdmandecoderaw(const char *Cmd) { uint8_t alignPos = 0; errCnt = manrawdecode(bits, &size, invert, &alignPos); if (errCnt >= maxErr) { - PrintAndLogEx(WARNING, "Too many errors: %u", errCnt); + PrintAndLogEx(ERR, "Too many errors: %u", errCnt); return PM3_ESOFT; } @@ -658,11 +658,11 @@ static int CmdBiphaseDecodeRaw(const char *Cmd) { errCnt = BiphaseRawDecode(bits, &size, &offset, invert); if (errCnt < 0) { - PrintAndLogEx(WARNING, "Error during decode:%d", errCnt); + PrintAndLogEx(ERR, "Error during decode:%d", errCnt); return PM3_ESOFT; } if (errCnt > maxErr) { - PrintAndLogEx(WARNING, "Too many errors attempting to decode: %d", errCnt); + PrintAndLogEx(ERR, "Too many errors attempting to decode: %d", errCnt); return PM3_ESOFT; } @@ -1290,7 +1290,7 @@ int CmdPSK1rawDemod(const char *Cmd) { int ans = PSKDemod(Cmd, true); //output if (ans != PM3_SUCCESS) { - if (g_debugMode) PrintAndLogEx(WARNING, "Error demoding: %d", ans); + if (g_debugMode) PrintAndLogEx(ERR, "Error demoding: %d", ans); return PM3_ESOFT; } PrintAndLogEx(NORMAL, "PSK1 demoded bitstream:"); @@ -1307,7 +1307,7 @@ static int CmdPSK2rawDemod(const char *Cmd) { int ans = PSKDemod(Cmd, true); if (ans != PM3_SUCCESS) { - if (g_debugMode) PrintAndLogEx(WARNING, "Error demoding: %d", ans); + if (g_debugMode) PrintAndLogEx(ERR, "Error demoding: %d", ans); return PM3_ESOFT; } psk1TOpsk2(DemodBuffer, DemodBufferLen); diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index dafda3ae6..9546b421f 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -37,17 +37,6 @@ static int usage_flashmem_spibaud(void) { return PM3_SUCCESS; } -static int usage_flashmem_read(void) { - PrintAndLogEx(NORMAL, "Read flash memory on device"); - PrintAndLogEx(NORMAL, "Usage: mem read o l "); - PrintAndLogEx(NORMAL, " o : offset in memory"); - PrintAndLogEx(NORMAL, " l : length"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " mem read o 0 l 32"); // read 32 bytes starting at offset 0 - PrintAndLogEx(NORMAL, " mem read o 1024 l 10"); // read 10 bytes starting at offset 1024 - return PM3_SUCCESS; -} static int usage_flashmem_load(void) { PrintAndLogEx(NORMAL, "Loads binary file into flash memory on device"); PrintAndLogEx(NORMAL, "Usage: mem load [o ] f [m|t|i]"); @@ -67,17 +56,19 @@ static int usage_flashmem_load(void) { PrintAndLogEx(NORMAL, " mem load f default_iclass_keys i"); return PM3_SUCCESS; } -static int usage_flashmem_save(void) { - PrintAndLogEx(NORMAL, "Saves flash memory on device into the file"); - PrintAndLogEx(NORMAL, " Usage: mem save [o ] [l ] f "); +static int usage_flashmem_dump(void) { + PrintAndLogEx(NORMAL, "Dumps flash memory on device into a file or in console"); + PrintAndLogEx(NORMAL, " Usage: mem dump [o ] [l ] [f ] [p]"); PrintAndLogEx(NORMAL, " o : offset in memory"); PrintAndLogEx(NORMAL, " l : length"); PrintAndLogEx(NORMAL, " f : file name"); + PrintAndLogEx(NORMAL, " p : print dump in console"); + PrintAndLogEx(NORMAL, " You must specify at lease option f or option p, both if you wish"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " mem save f myfile"); // download whole flashmem to file myfile - PrintAndLogEx(NORMAL, " mem save f myfile l 4096"); // download 4096 bytes from default offset 0 to file myfile - PrintAndLogEx(NORMAL, " mem save f myfile o 1024 l 4096"); // downlowd 4096 bytes from offset 1024 to file myfile + PrintAndLogEx(NORMAL, " mem dump f myfile"); // download whole flashmem to file myfile + PrintAndLogEx(NORMAL, " mem dump p o 262015 l 128"); // display 128 bytes from offset 262015 (RSA sig) + PrintAndLogEx(NORMAL, " mem dump p f myfile o 241664 l 58"); // download and display 58 bytes from offset 241664 to file myfile return PM3_SUCCESS; } static int usage_flashmem_wipe(void) { @@ -105,46 +96,6 @@ static int usage_flashmem_info(void) { return PM3_SUCCESS; } -static int CmdFlashMemRead(const char *Cmd) { - - uint8_t cmdp = 0; - bool errors = false; - uint32_t start_index = 0, len = 0; - - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'o': - start_index = param_get32ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - case 'l': - len = param_get32ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - case 'h': - return usage_flashmem_read(); - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - - //Validations - if (errors || cmdp == 0) { - usage_flashmem_read(); - return PM3_EINVARG; - } - if (start_index + len > FLASH_MEM_MAX_SIZE) { - PrintAndLogDevice(WARNING, "error, start_index + length is larger than available memory"); - return PM3_EOVFLOW; - } - - clearCommandBuffer(); - SendCommandMIX(CMD_FLASHMEM_READ, start_index, len, 0, NULL, 0); - return PM3_SUCCESS; -} - static int CmdFlashmemSpiBaudrate(const char *Cmd) { char ctmp = tolower(param_getchar(Cmd, 0)); @@ -258,7 +209,7 @@ static int CmdFlashMemLoad(const char *Cmd) { } if (datalen > FLASH_MEM_MAX_SIZE) { - PrintAndLogDevice(WARNING, "error, filesize is larger than available memory"); + PrintAndLogDevice(ERR, "error, filesize is larger than available memory"); free(data); return PM3_EOVFLOW; } @@ -311,17 +262,18 @@ static int CmdFlashMemLoad(const char *Cmd) { PrintAndLogEx(SUCCESS, "Wrote "_GREEN_("%u")"bytes to offset "_GREEN_("%u"), datalen, start_index); return PM3_SUCCESS; } -static int CmdFlashMemSave(const char *Cmd) { +static int CmdFlashMemDump(const char *Cmd) { char filename[FILE_PATH_SIZE] = {0}; uint8_t cmdp = 0; bool errors = false; + bool print = false; uint32_t start_index = 0, len = FLASH_MEM_MAX_SIZE; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': - return usage_flashmem_save(); + return usage_flashmem_dump(); case 'l': len = param_get32ex(Cmd, cmdp + 1, FLASH_MEM_MAX_SIZE, 10); cmdp += 2; @@ -330,6 +282,10 @@ static int CmdFlashMemSave(const char *Cmd) { start_index = param_get32ex(Cmd, cmdp + 1, 0, 10); cmdp += 2; break; + case 'p': + print = true; + cmdp += 1; + break; case 'f': //File handling if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { @@ -348,13 +304,13 @@ static int CmdFlashMemSave(const char *Cmd) { //Validations if (errors || cmdp == 0) { - usage_flashmem_save(); + usage_flashmem_dump(); return PM3_EINVARG; } uint8_t *dump = calloc(len, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(WARNING, "error, cannot allocate memory "); + PrintAndLogDevice(ERR, "error, cannot allocate memory "); return PM3_EMALLOC; } @@ -365,8 +321,15 @@ static int CmdFlashMemSave(const char *Cmd) { return PM3_EFLASH; } - saveFile(filename, ".bin", dump, len); - saveFileEML(filename, dump, len, 16); + if (print) { + print_hex_break(dump, len, 32); + } + + if (filename[0] != '\0') { + saveFile(filename, ".bin", dump, len); + saveFileEML(filename, dump, len, 16); + } + free(dump); return PM3_SUCCESS; } @@ -612,10 +575,9 @@ static int CmdFlashMemInfo(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"spibaud", CmdFlashmemSpiBaudrate, IfPm3Flash, "Set Flash memory Spi baudrate [rdv40]"}, - {"read", CmdFlashMemRead, IfPm3Flash, "Read Flash memory [rdv40]"}, {"info", CmdFlashMemInfo, IfPm3Flash, "Flash memory information [rdv40]"}, {"load", CmdFlashMemLoad, IfPm3Flash, "Load data into flash memory [rdv40]"}, - {"save", CmdFlashMemSave, IfPm3Flash, "Save data from flash memory [rdv40]"}, + {"dump", CmdFlashMemDump, IfPm3Flash, "Dump data from flash memory [rdv40]"}, {"wipe", CmdFlashMemWipe, IfPm3Flash, "Wipe data from flash memory [rdv40]"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/cmdflashmem.h b/client/cmdflashmem.h index 3c37239b7..790d42a5d 100644 --- a/client/cmdflashmem.h +++ b/client/cmdflashmem.h @@ -15,10 +15,11 @@ #include #include #include +#include "pmflash.h" +#include "common.h" #include "proxmark3.h" #include "ui.h" #include "cmdparser.h" -#include "common.h" #include "util.h" #include "util_posix.h" // msclock #include "loclass/fileutils.h" //saveFile diff --git a/client/cmdhf.c b/client/cmdhf.c index 7e42202a9..03a5c1681 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -40,7 +40,7 @@ static int usage_hf_sniff() { static int usage_hf_tune() { PrintAndLogEx(NORMAL, "Usage: hf tune []"); PrintAndLogEx(NORMAL, "Continuously measure HF antenna tuning."); - PrintAndLogEx(NORMAL, "Press button or keyboard to interrupt."); + PrintAndLogEx(NORMAL, "Press button or Enter to interrupt."); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " - number of iterations (default: infinite)"); PrintAndLogEx(NORMAL, ""); @@ -98,7 +98,7 @@ int CmdHFTune(const char *Cmd) { int iter = param_get32ex(Cmd, 0, 0, 10); PacketResponseNG resp; - PrintAndLogEx(SUCCESS, "Measuring HF antenna, click button or press a key to exit"); + PrintAndLogEx(SUCCESS, "Measuring HF antenna, click button or press Enter to exit"); clearCommandBuffer(); uint8_t mode[] = {1}; SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode)); @@ -109,9 +109,7 @@ int CmdHFTune(const char *Cmd) { mode[0] = 2; // loop forever (till button pressed) if iter = 0 (default) for (uint8_t i = 0; iter == 0 || i < iter; i++) { - if (ukbhit()) { // abort by keyboard press - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { // abort by keyboard press break; } SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode)); diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 018431a28..f92a35370 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -375,9 +375,7 @@ static int CmdHF14ACUIDs(const char *Cmd) { // repeat n times for (int i = 0; i < n; i++) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n"); break; } @@ -489,7 +487,7 @@ int CmdHF14ASim(const char *Cmd) { PrintAndLogEx(SUCCESS, "press pm3-button to abort simulation"); - while (!ukbhit()) { + while (!kbd_enter_pressed()) { if (WaitForResponseTimeout(CMD_SIMULATE_MIFARE_CARD, &resp, 1500) == 0) continue; if (resp.status != PM3_SUCCESS) break; @@ -800,7 +798,7 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea vActivateField = false; if (*dataoutlen) { if (clen != datainlen) - PrintAndLogEx(WARNING, "APDU: I-block/R-block sequence error. Data len=%d, Sent=%d, Last packet len=%d", datainlen, clen, *dataoutlen); + PrintAndLogEx(ERR, "APDU: I-block/R-block sequence error. Data len=%d, Sent=%d, Last packet len=%d", datainlen, clen, *dataoutlen); break; } } while (clen < datainlen); @@ -836,20 +834,33 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea static int CmdHF14AAPDU(const char *Cmd) { uint8_t data[PM3_CMD_DATA_SIZE]; int datalen = 0; + uint8_t header[PM3_CMD_DATA_SIZE]; + int headerlen = 0; bool activateField = false; bool leaveSignalON = false; bool decodeTLV = false; + bool decodeAPDU = false; + bool makeAPDU = false; + bool extendedAPDU = false; + int le = 0; CLIParserInit("hf 14a apdu", - "Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL)", - "Sample:\n\thf 14a apdu -st 00A404000E325041592E5359532E444446303100\n"); + "Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL). works with all apdu types from ISO 7816-4:2013", + "Sample:\n\thf 14a apdu -st 00A404000E325041592E5359532E444446303100\n" + "\thf 14a apdu -sd 00A404000E325041592E5359532E444446303100 - decode apdu\n" + "\thf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -l 256 - encode standard apdu\n" + "\thf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -el 65536 - encode extended apdu\n"); void *argtable[] = { arg_param_begin, - arg_lit0("sS", "select", "activate field and select card"), - arg_lit0("kK", "keep", "leave the signal field ON after receive response"), - arg_lit0("tT", "tlv", "executes TLV decoder if it possible"), - arg_strx1(NULL, NULL, "", NULL), + arg_lit0("sS", "select", "activate field and select card"), + arg_lit0("kK", "keep", "leave the signal field ON after receive response"), + arg_lit0("tT", "tlv", "executes TLV decoder if it possible"), + arg_lit0("dD", "decapdu", "decode apdu request if it possible"), + arg_str0("mM", "make", "", "make apdu with head from this field and data from data field. Must be 4 bytes length: "), + arg_lit0("eE", "extended", "make extended length apdu if `m` parameter included"), + arg_int0("lL", "le", "", "Le apdu parameter if `m` parameter included"), + arg_strx1(NULL, NULL, "", "data if `m` parameter included"), arg_param_end }; CLIExecWithReturn(Cmd, argtable, false); @@ -857,12 +868,66 @@ static int CmdHF14AAPDU(const char *Cmd) { activateField = arg_get_lit(1); leaveSignalON = arg_get_lit(2); decodeTLV = arg_get_lit(3); - // len = data + PCB(1b) + CRC(2b) - CLIGetHexBLessWithReturn(4, data, &datalen, 1 + 2); + decodeAPDU = arg_get_lit(4); + + CLIGetHexWithReturn(5, header, &headerlen); + makeAPDU = headerlen > 0; + if (makeAPDU && headerlen != 4) { + PrintAndLogEx(ERR, "header length must be 4 bytes instead of %d", headerlen); + return 1; + } + extendedAPDU = arg_get_lit(6); + le = arg_get_int_def(7, 0); + + if (makeAPDU) { + uint8_t apdudata[PM3_CMD_DATA_SIZE] = {0}; + int apdudatalen = 0; + + CLIGetHexBLessWithReturn(8, apdudata, &apdudatalen, 1 + 2); + + APDUStruct apdu; + apdu.cla = header[0]; + apdu.ins = header[1]; + apdu.p1 = header[2]; + apdu.p2 = header[3]; + + apdu.lc = apdudatalen; + apdu.data = apdudata; + + apdu.extended_apdu = extendedAPDU; + apdu.le = le; + + if (APDUEncode(&apdu, data, &datalen)) { + PrintAndLogEx(ERR, "can't make apdu with provided parameters."); + return 2; + } + + } else { + if (extendedAPDU) { + PrintAndLogEx(ERR, "make mode not set but here `e` option."); + return 3; + } + if (le > 0) { + PrintAndLogEx(ERR, "make mode not set but here `l` option."); + return 3; + } + + // len = data + PCB(1b) + CRC(2b) + CLIGetHexBLessWithReturn(8, data, &datalen, 1 + 2); + } CLIParserFree(); PrintAndLogEx(NORMAL, ">>>>[%s%s%s] %s", activateField ? "sel " : "", leaveSignalON ? "keep " : "", decodeTLV ? "TLV" : "", sprint_hex(data, datalen)); + if (decodeAPDU) { + APDUStruct apdu; + + if (APDUDecode(data, datalen, &apdu) == 0) + APDUPrint(apdu); + else + PrintAndLogEx(WARNING, "can't decode APDU."); + } + int res = ExchangeAPDU14a(data, datalen, activateField, leaveSignalON, data, PM3_CMD_DATA_SIZE, &datalen); if (res) diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 6f6d1ebc2..33c3957fe 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -407,6 +407,17 @@ static int usage_15_readmulti(void) { "\tcount#: number of pages"); return 0; } +static int usage_15_csetuid(void) { + PrintAndLogEx(NORMAL, "Set UID for magic Chinese card (only works with such cards)\n" + "\n" + "Usage: hf 15 csetuid \n" + "Options:\n" + "\tuid : <8B hex> full UID eg E011223344556677\n" + "\n" + "Example:\n" + "\thf 15 csetuid E011223344556677"); + return 0; +} /** * parses common HF 15 CMD parameters and prepares some data structures @@ -553,7 +564,7 @@ static int CmdHF15Demod(const char *Cmd) { } if (mask != 0x01) { - PrintAndLogEx(WARNING, "Error, uneven octet! (discard extra bits!)"); + PrintAndLogEx(WARNING, "Warning, uneven octet! (discard extra bits!)"); PrintAndLogEx(NORMAL, " mask = %02x", mask); } PrintAndLogEx(NORMAL, "%d octets", k); @@ -623,7 +634,7 @@ static int CmdHF15Info(const char *Cmd) { recv = resp.data.asBytes; if (recv[0] & ISO15_RES_ERROR) { - PrintAndLogEx(WARNING, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); + PrintAndLogEx(ERR, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); return 3; } @@ -1058,7 +1069,7 @@ static int CmdHF15Read(const char *Cmd) { } if (recv[0] & ISO15_RES_ERROR) { - PrintAndLogEx(WARNING, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); + PrintAndLogEx(ERR, "iso15693 card returned error %i: %s", recv[0], TagErrorStr(recv[0])); return 3; } @@ -1235,7 +1246,7 @@ static int CmdHF15Restore(const char *Cmd) { fclose(f); return 0; } else if (bytes_read != blocksize) { - PrintAndLogEx(WARNING, "File reading error (%s), %u bytes read instead of %u bytes.", filename, bytes_read, blocksize); + PrintAndLogEx(ERR, "File reading error (%s), %u bytes read instead of %u bytes.", filename, bytes_read, blocksize); fclose(f); return 2; } @@ -1269,6 +1280,103 @@ static int CmdHF15Restore(const char *Cmd) { return 0; } +/** + * Commandline handling: HF15 CMD CSETUID + * Set UID for magic Chinese card + */ +static int CmdHF15CSetUID(const char *Cmd) { + uint8_t uid[8] = {0x00}; + uint8_t oldUid[8], newUid[8] = {0x00}; + PacketResponseNG resp; + int reply = 1, fast = 0; + uint8_t data[4][9] = {{0x00}}; + + char cmdp = tolower(param_getchar(Cmd, 0)); + if (strlen(Cmd) < 1 || cmdp == 'h') return usage_15_csetuid(); + + if (param_gethex(Cmd, 0, uid, 16)) { + PrintAndLogEx(WARNING, "UID must include 16 HEX symbols"); + return 1; + } + + if (uid[0] != 0xe0) { + PrintAndLogEx(WARNING, "UID must begin with the byte " _YELLOW_("E0")); + return 1; + } + + PrintAndLogEx(SUCCESS, "new UID | %s", sprint_hex(uid, sizeof(uid))); + PrintAndLogEx(NORMAL, "Using backdoor Magic tag function"); + + if (!getUID(oldUid)) { + PrintAndLogEx(FAILED, "Can't get old UID."); + return PM3_ESOFT; + } + + // Command 1 : 02213E00000000 + data[0][0] = 0x02; + data[0][1] = 0x21; + data[0][2] = 0x3e; + data[0][3] = 0x00; + data[0][4] = 0x00; + data[0][5] = 0x00; + data[0][6] = 0x00; + + // Command 2 : 02213F69960000 + data[1][0] = 0x02; + data[1][1] = 0x21; + data[1][2] = 0x3f; + data[1][3] = 0x69; + data[1][4] = 0x96; + data[1][5] = 0x00; + data[1][6] = 0x00; + + // Command 3 : 022138u8u7u6u5 (where uX = uid byte X) + data[2][0] = 0x02; + data[2][1] = 0x21; + data[2][2] = 0x38; + data[2][3] = uid[7]; + data[2][4] = uid[6]; + data[2][5] = uid[5]; + data[2][6] = uid[4]; + + // Command 4 : 022139u4u3u2u1 (where uX = uid byte X) + data[3][0] = 0x02; + data[3][1] = 0x21; + data[3][2] = 0x39; + data[3][3] = uid[3]; + data[3][4] = uid[2]; + data[3][5] = uid[1]; + data[3][6] = uid[0]; + + for (int i = 0; i < 4; i++) { + AddCrc15(data[i], 7); + + clearCommandBuffer(); + SendCommandOLD(CMD_ISO_15693_COMMAND, sizeof(data[i]), fast, reply, data[i], sizeof(data[i])); + + if (reply) { + if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + uint8_t len = resp.oldarg[0]; + PrintAndLogEx(NORMAL, "received %i octets", len); + PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.data.asBytes, len)); + } else { + PrintAndLogEx(WARNING, "timeout while waiting for reply."); + } + } + } + + if (!getUID(newUid)) { + PrintAndLogEx(FAILED, "Can't get new UID."); + return PM3_ESOFT; + } + + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "old UID : %02X %02X %02X %02X %02X %02X %02X %02X", oldUid[7], oldUid[6], oldUid[5], oldUid[4], oldUid[3], oldUid[2], oldUid[1], oldUid[0]); + PrintAndLogEx(SUCCESS, "new UID : %02X %02X %02X %02X %02X %02X %02X %02X", newUid[7], newUid[6], newUid[5], newUid[4], newUid[3], newUid[2], newUid[1], newUid[0]); + + return PM3_SUCCESS; +} + static command_t CommandTable[] = { {"help", CmdHF15Help, AlwaysAvailable, "This help"}, {"demod", CmdHF15Demod, AlwaysAvailable, "Demodulate ISO15693 from tag"}, @@ -1285,6 +1393,7 @@ static command_t CommandTable[] = { {"read", CmdHF15Read, IfPm3Iso15693, "Read a block"}, {"write", CmdHF15Write, IfPm3Iso15693, "Write a block"}, {"readmulti", CmdHF15Readmulti, IfPm3Iso15693, "Reads multiple Blocks"}, + {"csetuid", CmdHF15CSetUID, IfPm3Iso15693, "Set UID for magic Chinese card"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/cmdhffelica.c b/client/cmdhffelica.c index 6f3e28737..91d171149 100644 --- a/client/cmdhffelica.c +++ b/client/cmdhffelica.c @@ -135,7 +135,7 @@ static int CmdHFFelicaSim(const char *Cmd) { if (verbose) PrintAndLogEx(NORMAL, "Press pm3-button to abort simulation"); - while (!ukbhit()) { + while (!kbd_enter_pressed()) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue; } return 0; @@ -357,9 +357,7 @@ static int CmdHFFelicaDumpLite(const char *Cmd) { timeout++; printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n"); DropField(); return 1; diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 2bdb91fa1..f8d57556f 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -176,7 +176,7 @@ static int usage_hf_iclass_managekeys(void) { return 0; } static int usage_hf_iclass_reader(void) { - PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until a key or the pm3 button is pressed\n"); + PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until Enter or the pm3 button is pressed\n"); PrintAndLogEx(NORMAL, "Usage: hf iclass reader [h] [1]\n"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h This help text"); @@ -376,16 +376,14 @@ static int CmdHFiClassSim(const char *Cmd) { case 2: { PrintAndLogEx(INFO, "Starting iCLASS sim 2 attack (elite mode)"); - PrintAndLogEx(INFO, "press keyboard to cancel"); + PrintAndLogEx(INFO, "press Enter to cancel"); PacketResponseNG resp; clearCommandBuffer(); SendCommandOLD(CMD_SIMULATE_TAG_ICLASS, simType, NUM_CSNS, 0, csns, 8 * NUM_CSNS); while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { tries++; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard."); return 0; } @@ -427,16 +425,14 @@ static int CmdHFiClassSim(const char *Cmd) { case 4: { // reader in key roll mode, when it has two keys it alternates when trying to verify. PrintAndLogEx(INFO, "Starting iCLASS sim 4 attack (elite mode, reader in key roll mode)"); - PrintAndLogEx(INFO, "press keyboard to cancel"); + PrintAndLogEx(INFO, "press Enter to cancel"); PacketResponseNG resp; clearCommandBuffer(); SendCommandOLD(CMD_SIMULATE_TAG_ICLASS, simType, NUM_CSNS, 0, csns, 8 * NUM_CSNS); while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { tries++; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard."); return 0; } @@ -554,14 +550,14 @@ static int CmdHFiClassELoad(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogDevice(WARNING, "error, when getting filesize"); + PrintAndLogDevice(ERR, "error, when getting filesize"); fclose(f); return 1; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { - PrintAndLogDevice(WARNING, "error, cannot allocate memory "); + PrintAndLogDevice(ERR, "error, cannot allocate memory "); fclose(f); return 1; } @@ -573,7 +569,7 @@ static int CmdHFiClassELoad(const char *Cmd) { //Validate if (bytes_read < fsize) { - PrintAndLogDevice(WARNING, "error, could only read %d bytes (should be %d)", bytes_read, fsize); + PrintAndLogDevice(ERR, "error, could only read %d bytes (should be %d)", bytes_read, fsize); free(dump); return 1; } @@ -654,7 +650,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "error, when getting filesize"); + PrintAndLogEx(ERR, "error, when getting filesize"); fclose(f); return 2; } @@ -669,7 +665,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { size_t bytes_read = fread(decrypted, 1, fsize, f); fclose(f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "file reading error"); + PrintAndLogEx(ERR, "file reading error"); free(decrypted); return 3; } @@ -969,9 +965,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n"); DropField(); return 0; @@ -1287,7 +1281,7 @@ static int CmdHFiClassCloneTag(const char *Cmd) { fseek(f, startblock * 8, SEEK_SET); size_t bytes_read = fread(tag_data, sizeof(iclass_block_t), endblock - startblock + 1, f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "file reading error."); + PrintAndLogEx(ERR, "file reading error."); fclose(f); return 2; } @@ -1454,7 +1448,7 @@ static int CmdHFiClass_loclass(const char *Cmd) { errors += testMAC(); errors += doKeyTests(0); errors += testElite(); - if (errors) PrintAndLogDevice(WARNING, "There were errors!!!"); + if (errors) PrintAndLogDevice(ERR, "There were errors!!!"); return errors; } return PM3_SUCCESS; @@ -1524,7 +1518,7 @@ static int CmdHFiClassReadTagFile(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "Error, when getting filesize"); + PrintAndLogEx(ERR, "Error, when getting filesize"); fclose(f); return 1; } @@ -1682,7 +1676,7 @@ static int loadKeys(char *filename) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "Error, when getting filesize"); + PrintAndLogEx(ERR, "Error, when getting filesize"); fclose(f); return 1; } @@ -1945,9 +1939,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { uint64_t t2 = msclock(); uint8_t timeout = 0; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\n[!] Aborted via keyboard!\n"); goto out; } @@ -2446,7 +2438,7 @@ int readIclass(bool loop, bool verbose) { // loop in client not device - else on windows have a communication error PacketResponseNG resp; - while (!ukbhit()) { + while (!kbd_enter_pressed()) { clearCommandBuffer(); SendCommandMIX(CMD_READER_ICLASS, flags, 0, 0, NULL, 0); diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index 8bd976030..03c5ecfcd 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -1037,7 +1037,7 @@ static int CmdLegicRestore(const char *Cmd) { fclose(f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "File reading error"); + PrintAndLogEx(ERR, "File reading error"); free(data); return 2; } @@ -1139,7 +1139,7 @@ static int CmdLegicELoad(const char *Cmd) { // load file size_t bytes_read = fread(data, 1, numofbytes, f); if (bytes_read == 0) { - PrintAndLogEx(WARNING, "File reading error"); + PrintAndLogEx(ERR, "File reading error"); free(data); fclose(f); f = NULL; diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 4fa3d8dc0..a62924787 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -765,7 +765,7 @@ static int CmdHF14AMfDump(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyA[sectorNo], 1, 6, f); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error."); + PrintAndLogEx(ERR, "File reading error."); fclose(f); return PM3_EFILE; } @@ -775,7 +775,7 @@ static int CmdHF14AMfDump(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyB[sectorNo], 1, 6, f); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error."); + PrintAndLogEx(ERR, "File reading error."); fclose(f); return PM3_EFILE; } @@ -984,7 +984,7 @@ static int CmdHF14AMfRestore(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyA[sectorNo], 1, 6, fkeys); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error " _YELLOW_("%s"), keyFilename); + PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), keyFilename); fclose(fkeys); return 2; } @@ -993,7 +993,7 @@ static int CmdHF14AMfRestore(const char *Cmd) { for (sectorNo = 0; sectorNo < numSectors; sectorNo++) { bytes_read = fread(keyB[sectorNo], 1, 6, fkeys); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error " _YELLOW_("%s"), keyFilename); + PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), keyFilename); fclose(fkeys); return 2; } @@ -1021,7 +1021,7 @@ static int CmdHF14AMfRestore(const char *Cmd) { memcpy(data, key, 6); bytes_read = fread(bldata, 1, 16, fdump); if (bytes_read != 16) { - PrintAndLogEx(WARNING, "File reading error " _YELLOW_("%s"), dataFilename); + PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), dataFilename); fclose(fdump); fdump = NULL; return 2; @@ -1129,7 +1129,7 @@ static int CmdHF14AMfNested(const char *Cmd) { int16_t isOK = mfnested(blockNo, keyType, key, trgBlockNo, trgKeyType, keyBlock, true); switch (isOK) { case -1 : - PrintAndLogEx(WARNING, "Error: No response from Proxmark3.\n"); + PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); break; case -2 : PrintAndLogEx(WARNING, "Button pressed. Aborted.\n"); @@ -1162,7 +1162,7 @@ static int CmdHF14AMfNested(const char *Cmd) { } return PM3_SUCCESS; default : - PrintAndLogEx(WARNING, "Unknown Error.\n"); + PrintAndLogEx(ERR, "Unknown Error.\n"); } return PM3_SUCCESS; } else { // ------------------------------------ multiple sectors working @@ -1199,7 +1199,7 @@ static int CmdHF14AMfNested(const char *Cmd) { int16_t isOK = mfnested(blockNo, keyType, key, FirstBlockOfSector(sectorNo), trgKeyType, keyBlock, calibrate); switch (isOK) { case -1 : - PrintAndLogEx(WARNING, "error: No response from Proxmark3.\n"); + PrintAndLogEx(ERR, "error: No response from Proxmark3.\n"); break; case -2 : PrintAndLogEx(WARNING, "button pressed. Aborted.\n"); @@ -1221,7 +1221,7 @@ static int CmdHF14AMfNested(const char *Cmd) { continue; default : - PrintAndLogEx(WARNING, "unknown Error.\n"); + PrintAndLogEx(ERR, "unknown Error.\n"); } free(e_sector); return PM3_ESOFT; @@ -1502,7 +1502,7 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { if (isOK) { switch (isOK) { case 1 : - PrintAndLogEx(WARNING, "Error: No response from Proxmark3.\n"); + PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); break; case 2 : PrintAndLogEx(NORMAL, "Button pressed. Aborted.\n"); @@ -1692,9 +1692,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { // main keychunk loop for (i = 0; i < keycnt; i += chunksize) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); goto out; } @@ -1961,6 +1959,8 @@ static int CmdHF14AMfChk(const char *Cmd) { // fast push mode conn.block_after_ACK = true; + // clear trace log by first check keys call only + bool clearLog = true; // check keys. for (trgKeyType = (keyType == 2) ? 0 : keyType; trgKeyType < 2; (keyType == 2) ? (++trgKeyType) : (trgKeyType = 2)) { @@ -1974,20 +1974,20 @@ static int CmdHF14AMfChk(const char *Cmd) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "\naborted via keyboard!\n"); goto out; } uint16_t size = keycnt - c > max_keys ? max_keys : keycnt - c; - if (mfCheckKeys(b, trgKeyType, true, size, &keyBlock[6 * c], &key64) == PM3_SUCCESS) { + if (mfCheckKeys(b, trgKeyType, clearLog, size, &keyBlock[6 * c], &key64) == PM3_SUCCESS) { e_sector[i].Key[trgKeyType] = key64; e_sector[i].foundKey[trgKeyType] = true; + clearLog = false; break; } + clearLog = false; } b < 127 ? (b += 4) : (b += 16); } @@ -2281,7 +2281,7 @@ static int CmdHF14AMfSim(const char *Cmd) { if (flags & FLAG_INTERACTIVE) { PrintAndLogEx(INFO, "Press pm3-button or send another cmd to abort simulation"); - while (!ukbhit()) { + while (!kbd_enter_pressed()) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue; if (!(flags & FLAG_NR_AR_ATTACK)) break; if ((resp.oldarg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD) break; @@ -2328,8 +2328,8 @@ static int CmdHF14AMfSniff(const char *Cmd) { PrintAndLogEx(NORMAL, "-------------------------------------------------------------------------\n"); PrintAndLogEx(NORMAL, "Executing mifare sniffing command. \n"); - PrintAndLogEx(NORMAL, "Press the key on the Proxmark3 device to abort both Proxmark3 and client.\n"); - PrintAndLogEx(NORMAL, "Press the key on pc keyboard to abort the client.\n"); + PrintAndLogEx(NORMAL, "Press the button on the Proxmark3 device to abort both Proxmark3 and client.\n"); + PrintAndLogEx(NORMAL, "Press Enter to abort the client.\n"); PrintAndLogEx(NORMAL, "-------------------------------------------------------------------------\n"); clearCommandBuffer(); @@ -2341,9 +2341,7 @@ static int CmdHF14AMfSniff(const char *Cmd) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "\naborted via keyboard!\n"); break; } @@ -2830,7 +2828,7 @@ static int CmdHF14AMfCSetUID(const char *Cmd) { res = mfCSetUID(uid, (atqaPresent) ? atqa : NULL, (atqaPresent) ? sak : NULL, oldUid, wipeCard); if (res) { - PrintAndLogEx(WARNING, "Can't set UID. error=%d", res); + PrintAndLogEx(ERR, "Can't set UID. error=%d", res); return PM3_ESOFT; } @@ -2860,7 +2858,7 @@ static int CmdHF14AMfCSetBlk(const char *Cmd) { res = mfCSetBlock(blockNo, block, NULL, params); if (res) { - PrintAndLogEx(WARNING, "Can't write block. error=%d", res); + PrintAndLogEx(ERR, "Can't write block. error=%d", res); return PM3_ESOFT; } return PM3_SUCCESS; @@ -2935,7 +2933,7 @@ static int CmdHF14AMfCLoad(const char *Cmd) { // 64 or 256blocks. if (datalen != 1024 && datalen != 4096) { - PrintAndLogEx(WARNING, "File content error. "); + PrintAndLogEx(ERR, "File content error. "); free(data); return PM3_EFILE; } @@ -2974,7 +2972,7 @@ static int CmdHF14AMfCLoad(const char *Cmd) { // 64 or 256blocks. if (blockNum != 16 * 4 && blockNum != 32 * 4 + 8 * 16) { - PrintAndLogEx(WARNING, "File content error. There must be 64 blocks"); + PrintAndLogEx(ERR, "File content error. There must be 64 blocks"); free(data); return PM3_EFILE; } @@ -2996,7 +2994,7 @@ static int CmdHF14AMfCGetBlk(const char *Cmd) { int res = mfCGetBlock(blockNo, data, MAGIC_SINGLE); if (res) { - PrintAndLogEx(WARNING, "Can't read block. error=%d", res); + PrintAndLogEx(ERR, "Can't read block. error=%d", res); return PM3_ESOFT; } @@ -3047,7 +3045,7 @@ static int CmdHF14AMfCGetSc(const char *Cmd) { int res = mfCGetBlock(start + i, data, flags); if (res) { - PrintAndLogEx(WARNING, "Can't read block. %d error=%d", start + i, res); + PrintAndLogEx(ERR, "Can't read block. %d error=%d", start + i, res); return PM3_ESOFT; } PrintAndLogEx(NORMAL, "%3d | %s", start + i, sprint_hex(data, 16)); @@ -3242,7 +3240,7 @@ static int CmdHf14AMfNack(const char *Cmd) { bool verbose = (ctmp == 'v'); if (verbose) - PrintAndLogEx(INFO, "Started testing card for NACK bug. Press key to abort"); + PrintAndLogEx(INFO, "Started testing card for NACK bug. Press Enter to abort"); detect_classic_nackbug(verbose); return PM3_SUCCESS; @@ -3307,9 +3305,7 @@ static int CmdHF14AMfice(const char *Cmd) { uint64_t t1 = msclock(); do { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "\naborted via keyboard!\n"); break; } diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index 2b96d8d77..4de46d36a 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -258,7 +258,7 @@ static void init_bitflip_bitarrays(void) { fseek(statesfile, 0, SEEK_END); int fsize = ftell(statesfile); if (fsize == -1) { - PrintAndLogEx(WARNING, "File read error with %s. Aborting...\n", state_file_name); + PrintAndLogEx(ERR, "File read error with %s. Aborting...\n", state_file_name); fclose(statesfile); exit(5); } @@ -267,7 +267,7 @@ static void init_bitflip_bitarrays(void) { uint8_t input_buffer[filesize]; size_t bytesread = fread(input_buffer, 1, filesize, statesfile); if (bytesread != filesize) { - PrintAndLogEx(WARNING, "File read error with %s. Aborting...\n", state_file_name); + PrintAndLogEx(ERR, "File read error with %s. Aborting...\n", state_file_name); fclose(statesfile); //inflateEnd(&compressed_stream); exit(5); @@ -279,7 +279,7 @@ static void init_bitflip_bitarrays(void) { if ((float)count / (1 << 24) < IGNORE_BITFLIP_THRESHOLD) { uint32_t *bitset = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (bitset == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_bitflip_statelists(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_bitflip_statelists(). Aborting...\n"); inflateEnd(&compressed_stream); exit(4); } @@ -390,7 +390,7 @@ static void init_part_sum_bitarrays(void) { for (uint16_t part_sum_a0 = 0; part_sum_a0 < NUM_PART_SUMS; part_sum_a0++) { part_sum_a0_bitarrays[odd_even][part_sum_a0] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (part_sum_a0_bitarrays[odd_even][part_sum_a0] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_part_suma0_statelists(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_part_suma0_statelists(). Aborting...\n"); exit(4); } clear_bitarray24(part_sum_a0_bitarrays[odd_even][part_sum_a0]); @@ -410,7 +410,7 @@ static void init_part_sum_bitarrays(void) { for (uint16_t part_sum_a8 = 0; part_sum_a8 < NUM_PART_SUMS; part_sum_a8++) { part_sum_a8_bitarrays[odd_even][part_sum_a8] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (part_sum_a8_bitarrays[odd_even][part_sum_a8] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_part_suma8_statelists(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_part_suma8_statelists(). Aborting...\n"); exit(4); } clear_bitarray24(part_sum_a8_bitarrays[odd_even][part_sum_a8]); @@ -449,7 +449,7 @@ static void init_sum_bitarrays(void) { for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) { sum_a0_bitarrays[odd_even][sum_a0] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (sum_a0_bitarrays[odd_even][sum_a0] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_sum_bitarrays(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_sum_bitarrays(). Aborting...\n"); exit(4); } clear_bitarray24(sum_a0_bitarrays[odd_even][sum_a0]); @@ -564,14 +564,14 @@ static void init_nonce_memory(void) { } nonces[i].states_bitarray[EVEN_STATE] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (nonces[i].states_bitarray[EVEN_STATE] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_nonce_memory(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_nonce_memory(). Aborting...\n"); exit(4); } set_bitarray24(nonces[i].states_bitarray[EVEN_STATE]); nonces[i].num_states_bitarray[EVEN_STATE] = 1 << 24; nonces[i].states_bitarray[ODD_STATE] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19)); if (nonces[i].states_bitarray[ODD_STATE] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in init_nonce_memory(). Aborting...\n"); + PrintAndLogEx(ERR, "Out of memory error in init_nonce_memory(). Aborting...\n"); exit(4); } set_bitarray24(nonces[i].states_bitarray[ODD_STATE]); @@ -1048,7 +1048,7 @@ static int read_nonce_file(char *filename) { hardnested_print_progress(0, progress_text, (float)(1LL << 47), 0); size_t bytes_read = fread(read_buf, 1, 6, fnonces); if (bytes_read != 6) { - PrintAndLogEx(WARNING, "File reading error."); + PrintAndLogEx(ERR, "File reading error."); fclose(fnonces); return 1; } @@ -1711,12 +1711,12 @@ static void add_matching_states(statelist_t *candidates, uint8_t part_sum_a0, ui const uint32_t worstcase_size = 1 << 20; candidates->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size); if (candidates->states[odd_even] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in add_matching_states() - statelist.\n"); + PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - statelist.\n"); exit(4); } uint32_t *candidates_bitarray = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * worstcase_size); if (candidates_bitarray == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in add_matching_states() - bitarray.\n"); + PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - bitarray.\n"); free(candidates->states[odd_even]); exit(4); } @@ -1772,7 +1772,7 @@ static void add_bitflip_candidates(uint8_t byte) { uint32_t worstcase_size = nonces[byte].num_states_bitarray[odd_even] + 1; candidates1->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size); if (candidates1->states[odd_even] == NULL) { - PrintAndLogEx(WARNING, "Out of memory error in add_bitflip_candidates().\n"); + PrintAndLogEx(ERR, "Out of memory error in add_bitflip_candidates().\n"); exit(4); } diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index eb7d26c4f..91e223427 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -1232,7 +1232,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { status = ul_read(0, data, sizeof(data)); if (status == -1) { DropField(); - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ"); return status; } else if (status == 16) { ul_print_default(data); @@ -1248,7 +1248,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { uint8_t ulc_conf[16] = {0x00}; status = ul_read(0x28, ulc_conf, sizeof(ulc_conf)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ UL-C"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ UL-C"); DropField(); return status; } @@ -1263,7 +1263,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { status = ul_read(0x2C, ulc_deskey, sizeof(ulc_deskey)); if (status == -1) { DropField(); - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ magic"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ magic"); return status; } if (status == 16) ulc_print_3deskey(ulc_deskey); @@ -1306,7 +1306,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { uint8_t ulev1_signature[32] = {0x00}; status = ulev1_readSignature(ulev1_signature, sizeof(ulev1_signature)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ SIGNATURE"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ SIGNATURE"); DropField(); return status; } @@ -1322,7 +1322,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { uint8_t version[10] = {0x00}; status = ulev1_getVersion(version, sizeof(version)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to GETVERSION"); + PrintAndLogEx(ERR, "Error: tag didn't answer to GETVERSION"); DropField(); return status; } else if (status == 10) { @@ -1346,7 +1346,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) { if (startconfigblock) { // if we know where the config block is... status = ul_read(startconfigblock, ulev1_conf, sizeof(ulev1_conf)); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to READ EV1"); + PrintAndLogEx(ERR, "Error: tag didn't answer to READ EV1"); DropField(); return status; } else if (status == 16) { @@ -2134,7 +2134,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { long fsize = ftell(f); fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "Error, when getting filesize"); + PrintAndLogEx(ERR, "Error, when getting filesize"); fclose(f); return 1; } @@ -2150,7 +2150,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { size_t bytes_read = fread(dump, 1, fsize, f); fclose(f); if (bytes_read < MFU_DUMP_PREFIX_LENGTH) { - PrintAndLogEx(WARNING, "Error, dump file is too small"); + PrintAndLogEx(ERR, "Error, dump file is too small"); free(dump); return 1; } @@ -2167,7 +2167,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { uint8_t pages = (bytes_read - MFU_DUMP_PREFIX_LENGTH) / 4; if (pages - 1 != mem->pages) { - PrintAndLogEx(WARNING, "Error, invalid dump, wrong page count"); + PrintAndLogEx(ERR, "Error, invalid dump, wrong page count"); free(dump); return 1; } diff --git a/client/cmdhftopaz.c b/client/cmdhftopaz.c index 2b743a574..d604d4baf 100644 --- a/client/cmdhftopaz.c +++ b/client/cmdhftopaz.c @@ -321,7 +321,7 @@ static void topaz_print_control_TLVs(uint8_t *memory) { static int topaz_read_dynamic_data(void) { // first read the remaining block of segment 0 if (topaz_read_block(topaz_tag.uid, 0x0f, &topaz_tag.dynamic_memory[0]) == -1) { - PrintAndLogEx(WARNING, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); + PrintAndLogEx(ERR, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); return -1; } @@ -329,7 +329,7 @@ static int topaz_read_dynamic_data(void) { uint8_t max_segment = topaz_tag.size / 128 - 1; for (uint8_t segment = 1; segment <= max_segment; segment++) { if (topaz_read_segment(topaz_tag.uid, segment, &topaz_tag.dynamic_memory[(segment - 1) * 128 + 8]) == -1) { - PrintAndLogEx(WARNING, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); + PrintAndLogEx(ERR, "Error while reading dynamic memory block %02x. Aborting...", 0x0f); return -1; } } @@ -381,7 +381,7 @@ static int CmdHFTopazReader(const char *Cmd) { status = topaz_select(atqa, rid_response); if (status == -1) { - if (verbose) PrintAndLogEx(WARNING, "Error: couldn't receive ATQA"); + if (verbose) PrintAndLogEx(ERR, "Error: couldn't receive ATQA"); return -1; } @@ -393,7 +393,7 @@ static int CmdHFTopazReader(const char *Cmd) { } if (status == -2) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to RID"); + PrintAndLogEx(ERR, "Error: tag didn't answer to RID"); topaz_switch_off_field(); return -1; } @@ -411,7 +411,7 @@ static int CmdHFTopazReader(const char *Cmd) { status = topaz_rall(uid_echo, rall_response); if (status == -1) { - PrintAndLogEx(WARNING, "Error: tag didn't answer to RALL"); + PrintAndLogEx(ERR, "Error: tag didn't answer to RALL"); topaz_switch_off_field(); return -1; } diff --git a/client/cmdhw.c b/client/cmdhw.c index 871d3bfbd..1348f16b4 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -479,6 +479,13 @@ static int CmdSetMux(const char *Cmd) { return PM3_SUCCESS; } +static int CmdStandalone(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + clearCommandBuffer(); + SendCommandNG(CMD_STANDALONE, NULL, 0); + return PM3_SUCCESS; +} + static int CmdTune(const char *Cmd) { return CmdTuneSamples(Cmd); } @@ -591,6 +598,7 @@ static command_t CommandTable[] = { {"reset", CmdReset, IfPm3Present, "Reset the Proxmark3"}, {"setlfdivisor", CmdSetDivisor, IfPm3Present, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"}, {"setmux", CmdSetMux, IfPm3Present, "Set the ADC mux to a specific value"}, + {"standalone", CmdStandalone, IfPm3Present, "Jump to the standalone mode"}, {"status", CmdStatus, IfPm3Present, "Show runtime status information about the connected Proxmark3"}, {"tune", CmdTune, IfPm3Present, "Measure antenna tuning"}, {"version", CmdVersion, IfPm3Present, "Show version information about the connected Proxmark3"}, @@ -621,6 +629,11 @@ void pm3_version(bool verbose) { PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? +#if defined(__clang__) + PrintAndLogEx(NORMAL, " compiled with Clang/LLVM "__VERSION__); +#elif defined(__GNUC__) || defined(__GNUG__) + PrintAndLogEx(NORMAL, " compiled with GCC "__VERSION__); +#endif PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 ]"); PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); diff --git a/client/cmdlf.c b/client/cmdlf.c index 8459eca3a..42b26be0d 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -573,7 +573,7 @@ int CmdLFfskSim(const char *Cmd) { dataLen = hextobinarray((char *)data, hexData); if (dataLen == 0) errors = true; - if (errors) PrintAndLogEx(WARNING, "Error getting hex data"); + if (errors) PrintAndLogEx(ERR, "Error getting hex data"); cmdp += 2; break; default: @@ -685,7 +685,7 @@ int CmdLFaskSim(const char *Cmd) { dataLen = hextobinarray((char *)data, hexData); if (dataLen == 0) errors = true; - if (errors) PrintAndLogEx(WARNING, "Error getting hex data, datalen: %d", dataLen); + if (errors) PrintAndLogEx(ERR, "Error getting hex data, datalen: %d", dataLen); cmdp += 2; break; default: @@ -788,7 +788,7 @@ int CmdLFpskSim(const char *Cmd) { dataLen = hextobinarray((char *)data, hexData); if (dataLen == 0) errors = true; - if (errors) PrintAndLogEx(WARNING, "Error getting hex data"); + if (errors) PrintAndLogEx(ERR, "Error getting hex data"); cmdp += 2; break; default: @@ -957,7 +957,7 @@ static bool CheckChipType(bool getDeviceData) { retval = true; goto out; } - + //check for t55xx chip... if (tryDetectP1(true)) { PrintAndLogEx(SUCCESS, "\nChipset detection : " _GREEN_("T55xx") "found"); @@ -1084,8 +1084,8 @@ int CmdLFfind(const char *Cmd) { } out: // identify chipset - if ( CheckChipType(isOnline) == false ) { - PrintAndLogEx(DEBUG, "Automatic chip type detection " _RED_("failed") ); + if (CheckChipType(isOnline) == false) { + PrintAndLogEx(DEBUG, "Automatic chip type detection " _RED_("failed")); } return PM3_SUCCESS; } diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 7cb24d9c2..386d14e5e 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -103,7 +103,7 @@ static int sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uin PrintAndLogEx(INFO, "Trying FC: %u; CN: %u", fc, cn); if (getAWIDBits(fmtlen, fc, cn, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -333,7 +333,7 @@ static int CmdAWIDSim(const char *Cmd) { verify_values(&fmtlen, &fc, &cn); if (getAWIDBits(fmtlen, fc, cn, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -388,7 +388,7 @@ static int CmdAWIDClone(const char *Cmd) { verify_values(&fmtlen, &fc, &cn); if (getAWIDBits(fmtlen, fc, cn, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -419,7 +419,7 @@ static int CmdAWIDClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -491,7 +491,7 @@ static int CmdAWIDBrute(const char *Cmd) { } PrintAndLogEx(SUCCESS, "Bruteforceing AWID %d Reader", fmtlen); - PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or press key"); + PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or press Enter"); uint16_t up = cn; uint16_t down = cn; @@ -503,9 +503,7 @@ static int CmdAWIDBrute(const char *Cmd) { PrintAndLogEx(WARNING, "Device offline\n"); return PM3_ENODATA; } - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "aborted via keyboard!"); return sendPing(); } diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index 6a5fae76f..aaf8c0db4 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -482,12 +482,12 @@ static int CmdEM410xBrute(const char *Cmd) { int filelen = param_getstr(Cmd, 0, filename, FILE_PATH_SIZE); if (filelen == 0) { - PrintAndLogEx(WARNING, "Error: Please specify a filename"); + PrintAndLogEx(ERR, "Error: Please specify a filename"); return PM3_EINVARG; } if ((f = fopen(filename, "r")) == NULL) { - PrintAndLogEx(WARNING, "Error: Could not open UIDs file ["_YELLOW_("%s")"]", filename); + PrintAndLogEx(ERR, "Error: Could not open UIDs file ["_YELLOW_("%s")"]", filename); return PM3_EFILE; } @@ -544,9 +544,7 @@ static int CmdEM410xBrute(const char *Cmd) { char testuid[11]; testuid[10] = 0; - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\nAborted via keyboard!\n"); free(uidBlock); return PM3_EOPABORTED; @@ -580,9 +578,7 @@ static int CmdEM410xBrute(const char *Cmd) { static int CmdEM410xWatch(const char *Cmd) { (void)Cmd; // Cmd is not used so far do { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); break; } @@ -617,21 +613,21 @@ static int CmdEM410xWrite(const char *Cmd) { // Check ID if (id == 0xFFFFFFFFFFFFFFFF) { - PrintAndLogEx(WARNING, "Error! ID is required.\n"); + PrintAndLogEx(ERR, "Error! ID is required.\n"); return PM3_EINVARG; } if (id >= 0x10000000000) { - PrintAndLogEx(WARNING, "Error! Given EM410x ID is longer than 40 bits.\n"); + PrintAndLogEx(ERR, "Error! Given EM410x ID is longer than 40 bits.\n"); return PM3_EINVARG; } // Check Card if (card == 0xFF) { - PrintAndLogEx(WARNING, "Error! Card type required.\n"); + PrintAndLogEx(ERR, "Error! Card type required.\n"); return PM3_EINVARG; } if (card < 0) { - PrintAndLogEx(WARNING, "Error! Bad card type selected.\n"); + PrintAndLogEx(ERR, "Error! Bad card type selected.\n"); return PM3_EINVARG; } @@ -641,7 +637,7 @@ static int CmdEM410xWrite(const char *Cmd) { // Allowed clock rates: 16, 32, 40 and 64 if ((clock1 != 16) && (clock1 != 32) && (clock1 != 64) && (clock1 != 40)) { - PrintAndLogEx(WARNING, "Error! Clock rate" _YELLOW_("%d")" not valid. Supported clock rates are 16, 32, 40 and 64.\n", clock1); + PrintAndLogEx(ERR, "Error! Clock rate" _YELLOW_("%d")" not valid. Supported clock rates are 16, 32, 40 and 64.\n", clock1); return PM3_EINVARG; } @@ -841,7 +837,7 @@ int EM4x50Read(const char *Cmd, bool verbose) { } } if (!clk) { - if (verbose || g_debugMode) PrintAndLogEx(WARNING, "Error: EM4x50 - didn't find a clock"); + if (verbose || g_debugMode) PrintAndLogEx(ERR, "Error: EM4x50 - didn't find a clock"); return PM3_ESOFT; } } else tol = clk / 8; @@ -1266,7 +1262,7 @@ static int CmdEM4x05Write(const char *Cmd) { SendCommandNG(CMD_EM4X_WRITE_WORD, (uint8_t *)&payload, sizeof(payload)); PacketResponseNG resp; if (!WaitForResponseTimeout(CMD_EM4X_WRITE_WORD, &resp, 2000)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } @@ -1377,10 +1373,10 @@ static void printEM4x05config(uint32_t wordData) { PrintAndLogEx(NORMAL, " PSK CF: %u | %s", PSKcf, cf); PrintAndLogEx(NORMAL, " Delay: %u | %s", delay, cdelay); PrintAndLogEx(NORMAL, " LastWordR: %02u | Address of last word for default read - meaning %u blocks are output", LWR, numblks); - PrintAndLogEx(NORMAL, " ReadLogin: %u | Read login is %s", readLogin, readLogin ? _YELLOW_("required") : _GREEN_("not required") ); - PrintAndLogEx(NORMAL, " ReadHKL: %u | Read housekeeping words login is %s", readHKL, readHKL ? _YELLOW_("required") : _GREEN_("not required") ); - PrintAndLogEx(NORMAL, "WriteLogin: %u | Write login is %s", writeLogin, writeLogin ? _YELLOW_("required") : _GREEN_("not required") ); - PrintAndLogEx(NORMAL, " WriteHKL: %u | Write housekeeping words login is %s", writeHKL, writeHKL ? _YELLOW_("required") : _GREEN_("not Required") ); + PrintAndLogEx(NORMAL, " ReadLogin: %u | Read login is %s", readLogin, readLogin ? _YELLOW_("required") : _GREEN_("not required")); + PrintAndLogEx(NORMAL, " ReadHKL: %u | Read housekeeping words login is %s", readHKL, readHKL ? _YELLOW_("required") : _GREEN_("not required")); + PrintAndLogEx(NORMAL, "WriteLogin: %u | Write login is %s", writeLogin, writeLogin ? _YELLOW_("required") : _GREEN_("not required")); + PrintAndLogEx(NORMAL, " WriteHKL: %u | Write housekeeping words login is %s", writeHKL, writeHKL ? _YELLOW_("required") : _GREEN_("not Required")); PrintAndLogEx(NORMAL, " R.A.W.: %u | Read after write is %s", raw, raw ? "on" : "off"); PrintAndLogEx(NORMAL, " Disable: %u | Disable command is %s", disable, disable ? "accepted" : "not accepted"); PrintAndLogEx(NORMAL, " R.T.F.: %u | Reader talk first is %s", rtf, rtf ? _YELLOW_("enabled") : "disabled"); @@ -1400,7 +1396,7 @@ static void printEM4x05info(uint32_t block0, uint32_t serial) { snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "EM4305"); break; case 8: - snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "EM4205"); + snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "EM4205"); break; case 4: snprintf(ctstr + strlen(ctstr), sizeof(ctstr) - strlen(ctstr), _YELLOW_("%s"), "Unknown"); diff --git a/client/cmdlffdx.c b/client/cmdlffdx.c index 8cf93b12f..35f3216ad 100644 --- a/client/cmdlffdx.c +++ b/client/cmdlffdx.c @@ -264,7 +264,7 @@ static int CmdFdxClone(const char *Cmd) { // getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t isextended, uint32_t extended, uint8_t *bits) if (getFDXBits(animalid, countryid, 1, 0, 0, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -300,7 +300,7 @@ static int CmdFdxClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfguard.c b/client/cmdlfguard.c index 54073fc02..1b09eb18d 100644 --- a/client/cmdlfguard.c +++ b/client/cmdlfguard.c @@ -155,7 +155,7 @@ static int CmdGuardClone(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getGuardBits(fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -189,7 +189,7 @@ static int CmdGuardClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -213,7 +213,7 @@ static int CmdGuardSim(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getGuardBits(fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index b300858d2..cc395c8c5 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -580,9 +580,7 @@ static int CmdHIDBrute(const char *Cmd) { return PM3_ENODATA; } - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(INFO, "aborted via keyboard!"); return sendPing(); } diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index 998512575..69ba874c1 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -106,6 +106,7 @@ static int usage_hitag_writer(void) { PrintAndLogEx(NORMAL, " Hitag1 (1*)"); PrintAndLogEx(NORMAL, " Hitag2 (2*)"); PrintAndLogEx(NORMAL, " 24 (set to 0 if no authentication is needed) write page on a Hitag2 tag"); + PrintAndLogEx(NORMAL, " 27 write page on a Hitag2 tag"); return 0; } static int usage_hitag_checkchallenges(void) { @@ -176,7 +177,7 @@ static int CmdLFHitagList(const char *Cmd) { if (strlen(filename) > 0) { f = fopen(filename, "wb"); if (!f) { - PrintAndLogEx(WARNING, "Error: Could not open file [%s]", filename); + PrintAndLogEx(ERR, "Error: Could not open file [%s]", filename); return PM3_EFILE; } } @@ -551,6 +552,7 @@ static int CmdLFHitagReader(const char *Cmd) { case WHTSF_CHALLENGE: case WHTSF_KEY: case WHT2F_CRYPTO: + default: return usage_hitag_reader(); } @@ -658,6 +660,12 @@ static int CmdLFHitagWriter(const char *Cmd) { num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd.crypto.data); break; } + case WHT2F_PASSWORD: { + num_to_bytes(param_get64ex(Cmd, 1, 0, 16), 4, htd.pwd.password); + arg2 = param_get32ex(Cmd, 2, 0, 10); + num_to_bytes(param_get32ex(Cmd, 3, 0, 16), 4, htd.crypto.data); + break; + } case RHTSF_CHALLENGE: case RHTSF_KEY: case RHT2F_PASSWORD: @@ -665,6 +673,7 @@ static int CmdLFHitagWriter(const char *Cmd) { case RHT2F_CRYPTO: case RHT2F_TEST_AUTH_ATTEMPTS: case RHT2F_UID_ONLY: + default: return usage_hitag_writer(); } diff --git a/client/cmdlfio.c b/client/cmdlfio.c index ad37b9fd7..d187daaab 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -199,7 +199,7 @@ static int CmdIOProxSim(const char *Cmd) { PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or run another command"); if (getIOProxBits(version, fc, cn, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } // IOProx uses: fcHigh: 10, fcLow: 8, clk: 64, invert: 1 @@ -249,7 +249,7 @@ static int CmdIOProxClone(const char *Cmd) { } if (getIOProxBits(version, fc, cn, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfjablotron.c b/client/cmdlfjablotron.c index a5b9166ac..c2478705c 100644 --- a/client/cmdlfjablotron.c +++ b/client/cmdlfjablotron.c @@ -145,7 +145,7 @@ static int CmdJablotronClone(const char *Cmd) { } if (getJablotronBits(fullcode, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -174,7 +174,7 @@ static int CmdJablotronClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfkeri.c b/client/cmdlfkeri.c index 82d1b9f84..b3761055f 100644 --- a/client/cmdlfkeri.c +++ b/client/cmdlfkeri.c @@ -164,7 +164,7 @@ static int CmdKeriClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfnedap.c b/client/cmdlfnedap.c index d081ff56c..0b998d716 100644 --- a/client/cmdlfnedap.c +++ b/client/cmdlfnedap.c @@ -182,7 +182,7 @@ static int CmdLFNedapClone(const char *Cmd) { cardnumber = (cn & 0x00FFFFFF); if ( getNedapBits(cardnumber, bits) == PM3_SUCCESS ) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -220,7 +220,7 @@ static int CmdLFNedapClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -243,7 +243,7 @@ static int CmdLFNedapSim(const char *Cmd) { memset(bs, 0x00, sizeof(bs)); if (getNedapBits(cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfnoralsy.c b/client/cmdlfnoralsy.c index 9e3413405..34ad1023f 100644 --- a/client/cmdlfnoralsy.c +++ b/client/cmdlfnoralsy.c @@ -142,7 +142,7 @@ static int CmdNoralsyClone(const char *Cmd) { blocks[0] = T5555_MODULATION_MANCHESTER | T5555_SET_BITRATE(32) | T5555_ST_TERMINATOR | 3 << T5555_MAXBLOCK_SHIFT; if (getnoralsyBits(id, year, bits) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -172,7 +172,7 @@ static int CmdNoralsyClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -195,7 +195,7 @@ static int CmdNoralsySim(const char *Cmd) { year = param_get32ex(Cmd, 1, 2000, 10); if (getnoralsyBits(id, year, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 684730ef3..c5c022d9b 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -128,7 +128,7 @@ static int CmdParadoxSim(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); // if ( GetParadoxBits(facilitycode, cardnumber, bs) != PM3_SUCCESS) { - // PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + // PrintAndLogEx(ERR, "Error with tag bitstream generation."); // return 1; // } diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index a51155e78..3f1ce71f3 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -138,7 +138,7 @@ static int CmdPrescoClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index 91b895bcb..4e5588ec6 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -212,7 +212,7 @@ static int CmdPyramidClone(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getPyramidBits(facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } @@ -249,7 +249,7 @@ static int CmdPyramidClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } @@ -272,7 +272,7 @@ static int CmdPyramidSim(const char *Cmd) { cardnumber = (cn & 0x0000FFFF); if (getPyramidBits(facilitycode, cardnumber, bs) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Error with tag bitstream generation."); + PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 923e50110..9a23e660b 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -1103,7 +1103,7 @@ static int CmdT55xxWriteBlock(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, 2000)) { - PrintAndLogEx(WARNING, "Error occurred, device did not ACK write operation. (May be due to old firmware)"); + PrintAndLogEx(ERR, "Error occurred, device did not ACK write operation. (May be due to old firmware)"); return PM3_ETIMEOUT; } return PM3_SUCCESS; @@ -1829,13 +1829,13 @@ static int CmdT55xxWipe(const char *Cmd) { else snprintf(ptrData, sizeof(writeData), "b 0 d 000880E0 p 0"); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Error writing blk 0"); + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Warning: error writing blk 0"); for (uint8_t blk = 1; blk < 8; blk++) { snprintf(ptrData, sizeof(writeData), "b %d d 0", blk); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Error writing blk %d", blk); + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Warning: error writing blk %d", blk); memset(writeData, 0x00, sizeof(writeData)); } @@ -1843,9 +1843,7 @@ static int CmdT55xxWipe(const char *Cmd) { } static bool IsCancelled(void) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); return true; } @@ -1921,7 +1919,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { // TODO, a way of reallocating memory if file was larger keyBlock = calloc(4 * 200, sizeof(uint8_t)); if (keyBlock == NULL) { - PrintAndLogDevice(WARNING, "error, cannot allocate memory "); + PrintAndLogDevice(ERR, "error, cannot allocate memory "); return PM3_ESOFT; } @@ -2155,7 +2153,7 @@ bool tryDetectP1(bool getData) { } return false; } - + // try ask clock detect. it could be another type even if successful. clk = GetAskClock("", false); if (clk > 0) { @@ -2164,14 +2162,14 @@ bool tryDetectP1(bool getData) { (DemodBufferLen == 32 || DemodBufferLen == 64)) { return true; } - + st = true; if ((ASKDemod_ext("0 1 1", false, false, 1, &st) == PM3_SUCCESS) && preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) && (DemodBufferLen == 32 || DemodBufferLen == 64)) { return true; } - + if ((ASKbiphaseDemod("0 0 0 2", false) == PM3_SUCCESS) && preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) && (DemodBufferLen == 32 || DemodBufferLen == 64)) { @@ -2184,7 +2182,7 @@ bool tryDetectP1(bool getData) { return true; } } - + // try NRZ clock detect. it could be another type even if successful. clk = GetNrzClock("", false); //has the most false positives :( if (clk > 0) { diff --git a/client/cmdlfti.c b/client/cmdlfti.c index 3baa8c2e6..5236550b2 100644 --- a/client/cmdlfti.c +++ b/client/cmdlfti.c @@ -233,7 +233,7 @@ static int CmdTIDemod(const char *Cmd) { // only 15 bits compare, last bit of ident is not valid if ((shift3 ^ shift0) & 0x7FFF) { - PrintAndLogEx(WARNING, "Error: Ident mismatch!"); + PrintAndLogEx(WARNING, "Warning: Ident mismatch!"); } // WARNING the order of the bytes in which we calc crc below needs checking // i'm 99% sure the crc algorithm is correct, but it may need to eat the @@ -257,7 +257,7 @@ static int CmdTIDemod(const char *Cmd) { PrintAndLogEx(INFO, "Tag data = %08X%08X [Crc %04X %s]", shift1, shift0, crc, crcStr); if (crc != (shift2 & 0xFFFF)) - PrintAndLogEx(WARNING, "Error: CRC mismatch, calculated %04X, got %04X", crc, shift2 & 0xFFFF); + PrintAndLogEx(WARNING, "Warning: CRC mismatch, calculated %04X, got %04X", crc, shift2 & 0xFFFF); retval = PM3_SUCCESS; goto out; diff --git a/client/cmdlfviking.c b/client/cmdlfviking.c index 750070a34..41193ea12 100644 --- a/client/cmdlfviking.c +++ b/client/cmdlfviking.c @@ -91,7 +91,7 @@ static int CmdVikingClone(const char *Cmd) { SendCommandMIX(CMD_VIKING_CLONE_TAG, rawID >> 32, rawID & 0xFFFFFFFF, Q5, NULL, 0); PacketResponseNG resp; if (!WaitForResponseTimeout(CMD_ACK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } return PM3_SUCCESS; diff --git a/client/cmdlfvisa2000.c b/client/cmdlfvisa2000.c index b717f65dd..12d4ba1c6 100644 --- a/client/cmdlfvisa2000.c +++ b/client/cmdlfvisa2000.c @@ -186,7 +186,7 @@ static int CmdVisa2kClone(const char *Cmd) { SendCommandNG(CMD_T55XX_WRITE_BLOCK, (uint8_t *)&ng, sizeof(ng)); if (!WaitForResponseTimeout(CMD_T55XX_WRITE_BLOCK, &resp, T55XX_WRITE_TIMEOUT)) { - PrintAndLogEx(WARNING, "Error occurred, device did not respond during write operation."); + PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation."); return PM3_ETIMEOUT; } } diff --git a/client/cmdmain.c b/client/cmdmain.c index 311e2d6de..6748f81f0 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -31,6 +31,32 @@ static int CmdRem(const char *Cmd) { return PM3_SUCCESS; } +static int usage_msleep(void) { + PrintAndLogEx(NORMAL, "Sleep for given amount of milliseconds"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: msleep "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " time in milliseconds"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " msleep 100"); + return PM3_SUCCESS; +} + +static int CmdMsleep(const char *Cmd) { + uint32_t ms = 0; + char ctmp = tolower(param_getchar(Cmd, 0)); + if (strlen(Cmd) < 1 || ctmp == 'h') return usage_msleep(); + if (param_getchar(Cmd, 0) != 0x00) { + ms = param_get32ex(Cmd, 0, 0, 10); + if (ms == 0) + return usage_msleep(); + } + msleep(ms); + return PM3_SUCCESS; +} + static int CmdQuit(const char *Cmd) { (void)Cmd; // Cmd is not used so far return PM3_EFATAL; @@ -50,8 +76,9 @@ static command_t CommandTable[] = { {"hw", CmdHW, AlwaysAvailable, "{ Hardware commands... }"}, {"lf", CmdLF, AlwaysAvailable, "{ Low Frequency commands... }"}, {"mem", CmdFlashMem, IfPm3Flash, "{ Flash Memory manipulation... }"}, - {"rem", CmdRem, AlwaysAvailable, "{ Add text to row in log file }"}, - {"reveng", CmdRev, AlwaysAvailable, "{ Crc calculations from the RevEng software... }"}, + {"msleep", CmdMsleep, AlwaysAvailable, "Add a pause in milliseconds"}, + {"rem", CmdRem, AlwaysAvailable, "Add text to row in log file"}, + {"reveng", CmdRev, AlwaysAvailable, "{ Crc calculations from the RevEng software }"}, {"sc", CmdSmartcard, IfPm3Smartcard, "{ Smart card ISO7816 commands... }"}, {"script", CmdScript, AlwaysAvailable, "{ Scripting commands }"}, {"trace", CmdTrace, AlwaysAvailable, "{ Trace manipulation... }"}, diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index c8529fa23..c49f0d0e7 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -284,7 +284,7 @@ static int PrintATR(uint8_t *atr, size_t atrlen) { vxor ^= atr[i]; if (vxor) - PrintAndLogEx(WARNING, "Check sum error. Must be 0 got 0x%02X", vxor); + PrintAndLogEx(WARNING, "Invalid check sum. Must be 0 got 0x%02X", vxor); else PrintAndLogEx(INFO, "Check sum OK."); } @@ -295,7 +295,7 @@ static int PrintATR(uint8_t *atr, size_t atrlen) { uint8_t calen = 2 + T1len + TD1len + TDilen + K; if (atrlen != calen && atrlen != calen + 1) // may be CRC - PrintAndLogEx(ERR, "ATR length error. len: %d, T1len: %d, TD1len: %d, TDilen: %d, K: %d", atrlen, T1len, TD1len, TDilen, K); + PrintAndLogEx(WARNING, "Invalid ATR length. len: %d, T1len: %d, TD1len: %d, TDilen: %d, K: %d", atrlen, T1len, TD1len, TDilen, K); if (K > 0) PrintAndLogEx(INFO, "\nHistorical bytes | len 0x%02d | format %02x", K, atr[2 + T1len + TD1len + TDilen]); @@ -568,14 +568,14 @@ static int CmdSmartUpgrade(const char *Cmd) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogEx(WARNING, "error, when getting filesize"); + PrintAndLogEx(ERR, "error, when getting filesize"); fclose(f); return 1; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { - PrintAndLogEx(WARNING, "error, cannot allocate memory "); + PrintAndLogEx(ERR, "error, cannot allocate memory "); fclose(f); return 1; } @@ -914,9 +914,7 @@ static int smart_brute_sfi(bool decodeTLV) { for (uint16_t rec = 1; rec <= 255; rec++) { - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); free(buf); return 1; diff --git a/client/cmdusart.c b/client/cmdusart.c index e57834545..60b977430 100644 --- a/client/cmdusart.c +++ b/client/cmdusart.c @@ -312,11 +312,9 @@ static int CmdUsartBtFactory(const char *Cmd) { PrintAndLogEx(WARNING, _RED_("WARNING: process only if strictly needed!")); PrintAndLogEx(WARNING, "This requires BT turned ON and NOT connected!"); PrintAndLogEx(WARNING, "Is the add-on blue light blinking? (Say 'n' if you want to abort) [y/n]"); - while (!ukbhit()) { - msleep(200); - } - if (tolower(getchar()) != 'y') { + char input[3]; + if ((fgets(input, sizeof(input), stdin) == NULL) || (strncmp(input, "y\n", sizeof(input)) != 0)) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(FAILED, "Aborting."); return PM3_EOPABORTED; @@ -448,11 +446,10 @@ static int CmdUsartBtFactory(const char *Cmd) { } if ((baudrate != USART_BAUD_RATE) || (parity != USART_PARITY)) { - PrintAndLogEx(WARNING, "Add-on uart settings changed, please turn BT add-on OFF and ON again, then press any key."); - while (!ukbhit()) { + PrintAndLogEx(WARNING, "Add-on uart settings changed, please turn BT add-on OFF and ON again, then press Enter."); + while (!kbd_enter_pressed()) { msleep(200); } - getchar(); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "Trying to connect add-on with the new settings."); found = usart_bt_testcomm(USART_BAUD_RATE, USART_PARITY) == PM3_SUCCESS; diff --git a/client/comms.c b/client/comms.c index 5aa704728..304948a4d 100644 --- a/client/comms.c +++ b/client/comms.c @@ -136,7 +136,7 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool txBufferNG.pre.ng = ng; txBufferNG.pre.length = len; txBufferNG.pre.cmd = cmd; - if ( len > 0 && data ) + if (len > 0 && data) memcpy(&txBufferNG.data, data, len); if ((conn.send_via_fpc_usart && conn.send_with_crc_on_fpc) || ((!conn.send_via_fpc_usart) && conn.send_with_crc_on_usb)) { @@ -359,7 +359,7 @@ __attribute__((force_align_arg_pointer)) res = uart_receive(sp, (uint8_t *)&rx_raw.data, length, &rxlen); if ((res != PM3_SUCCESS) || (rxlen != length)) { - PrintAndLogEx(WARNING, "Received packet frame error variable part too short? %d/%d", rxlen, length); + PrintAndLogEx(WARNING, "Received packet frame with variable part too short? %d/%d", rxlen, length); error = true; } else { @@ -392,7 +392,7 @@ __attribute__((force_align_arg_pointer)) if (!error) { // Get the postamble res = uart_receive(sp, (uint8_t *)&rx_raw.foopost, sizeof(PacketResponseNGPostamble), &rxlen); if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseNGPostamble))) { - PrintAndLogEx(WARNING, "Received packet frame error fetching postamble"); + PrintAndLogEx(WARNING, "Received packet frame without postamble"); error = true; } } @@ -402,7 +402,7 @@ __attribute__((force_align_arg_pointer)) uint8_t first, second; compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(PacketResponseNGPreamble) + length, &first, &second); if ((first << 8) + second != rx.crc) { - PrintAndLogEx(WARNING, "Received packet frame CRC error %02X%02X <> %04X", first, second, rx.crc); + PrintAndLogEx(WARNING, "Received packet frame with invalid CRC %02X%02X <> %04X", first, second, rx.crc); error = true; } } @@ -424,7 +424,7 @@ __attribute__((force_align_arg_pointer)) res = uart_receive(sp, ((uint8_t *)&rx_old) + sizeof(PacketResponseNGPreamble), sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble), &rxlen); if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble))) { - PrintAndLogEx(WARNING, "Received packet OLD frame payload error too short? %d/%d", rxlen, sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble)); + PrintAndLogEx(WARNING, "Received packet OLD frame with payload too short? %d/%d", rxlen, sizeof(PacketResponseOLD) - sizeof(PacketResponseNGPreamble)); error = true; } if (!error) { diff --git a/client/default_keys.dic b/client/default_keys.dic index f02428c18..c8d96bd44 100644 --- a/client/default_keys.dic +++ b/client/default_keys.dic @@ -97,9 +97,15 @@ f1d83f964314,--RKFRejskortDanmarkKeyB fc00018778f7,--VästtrafikenKeyA, RKFÖstgötaTrafikenKeyA 44ab09010845,-- hotel system 85fed980ea5a,-- hotel system -314B49474956,--VIGIK1KeyA -564c505f4d41,--VIGIK1KeyB -ba5b895da162,--VIGIK1KeyB +314B49474956 --VIGIK1 A +564c505f4d41 --VIGIK1 B +ba5b895da162 --VIGIK1 B +# Vigik mystery Keys Mifare 1k EV1 (S50) +5c8ff9990da2, 16 A +75ccb59c9bed, 17 A +d01afeeb890a, 16 B +4b791bea7bcc, 17 B +# 4143414F5250, a9b43414F585,--Tehran Railway 1FB235AC1388,--Tehran Railway @@ -109,8 +115,6 @@ f4a9ef2afc6d,--BCARD KeyB # # a9f953def0a3,-- -75ccb59c9bed,-- mystery KeyA Mifare 1k EV1 (S50) Sector 17! -4b791bea7bcc,-- mystery KeyB Mifare 1k EV1 (S50) Sector 17! # # Here be BIP keys... 3A42F33AF429, @@ -770,14 +774,18 @@ A2B2C9D187FB, A2F63A485632, 98631ED2B229, 19F1FFE02563, -#OMNITEC.ES HOTEL TIMECARD / MAINTENANCECARD +563A22C01FC8, -- Argentina +43CA22C13091, -- Argentina +25094DF2C1BD, -- Argentina +# +# OMNITEC.ES HOTEL TIMECARD / MAINTENANCECARD AFBECD120454, -#OMNITEC.ES HOTEL EMERGENCYCARD +# +# OMNITEC.ES HOTEL EMERGENCYCARD 842146108088, -# MORE KEYS: -8A19D40CF2B5, -AE8587108640, -#TAPCARD PUBLIC TRANSPORT LA +# +# TAPCARD PUBLIC TRANSPORT LA +# EA1B88DF0A76, D1991E71E2C5, 05F89678CFCF, @@ -810,10 +818,10 @@ B81846F06EDF, C6A76CB2F3B5, E3AD9E9BA5D4, 6C9EC046C1A4, -#ROC HIGHSCHOOL ACCESSCARD -A0A1A2A3A4A5, +# +# ROC HIGHSCHOOL ACCESSCARD +# B021669B44BB, -A0A1A2A3A4A5, B18CDCDE52B7, A22647F422AE, B268F7C9CA63, @@ -840,10 +848,12 @@ BCF5A6B5E13F, AD5645062534, BDF837787A71, AE43F36C1A9A, -BE7C4F6C7A9A, +BE7C4F6C7A9A, 5EC7938F140A, 82D58AA49CCB, -#MELONCARD +# +# MELONCARD +# 323334353637, # # @@ -861,7 +871,9 @@ A7FB4824ACBF, 00F0BD116D70, 4CFF128FA3EF, 10F3BEBC01DF, -#Transportes Insular La Palma +# +# Transportes Insular La Palma +# 0172066b2f03, 0000085f0000, 1a80b93f7107, @@ -894,3 +906,43 @@ b1a862985913, 3b0172066b2f, 3f1a87298691, f3f0172066b2, +# +# Tehran ezpay +# +38A88AEC1C43 +CBD2568BC7C6 +7BCB4774EC8F +22ECE9316461 +AE4B497A2527 +EEC0626B01A1 +2C71E22A32FE +91142568B22F +7D56759A974A +D3B1C7EA5C53 +41C82D231497 +0B8B21C692C2 +604Ac8D87C7E +8E7B29460F12 +BB3D7B11D224 +# +# Chaco +# +b210cfa436d2 +b8b1cfa646a8 +a9f95891f0a4 +# +# Keys from APK application "Scan Badge" +4A4C474F524D +444156494442 +434143445649 +434456495243 +A00002000021 +EF61A3D48E2A +A23456789123 +010000000000 +363119000001 +A00003000084 +675A32413770 +395244733978 +# +B069D0D03D17 diff --git a/client/deprecated-hid-flasher/flasher/elf.h b/client/deprecated-hid-flasher/flasher/elf.h index 0551cbd76..eef2863d8 100644 --- a/client/deprecated-hid-flasher/flasher/elf.h +++ b/client/deprecated-hid-flasher/flasher/elf.h @@ -9,6 +9,8 @@ #ifndef __ELF_H__ #define __ELF_H__ +#include "proxmark3.h" + typedef struct { uint32_t p_type; uint32_t p_offset; @@ -18,7 +20,7 @@ typedef struct { uint32_t p_memsz; uint32_t p_flags; uint32_t p_align; -} __attribute__((__packed__)) Elf32_Phdr; +} PACKED Elf32_Phdr; #define EI_NIDENT 16 @@ -37,7 +39,7 @@ typedef struct { uint16_t e_shentsize; uint16_t e_shnum; uint16_t e_shtrndx; -} __attribute__((__packed__)) Elf32_Ehdr; +} PACKED Elf32_Ehdr; #define PT_NULL 0 #define PT_LOAD 1 diff --git a/client/deprecated-hid-flasher/flasher/proxmark3.h b/client/deprecated-hid-flasher/flasher/proxmark3.h index f5dd2b7fa..c9e42efd8 100644 --- a/client/deprecated-hid-flasher/flasher/proxmark3.h +++ b/client/deprecated-hid-flasher/flasher/proxmark3.h @@ -14,4 +14,16 @@ #define PROXPROMPT "proxmark3> " +#ifdef _MSC_VER +typedef DWORD uint32_t; +typedef BYTE uint8_t; +#define PACKED +// stuff +#else +#include +#include +#define PACKED __attribute__((packed)) +#endif + + #endif diff --git a/client/deprecated-hid-flasher/flasher/sleep.h b/client/deprecated-hid-flasher/flasher/sleep.h index f3aac0c8f..ffb5486aa 100644 --- a/client/deprecated-hid-flasher/flasher/sleep.h +++ b/client/deprecated-hid-flasher/flasher/sleep.h @@ -6,18 +6,18 @@ #define SLEEP_H__ #ifdef _WIN32 - #include - #define msleep(n) Sleep(n) +#include +#define msleep(n) Sleep(n) #else - #include - #include - static void nsleep(uint64_t n) { - struct timespec timeout; - timeout.tv_sec = n / 1000000000; - timeout.tv_nsec = n % 1000000000; - while (nanosleep(&timeout, &timeout) && errno == EINTR); - } - #define msleep(n) nsleep(1000000 * (uint64_t)n) +#include +#include +static void nsleep(uint64_t n) { + struct timespec timeout; + timeout.tv_sec = n / 1000000000; + timeout.tv_nsec = n % 1000000000; + while (nanosleep(&timeout, &timeout) && errno == EINTR); +} +#define msleep(n) nsleep(1000000 * (uint64_t)n) #endif #endif diff --git a/client/deprecated-hid-flasher/flasher/usb_cmd.h b/client/deprecated-hid-flasher/flasher/usb_cmd.h index 2b383faf8..60c359e5a 100644 --- a/client/deprecated-hid-flasher/flasher/usb_cmd.h +++ b/client/deprecated-hid-flasher/flasher/usb_cmd.h @@ -12,16 +12,8 @@ #ifndef __USB_CMD_H #define __USB_CMD_H -#ifdef _MSC_VER -typedef DWORD uint32_t; -typedef BYTE uint8_t; -#define PACKED -// stuff -#else -#include -#include -#define PACKED __attribute__((packed)) -#endif + +#include "proxmark3.h" typedef struct { uint32_t cmd; diff --git a/client/elf.h b/client/elf.h index 0551cbd76..50533224f 100644 --- a/client/elf.h +++ b/client/elf.h @@ -9,6 +9,8 @@ #ifndef __ELF_H__ #define __ELF_H__ +#include "common.h" + typedef struct { uint32_t p_type; uint32_t p_offset; @@ -18,7 +20,7 @@ typedef struct { uint32_t p_memsz; uint32_t p_flags; uint32_t p_align; -} __attribute__((__packed__)) Elf32_Phdr; +} PACKED Elf32_Phdr; #define EI_NIDENT 16 @@ -37,7 +39,7 @@ typedef struct { uint16_t e_shentsize; uint16_t e_shnum; uint16_t e_shtrndx; -} __attribute__((__packed__)) Elf32_Ehdr; +} PACKED Elf32_Ehdr; #define PT_NULL 0 #define PT_LOAD 1 diff --git a/client/emv/apduinfo.c b/client/emv/apduinfo.c index df44ef961..48e97622b 100644 --- a/client/emv/apduinfo.c +++ b/client/emv/apduinfo.c @@ -314,3 +314,190 @@ const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2) { else return APDUCodeTable[0].Description; //empty string } + +int APDUDecode(uint8_t *data, int len, APDUStruct *apdu) { + ExtAPDUHeader *hapdu = (ExtAPDUHeader *)data; + + apdu->cla = hapdu->cla; + apdu->ins = hapdu->ins; + apdu->p1 = hapdu->p1; + apdu->p2 = hapdu->p2; + + apdu->lc = 0; + apdu->data = NULL; + apdu->le = 0; + apdu->extended_apdu = false; + apdu->case_type = 0x00; + + uint8_t b0 = hapdu->lc[0]; + + // case 1 + if (len == 4) { + apdu->case_type = 0x01; + } + + // case 2S (Le) + if (len == 5) { + apdu->case_type = 0x02; + apdu->le = b0; + if (!apdu->le) + apdu->le = 0x100; + } + + // case 3S (Lc + data) + if (len == 5U + b0 && b0 != 0) { + apdu->case_type = 0x03; + apdu->lc = b0; + } + + // case 4S (Lc + data + Le) + if (len == 5U + b0 + 1U && b0 != 0) { + apdu->case_type = 0x04; + apdu->lc = b0; + apdu->le = data[len - 1]; + if (!apdu->le) + apdu->le = 0x100; + } + + // extended length apdu + if (len >= 7 && b0 == 0) { + uint16_t extlen = (hapdu->lc[1] << 8) + hapdu->lc[2]; + + // case 2E (Le) - extended + if (len == 7) { + apdu->case_type = 0x12; + apdu->extended_apdu = true; + apdu->le = extlen; + if (!apdu->le) + apdu->le = 0x10000; + } + + // case 3E (Lc + data) - extended + if (len == 7U + extlen) { + apdu->case_type = 0x13; + apdu->extended_apdu = true; + apdu->lc = extlen; + } + + // case 4E (Lc + data + Le) - extended 2-byte Le + if (len == 7U + extlen + 2U) { + apdu->case_type = 0x14; + apdu->extended_apdu = true; + apdu->lc = extlen; + apdu->le = (data[len - 2] << 8) + data[len - 1]; + if (!apdu->le) + apdu->le = 0x10000; + } + + // case 4E (Lc + data + Le) - extended 3-byte Le + if (len == 7U + extlen + 3U && data[len - 3] == 0) { + apdu->case_type = 0x24; + apdu->extended_apdu = true; + apdu->lc = extlen; + apdu->le = (data[len - 2] << 8) + data[len - 1]; + if (!apdu->le) + apdu->le = 0x10000; + } + } + + if (!apdu->case_type) + return 1; + + if (apdu->lc) { + if (apdu->extended_apdu) { + apdu->data = data + 7; + } else { + apdu->data = data + 5; + } + + } + + return 0; +} + +int APDUEncode(APDUStruct *apdu, uint8_t *data, int *len) { + if (len) + *len = 0; + + if (apdu->le > 0x10000 || apdu->lc > 0xffff) + return 1; + + size_t dptr = 0; + data[dptr++] = apdu->cla; + data[dptr++] = apdu->ins; + data[dptr++] = apdu->p1; + data[dptr++] = apdu->p2; + + if (apdu->lc) { + if (apdu->extended_apdu || apdu->lc > 0xff || apdu->le > 0x100) { + data[dptr++] = 0x00; + data[dptr++] = (apdu->lc >> 8) & 0xff; + data[dptr++] = (apdu->lc) & 0xff; + memmove(&data[dptr], apdu->data, apdu->lc); + dptr += apdu->lc; + apdu->extended_apdu = true; + } else { + data[dptr++] = apdu->lc; + memmove(&data[dptr], apdu->data, apdu->lc); + dptr += apdu->lc; + } + } + + if (apdu->le) { + if (apdu->extended_apdu) { + if (apdu->le != 0x10000) { + data[dptr++] = 0x00; + data[dptr++] = (apdu->le >> 8) & 0xff; + data[dptr++] = (apdu->le) & 0xff; + } else { + data[dptr++] = 0x00; + data[dptr++] = 0x00; + data[dptr++] = 0x00; + } + } else { + if (apdu->le != 0x100) + data[dptr++] = apdu->le; + else + data[dptr++] = 0x00; + } + } + + if (len) + *len = dptr; + return 0; +} + +int APDUEncodeS(sAPDU *sapdu, bool extended, uint16_t le, uint8_t *data, int *len) { + if (extended && le > 0x100) + return 10; + + APDUStruct apdu; + + apdu.cla = sapdu->CLA; + apdu.ins = sapdu->INS; + apdu.p1 = sapdu->P1; + apdu.p2 = sapdu->P2; + + apdu.lc = sapdu->Lc; + if (sapdu->Lc) + apdu.data = sapdu->data; + else + apdu.data = NULL; + apdu.le = le; + + apdu.extended_apdu = extended; + apdu.case_type = 0x00; + + return APDUEncode(&apdu, data, len); +} + +void APDUPrint(APDUStruct apdu) { + APDUPrintEx(apdu, 0); +} + +void APDUPrintEx(APDUStruct apdu, size_t maxdatalen) { + PrintAndLogEx(INFO, "APDU: %scase=0x%02x cla=0x%02x ins=0x%02x p1=0x%02x p2=0x%02x Lc=0x%02x(%d) Le=0x%02x(%d)", + apdu.extended_apdu ? "[e]" : "", apdu.case_type, apdu.cla, apdu.ins, apdu.p1, apdu.p2, apdu.lc, apdu.lc, apdu.le, apdu.le); + if (maxdatalen > 0) + PrintAndLogEx(INFO, "data: %s%s", sprint_hex(apdu.data, MIN(apdu.lc, maxdatalen)), apdu.lc > maxdatalen ? "..." : ""); +} diff --git a/client/emv/apduinfo.h b/client/emv/apduinfo.h index 317d661ff..25d062dcf 100644 --- a/client/emv/apduinfo.h +++ b/client/emv/apduinfo.h @@ -14,8 +14,11 @@ #include #include #include +#include #include +#include "util.h" + #define APDUCODE_TYPE_NONE 0 #define APDUCODE_TYPE_INFO 1 #define APDUCODE_TYPE_WARNING 2 @@ -31,4 +34,39 @@ typedef struct { const APDUCode *GetAPDUCode(uint8_t sw1, uint8_t sw2); const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2); +typedef struct { + uint8_t CLA; + uint8_t INS; + uint8_t P1; + uint8_t P2; + uint8_t Lc; + uint8_t *data; +} PACKED sAPDU; + +typedef struct { + uint8_t cla; + uint8_t ins; + uint8_t p1; + uint8_t p2; + uint8_t lc[3]; +} PACKED ExtAPDUHeader; + +typedef struct { + uint8_t cla; + uint8_t ins; + uint8_t p1; + uint8_t p2; + uint16_t lc; + uint8_t *data; + uint32_t le; + bool extended_apdu; + uint8_t case_type; +} PACKED APDUStruct; + +extern int APDUDecode(uint8_t *data, int len, APDUStruct *apdu); +extern int APDUEncode(APDUStruct *apdu, uint8_t *data, int *len); +extern int APDUEncodeS(sAPDU *apdu, bool extended, uint16_t le, uint8_t *data, int *len); +extern void APDUPrint(APDUStruct apdu); +extern void APDUPrintEx(APDUStruct apdu, size_t maxdatalen); + #endif diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index ca3866805..0cf177620 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -287,8 +287,8 @@ static int CmdEMVGPO(const char *Cmd) { PrintAndLogEx(ERR, "Can't create PDOL data."); tlvdb_free(tmp_ext); tlvdb_free(tlvRoot); - if (pdol_data_tlv != &data_tlv); - free(pdol_data_tlv); + if (pdol_data_tlv != &data_tlv) + free(pdol_data_tlv); return PM3_ESOFT; } PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len)); @@ -830,6 +830,12 @@ static int CmdEMVExec(const char *Cmd) { SetAPDULogging(showAPDU); res = EMVSearchPSE(channel, activateField, true, psenum, decodeTLV, tlvSelect); + // check PPSE instead of PSE and vice versa + if (res) { + PrintAndLogEx(NORMAL, "Check PPSE instead of PSE and vice versa..."); + res = EMVSearchPSE(channel, false, true, psenum == 1 ? 2 : 1, decodeTLV, tlvSelect); + } + // check PPSE and select application id if (!res) { TLVPrintAIDlistFromSelectTLV(tlvSelect); @@ -931,7 +937,7 @@ static int CmdEMVExec(const char *Cmd) { while (AFL && AFL->len) { if (AFL->len % 4) { - PrintAndLogEx(WARNING, "Error: Wrong AFL length: %d", AFL->len); + PrintAndLogEx(WARNING, "Warning: Wrong AFL length: %d", AFL->len); break; } @@ -1001,7 +1007,7 @@ static int CmdEMVExec(const char *Cmd) { AIP = AIPtlv->value[0] + AIPtlv->value[1] * 0x100; PrintAndLogEx(NORMAL, "* * AIP=%04x", AIP); } else { - PrintAndLogEx(ERR, "Can't found AIP."); + PrintAndLogEx(ERR, "Can't find AIP."); } // SDA @@ -1047,11 +1053,11 @@ static int CmdEMVExec(const char *Cmd) { TLVPrintFromTLVLev(cvr, 1); } } else { - PrintAndLogEx(NORMAL, "WARNING: IAD not found."); + PrintAndLogEx(WARNING, "WARNING: IAD not found."); } } else { - PrintAndLogEx(WARNING, "Error AC: Application Transaction Counter (ATC) not found."); + PrintAndLogEx(WARNING, "Warning AC: Application Transaction Counter (ATC) not found."); } } } @@ -1131,14 +1137,14 @@ static int CmdEMVExec(const char *Cmd) { PrintAndLogEx(NORMAL, "Transaction approved ONLINE."); break; default: - PrintAndLogEx(WARNING, "Error: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK); + PrintAndLogEx(WARNING, "Warning: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK); break; } } else { - PrintAndLogEx(WARNING, "Error: Wrong CID length %d", CID->len); + PrintAndLogEx(WARNING, "Warning: Wrong CID length %d", CID->len); } } else { - PrintAndLogEx(WARNING, "Error: CID(9F27) not found."); + PrintAndLogEx(WARNING, "Warning: CID(9F27) not found."); } } diff --git a/client/emv/emv_pk.c b/client/emv/emv_pk.c index ae23c8470..b03567440 100644 --- a/client/emv/emv_pk.c +++ b/client/emv/emv_pk.c @@ -24,7 +24,7 @@ #include "emv_pk.h" #include "crypto.h" #include "proxmark3.h" - +#include "util.h" #include #include #include @@ -398,7 +398,7 @@ static struct emv_pk *emv_pk_get_ca_pk_from_file(const char *fname, FILE *f = fopen(fname, "r"); if (!f) { - perror("fopen"); + PrintAndLogEx(ERR, "Error: can't open file %s.", fname); return NULL; } diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index e9e725448..6657f2ce3 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -277,24 +277,25 @@ static int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool Lea } // COMPUTE APDU - memcpy(data, &apdu, 5); - if (apdu.data) - memcpy(&data[5], apdu.data, apdu.Lc); + int datalen = 0; + if (APDUEncodeS(&apdu, false, IncludeLe ? 0x100 : 0x00, data, &datalen)) { + PrintAndLogEx(ERR, "APDU encoding error."); + return 201; + } if (APDULogging) - PrintAndLogEx(SUCCESS, ">>>> %s", sprint_hex(data, (IncludeLe ? 6 : 5) + apdu.Lc)); + PrintAndLogEx(SUCCESS, ">>>> %s", sprint_hex(data, datalen)); switch (channel) { case ECC_CONTACTLESS: - // 6 byes + data = INS + CLA + P1 + P2 + Lc + + Le(?IncludeLe) - res = ExchangeAPDU14a(data, (IncludeLe ? 6 : 5) + apdu.Lc, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen); + res = ExchangeAPDU14a(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen); if (res) { return res; } break; case ECC_CONTACT: if (IfPm3Smartcard()) - res = ExchangeAPDUSC(data, (IncludeLe ? 6 : 5) + apdu.Lc, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen); + res = ExchangeAPDUSC(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen); else res = 1; if (res) { @@ -336,7 +337,7 @@ static int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool Lea } int EMVExchange(EMVCommandChannel channel, bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { - return EMVExchangeEx(channel, false, LeaveFieldON, apdu, (channel == ECC_CONTACTLESS), Result, MaxResultLen, ResultLen, sw, tlv); + return EMVExchangeEx(channel, false, LeaveFieldON, apdu, false, Result, MaxResultLen, ResultLen, sw, tlv); } int EMVSelect(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *AID, size_t AIDLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { @@ -511,7 +512,7 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO PrintAndLogEx(WARNING, "%s ERROR: Can't get TLV from response.", PSE_or_PPSE); } } else { - PrintAndLogEx(WARNING, "%s ERROR: Can't select PPSE AID. Error: %d", PSE_or_PPSE, res); + PrintAndLogEx(ERR, "%s ERROR: Can't select PPSE AID. Error: %d", PSE_or_PPSE, res); } if (!LeaveFieldON) @@ -531,14 +532,17 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, int retrycnt = 0; for (int i = 0; i < AIDlistLen; i ++) { param_gethex_to_eol(AIDlist[i].aid, 0, aidbuf, sizeof(aidbuf), &aidlen); - res = EMVSelect(channel, (i == 0) ? ActivateField : false, (i == AIDlistLen - 1) ? LeaveFieldON : true, aidbuf, aidlen, data, sizeof(data), &datalen, &sw, tlv); + res = EMVSelect(channel, (i == 0) ? ActivateField : false, true, aidbuf, aidlen, data, sizeof(data), &datalen, &sw, tlv); // retry if error and not returned sw error if (res && res != 5) { if (++retrycnt < 3) { i--; } else { - // (1) - card select error, proxmark error OR (200) - result length = 0 - if (res == 1 || res == 200) { + // (1) - card select error, (4) reply timeout, (200) - result length = 0 + if (res == 1 || res == 4 ||res == 200) { + if (!LeaveFieldON) + DropFieldEx(channel); + PrintAndLogEx(WARNING, "Exit..."); return 1; } @@ -562,6 +566,9 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, } } + if (!LeaveFieldON) + DropFieldEx(channel); + return 0; } @@ -609,9 +616,9 @@ int EMVGPO(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *PDOL, size_t P } int EMVReadRecord(EMVCommandChannel channel, bool LeaveFieldON, uint8_t SFI, uint8_t SFIrec, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { - int res = EMVExchange(channel, LeaveFieldON, (sAPDU) {0x00, 0xb2, SFIrec, (SFI << 3) | 0x04, 0, NULL}, Result, MaxResultLen, ResultLen, sw, tlv); - if (*sw == 0x6700) { - PrintAndLogEx(INFO, ">>> trying to reissue command withouth Le..."); + int res = EMVExchangeEx(channel, false, LeaveFieldON, (sAPDU) {0x00, 0xb2, SFIrec, (SFI << 3) | 0x04, 0, NULL}, true, Result, MaxResultLen, ResultLen, sw, tlv); + if (*sw == 0x6700 || *sw == 0x6f00) { + PrintAndLogEx(INFO, ">>> trying to reissue command without Le..."); res = EMVExchangeEx(channel, false, LeaveFieldON, (sAPDU) {0x00, 0xb2, SFIrec, (SFI << 3) | 0x04, 0, NULL}, false, Result, MaxResultLen, ResultLen, sw, tlv); } return res; @@ -622,9 +629,9 @@ int EMVAC(EMVCommandChannel channel, bool LeaveFieldON, uint8_t RefControl, uint } int EMVGenerateChallenge(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) { - int res = EMVExchange(channel, LeaveFieldON, (sAPDU) {0x00, 0x84, 0x00, 0x00, 0x00, NULL}, Result, MaxResultLen, ResultLen, sw, tlv); - if (*sw == 0x6700) { - PrintAndLogEx(INFO, ">>> trying to reissue command withouth Le..."); + int res = EMVExchangeEx(channel, false, LeaveFieldON, (sAPDU) {0x00, 0x84, 0x00, 0x00, 0x00, NULL}, true, Result, MaxResultLen, ResultLen, sw, tlv); + if (*sw == 0x6700 || *sw == 0x6f00) { + PrintAndLogEx(INFO, ">>> trying to reissue command without Le..."); res = EMVExchangeEx(channel, false, LeaveFieldON, (sAPDU) {0x00, 0x84, 0x00, 0x00, 0x00, NULL}, false, Result, MaxResultLen, ResultLen, sw, tlv); } return res; @@ -654,14 +661,14 @@ int trSDA(struct tlvdb *tlv) { struct emv_pk *pk = get_ca_pk(tlv); if (!pk) { - PrintAndLogEx(WARNING, "Error: Key not found. Exit."); + PrintAndLogEx(ERR, "Error: Key not found. Exit."); return 2; } struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv); if (!issuer_pk) { emv_pk_free(pk); - PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit."); return 2; } @@ -693,7 +700,7 @@ int trSDA(struct tlvdb *tlv) { } else { emv_pk_free(issuer_pk); emv_pk_free(pk); - PrintAndLogEx(WARNING, "SSAD verify error"); + PrintAndLogEx(ERR, "SSAD verify error"); return 4; } @@ -712,21 +719,21 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct emv_pk *pk = get_ca_pk(tlv); if (!pk) { - PrintAndLogEx(WARNING, "Error: Key not found. Exit."); + PrintAndLogEx(ERR, "Error: Key not found. Exit."); return 2; } const struct tlv *sda_tlv = tlvdb_get(tlv, 0x21, NULL); /* if (!sda_tlv || sda_tlv->len < 1) { it may be 0!!!! emv_pk_free(pk); - PrintAndLogEx(WARNING, "Error: Can't find input list for Offline Data Authentication. Exit."); + PrintAndLogEx(ERR, "Error: Can't find input list for Offline Data Authentication. Exit."); return 3; } */ struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv); if (!issuer_pk) { emv_pk_free(pk); - PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit."); return 2; } PrintAndLogEx(SUCCESS, "Issuer PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n", @@ -745,7 +752,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { if (!icc_pk) { emv_pk_free(pk); emv_pk_free(issuer_pk); - PrintAndLogEx(WARNING, "Error: ICC certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: ICC certificate not found. Exit."); return 2; } PrintAndLogEx(SUCCESS, "ICC PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n", @@ -790,7 +797,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { const struct tlvdb *atc_db = emv_pki_recover_atc_ex(icc_pk, tlv, true); if (!atc_db) { - PrintAndLogEx(WARNING, "Error: Can't recover IDN (ICC Dynamic Number)"); + PrintAndLogEx(ERR, "Error: Can't recover IDN (ICC Dynamic Number)"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); @@ -823,7 +830,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { PrintAndLogEx(NORMAL, "SDAD verified OK. (Data Authentication Code: %02hhx:%02hhx)\n", dac_tlv->value[0], dac_tlv->value[1]); tlvdb_add(tlv, dac_db); } else { - PrintAndLogEx(WARNING, "Error: SSAD verify error"); + PrintAndLogEx(ERR, "Error: SSAD verify error"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); @@ -839,7 +846,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct tlv *ddol_data_tlv = dol_process(ddol_tlv, tlv, 0); if (!ddol_data_tlv) { - PrintAndLogEx(WARNING, "Error: Can't create DDOL TLV"); + PrintAndLogEx(ERR, "Error: Can't create DDOL TLV"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); @@ -851,7 +858,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { PrintAndLogEx(NORMAL, "\n* Internal Authenticate"); int res = EMVInternalAuthenticate(channel, true, (uint8_t *)ddol_data_tlv->value, ddol_data_tlv->len, buf, sizeof(buf), &len, &sw, NULL); if (res) { - PrintAndLogEx(WARNING, "Internal Authenticate error(%d): %4x. Exit...", res, sw); + PrintAndLogEx(ERR, "Internal Authenticate error(%d): %4x. Exit...", res, sw); free(ddol_data_tlv); emv_pk_free(pk); emv_pk_free(issuer_pk); @@ -862,7 +869,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct tlvdb *dda_db = NULL; if (buf[0] == 0x80) { if (len < 3) { - PrintAndLogEx(WARNING, "Error: Internal Authenticate format1 parsing error. length=%d", len); + PrintAndLogEx(WARNING, "Warning: Internal Authenticate format1 parsing error. length=%d", len); } else { // parse response 0x80 struct tlvdb *t80 = tlvdb_parse_multi(buf, len); @@ -882,7 +889,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { } else { dda_db = tlvdb_parse_multi(buf, len); if (!dda_db) { - PrintAndLogEx(WARNING, "Error: Can't parse Internal Authenticate result as TLV"); + PrintAndLogEx(ERR, "Error: Can't parse Internal Authenticate result as TLV"); free(ddol_data_tlv); emv_pk_free(pk); emv_pk_free(issuer_pk); @@ -898,7 +905,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) { struct tlvdb *idn_db = emv_pki_recover_idn_ex(icc_pk, dda_db, ddol_data_tlv, true); free(ddol_data_tlv); if (!idn_db) { - PrintAndLogEx(WARNING, "Error: Can't recover IDN (ICC Dynamic Number)"); + PrintAndLogEx(ERR, "Error: Can't recover IDN (ICC Dynamic Number)"); tlvdb_free(dda_db); emv_pk_free(pk); emv_pk_free(issuer_pk); @@ -935,20 +942,20 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st struct emv_pk *pk = get_ca_pk(tlv); if (!pk) { - PrintAndLogEx(WARNING, "Error: Key not found. Exit."); + PrintAndLogEx(ERR, "Error: Key not found. Exit."); return 2; } const struct tlv *sda_tlv = tlvdb_get(tlv, 0x21, NULL); if (!sda_tlv || sda_tlv->len < 1) { - PrintAndLogEx(WARNING, "Error: Can't find input list for Offline Data Authentication. Exit."); + PrintAndLogEx(ERR, "Error: Can't find input list for Offline Data Authentication. Exit."); emv_pk_free(pk); return 3; } struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv); if (!issuer_pk) { - PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit."); emv_pk_free(pk); return 2; } @@ -966,7 +973,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st struct emv_pk *icc_pk = emv_pki_recover_icc_cert(issuer_pk, tlv, sda_tlv); if (!icc_pk) { - PrintAndLogEx(WARNING, "Error: ICC certificate not found. Exit."); + PrintAndLogEx(ERR, "Error: ICC certificate not found. Exit."); emv_pk_free(pk); emv_pk_free(issuer_pk); return 2; @@ -989,7 +996,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st PrintAndLogEx(NORMAL, "SSAD verified OK. (%02hhx:%02hhx)", dac_tlv->value[0], dac_tlv->value[1]); tlvdb_add(tlv, dac_db); } else { - PrintAndLogEx(WARNING, "Error: SSAD verify error"); + PrintAndLogEx(ERR, "Error: SSAD verify error"); emv_pk_free(pk); emv_pk_free(issuer_pk); emv_pk_free(icc_pk); diff --git a/client/emv/emvcore.h b/client/emv/emvcore.h index 219c3f9b5..3faae283d 100644 --- a/client/emv/emvcore.h +++ b/client/emv/emvcore.h @@ -45,15 +45,6 @@ enum TransactionType { }; extern const char *TransactionTypeStr[]; -typedef struct { - uint8_t CLA; - uint8_t INS; - uint8_t P1; - uint8_t P2; - uint8_t Lc; - uint8_t *data; -} sAPDU; - enum CardPSVendor { CV_NA, CV_VISA, diff --git a/client/flash.c b/client/flash.c index 891efaeb3..e41b47fb0 100644 --- a/client/flash.c +++ b/client/flash.c @@ -173,6 +173,10 @@ static int check_segs(flash_file_t *ctx, int can_write_bl) { PrintAndLogEx(ERR, "Attempted to write bootloader but bootloader writes are not enabled"); return -1; } + if (can_write_bl && seg->start < BOOTLOADER_END && (seg->start + seg->length > BOOTLOADER_END)) { + PrintAndLogEx(ERR, "Error: Segment is outside of bootloader bounds"); + return -1; + } } return 0; } @@ -188,7 +192,6 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl) { fd = fopen(name, "rb"); if (!fd) { PrintAndLogEx(ERR, _RED_("Could not open file") "%s >>> ", name); - perror(NULL); goto fail; } @@ -343,7 +346,7 @@ static int wait_for_ack(PacketResponseNG *ack) { } // Go into flashing mode -int flash_start_flashing(int enable_bl_writes, char *serial_port_name) { +int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *chipinfo) { uint32_t state; if (enter_bootloader(serial_port_name) < 0) @@ -352,6 +355,13 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name) { if (get_proxmark_state(&state) < 0) return -1; + if (state & DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO) { + SendCommandBL(CMD_CHIP_INFO, 0, 0, 0, NULL, 0); + PacketResponseNG resp; + WaitForResponse(CMD_CHIP_INFO, &resp); + *chipinfo = resp.oldarg[0]; + } + if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) { // This command is stupid. Why the heck does it care which area we're // flashing, as long as it's not the bootloader area? The mind boggles. diff --git a/client/flash.h b/client/flash.h index a230715d1..7140de673 100644 --- a/client/flash.h +++ b/client/flash.h @@ -38,7 +38,7 @@ typedef struct { } flash_file_t; int flash_load(flash_file_t *ctx, const char *name, int can_write_bl); -int flash_start_flashing(int enable_bl_writes, char *serial_port_name); +int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *chipid); int flash_write(flash_file_t *ctx); void flash_free(flash_file_t *ctx); int flash_stop_flashing(void); diff --git a/client/flasher.c b/client/flasher.c index 88c154605..94e2ef6ba 100644 --- a/client/flasher.c +++ b/client/flasher.c @@ -35,6 +35,42 @@ static void usage(char *argv0) { #endif } +int chipid_to_mem_avail(uint32_t iChipID) { + int mem_avail = 0; + switch ((iChipID & 0xF00) >> 8) { + case 0: + mem_avail = 0; + break; + case 1: + mem_avail = 8; + break; + case 2: + mem_avail = 16; + break; + case 3: + mem_avail = 32; + break; + case 5: + mem_avail = 64; + break; + case 7: + mem_avail = 128; + break; + case 9: + mem_avail = 256; + break; + case 10: + mem_avail = 512; + break; + case 12: + mem_avail = 1024; + break; + case 14: + mem_avail = 2048; + } + return mem_avail; +} + int main(int argc, char **argv) { int can_write_bl = 0; int num_files = 0; @@ -84,12 +120,21 @@ int main(int argc, char **argv) { return -1; } - res = flash_start_flashing(can_write_bl, serial_port_name); + uint32_t chipid = 0; + res = flash_start_flashing(can_write_bl, serial_port_name, &chipid); if (res < 0) return -1; + int mem_avail = chipid_to_mem_avail(chipid); + if (mem_avail != 0) { + PrintAndLogEx(NORMAL, "Available memory on this board: %uK bytes\n", mem_avail); + } else { + PrintAndLogEx(NORMAL, "Available memory on this board: "_RED_("UNKNOWN")"\n"); + PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new CHIP_INFO command")); + PrintAndLogEx(ERR, _RED_("It is recommended that you update your bootloader") "\n"); + } PrintAndLogEx(SUCCESS, "\n" _BLUE_("Flashing...")); - +// TODO check if enough space on Pm3 mem to write the given files for (int i = 0; i < num_files; i++) { res = flash_write(&files[i]); if (res < 0) diff --git a/client/fpga_compress.c b/client/fpga_compress.c index 7cd4652e1..a030afe81 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -375,7 +375,7 @@ static void print_version_info_preamble(FILE *outfile, int num_infiles) { fprintf(outfile, "\n"); fprintf(outfile, "\n"); fprintf(outfile, "const int fpga_bitstream_num = %d;\n", num_infiles); - fprintf(outfile, "const char* const fpga_version_information[%d] = {\n", num_infiles); + fprintf(outfile, "const char *const fpga_version_information[%d] = {\n", num_infiles); } static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int num_infiles, FILE *outfile) { @@ -386,7 +386,7 @@ static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int for (int i = 0; i < num_infiles; i++) { FpgaGatherVersion(infile[i], infile_names[i], version_string, sizeof(version_string)); - fprintf(outfile, "\t\" %s\"", version_string); + fprintf(outfile, " \" %s\"", version_string); if (i != num_infiles - 1) { fprintf(outfile, ","); } diff --git a/client/jansson/Makefile b/client/jansson/Makefile index 323d26216..e06ffbc76 100644 --- a/client/jansson/Makefile +++ b/client/jansson/Makefile @@ -36,15 +36,23 @@ CFILES = $(filter %.c, $(libjansson_la_SOURCES)) CMDOBJS = $(CFILES:%.c=%.o) CLEAN = $(CMDOBJS) +platform = $(shell uname) + CC= gcc -CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function -Wno-format-truncation +CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function + LDFLAGS= $(SYSLDFLAGS) $(libjansson_la_LDFLAGS) LIBS= $(SYSLIBS) $(MYLIBS) DEFAULT_INCLUDES = -I. DEFS = -DHAVE_STDINT_H +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rcs +RANLIB= /usr/bin/ranlib +else AR= ar rcs RANLIB= ranlib +endif RM= rm -f TST= echo diff --git a/client/jansson/load.c b/client/jansson/load.c index 43e035cb2..4e05dc87b 100644 --- a/client/jansson/load.c +++ b/client/jansson/load.c @@ -111,7 +111,11 @@ static void error_set(json_error_t *error, const lex_t *lex, if (saved_text && saved_text[0]) { if (lex->saved_text.length <= 20) { - snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", msg_text, saved_text); + int ret = snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'", msg_text, saved_text); + if (ret < 0) { + jsonp_error_set(error, line, col, pos, code, "%s", "internal snprint error"); + return; + } msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; result = msg_with_context; } @@ -124,7 +128,11 @@ static void error_set(json_error_t *error, const lex_t *lex, /* No context for UTF-8 decoding errors */ result = msg_text; } else { - snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file", msg_text); + int ret = snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file", msg_text); + if (ret < 0) { + jsonp_error_set(error, line, col, pos, code, "%s", "internal snprint error"); + return; + } msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; result = msg_with_context; } diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index a461557b1..5b019d8e0 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -517,7 +517,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { first16bytes[i] = keytable[i] & 0xFF; if (!(keytable[i] & CRACKED)) - PrintAndLogDevice(WARNING, "error, we are missing byte %d, custom key calculation will fail...", i); + PrintAndLogDevice(WARNING, "Warning: we are missing byte %d, custom key calculation will fail...", i); } errors += calculateMasterKey(first16bytes, NULL); return errors; @@ -541,7 +541,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { fseek(f, 0, SEEK_SET); if (fsize <= 0) { - PrintAndLogDevice(WARNING, "Error, when getting filesize"); + PrintAndLogDevice(ERR, "Error, when getting filesize"); fclose(f); return 1; } @@ -557,7 +557,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { fclose(f); if (bytes_read < fsize) { - PrintAndLogDevice(WARNING, "Error, could only read %d bytes (should be %d)", bytes_read, fsize); + PrintAndLogDevice(WARNING, "Warning: could only read %d bytes (should be %d)", bytes_read, fsize); } uint8_t res = bruteforceDump(dump, fsize, keytable); @@ -612,7 +612,7 @@ static int _testBruteforce() { } else if (fileExists("client/loclass/iclass_dump.bin")) { errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable); } else { - PrintAndLogDevice(WARNING, "Error: The file iclass_dump.bin was not found!"); + PrintAndLogDevice(ERR, "Error: The file iclass_dump.bin was not found!"); } } return errors; @@ -627,14 +627,14 @@ static int _test_iclass_key_permutation() { permutekey_rev(testcase_output, testcase_output_rev); if (memcmp(testcase_output, testcase_output_correct, 8) != 0) { - PrintAndLogDevice(WARNING, "Error with iclass key permute!"); + PrintAndLogDevice(ERR, "Error with iclass key permute!"); printarr("testcase_output", testcase_output, 8); printarr("testcase_output_correct", testcase_output_correct, 8); return 1; } if (memcmp(testcase, testcase_output_rev, 8) != 0) { - PrintAndLogDevice(WARNING, "Error with reverse iclass key permute"); + PrintAndLogDevice(ERR, "Error with reverse iclass key permute"); printarr("testcase", testcase, 8); printarr("testcase_output_rev", testcase_output_rev, 8); return 1; @@ -651,7 +651,7 @@ static int _testHash1() { hash1(csn, k); if (memcmp(k, expected, 8) != 0) { - PrintAndLogDevice(WARNING, "Error with hash1!"); + PrintAndLogDevice(ERR, "Error with hash1!"); printarr("calculated", k, 8); printarr("expected", expected, 8); return 1; diff --git a/client/lualibs/emulator.lua b/client/lualibs/emulator.lua index 843d8f9f1..af92d5cf8 100644 --- a/client/lualibs/emulator.lua +++ b/client/lualibs/emulator.lua @@ -14,7 +14,7 @@ function Emulator:set_mem (data, clear_first) -- Clear out the emulator memory first local memclrCmd = Command:newMIX{cmd = cmds.CMD_MIFARE_EML_MEMCLR} - local _, err = memclrCmd.sendMIX() + local _, err = memclrCmd:sendMIX() if err then print('Failed to clear emulator memory:', err) return false @@ -36,7 +36,7 @@ function Emulator:set_mem (data, clear_first) arg2 = self.BLOCK_COUNT} -- Send command and wait for response - local _, err = memsetCmd.sendMIX() + local _, err = memsetCmd:sendMIX() if err then print('Failed setting memory', err) return false @@ -62,7 +62,7 @@ function Emulator:get_mem (size) arg2 = MAX_BLOCKS, arg3 = 0} - local response, err = getmemCmd.sendMIX() + local response, err = getmemCmd:sendMIX() if err then print('Failed getting memory:', err) return false diff --git a/client/lualibs/hf_reader.lua b/client/lualibs/hf_reader.lua index b99b521da..ba7e3a17c 100644 --- a/client/lualibs/hf_reader.lua +++ b/client/lualibs/hf_reader.lua @@ -15,10 +15,10 @@ local reader15693 = require('read15') -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitForTag() - print("Waiting for card... press any key to quit") + print("Waiting for card... press Enter to quit") local readers = {reader14443A, reader14443B, reader15693} local i = 0; - while not core.ukbhit() do + while not core.kbd_enter_pressed() do i = (i % 3) +1 r = readers[i] print("Reading with ",i) diff --git a/client/lualibs/read14a.lua b/client/lualibs/read14a.lua index 5cdf5a2e4..3bf243235 100644 --- a/client/lualibs/read14a.lua +++ b/client/lualibs/read14a.lua @@ -60,7 +60,7 @@ local function parse14443a(data) uint8_t sak; uint8_t ats_len; uint8_t ats[256]; - } __attribute__((__packed__)) iso14a_card_select_t; + } PACKED iso14a_card_select_t; --]] local count, uid, uidlen, atqa, sak, ats_len, ats = bin.unpack('H10CH2CCH', data) @@ -121,8 +121,8 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitFor14443a() - print('Waiting for card... press any key to quit') - while not core.ukbhit() do + print('Waiting for card... press Enter to quit') + while not core.kbd_enter_pressed() do res, err = read14443a() if res then return res end -- err means that there was no response from card diff --git a/client/lualibs/read14b.lua b/client/lualibs/read14b.lua index 3102acb04..67d2bd469 100644 --- a/client/lualibs/read14b.lua +++ b/client/lualibs/read14b.lua @@ -39,7 +39,7 @@ local function parse1443b(data) uint8_t atqb[7]; uint8_t chipid; uint8_t cid; - } __attribute__((__packed__)) iso14b_card_select_t; + } PACKED iso14b_card_select_t; --]] @@ -99,8 +99,8 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitFor14443b() - print('Waiting for card... press any key to quit') - while not core.ukbhit() do + print('Waiting for card... press Enter to quit') + while not core.kbd_enter_pressed() do res, err = read14443b(false) if res then return res end -- err means that there was no response from card @@ -112,7 +112,7 @@ end -- turns on the HF field. local function connect14443b() local c = Command:newMIX{cmd = cmds.CMD_ISO_14443B_COMMAND, arg1 = ISO14B_COMMAND.ISO14B_CONNECT} - return c.sendMIX(true) + return c:sendMIX(true) end --- -- Sends an instruction to do nothing, only disconnect @@ -120,7 +120,7 @@ local function disconnect14443b() local c = Command:newMIX{cmd = cmds.CMD_ISO_14443B_COMMAND, arg1 = ISO14B_COMMAND.ISO14B_DISCONNECT} -- We can ignore the response here, no ACK is returned for this command -- Check /armsrc/iso14443b.c, ReaderIso14443b() for details - return c.sendMIX(true) + return c:sendMIX(true) end local library = { diff --git a/client/lualibs/read15.lua b/client/lualibs/read15.lua index 88cce5484..a70641186 100644 --- a/client/lualibs/read15.lua +++ b/client/lualibs/read15.lua @@ -133,8 +133,8 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitFor15693() - print('Waiting for card... press any key to quit') - while not core.ukbhit() do + print('Waiting for card... press Enter to quit') + while not core.kbd_enter_pressed() do res, err = read15693() if res then return res end -- err means that there was no response from card @@ -147,7 +147,7 @@ local function disconnect15693() local c = Command:newMIX{cmd = cmds.CMD_ISO_15693_COMMAND} -- We can ignore the response here, no ACK is returned for this command -- Check /armsrc/iso14443a.c, ReaderIso14443a() for details - return c.sendMIX(true) + return c:sendMIX(true) end local library = { diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 893664e86..100b595ce 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -28,9 +28,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { SendCommandMIX(CMD_READER_MIFARE, arg0, blockno, key_type, NULL, 0); //flush queue - while (ukbhit()) { - int gc = getchar(); - (void)gc; + while (kbd_enter_pressed()) { return PM3_EOPABORTED; } @@ -38,9 +36,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { return PM3_EOPABORTED; } @@ -918,7 +914,7 @@ int detect_classic_prng(void) { // if select tag failed. if (resp.oldarg[0] == 0) { - PrintAndLogEx(WARNING, "error: selecting tag failed, can't detect prng\n"); + PrintAndLogEx(ERR, "error: selecting tag failed, can't detect prng\n"); return PM3_ERFTRANS; } if (!WaitForResponseTimeout(CMD_ACK, &respA, 2500)) { @@ -928,7 +924,7 @@ int detect_classic_prng(void) { // check respA if (respA.oldarg[0] != 4) { - PrintAndLogEx(WARNING, "PRNG data error: Wrong length: %d", respA.oldarg[0]); + PrintAndLogEx(ERR, "PRNG data error: Wrong length: %d", respA.oldarg[0]); return PM3_ESOFT; } @@ -955,9 +951,7 @@ int detect_classic_nackbug(bool verbose) { while (true) { printf("."); fflush(stdout); - if (ukbhit()) { - int gc = getchar(); - (void)gc; + if (kbd_enter_pressed()) { return PM3_EOPABORTED; } @@ -1002,7 +996,7 @@ int detect_classic_nackbug(bool verbose) { PrintAndLogEx(SUCCESS, "No NACK bug detected"); return PM3_SUCCESS; default : - PrintAndLogEx(WARNING, "errorcode from device [%i]", ok); + PrintAndLogEx(ERR, "errorcode from device [%i]", ok); return PM3_EUNDEF; } break; diff --git a/client/proxguiqt.h b/client/proxguiqt.h index 458a70058..e50bfe073 100644 --- a/client/proxguiqt.h +++ b/client/proxguiqt.h @@ -97,8 +97,8 @@ class WorkerThread : public QThread { ~WorkerThread(); void run(); private: - char *script_cmds_file = NULL; - char *script_cmd = NULL; + char *script_cmds_file; + char *script_cmd; }; class ProxGuiQT : public QObject { diff --git a/client/proxmark3.c b/client/proxmark3.c index 879b3630b..480f39fa3 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -388,7 +388,7 @@ int main(int argc, char *argv[]) { show_help(false, exec_name); return 1; } - uint32_t tmpspeed = strtoul(argv[i + 1], NULL, 10); + uint64_t tmpspeed = strtoul(argv[i + 1], NULL, 10); if ((tmpspeed == ULONG_MAX) || (tmpspeed == 0)) { PrintAndLogEx(ERR, _RED_("ERROR:") "invalid baudrate: -b " _YELLOW_("%s") "\n", argv[i + 1]); return 1; diff --git a/client/scripting.c b/client/scripting.c index cfa361256..572899e2d 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -411,8 +411,8 @@ static int l_foobar(lua_State *L) { * @param L * @return boolean, true if kbhit, false otherwise. */ -static int l_ukbhit(lua_State *L) { - lua_pushboolean(L, ukbhit() ? true : false); +static int l_kbd_enter_pressed(lua_State *L) { + lua_pushboolean(L, kbd_enter_pressed() ? true : false); return 1; } @@ -1064,7 +1064,7 @@ int set_pm3_libraries(lua_State *L) { {"WaitForResponseTimeout", l_WaitForResponseTimeout}, {"mfDarkside", l_mfDarkside}, {"foobar", l_foobar}, - {"ukbhit", l_ukbhit}, + {"kbd_enter_pressed", l_kbd_enter_pressed}, {"clearCommandBuffer", l_clearCommandBuffer}, {"console", l_CmdConsole}, {"iso15693_crc", l_iso15693_crc}, diff --git a/client/scripts/amiibo.lua b/client/scripts/amiibo.lua index 3d8e026dd..73366de02 100644 --- a/client/scripts/amiibo.lua +++ b/client/scripts/amiibo.lua @@ -21,7 +21,7 @@ local function nfc_read_amiibo () arg2 = 135 } - local result, err = command.sendMIX() + local result, err = command:sendMIX() if result then -- Do Mifare Ultralight read local count, cmd, arg0, data_len, offset = bin.unpack('LLLL', result) @@ -95,7 +95,7 @@ local function emulate_amiibo (amiibo_data) arg2 = uid_first, arg3 = uid_second } - local _, err = simCmd.sendMIX() + local _, err = simCmd:sendMIX() if err then print('Failed to start simulator', err) return diff --git a/client/scripts/calypso.lua b/client/scripts/calypso.lua index 696f08e8b..de512c5c8 100644 --- a/client/scripts/calypso.lua +++ b/client/scripts/calypso.lua @@ -68,7 +68,7 @@ local function help() print(desc) print('Example usage') print(example) - print(usage)) + print(usage) end -- -- helper function, give current count of items in lua-table. diff --git a/client/scripts/didump.lua b/client/scripts/didump.lua index b0cc964ee..d5ac6f873 100644 --- a/client/scripts/didump.lua +++ b/client/scripts/didump.lua @@ -488,7 +488,7 @@ local function readtag(mfkey, aeskey ) for blockNo = 0, numBlocks-1 do - if core.ukbhit() then + if core.kbd_enter_pressed() then print("[fail] aborted by user") return nil end diff --git a/client/scripts/formatMifare.lua b/client/scripts/formatMifare.lua index e200d92cb..7c6fd92c0 100644 --- a/client/scripts/formatMifare.lua +++ b/client/scripts/formatMifare.lua @@ -206,7 +206,7 @@ local function main(args) if x then core.console(cmd) end end - if core.ukbhit() then + if core.kbd_enter_pressed() then print('aborted by user') break end diff --git a/client/scripts/lf_bulk.lua b/client/scripts/lf_bulk.lua index 5e8562ae7..54c60fb89 100644 --- a/client/scripts/lf_bulk.lua +++ b/client/scripts/lf_bulk.lua @@ -186,7 +186,7 @@ local function main(args) for cardnum = baseid, endid do local card = cardHex(cardnum, facility) print('Press enter to program card '..cardnum..':'..facility..' (hex: '..card..')') - --This would be better with 'press any key', but we'll take what we can get. + --This would be better with 'press Enter', but we'll take what we can get. io.read() core.console( ('lf hid clone %s'):format(card) ) end diff --git a/client/scripts/mfkeys.lua b/client/scripts/mfkeys.lua index 7d4a726d6..65f50eb9c 100644 --- a/client/scripts/mfkeys.lua +++ b/client/scripts/mfkeys.lua @@ -208,7 +208,7 @@ local function perform_check(numsectors) for sector = 0, #keys do -- Check if user aborted - if core.ukbhit() then + if core.kbd_enter_pressed() then print('Aborted by user') break end diff --git a/client/scripts/mifare_autopwn.lua b/client/scripts/mifare_autopwn.lua index a9859ac25..7a04cd641 100644 --- a/client/scripts/mifare_autopwn.lua +++ b/client/scripts/mifare_autopwn.lua @@ -70,7 +70,7 @@ end -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function wait_for_mifare() - while not core.ukbhit() do + while not core.kbd_enter_pressed() do res, err = lib14a.read() if res then return res end -- err means that there was no response from card @@ -161,7 +161,7 @@ local function main(args) while not _exit do if print_message then - print('Waiting for card or press any key to stop') + print('Waiting for card or press Enter to stop') print_message = false end res, err = wait_for_mifare() diff --git a/client/scripts/mifareplus.lua b/client/scripts/mifareplus.lua index 02e1e6c76..a81be26d8 100644 --- a/client/scripts/mifareplus.lua +++ b/client/scripts/mifareplus.lua @@ -80,7 +80,7 @@ local function sendRaw(rawdata, crc, power) data = rawdata } local ignore_response = false - local result, err = command.sendMIX(ignore_response) + local result, err = command:sendMIX(ignore_response) if result then --unpack the first 4 parts of the result as longs, and the last as an extremely long string to later be cut down based on arg1, the number of bytes returned local count,cmd,arg1,arg2,arg3,data = bin.unpack('LLLLH512',result) diff --git a/client/scripts/read_pwd_mem.lua b/client/scripts/read_pwd_mem.lua index 4aa2e6299..5f8edcc74 100644 --- a/client/scripts/read_pwd_mem.lua +++ b/client/scripts/read_pwd_mem.lua @@ -81,18 +81,19 @@ local function main(args) if o == 'o' then offset = tonumber(a) end -- num of bytes to read - if o == 'l' then length = tonumber(a) end + if o == 'l' then + length = tonumber(a) + if length < 0 or length > 256 then + return oops('Error: Length is not valid. Must be less than 256') + end + end -- keylength if o == 'k' then keylength = tonumber(a); usedkey = true end - if o == 'm' then keylength =6; usedkey = true; offset = 0x3F000-0x6000; end - if o == 't' then keylength =4; usedkey = true; offset = 0x3F000-0x3000; end - if o == 'i' then keylength =8; usedkey = true; offset = 0x3F000-0x4000; end - end - - if length < 0 or length > 256 then - return oops('Error: Length is not valid. Must be less than 256') + if o == 'm' then keylength = 6; usedkey = true; length = 8192; offset = 0x3F000-0x6000; end + if o == 't' then keylength = 4; usedkey = true; length = 4096; offset = 0x3F000-0x3000; end + if o == 'i' then keylength = 8; usedkey = true; length = 4096; offset = 0x3F000-0x4000; end end if (offset < 0) or (offset % 4 ~= 0) then @@ -102,9 +103,7 @@ local function main(args) print('Memory offset', offset) print('Length ', length) print('Key length ', keylength) - print( string.rep('--',20) ) - - if usedkey then length = 4096 end + print( string.rep('--', 20) ) data, err = core.GetFromFlashMem(offset, length) if err then return oops(err) end @@ -116,7 +115,6 @@ local function main(args) local kl = keylength * 2 for i = 1, keys do - key = string.sub(s, (i - 1) * kl + 1, i * kl ) print(string.format('[%02d] %s',i, key)) end diff --git a/client/scripts/tnp3dump.lua b/client/scripts/tnp3dump.lua index 00070eacc..0faadecaf 100644 --- a/client/scripts/tnp3dump.lua +++ b/client/scripts/tnp3dump.lua @@ -198,7 +198,7 @@ local function main(args) io.flush() - if core.ukbhit() then + if core.kbd_enter_pressed() then print("aborted by user") break end diff --git a/client/scripts/tracetest.lua b/client/scripts/tracetest.lua index e5943fd6a..44cd66b58 100644 --- a/client/scripts/tracetest.lua +++ b/client/scripts/tracetest.lua @@ -118,7 +118,7 @@ local function main(args) core.clearCommandBuffer() - if core.ukbhit() then + if core.kbd_enter_pressed() then print('aborted by user') break end diff --git a/client/tinycbor/Makefile b/client/tinycbor/Makefile index 8124196eb..af22846e9 100644 --- a/client/tinycbor/Makefile +++ b/client/tinycbor/Makefile @@ -19,14 +19,21 @@ CFILES = $(filter %.c, $(tinycbor_SOURCES)) CMDOBJS = $(CFILES:%.c=%.o) CLEAN = $(CMDOBJS) +platform = $(shell uname) + CC= gcc CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function LIBS= $(SYSLIBS) $(MYLIBS) DEFAULT_INCLUDES = -I. -I.. DEFS = -DHAVE_STDINT_H +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rcs +RANLIB= /usr/bin/ranlib +else AR= ar rcs RANLIB= ranlib +endif RM= rm -f TST= echo diff --git a/client/util.c b/client/util.c index 568a022f1..f6f89e0ff 100644 --- a/client/util.c +++ b/client/util.c @@ -26,38 +26,45 @@ uint8_t g_debugMode = 0; #define MAX_BIN_BREAK_LENGTH (3072+384+1) #ifndef _WIN32 -#include -#include #include -#include +#include -int ukbhit(void) { - int cnt = 0; - int error; - static struct termios Otty, Ntty; - - if (tcgetattr(STDIN_FILENO, &Otty) == -1) return -1; - - Ntty = Otty; - - Ntty.c_iflag = 0x0000; // input mode - Ntty.c_oflag = 0x0000; // output mode - Ntty.c_lflag &= ~ICANON; // control mode = raw - Ntty.c_cc[VMIN] = 1; // return if at least 1 character is in the queue - Ntty.c_cc[VTIME] = 0; // no timeout. Wait forever - - if (0 == (error = tcsetattr(STDIN_FILENO, TCSANOW, &Ntty))) { // set new attributes - error += ioctl(STDIN_FILENO, FIONREAD, &cnt); // get number of characters available - error += tcsetattr(STDIN_FILENO, TCSANOW, &Otty); // reset attributes +int kbd_enter_pressed(void) { + int flags; + if ((flags = fcntl(STDIN_FILENO, F_GETFL, 0)) < 0) { + PrintAndLogEx(ERR, "fcntl failed in kbd_enter_pressed"); + return -1; } - return (error == 0 ? cnt : -1); + //non-blocking + flags |= O_NONBLOCK; + if (fcntl(STDIN_FILENO, F_SETFL, flags) < 0) { + PrintAndLogEx(ERR, "fcntl failed in kbd_enter_pressed"); + return -1; + } + int c; + int ret = 0; + do { //get all available chars + c = getchar(); + ret |= c == '\n'; + } while (c != EOF); + //blocking + flags &= ~O_NONBLOCK; + if (fcntl(STDIN_FILENO, F_SETFL, flags) < 0) { + PrintAndLogEx(ERR, "fcntl failed in kbd_enter_pressed"); + return -1; + } + return ret; } #else #include -int ukbhit(void) { - return kbhit(); +int kbd_enter_pressed(void) { + int ret = 0; + while (kbhit()) { + ret |= getch() == '\r'; + } + return ret; } #endif @@ -170,8 +177,8 @@ bool CheckStringIsHEXValue(const char *value) { void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between, bool uppercase) { - if (buf == NULL ) return; - + if (buf == NULL) return; + char *tmp = (char *)buf; size_t i; memset(tmp, 0x00, hex_max_len); @@ -197,16 +204,16 @@ void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex // printing and converting functions void print_hex(const uint8_t *data, const size_t len) { - if (data == NULL || len == 0 ) return; - + if (data == NULL || len == 0) return; + for (size_t i = 0; i < len; i++) printf("%02x ", data[i]); printf("\n"); } void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) { - if (data == NULL || len == 0 ) return; - + if (data == NULL || len == 0) return; + int rownum = 0; printf("[%02d] | ", rownum); for (size_t i = 0; i < len; ++i) { diff --git a/client/util.h b/client/util.h index e194bb5be..3f677df7a 100644 --- a/client/util.h +++ b/client/util.h @@ -20,94 +20,12 @@ #include #include "ui.h" // PrintAndLog #include "commonutil.h" +#include "common.h" #ifdef ANDROID #include #endif -#ifndef ROTR -# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n)))) -#endif -#ifndef ROTL -# define ROTL(x,n) (((uintmax_t)(x) << (n)) | ((uintmax_t)(x) >> ((sizeof(x) * 8) - (n)))) -#endif - -#ifndef MIN -# define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif -#ifndef MAX -# define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif - -// endian change for 64bit -#ifdef __GNUC__ -#ifndef BSWAP_64 -#define BSWAP_64(x) __builtin_bswap64(x) -#endif -#else -#ifdef _MSC_VER -#ifndef BSWAP_64 -#define BSWAP_64(x) _byteswap_uint64(x) -#endif -#else -#ifndef BSWAP_64 -#define BSWAP_64(x) \ - (((uint64_t)(x) << 56) | \ - (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \ - (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \ - (((uint64_t)(x) << 8) & 0xff00000000ULL) | \ - (((uint64_t)(x) >> 8) & 0xff000000ULL) | \ - (((uint64_t)(x) >> 24) & 0xff0000ULL) | \ - (((uint64_t)(x) >> 40) & 0xff00ULL) | \ - ((uint64_t)(x) >> 56)) -#endif -#endif -#endif - -// endian change for 32bit -#ifdef __GNUC__ -#ifndef BSWAP_32 -#define BSWAP_32(x) __builtin_bswap32(x) -#endif -#else -#ifdef _MSC_VER -#ifndef BSWAP_32 -#define BSWAP_32(x) _byteswap_ulong(x) -#endif -#else -#ifndef BSWAP_32 -# define BSWAP_32(x) \ - ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ - (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) -#endif -#endif -#endif - -#define EVEN 0 -#define ODD 1 - -// Nibble logic -#ifndef NIBBLE_HIGH -# define NIBBLE_HIGH(b) ( (b & 0xF0) >> 4 ) -#endif -#ifndef NIBBLE_LOW -# define NIBBLE_LOW(b) ( b & 0x0F ) -#endif -#ifndef CRUMB -# define CRUMB(b,p) (((b & (0x3 << p) ) >> p ) & 0xF) -#endif -#ifndef SWAP_NIBBLE -# define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b)) -#endif - -// Binary Encoded Digit -#ifndef BCD2DEC -# define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10) -#endif -#ifndef DEC2BCD -# define DEC2BCD(dec) HornerScheme(dec, 10, 0x10) -#endif - // used for save/load files #ifndef FILE_PATH_SIZE # define FILE_PATH_SIZE 1000 @@ -129,7 +47,7 @@ uint8_t g_debugMode; -int ukbhit(void); +int kbd_enter_pressed(void); void AddLogLine(const char *fn, const char *data, const char *c); void AddLogHex(const char *fn, const char *extData, const uint8_t *data, const size_t len); void AddLogUint64(const char *fn, const char *data, const uint64_t value); diff --git a/common/Makefile.common b/common/Makefile.common index 132507547..282f242d9 100644 --- a/common/Makefile.common +++ b/common/Makefile.common @@ -43,15 +43,13 @@ TARFLAGS = -C .. -rvf # amount of shell command line parsing going on. echo "" on # Windows yields literal "", on Linux yields an empty line ifeq ($(shell echo ""),) - -# This is probably a proper system, so we can use uname -UNAME := $(shell uname) DELETE=rm -rf MOVE=mv COPY=cp PATHSEP=/ FLASH_TOOL=client/flasher -DETECTED_OS=$(UNAME) +# This is probably a proper system, so we can use uname +DETECTED_OS=$(platform) else # Assume that we are running on Windows. @@ -65,7 +63,7 @@ DETECTED_OS=Windows endif # Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory -VPATH = . ../common ../common/crapto1 ../common/polarssl ../fpga ../zlib ../armsrc/Standalone ../uart +VPATH = . ../common ../common/crapto1 ../common/mbedtls ../fpga ../zlib ../armsrc/Standalone ../uart INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h $(APP_INCLUDES) diff --git a/common/Makefile.hal b/common/Makefile.hal index ff3f83a4c..bf9231f5c 100644 --- a/common/Makefile.hal +++ b/common/Makefile.hal @@ -1,10 +1,14 @@ # Default platform if no platform specified PLATFORM?=PM3RDV4 -# Default standalone if no standalone specified -# (you can set explicitly STANDALONE= to disable standalone modes) -STANDALONE?=LF_SAMYRUN -define KNOWN_DEFINITIONS +# Standalone Mode info (path depends if make is called at top or from armsrc) +-include armsrc/Standalone/Makefile.hal +-include Standalone/Makefile.hal +ifndef DEFAULT_STANDALONE +$(error Could not find armsrc/Standalone/Makefile.hal) +endif + +define KNOWN_PLATFORM_DEFINITIONS Known definitions: @@ -30,39 +34,12 @@ Known definitions: | BTADDON | Proxmark3 rdv4 BT add-on | +----------------------------------------------------------+ -+==========================================================+ -| STANDALONE | DESCRIPTION | -+==========================================================+ -| | No standalone mode | -+----------------------------------------------------------+ -| LF_SAMYRUN (def)| HID26 read/clone/sim | -| | - Samy Kamkar | -+----------------------------------------------------------+ -| LF_ICERUN | standalone mode skeleton | -| | - iceman | -+----------------------------------------------------------+ -| LF_PROXBRUTE | HID ProxII bruteforce | -| | - Brad Antoniewicz | -+----------------------------------------------------------+ -| LF_HIDBRUTE | HID corporate 1000 bruteforce | -| | - Federico dotta & Maurizio Agazzini | -+----------------------------------------------------------+ -| HF_YOUNG | Mifare sniff/simulation | -| | - Craig Young | -+----------------------------------------------------------+ -| HF_MATTYRUN | Mifare sniff/clone | -| | - Matías A. Ré Medina | -+----------------------------------------------------------+ -| HF_COLIN | Mifare ultra fast sniff/sim/clone | -| | - Colin Brigato | -+----------------------------------------------------------+ -| HF_BOG | 14a sniff with ULC/ULEV1/NTAG auth | -| | storing in flashmem - Bogito | -+----------------------------------------------------------+ +endef +define HELP_DEFINITIONS Options to define platform, platform extras and/or standalone mode: (1) Run make with PLATFORM, PLATFORM_EXTRAS and/or STANDALONE as follows: -make PLATFORM=PM3EASY STANDALONE=HF_COLIN +make PLATFORM=PM3EASY STANDALONE=$(HELP_EXAMPLE_STANDALONE) (2) Save a file called Makefile.platform with contents: PLATFORM=PM3EASY @@ -71,11 +48,17 @@ or if you have a Proxmark 3 RDV4 with the BT add-on: PLATFORM=PM3RDV4 PLATFORM_EXTRAS=BTADDON -Default standalone mode is LF_SAMYRUN. +Default standalone mode is $(DEFAULT_STANDALONE). To disable standalone modes, set explicitly an empty STANDALONE: STANDALONE= endef +define KNOWN_DEFINITIONS +$(KNOWN_PLATFORM_DEFINITIONS) +$(KNOWN_STANDALONE_DEFINITIONS) +$(HELP_DEFINITIONS) +endef + PLTNAME = Unknown Platform ifeq ($(PLATFORM),PM3RDV4) @@ -131,13 +114,7 @@ PLATFORM_DEFS += \ -DWITH_HFSNIFF # Standalone mode -STANDALONE_MODES := LF_SAMYRUN LF_ICERUN LF_PROXBRUTE LF_HIDBRUTE -STANDALONE_MODES += HF_YOUNG HF_MATTYRUN HF_COLIN HF_BOG -ifneq ($(filter $(STANDALONE),$(STANDALONE_MODES)),) - PLATFORM_DEFS += -DWITH_STANDALONE_$(STANDALONE) -else ifneq ($(STANDALONE),) - $(error Invalid STANDALONE: $(STANDALONE). $(KNOWN_DEFINITIONS)) -endif +PLATFORM_DEFS+=$(STANDALONE_PLATFORM_DEFS) $(info $(findstring WITH_STANDALONE_*,$(PLATFORM_DEFS))) @@ -171,15 +148,6 @@ ifeq (,$(PLATFORM_DEFS_INFO_STANDALONE)) PLATFORM_DEFS_INFO_STANDALONE = No standalone mode selected endif -export PLATFORM -export PLATFORM_EXTRAS -export PLATFORM_EXTRAS_INFO -export PLTNAME -export MCU -export PLATFORM_DEFS -export PLATFORM_DEFS_INFO -export PLATFORM_DEFS_INFO_STANDALONE - PLATFORM_CHANGED=false ifneq ($(PLATFORM), $(CACHED_PLATFORM)) PLATFORM_CHANGED=true @@ -189,6 +157,16 @@ else ifneq ($(PLATFORM_DEFS), $(CACHED_PLATFORM_DEFS)) PLATFORM_CHANGED=true endif +export PLATFORM +export PLATFORM_EXTRAS +export PLATFORM_EXTRAS_INFO +export PLTNAME +export MCU +export PLATFORM_DEFS +export PLATFORM_DEFS_INFO +export PLATFORM_DEFS_INFO_STANDALONE +export PLATFORM_CHANGED + $(info ===================================================================) $(info Platform name: $(PLTNAME)) $(info PLATFORM: $(PLATFORM)) diff --git a/common/desfire.h b/common/desfire.h index 3cffd2967..41e5b6e12 100644 --- a/common/desfire.h +++ b/common/desfire.h @@ -3,7 +3,7 @@ #include #include -#include "aes.h" +#include "mbedtls/aes.h" #include "mifare.h" #define MAX_CRYPTO_BLOCK_SIZE 16 @@ -71,10 +71,6 @@ enum DESFIRE_CRYPTOALGO { struct desfire_key { enum DESFIRE_CRYPTOALGO type; uint8_t data[24]; - // DES_key_schedule ks1; - // DES_key_schedule ks2; - // DES_key_schedule ks3; - AesCtx aes_ks; uint8_t cmac_sk1[24]; uint8_t cmac_sk2[24]; uint8_t aes_version; diff --git a/common/lfdemod.c b/common/lfdemod.c index ef18b59ef..f8daec079 100644 --- a/common/lfdemod.c +++ b/common/lfdemod.c @@ -103,7 +103,7 @@ void computeSignalProperties(uint8_t *samples, uint32_t size) { // we can detect noise signalprop.isnoise = signalprop.amplitude < NOISE_AMPLITUDE_THRESHOLD; - if (g_debugMode) + if (g_debugMode) printSignal(); } @@ -1365,8 +1365,8 @@ static int millerRawDecode(uint8_t *bits, size_t *size, int invert) { int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert) { //sanity check if (*size < 51) return -1; - - if ( *offset < 0 ) *offset = 0; + + if (*offset < 0) *offset = 0; uint16_t bitnum = 0; uint16_t errCnt = 0; diff --git a/common/mbedtls/Makefile b/common/mbedtls/Makefile index fa0dff05f..a16b2cfd9 100644 --- a/common/mbedtls/Makefile +++ b/common/mbedtls/Makefile @@ -59,6 +59,8 @@ CFILES = $(filter %.c, $(mbedtls_SOURCES)) CMDOBJS = $(CFILES:%.c=%.o) CLEAN = $(CMDOBJS) +platform = $(shell uname) + CC= gcc CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function LDFLAGS= $(SYSLDFLAGS) $(mbedtls_LDFLAGS) @@ -66,8 +68,13 @@ LIBS= $(SYSLIBS) $(MYLIBS) DEFAULT_INCLUDES = -I. -I.. DEFS = -DHAVE_STDINT_H +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rcs +RANLIB= /usr/bin/ranlib +else AR= ar rcs RANLIB= ranlib +endif RM= rm -f TST= echo diff --git a/common/mbedtls/config.h b/common/mbedtls/config.h index dfda7ca40..9f4b19c5e 100644 --- a/common/mbedtls/config.h +++ b/common/mbedtls/config.h @@ -489,7 +489,7 @@ * This option is independent of \c MBEDTLS_AES_FEWER_TABLES. * */ -//#define MBEDTLS_AES_ROM_TABLES +#define MBEDTLS_AES_ROM_TABLES /** * \def MBEDTLS_AES_FEWER_TABLES @@ -511,7 +511,7 @@ * This option is independent of \c MBEDTLS_AES_ROM_TABLES. * */ -//#define MBEDTLS_AES_FEWER_TABLES +#define MBEDTLS_AES_FEWER_TABLES /** * \def MBEDTLS_CAMELLIA_SMALL_MEMORY diff --git a/common/mbedtls/platform_util.c b/common/mbedtls/platform_util.c index a3634e246..c30a52c08 100644 --- a/common/mbedtls/platform_util.c +++ b/common/mbedtls/platform_util.c @@ -60,9 +60,9 @@ * mbedtls_platform_zeroize() to use a suitable implementation for their * platform and needs. */ -static void *(* const volatile memset_func)(void *, int, size_t) = memset; +//static void *(* const volatile memset_func)(void *, int, size_t) = memset; void mbedtls_platform_zeroize(void *buf, size_t len) { - memset_func(buf, 0, len); + memset(buf, 0, len); } #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */ diff --git a/doc/bt_manual_v10.md b/doc/bt_manual_v10.md index 81d87acc6..032680cfa 100644 --- a/doc/bt_manual_v10.md +++ b/doc/bt_manual_v10.md @@ -33,9 +33,12 @@ Built-in battery can support standalone mode, off-line sniffing, off-line readin * Unplug your Proxmark3 RDV4.0 device from any usb cable. * Remove the plastic upper case of Proxmark3 RDV4.0 with opener. -* Remove temporarily the antenna with a screwdriver to expose the FPC interface. -* Turn off all power switches, insert the FPC wire into the FPC connector, and lock the FPC connector. -* Tear off the blue film of heat conductive double-sided tape. Align the add-on to the hole positions and gently insert it into the case. +* Remove temporarily the antenna with a H5 (Hex/Allen) screwdriver to expose the FPC interface.

+ Image of blue shark add-on fpc interface

+* Turn off all power switches, insert the FPC wire into the FPC connector, and lock the FPC connector.

+ Image of blue shark add-on fpc wire

+* Tear off the blue film of heat conductive double-sided tape. Align the add-on to the hole positions and gently insert it into the case.

+ Image of blue shark add-on blue film location

* Assembly finished!

@@ -44,6 +47,8 @@ Built-in battery can support standalone mode, off-line sniffing, off-line readin ### 4. COMPILATION / FLASHING +#### From Source + Please download the latest source code from Rfid Research Group's Github repo: https://github.com/RfidResearchGroup/proxmark3 @@ -58,6 +63,12 @@ To compile the client and firmware with FPC support, the easiest way is to You are now ready to run the client with the serial port you got from your BT device on your laptop etc. See instructions below. +#### Homebrew (macOS) +From the [homebrew-proxmark3 readme](https://github.com/RfidResearchGroup/homebrew-proxmark3) + +1. `brew tap rfidresearchgroup/proxmark3` +2. `brew install --with-blueshark proxmark3` + ### 5. CONNECT WITH BLUETOOTH You can have both USB cable connect and BT active at the same time and connect to either serial port. @@ -84,7 +95,8 @@ You can also switch serial port from inside the proxmark3 client using the new c * Install driver: http://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers * Insert the adapter into the USB port. The adapter will search automatically and establish the connection. The adapter will remember the device that was first connected and after that the same device will be connected. -* The adapter button can be used to delete memory so that other add-on can be searched and connected. +* The adapter button can be used to delete memory so that other add-on can be searched and connected.

+ Image of blue shark add-on HC-06 white dongle button * After the connection is established, the blue state LED on add-on will turn on solid. * look for _CP2104 USB tp UART bridge controller_ under devices in order to get the assigned serial port @@ -122,6 +134,21 @@ The first time, your OS will ask you for pairing. The default PIN is 1234. If PIN is not typed in quickly, the client might timeout. Simply restart it again after pairing. +If your OS doesn't prompt you for pairing, you can do it in command line, e.g. (again, replace with your addon MAC address): + +```sh +bluetoothctl +[bluetooth]# pairable on +[bluetooth]# scan on +Discovery started +... +[CHG] Device aa:bb:cc:dd:ee:ff Name: PM3_RDV4.0 +[bluetooth]# trust aa:bb:cc:dd:ee:ff +[bluetooth]# pair aa:bb:cc:dd:ee:ff +[agent] Enter PIN code: 1234 +[bluetooth]# quit +``` + #### (2) Fast connection using dedicated USB Bluetooth adapter under Linux

@@ -133,7 +160,9 @@ the device that was first connected and after that the same device will be connected. 2. The adapter button can be used to delete memory so that other add-on -can be searched and connected. +can be searched and connected.

+ Image of blue shark add-on HC-06 white dongle button +

3. After the connection is established, the blue state LED on add-on will turn on solid. @@ -143,6 +172,29 @@ turn on solid. ./proxmark /dev/ttyUSB0 ``` +#### MacOS + +#### (1) Connecting rdv4.0 with Bluetooth on MacOS + +With MacOS Mojave 10.14.5 you could experience some continuosly disconnecting and difficult to recconnect the device at the system wakeup, to avoid this problem do a PRAM reset before to add your Proxmark3 RDV4 Blue Shark: + + 1. Open a Terminal and execute this command: sudo rm -R /Library/Preferences/com.apple.Bluetooth.plist. + 2. Shut down your Mac. + 3. Then turn it on and immediately press and hold these four keys together: Option, Command, P, and R. + 4. You can release the keys after about 20 seconds, during which your Mac might appear to restart. + +After reboot you can go ahead to pairing your Proxmark3 RDV4 Blue Shark: + + 5. Make sure the Blue Shark BT switch is turned ON + 6. On your Mac, choose Apple menu -> System Preferences, then click Bluetooth. + 7. Select the device in the list, then click Connect and add the 1234 pwd. + 8. A serial port like `/dev/tty.PM3_RDV40-DevB` will be created, use Proxmark3 client on it + +```sh +./proxmark /dev/tty.PM3_RDV40-DevB +``` + + ### 6. OTHER NOTES #### (1) UART and LED behavior diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index 5eb8bc66b..bb5afb268 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -13,7 +13,7 @@ You might want to follow one of these external resources to get an overview, but # Install the required dependencies -## On Debian / Ubuntu / Kali / ParrotOS +## On Debian / Ubuntu / Kali / ParrotOS / Raspbian First what we want to do is get an update for the system. If you need to upgrade do this **before** the install. An upgrade was carried out prior to following these instructions. @@ -25,7 +25,7 @@ Install the requirements ```sh sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev \ -libusb-0.1-4 libusb-dev libqt4-dev perl pkg-config wget libncurses5-dev gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib +libusb-0.1-4 libusb-dev perl pkg-config wget libncurses5-dev gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib libqt4-dev ``` If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. @@ -41,8 +41,10 @@ Additional AUR packages: ```sh yaourt -S termcap ``` - -Note that with only these requirements, you will not get the graphical components of the Proxmark3 client. (Untested: how to get it? `yaourt -S qt4` ?) +If you want graphical output (such as in `hw tune`): +```sh +sudo pacman -Su qt5-base +``` # Clone the RRG/Iceman repository diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index ac88906da..db9a9084f 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -1,60 +1,169 @@ -# Building on Windows -You will need to use the Gator96100 Proxspace package to assist in your windows installation. -This can be downloaded from https://github.com/Gator96100/ProxSpace/ +# Installing on Windows + +There are two ways to install, build and use Proxmark3 on Windows: + +* Using Gator96100 **ProxSpace**, a package to assist in your Windows installation of MinGW +* Using native **WSL**, if you're running a Windows 10 version recent enough (FCU 1709 or later) --- -# Video Installation guide + +# Installing on Windows with ProxSpace + +## Video Installation guide [![Windows Installation tutorial](https://github.com/5w0rdfish/Proxmark3-RDV4-ParrotOS/blob/master/screenshot-www.youtube.com-2019.03.17-20-44-33.png)](https://youtu.be/zzF0NCMJnYU "Windows Installation Tutorial") -## Manual Installation +## Driver Installation -### Driver Installation +Install required drivers for your Windows installation. You may need admin privileges to do this. +Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs/news/how-to-install-a-proxmark3-driver-on-windows-10). -Install required drivers for your windows installation. You will may need admin privileges to do this. -(This is covered in the video) Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs/news/how-to-install-a-proxmark3-driver-on-windows-10) +## Download / clone ProxSpace repo -### Install Github +Download the Gator96100 ProxSpace package from https://github.com/Gator96100/ProxSpace/ -Install Github for Windows https://desktop.github.com/ +If you prefer, you can clone it, provided that you installed Github for Windows https://desktop.github.com/. -### Download / clone Proxspace repo - -Download the required proxspace repo. https://github.com/Gator96100/ProxSpace/ - -Extract 'ProxSpace' to a location on drive without spaces. +Extract 'ProxSpace' to a location path without spaces. For example D:\OneDrive\Documents\GitHub is ok whereas C:\My Documents\My Projects\proxspace is not. -### Clone the RRG/Iceman repository +If you're running Windows in a Virtualbox guest, make sure not to install ProxSpace on a vbox shared drive. (It's ok later to move the `/pm3` subfolder to a shared drive and edit the `*.bat`) -```sh -git clone https://github.com/RfidResearchGroup/proxmark3.git -``` - -### Copy files to Proxspace - -Copy all the contents from the `proxmark3` folder into the proxspace `pm3` folder - -### Run the .bat +## Launch ProxSpace Run `runme.bat` or `runme64.bat` depending on your Windows architecture. -Please note you will need to use `/` as you are using BASH. +You'll get a Bash prompt and your home directory should become the ProxSpace `pm3` sub-directory. -### Compile and use the project +Please note you will need to use `/` in paths as you are using Bash. + +## Clone the RRG/Iceman repository + +```sh +cd +git clone https://github.com/RfidResearchGroup/proxmark3.git +cd proxmark3 +``` + +If you're a contributing developer, you probably want to be able to use `make style`. If so, you've to install astyle: + +```sh +pacman -S mingw-w64-x86_64-astyle +``` + +## Compile and use the project Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). -The only differences are that executables end with `.exe` (e.g. `client/flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. +To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `client/flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. -So flashing will resemble +To flash: In principle, the helper script `flash-all.sh` should auto-detect your COM port, so you can just try: + +```sh +./flash-all.sh +``` + +If COM port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh client/flasher.exe comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` -And running the client will resemble +Similarly, to run the client, you may try: ```sh -cd client -./proxmark3.exe comX +./proxmark3.sh ``` + +Or, by specifying the COM port manually: + +```sh +client/proxmark3.exe comX +``` + +# Installing on Windows with WSL + +It requires to run a Windows 10 version 1709 or above. Previous versions didn't have support for COM ports. + +Install WSL with e.g. the standard Ubuntu. + +For WSL configuration, see [Manage and configure Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/wsl-config). + +## X Server Installation + +If you want to run the graphical components of the Proxmark3 client, you need to install a X Server such as [VcXsrv](https://sourceforge.net/projects/vcxsrv/) or [Xming](https://sourceforge.net/projects/xming/) and launch it, e.g. by executing XLaunch. + +## Dependencies + +Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instructions](/doc/md/Installation_Instructions/Linux-Installation-Instructions.md) for Ubuntu, summarized here below: + +```sh +sudo apt-get update +sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev libusb-0.1-4 \ +libusb-dev perl pkg-config wget libncurses5-dev gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ +libqt4-dev +``` + +If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. + +## Clone the RRG/Iceman repository + +```sh +git clone https://github.com/RfidResearchGroup/proxmark3.git +``` + +## Compile and use the project + +Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). + +To use the compiled client and flasher, the only difference is that the Proxmark3 port is translated from your `comX` port where "X" is the com port number assigned to proxmark3 under Windows, to a `/dev/ttySX`. + +Depending on the Windows version, you might need to give permission to the current user to access `/dev/ttySX`: (change X to your port number) + +```sh +ls -al /dev/ttySX +groups|grep dialout +``` + +If group ownership is `dialout` and your user is member of `dialout` group, all is fine. Else you'll have to provide access to `/dev/ttySX`: (Unfortunately the access rights of the port won't survive and will have to be fixed again next time.) + +```sh +sudo chmod 666 /dev/ttySX +``` + +If you installed a X Server and compiled the Proxmark3 with QT4 support, you've to export the `DISPLAY` environment variable: + +```sh +export DISPLAY=:0 +``` + +and add it to your Bash profile for the next times: + +```sh +echo "export DISPLAY=:0" >> ~/.bashrc +``` + +To flash: In principle, the helper script `flash-all.sh` should auto-detect your COMX==/dev/ttySX port, so you can just try: + +```sh +./flash-all.sh +``` + +If port detection failed, you'll have to call the flasher manually and specify the correct port: + +```sh +client/flasher /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +``` + +Similarly, to run the client, you may try: + +```sh +./proxmark3.sh +``` + +Or, by specifying the COM port manually: + +```sh +client/proxmark3 /dev/ttySX +``` + +Note that it may take a quite long time for a freshly plugged Proxmark3 to be visible on a WSL /dev/ttySX port. diff --git a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md index ffe312aac..7493fba1a 100644 --- a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md +++ b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md @@ -1,5 +1,16 @@ # Compilation instructions +## Tuning compilation parameters + +The client and the Proxmark3 firmware should always be in sync. +Nevertheless, the firmware can be tuned depending on the Proxmark3 platform and options. + +Indeed, the RRG/Iceman fork can be used on other Proxmark3 hardware platforms as well. + +Via some definitions, you can adjust the firmware for a given platform, but also to add features like the support of the Blue Shark add-on or to select which standalone mode to embed. + +To learn how to adjust the firmware, please read [Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md). + ## Get the latest commits ```sh @@ -15,12 +26,22 @@ make clean && make all ## Flash the BOOTROM & FULLIMAGE +In most cases, you can run the script `flash-all.sh` which try to auto-detect the port to use, on several OS. + +For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: + ```sh client/flasher /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` ## Run the client +In most cases, you can run the script `proxmark3.sh` which try to auto-detect the port to use, on several OS. + +For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: + +Here, for example, for a Proxmark3 connected via USB under Linux: + ```sh cd client ./proxmark3 /dev/ttyACM0 diff --git a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md new file mode 100644 index 000000000..aea5b5e30 --- /dev/null +++ b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md @@ -0,0 +1,82 @@ +# Advanced compilation parameters + +The client and the Proxmark3 firmware should always be in sync. +Nevertheless, the firmware can be tuned depending on the Proxmark3 platform and options. + +Indeed, the RRG/Iceman fork can be used on other Proxmark3 hardware platforms as well. + +Via some definitions, you can adjust the firmware for a given platform, but also to add features like the support of the Blue Shark add-on or to select which standalone mode to embed. + +## Client + +The client doesn't depend on the capabilities of the Proxmark3 it's connected to. +So you can use the same client for different Proxmark3 platforms, given that everything is running the same version. + +## Firmware + +By default, the firmware is of course tuned for the Proxmark3 Rdv4.0 device, which has built-in support for 256kb onboard flash SPI memory, Sim module (smart card support), FPC connector. +These features make it very different from all other devices, there is non other like this one. + +**Recommendation**: if you don't have a RDV4, we strongly recommend your device to have at least a 512kb arm chip, since this repo is on the very edge of 256kb limit. + +A firmware built for the RDV4 can still run on the other platforms as it will auto-detect during boot that external SPI and Sim are not present, still it will boot faster if it's tuned to the platform. + +If you need to tune things and save the configuration, create a file `Makefile.platform` in the root directory of the repository, see `Makefile.platform.sample`. +For an up-to-date exhaustive list of options, you can run `make PLATFORM=`. + +## PLATFORM + +Here are the supported values you can assign to `PLATFORM` in `Makefile.platform`: + +| PLATFORM | DESCRIPTION | +|-----------------|----------------------------------------| +| PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | +| PM3EVO | Proxmark3 EVO with AT91SAM7S512 | +| PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | +| PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 | +| PM3OLD256 | Proxmark3 V1 with AT91SAM7S256 | +| PM3OLD512 | Proxmark3 V1 with AT91SAM7S512 | + +By default `PLATFORM=PM3RDV4`. + +Known issues: + +* 256kb Arm chip devices: The compiled firmware image from this repo may/will be too large for your device. +* PM3 Evo: it has a different led/button pin assignment. It tends to be messed up. + +## PLATFORM_EXTRAS + +Here are the supported values you can assign to `PLATFORM_EXTRAS` in `Makefile.platform`: + +| PLATFORM_EXTRAS | DESCRIPTION | +|-----------------|----------------------------------------| +| BTADDON | Proxmark3 rdv4 BT add-on | + +By default `PLATFORM_EXTRAS=`. + +If you have installed a Blue Shark add-on on your RDV4, define `PLATFORM_EXTRAS=BTADDON` in your `Makefile.platform`. + + +## STANDALONE + +The RRG/Iceman fork gives you to easily choose which standalone mode to embed in the firmware. + +Here are the supported values you can assign to `STANDALONE` in `Makefile.platform`: + +| STANDALONE | DESCRIPTION | +|-----------------|----------------------------------------| +| | No standalone mode +| LF_SAMYRUN (def)| HID26 read/clone/sim - Samy Kamkar +| LF_ICERUN | standalone mode skeleton - iceman +| LF_PROXBRUTE | HID ProxII bruteforce - Brad Antoniewicz +| LF_HIDBRUTE | HID corporate 1000 bruteforce - Federico dotta & Maurizio Agazzini +| HF_YOUNG | Mifare sniff/simulation - Craig Young +| HF_MATTYRUN | Mifare sniff/clone - Matías A. Ré Medina +| HF_COLIN | Mifare ultra fast sniff/sim/clone - Colin Brigato +| HF_BOG | 14a sniff with ULC/ULEV1/NTAG auth storing in flashmem - Bogito + +By default `STANDALONE=LF_SAMYRUN`. + +## Next step + +See [Compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md) diff --git a/doc/new_frame_format.md b/doc/new_frame_format.md index 76424f8b6..17c94120a 100644 --- a/doc/new_frame_format.md +++ b/doc/new_frame_format.md @@ -373,9 +373,9 @@ It was needed to tune pm3 RX usart `maxtry` : time client/proxmark3 -p /dev/ttyUSB0 -b 115200 -c "lf read" 6.28s - time client/proxmark3 -p /dev/ttyACM0 -c "mem save f foo_usb" + time client/proxmark3 -p /dev/ttyACM0 -c "mem dump f foo_usb" 1.48s - time client/proxmark3 -p /dev/ttyUSB0 -b 115200 -c "mem save f foo_fpc" + time client/proxmark3 -p /dev/ttyUSB0 -b 115200 -c "mem dump f foo_fpc" 25.34s diff --git a/doc/termux_notes.md b/doc/termux_notes.md new file mode 100644 index 000000000..f568c6f16 --- /dev/null +++ b/doc/termux_notes.md @@ -0,0 +1,68 @@ +# Proxmark 3 on Android + +## Requirements +- Android phone +- Kernel with one of: + - USB_ACM driver + - module loading enabled + - published sources +- Root +- [Termux](https://play.google.com/store/apps/details?id=com.termux) + +## Notes +From official Proxmark3 wiki: + > In any case, you would need a USB-C to A or USB-OTG cable to connect Proxmark3 to your Android device. Some Android devices may not supply enough power (USB-OTG = 100mA), and need a USB Y-cable and external battery, otherwise they will get strange failures. +ref : https://github.com/Proxmark/proxmark3/wiki/android + +## Tested setup +- OnePlus 5 (arm64, USB-C) +- [OmniROM (Android 9)](https://www.omnirom.org/) +- [OmniROM kernel](https://www.omnirom.org/) +- [Magisk 19.3](https://github.com/topjohnwu/Magisk/) + +## Setup +### Getting ncurses with termcap +You need `termcap` to build the Proxmark3 client. Unfortunately, the prebuilt `ncurses` package does not include it. Since [this PR](https://github.com/termux/termux-packages/pull/2131) hasn't been merged yet, you will have to build `ncurses` yourself + +1. Clone the [termux-packages](https://github.com/termux/termux-packages) repo +2. Apply [the PR](https://github.com/termux/termux-packages/pull/2131) +3. Build `ncurses`. Refer to the [build docs](https://github.com/termux/termux-packages/blob/master/docs/BUILD_ENVIRONMENT.md) for more information. The easiest way is to use Docker: + - `./scripts/run-docker.sh` + - `./build-package.sh ncurses` + - the built packages will be under the `debs` directory +4. Copy `ncurses_6.1.x-x_aarch64.deb` to your phone's `/sdcard` +### Setting up Termux +1. Install [Termux](https://play.google.com/store/apps/details?id=com.termux) and start it +2. Run the following commands: +``` +pkg install make, clang, clang++, readline-dev, libclang-dev, libc++, git, tsu +termux-setup-storage +dpkg -i /sdcard/ncurses_6.1.x-x_aarch64.deb +git clone https://github.com/RfidResearchGroup/proxmark3.git +``` +### Building Proxmark3 client +1. Edit `proxmark3/client/Makefile` and append `-fPIC` to the `CFLAGS` variable (line 30) +2. `make clean && make client` + +### USB_ACM +You need the `USB_ACM` driver enabled and working to communicate with the Proxmark3. To see if it's working, run `tsudo ls /dev/tty*` and it should list `/dev/ttyACM0` (or similar). If you see this, congratulations, skip this step! + +#### Enable the driver +If your kernel has module loading enabled, you should be able to build the module separately and load it on your system without any changes. Otherwise, grab your kernel sources and edit your build config to include `CONFIG_USB_ACM=y`. On the tested kernel, this was under: `android_kernel_oneplus_msm8998/arch/arm64/configs/omni_oneplus5_defconfig` + +#### Building the kernel +If using a custom kernel, refer to the build instructions provided by its maintainer. Otherwise, follow the standard Linux kernel build procedure + +#### Flashing the kernel +You can flash the kernel however it suits you. On the tested device, this was achieved using [TWRP](https://twrp.me/), the most popular custom recovery + +### Testing +Open Termux and start the Proxmark3 client: +``` +tsudo proxmark3/client/proxmark3 /dev/ttyACM0 +``` +Everything should work just like if it was your PC! + +### Troubleshooting +- `dmesg | grep usb` - useful debug info +- `/proc/config.gz` - contains your kernel's build configuration. Look for `CONFIG_USB_ACM`, which should be enabled diff --git a/flash-all.sh b/flash-all.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-all.sh +++ b/flash-all.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/flash-bootrom.sh b/flash-bootrom.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-bootrom.sh +++ b/flash-bootrom.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/flash-fullimage.sh b/flash-fullimage.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-fullimage.sh +++ b/flash-fullimage.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/include/common.h b/include/common.h index 3dbf77622..dec2261ec 100644 --- a/include/common.h +++ b/include/common.h @@ -19,9 +19,20 @@ extern "C" { #include #include #include -#include + typedef unsigned char byte_t; +#ifdef _MSC_VER +typedef DWORD uint32_t; +typedef BYTE uint8_t; +#define PACKED +// stuff +#else +#include +#include +#define PACKED __attribute__((packed)) +#endif + // debug #define DBG_NONE 0 // no messages #define DBG_ERROR 1 // errors only @@ -30,9 +41,6 @@ typedef unsigned char byte_t; #define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages extern int DBGLEVEL; -// Flashmem spi baudrate -extern uint32_t FLASHMEM_SPIBAUDRATE; - // reader voltage field detector #define MF_MINFIELDV 4000 @@ -49,74 +57,87 @@ extern uint32_t FLASHMEM_SPIBAUDRATE; #endif #define RAMFUNC __attribute((long_call, section(".ramfunc"))) -// RDV40 Section -// 256kb divided into 4k sectors. -// -// 0x3F000 - 1 4kb sector = signature -// 0x3E000 - 1 4kb sector = settings -// 0x3D000 - 1 4kb sector = default T55XX keys dictionary -// 0x3B000 - 1 4kb sector = default ICLASS keys dictionary -// 0x39000 - 2 4kb sectors = default MFC keys dictionary -// -#ifndef FLASH_MEM_BLOCK_SIZE -# define FLASH_MEM_BLOCK_SIZE 256 +#ifndef ROTR +# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n)))) #endif -#ifndef FLASH_MEM_MAX_SIZE -# define FLASH_MEM_MAX_SIZE 0x40000 // (262144) +#ifndef ROTL +# define ROTL(x,n) (((uintmax_t)(x) << (n)) | ((uintmax_t)(x) >> ((sizeof(x) * 8) - (n)))) #endif -#ifndef FLASH_MEM_MAX_4K_SECTOR -# define FLASH_MEM_MAX_4K_SECTOR 0x3F000 +// endian change for 64bit +#ifdef __GNUC__ +#ifndef BSWAP_64 +#define BSWAP_64(x) __builtin_bswap64(x) +#endif +#else +#ifdef _MSC_VER +#ifndef BSWAP_64 +#define BSWAP_64(x) _byteswap_uint64(x) +#endif +#else +#ifndef BSWAP_64 +#define BSWAP_64(x) \ + (((uint64_t)(x) << 56) | \ + (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \ + (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \ + (((uint64_t)(x) << 8) & 0xff00000000ULL) | \ + (((uint64_t)(x) >> 8) & 0xff000000ULL) | \ + (((uint64_t)(x) >> 24) & 0xff0000ULL) | \ + (((uint64_t)(x) >> 40) & 0xff00ULL) | \ + ((uint64_t)(x) >> 56)) +#endif +#endif #endif - -#ifndef FLASH_MEM_ID_LEN -# define FLASH_MEM_ID_LEN 8 +// endian change for 32bit +#ifdef __GNUC__ +#ifndef BSWAP_32 +#define BSWAP_32(x) __builtin_bswap32(x) +#endif +#else +#ifdef _MSC_VER +#ifndef BSWAP_32 +#define BSWAP_32(x) _byteswap_ulong(x) +#endif +#else +#ifndef BSWAP_32 +# define BSWAP_32(x) \ + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) +#endif +#endif #endif -#ifndef FLASH_MEM_SIGNATURE_LEN -# define FLASH_MEM_SIGNATURE_LEN 128 +#define EVEN 0 +#define ODD 1 + +// Nibble logic +#ifndef NIBBLE_HIGH +# define NIBBLE_HIGH(b) ( (b & 0xF0) >> 4 ) #endif -#ifndef FLASH_MEM_SIGNATURE_OFFSET -// -1 for historical compatibility with already released Proxmark3 RDV4.0 devices -# define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN - 1) +#ifndef NIBBLE_LOW +# define NIBBLE_LOW(b) ( b & 0x0F ) #endif -#ifndef T55XX_CONFIG_LEN -# define T55XX_CONFIG_LEN sizeof( t55xx_config ) +#ifndef CRUMB +# define CRUMB(b,p) (((b & (0x3 << p) ) >> p ) & 0xF) #endif -#ifndef T55XX_CONFIG_OFFSET -# define T55XX_CONFIG_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x2000) +#ifndef SWAP_NIBBLE +# define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b)) #endif -// Reserved space for T55XX PWD = 4 kb -#ifndef DEFAULT_T55XX_KEYS_OFFSET -# define DEFAULT_T55XX_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x3000) +// Binary Encoded Digit +#ifndef BCD2DEC +# define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10) #endif -// Reserved space for iClass keys = 4 kb -#ifndef DEFAULT_ICLASS_KEYS_OFFSET -# define DEFAULT_ICLASS_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x4000) +#ifndef DEC2BCD +# define DEC2BCD(dec) HornerScheme(dec, 10, 0x10) #endif -// Reserved space for MIFARE Keys = 8 kb -#ifndef DEFAULT_MF_KEYS_OFFSET -# define DEFAULT_MF_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x6000) -#endif - - - -// RDV40, validation structure to help identifying that client/firmware is talking with RDV40 -typedef struct { - uint8_t magic[4]; - uint8_t flashid[FLASH_MEM_ID_LEN]; - uint8_t signature[FLASH_MEM_SIGNATURE_LEN]; -} __attribute__((__packed__)) rdv40_validation_t; - - #ifdef __cplusplus } #endif diff --git a/include/hitag.h b/include/hitag.h index 742d7ecd0..9df93fcf7 100644 --- a/include/hitag.h +++ b/include/hitag.h @@ -14,11 +14,7 @@ #ifndef HITAG_H__ #define HITAG_H__ -#ifdef _MSC_VER -#define PACKED -#else -#define PACKED __attribute__((packed)) -#endif +#include "common.h" typedef enum { RHTSF_CHALLENGE = 01, @@ -31,6 +27,7 @@ typedef enum { WHT2F_CRYPTO = 24, RHT2F_TEST_AUTH_ATTEMPTS = 25, RHT2F_UID_ONLY = 26, + WHT2F_PASSWORD = 27, } hitag_function; typedef struct { diff --git a/include/mifare.h b/include/mifare.h index 87ba3a74e..9d444e833 100644 --- a/include/mifare.h +++ b/include/mifare.h @@ -46,7 +46,7 @@ typedef struct { uint8_t sak; uint8_t ats_len; uint8_t ats[256]; -} __attribute__((__packed__)) iso14a_card_select_t; +} PACKED iso14a_card_select_t; typedef enum ISO14A_COMMAND { ISO14A_CONNECT = (1 << 0), @@ -129,7 +129,7 @@ typedef struct { typedef struct { uint8_t atr_len; uint8_t atr[30]; -} __attribute__((__packed__)) smart_card_atr_t; +} PACKED smart_card_atr_t; typedef enum SMARTCARD_COMMAND { SC_CONNECT = (1 << 0), @@ -167,7 +167,7 @@ typedef struct { uint8_t iccode[2]; uint8_t mrt[6]; uint8_t servicecode[2]; -} __attribute__((__packed__)) felica_card_select_t; +} PACKED felica_card_select_t; typedef enum FELICA_COMMAND { FELICA_CONNECT = (1 << 0), diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 772ec02b9..d271d3099 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -13,20 +13,11 @@ #ifndef __PM3_CMD_H #define __PM3_CMD_H +#include "common.h" + // Use it e.g. when using slow links such as BT #define USART_SLOW_LINK -#ifdef _MSC_VER -typedef DWORD uint32_t; -typedef BYTE uint8_t; -#define PACKED -// stuff -#else -#include -#include -#define PACKED __attribute__((packed)) -#endif - #define PM3_CMD_DATA_SIZE 512 #define PM3_CMD_DATA_SIZE_MIX ( PM3_CMD_DATA_SIZE - 3 * sizeof(uint64_t) ) @@ -216,6 +207,7 @@ typedef struct { #define CMD_FINISH_WRITE 0x0003 #define CMD_HARDWARE_RESET 0x0004 #define CMD_START_FLASH 0x0005 +#define CMD_CHIP_INFO 0x0006 #define CMD_NACK 0x00fe #define CMD_ACK 0x00ff @@ -235,9 +227,9 @@ typedef struct { #define CMD_CAPABILITIES 0x0112 #define CMD_QUIT_SESSION 0x0113 #define CMD_SET_DBGMODE 0x0114 +#define CMD_STANDALONE 0x0115 // RDV40, Flash memory operations -#define CMD_FLASHMEM_READ 0x0120 #define CMD_FLASHMEM_WRITE 0x0121 #define CMD_FLASHMEM_WIPE 0x0122 #define CMD_FLASHMEM_DOWNLOAD 0x0123 @@ -541,6 +533,9 @@ typedef struct { /* Set if this device understands the extend start flash command */ #define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4) +/* Set if this device understands the chip info command */ +#define DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO (1<<5) + /* CMD_START_FLASH may have three arguments: start of area to flash, end of area to flash, optional magic. The bootrom will not allow to overwrite itself unless this magic diff --git a/include/pmflash.h b/include/pmflash.h new file mode 100644 index 000000000..b7bf39ddc --- /dev/null +++ b/include/pmflash.h @@ -0,0 +1,97 @@ +//----------------------------------------------------------------------------- +// (c) RFID Research Group - 2019 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +// +//----------------------------------------------------------------------------- +// RDV4 flash constants +//----------------------------------------------------------------------------- + +#ifndef __PMFLASH_H +#define __PMFLASH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#include "common.h" + +// Flashmem spi baudrate +extern uint32_t FLASHMEM_SPIBAUDRATE; + +// RDV40 Section +// 256kb divided into 4k sectors. +// +// 0x3F000 - 1 4kb sector = signature +// 0x3E000 - 1 4kb sector = settings +// 0x3D000 - 1 4kb sector = default T55XX keys dictionary +// 0x3B000 - 1 4kb sector = default ICLASS keys dictionary +// 0x39000 - 2 4kb sectors = default MFC keys dictionary +// +#ifndef FLASH_MEM_BLOCK_SIZE +# define FLASH_MEM_BLOCK_SIZE 256 +#endif + +#ifndef FLASH_MEM_MAX_SIZE +# define FLASH_MEM_MAX_SIZE 0x40000 // (262144) +#endif + +#ifndef FLASH_MEM_MAX_4K_SECTOR +# define FLASH_MEM_MAX_4K_SECTOR 0x3F000 +#endif + + +#ifndef FLASH_MEM_ID_LEN +# define FLASH_MEM_ID_LEN 8 +#endif + +#ifndef FLASH_MEM_SIGNATURE_LEN +# define FLASH_MEM_SIGNATURE_LEN 128 +#endif + +#ifndef FLASH_MEM_SIGNATURE_OFFSET +// -1 for historical compatibility with already released Proxmark3 RDV4.0 devices +# define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN - 1) +#endif + +#ifndef T55XX_CONFIG_LEN +# define T55XX_CONFIG_LEN sizeof( t55xx_config ) +#endif + +#ifndef T55XX_CONFIG_OFFSET +# define T55XX_CONFIG_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x2000) +#endif + +// Reserved space for T55XX PWD = 4 kb +#ifndef DEFAULT_T55XX_KEYS_OFFSET +# define DEFAULT_T55XX_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x3000) +#endif + +// Reserved space for iClass keys = 4 kb +#ifndef DEFAULT_ICLASS_KEYS_OFFSET +# define DEFAULT_ICLASS_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x4000) +#endif + +// Reserved space for MIFARE Keys = 8 kb +#ifndef DEFAULT_MF_KEYS_OFFSET +# define DEFAULT_MF_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x6000) +#endif + +// RDV40, validation structure to help identifying that client/firmware is talking with RDV40 +typedef struct { + uint8_t magic[4]; + uint8_t flashid[FLASH_MEM_ID_LEN]; + uint8_t signature[FLASH_MEM_SIGNATURE_LEN]; +} PACKED rdv40_validation_t; + +#ifdef __cplusplus +} +#endif + +#endif // __PMFLASH_H diff --git a/include/proxmark3.h b/include/proxmark3.h index 8748e82d8..469713b5b 100644 --- a/include/proxmark3.h +++ b/include/proxmark3.h @@ -15,6 +15,7 @@ #include "at91sam7s512.h" #include "config_gpio.h" #include "pm3_cmd.h" +#include "common.h" #define WDT_HIT() AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001 @@ -71,8 +72,6 @@ #define COTAG_BITS 264 #endif -//#define PACKED __attribute__((__packed__)) - #define LED_A_ON() HIGH(GPIO_LED_A) #define LED_A_OFF() LOW(GPIO_LED_A) #define LED_A_INV() INVBIT(GPIO_LED_A) @@ -116,7 +115,7 @@ struct version_information { char clean; /* 1: Tree was clean, no local changes. 0: Tree was unclean. 2: Couldn't be determined */ char gitversion[50]; /* String with the git revision */ char buildtime[30]; /* string with the build time */ -} __attribute__((packed)); +} PACKED; #define COMMON_AREA_MAGIC 0x43334d50 // "PM3C" #define COMMON_AREA_COMMAND_NONE 0 @@ -129,8 +128,8 @@ struct common_area { unsigned int bootrom_present: 1; /* Set when a bootrom that is capable of parsing the common area is present */ unsigned int osimage_present: 1; /* Set when a osimage that is capable of parsing the common area is present */ unsigned int button_pressed: 1; - } __attribute__((packed)) flags; + } PACKED flags; int arg1, arg2; -} __attribute__((packed)); +} PACKED; #endif diff --git a/liblua/Makefile b/liblua/Makefile index bf2a4fa3c..2b3d7614f 100644 --- a/liblua/Makefile +++ b/liblua/Makefile @@ -12,13 +12,20 @@ endif # Your platform. See PLATS for possible values. PLAT= none +platform= $(shell uname) + CC= gcc CFLAGS= -O3 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= -lm $(SYSLIBS) $(MYLIBS) +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rc +RANLIB= /usr/bin/ranlib +else AR= ar rc RANLIB= ranlib +endif RM= rm -f SYSCFLAGS= diff --git a/proxmark3.sh b/proxmark3.sh index b4cbd49fd..4cd6d76bc 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -3,54 +3,89 @@ FULLIMAGE="armsrc/obj/fullimage.elf" BOOTIMAGE="bootrom/obj/bootrom.elf" -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 function wait4proxmark_Linux { echo >&2 "Waiting for Proxmark to appear..." - while [ ! -c /dev/ttyACM? -a ! -c /dev/pm3-? ]; do + while true; do + PM3=$(find /dev/pm3-* /dev/ttyACM* 2>/dev/null | head -1) + if [[ $PM3 != "" ]]; then + break + fi sleep .1 done - local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1` - echo >&2 -e "Found proxmark on ${PM3}\n" - echo $PM3 + echo "$PM3" } function wait4proxmark_macOS { echo >&2 "Waiting for Proxmark to appear..." while true; do - PM3=$(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) + PM3=$(find /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) if [[ $PM3 != "" ]]; then - #echo >&2 -e "Found proxmark on $(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1)\n" break fi sleep .1 done - echo $PM3 + echo "$PM3" +} + +function wait4proxmark_Windows { + echo >&2 "Waiting for Proxmark to appear..." + while true; do + device=$(wmic path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2') + if [[ $device != "" ]]; then + PM3=${device/ */} + break + fi + sleep .1 + done + echo "$PM3" +} + +function wait4proxmark_WSL { + echo >&2 "Waiting for Proxmark to appear..." + while true; do + device=$(wmic.exe path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2') + if [[ $device != "" ]]; then + PM3=${device/ */} + PM3="/dev/ttyS${PM3#COM}" + break + fi + sleep .1 + done + if [ -e "$PM3" ] && [ ! -w "$PM3" ]; then + echo "We need to give current user read/write access to $PM3" + sudo chmod 666 "$PM3" + fi + echo "$PM3" } SCRIPT=$(basename -- "$0") if [ "$SCRIPT" = "proxmark3.sh" ]; then - CMD=client/proxmark3 + CMD() { client/proxmark3 "$@"; } elif [ "$SCRIPT" = "flash-all.sh" ]; then - CMD=client/flasher - ARG1="-b $BOOTIMAGE" - ARG2="$FULLIMAGE" + CMD() { client/flasher "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; } elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then - CMD=client/flasher - ARG2="$FULLIMAGE" + CMD() { client/flasher "$1" "$FULLIMAGE"; } elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then - CMD=client/flasher - ARG1="-b $BOOTIMAGE" + CMD() { client/flasher "$1" -b "$BOOTIMAGE"; } else echo "Script ran under unknown name, abort: $SCRIPT" exit 1 fi HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then - PORT=$(wait4proxmark_Linux) + if uname -a|grep -q Microsoft; then + PORT=$(wait4proxmark_WSL) + else + PORT=$(wait4proxmark_Linux) + fi elif [ "$HOSTOS" = "DARWIN" ]; then PORT=$(wait4proxmark_macOS) +elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then + PORT=$(wait4proxmark_Windows) else echo "Host OS not recognized, abort: $HOSTOS" exit 1 @@ -60,6 +95,5 @@ if [ "$PORT" = "" ]; then exit 1 fi -#echo Running "$CMD" "$PORT" $ARG1 $ARG2 "$@" -"$CMD" "$PORT" $ARG1 $ARG2 "$@" +CMD "$PORT" "$@" exit $? diff --git a/tools/jtag_openocd/general.cfg b/tools/jtag_openocd/general.cfg new file mode 100644 index 000000000..6151d82bc --- /dev/null +++ b/tools/jtag_openocd/general.cfg @@ -0,0 +1,3 @@ +# Ports +telnet_port 4444 +gdb_port 3333 diff --git a/tools/jtag_openocd/interface-armusbocd.cfg b/tools/jtag_openocd/interface-armusbocd.cfg index e4689e21b..4820136f0 100644 --- a/tools/jtag_openocd/interface-armusbocd.cfg +++ b/tools/jtag_openocd/interface-armusbocd.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Olimex ARM-USB-OCD Dongle interface ft2232 ft2232_device_desc "Olimex OpenOCD JTAG" diff --git a/tools/jtag_openocd/interface-busblaster.cfg b/tools/jtag_openocd/interface-busblaster.cfg index 337e9a2de..bd1df2c5f 100644 --- a/tools/jtag_openocd/interface-busblaster.cfg +++ b/tools/jtag_openocd/interface-busblaster.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Bus Blaster interface ftdi ftdi_device_desc "Dual RS232-HS" diff --git a/tools/jtag_openocd/interface-buspirate.cfg b/tools/jtag_openocd/interface-buspirate.cfg index 4ed5b88a5..8eccadd79 100644 --- a/tools/jtag_openocd/interface-buspirate.cfg +++ b/tools/jtag_openocd/interface-buspirate.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the BusPirate interface buspirate buspirate_port /dev/ttyUSB0 diff --git a/tools/jtag_openocd/interface-c232hm.cfg b/tools/jtag_openocd/interface-c232hm.cfg new file mode 100644 index 000000000..f4d0f471a --- /dev/null +++ b/tools/jtag_openocd/interface-c232hm.cfg @@ -0,0 +1,23 @@ +# Commands specific to the FTDI USB Hi-Speed to MPSSE Cable +# http://www.ftdichip.com/Products/Cables/USBMPSSE.htm +# C232HM-DDHSL-0 => 3.3V +# C232HM-EDSL-0 => 5V !! don't apply 5V on the 3.3v pm3 pin !! + +# Pinouts: +# Brown <> TMS +# Yellow <> TDI +# Green <> TDO +# Orange <> TCK +# Black <> GND +# Red <> 3.3 (don't connect if C232HM-EDSL-0! power via USB instead) + +interface ftdi +#ftdi_device_desc "C232HM-DDHSL-0" +#ftdi_device_desc "C232HM-EDHSL-0" +ftdi_vid_pid 0x0403 0x6014 + +ftdi_layout_init 0x0008 0x400b +ftdi_layout_signal LED -ndata 0x4000 + +transport select jtag +adapter_khz 1000 diff --git a/tools/jtag_openocd/interface-jlink.cfg b/tools/jtag_openocd/interface-jlink.cfg index 56a04fef2..011cb7844 100644 --- a/tools/jtag_openocd/interface-jlink.cfg +++ b/tools/jtag_openocd/interface-jlink.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Segger J-Link interface jlink transport select jtag diff --git a/tools/jtag_openocd/interface-jtagkey.cfg b/tools/jtag_openocd/interface-jtagkey.cfg index 3e48c08df..420e6e97e 100644 --- a/tools/jtag_openocd/interface-jtagkey.cfg +++ b/tools/jtag_openocd/interface-jtagkey.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Amontec JTAGKey interface ft2232 ft2232_device_desc "Amontec JTAGkey A" diff --git a/tools/jtag_openocd/interface-raspberrypi.cfg b/tools/jtag_openocd/interface-raspberrypi.cfg new file mode 100644 index 000000000..984afe41b --- /dev/null +++ b/tools/jtag_openocd/interface-raspberrypi.cfg @@ -0,0 +1,37 @@ +# Config for using Raspberry Pi's expansion header +# Using BCM2835 chip present in models Pi1, Pi2 and Pi Zero + +# Use short cables! +# Make sure the CPU is not busy with other processes! +# Connect pm3 before booting to avoid power loss & reboot problems +# Pinouts: +# 22 <> TMS +# 19 <> TDI +# 21 <> TDO +# 23 <> TCK +# 6 <> GND +# 1 <> 3.3 + +interface bcm2835gpio + +# This file is meant for first versions of Raspberry Pi +# You can check yours with: +# dd if=/proc/device-tree/soc/ranges bs=4 skip=1 count=1 2>/dev/null|xxd -p +# if it returns 20000000, you're fine +# if it returns 3F000000, use interface-raspberrypi2.cfg +bcm2835gpio_peripheral_base 0x20000000 + +# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET +# These depend on system clock, calibrated for stock 700MHz +# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET +bcm2835gpio_speed_coeffs 113714 28 + +# Each of the JTAG lines need a gpio number set: tck tms tdi tdo +# Header pin numbers: 23 22 19 21 +bcm2835gpio_jtag_nums 11 25 10 9 + +bcm2835gpio_srst_num 18 +reset_config srst_only srst_push_pull + +transport select jtag +adapter_khz 1000 diff --git a/tools/jtag_openocd/interface-raspberrypi2.cfg b/tools/jtag_openocd/interface-raspberrypi2.cfg new file mode 100644 index 000000000..b779cd290 --- /dev/null +++ b/tools/jtag_openocd/interface-raspberrypi2.cfg @@ -0,0 +1,37 @@ +# Config for using Raspberry Pi's expansion header +# Using BCM2835 chip present in models 2+ and above + +# Use short cables! +# Make sure the CPU is not busy with other processes! +# Connect pm3 before booting to avoid power loss & reboot problems +# Pinouts: +# 22 <> TMS +# 19 <> TDI +# 21 <> TDO +# 23 <> TCK +# 6 <> GND +# 1 <> 3.3 + +interface bcm2835gpio + +# This file is meant for recent versions of Raspberry Pi +# You can check yours with: +# dd if=/proc/device-tree/soc/ranges bs=4 skip=1 count=1 2>/dev/null|xxd -p +# if it returns 20000000, use interface-raspberrypi2.cfg +# if it returns 3F000000, you're fine +bcm2835gpio_peripheral_base 0x3F000000 + +# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET +# These depend on system clock, calibrated for stock 700MHz +# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET +bcm2835gpio_speed_coeffs 146203 36 + +# Each of the JTAG lines need a gpio number set: tck tms tdi tdo +# Header pin numbers: 23 22 19 21 +bcm2835gpio_jtag_nums 11 25 10 9 + +bcm2835gpio_srst_num 18 +reset_config srst_only srst_push_pull + +transport select jtag +adapter_khz 1000 diff --git a/tools/jtag_openocd/interface-shikra.cfg b/tools/jtag_openocd/interface-shikra.cfg index 507c301b4..ba4b21419 100644 --- a/tools/jtag_openocd/interface-shikra.cfg +++ b/tools/jtag_openocd/interface-shikra.cfg @@ -1,7 +1,3 @@ -# Ports -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Shikra interface ftdi transport select jtag diff --git a/tools/jtag_openocd/interface-wiggler.cfg b/tools/jtag_openocd/interface-wiggler.cfg index 88448de82..ce9a1da06 100644 --- a/tools/jtag_openocd/interface-wiggler.cfg +++ b/tools/jtag_openocd/interface-wiggler.cfg @@ -1,6 +1,3 @@ -telnet_port 4444 -gdb_port 3333 - # Commands specific to the Wiggler interface parport parport_port 0x378 diff --git a/tools/jtag_openocd/openocd_configuration.sample b/tools/jtag_openocd/openocd_configuration.sample new file mode 100644 index 000000000..466e28d9b --- /dev/null +++ b/tools/jtag_openocd/openocd_configuration.sample @@ -0,0 +1,7 @@ +CONFIG_GEN=general.cfg +CONFIG_CHIP=chip-at91sam7s.cfg +IMAGE=../../recovery/proxmark3_recovery.bin +DUMP="dump_$(date +'%Y%m%d-%H%M%S').bin" + +# Example using Segger Jlink: +CONFIG_IF=interface-jlink.cfg diff --git a/tools/jtag_openocd/openocd_flash_dump.sh b/tools/jtag_openocd/openocd_flash_dump.sh new file mode 100755 index 000000000..497847dd1 --- /dev/null +++ b/tools/jtag_openocd/openocd_flash_dump.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +. openocd_configuration || exit 1 + +if [ -e "$DUMP" ]; then + echo "$DUMP exists already. Abort!" + exit 1 +fi +openocd -f $CONFIG_GEN -f $CONFIG_IF -f $CONFIG_CHIP -c "init;halt;dump_image $DUMP 0x100000 0x80000;exit" diff --git a/tools/jtag_openocd/openocd_flash_recovery.sh b/tools/jtag_openocd/openocd_flash_recovery.sh index b51076d5a..2e88c52e6 100755 --- a/tools/jtag_openocd/openocd_flash_recovery.sh +++ b/tools/jtag_openocd/openocd_flash_recovery.sh @@ -1,12 +1,9 @@ #!/bin/bash -# Example using Segger Jlink: -CONFIG_CHIP=chip-at91sam7s.cfg -CONFIG_IF=interface-jlink.cfg -IMAGE=../../recovery/proxmark3_recovery.bin +. openocd_configuration || exit 1 if [ ! -e "$IMAGE" ]; then echo "$IMAGE missing. Abort!" exit 1 fi -openocd -f $CONFIG_IF -f $CONFIG_CHIP -c "init;halt;flash erase_sector 0 0 15;flash erase_sector 1 0 15;flash write_image $IMAGE 0x100000;exit" +openocd -f $CONFIG_GEN -f $CONFIG_IF -f $CONFIG_CHIP -c "init;halt;flash erase_sector 0 0 15;flash erase_sector 1 0 15;flash write_image $IMAGE 0x100000;exit" diff --git a/tools/jtag_openocd/openocd_interactive.sh b/tools/jtag_openocd/openocd_interactive.sh new file mode 100755 index 000000000..ea7919da8 --- /dev/null +++ b/tools/jtag_openocd/openocd_interactive.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +. openocd_configuration || exit 1 + +echo "*********************************************" +echo "Connect to OpenOCD via: telnet localhost $(awk '/^telnet_port/{print$2}' $CONFIG_GEN)" +echo "*********************************************" +openocd -f $CONFIG_GEN -f $CONFIG_IF -f $CONFIG_CHIP diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 93b7229ce..ea535fd73 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -238,7 +238,8 @@ void uart_close(const serial_port sp) { // Does the system allows us to place a lock on this file descriptor int err = fcntl(spu->fd, F_SETLK, &fl); if (err == -1) { - //perror("fcntl"); + //silent error message as it can be called from uart_open failing modes, e.g. when waiting for port to appear + //printf("[!] UART error while closing port\n"); } close(spu->fd); free(sp);