Firefox2100 / AmiiPi

This is a Python project to use RPi 0w with OLED hat to work with Proxmark3, acting as an Amiibo emulator.
GNU General Public License v3.0
0 stars 1 forks source link

Script failure during call to pm3_load #1

Open EtherealMochi opened 1 year ago

EtherealMochi commented 1 year ago

First off, I love what you have created here. Thank you for the time you've spent and for sharing! I followed all the steps as laid out in the readme. I did have to edit Interface.py and Proxmark3.py as well. I added logging to proxmark3 sub process for debugging.

My info:

The error I am getting:

(venv) pi@nfcmemories:~/AmiiPi $ python3 src/AmiiPi.py
amiibo:  ('Antonio', '02010001', '016a0502')
hf mfu eload -f /home/pi/AmiiPi/assets/amiibos/02010001_016a0502.bin
[=] Session log /home/pi/.proxmark3/logs/log_20230620.txt
[+] loaded from JSON file /home/pi/.proxmark3/preferences.json
[=] Using UART port /dev/ttyACM0
[=] Communicating with PM3 over USB-CDC
[usb|script] pm3 --> hf mfu eload -f /home/pi/AmiiPi/assets/amiibos/02010001_016a0502.bin
[=] 255 blocks ( 1020 bytes ) to upload
[=] pm3dir...... resources/
[=] Searching... /home/pi/AmiiPi/assets/amiibos/02010001_016a0502.bin
[#] Searching implicit relative paths
[=] Found /home/pi/AmiiPi/assets/amiibos/02010001_016a0502.bin
[+] loaded 540 bytes from binary file /home/pi/AmiiPi/assets/amiibos/02010001_016a0502.bin
[=] detected plain mfu dump format
[+] plain mfu dump format was converted to 135 blocks

[=] MFU dump file information
[=] -------------------------------------------------------------
[=] Version..... 00 00 00 00 00 00 00 00
[=] TBD 0....... 00 00
[=] TBD 1....... 00
[=] Signature... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[=]              00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[=] Counter 0... 00 00 00
[=] Tearing 0... 00
[=] Counter 1... 00 00 00
[=] Tearing 1... 00
[=] Counter 2... 00 00 00
[=] Tearing 2... 00
[=] Max data page... 133 ( 536 bytes )
[=] Header size..... 56 bytes

[=] -------------------------------------------------------------
[=] block#   | data        |lck| ascii
[=] ---------+-------------+---+------
[=]   0/0x00 | 04 AE 0D 2F |   | .�./
[=]   1/0x01 | 4A 8D 4B 84 |   | J�K�
[=]   2/0x02 | 08 48 0F E0 |   | .H.�
[=]   3/0x03 | F1 10 FF EE | 1 | �.��
[=]   4/0x04 | A5 00 00 00 | 0 | �...
[=]   5/0x05 | DE DC 73 14 | 0 | ��s.
[=]   6/0x06 | 8D 16 85 D7 | 0 | �.��
[=]   7/0x07 | F8 D9 5D 80 | 0 | ��]�
[=]   8/0x08 | 23 02 67 F3 | 0 | #.g�
[=]   9/0x09 | 37 9E 5C 16 | 0 | 7�\.
[=]  10/0x0A | 38 0E 44 DB | 0 | 8.D�
[=]  11/0x0B | A0 1F 19 09 | 0 | �...
[=]  12/0x0C | 52 47 74 30 | 0 | RGt0
[=]  13/0x0D | 6E E9 05 85 | 1 | n�.�
[=]  14/0x0E | 94 A0 D1 25 | 1 | ���%
[=]  15/0x0F | AD D3 89 90 | 1 | �Ӊ�
[=]  16/0x10 | DB 88 B8 7B | 0 | ۈ�{
[=]  17/0x11 | E9 BC 9C CD | 0 | 鼜�
[=]  18/0x12 | 0D 22 18 00 | 0 | ."..
[=]  19/0x13 | 29 9E 24 16 | 0 | )�$.
[=]  20/0x14 | 7C 02 F6 FB | 0 | |.��
[=]  21/0x15 | 02 01 00 01 | 0 | ....
[=]  22/0x16 | 01 6A 05 02 | 0 | .j..
[=]  23/0x17 | 32 39 35 30 | 0 | 2950
[=]  24/0x18 | 5B 33 C0 DB | 0 | [3��
[=]  25/0x19 | 3A 87 CC 21 | 0 | :��!
[=]  26/0x1A | 96 F5 CA D0 | 0 | ����
[=]  27/0x1B | 76 FA A2 D6 | 0 | v��
[=]  28/0x1C | CF B6 5E B7 | 0 | ϶^�
[=]  29/0x1D | BB AA 2A B5 | 0 | ��*�
[=]  30/0x1E | 18 F4 93 65 | 0 | .�e
[=]  31/0x1F | 57 18 B9 7F | 0 | W.�.
[=]  32/0x20 | CB 5A EA 19 | 0 | �Z�.
[=]  33/0x21 | 5C EF 09 24 | 0 | \�.$
[=]  34/0x22 | 9B 6D 04 55 | 0 | �m.U
[=]  35/0x23 | 6F 38 7F 16 | 0 | o8..
[=]  36/0x24 | D5 F3 94 DB | 0 | ���
[=]  37/0x25 | D0 31 B5 07 | 0 | �1�.
[=]  38/0x26 | 57 21 D2 48 | 0 | W!�H
[=]  39/0x27 | 00 D2 4E 9A | 0 | .�N�
[=]  40/0x28 | E1 54 90 F0 | 0 | �T��
[=]  41/0x29 | 19 CC 16 C5 | 0 | .�.�
[=]  42/0x2A | C9 A0 56 70 | 0 | ɠVp
[=]  43/0x2B | DC 1D 35 D0 | 0 | �.5�
[=]  44/0x2C | B9 F6 15 7B | 0 | ��.{
[=]  45/0x2D | E1 F7 A7 60 | 0 | ��`
[=]  46/0x2E | E0 6C 2C 45 | 0 | �l,E
[=]  47/0x2F | 1D C2 A8 BB | 0 | .¨�
[=]  48/0x30 | 1C CE 2E 4B | 0 | .�.K
[=]  49/0x31 | 0A EA DD A5 | 0 | .�ݥ
[=]  50/0x32 | 36 1F 76 C6 | 0 | 6.v�
[=]  51/0x33 | A4 37 F0 69 | 0 | �7�i
[=]  52/0x34 | 1B 6E 74 2E | 0 | .nt.
[=]  53/0x35 | DB AC 72 5D | 0 | ۬r]
[=]  54/0x36 | DD 06 80 74 | 0 | �.�t
[=]  55/0x37 | 7D 77 7B 46 | 0 | }w{F
[=]  56/0x38 | 7D 9C 4D 2C | 0 | }�M,
[=]  57/0x39 | 11 75 6F EF | 0 | .uo�
[=]  58/0x3A | 1D 08 33 2B | 0 | ..3+
[=]  59/0x3B | 92 EB 08 2B | 0 | ��.+
[=]  60/0x3C | 04 95 3F 08 | 0 | .�?.
[=]  61/0x3D | 02 35 7F 24 | 0 | .5.$
[=]  62/0x3E | D8 CA 4D 04 | 0 | ��M.
[=]  63/0x3F | C1 BC 5A C2 | 0 | ��Z�
[=]  64/0x40 | 9C 81 FE 04 | 0 | ���.
[=]  65/0x41 | D6 22 11 A0 | 0 | �".�
[=]  66/0x42 | 06 A4 44 17 | 0 | .�D.
[=]  67/0x43 | 89 66 89 97 | 0 | �f��
[=]  68/0x44 | 00 66 6B 91 | 0 | .fk�
[=]  69/0x45 | 55 C6 2F 89 | 0 | U�/�
[=]  70/0x46 | F6 73 8E 02 | 0 | �s�.
[=]  71/0x47 | 32 E9 5A 93 | 0 | 2�Z�
[=]  72/0x48 | B3 25 2D E2 | 0 | �%-�
[=]  73/0x49 | D0 8A F2 98 | 0 | Њ�
[=]  74/0x4A | B1 2D 8F 5C | 0 | �-�\
[=]  75/0x4B | B1 AB DA 4B | 0 | ���K
[=]  76/0x4C | F6 12 5F 4C | 0 | �._L
[=]  77/0x4D | 6F B4 5B 55 | 0 | o�[U
[=]  78/0x4E | 61 82 CC DE | 0 | a���
[=]  79/0x4F | 46 8A 39 2F | 0 | F�9/
[=]  80/0x50 | 4C 59 70 91 | 0 | LYp�
[=]  81/0x51 | AC E4 CE B2 | 0 | ��β
[=]  82/0x52 | 6F D2 85 BB | 0 | o҅�
[=]  83/0x53 | CD 9C A6 CD | 0 | ͜��
[=]  84/0x54 | 56 51 AE 69 | 0 | VQ�i
[=]  85/0x55 | 05 69 38 7D | 0 | .i8}
[=]  86/0x56 | 32 04 58 82 | 0 | 2.X�
[=]  87/0x57 | 48 8F 6C FB | 0 | H�l�
[=]  88/0x58 | E8 90 E2 5F | 0 | ��_
[=]  89/0x59 | 11 4A 22 FF | 0 | .J"[=]  90/0x5A | F9 98 00 92 | 0 | �.�
[=]  91/0x5B | 0A 06 F6 76 | 0 | ..�v
[=]  92/0x5C | CB D4 9B 29 | 0 | �ԛ)
[=]  93/0x5D | EA 59 07 DD | 0 | �Y.�
[=]  94/0x5E | C7 71 AB 3D | 0 | �q�=
[=]  95/0x5F | BA 80 8D 0B | 0 | ���.
[=]  96/0x60 | CD B9 B0 2D | 0 | ͹�-
[=]  97/0x61 | CB BE 9B 1C | 0 | ˾�.
[=]  98/0x62 | A0 7F 23 D5 | 0 | �.#�
[=]  99/0x63 | 78 51 C0 79 | 0 | xQ�y
[=] 100/0x64 | 52 97 BA B0 | 0 | R���
[=] 101/0x65 | 30 82 03 F1 | 0 | 0�.�
[=] 102/0x66 | 94 B7 F9 E2 | 0 | ����
[=] 103/0x67 | 89 48 07 57 | 0 | �H.W
[=] 104/0x68 | A2 2C A8 94 | 0 | �,��
[=] 105/0x69 | F2 7C 89 8C | 0 | �|��
[=] 106/0x6A | 0E 96 9B DF | 0 | .���
[=] 107/0x6B | 19 33 BA C1 | 0 | .3��
[=] 108/0x6C | 6D 2E 0D 29 | 0 | m..)
[=] 109/0x6D | F9 96 00 DE | 0 | �.�
[=] 110/0x6E | 3D 47 99 6E | 0 | =G�n
[=] 111/0x6F | 8C A7 E4 EA | 0 | ����
[=] 112/0x70 | 40 C7 41 A0 | 0 | @�A�
[=] 113/0x71 | BB E0 66 72 | 0 | ��fr
[=] 114/0x72 | 5F 49 16 F1 | 0 | _I.�
[=] 115/0x73 | B0 5C D3 B1 | 0 | �\ӱ
[=] 116/0x74 | E1 89 73 11 | 0 | �s.
[=] 117/0x75 | A9 3D D0 D6 | 0 | �=��
[=] 118/0x76 | 30 9D 39 A0 | 0 | 0�9�
[=] 119/0x77 | 2D 40 2D 88 | 0 | -@-�
[=] 120/0x78 | 80 B9 C8 DF | 0 | ����
[=] 121/0x79 | 5F 07 8E 61 | 0 | _.�a
[=] 122/0x7A | 0C F8 0C C2 | 0 | .�.�
[=] 123/0x7B | E7 86 FA 5A | 0 | ��Z
[=] 124/0x7C | D0 DB 51 DF | 0 | ��Q�
[=] 125/0x7D | D7 35 7E 9C | 0 | �5~�
[=] 126/0x7E | C1 B7 57 B4 | 0 | ��W�
[=] 127/0x7F | 5C 3C 6B B4 | 0 | \<k�
[=] 128/0x80 | 43 18 05 9C | 0 | C..�
[=] 129/0x81 | 28 5E 8B C5 | 0 | (^��
[=] 130/0x82 | 01 00 0F BD | 0 | ...�
[=] 131/0x83 | 00 00 00 04 | 0 | ....
[=] 132/0x84 | 5F 00 00 00 | 0 | _...
[=] 133/0x85 | 00 00 00 00 | 0 | ....
[=] 134/0x86 | 00 00 00 00 | 0 | ....
[=] ---------------------------------
[=] MIFARE Ultralight override, will use 149 blocks ( 596 bytes )
[=] Uploading to emulator memory
[=] ......................................................................................................................................................Traceback (most recent call last):
  File "/home/pi/AmiiPi/src/AmiiPi.py", line 86, in <module>
    AmiiboInfo.amiibo_info(term, amiibo_result[amiibo_selected], pm3)
  File "/home/pi/AmiiPi/src/AmiiboInfo.py", line 21, in amiibo_info
    pm3.pm3_load(amiibo_data[1] + "_" + amiibo_data[2] + ".bin")
  File "/home/pi/AmiiPi/src/Proxmark3.py", line 50, in pm3_load
    self.proxmark3.expect('Done!')
  File "/home/pi/AmiiPi/venv/lib/python3.11/site-packages/pexpect/spawnbase.py", line 343, in expect
    return self.expect_list(compiled_pattern_list,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/AmiiPi/venv/lib/python3.11/site-packages/pexpect/spawnbase.py", line 372, in expect_list
    return exp.expect_loop(timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/AmiiPi/venv/lib/python3.11/site-packages/pexpect/expect.py", line 181, in expect_loop
    return self.timeout(e)
           ^^^^^^^^^^^^^^^
  File "/home/pi/AmiiPi/venv/lib/python3.11/site-packages/pexpect/expect.py", line 144, in timeout
    raise exc
pexpect.exceptions.TIMEOUT: <pexpect.popen_spawn.PopenSpawn object at 0xb356c2f0>
searcher: searcher_re:
    0: re.compile(b'Done!')
<pexpect.popen_spawn.PopenSpawn object at 0xb356c2f0>
searcher: searcher_re:
    0: re.compile(b'Done!')
(venv) pi@nfcmemories:~/AmiiPi $

Proxmark3.py

import os
import sys # J.P. added 6-19-23
import random
from amiibo import AmiiboDump, AmiiboMasterKey
from time import sleep
from pexpect.popen_spawn import PopenSpawn

eml_starting_line = 19
proxmark_path = "/home/pi/proxmark3/"
#port = "bt:20:19:05:06:22:69"
port = "/dev/ttyACM0"
amiibo_path = "/home/pi/AmiiPi/assets/amiibos/"
key_path = "/home/pi/AmiiPi/assets/key_retail.bin"

class Proxmark3:
    def __init__(self) -> None:
        self.proxmark_path = proxmark_path

        # Start the PM3 shell
        shell_command = os.path.join(proxmark_path, "client", "") + "proxmark3 " + port
        #print(shell_command)
        self.proxmark3 = PopenSpawn(shell_command)
        # Log file creation
        fout = open("../prox-test.log", "wb")
        self.proxmark3.logfile_read = fout  # use child.logfile to also log writes
        self.proxmark3.logfile = sys.stdout.buffer

    def eml_to_bin(self, eml_path: str, bin_path: str):
        eml_file = open(eml_path, 'r')
        lines = eml_file.readlines()
        lines = lines[eml_starting_line:]

        data = []

        for line in lines:
            data.append(int(line[0:1], 16))
            data.append(int(line[2:3], 16))
            data.append(int(line[4:5], 16))
            data.append(int(line[6:7], 16))

        bin_file = open(bin_path, "wb")
        bin_file.write(bytearray(data))

    def pm3_load(self, dump_name: str):
        command = "hf mfu eload -f " + os.path.join(amiibo_path, dump_name)
        #print("run_cmd: ", command)
        self.proxmark3.sendline(command)
        self.proxmark3.expect('Done!')

        command = "hf mfu sim -t 7"
        #print("run_cmd: ", command)
        self.proxmark3.send(command)

    def randomize_uid(self, input_name: str):
        uid = "04"

        input_path = os.path.join(amiibo_path, input_name)
        output_path = os.path.join(amiibo_path, "temp.bin")

        for i in range(0, 6):
            uid += hex(random.randint(0, 255))[2:]

        with open(key_path, 'rb') as keybin:
            master_key = AmiiboMasterKey.from_combined_bin(keybin.read())

        with open(input_path, 'rb') as fin, open(output_path, 'wb') as fout:
            dump = AmiiboDump(master_key, fin.read(), is_locked=True)
            dump.unlock()
            dump.uid_hex = uid
            dump.lock()
            fout.write(dump.data)
        self.pm3_load("temp.bin")

        os.remove(output_path)

    def write_back(self, dump_name: str):
        command = "hf mfu esave -f temp"
        print("write_back__cmd: ", command)
        self.proxmark3.sendline(command)
        self.proxmark3.expect("to binary")
        sleep(1)

        source_path = os.path.join(self.proxmark_path, "temp.bin")
        print("wb_src_path: ", source_path)
        destination_path = os.path.join(amiibo_path, dump_name)
        print("wb_dst_path: ", destination_path)
        os.replace(source_path, destination_path)

        os.remove(source_path)

Interface.py

import RPi.GPIO as GPIO
from luma.core.interface.serial import gpio_cs_spi
from luma.oled.device import ssd1351
from luma.core.virtual import terminal
from PIL import ImageFont

# GPIO Pins
stick_up = 5
stick_down = 6
stick_left = 13
stick_right = 19
stick_press = 26
key1 = 16
key2 = 20
key3 = 21
dc_pin = 25
reset_pin = 24
cs_pin = 8

# Display info
spi_device = 0
spi_port = 0
rotation = 0

font_path = "/home/pi/AmiiPi/assets/ProggyTiny.ttf"
font_size = 16

def gpio_config():
    GPIO.setmode(GPIO.BCM)

    GPIO.setup(stick_up,    GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(stick_down,  GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(stick_left,  GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(stick_right, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(stick_press, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(key1,        GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(key2,        GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(key3,        GPIO.IN, pull_up_down=GPIO.PUD_UP)

    GPIO.add_event_detect(stick_up,     GPIO.RISING)
    GPIO.add_event_detect(stick_down,   GPIO.RISING)
    GPIO.add_event_detect(stick_left,   GPIO.RISING)
    GPIO.add_event_detect(stick_right,  GPIO.RISING)
    GPIO.add_event_detect(stick_press,  GPIO.RISING)
    GPIO.add_event_detect(key1,         GPIO.RISING)
    GPIO.add_event_detect(key2,         GPIO.RISING)
    GPIO.add_event_detect(key3,         GPIO.RISING)

def get_terminal() -> terminal:
    serial = gpio_cs_spi(device=spi_device, port=spi_port, gpio_DC=dc_pin, gpio_RST=reset_pin, gpio_CS=cs_pin)
    device = ssd1351(serial, rotate=rotation)

    font = ImageFont.truetype(font_path, font_size)
    term = terminal(device, font)

    return term
EtherealMochi commented 1 year ago

Weird.

I was able to get it working by adding " -f" to the end of the shell command. I verified by this by git reset --hard and then editing the Interface file and the Proxmark3 file.

Proxmark3.py

shell_command = os.path.join(proxmark_path, "client", "") + "proxmark3 " + port + " -f"
shell_cmd_pm3 = 'pm3 -f'                                 #testing 
self.proxmark3 = PopenSpawn(shell_command)                 # shell_cmd_pm3 works also
Firefox2100 commented 11 months ago

Hello,

Sorry for the late reply. Yes, I confirmed the issue with the latest version of PM3 firmware. There appears to be some update in the firmware that is breaking some hard-coded parts. I wasn't expecting much usage on this project, so I've been pushing off the cleanup of the codes. I will, in the near future, refactor the code, add more error checks and logging, and make it compatible with the latest releases.