From f63ffd7d1f38754e3495d698b11140cfec1d3867 Mon Sep 17 00:00:00 2001 From: doomwastaken Date: Tue, 10 Oct 2023 12:08:18 +0300 Subject: [PATCH 1/6] added browser favorites --- .../img/ref/browser_head_Favorites.bmp | Bin 0 -> 6710 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 scripts/flippigator/img/ref/browser_head_Favorites.bmp diff --git a/scripts/flippigator/img/ref/browser_head_Favorites.bmp b/scripts/flippigator/img/ref/browser_head_Favorites.bmp new file mode 100644 index 0000000000000000000000000000000000000000..1a2ab1f364fdb6adbc34c049d3ff2d65853a361a GIT binary patch literal 6710 zcmd^+-A%+m41|vYXn-dkso)CWou26Y$Q*pq$ns`?1Il43v3F)X_9pKi*O$vZuG{-< zdp@`4d3&BNuiHD1+wGPUCqs3Q|M0B*Esyf=`6iG4|GDSteD?1)`#p}n|LlI=ziQVb zJXh`3>*IGBt$Sy->PPn}^|j8e>D)iliqCLi9%#TgyADhmYIx2W=a^~*de7fX&bh8s z&-VY8Z|VM;pK%$+uJ?wY7ntW#ujABY-=l`PcCYrGq7F{8MuL8PM?7jh%s}U}yoRr3 z{5;d+n0rUuIrWzK8cr`6U(a5<&hf04mJlB`VBpd^)>6kF=B>)?5a)pR=FG=;jeet? zd}81&Jk}!^Gon`s_Zjq%#r1~wQXi4E7rwnaW_rAoV>nmiy*KvJo8fTub4DxN>+B5X zS+%0n%N*D2Y2ixQeN-#r49DQe_lAZS^YP+5k~0rqA$pE-^2ugJ|CQ&Nd4A7Y?K{uR zbe~!s=hSxGWHnfpg@Mb1b5Gvu t%eV| Date: Fri, 13 Oct 2023 00:54:38 +0300 Subject: [PATCH 2/6] saving temp changes. ntag and mfc are under work. parser for pm3 needs full rewrite --- .github/workflows/smoke_tests.yml | 4 - .../flippigator/extensions/command_result.py | 4 +- .../extensions/proxmark_wrapper.py | 4 +- .../flippigator/flippigator/flippigator.py | 7 +- .../flippigator/img/ref/browser_T_mfc_4k7.bmp | Bin 0 -> 5014 bytes .../nfc/test_emulate_mifare_classic.py | 117 ++++++++++++++++++ .../flippigator/nfc/test_emulate_ntag213.py | 36 +----- 7 files changed, 130 insertions(+), 42 deletions(-) create mode 100644 scripts/flippigator/img/ref/browser_T_mfc_4k7.bmp create mode 100644 scripts/flippigator/nfc/test_emulate_mifare_classic.py diff --git a/.github/workflows/smoke_tests.yml b/.github/workflows/smoke_tests.yml index 2e1ee1398eb..cfc7faf6d22 100644 --- a/.github/workflows/smoke_tests.yml +++ b/.github/workflows/smoke_tests.yml @@ -3,11 +3,7 @@ name: 'Smoke tests' on: push: branches: - - dev - "release*" - tags: - - '*' - pull_request: env: TARGETS: f7 diff --git a/scripts/flippigator/flippigator/extensions/command_result.py b/scripts/flippigator/flippigator/extensions/command_result.py index 27ce6ea8555..55f40e3f839 100644 --- a/scripts/flippigator/flippigator/extensions/command_result.py +++ b/scripts/flippigator/flippigator/extensions/command_result.py @@ -13,8 +13,10 @@ def Result(self): def __init__(self, input): print("input: ", input) s = str(input).split("\n") + # remove empty lines + s = list(filter(None, s)) self.__Command = s[0] - self.__Result = s[1].removeprefix("[+] ").removesuffix(" ") + self.__Result = s[1:] class proxmark_command: diff --git a/scripts/flippigator/flippigator/extensions/proxmark_wrapper.py b/scripts/flippigator/flippigator/extensions/proxmark_wrapper.py index 00b79557000..b61594bec45 100644 --- a/scripts/flippigator/flippigator/extensions/proxmark_wrapper.py +++ b/scripts/flippigator/flippigator/extensions/proxmark_wrapper.py @@ -44,7 +44,7 @@ def execute(self, cmd) -> List[command_result]: result = self.__get_result(data_out) print("result: ", result[0]) - return result + return result[0] def shutdown(self): pass @@ -57,8 +57,8 @@ def __parse_data(self, output_data): raw_result = str(output_data).split("[usb|script] pm3 --> ") print("raw_result: ", raw_result) + print("-------------------------------------") result = [] for raw in raw_result[1:]: - print("raw: ", raw) result.append(command_result(raw).Result) return result diff --git a/scripts/flippigator/flippigator/flippigator.py b/scripts/flippigator/flippigator/flippigator.py index 351de9be62f..d261e62a69d 100644 --- a/scripts/flippigator/flippigator/flippigator.py +++ b/scripts/flippigator/flippigator/flippigator.py @@ -298,12 +298,15 @@ def get_first_item(self, browser: Optional[bool] = False): return menus - def go_to(self, target, area=(0, 64, 0, 128)): + def go_to(self, target, area=(0, 64, 0, 128), direction: Optional[str] = "down"): state = self.get_current_state(area=area) self.logger.info("Going to " + target) while not (target in state): - self.press_down() + if direction == "down": + self.press_down() + elif direction == "up": + self.press_up() state = self.get_current_state(area=area) def go_to_main_screen(self): diff --git a/scripts/flippigator/img/ref/browser_T_mfc_4k7.bmp b/scripts/flippigator/img/ref/browser_T_mfc_4k7.bmp new file mode 100644 index 0000000000000000000000000000000000000000..f72daac12eb1119d71c5b0054da4ced5a8d84a8b GIT binary patch literal 5014 zcmeH^!41Mt3`60{l?6C50RwPnBj#Y;@`Lmw*GgzhPvy7LZyd)C#sB_zoe!Vq*5224 zp6#64IUX+Uz5E%5VYz8{Y&wDc&NqF1>Bsw>PW7=wHG%zP8h#uvRe9xnr_R(fg=3z1 z@%2=-tX|b9-xKx>ruxXnHNWJwc1QSihvMpc=4dK!4}6tR#V^fd?H=_j V<~xG(!)&kP1hV|bioM%f0&jAhT=4(^ literal 0 HcmV?d00001 diff --git a/scripts/flippigator/nfc/test_emulate_mifare_classic.py b/scripts/flippigator/nfc/test_emulate_mifare_classic.py new file mode 100644 index 00000000000..cfe5895f601 --- /dev/null +++ b/scripts/flippigator/nfc/test_emulate_mifare_classic.py @@ -0,0 +1,117 @@ +import pytest +from flippigator.extensions.proxmark_wrapper import proxmark_wrapper +from flippigator.flippigator import FlipperHEXKeyboard, FlipperTextKeyboard +import time + + +class TestEmulateClassic: + + @pytest.fixture(scope="function", autouse=True) + def add_4k7_manually(self, nav): + # Code below will run before each "function" (test) + nav.go_to_main_screen() + + # Delete file if exists, needs to be added as picture sadly + nav.delete_file("NFC", "T_mfc_4k7") + nav.nfc.go_into() + nav.go_to("Add Manually") + nav.press_ok() + # direction for faster testing, since its last element + nav.go_to("Mifare Classic 4k 7byte UID", direction="up") + nav.press_ok() + nav.press_right() + nav.press_ok() + key = FlipperTextKeyboard(nav) + # if you need, you can make another fixture and use any "existing" file name in /img/ref + key.send("T_mfc_4k7\n") + nav.go_to_main_screen() + + # here will be a test call + yield + + # This code will run after each "function" (test) + nav.go_to_main_screen() + nav.delete_file("NFC", "T_mfc_4k7") + + @pytest.fixture(scope="function") + def emulate_classic(self, nav): + nav.go_to_main_screen() + if nav.open_file("NFC", "T_mfc_4k7") == -1: + assert 0, "File not found" + + # Need for emulation to start, otherwise error on proxmark side + time.sleep(2) + + def test_mfc_4k7_basic(self, px, emulate_classic): + """ + px: proxmark_wrapper fixture + command: command to be executed + expected_result: expected result of the command + error: if the command should return an error + """ + + # read 1 block + read1 = px.execute("hf mf rdbl --blk 1 -k ffffffffffff") + expected = "[=] 1 | FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF | ................ " + print("///////////////////////////////////") + print(expected in read1) + print("///////////////////////////////////") + assert expected in read1, "Incorrect block read" + + # write 1 block + write1 = px.execute("hf mf wrbl --blk 1 -k ffffffffffff -d 11223344556677889910111213141516") + expected = "[+] Write ( ok )" + assert expected in write1, "Incorrect block write" + + # read 1 block + read1_wrong = px.execute("hf mf rdbl --blk 1 -k ffffffffffff") + expected = "[=] 1 | 11 22 33 44 55 66 77 88 99 10 11 12 13 14 15 16 | .\"3DUfw......... " + assert expected in read1_wrong, "Incorrect block read" + + # set value block + set_value = px.execute("hf mf value --blk 1 -k ffffffffffff --set 1000") + expected = "[+] Update ... : success" + assert expected in set_value, "Incorrect set value" + + # increment value block + inc_value = px.execute("hf mf value --blk 1 -k ffffffffffff --inc 200") + expected = "[+] Update ... : success" + + # tests work up to this point + assert expected in inc_value, "Incorrect increment value" + + # decrement value block + dec_value = px.execute("hf mf value --blk 1 -k ffffffffffff --dec 10000") + assert dec_value[0] == "Decrement success, new value is -8800", "Incorrect decrement value" + + # change key A in 0 sector + change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d a0a1a2a3a4a5ff078069ffffffffffff") + assert change_key[0] == "Block write OK", "Incorrect change key" + + # read 1 block with old key + read1 = px.execute("hf mf rdbl --blk 1 -k ffffffffffff") + assert read1[0] == "Auth error", "Incorrect block read" + + # read 1 block with new key + read1 = px.execute("hf mf rdbl --blk 1 -k a0a1a2a3a4a5") + assert read1[0] == "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "Incorrect block read" + + # change key B in 0 sector + change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d b0b1b2b3b4b5ff078069ffffffffffff") + assert change_key[0] == "Block write OK", "Incorrect change key" + + # read sector trailer with key A + trailer_a_key = px.execute("hf mf rdbl --blk 3 -k a0a1a2a3a4a5") + assert trailer_a_key[0] == "Key A not present, Access Bits present, Key B present in the output", "Incorrect trailer read" + + # read sector trailer with key B + trailer_b_key = px.execute("hf mf rdbl --blk 3 -b -k b0b1b2b3b4b5") + assert trailer_b_key[0] == "Key A not present, Access Bits not present, Key B not present in the output", "Incorrect trailer read" + + + + px_result = px.execute(command) + # + # result = px_result[0] + + assert 1 diff --git a/scripts/flippigator/nfc/test_emulate_ntag213.py b/scripts/flippigator/nfc/test_emulate_ntag213.py index 4d46897d378..6295bbfcd23 100644 --- a/scripts/flippigator/nfc/test_emulate_ntag213.py +++ b/scripts/flippigator/nfc/test_emulate_ntag213.py @@ -13,18 +13,9 @@ def emulate_ntag213(self, nav): @pytest.mark.skip(reason="not implemented") def test_ntag213_basic(self, px): - # nav.go_to_main_screen() - # - # if nav.open_file("NFC", "Ntag213") == -1: - # assert 0, "File not found" - # nav.get_current_state() - - # data = px.execute_single("hf 14a raw -sc 3000") - # repeat previous line with enter button in the end - # data = px.execute(["hf 14a raw -sc 3000\n"]) - # - # print(data) - # result = px.execute_single("hf 14a raw -sc 3000") + """ + Todo: Rewrite proper example (not up to date) + """ pm = proxmark_wrapper("/home/vk/work/proxmark3/pm3") # pm.execute_single("hf 14a raw -sc 3000") @@ -34,30 +25,9 @@ def test_ntag213_basic(self, px): print(result) print("-------------------------------------") - # result = px.execute(["hf 14a raw -sc 3000\n","hf 14a raw -sc 3000\n","hf 14a raw -sc 3001\n"]) - # print(result) - assert ( result == "04 63 5D B2 9A 5A 12 90 42 48 00 00 E1 10 6D 00 [ 65 9C ]" ), "Incorrect data on NFC card" - # reader_nfc.go_to_place() - # reader_nfc.clear() - # - # if nav.open_file("NFC", "BN2") == -1: - # assert 0, "File not found" - # nav.get_current_state() - # - # start_time = time.time() - # while start_time + 5 > time.time(): - # if reader_nfc.update(): - # string = reader_nfc.get() - # assert string == "W58W60950399D1334", "Emulated NFC card reading failed" - # break - # - # if start_time + 5 < time.time(): - # assert 0, "Timeout of emulation" - - # nav.go_to_main_screen() Test_Data = [ ("hf 14a raw -sc A229440024FF", "0A", "Error: NFC card not found"), From b4b00b70aa64895c4d59e1ab3e968524f1e0f420 Mon Sep 17 00:00:00 2001 From: doomwastaken Date: Mon, 16 Oct 2023 10:08:50 +0300 Subject: [PATCH 3/6] temp changes to mfc, will need to update menu navigation further --- .../nfc/test_emulate_mifare_classic.py | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/scripts/flippigator/nfc/test_emulate_mifare_classic.py b/scripts/flippigator/nfc/test_emulate_mifare_classic.py index cfe5895f601..ba5500bd6ec 100644 --- a/scripts/flippigator/nfc/test_emulate_mifare_classic.py +++ b/scripts/flippigator/nfc/test_emulate_mifare_classic.py @@ -9,10 +9,21 @@ class TestEmulateClassic: @pytest.fixture(scope="function", autouse=True) def add_4k7_manually(self, nav): # Code below will run before each "function" (test) - nav.go_to_main_screen() # Delete file if exists, needs to be added as picture sadly - nav.delete_file("NFC", "T_mfc_4k7") + # nav.delete_file("NFC", "T_mfc_4k7") + # Todo: return back to line above, after browser is fixed + nav.nfc.go_into() + nav.go_to("Saved") + nav.press_ok() + nav.go_to("T_mfc_4k7", direction="up") + menu_items = nav.get_menu_list() + if "T_mfc_4k7" in menu_items: + nav.press_ok() + nav.go_to("Delete", direction="up") + nav.press_ok() + nav.press_right() + nav.nfc.go_into() nav.go_to("Add Manually") nav.press_ok() @@ -30,8 +41,19 @@ def add_4k7_manually(self, nav): yield # This code will run after each "function" (test) - nav.go_to_main_screen() - nav.delete_file("NFC", "T_mfc_4k7") + # nav.delete_file("NFC", "T_mfc_4k7") + # Todo: return back to line above, after browser is fixed + # Todo2: move to function + nav.nfc.go_into() + nav.go_to("Saved") + nav.press_ok() + nav.go_to("T_mfc_4k7", direction="up") + menu_items = nav.get_menu_list() + if "T_mfc_4k7" in menu_items: + nav.press_ok() + nav.go_to("Delete", direction="up") + nav.press_ok() + nav.press_right() @pytest.fixture(scope="function") def emulate_classic(self, nav): @@ -53,9 +75,6 @@ def test_mfc_4k7_basic(self, px, emulate_classic): # read 1 block read1 = px.execute("hf mf rdbl --blk 1 -k ffffffffffff") expected = "[=] 1 | FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF | ................ " - print("///////////////////////////////////") - print(expected in read1) - print("///////////////////////////////////") assert expected in read1, "Incorrect block read" # write 1 block @@ -70,48 +89,52 @@ def test_mfc_4k7_basic(self, px, emulate_classic): # set value block set_value = px.execute("hf mf value --blk 1 -k ffffffffffff --set 1000") - expected = "[+] Update ... : success" + expected = "[=] set value to : 1000" + expected_status = "[+] Update ... : success" assert expected in set_value, "Incorrect set value" + assert expected_status in set_value, "Update failed" # increment value block inc_value = px.execute("hf mf value --blk 1 -k ffffffffffff --inc 200") - expected = "[+] Update ... : success" + expected = "[=] Value incremented by : 200" + expected_status = "[+] Update ... : success" - # tests work up to this point assert expected in inc_value, "Incorrect increment value" + assert expected_status in inc_value, "Update failed" # decrement value block dec_value = px.execute("hf mf value --blk 1 -k ffffffffffff --dec 10000") - assert dec_value[0] == "Decrement success, new value is -8800", "Incorrect decrement value" + expected = "[=] Value decremented by : 10000" + expected_status = "[+] Update ... : success" + assert expected in dec_value, "Incorrect decrement value" + assert expected_status in dec_value, "Update failed" # change key A in 0 sector change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d a0a1a2a3a4a5ff078069ffffffffffff") - assert change_key[0] == "Block write OK", "Incorrect change key" + expected = "[=] data: A0 A1 A2 A3 A4 A5 FF 07 80 69 FF FF FF FF FF FF" + expected_status = "[+] Write ( ok )" + assert expected in change_key, "Incorrect change key" + assert expected_status in change_key, "Update failed" # read 1 block with old key read1 = px.execute("hf mf rdbl --blk 1 -k ffffffffffff") - assert read1[0] == "Auth error", "Incorrect block read" + expected_status = "[#] Auth error" + assert expected_status in read1, "Auth error not present" # read 1 block with new key read1 = px.execute("hf mf rdbl --blk 1 -k a0a1a2a3a4a5") - assert read1[0] == "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "Incorrect block read" + expected = "[=] 1 | E8 03 00 00 17 FC FF FF E8 03 00 00 01 FE 01 FE | ................ " + assert expected in read1, "Incorrect block read" + # all tests below are non-functional, need help verifying them # change key B in 0 sector - change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d b0b1b2b3b4b5ff078069ffffffffffff") - assert change_key[0] == "Block write OK", "Incorrect change key" + # change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d ffffffffffff078069b0b1b2b3b4b5ff") + # assert change_key[0] == "Block write OK", "Incorrect change key" # read sector trailer with key A - trailer_a_key = px.execute("hf mf rdbl --blk 3 -k a0a1a2a3a4a5") - assert trailer_a_key[0] == "Key A not present, Access Bits present, Key B present in the output", "Incorrect trailer read" + # trailer_a_key = px.execute("hf mf rdbl --blk 3 -k a0a1a2a3a4a5") + # assert trailer_a_key[0] == "Key A not present, Access Bits present, Key B present in the output", "Incorrect trailer read" # read sector trailer with key B - trailer_b_key = px.execute("hf mf rdbl --blk 3 -b -k b0b1b2b3b4b5") - assert trailer_b_key[0] == "Key A not present, Access Bits not present, Key B not present in the output", "Incorrect trailer read" - - - - px_result = px.execute(command) - # - # result = px_result[0] - - assert 1 + # trailer_b_key = px.execute("hf mf rdbl --blk 3 -b -k b0b1b2b3b4b5") + # assert trailer_b_key[0] == "Key A not present, Access Bits not present, Key B not present in the output", "Incorrect trailer read" From 80892297e944bcb7ac7de528620ccbda7bea7e82 Mon Sep 17 00:00:00 2001 From: doomwastaken Date: Mon, 16 Oct 2023 11:46:38 +0300 Subject: [PATCH 4/6] fixed navigation in saved, needs refactor --- scripts/flippigator/nfc/test_emulate_mifare_classic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/flippigator/nfc/test_emulate_mifare_classic.py b/scripts/flippigator/nfc/test_emulate_mifare_classic.py index ba5500bd6ec..4834f5d7411 100644 --- a/scripts/flippigator/nfc/test_emulate_mifare_classic.py +++ b/scripts/flippigator/nfc/test_emulate_mifare_classic.py @@ -16,9 +16,9 @@ def add_4k7_manually(self, nav): nav.nfc.go_into() nav.go_to("Saved") nav.press_ok() - nav.go_to("T_mfc_4k7", direction="up") menu_items = nav.get_menu_list() - if "T_mfc_4k7" in menu_items: + if "browser_T_mfc_4k7" in menu_items: + nav.go_to("browser_T_mfc_4k7", direction="up") nav.press_ok() nav.go_to("Delete", direction="up") nav.press_ok() @@ -47,9 +47,9 @@ def add_4k7_manually(self, nav): nav.nfc.go_into() nav.go_to("Saved") nav.press_ok() - nav.go_to("T_mfc_4k7", direction="up") menu_items = nav.get_menu_list() - if "T_mfc_4k7" in menu_items: + if "browser_T_mfc_4k7" in menu_items: + nav.go_to("browser_T_mfc_4k7", direction="up") nav.press_ok() nav.go_to("Delete", direction="up") nav.press_ok() From 739138b6aada4a0b74c2300748cf53f61167e74a Mon Sep 17 00:00:00 2001 From: doomwastaken Date: Tue, 17 Oct 2023 16:30:04 +0300 Subject: [PATCH 5/6] added additional refs, more mfc tests, update to ntag tests --- .../flippigator/flippigator/flippigator.py | 6 + scripts/flippigator/img/ref/Rename.bmp | Bin 0 -> 5862 bytes .../img/ref/Restore Data Changes.bmp | Bin 0 -> 5862 bytes .../img/ref/Update from Initial Card.bmp | Bin 0 -> 5862 bytes .../img/ref/Write to Initial Card.bmp | Bin 0 -> 5862 bytes .../nfc/test_emulate_mifare_classic.py | 47 ++++- .../flippigator/nfc/test_emulate_ntag213.py | 181 +++++++++--------- 7 files changed, 145 insertions(+), 89 deletions(-) create mode 100644 scripts/flippigator/img/ref/Rename.bmp create mode 100644 scripts/flippigator/img/ref/Restore Data Changes.bmp create mode 100644 scripts/flippigator/img/ref/Update from Initial Card.bmp create mode 100644 scripts/flippigator/img/ref/Write to Initial Card.bmp diff --git a/scripts/flippigator/flippigator/flippigator.py b/scripts/flippigator/flippigator/flippigator.py index d261e62a69d..a837e9bd9fc 100644 --- a/scripts/flippigator/flippigator/flippigator.py +++ b/scripts/flippigator/flippigator/flippigator.py @@ -46,6 +46,8 @@ def __init__( self.logger = logging.getLogger(window_name) if self._debugFlag: self.logger.setLevel(logging.DEBUG) + else: + self.logger.setLevel(logging.WARNING) self.nfc = AppNfc(self) self.rfid = AppRfid(self) @@ -309,6 +311,10 @@ def go_to(self, target, area=(0, 64, 0, 128), direction: Optional[str] = "down") self.press_up() state = self.get_current_state(area=area) + def open(self, target, area=(0, 64, 0, 128), direction: Optional[str] = "down"): + self.go_to(target, area, direction) + self.press_ok() + def go_to_main_screen(self): self.press_back() self.press_back() diff --git a/scripts/flippigator/img/ref/Rename.bmp b/scripts/flippigator/img/ref/Rename.bmp new file mode 100644 index 0000000000000000000000000000000000000000..196edc6cc858e6221d0e78d0410cf402436b4034 GIT binary patch literal 5862 zcmeH`F%AMT5Ce~%nwpXq@Bn%q#E1Dth>=DzQ3NS2MTA${^RCxP?i}6i{yc5(xYp;T z=A-7Z=3zV6XCe;7fq!zKl=AVp-m7kV#4YdIcJ^%zv*0`jM(%^td)iS>d!Pl`H#pY; z{02Eqy{CBBP=h}2aqV0hQnSQ72k;r>B=rO}D4rVp#f{9RN$l@{-;s9rUUjc`jy0~O rMn~^&-{X9qdOrua2X<_G_~5z@@IQg;eo5Xu4#a^t5C`JG8V&tn6XXEd=Rmn|uHm=`9y|(-#)26U1~tfCRsECNU*ErP+r>VQ z@5ga|j`Mn)m+k%dE}OA|ec!h_%btG&|NTGb{mcvZc>O)c;ns}#+okpNRvgWB#-5$} zwV3k~7e~X>C*P6r9;bGu&-*ajIvU=wTiEfcPfpKPj9h%?oYAw!yj6cMt>)O=*ZK_1 zY&>g%08qwl=uo_vopeb40Z X9{08eUVd$0ZD4I+ZD4I+)&~9n8bNAA literal 0 HcmV?d00001 diff --git a/scripts/flippigator/img/ref/Update from Initial Card.bmp b/scripts/flippigator/img/ref/Update from Initial Card.bmp new file mode 100644 index 0000000000000000000000000000000000000000..c56f9f3ca50cf56e387cc968d060136f84f022e3 GIT binary patch literal 5862 zcmeH_O>RO#41;0cHEWifpavS3fn_<9fQ!aj$X@_mPA6y!IUZ z)fjhBgW5+9_BhvDIT~|8@d~fW!J2++wBF30aXv58opUeyK=+Y@Ef3lrSlch2<9p$} zFLJR~Kb+5khr=Tz;9`v@>h4pHjvo$0rxq&U=>z}N`~M#tnDxTdJn(zq%-wx|>~l?d zPscy%!#|3nb077^zF5Edo}=?JU%XqavmS9hUr+bBGhXj&<*k{n)$%yoeQ4r1aI=`r Uot?4#>jl;etQS}>@V{Q*3Z(g$7XSbN literal 0 HcmV?d00001 diff --git a/scripts/flippigator/img/ref/Write to Initial Card.bmp b/scripts/flippigator/img/ref/Write to Initial Card.bmp new file mode 100644 index 0000000000000000000000000000000000000000..5cc7152a5b74c54ff9b677d66e1ad27c437d45bc GIT binary patch literal 5862 zcmeH@L5jmL5CpyVoO9mez90|CJrBx<_ZwbKNI@}-VtXMVhy-%Cx_ibNU2nhV<*_d9 z`_uNl?Ni%d%Xjyx~@y?SmvA`#`8n2=h^SoQCnrvK(fXy9<|hiQNzN| zUe>c8^*KY&k Date: Tue, 17 Oct 2023 17:41:35 +0300 Subject: [PATCH 6/6] minor mfc refactor --- .../nfc/test_emulate_mifare_classic.py | 95 ++++++++++--------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/scripts/flippigator/nfc/test_emulate_mifare_classic.py b/scripts/flippigator/nfc/test_emulate_mifare_classic.py index d2b4cee7db6..9e99f6c9a36 100644 --- a/scripts/flippigator/nfc/test_emulate_mifare_classic.py +++ b/scripts/flippigator/nfc/test_emulate_mifare_classic.py @@ -5,7 +5,6 @@ class TestEmulateClassic: - @pytest.fixture(scope="class", autouse=True) def add_4k7_manually(self, nav): # Code below will run before each "function" (test) @@ -14,22 +13,17 @@ def add_4k7_manually(self, nav): # nav.delete_file("NFC", "T_mfc_4k7") # Todo: return back to line above, after browser is fixed nav.nfc.go_into() - nav.go_to("Saved") - nav.press_ok() + nav.open("Saved") menu_items = nav.get_menu_list() if "browser_T_mfc_4k7" in menu_items: - nav.go_to("browser_T_mfc_4k7", direction="up") - nav.press_ok() - nav.go_to("Delete", direction="up") - nav.press_ok() + nav.open("browser_T_mfc_4k7", direction="up") + nav.open("Delete", direction="up") nav.press_right() nav.nfc.go_into() - nav.go_to("Add Manually") - nav.press_ok() + nav.open("Add Manually") # direction for faster testing, since its last element - nav.go_to("Mifare Classic 4k 7byte UID", direction="up") - nav.press_ok() + nav.open("Mifare Classic 4k 7byte UID", direction="up") nav.press_right() nav.press_ok() key = FlipperTextKeyboard(nav) @@ -45,14 +39,11 @@ def add_4k7_manually(self, nav): # Todo: return back to line above, after browser is fixed # Todo2: move to function nav.nfc.go_into() - nav.go_to("Saved") - nav.press_ok() + nav.open("Saved") menu_items = nav.get_menu_list() if "browser_T_mfc_4k7" in menu_items: - nav.go_to("browser_T_mfc_4k7", direction="up") - nav.press_ok() - nav.go_to("Delete", direction="up") - nav.press_ok() + nav.open("browser_T_mfc_4k7", direction="up") + nav.open("Delete", direction="up") nav.press_right() @pytest.fixture(scope="function") @@ -78,13 +69,15 @@ def test_mfc_4k7_basic(self, px, emulate_classic): assert expected in read1, "Incorrect block read" # write 1 block - write1 = px.execute("hf mf wrbl --blk 1 -k ffffffffffff -d 11223344556677889910111213141516") + write1 = px.execute( + "hf mf wrbl --blk 1 -k ffffffffffff -d 11223344556677889910111213141516" + ) expected = "[+] Write ( ok )" assert expected in write1, "Incorrect block write" # read 1 block read1_wrong = px.execute("hf mf rdbl --blk 1 -k ffffffffffff") - expected = "[=] 1 | 11 22 33 44 55 66 77 88 99 10 11 12 13 14 15 16 | .\"3DUfw......... " + expected = '[=] 1 | 11 22 33 44 55 66 77 88 99 10 11 12 13 14 15 16 | ."3DUfw......... ' assert expected in read1_wrong, "Incorrect block read" # set value block @@ -110,7 +103,9 @@ def test_mfc_4k7_basic(self, px, emulate_classic): assert expected_status in dec_value, "Update failed" # change key A in 0 sector - change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d a0a1a2a3a4a5ff078069ffffffffffff") + change_key = px.execute( + "hf mf wrbl --blk 3 -k ffffffffffff -d a0a1a2a3a4a5ff078069ffffffffffff" + ) expected = "[=] data: A0 A1 A2 A3 A4 A5 FF 07 80 69 FF FF FF FF FF FF" expected_status = "[+] Write ( ok )" assert expected in change_key, "Incorrect change key" @@ -150,34 +145,42 @@ def test_mfc_4k7_basic(self, px, emulate_classic): ( "FF0F00", [ - ("hf mf wrbl --blk 3 -k ffffffffffff -d ffffffffffffff0f0069ffffffffffff", "[+] Write ( ok )"), - ("hf mf rdbl --blk 3 -k ffffffffffff", "[=] 3 | 00 00 00 00 00 00 FF 0F 00 69 FF FF FF FF FF FF | .........i......"), - ("hf mf rdbl --blk 3 -b -k ffffffffffff", "[#] Read block error"), # [#] Read block error - ("hf mf wrbl --blk 3 -k ffffffffffff -d a0a1a2a3a4a5ff0f0069b0b1b2b3b4b5", "[+] Write ( ok )"), - ("hf mf wrbl --blk 3 -b -k b0b1b2b3b4b5 -d a1a2a3a4a5a6ff0f0069b1b2b3b4b5b6", "[-] ⛔ Write ( fail )"), - ("hf mf wrbl --blk 3 -k a0a1a2a3a4a5 -d a1a2a3a4a5a6ff078069b1b2b3b4b5b6", "[+] Write ( ok )"), - ("hf mf wrbl --blk 3 -b -k b1b2b3b4b5b6 -d a1a2a3a4a5a6ff078069b1b2b3b4b5b6", "[-] ⛔ Write ( fail )"), - ] + ( + "hf mf wrbl --blk 3 -k ffffffffffff -d ffffffffffffff0f0069ffffffffffff", + "[+] Write ( ok )", + ), + ( + "hf mf rdbl --blk 3 -k ffffffffffff", + "[=] 3 | 00 00 00 00 00 00 FF 0F 00 69 FF FF FF FF FF FF | .........i......", + ), + ( + "hf mf rdbl --blk 3 -b -k ffffffffffff", + "[#] Read block error", + ), # [#] Read block error + ( + "hf mf wrbl --blk 3 -k ffffffffffff -d a0a1a2a3a4a5ff0f0069b0b1b2b3b4b5", + "[+] Write ( ok )", + ), + ( + "hf mf wrbl --blk 3 -b -k b0b1b2b3b4b5 -d a1a2a3a4a5a6ff0f0069b1b2b3b4b5b6", + "[-] ⛔ Write ( fail )", + ), + ( + "hf mf wrbl --blk 3 -k a0a1a2a3a4a5 -d a1a2a3a4a5a6ff078069b1b2b3b4b5b6", + "[+] Write ( ok )", + ), + ( + "hf mf wrbl --blk 3 -b -k b1b2b3b4b5b6 -d a1a2a3a4a5a6ff078069b1b2b3b4b5b6", + "[-] ⛔ Write ( fail )", + ), + ], ), ] @pytest.mark.parametrize("condition, cmds", data) def test_trailer_access_condition(self, px, emulate_classic, condition, cmds): - result = px.execute(cmds[0][0]) - assert result[0] == cmds[0][1], "1: Write failed" - - result = px.execute(cmds[1][0]) - assert result[0] == cmds[1][1], "2: No keyA, ACs, KeyB" - - result = px.execute(cmds[2][0]) - assert result[0] == cmds[2][1], "3: No KeyA, No ACs, No KeyB" - - result = px.execute(cmds[3][0]) - assert result[0] == cmds[3][1], "4 Incorrect trailer read" - - result = px.execute(cmds[4][0]) - assert result[0] == cmds[4][1], "5 Incorrect trailer read" - - result = px.execute(cmds[5][0]) - assert result[0] == cmds[5][1], "Incorrect trailer read" - + for i, cmd in enumerate(cmds): + command = cmd[0] + expected = cmd[1] + result = px.execute(command) + assert expected in result, f"{i}: {command} failed"