diff --git a/software/script/chameleon_cli_main.py b/software/script/chameleon_cli_main.py index 337ca142..107b5145 100755 --- a/software/script/chameleon_cli_main.py +++ b/software/script/chameleon_cli_main.py @@ -80,7 +80,8 @@ def get_prompt(self): @staticmethod def print_banner(): """ - print chameleon ascii banner + print chameleon ascii banner. + :return: """ print(f"{CY}{BANNER}{C0}") @@ -88,6 +89,7 @@ def print_banner(): def startCLI(self): """ start listen input. + :return: """ if sys.version_info < (3, 9): diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index 9aeee923..c6d07dea 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -70,7 +70,8 @@ def cmd(self) -> chameleon_cmd.ChameleonCMD: def args_parser(self) -> ArgumentParserNoExit: """ - CMD unit args + CMD unit args. + :return: """ raise NotImplementedError("Please implement this") @@ -78,13 +79,15 @@ def args_parser(self) -> ArgumentParserNoExit: def before_exec(self, args: argparse.Namespace): """ Call a function before exec cmd. + :return: function references """ return True def on_exec(self, args: argparse.Namespace): """ - Call a function on cmd match + Call a function on cmd match. + :return: function references """ raise NotImplementedError("Please implement this") @@ -92,6 +95,7 @@ def on_exec(self, args: argparse.Namespace): def after_exec(self, args: argparse.Namespace): """ Call a function after exec cmd. + :return: function references """ return True @@ -663,7 +667,8 @@ def from_nt_level_code_to_str(self, nt_level): def recover_a_key(self, block_known, type_known, key_known, block_target, type_target) -> str or None: """ - recover a key from key known + recover a key from key known. + :param block_known: :param type_known: :param key_known: @@ -769,7 +774,8 @@ def args_parser(self) -> ArgumentParserNoExit: def recover_key(self, block_target, type_target): """ - Execute darkside acquisition and decryption + Execute darkside acquisition and decryption. + :param block_target: :param type_target: :return: @@ -877,6 +883,7 @@ def args_parser(self) -> ArgumentParserNoExit: def decrypt_by_list(self, rs: list): """ Decrypt key from reconnaissance log list + :param rs: :return: """ diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index 2c515a7c..130d6579 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -72,7 +72,8 @@ def get_device_mode(self): def is_device_reader_mode(self) -> bool: """ - Get device mode, reader or tag + Get device mode, reader or tag. + :return: True is reader mode, else tag mode """ return self.get_device_mode() @@ -85,7 +86,8 @@ def change_device_mode(self, mode): def set_device_reader_mode(self, reader_mode: bool = True): """ - Change device mode, reader or tag + Change device mode, reader or tag. + :param reader_mode: True if reader mode, False if tag mode. :return: """ @@ -94,7 +96,8 @@ def set_device_reader_mode(self, reader_mode: bool = True): @expect_response(Status.HF_TAG_OK) def hf14a_scan(self): """ - 14a tags in the scanning field + 14a tags in the scanning field. + :return: """ resp = self.device.send_cmd_sync(Command.HF14A_SCAN) @@ -115,7 +118,8 @@ def hf14a_scan(self): def mf1_detect_support(self): """ - Detect whether it is mifare classic tag + Detect whether it is mifare classic tag. + :return: """ resp = self.device.send_cmd_sync(Command.MF1_DETECT_SUPPORT) @@ -124,7 +128,8 @@ def mf1_detect_support(self): @expect_response(Status.HF_TAG_OK) def mf1_detect_prng(self): """ - detect mifare Class of classic nt vulnerabilities + Detect mifare Class of classic nt vulnerabilities. + :return: """ resp = self.device.send_cmd_sync(Command.MF1_DETECT_PRNG) @@ -135,7 +140,8 @@ def mf1_detect_prng(self): @expect_response(Status.HF_TAG_OK) def mf1_detect_nt_dist(self, block_known, type_known, key_known): """ - Detect the random number distance of the card + Detect the random number distance of the card. + :return: """ data = struct.pack('!BB6s', type_known, block_known, key_known) @@ -161,7 +167,8 @@ def mf1_nested_acquire(self, block_known, type_known, key_known, block_target, t @expect_response(Status.HF_TAG_OK) def mf1_darkside_acquire(self, block_target, type_target, first_recover: int or bool, sync_max): """ - Collect the key parameters needed for Darkside decryption + Collect the key parameters needed for Darkside decryption. + :param block_target: :param type_target: :param first_recover: @@ -181,7 +188,8 @@ def mf1_darkside_acquire(self, block_target, type_target, first_recover: int or @expect_response([Status.HF_TAG_OK, Status.MF_ERR_AUTH]) def mf1_auth_one_key_block(self, block, type_value, key): """ - Verify the mf1 key, only verify the specified type of key for a single sector + Verify the mf1 key, only verify the specified type of key for a single sector. + :param block: :param type_value: :param key: @@ -195,7 +203,8 @@ def mf1_auth_one_key_block(self, block, type_value, key): @expect_response(Status.HF_TAG_OK) def mf1_read_one_block(self, block, type_value, key): """ - read one mf1 block + Read one mf1 block. + :param block: :param type_value: :param key: @@ -207,7 +216,8 @@ def mf1_read_one_block(self, block, type_value, key): @expect_response(Status.HF_TAG_OK) def mf1_write_one_block(self, block, type_value, key, block_data): """ - Write mf1 single block + Write mf1 single block. + :param block: :param type_value: :param key: @@ -222,7 +232,8 @@ def mf1_write_one_block(self, block, type_value, key, block_data): @expect_response(Status.HF_TAG_OK) def hf14a_raw(self, options, resp_timeout_ms=100, data=[], bitlen=None): """ - Send raw cmd to 14a tag + Send raw cmd to 14a tag. + :param options: :param resp_timeout_ms: :param data: @@ -284,7 +295,8 @@ def mf1_static_nested_acquire(self, block_known, type_known, key_known, block_ta @expect_response(Status.LF_TAG_OK) def em410x_scan(self): """ - Read the card number of EM410X + Read the card number of EM410X. + :return: """ return self.device.send_cmd_sync(Command.EM410X_SCAN) @@ -292,7 +304,8 @@ def em410x_scan(self): @expect_response(Status.LF_TAG_OK) def em410x_write_to_t55xx(self, id_bytes: bytes): """ - Write EM410X card number into T55XX + Write EM410X card number into T55XX. + :param id_bytes: ID card number :return: """ @@ -306,7 +319,8 @@ def em410x_write_to_t55xx(self, id_bytes: bytes): @expect_response(Status.SUCCESS) def get_slot_info(self): """ - Get slots info + Get slots info. + :return: """ resp = self.device.send_cmd_sync(Command.GET_SLOT_INFO) @@ -318,7 +332,8 @@ def get_slot_info(self): @expect_response(Status.SUCCESS) def get_active_slot(self): """ - Get selected slot + Get selected slot. + :return: """ resp = self.device.send_cmd_sync(Command.GET_ACTIVE_SLOT) @@ -329,7 +344,8 @@ def get_active_slot(self): @expect_response(Status.SUCCESS) def set_active_slot(self, slot_index: SlotNumber): """ - Set the card slot currently active for use + Set the card slot currently active for use. + :param slot_index: Card slot index :return: """ @@ -342,7 +358,8 @@ def set_slot_tag_type(self, slot_index: SlotNumber, tag_type: TagSpecificType): """ Set the label type of the simulated card of the current card slot Note: This operation will not change the data in the flash, - and the change of the data in the flash will only be updated at the next save + and the change of the data in the flash will only be updated at the next save. + :param slot_index: Card slot number :param tag_type: label type :return: @@ -355,6 +372,7 @@ def set_slot_tag_type(self, slot_index: SlotNumber, tag_type: TagSpecificType): def delete_slot_sense_type(self, slot_index: SlotNumber, sense_type: TagSenseType): """ Delete a sense type for a specific slot. + :param slot_index: Slot index :param sense_type: Sense type to disable :return: @@ -366,7 +384,8 @@ def delete_slot_sense_type(self, slot_index: SlotNumber, sense_type: TagSenseTyp def set_slot_data_default(self, slot_index: SlotNumber, tag_type: TagSpecificType): """ Set the data of the simulated card in the specified card slot as the default data - Note: This API will set the data in the flash together + Note: This API will set the data in the flash together. + :param slot_index: Card slot number :param tag_type: The default label type to set :return: @@ -378,7 +397,8 @@ def set_slot_data_default(self, slot_index: SlotNumber, tag_type: TagSpecificTyp @expect_response(Status.SUCCESS) def set_slot_enable(self, slot_index: SlotNumber, sense_type: TagSenseType, enabled: bool): """ - Set whether the specified card slot is enabled + Set whether the specified card slot is enabled. + :param slot_index: Card slot number :param enable: Whether to enable :return: @@ -390,7 +410,8 @@ def set_slot_enable(self, slot_index: SlotNumber, sense_type: TagSenseType, enab @expect_response(Status.SUCCESS) def em410x_set_emu_id(self, id: bytes): """ - Set the card number simulated by EM410x + Set the card number simulated by EM410x. + :param id_bytes: byte of the card number :return: """ @@ -409,7 +430,8 @@ def em410x_get_emu_id(self): @expect_response(Status.SUCCESS) def mf1_set_detection_enable(self, enabled: bool): """ - Set whether to enable the detection of the current card slot + Set whether to enable the detection of the current card slot. + :param enable: Whether to enable :return: """ @@ -419,7 +441,8 @@ def mf1_set_detection_enable(self, enabled: bool): @expect_response(Status.SUCCESS) def mf1_get_detection_count(self): """ - Get the statistics of the current detection records + Get the statistics of the current detection records. + :return: """ resp = self.device.send_cmd_sync(Command.MF1_GET_DETECTION_COUNT) @@ -430,7 +453,8 @@ def mf1_get_detection_count(self): @expect_response(Status.SUCCESS) def mf1_get_detection_log(self, index: int): """ - Get detection logs from the specified index position + Get detection logs from the specified index position. + :param index: start index :return: """ @@ -458,10 +482,11 @@ def mf1_get_detection_log(self, index: int): @expect_response(Status.SUCCESS) def mf1_write_emu_block_data(self, block_start: int, block_data: bytes): """ - Set the block data of the analog card of MF1 + Set the block data of the analog card of MF1. + :param block_start: Start setting the location of block data, including this location - :param block_data: The byte buffer of the block data to be set - can contain multiple block data, automatically from block_start increment + :param block_data: The byte buffer of the block data to be set can contain multiple block data, + automatically from block_start increment :return: """ data = struct.pack(f'!B{len(block_data)}s', block_start, block_data) @@ -478,7 +503,8 @@ def mf1_read_emu_block_data(self, block_start: int, block_count: int): @expect_response(Status.SUCCESS) def hf14a_set_anti_coll_data(self, uid: bytes, atqa: bytes, sak: bytes, ats: bytes = b''): """ - Set anti-collision data of current HF slot (UID/SAK/ATQA/ATS) + Set anti-collision data of current HF slot (UID/SAK/ATQA/ATS). + :param uid: uid bytes :param atqa: atqa bytes :param sak: sak bytes @@ -491,7 +517,8 @@ def hf14a_set_anti_coll_data(self, uid: bytes, atqa: bytes, sak: bytes, ats: byt @expect_response(Status.SUCCESS) def set_slot_tag_nick(self, slot: SlotNumber, sense_type: TagSenseType, name: bytes): """ - Set the nick name of the slot + Set the nick name of the slot. + :param slot: Card slot number :param sense_type: field type :param name: Card slot nickname @@ -504,7 +531,8 @@ def set_slot_tag_nick(self, slot: SlotNumber, sense_type: TagSenseType, name: by @expect_response(Status.SUCCESS) def get_slot_tag_nick(self, slot: SlotNumber, sense_type: TagSenseType): """ - Get the nick name of the slot + Get the nick name of the slot. + :param slot: Card slot number :param sense_type: field type :return: @@ -516,7 +544,8 @@ def get_slot_tag_nick(self, slot: SlotNumber, sense_type: TagSenseType): @expect_response(Status.SUCCESS) def delete_slot_tag_nick(self, slot: SlotNumber, sense_type: TagSenseType): """ - Delete the nick name of the slot + Delete the nick name of the slot. + :param slot: Card slot number :param sense_type: field type :return: @@ -534,6 +563,7 @@ def mf1_get_emulator_config(self): [2] - mf1_is_gen2_magic_mode [3] - mf1_is_use_mf1_coll_res (use UID/BCC/SAK/ATQA from 0 block) [4] - mf1_get_write_mode + :return: """ resp = self.device.send_cmd_sync(Command.MF1_GET_EMULATOR_CONFIG) @@ -793,6 +823,7 @@ def get_device_settings(self): def hf14a_get_anti_coll_data(self): """ Get anti-collision data from current HF slot (UID/SAK/ATQA/ATS) + :return: """ resp = self.device.send_cmd_sync(Command.HF14A_GET_ANTI_COLL_DATA) @@ -812,6 +843,7 @@ def hf14a_get_anti_coll_data(self): def get_ble_pairing_enable(self): """ Is ble pairing enable? + :return: True if pairing is enable, False if pairing disabled """ resp = self.device.send_cmd_sync(Command.GET_BLE_PAIRING_ENABLE) diff --git a/software/script/chameleon_com.py b/software/script/chameleon_com.py index d4fa7241..34b63270 100644 --- a/software/script/chameleon_com.py +++ b/software/script/chameleon_com.py @@ -63,6 +63,7 @@ def __init__(self): def isOpen(self): """ Chameleon is connected and init. + :return: """ return self.serial_instance is not None and self.serial_instance.isOpen() @@ -71,6 +72,7 @@ def open(self, port): """ Open chameleon port to communication And init some variables + :param port: com port, comXXX or ttyXXX :return: """ @@ -111,7 +113,8 @@ def check_open(self): @staticmethod def lrc_calc(array): """ - calc lrc and auto cut byte + Calc lrc and auto cut byte. + :param array: value array :return: u8 result """ @@ -124,7 +127,8 @@ def lrc_calc(array): def close(self): """ - Close chameleon and clear variable + Close chameleon and clear variable. + :return: """ self.event_closing.set() @@ -139,7 +143,8 @@ def close(self): def thread_data_receive(self): """ - SubThread to receive data from chameleon device + Sub thread to receive data from chameleon device. + :return: """ data_buffer = bytearray() @@ -234,7 +239,8 @@ def thread_data_receive(self): def thread_data_transfer(self): """ - SubThread to transfer data to chameleon device + Sub thread to transfer data to chameleon device. + :return: """ while self.isOpen(): @@ -271,7 +277,8 @@ def thread_data_transfer(self): def thread_check_timeout(self): """ - Check task timeout + Check task timeout. + :return: """ while self.isOpen(): @@ -288,6 +295,7 @@ def thread_check_timeout(self): def make_data_frame_bytes(self, cmd: int, data: bytearray = None, status: int = 0) -> bytearray: """ Make data frame + :return: frame """ if data is None: @@ -306,6 +314,7 @@ def send_cmd_auto(self, cmd: int, data: bytearray = None, status: int = 0, callb close: bool = False): """ Send cmd to device + :param cmd: cmd :param data: bytes data (optional) :param status: status (optional) @@ -339,6 +348,7 @@ def send_cmd_sync(self, cmd: int, data: bytearray or bytes or list or int = None timeout: int = 3) -> Response: """ Send cmd to device, and block receive data. + :param cmd: cmd :param data: bytes data (optional) :param status: status (optional)