From 81c1625bfc7755c702f42676dde6cd07ade34241 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 10 Oct 2019 14:52:51 +0200 Subject: [PATCH 1/9] cov settings --- .coverity.conf.sample | 6 +++++- covbuild.sh | 39 +++++++++++++++++++++++++++++++-------- covconfig.sh | 3 +++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.coverity.conf.sample b/.coverity.conf.sample index 3ed4be64b..5caf5d6fb 100644 --- a/.coverity.conf.sample +++ b/.coverity.conf.sample @@ -4,9 +4,13 @@ COVTOKEN=aAbBcCdDeEfFgGhHiIjJkK COVBINDIR="/opt/cov-analysis-linux64-2019.03/bin" # Nickname included in scan description: NICKNAME=myself +# cov can't read gcov from gcc > 7 +HOSTCC=gcc-7 +HOSTCXX=g++-7 +HOSTLD=g++-7 +# Do not change it: COVDIR=cov-int -COVBUILD="cov-build --dir $COVDIR" # Depending if your kernel > 4.8.x, you might need to activate this to run Coverity executables # (but latest tools with kernel 5.2 run fine) diff --git a/covbuild.sh b/covbuild.sh index bd06630d4..4784a1de6 100755 --- a/covbuild.sh +++ b/covbuild.sh @@ -5,16 +5,39 @@ set -e pre_build_hook -rm -rf "$COVDIR" -mkdir "$COVDIR" +mkdir -p "$COVDIR" make clean -$COVBUILD make -j 4 bootrom -$COVBUILD make -j 4 fullimage -$COVBUILD make -j 4 mfkey -$COVBUILD make -j 4 nonce2key -$COVBUILD make -j 4 fpga_compress +cov-build --dir "$COVDIR" --initialize + +######################################### +# Build Host prerequisites # +######################################### +cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --no-generate-build-id --force make CC=$HOSTCC CXX=$HOSTCXX LD=$HOSTLD fpga_compress + +######################################### +# Build ARM, no test coverage # +######################################### +cov-build --dir "$COVDIR" --no-generate-build-id --force make bootrom +cov-build --dir "$COVDIR" --no-generate-build-id --force make fullimage + +######################################### +# Build client # +######################################### # make sure to do client after ARM because Coverity retains one build info per file # and we want the client-side of the common/ analysis -$COVBUILD make -j 4 client +cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --no-generate-build-id --force make CC=$HOSTCC CXX=$HOSTCXX LD=$HOSTLD mfkey +cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --no-generate-build-id --force make CC=$HOSTCC CXX=$HOSTCXX LD=$HOSTLD nonce2key +cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --no-generate-build-id --force make CC=$HOSTCC CXX=$HOSTCXX LD=$HOSTLD client + +######################################### +# Run tests # +######################################### +cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --test-capture ./pm3test.sh +#cov-manage-emit --dir "$COVDIR" list-coverage-known + +######################################### +# Import Git annotations (~ git blame) # +######################################### +cov-import-scm --dir "$COVDIR" --scm git --filename-regex "$PWD" --log ""$COVDIR"/cov-import-scm-log.txt" post_build_hook diff --git a/covconfig.sh b/covconfig.sh index 5f4878b3c..24815f200 100755 --- a/covconfig.sh +++ b/covconfig.sh @@ -3,4 +3,7 @@ set -e . .coverity.conf || exit 1 +# cov-configure --list-configured-compilers text cov-configure --template --compiler arm-none-eabi-gcc --comptype gcc +# cov can't read gcov from gcc > 7 +cov-configure --template --compiler $HOSTCC --comptype gcc From d61a7b4a0fd6599436379646703c1df4da8577b4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 10 Oct 2019 15:10:22 +0200 Subject: [PATCH 2/9] textual --- client/cmdlfindala.c | 62 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index 0668fedd6..8926d9007 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -137,44 +137,42 @@ static int CmdIndalaDemod(const char *Cmd) { p1 |= DemodBuffer[32 + 24] << 9; uint8_t fc = 0; - fc |= DemodBuffer[32+25] << 7; // b8 - fc |= DemodBuffer[32+17] << 6; // b7 - fc |= DemodBuffer[32+12] << 5; // b6 - fc |= DemodBuffer[32+16] << 4; // b5 - fc |= DemodBuffer[32+15] << 3; // b4 - fc |= DemodBuffer[32+21] << 2; // b3 - fc |= DemodBuffer[32+7] << 1; // b2 - fc |= DemodBuffer[32+26] << 0; // b1 - + fc |= DemodBuffer[57] << 7; // b8 + fc |= DemodBuffer[49] << 6; // b7 + fc |= DemodBuffer[44] << 5; // b6 + fc |= DemodBuffer[48] << 4; // b5 + fc |= DemodBuffer[47] << 3; // b4 + fc |= DemodBuffer[53] << 2; // b3 + fc |= DemodBuffer[39] << 1; // b2 + fc |= DemodBuffer[58] << 0; // b1 + uint16_t csn = 0; - csn |= DemodBuffer[32+10] << 15; // b16 - csn |= DemodBuffer[32+13] << 14; // b15 - csn |= DemodBuffer[32+11] << 13; // b14 - csn |= DemodBuffer[32+8] << 12; // b13 - csn |= DemodBuffer[32+20] << 11; // b12 - csn |= DemodBuffer[32+4] << 10; // b11 - csn |= DemodBuffer[32+3] << 9; // b10 - csn |= DemodBuffer[32+19] << 8; // b9 - csn |= DemodBuffer[32+14] << 7; // b8 - csn |= DemodBuffer[32+1] << 6; // b7 - csn |= DemodBuffer[32+5] << 5; // b6 - csn |= DemodBuffer[32+22] << 4; // b5 - csn |= DemodBuffer[32+24] << 3; // b4 - csn |= DemodBuffer[32+27] << 2; // b3 - csn |= DemodBuffer[32+18] << 1; // b2 - csn |= DemodBuffer[32+9] << 0; // b1 - - uint8_t checksum = 0; - checksum |= DemodBuffer[32+30] << 1; // b2 - checksum |= DemodBuffer[92+31] << 0; // b1 + csn |= DemodBuffer[42] << 15; // b16 + csn |= DemodBuffer[45] << 14; // b15 + csn |= DemodBuffer[43] << 13; // b14 + csn |= DemodBuffer[40] << 12; // b13 + csn |= DemodBuffer[52] << 11; // b12 + csn |= DemodBuffer[36] << 10; // b11 + csn |= DemodBuffer[35] << 9; // b10 + csn |= DemodBuffer[51] << 8; // b9 + csn |= DemodBuffer[46] << 7; // b8 + csn |= DemodBuffer[33] << 6; // b7 + csn |= DemodBuffer[37] << 5; // b6 + csn |= DemodBuffer[54] << 4; // b5 + csn |= DemodBuffer[56] << 3; // b4 + csn |= DemodBuffer[59] << 2; // b3 + csn |= DemodBuffer[50] << 1; // b2 + csn |= DemodBuffer[41] << 0; // b1 + + uint8_t checksum = 0; + checksum |= DemodBuffer[62] << 1; // b2 + checksum |= DemodBuffer[63] << 0; // b1 PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, "Possible de-scramble patterns"); PrintAndLogEx(SUCCESS, "\tPrinted | __%04d__ [0x%X]", p1, p1); - //PrintAndLogEx(SUCCESS, "\tPrinted | __%04d__ [0x%X]", fc, fc); PrintAndLogEx(SUCCESS, "\tInternal ID | %" PRIu64, foo); - PrintAndLogEx(SUCCESS, "\nFC %u , CSN %u , checksum %1d%1d", fc, csn, checksum >> 1 & 0x01, checksum & 0x01 ); - + PrintAndLogEx(SUCCESS, "Fmt 26 bit FC %u , CSN %u , checksum %1d%1d", fc, csn, checksum >> 1 & 0x01, checksum & 0x01 ); } else { uint32_t uid3 = bytebits_to_byte(DemodBuffer + 64, 32); From 602067da4a508dd3c199e5aadf467c1707e2c82d Mon Sep 17 00:00:00 2001 From: martinbeier Date: Thu, 10 Oct 2019 15:32:27 +0200 Subject: [PATCH 3/9] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f6996545..102cd8590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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] + - Chg ´lf indala read´ - added indala 26bit decoding (@martinbeier) - Added lf t55xx detected to try without password first (@mwalker33) - Display high bit for detected Kastle HIDs to allow `lf hid clone [id]` to work properly (@swg0101) - Add option `-n` to scripts pm3* (@doegox) From baffd45d5ae5923e32d6d1cf6c95f9998a727927 Mon Sep 17 00:00:00 2001 From: martinbeier Date: Thu, 10 Oct 2019 16:01:54 +0200 Subject: [PATCH 4/9] fixed indala FC decoding --- client/cmdlfindala.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmdlfindala.c b/client/cmdlfindala.c index 8926d9007..c93d695aa 100644 --- a/client/cmdlfindala.c +++ b/client/cmdlfindala.c @@ -140,8 +140,8 @@ static int CmdIndalaDemod(const char *Cmd) { fc |= DemodBuffer[57] << 7; // b8 fc |= DemodBuffer[49] << 6; // b7 fc |= DemodBuffer[44] << 5; // b6 - fc |= DemodBuffer[48] << 4; // b5 - fc |= DemodBuffer[47] << 3; // b4 + fc |= DemodBuffer[47] << 4; // b5 + fc |= DemodBuffer[48] << 3; // b4 fc |= DemodBuffer[53] << 2; // b3 fc |= DemodBuffer[39] << 1; // b2 fc |= DemodBuffer[58] << 0; // b1 From 973c1c71cf6b22f2c7c5d9645bfdd40e0f259392 Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 10 Oct 2019 16:27:33 +0200 Subject: [PATCH 5/9] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 102cd8590..86b768210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ 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] - - Chg ´lf indala read´ - added indala 26bit decoding (@martinbeier) - - Added lf t55xx detected to try without password first (@mwalker33) + - Chg `lf indala read` - added indala 26bit decoding (@martinbeier) + - Chg `lf t55xx detect` to try without password first (@mwalker33) - Display high bit for detected Kastle HIDs to allow `lf hid clone [id]` to work properly (@swg0101) - Add option `-n` to scripts pm3* (@doegox) - Add `wiegand list/encode/decode` - wiegand format manipulation. Adapted to fit here. (@grauerfuchs) From 6781eeae1eb3d84a47d50fce91517728d8a01f43 Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 11 Oct 2019 09:32:51 +0200 Subject: [PATCH 6/9] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f5b35569..8ff5a3b61 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,10 @@ On the software side: quite a lot, see the [Changelog file](CHANGELOG.md). ## Development -This repo now compiles just fine on +⚠ **Note**: This is a bleeding edge repository. The maintainers actively is working out of this repository and will be periodically re-structuring the code to make it easier to comprehend, navigate, build, test, and contribute to, so **DO expect significant changes to code layout on a regular basis**. + + +This repo compiles nicely on - Proxspace v3.2 - Windows/mingw environment with Qt5.6.1 & GCC 4.8 - Ubuntu 1404, 1510, 1604, 1804, 1904 @@ -54,8 +57,9 @@ This repo now compiles just fine on - WSL, WSL2 (Windows subsystem linux) on Windows 10 - Docker container -If you intend to contribute to the code, please read the [coding style notes](HACKING.md) first. +👉 **Remember** If you intend to contribute to the code, please read the [coding style notes](HACKING.md) first. +## Notes / helpful documents - Internal notes on [Coverity Scan Config & Run](/doc/md/Development/Coverity-Scan-Config-%26-Run.md). - Internal notes on [UART](/doc/uart_notes.md) - Internal notes on [Frame format](/doc/new_frame_format.md) From b2fb2677743a89e4775a48e159ac2180788cbddb Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 11 Oct 2019 09:34:55 +0200 Subject: [PATCH 7/9] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ff5a3b61..7386baf10 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ This repo compiles nicely on - WSL, WSL2 (Windows subsystem linux) on Windows 10 - Docker container -👉 **Remember** If you intend to contribute to the code, please read the [coding style notes](HACKING.md) first. +👉 **Remember!** If you intend to contribute to the code, please read the [coding style notes](HACKING.md) first. +We usually merge your contributions fast since we do like the idea of getting a functionality in the Proxmark3 and weed out the bugs afterwards. ## Notes / helpful documents - Internal notes on [Coverity Scan Config & Run](/doc/md/Development/Coverity-Scan-Config-%26-Run.md). From f5d0fdf2a1aec7b0f1f98741999c3bc429e78b5e Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 11 Oct 2019 09:36:09 +0200 Subject: [PATCH 8/9] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7386baf10..62c3add53 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,7 @@ On the software side: quite a lot, see the [Changelog file](CHANGELOG.md). ## Development -⚠ **Note**: This is a bleeding edge repository. The maintainers actively is working out of this repository and will be periodically re-structuring the code to make it easier to comprehend, navigate, build, test, and contribute to, so **DO expect significant changes to code layout on a regular basis**. - +> ⚠ **Note**: This is a bleeding edge repository. The maintainers actively is working out of this repository and will be periodically re-structuring the code to make it easier to comprehend, navigate, build, test, and contribute to, so **DO expect significant changes to code layout on a regular basis**. This repo compiles nicely on - Proxspace v3.2 @@ -57,7 +56,7 @@ This repo compiles nicely on - WSL, WSL2 (Windows subsystem linux) on Windows 10 - Docker container -👉 **Remember!** If you intend to contribute to the code, please read the [coding style notes](HACKING.md) first. +> 👉 **Remember!** If you intend to contribute to the code, please read the [coding style notes](HACKING.md) first. We usually merge your contributions fast since we do like the idea of getting a functionality in the Proxmark3 and weed out the bugs afterwards. ## Notes / helpful documents From 9c82f84fa7ab49d1147c9fd18193280e108fbcae Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 11 Oct 2019 11:26:14 +0200 Subject: [PATCH 9/9] analyze demodbuff - fill demodbuffer with binary from client --- client/cmdanalyse.c | 59 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index 733c741c7..6f3af2247 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -12,7 +12,7 @@ #include // size_t #include #include // tolower - +#include // printf #include "commonutil.h" // reflect... #include "comms.h" // clearCommandBuffer #include "cmdparser.h" // command_t @@ -21,6 +21,7 @@ #include "crc16.h" // crc16 ccitt #include "tea.h" #include "legic_prng.h" +#include "cmddata.h" // demodbuffer static int CmdHelp(const char *Cmd); @@ -36,7 +37,7 @@ static int usage_analyse_lcr(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " analyse lcr 04008064BA"); PrintAndLogEx(NORMAL, "expected output: Target (BA) requires final LRC XOR byte value: 5A"); - return 0; + return PM3_SUCCESS; } static int usage_analyse_checksum(void) { PrintAndLogEx(NORMAL, "The bytes will be added with eachother and than limited with the applied mask"); @@ -52,7 +53,7 @@ static int usage_analyse_checksum(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " analyse chksum b 137AF00A0A0D m FF"); PrintAndLogEx(NORMAL, "expected output: 0x61"); - return 0; + return PM3_SUCCESS; } static int usage_analyse_crc(void) { PrintAndLogEx(NORMAL, "A stub method to test different crc implementations inside the PM3 sourcecode. Just because you figured out the poly, doesn't mean you get the desired output"); @@ -64,7 +65,7 @@ static int usage_analyse_crc(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " analyse crc 137AF00A0A0D"); - return 0; + return PM3_SUCCESS; } static int usage_analyse_nuid(void) { PrintAndLogEx(NORMAL, "Generate 4byte NUID from 7byte UID"); @@ -76,7 +77,7 @@ static int usage_analyse_nuid(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " analyse nuid 11223344556677"); - return 0; + return PM3_SUCCESS; } static int usage_analyse_a(void) { PrintAndLogEx(NORMAL, "Iceman's personal garbage test command"); @@ -88,7 +89,19 @@ static int usage_analyse_a(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " analyse a d 137AF00A0A0D"); - return 0; + return PM3_SUCCESS; +} +static int usage_analyse_demodbuffer(void) { + PrintAndLogEx(NORMAL, "loads a binary string into demod buffer"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Usage: analyse demodbuff [h] "); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h This help"); + PrintAndLogEx(NORMAL, " Binary string to load"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " analyse demodbuff 0011101001001011"); + return PM3_SUCCESS; } static uint8_t calculateLRC(uint8_t *bytes, uint8_t len) { @@ -878,6 +891,39 @@ static int CmdAnalyseNuid(const char *Cmd) { PrintAndLogEx(NORMAL, "NUID | %s \n", sprint_hex(nuid, 4)); return 0; } + +static int CmdAnalyseDemodBuffer(const char *Cmd) { + + char cmdp = tolower(param_getchar(Cmd, 0)); + if (strlen(Cmd) == 0 || cmdp == 'h') return usage_analyse_demodbuffer(); + + int bg = 0, en = 0; + if (param_getptr(Cmd, &bg, &en, 0)) + return usage_analyse_demodbuffer(); + + int len = MIN( (en- bg + 1), MAX_DEMOD_BUF_LEN); + + // add 1 for null terminator. + uint8_t *data = calloc(len + 1, sizeof(uint8_t)); + if (!data) return PM3_EMALLOC; + + for(int i = 0; bg <= en; bg++ , i++) { + char c = Cmd[bg]; + if (c == '1') + DemodBuffer[i] = 1; + if (c == '0') + DemodBuffer[i] = 0; + + printf("%c", c); + } + + printf("\n"); + + DemodBufferLen = len; + free(data); + return PM3_SUCCESS; +} + static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"lcr", CmdAnalyseLCR, AlwaysAvailable, "Generate final byte for XOR LRC"}, @@ -888,6 +934,7 @@ static command_t CommandTable[] = { {"lfsr", CmdAnalyseLfsr, AlwaysAvailable, "LFSR tests"}, {"a", CmdAnalyseA, AlwaysAvailable, "num bits test"}, {"nuid", CmdAnalyseNuid, AlwaysAvailable, "create NUID from 7byte UID"}, + {"demodbuff", CmdAnalyseDemodBuffer, AlwaysAvailable, "Load binary string to demodbuffer"}, {NULL, NULL, NULL, NULL} };