From 2597c7576ed46cb655c1b2f15f87a646bdb7af26 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 10 Jul 2025 11:52:39 +0200 Subject: [PATCH] style --- client/Makefile | 2 + client/deps/mqtt/posix_sockets.h | 4 +- client/deps/mqtt/win32_sockets.h | 2 +- client/dictionaries/mfc_default_keys.dic | 2 +- client/luascripts/kybercrystals.lua | 30 +++++++-------- client/luascripts/lf_awid_bulkclone.lua | 14 +++---- client/luascripts/lf_electra.lua | 2 +- client/luascripts/lf_hid_bulkclone_v2.lua | 6 +-- client/luascripts/lf_ioprox_bulkclone.lua | 2 +- client/luascripts/lf_t55xx_fix.lua | 4 +- client/luascripts/paxton_clone.lua | 14 +++---- client/src/cmdhf14b.c | 2 +- client/src/cmdhfcryptorf.c | 3 +- client/src/cmdhffelica.c | 2 +- client/src/cmdhffudan.c | 2 +- client/src/cmdhflto.c | 2 +- client/src/cmdhftexkom.c | 2 +- client/src/cmdhftopaz.c | 4 +- client/src/cmdhfxerox.c | 2 +- client/src/cmdlfdestron.c | 2 +- client/src/cmdlffdxb.c | 2 +- client/src/cmdlfgallagher.c | 2 +- client/src/cmdlfhitaghts.c | 2 +- client/src/cmdlfidteck.c | 2 +- client/src/cmdlfindala.c | 2 +- client/src/cmdlfio.c | 2 +- client/src/cmdlfjablotron.c | 2 +- client/src/cmdlfkeri.c | 2 +- client/src/cmdlfmotorola.c | 2 +- client/src/cmdlfnedap.c | 2 +- client/src/cmdlfnexwatch.c | 2 +- client/src/cmdlfnoralsy.c | 2 +- client/src/cmdlfpac.c | 2 +- client/src/cmdlfparadox.c | 2 +- client/src/cmdlfpcf7931.c | 2 +- client/src/cmdlfpresco.c | 2 +- client/src/cmdlfpyramid.c | 2 +- client/src/cmdlfsecurakey.c | 2 +- client/src/cmdlfti.c | 2 +- client/src/cmdlfviking.c | 2 +- client/src/cmdlfvisa2000.c | 2 +- client/src/cmdlfzx8211.c | 2 +- client/src/cmdmqtt.c | 7 +++- client/src/cmdsmartcard.c | 2 +- client/src/fileutils.c | 6 +++ client/src/fileutils.h | 1 + client/src/uart/uart_common.c | 19 +++++---- client/src/util.c | 1 + common/crc16.c | 47 +++++++++++++++-------- doc/commands.json | 4 +- 50 files changed, 135 insertions(+), 99 deletions(-) diff --git a/client/Makefile b/client/Makefile index 2c0f7ef04..de90a5f5c 100644 --- a/client/Makefile +++ b/client/Makefile @@ -452,6 +452,7 @@ endif ifeq ($(SWIG_LUA_FOUND),1) PM3CFLAGS += -DHAVE_LUA_SWIG endif + ifeq ($(SWIG_PYTHON_FOUND),1) PM3CFLAGS += -DHAVE_PYTHON_SWIG endif @@ -594,6 +595,7 @@ endif ifeq ($(SWIG_LUA_FOUND),1) $(info Lua SWIG: wrapper found) endif + ifeq ($(SWIG_PYTHON_FOUND),1) $(info Python SWIG: wrapper found) endif diff --git a/client/deps/mqtt/posix_sockets.h b/client/deps/mqtt/posix_sockets.h index d44e1c374..42954f640 100644 --- a/client/deps/mqtt/posix_sockets.h +++ b/client/deps/mqtt/posix_sockets.h @@ -53,7 +53,7 @@ int open_nb_socket(const char *addr, const char *port) { break; } - // free servinfo + // free servinfo freeaddrinfo(servinfo); // make non-blocking @@ -70,4 +70,4 @@ void close_nb_socket(int sockfd) { } } #endif -#endif \ No newline at end of file +#endif diff --git a/client/deps/mqtt/win32_sockets.h b/client/deps/mqtt/win32_sockets.h index 20a774a63..4775bb851 100644 --- a/client/deps/mqtt/win32_sockets.h +++ b/client/deps/mqtt/win32_sockets.h @@ -29,7 +29,7 @@ mqtt_pal_socket_handle open_nb_socket(const char *addr, const char *port) { hints.ai_protocol = IPPROTO_TCP; // struct addrinfo *p, *servinfo; - // get address information + // get address information int rv = getaddrinfo(addr, port, &hints, &servinfo); if (rv != 0) { fprintf(stderr, "error: getaddrinfo: %s", gai_strerror(rv)); diff --git a/client/dictionaries/mfc_default_keys.dic b/client/dictionaries/mfc_default_keys.dic index 465431dd8..eeeaecc23 100644 --- a/client/dictionaries/mfc_default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -2542,7 +2542,7 @@ FAB943906E9C # R.A.T.T transport card key A/B AA034F342A55 456776908C48 - +# # BusFacil - Brazilian public transport card for some cities fae9b14365a9 c567dd4a6004 diff --git a/client/luascripts/kybercrystals.lua b/client/luascripts/kybercrystals.lua index 70306842b..1b707768b 100644 --- a/client/luascripts/kybercrystals.lua +++ b/client/luascripts/kybercrystals.lua @@ -2,7 +2,7 @@ Simple script to program DIY kyber crystals works on real kyber crystals and EM4305 2.12x12mm chips simply run the program and select a profile via a number - + issues if you are getting errors when trying to read or write a chip run the cmd "lf tune" with no chip on the device, then move the chip over the coils till you see the lowest voltage. try different angles and in the center and or the edge of the antenna ring. @@ -10,7 +10,7 @@ if thats still not working run "lf tune" again and put the chip in the best position like before the total voltage may be too high to reduce it slowly lower tin foil over the antenna and watch the voltage. the foil should be a bit bigger than the coil exact size does not matter. - + data pulled from here https://docs.google.com/spreadsheets/d/13P_GE6tNYpGvoVUTEQvA3SQzMqpZ-SoiWaTNoJoTV9Q/edit?usp=sharing --]] @@ -663,12 +663,12 @@ function get_profile_data(profile_name) [9] = "010D0000" } } - + -- When called without arguments, return the whole table if not profile_name then return profiles end - + -- Otherwise return the specific profile or wipe chip return profiles[profile_name] or profiles["wipe chip"] end @@ -676,7 +676,7 @@ end function get_profile_names() -- Get the complete profiles table from get_profile_data local all_profiles = get_profile_data() - + local names = {} for name, _ in pairs(all_profiles) do table.insert(names, name) @@ -687,16 +687,16 @@ end function select_profile() local profile_names = get_profile_names() - + print("\nAvailable profiles:") for i, name in ipairs(profile_names) do print(string.format("%d. %s", i, name)) end - + while true do io.write("\nSelect profile (1-" .. #profile_names .. "): ") local choice = tonumber(io.read()) - + if choice and choice >= 1 and choice <= #profile_names then return profile_names[choice] else @@ -707,40 +707,40 @@ end function main() print("\n[=== kyber crystal programmer ===]") - + -- Get profile from command line argument or prompt user local profile_name = args and args[1] if not profile_name then --print("\nNo profile specified as argument.") profile_name = select_profile() end - + local data_to_write = get_profile_data(profile_name) print("\n[+] Using profile: " .. profile_name) - + -- Display what will be written print("\n[+] Data to be written:") for addr, data in pairs(data_to_write) do print(string.format("Address %d: %s", addr, data)) end - + -- Step 1: Wipe the tag print("\n[+] Wiping tag...") send_command("lf em 4x05 wipe --4305") - + -- Step 2: Write data print("\n[+] Writing data...") for addr, data in pairs(data_to_write) do send_command("lf em 4x05 write -a " .. addr .. " -d " .. data) utils.Sleep(0.5) end - + -- Step 3: Read back and display data for verification print("\n[+] Verifying writes by reading back data...") for addr, expected_data in pairs(data_to_write) do local output = send_command("lf em 4x05 read -a " .. addr) end - + print("\n[+] Read complete. Review output above.") end diff --git a/client/luascripts/lf_awid_bulkclone.lua b/client/luascripts/lf_awid_bulkclone.lua index 63394aa99..3fa145ec2 100644 --- a/client/luascripts/lf_awid_bulkclone.lua +++ b/client/luascripts/lf_awid_bulkclone.lua @@ -10,7 +10,7 @@ For more info, check the comments in the code ]] example = [[ -- - script run lf_awid_bulkclone.lua -f 1 -b 1000 + script run lf_awid_bulkclone.lua -f 1 -b 1000 ]] usage = [[ script run lf_awid_bulkclone.lua -f facility -b base_id_num @@ -91,7 +91,7 @@ local function main(args) end end if o == 'b' then - if isempty(a) then + if isempty(a) then print('You did not supply a starting card number, using 59615') cn = 59615 else @@ -105,18 +105,18 @@ local function main(args) print("Session Start: " .. sessionStart) print("Facility Code,Card Number") - + while true do print(string.format("Preparing to Write: Facility Code %d, Card Number %d", fc, cn)) - + local command = string.format("lf awid clone --fmt 26 --fc %d --cn %d", fc, cn) core.console(command) - + print(string.format("%d,%d", fc, cn)) - + print("Press Enter to continue with the next card number or type 'q' and press Enter to quit.") local user_input = io.read() - + if user_input:lower() == 'q' then break else diff --git a/client/luascripts/lf_electra.lua b/client/luascripts/lf_electra.lua index 7502522e8..2c130ba7a 100644 --- a/client/luascripts/lf_electra.lua +++ b/client/luascripts/lf_electra.lua @@ -145,7 +145,7 @@ local function readfile() local f = io.open(ID_STATUS, "r") for line in f:lines() do id = line:match"^(%x+)" - if id then break end + if id then break end end f:close() if not id then diff --git a/client/luascripts/lf_hid_bulkclone_v2.lua b/client/luascripts/lf_hid_bulkclone_v2.lua index 31615d19d..50762e8f1 100644 --- a/client/luascripts/lf_hid_bulkclone_v2.lua +++ b/client/luascripts/lf_hid_bulkclone_v2.lua @@ -14,7 +14,7 @@ example = [[ script run lf_hid_bulkclone_v2.lua -f 1 -b 1000 ]] usage = [[ -script run lf_hid_bulkclone_v2.lua -f facility -b base_id_num +script run lf_hid_bulkclone_v2.lua -f facility -b base_id_num ]] arguments = [[ -h : this help @@ -67,7 +67,7 @@ local function exitMsg(msg) end local function main(args) - + print( string.rep('--',20) ) print( string.rep('--',20) ) print() @@ -107,7 +107,7 @@ local function main(args) print("Press Enter to write the next card, type 'r' and press Enter to retry, or type 'q' and press Enter to quit.") local user_input = io.read() - + if user_input:lower() == 'q' then print("Timestamp: ", timestamp) print("Successful Writes:") diff --git a/client/luascripts/lf_ioprox_bulkclone.lua b/client/luascripts/lf_ioprox_bulkclone.lua index 37e9c4ce9..31fb91e76 100644 --- a/client/luascripts/lf_ioprox_bulkclone.lua +++ b/client/luascripts/lf_ioprox_bulkclone.lua @@ -69,7 +69,7 @@ local function exitMsg(msg) end local function main(args) - + print( string.rep('--',20) ) print( string.rep('--',20) ) print() diff --git a/client/luascripts/lf_t55xx_fix.lua b/client/luascripts/lf_t55xx_fix.lua index cfdffc8f0..b793cf629 100644 --- a/client/luascripts/lf_t55xx_fix.lua +++ b/client/luascripts/lf_t55xx_fix.lua @@ -18,7 +18,7 @@ desc = [[ is found, it uses the wipe command to erase the T5577. Then the reanimation procedure is applied. If the password is not found or doesn't exist the script only performs the reanimation procedure. The script revives 99% of blocked tags. -]] + ]] usage = [[ script run lf_t55xx_fix ]] @@ -87,7 +87,7 @@ local function reanimate_t5577(password) p:console('lf t55 wipe -p ' .. password) print("T5577 wiped using a password: " ..ac.green.. password ..ac.reset) else - print(ac.yellow.."No valid password found, proceeding with reanimation."..ac.reset) + print(ac.yellow.." No valid password found, proceeding with reanimation."..ac.reset) end p:console('lf t55 write -b 0 -d 000880E8 -p 00000000') diff --git a/client/luascripts/paxton_clone.lua b/client/luascripts/paxton_clone.lua index b8aaf2a9d..c4fb206be 100644 --- a/client/luascripts/paxton_clone.lua +++ b/client/luascripts/paxton_clone.lua @@ -15,10 +15,10 @@ command('clear') author = ' Author: jareckib - 30.01.2025' tutorial = ' Based on Equipter tutorial - Downgrade Paxton to EM4102' version = ' version v1.20' -desc = [[ - The script automates the copying of Paxton fobs read - write. - It also allows manual input of data for blocks 4-7. - The third option is reading data stored in the log file and create new fob. +desc = [[ + The script automates the copying of Paxton fobs read - write. + It also allows manual input of data for blocks 4-7. + The third option is reading data stored in the log file and create new fob. Additionally, the script calculates the ID for downgrading Paxton to EM4102. ]] @@ -61,7 +61,7 @@ local function reset_log_file() file:write("") file:close() end - + local function read_log_file(logfile) local file = io.open(logfile, "r") if not file then @@ -331,7 +331,7 @@ local function main(args) print(ac.cyan .. ' 1' .. ac.reset .. ' - Read Paxton blocks 4-7 to make a copy') print(ac.cyan .. ' 2' .. ac.reset .. ' - Manually input data for Paxton blocks 4-7') print(ac.cyan .. " 3" .. ac.reset .. " - Search in Paxton_log by name and use the data") - print(dash) + print(dash) while true do io.write(' Your choice '..ac.cyan..'(1/2/3): ' .. ac.reset) input_option = io.read() @@ -428,7 +428,7 @@ local function main(args) was_option_3 = true local retries = 3 while retries > 0 do - io.write(' Enter the name to search ('..retries..' attempts) : '..ac.yellow) + io.write(' Enter the name to search ('..retries..' attempts) : '..ac.yellow) local user_input = io.read() io.write(ac.reset..'') if user_input == nil or user_input:match("^%s*$") then diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index f61d7d1fb..7d05c2e75 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -3073,7 +3073,7 @@ plot: } } - } while (loop && kbd_enter_pressed() == false); + } while (loop && (kbd_enter_pressed() == false)); if (verbose && found == false) { PrintAndLogEx(FAILED, "no ISO 14443-B tag found"); diff --git a/client/src/cmdhfcryptorf.c b/client/src/cmdhfcryptorf.c index af703e511..1a00881e1 100644 --- a/client/src/cmdhfcryptorf.c +++ b/client/src/cmdhfcryptorf.c @@ -232,8 +232,7 @@ int readHFCryptoRF(bool loop, bool verbose) { PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex_inrow(card.uid, card.uidlen)); set_last_known_card(card); } - } while (loop && kbd_enter_pressed() == false); - + } while (loop && (kbd_enter_pressed() == false)); DropField(); return res; } diff --git a/client/src/cmdhffelica.c b/client/src/cmdhffelica.c index 278b301c4..3b2a53b49 100644 --- a/client/src/cmdhffelica.c +++ b/client/src/cmdhffelica.c @@ -348,7 +348,7 @@ int read_felica_uid(bool loop, bool verbose) { res = PM3_SUCCESS; } - } while (loop && kbd_enter_pressed() == false); + } while (loop && (kbd_enter_pressed() == false)); DropField(); return res; diff --git a/client/src/cmdhffudan.c b/client/src/cmdhffudan.c index 52ed3bc5f..817749353 100644 --- a/client/src/cmdhffudan.c +++ b/client/src/cmdhffudan.c @@ -199,7 +199,7 @@ int read_fudan_uid(bool loop, bool verbose) { PrintAndLogEx(NORMAL, ""); } - } while (loop && kbd_enter_pressed() == false); + } while (loop && (kbd_enter_pressed() == false)); return PM3_SUCCESS; diff --git a/client/src/cmdhflto.c b/client/src/cmdhflto.c index 51ede17ca..1eadb3d67 100644 --- a/client/src/cmdhflto.c +++ b/client/src/cmdhflto.c @@ -438,7 +438,7 @@ int reader_lto(bool loop, bool verbose) { PrintAndLogEx(INFO, "UID......... " _GREEN_("%s"), sprint_hex_inrow(serial, sizeof(serial))); } - } while (loop && kbd_enter_pressed() == false); + } while (loop && (kbd_enter_pressed() == false)); lto_switch_off_field(); return ret; diff --git a/client/src/cmdhftexkom.c b/client/src/cmdhftexkom.c index 6993d70cf..8a6cee6f2 100644 --- a/client/src/cmdhftexkom.c +++ b/client/src/cmdhftexkom.c @@ -623,7 +623,7 @@ int read_texkom_uid(bool loop, bool verbose) { } } - } while (loop && kbd_enter_pressed() == false); + } while (loop && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdhftopaz.c b/client/src/cmdhftopaz.c index 05069a35b..ca3efdaa3 100644 --- a/client/src/cmdhftopaz.c +++ b/client/src/cmdhftopaz.c @@ -109,7 +109,7 @@ static int topaz_select(uint8_t *atqa, uint8_t atqa_len, uint8_t *rid_response, } // read all of the static memory of a selected Topaz tag. -static int topaz_rall(uint8_t *uid, uint8_t *response) { +static int topaz_rall(const uint8_t *uid, uint8_t *response) { uint16_t resp_len = 124; uint8_t rall_cmd[] = {TOPAZ_RALL, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -1180,7 +1180,7 @@ int readTopazUid(bool loop, bool verbose) { topaz_tag.HR01[0] = rid_response[0]; topaz_tag.HR01[1] = rid_response[1]; - } while (loop && kbd_enter_pressed() == false); + } while (loop && (kbd_enter_pressed() == false)); topaz_switch_off_field(); return res; diff --git a/client/src/cmdhfxerox.c b/client/src/cmdhfxerox.c index 0bec9a1d9..713b7f616 100644 --- a/client/src/cmdhfxerox.c +++ b/client/src/cmdhfxerox.c @@ -593,7 +593,7 @@ int read_xerox_uid(bool loop, bool verbose) { return PM3_ESOFT; } - } while (loop && kbd_enter_pressed() == false); + } while (loop && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfdestron.c b/client/src/cmdlfdestron.c index c8cd6c596..a9c6b1bd2 100644 --- a/client/src/cmdlfdestron.c +++ b/client/src/cmdlfdestron.c @@ -129,7 +129,7 @@ static int CmdDestronReader(const char *Cmd) { do { lf_read(false, 16000); demodDestron(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlffdxb.c b/client/src/cmdlffdxb.c index c3034f98f..853c10dde 100644 --- a/client/src/cmdlffdxb.c +++ b/client/src/cmdlffdxb.c @@ -692,7 +692,7 @@ static int CmdFdxBReader(const char *Cmd) { lf_read(false, 10000); ret = demodFDXB(!cm); // be verbose only if not in continuous mode - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); if (old_div != curr_div) { diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index b4955290d..98e6bf524 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -132,7 +132,7 @@ static int CmdGallagherReader(const char *Cmd) { do { lf_read(false, 4096 * 2 + 20); demodGallagher(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfhitaghts.c b/client/src/cmdlfhitaghts.c index f474e1bd1..8af7dc998 100644 --- a/client/src/cmdlfhitaghts.c +++ b/client/src/cmdlfhitaghts.c @@ -968,7 +968,7 @@ static int CmdLFHitagSReader(const char *Cmd) { if (hts_get_uid(&uid)) { PrintAndLogEx(SUCCESS, "UID.... " _GREEN_("%08X"), uid); } - } while (cm && kbd_enter_pressed() == false); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfidteck.c b/client/src/cmdlfidteck.c index fa498ea74..b6976fe4d 100644 --- a/client/src/cmdlfidteck.c +++ b/client/src/cmdlfidteck.c @@ -315,7 +315,7 @@ static int CmdIdteckReader(const char *Cmd) { do { lf_read(false, 5000); demodIdteck(NULL, !cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index 87ad4d833..53cd2647a 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -632,7 +632,7 @@ static int CmdIndalaReader(const char *Cmd) { do { lf_read(false, 30000); demodIndalaEx(clk, invert, max_err, !cm); - } while (cm && !kbd_enter_pressed()); + } while (cm & (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index 865b2b74a..a56b6b3a0 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -202,7 +202,7 @@ static int CmdIOProxReader(const char *Cmd) { do { lf_read(false, 12000); demodIOProx(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfjablotron.c b/client/src/cmdlfjablotron.c index 290181ae7..d0f9305d8 100644 --- a/client/src/cmdlfjablotron.c +++ b/client/src/cmdlfjablotron.c @@ -152,7 +152,7 @@ static int CmdJablotronReader(const char *Cmd) { do { lf_read(false, 16000); demodJablotron(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfkeri.c b/client/src/cmdlfkeri.c index fc599a646..4fc5cac72 100644 --- a/client/src/cmdlfkeri.c +++ b/client/src/cmdlfkeri.c @@ -221,7 +221,7 @@ static int CmdKeriReader(const char *Cmd) { do { lf_read(false, 10000); demodKeri(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfmotorola.c b/client/src/cmdlfmotorola.c index 99caaa7a3..04cf7fe20 100644 --- a/client/src/cmdlfmotorola.c +++ b/client/src/cmdlfmotorola.c @@ -179,7 +179,7 @@ static int CmdMotorolaReader(const char *Cmd) { // 64 * 32 * 2 * n-ish lf_read(false, 5000); res = demodMotorola(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); // reset back to 125 kHz sc.divisor = LF_DIVISOR_125; diff --git a/client/src/cmdlfnedap.c b/client/src/cmdlfnedap.c index ac6bea204..ac50d4851 100644 --- a/client/src/cmdlfnedap.c +++ b/client/src/cmdlfnedap.c @@ -296,7 +296,7 @@ static int CmdLFNedapReader(const char *Cmd) { do { lf_read(false, 16000); demodNedap(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfnexwatch.c b/client/src/cmdlfnexwatch.c index b1a162817..505ca6d7e 100644 --- a/client/src/cmdlfnexwatch.c +++ b/client/src/cmdlfnexwatch.c @@ -287,7 +287,7 @@ static int CmdNexWatchReader(const char *Cmd) { do { lf_read(false, 20000); demodNexWatch(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfnoralsy.c b/client/src/cmdlfnoralsy.c index 2a0fbd2b2..b10ee7f97 100644 --- a/client/src/cmdlfnoralsy.c +++ b/client/src/cmdlfnoralsy.c @@ -150,7 +150,7 @@ static int CmdNoralsyReader(const char *Cmd) { do { lf_read(false, 8000); demodNoralsy(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfpac.c b/client/src/cmdlfpac.c index 8d9dbebf4..8d00c40df 100644 --- a/client/src/cmdlfpac.c +++ b/client/src/cmdlfpac.c @@ -214,7 +214,7 @@ static int CmdPacReader(const char *Cmd) { do { lf_read(false, 4096 * 2 + 20); demodPac(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfparadox.c b/client/src/cmdlfparadox.c index dae518311..71aa19ebe 100644 --- a/client/src/cmdlfparadox.c +++ b/client/src/cmdlfparadox.c @@ -285,7 +285,7 @@ static int CmdParadoxReader(const char *Cmd) { do { lf_read(false, 10000); demodParadox(!cm, old); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfpcf7931.c b/client/src/cmdlfpcf7931.c index ae19b174f..df18617dc 100644 --- a/client/src/cmdlfpcf7931.c +++ b/client/src/cmdlfpcf7931.c @@ -84,7 +84,7 @@ static int CmdLFPCF7931Reader(const char *Cmd) { PrintAndLogEx(WARNING, "command execution time out"); return PM3_ETIMEOUT; } - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfpresco.c b/client/src/cmdlfpresco.c index a3f1c89e2..969a054ce 100644 --- a/client/src/cmdlfpresco.c +++ b/client/src/cmdlfpresco.c @@ -160,7 +160,7 @@ static int CmdPrescoReader(const char *Cmd) { do { lf_read(false, 12000); demodPresco(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfpyramid.c b/client/src/cmdlfpyramid.c index 9e24c319b..e763c68e3 100644 --- a/client/src/cmdlfpyramid.c +++ b/client/src/cmdlfpyramid.c @@ -231,7 +231,7 @@ static int CmdPyramidReader(const char *Cmd) { do { lf_read(false, 15000); demodPyramid(true); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfsecurakey.c b/client/src/cmdlfsecurakey.c index f4e381e42..30e997421 100644 --- a/client/src/cmdlfsecurakey.c +++ b/client/src/cmdlfsecurakey.c @@ -161,7 +161,7 @@ static int CmdSecurakeyReader(const char *Cmd) { do { lf_read(false, 8000); demodSecurakey(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfti.c b/client/src/cmdlfti.c index 4664a344d..17d843a7c 100644 --- a/client/src/cmdlfti.c +++ b/client/src/cmdlfti.c @@ -325,7 +325,7 @@ static int CmdTIReader(const char *Cmd) { do { clearCommandBuffer(); SendCommandNG(CMD_LF_TI_READ, NULL, 0); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfviking.c b/client/src/cmdlfviking.c index 6807e828c..7c206af4b 100644 --- a/client/src/cmdlfviking.c +++ b/client/src/cmdlfviking.c @@ -102,7 +102,7 @@ static int CmdVikingReader(const char *Cmd) { do { lf_read(false, 10000); demodViking(true); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfvisa2000.c b/client/src/cmdlfvisa2000.c index 7de1e9334..092f38e30 100644 --- a/client/src/cmdlfvisa2000.c +++ b/client/src/cmdlfvisa2000.c @@ -185,7 +185,7 @@ static int CmdVisa2kReader(const char *Cmd) { do { lf_read(false, 20000); demodVisa2k(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdlfzx8211.c b/client/src/cmdlfzx8211.c index 03fcd6053..793cc3d54 100644 --- a/client/src/cmdlfzx8211.c +++ b/client/src/cmdlfzx8211.c @@ -138,7 +138,7 @@ static int CmdzxReader(const char *Cmd) { do { lf_Zx_read(); demodzx(!cm); - } while (cm && !kbd_enter_pressed()); + } while (cm && (kbd_enter_pressed() == false)); return PM3_SUCCESS; } diff --git a/client/src/cmdmqtt.c b/client/src/cmdmqtt.c index ace6c62c1..e805f473d 100644 --- a/client/src/cmdmqtt.c +++ b/client/src/cmdmqtt.c @@ -30,12 +30,17 @@ #include "util_posix.h" // time #include "fileutils.h" - #define MQTT_BUFFER_SIZE ( 1 << 16 ) static int CmdHelp(const char *Cmd); static void mqtt_publish_callback(void **unused, struct mqtt_response_publish *published) { + + if (published == NULL) { + return; + } + + // note that published->topic_name is NOT null-terminated (here we'll change it to a c-string) char *topic_name = (char *) calloc(published->topic_name_size + 1, 1); memcpy(topic_name, published->topic_name, published->topic_name_size); diff --git a/client/src/cmdsmartcard.c b/client/src/cmdsmartcard.c index 46b467f94..6e1c67ba5 100644 --- a/client/src/cmdsmartcard.c +++ b/client/src/cmdsmartcard.c @@ -1469,7 +1469,7 @@ static int CmdPCSC(const char *Cmd) { msleep(300); } - } while (!kbd_enter_pressed()); + } while (kbd_enter_pressed() == false); mbedtls_net_close(&netCtx); mbedtls_net_free(&netCtx); diff --git a/client/src/fileutils.c b/client/src/fileutils.c index 805235e42..4ab0b7595 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -89,6 +89,8 @@ DumpFileType_t get_filetype(const char *filename) { o = FLIPPER; } else if (str_endswith(s, "picopass")) { o = FLIPPER; + } else if (str_endswith(s, "xml")) { + o = TAGINFO; } else { // mfd, trc, trace is binary o = BIN; @@ -3323,6 +3325,10 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl } break; } + case TAGINFO: { + //res = loadFileXML_safe(fn, ".xml", pdump, dumplen); + break; + } } return res; } diff --git a/client/src/fileutils.h b/client/src/fileutils.h index bbb548fb9..a2d31c196 100644 --- a/client/src/fileutils.h +++ b/client/src/fileutils.h @@ -83,6 +83,7 @@ typedef enum { DICTIONARY, MCT, FLIPPER, + TAGINFO, } DumpFileType_t; typedef enum { diff --git a/client/src/uart/uart_common.c b/client/src/uart/uart_common.c index e10897326..f797d763c 100644 --- a/client/src/uart/uart_common.c +++ b/client/src/uart/uart_common.c @@ -39,31 +39,36 @@ #endif bool uart_bind(void *socket, const char *bindAddrStr, const char *bindPortStr, bool isBindingIPv6) { - if (bindAddrStr == NULL && bindPortStr == NULL) + if (bindAddrStr == NULL && bindPortStr == NULL) { return true; // no need to bind + } struct sockaddr_storage bindSockaddr; memset(&bindSockaddr, 0, sizeof(bindSockaddr)); int bindPort = 0; // 0: port unspecified - if (bindPortStr != NULL) + if (bindPortStr != NULL) { bindPort = atoi(bindPortStr); + } - if (!isBindingIPv6) { + if (isBindingIPv6 == false) { struct sockaddr_in *bindSockaddr4 = (struct sockaddr_in *)&bindSockaddr; bindSockaddr4->sin_family = AF_INET; bindSockaddr4->sin_port = htons(bindPort); - if (bindAddrStr == NULL) + if (bindAddrStr == NULL) { bindSockaddr4->sin_addr.s_addr = INADDR_ANY; - else + } else { bindSockaddr4->sin_addr.s_addr = inet_addr(bindAddrStr); + } + } else { struct sockaddr_in6 *bindSockaddr6 = (struct sockaddr_in6 *)&bindSockaddr; bindSockaddr6->sin6_family = AF_INET6; bindSockaddr6->sin6_port = htons(bindPort); - if (bindAddrStr == NULL) + if (bindAddrStr == NULL) { bindSockaddr6->sin6_addr = in6addr_any; - else + } else { inet_pton(AF_INET6, bindAddrStr, &(bindSockaddr6->sin6_addr)); + } } #ifdef _WIN32 int res = bind(*(SOCKET *)socket, (struct sockaddr *)&bindSockaddr, sizeof(bindSockaddr)); diff --git a/client/src/util.c b/client/src/util.c index ff71b74e1..133f639ee 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -73,6 +73,7 @@ int kbd_enter_pressed(void) { c = getchar(); ret |= c == '\n'; } while (c != EOF); + //blocking flags &= ~O_NONBLOCK; if (fcntl(STDIN_FILENO, F_SETFL, flags) < 0) { diff --git a/common/crc16.c b/common/crc16.c index e55b20bdc..ecf8c1ed7 100644 --- a/common/crc16.c +++ b/common/crc16.c @@ -27,12 +27,14 @@ static CrcType_t current_crc_type = CRC_NONE; void init_table(CrcType_t crctype) { // same crc algo, and initialised already - if (crctype == current_crc_type && crc_table_init) + if (crctype == current_crc_type && crc_table_init) { return; + } // not the same crc algo. reset table. - if (crctype != current_crc_type) + if (crctype != current_crc_type) { reset_table(); + } current_crc_type = crctype; @@ -68,23 +70,29 @@ void init_table(CrcType_t crctype) { void generate_table(uint16_t polynomial, bool refin) { for (uint16_t i = 0; i < 256; i++) { + uint16_t c, crc = 0; - if (refin) + + if (refin) { c = reflect8(i) << 8; - else + } else { c = i << 8; + } for (uint16_t j = 0; j < 8; j++) { - if ((crc ^ c) & 0x8000) + if ((crc ^ c) & 0x8000) { crc = (crc << 1) ^ polynomial; - else + } else { crc = crc << 1; + } c = c << 1; } - if (refin) + + if (refin) { crc = reflect16(crc); + } crc_table[i] = crc; } @@ -102,21 +110,25 @@ uint16_t crc16_fast(uint8_t const *d, size_t n, uint16_t initval, bool refin, bo // fast lookup table algorithm without augmented zero bytes, e.g. used in pkzip. // only usable with polynom orders of 8, 16, 24 or 32. - if (n == 0) + if (n == 0) { return (~initval); + } uint16_t crc = initval; - if (refin) + if (refin) { crc = reflect16(crc); + } - if (!refin) + if (refin == false) { while (n--) crc = (crc << 8) ^ crc_table[((crc >> 8) ^ *d++) & 0xFF ]; - else + } else { while (n--) crc = (crc >> 8) ^ crc_table[(crc & 0xFF) ^ *d++]; + } - if (refout ^ refin) + if (refout ^ refin) { crc = reflect16(crc); + } return crc; } @@ -143,8 +155,9 @@ uint16_t update_crc16(uint16_t crc, uint8_t c) { // two ways. msb or lsb loop. uint16_t Crc16(uint8_t const *d, size_t bitlength, uint16_t remainder, uint16_t polynomial, bool refin, bool refout) { - if (bitlength == 0) + if (bitlength == 0) { return (~remainder); + } uint8_t offset = 8 - (bitlength % 8); // front padding with 0s won't change the CRC result @@ -153,7 +166,9 @@ uint16_t Crc16(uint8_t const *d, size_t bitlength, uint16_t remainder, uint16_t uint8_t c = prebits | d[i] >> offset; prebits = d[i] << (8 - offset); - if (refin) c = reflect8(c); + if (refin) { + c = reflect8(c); + } // xor in at msb remainder ^= (c << 8); @@ -167,8 +182,10 @@ uint16_t Crc16(uint8_t const *d, size_t bitlength, uint16_t remainder, uint16_t } } } - if (refout) + + if (refout) { remainder = reflect16(remainder); + } return remainder; } diff --git a/doc/commands.json b/doc/commands.json index 0d4ab0c28..2c1c2b02a 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -12363,7 +12363,7 @@ "--addr MQTT server address", "-p, --port MQTT server port", "--topic MQTT topic", - "-f, --file file to send" + "-f, --file file name to use for received files" ], "usage": "mqtt receive [-h] [--addr ] [-p ] [--topic ] [-f ]" }, @@ -13413,6 +13413,6 @@ "metadata": { "commands_extracted": 770, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2025-07-08T19:08:23" + "extracted_on": "2025-07-10T05:07:28" } }