Skip to content

Commit

Permalink
pep287
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Oct 23, 2023
1 parent ff3df15 commit d77e166
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 40 deletions.
4 changes: 3 additions & 1 deletion software/script/chameleon_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ def get_prompt(self):
@staticmethod
def print_banner():
"""
print chameleon ascii banner
print chameleon ascii banner.
:return:
"""
print(f"{CY}{BANNER}{C0}")

def startCLI(self):
"""
start listen input.
:return:
"""
if sys.version_info < (3, 9):
Expand Down
15 changes: 11 additions & 4 deletions software/script/chameleon_cli_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,32 @@ def cmd(self) -> chameleon_cmd.ChameleonCMD:

def args_parser(self) -> ArgumentParserNoExit:
"""
CMD unit args
CMD unit args.
:return:
"""
raise NotImplementedError("Please implement this")

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")

def after_exec(self, args: argparse.Namespace):
"""
Call a function after exec cmd.
:return: function references
"""
return True
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand Down
92 changes: 62 additions & 30 deletions software/script/chameleon_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
"""
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -284,15 +295,17 @@ 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)

@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:
"""
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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:
"""
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
"""
Expand All @@ -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:
"""
Expand All @@ -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)
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit d77e166

Please sign in to comment.