From 89e098c773a53f103a88afaaaa17f01b369e448c Mon Sep 17 00:00:00 2001 From: unkernet Date: Sun, 10 Aug 2025 14:43:19 +0700 Subject: [PATCH] Make CLI compatible with Python 3.9 - Replace Python 3.10+ type hint syntax (`int | None`) with `Union[int, None]`. - Add explicit `byteorder='big'` argument to all `int.from_bytes()` calls. --- software/script/chameleon_cli_unit.py | 2 +- software/script/chameleon_cmd.py | 4 ++-- software/script/chameleon_utils.py | 2 +- software/script/tests/test_hard_acquire.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index c1938c6..b4b9972 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -421,7 +421,7 @@ class LFHIDIdArgsUnit(DeviceRequiredUnit): return parser @staticmethod - def check_limits(format: int, fc: int | None, cn: int | None, il: int | None, oem: int | None): + def check_limits(format: int, fc: Union[int, None], cn: Union[int, None], il: Union[int, None], oem: Union[int, None]): limits = { HIDFormat.H10301: [0xFF, 0xFFFF, 0, 0], HIDFormat.IND26: [0xFFF, 0xFFF, 0, 0], diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index de7bc93..b7a0cdf 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -409,7 +409,7 @@ class ChameleonCMD: resp.parsed['nts']['a'].append( { 'nt': reconstruct_full_nt(resp.data, i), - 'nt_enc': int.from_bytes(resp.data[i + 3: i + 7]), + 'nt_enc': int.from_bytes(resp.data[i + 3: i + 7], byteorder='big'), 'parity': parity_to_str(resp.data[i + 2]) } ) @@ -417,7 +417,7 @@ class ChameleonCMD: resp.parsed['nts']['b'].append( { 'nt': reconstruct_full_nt(resp.data, i + 7), - 'nt_enc': int.from_bytes(resp.data[i + 10: i + 14]), + 'nt_enc': int.from_bytes(resp.data[i + 10: i + 14], byteorder='big'), 'parity': parity_to_str(resp.data[i + 9]) } ) diff --git a/software/script/chameleon_utils.py b/software/script/chameleon_utils.py index 60669af..8effa5e 100644 --- a/software/script/chameleon_utils.py +++ b/software/script/chameleon_utils.py @@ -164,7 +164,7 @@ def prng_successor(x, n): def reconstruct_full_nt(response_data, offset): - nt = int.from_bytes(response_data[offset: offset + 2]) + nt = int.from_bytes(response_data[offset: offset + 2], byteorder='big') return (nt << 16) | prng_successor(nt, 16) diff --git a/software/script/tests/test_hard_acquire.py b/software/script/tests/test_hard_acquire.py index f0ef424..8568aa1 100644 --- a/software/script/tests/test_hard_acquire.py +++ b/software/script/tests/test_hard_acquire.py @@ -69,8 +69,8 @@ def test_hardnested_acquire(): while data_check_index < len(acquire_datas): # Memory Layout: nt_enc1(4byte) - nt_enc2(4byte) - par(1byte)... # To integer - nt_enc1 = int.from_bytes(acquire_datas[data_check_index + 0: data_check_index + 0 + 4]) - nt_enc2 = int.from_bytes(acquire_datas[data_check_index + 4: data_check_index + 4 + 4]) + nt_enc1 = int.from_bytes(acquire_datas[data_check_index + 0: data_check_index + 0 + 4], byteorder='big') + nt_enc2 = int.from_bytes(acquire_datas[data_check_index + 4: data_check_index + 4 + 4], byteorder='big') par_enc = acquire_datas[data_check_index + 8] # check unique and sum hardnested_utils.check_nonce_unique_sum(nt_enc1, par_enc >> 4)