From 0cd6e950b0d2b62c243141ca82a7d1cb89038d1f Mon Sep 17 00:00:00 2001 From: jakkpotts Date: Sun, 20 Oct 2024 02:47:55 -0700 Subject: [PATCH 1/3] Fixed syntax error in flags declaration in hf_young.c --- armsrc/Standalone/hf_young.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/Standalone/hf_young.c b/armsrc/Standalone/hf_young.c index a887c2bb5..1356e2954 100644 --- a/armsrc/Standalone/hf_young.c +++ b/armsrc/Standalone/hf_young.c @@ -236,7 +236,7 @@ void RunMod(void) { int button_pressed = BUTTON_HELD(1000); if (button_pressed == BUTTON_NO_CLICK) { // No button action, proceed with sim - uint16_t flags = 0 + uint16_t flags = 0; FLAG_SET_UID_IN_DATA(flags, 4); uint8_t data[PM3_CMD_DATA_SIZE] = {0}; // in case there is a read command received we shouldn't break From 177be842bd82ee365ad7b5856d10b6d9a018b283 Mon Sep 17 00:00:00 2001 From: jakkpotts Date: Sun, 20 Oct 2024 02:51:53 -0700 Subject: [PATCH 2/3] Added changelog entry for fixing syntax on hf_young --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447280308..b77839ee8 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] +- Fixed 'hf_young.c' - flags declaration was missing a semicolon (@jakkpotts) - Changed `hf mf sim` - add option to allow key b to be used even if readable (@doegox) - Changed `data num` - outputed binary strings are now properly zero padded (@iceman1001) - Changed `hf iclass info` - now tries default keys and decode if legacy (@iceman1001) From 70cc7765f373c3ecc1b13ce16580826891dade4f Mon Sep 17 00:00:00 2001 From: Adam Jon Foster Date: Mon, 21 Oct 2024 23:16:05 +0800 Subject: [PATCH 3/3] Update cmdhfgallagher.c Added CmdGallagherEncode to allow someone to encode their own credentials into a raw and bitwise format without having it go onto a specific technology type. Signed-off-by: Adam Jon Foster --- client/src/cmdhfgallagher.c | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index b83bfd455..4165856b0 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -1311,6 +1311,52 @@ static int CmdGallagherDecode(const char *cmd) { return PM3_SUCCESS; } +static int CmdGallagherEncode (const char *cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf gallagher encode", + "Encode a Gallagher credential block\n" + "Credential block can be specified with or without the bitwise inverse.", + "hf gallagher encode --rc 1 --fc 22153 --cn 1253518 --il 1" + ); + + void *argtable[] = { + arg_param_begin, + arg_u64_1("r", "rc", "", "Region code. 4 bits max"), + arg_u64_1("f", "fc", "", "Facility code. 2 bytes max"), + arg_u64_1("c", "cn", "", "Card number. 3 bytes max"), + arg_u64_1("i", "il", "", "Issue level. 4 bits max"), + arg_param_end + }; + CLIExecWithReturn(ctx, cmd, argtable, false); + + uint64_t region_code = arg_get_u64(ctx, 1); // uint4, input will be validated later + uint64_t facility_code = arg_get_u64(ctx, 2); // uint16 + uint64_t card_number = arg_get_u64(ctx, 3); // uint24 + uint64_t issue_level = arg_get_u64(ctx, 4); // uint4 + + CLIParserFree(ctx); + + GallagherCredentials_t creds = { + .region_code = region_code, + .facility_code = facility_code, + .card_number = card_number, + .issue_level = issue_level, + }; + + + uint8_t contents[16] = {0}; + + gallagher_encode_creds(contents, &creds); + for (int i = 0; i < 8; i++) { + contents[i + 8] = contents[i] ^ 0xFF; + } + + PrintAndLogEx(SUCCESS, "Raw: " _YELLOW_("%s"), sprint_hex_inrow(contents, ARRAYLEN(contents)/2)); + PrintAndLogEx(SUCCESS, "Bitwise: " _YELLOW_("%s"), sprint_hex_inrow(contents, ARRAYLEN(contents))); + + return PM3_SUCCESS; +} + static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, @@ -1319,6 +1365,7 @@ static command_t CommandTable[] = { {"delete", CmdGallagherDelete, IfPm3Iso14443, "Delete Gallagher credentials from a DESFire card"}, {"diversifykey", CmdGallagherDiversify, AlwaysAvailable, "Diversify Gallagher key"}, {"decode", CmdGallagherDecode, AlwaysAvailable, "Decode Gallagher credential block"}, + {"encode", CmdGallagherEncode, AlwaysAvailable, "Encode Gallagher credential block"}, {NULL, NULL, NULL, NULL} };