2021-03-15 15:31:52 +00:00
#!/usr/bin/env python3
"""
2021-03-20 01:59:53 +00:00
* nxdt_host . py
2021-03-15 15:31:52 +00:00
*
* Copyright ( c ) 2021 , DarkMatterCore < pabloacurielz @gmail.com > .
*
* This file is part of nxdumptool ( https : / / github . com / DarkMatterCore / nxdumptool ) .
*
* nxdumptool is free software ; you can redistribute it and / or modify it
* under the terms and conditions of the GNU General Public License ,
* version 2 , as published by the Free Software Foundation .
*
* nxdumptool is distributed in the hope it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License for
* more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : / / www . gnu . org / licenses / > .
"""
2021-03-20 01:59:53 +00:00
# This script depends on PyUSB and tqdm.
# Optionally, comtypes may also be installed under Windows to provide taskbar progress functionality.
# Use `pip -r requirements.txt` under Linux or MacOS to install these dependencies.
# Windows users may just double-click `windows_install_deps.py` to achieve the same result.
2021-03-15 15:31:52 +00:00
# libusb needs to be installed as well. PyUSB uses it as its USB backend. Otherwise, a NoBackend exception will be raised while calling PyUSB functions.
# Under Windows, the recommended way to do this is by installing the libusb driver with Zadig (https://zadig.akeo.ie). This is a common step in Switch modding guides.
# Under MacOS, use `brew install libusb` to install libusb via Homebrew.
2021-03-16 05:08:38 +00:00
# Under Linux, you should be good to go from the start. If not, just use the package manager from your distro to install libusb.
2021-03-15 15:31:52 +00:00
import os
import platform
import threading
import traceback
import logging
import queue
import shutil
import time
import struct
import usb . core
import usb . util
2021-03-16 03:28:06 +00:00
import warnings
2021-03-15 15:31:52 +00:00
import tkinter as tk
2021-03-16 03:28:06 +00:00
import tkinter . ttk as ttk
2021-03-15 15:31:52 +00:00
from tkinter import filedialog , messagebox , font , scrolledtext
2021-03-16 03:28:06 +00:00
from tqdm import tqdm
2021-03-15 15:31:52 +00:00
import base64
# Scaling factors.
WINDOWS_SCALING_FACTOR = 96.0
SCALE = 1.0
# Window size.
WINDOW_WIDTH = 500
WINDOW_HEIGHT = 470
# Application version.
APP_VERSION = ' 0.2 '
# Copyright year.
COPYRIGHT_YEAR = ' 2021 '
# USB VID/PID pair.
USB_DEV_VID = 0x057E
USB_DEV_PID = 0x3000
# USB manufacturer and product strings.
USB_DEV_MANUFACTURER = ' DarkMatterCore '
USB_DEV_PRODUCT = ' nxdumptool '
# USB timeout (milliseconds).
USB_TRANSFER_TIMEOUT = 5000
# USB transfer block size.
USB_TRANSFER_BLOCK_SIZE = 0x800000
2021-03-17 17:25:30 +00:00
# USB transfer threshold. Used to determine whether a progress bar should be displayed or not.
2021-03-20 01:59:53 +00:00
USB_TRANSFER_THRESHOLD = ( USB_TRANSFER_BLOCK_SIZE * 4 )
2021-03-17 17:25:30 +00:00
2021-03-15 15:31:52 +00:00
# USB command header/status magic word.
USB_MAGIC_WORD = b ' NXDT '
# Supported USB ABI version.
USB_ABI_VERSION = 1
# USB command header size.
USB_CMD_HEADER_SIZE = 0x10
# USB command IDs.
USB_CMD_START_SESSION = 0
USB_CMD_SEND_FILE_PROPERTIES = 1
USB_CMD_CANCEL_FILE_TRANSFER = 2
USB_CMD_SEND_NSP_HEADER = 3
USB_CMD_END_SESSION = 4
# USB command block sizes.
USB_CMD_BLOCK_SIZE_START_SESSION = 0x10
USB_CMD_BLOCK_SIZE_SEND_FILE_PROPERTIES = 0x320
# Max filename length (file properties).
USB_FILE_PROPERTIES_MAX_NAME_LENGTH = 0x300
# USB status codes.
USB_STATUS_SUCCESS = 0
USB_STATUS_INVALID_MAGIC_WORD = 4
USB_STATUS_UNSUPPORTED_CMD = 5
USB_STATUS_UNSUPPORTED_ABI_VERSION = 6
USB_STATUS_MALFORMED_CMD = 7
USB_STATUS_HOST_IO_ERROR = 8
2021-03-20 01:59:53 +00:00
# Messages displayed as labels.
SERVER_START_MSG = ' Please connect a Nintendo Switch console running {} . ' . format ( USB_DEV_PRODUCT )
SERVER_STOP_MSG = ' Exit {} on your console or disconnect it at any time to stop the server. ' . format ( USB_DEV_PRODUCT )
2021-03-15 15:31:52 +00:00
# Default directory paths.
INITIAL_DIR = os . path . abspath ( os . path . dirname ( __file__ ) )
DEFAULT_DIR = ( INITIAL_DIR + os . path . sep + USB_DEV_PRODUCT )
2021-03-20 01:59:53 +00:00
# Application icon (PNG).
# Embedded to load it as the icon for all windows using PhotoImage (which doesn't support ICO files) + wm_iconphoto.
# iconbitmap supports external ICO files, but it's not capable of setting the icon to all child windows.
2021-03-15 15:31:52 +00:00
APP_ICON = b ' iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAABfVelRYdFJhdyBw ' + \
b ' cm9maWxlIHR5cGUgZXhpZgAAeNrNmll23TiWRf8xihoC+mY4uGjWqhnU8GsfPjV2SJGpcuRHWbYoU3wkcJvTAHTnf/77uv/iT83Ru1xar6NWz5888oiTH7p//RnP9+Dz ' + \
b ' 8/39T3j7/tt59/Fj5Jg4ptcv2nz71OR8+fzA+zOC/X7e9bffxP52o/cnx9ch6cn6ef06SM7H1/mQ32403i6oo7dfh2pvH1jHfw7l7V/9fZLP/92vJ3IjSrvwoBTjSSF5 ' + \
b ' vnc9PTGyNNLkWPkeUos6E54zTd9dqm/TUJS/C2r6m/Pe/xq04H6Skb9LSMrvD9ONfg1w/TiG786H8pfz6eMx8bcRpfnx5Pjr+Z1C+zKdt3/37n7vUbCZxcyVMNe3Sb1P ' + \
b ' 5fmJC0lgTs/HKl+Nf4Wf2/M1+Op++uWog02NGF8rjBBJ1Q057DDDDec5rrAYYo4nkqsY44rpOdfJ3YjryWh2Kaccbmwkd6dOohcpT5yNH2MJz3PH87gVOg/egStj4GaB ' + \
b ' Tzxf7v2Hf/r17Y3uVbmH4PtHrBhXfKotKIpJ37mKhIT7XkflCfD711//qJ8SGSxPmDsTnN5et7ASPmsruSfRiQsLx1cDhrbfbkCIeH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JeX4NyFr4V3WRgeHkbX73+g+tJ5VkIzM1OFlQmkthm1QTxFVgCUbiJq7eqVOJD3MUykHLf//AuyDh5mVYdmXKS0tAzbt25B4eel+DAnD5GR ' + \
b ' EcKKBXtsI4ULC1sje/eKjX0Be/fq4ElqP6W1tQ1hYaGsv1LyJIJC942EhE2sX1b2BWsp9OGOjtZ5GzMvokgASrCPVhs7Mi8i20JyoLZxIQUseYod1lZmLQCx2ky3SdnC ' + \
b ' rAQgrTb2ev5uZjwAR6uNNWY0AKVsI2XGAlDSNlJmJAClbSPF6QE4wzZSnBqAs2wjxWkBONM2Upzyrc62jRTFv5k+7vMzjZA/4O1Os80EwP/vHLXv3BH8dQAAAABJRU5E ' + \
b ' rkJggg== '
2021-03-20 01:59:53 +00:00
# Taskbar Type Library (TLB). Used under Windows 7 or greater.
TASKBAR_LIB_NAME = ' TaskbarLib.tlb '
2021-03-17 21:19:44 +00:00
2021-03-20 01:59:53 +00:00
TASKBAR_LIB = b ' TVNGVAIAAQAAAAAACQQAAAAAAABBAAAAAQAAAAAAAAAOAAAA/////wAAAAAAAAAATgAAADMDAAAAAAAA/////xgAAAAgAAAAgAAAAP////8AAAAAAAAAAGQAAADIAAAA ' + \
2021-03-17 21:19:44 +00:00
b ' LAEAAJABAAD0AQAAWAIAALwCAAAgAwAAhAMAAOgDAABMBAAAsAQAABQFAAB8AQAAeAUAAP////8PAAAA/////wAAAAD/////DwAAAP////8AAAAA/////w8AAABMCAAA ' + \
b ' EAAAAP////8PAAAA9AYAAIAAAAD/////DwAAAHQHAADYAAAA/////w8AAABcCAAAAAIAAP////8PAAAAXAoAAEQHAAD/////DwAAAP////8AAAAA/////w8AAACgEQAA ' + \
b ' iAAAAP////8PAAAAKBIAACAAAAD/////DwAAAEgSAABUAAAA/////w8AAACcEgAAJAAAAP////8PAAAA/////wAAAAD/////DwAAAP////8AAAAA/////w8AAAAjIgAA ' + \
b ' wBIAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAGAAAAAAAAAD/////AAAAAAAAAAD/////AQAgAAQAAABkAAAAAQADAAAAAAD///// ' + \
b ' IyIBAKgTAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAB4AAAAAAAAADAAAAAAAAAA/////wAAAAAAAAAA/////wAADAAEAAAA/////wAAAAAAAAAA ' + \
b ' /////yYhAgAwFAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////wAAAABEAAAAAAAAAP////8AAAAAAAAAAP////8AAAAAEAAAAAgAAAAAAAAA ' + \
b ' AAAAAP////8hIQMAMBQAAAAAAAAAAAAAAwAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAP////8AAAAAVAAAAAAAAAD/////AAAAAAAAAAD/////AAAAABAAAAD///// ' + \
b ' AAAAAAAAAAD/////IyIEALQUAAAAAAAAAAAAAAMAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAACQAAAAAAAAAMwBAAAAAAAA/////wAAAAAAAAAA/////wEAJAAEAAAA ' + \
b ' AAAAAAIACAAAAAAA/////yEhBQD0FAAAAAAAAAAAAAADAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAA/////wAAAAAgAgAAAAAAAP////8AAAAAAAAAAP////8AAAAA ' + \
b ' HAIAAP////8AAAAAAAAAAP////8jIgYAuBUAAAAAAAAAAAAAAwAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAKgAAAAAAAAAsAIAAAAAAAD/////AAAAAAAAAAD///// ' + \
b ' AQBUAAQAAACQAQAAAwAJAAAAAAD/////ICEHALwYAAAAAAAAAAAAAAMAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAD/////AAAAABQDAAAAAAAA/////wAAAAAAAAAA ' + \
b ' /////wAAAAAEAAAA/////wAAAAAAAAAA/////yYhCABgGQAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////wAAAADcAwAAAAAAAP////8AAAAA ' + \
b ' AAAAAP////8AAAAABAAAAFAAAAAIAAAAAAAAAP////8hIQkAYBkAAAAAAAAAAAAAAwAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAP////8AAAAA8AMAAAAAAAD///// ' + \
b ' AAAAAAAAAAD/////AAAAAAgAAAD/////AAAAAAAAAAD/////JyEKAKQZAAAAAAAAAAAAAAMAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAD/////AAAAACAEAAAAAAAA ' + \
b ' /////wAAAAAAAAAA/////wAAAAAEAAAA/////wAAAAAAAAAA/////yAhCwDoGQAAAAAAAAAAAAADAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAA/////wAAAAAMBQAA ' + \
b ' AAAAAP////8AAAAAAAAAAP////8AAAAABAAAAP////8AAAAAAAAAAP////8hIQwALBoAAAAAAAAAAAAAAwAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAP////8AAAAA ' + \
b ' oAYAAAAAAAD/////AAAAAAAAAAD/////AAAAABAAAAD/////AAAAAAAAAAD/////JSINALAaAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAA ' + \
b ' AgAAACwHAAAAAAAA/////wAAAAAAAAAA/////wEAAAAEAAAAAAAAAAAAAAAAAAAA/////3gAAACQAAAA/////////////////////8AAAAD///////////////////// ' + \
b ' ////////////////qAAAAP////////////////////8AAAAA/////////////////////0gAAAAYAAAA//////////////////////////8wAAAAQvY7aMrpJEG+Q2cG ' + \
b ' Wy+mU/7/////////Zbp33nxR0RGi2gAA+Hc86f//////////Y7p33nxR0RGi2gAA+Hc86f//////////ZLp33nxR0RGi2gAA+Hc86f//////////QvP9Vm390BGVigBg ' + \
b ' l8mgkAAAAAD/////AAAAAAAAAADAAAAAAAAARmQAAABgAAAAlUktYDqxm0Kmbhk15E9DF5ABAAD/////kfsa6iiehkuQ6Z6fil7vr1gCAAD/////RPP9Vm390BGVigBg ' + \
b ' l8mgkBQFAAD/////WAIAAAEAAAD/////////////////////6AIAAP/////////////////////////////////////////////////////UBgAA4AUAAP////////// ' + \
b ' //////////8sBwAAIAQAAP/////YBAAARAQAAP/////oAQAAoAYAAPgAAAC8BAAA/////3wEAAAMBAAA////////////////qAQAAP///////////////1AGAACsAwAA ' + \
b ' KAMAAP/////wBAAA3AMAAP//////////nAIAAP///////////////5gFAAC4BQAAxAYAAP///////////////0QFAAD///////////////8YAAAA3AAAAP////+MAAAA ' + \
b ' SAEAAAADAAAYBwAA/////8wBAACwAgAADAUAAOgGAAD//////////4wGAAD/////CAIAAP////9cAQAA//////////+YAQAAAAAAALABAAD///////////////////// ' + \
b ' /////1gEAAD8BgAA////////////////////////////////////////////////tAYAAP////////////////////+ABQAA/////2wEAACUAwAA/////zQBAAAgAgAA ' + \
b ' //////////////////////////8IAQAA/////1ACAAA8AgAAaAUAAIgCAAD/////FAMAAMgDAABEAAAA//////////8KANOVVGFza2JhckxpYldXAAAAAP////8MOD29 ' + \
b ' SVRhc2tiYXJMaXN0ZAAAAP////8IOFuISVVua25vd27IAAAA/////wQ4f/VHVUlELAEAAP////8rOALfX19NSURMX19fTUlETF9pdGZfVGFza2JhckxpYl8wMDA3XzAw ' + \
b ' MDFfMDAwMVcsAQAA/////wUQQDFEYXRhMVdXVywBAAD/////BRBBMURhdGEyV1dXLAEAAP////8FEEIxRGF0YTNXV1csAQAA/////wUQQzFEYXRhNFdXV2QAAAD///// ' + \
b ' DgC+jlF1ZXJ5SW50ZXJmYWNlV1f//////////wQAmzNyaWlk//////////8JAPb2cHB2T2JqZWN0V1dXZAAAAP////8GALW4QWRkUmVmV1dkAAAA/////wcAb2FSZWxl ' + \
b ' YXNlVwAAAACgAAAABgDBGUhySW5pdFdXAAAAAP////8GAM/CQWRkVGFiV1f//////////wQAL8Fod25kAAAAAP////8JAEcJRGVsZXRlVGFiV1dXAAAAAP////8LANKD ' + \
b ' QWN0aXZhdGVUYWJXAAAAAP////8OANQ5U2V0QWN0aXZhdGVBbHRXV5ABAAD/////DThF70lUYXNrYmFyTGlzdDJXV1eQAQAA/////xQAmQVNYXJrRnVsbHNjcmVlbldp ' + \
b ' bmRvd///////////CwBN92ZGdWxsc2NyZWVuV/QBAAD/////Djhw9nRhZ1RIVU1CQlVUVE9OV1f0AQAA/////wYQedlkd01hc2tXV/QBAAD/////AxB4nmlJZFf0AQAA ' + \
b ' /////wcQqxNpQml0bWFwV/QBAAD/////BRCeTWhJY29uV1dX9AEAAP////8FEPsMc3pUaXBXV1f0AQAAcAEAAAcQL4Bkd0ZsYWdzV1gCAAD/////DThG70lUYXNrYmFy ' + \
b ' TGlzdDNXV1dYAgAA/////xAAk5hTZXRQcm9ncmVzc1ZhbHVl/////1QAAAAMAAJpdWxsQ29tcGxldGVk/////7QAAAAIAMIbdWxsVG90YWy8AgAA/////wc4feJUQlBG ' + \
b ' TEFHV7wCAAD/////DzCpRlRCUEZfTk9QUk9HUkVTU1e8AgAA/////xIwqDxUQlBGX0lOREVURVJNSU5BVEVXV7wCAADIAAAACzDDqVRCUEZfTk9STUFMV7wCAAD///// ' + \
b ' CjCnMVRCUEZfRVJST1JXV7wCAAD/////CzDtTVRCUEZfUEFVU0VEV1gCAABEAwAAEACoU1NldFByb2dyZXNzU3RhdGX//////////wgAfld0YnBGbGFncyADAAD///// ' + \
b ' CDgsBXdpcmVIV05EhAMAAGQDAAAQOMPUX1JlbW90YWJsZUhhbmRsZYQDAAD/////CBAfY2ZDb250ZXh06AMAAP////8VOJRaX19NSURMX0lXaW5UeXBlc18wMDA5V1dX ' + \
b ' 6AMAAP////8HEJdKaElucHJvY1foAwAA/////wcQWpVoUmVtb3RlV4QDAAD/////ARBsEHVXV1dYAgAAdAIAAAsAHgFSZWdpc3RlclRhYlf//////////wcAHDZod25k ' + \
b ' VGFiV///////////BwAjEWh3bmRNRElXWAIAAJQEAAANABymVW5yZWdpc3RlclRhYldXV1gCAAD/////CwAWi1NldFRhYk9yZGVyV/////9gAgAAEACrAmh3bmRJbnNl ' + \
b ' cnRCZWZvcmVMBAAAgAEAAAg4x5VUQkFURkxBR0wEAAD/////FTDLIlRCQVRGX1VTRU1ESVRIVU1CTkFJTFdXV0wEAAD/////FzC5uFRCQVRGX1VTRU1ESUxJVkVQUkVW ' + \
b ' SUVXV1gCAAD/////DAB661NldFRhYkFjdGl2Zf//////////CQBqkXRiYXRGbGFnc1dXV1gCAAD/////EgAzhVRodW1iQmFyQWRkQnV0dG9uc1dX//////////8IALRQ ' + \
b ' Y0J1dHRvbnP/////IAEAAAcAtchwQnV0dG9uV1gCAAD/////FQAObVRodW1iQmFyVXBkYXRlQnV0dG9uc1dXV1gCAAAgBQAAFADLRVRodW1iQmFyU2V0SW1hZ2VMaXN0 ' + \
b ' //////////8EAI17aGltbFgCAAD/////DgBloFNldE92ZXJsYXlJY29uV1f/////fAMAAA4AJ6twc3pEZXNjcmlwdGlvbldXWAIAAP////8TAJr4U2V0VGh1bWJuYWls ' + \
b ' VG9vbHRpcFf/////BAYAAAYAy6Fwc3pUaXBXV7AEAABsBgAABziayXRhZ1JFQ1RXsAQAADQGAAAEEOV7bGVmdLAEAADMBQAAAxA12nRvcFewBAAAJAYAAAUQDRVyaWdo ' + \
b ' dFdXV7AEAAD/////BhBIe2JvdHRvbVdXWAIAADAAAAAQANtfU2V0VGh1bWJuYWlsQ2xpcP/////wAwAABwDDlXByY0NsaXBXFAUAAMwCAAALOBMKVGFza2Jhckxpc3RX ' + \
b ' HAD+fwAAAAAdAP9/LAEAAB0A/3/IAAAAGgD/fxAAAAAaAABAGAAAgBoA/n8gAAAAHAD+fxAAAAAdAAMAvAIAAB0A/3/oAwAAHQD/f4QDAAAaAP9/SAAAAB0A/38gAwAA ' + \
b ' HQADAEwEAAAdAP9/9AEAABoA/39oAAAAHQD/f7AEAAAaAP9/eAAAABEAEYABAAgACAAAAAAAAAASABKAAQAIAAQBAAAAAAAACAA+AAAAQ3JlYXRlZCBieSBNSURMIHZl ' + \
b ' cnNpb24gOC4wMS4wNjIyIGF0IE1vbiBKYW4gMTggMTk6MTQ6MDcgMjAzOAoTAP///39XVxMAbgIBCFdXGAAAAAAAAAD/////MAAAAEQAAAAAAAAASAAAAEwAAAAMAAAA ' + \
b ' qAAAABgAAAAZABmAAAAAAAwANAAJBAAAAAAAACQAAQAZABmAAAAAABAARAAJBAEAAQAAAAMAA4BwAQAAAQAAACQAAgAZABmAAAAAABQARAAJBAIAAQAAAAMAA4BwAQAA ' + \
b ' AQAAACQAAwAZABmAAAAAABgARAAJBAMAAQAAAAMAA4BwAQAAAQAAACQABAAZABmAAAAAABwARAAJBAQAAQAAAAMAA4BwAQAAAQAAAAAAAWABAAFgAgABYAMAAWAEAAFg ' + \
b ' SAEAAFwBAACAAQAAmAEAALABAAAAAAAAGAAAADwAAABgAAAAhAAAAGAAAAAwAAAAGQAZgAAAAAAAAGwACQQAAAIAAAAYAAAA+AAAAAEAAAAoAAAACAEAAAIAAAAYAAEA ' + \
b ' EwATgAAAAAAEADQACQQBAAAAAAAYAAIAEwATgAAAAAAIADQACQQCAAAAAAAAAABgAQAAYAIAAGDcAAAAIAEAADQBAAAAAAAAMAAAAEgAAABQAAAAFAAAABMAE4AAAAAA ' + \
b ' AAAkAAAAAAAUAAEAEgASgAAAAAAAACQABAAAABQAAgASABKAAAAAAAAAJAAGAAAAFAADAAAAAAAAAAAAAAA4AAgAAAAAAABAAQAAQAIAAEADAABAjAAAAKAAAAC0AAAA ' + \
b ' yAAAAAAAAAAUAAAAKAAAADwAAAAwAAAAMAAAABkAGYAAAAAAIABUAAkEAAACAAAAAwADgHABAAABAAAAAwADgAgCAAABAAAAAAACYOgBAAAAAAAAeAAAABQAAAATABOA ' + \
b ' AAAAAAAAJAAAAAAAFAABABcAE4AAAAAAAAAkAAQAAAAUAAIAFwATgAAAAAAAACQACAAAABQAAwANAA2AAAAAAAAAJAAMAAAAFAAEADAAAAAAAAAAAAA4ABAAAAAUAAUA ' + \
b ' EwATgA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AMAAHwEAAC8BAAA2AQAAGgFAACYBQAA4AUAAAQGAAA0BgAAbAYAAPwGAAAAAAAAPAAAAGwAAACcAAAAwAAAAPAAAAAsAQAAaAEAAKQBAADUAQAAEAIAAEACAABkAAAA ' + \
b ' FAAAABYAA4AAAAAAAgA0AAAAAIwUAAEAFgADgAAAAAACADQAAQAAjBQAAgAWAAOAAAAAAAIANAACAACMFAADABYAA4AAAAAAAgA0AAQAAIwUAAQAFgADgAAAAAACADQA ' + \
b ' CAAAjAAAAEABAABAAgAAQAMAAEAEAABAKAMAAEQDAABkAwAAfAMAAJQDAAAAAAAAFAAAACgAAAA8AAAAUAAAACgAAAAUAAAAAwADgAAAAAAAACQAAAAAABQAAQBAAAAA ' + \
b ' AAAAAAAAJAAEAAAAAAAAQAEAAEAMBAAAbAQAAAAAAAAUAAAAKAAAABQAAAADAAOAAAAAAAAAJAAAAAAAFAABAAMAA4AAAAAAAAAkAAAAAAAAAABAAQAAQEQEAABYBAAA ' + \
b ' AAAAABQAAAAoAAAAFAAAABYAA4AAAAAAAgA0AAEAAIwUAAEAFgADgAAAAAACADQAAgAAjAAAAEABAABAIAUAAEQFAAAAAAAAFAAAAFAAAAAUAAAAAwADgAAAAAAAACQA ' + \
b ' AAAAABQAAQADAAOAAAAAAAAAJAAEAAAAFAACAAMAA4AAAAAAAAAkAAgAAAAUAAMAAwADgAAAAAAAACQADAAAAAAAAEABAABAAgAAQAMAAEC0BgAAxAYAANQGAADoBgAA ' + \
b ' AAAAABQAAAAoAAAAPAAAAA== '
2021-03-15 15:31:52 +00:00
# Reference: https://beenje.github.io/blog/posts/logging-to-a-tkinter-scrolledtext-widget.
class LogQueueHandler ( logging . Handler ) :
def __init__ ( self , log_queue ) :
super ( ) . __init__ ( )
self . log_queue = log_queue
def emit ( self , record ) :
self . log_queue . put ( record )
# Reference: https://beenje.github.io/blog/posts/logging-to-a-tkinter-scrolledtext-widget.
class LogConsole :
def __init__ ( self , scrolled_text ) :
self . scrolled_text = scrolled_text
self . frame = self . scrolled_text . winfo_toplevel ( )
# Create a logging handler using a queue.
self . log_queue = queue . Queue ( )
self . queue_handler = LogQueueHandler ( self . log_queue )
#formatter = logging.Formatter('[%(asctime)s] -> %(message)s')
formatter = logging . Formatter ( ' %(message)s ' )
self . queue_handler . setFormatter ( formatter )
g_Logger . addHandler ( self . queue_handler )
# Start polling messages from the queue.
self . frame . after ( 100 , self . poll_log_queue )
def display ( self , record ) :
msg = self . queue_handler . format ( record )
self . scrolled_text . configure ( state = ' normal ' )
self . scrolled_text . insert ( tk . END , msg + ' \n ' , record . levelname )
self . scrolled_text . configure ( state = ' disabled ' )
self . scrolled_text . yview ( tk . END )
def poll_log_queue ( self ) :
# Check every 100 ms if there is a new message in the queue to display.
while True :
try :
record = self . log_queue . get ( block = False )
except queue . Empty :
break
else :
self . display ( record )
self . frame . after ( 100 , self . poll_log_queue )
2021-03-16 03:28:06 +00:00
# Loosely based on tk.py from tqdm.
2021-03-17 21:19:44 +00:00
class ProgressBarWindow :
global g_tlb , g_taskbar
2021-03-16 15:44:48 +00:00
def __init__ ( self , bar_format = None , tk_parent = None , window_title = ' ' , window_resize = False , window_protocol = None ) :
2021-03-17 17:25:30 +00:00
if tk_parent is None : raise Exception ( ' `tk_parent` must be provided! ' )
2021-03-16 03:28:06 +00:00
self . n = 0
2021-03-16 15:44:48 +00:00
self . total = 0
2021-03-17 21:19:44 +00:00
self . divider = 1
self . total_div = 0
2021-03-16 15:44:48 +00:00
self . prefix = ' '
self . unit = ' B '
2021-03-16 03:28:06 +00:00
self . bar_format = bar_format
2021-03-16 15:44:48 +00:00
self . start_time = 0
self . elapsed_time = 0
2021-03-17 21:19:44 +00:00
self . hwnd = 0
2021-03-16 03:28:06 +00:00
self . tk_parent = tk_parent
2021-03-16 15:44:48 +00:00
2021-03-16 03:28:06 +00:00
self . tk_window = tk . Toplevel ( self . tk_parent )
2021-03-16 15:44:48 +00:00
self . tk_window . withdraw ( )
self . withdrawn = True
2021-03-17 17:25:30 +00:00
if window_title : self . tk_window . title ( window_title )
2021-03-16 03:28:06 +00:00
self . tk_window . resizable ( window_resize , window_resize )
2021-03-17 17:25:30 +00:00
if window_protocol : self . tk_window . protocol ( ' WM_DELETE_WINDOW ' , window_protocol )
2021-03-16 03:28:06 +00:00
pbar_frame = ttk . Frame ( self . tk_window , padding = 5 )
pbar_frame . pack ( )
self . tk_text_var = tk . StringVar ( self . tk_window )
tk_label = ttk . Label ( pbar_frame , textvariable = self . tk_text_var , wraplength = 600 , anchor = ' center ' , justify = ' center ' )
tk_label . pack ( )
self . tk_n_var = tk . DoubleVar ( self . tk_window , value = 0 )
self . tk_pbar = ttk . Progressbar ( pbar_frame , variable = self . tk_n_var , length = 450 )
2021-03-16 15:44:48 +00:00
self . tk_pbar . configure ( maximum = 100 , mode = ' indeterminate ' )
2021-03-16 03:28:06 +00:00
self . tk_pbar . pack ( )
2021-03-16 15:44:48 +00:00
def __del__ ( self ) :
2021-03-16 03:28:06 +00:00
self . tk_parent . after ( 0 , self . tk_window . destroy )
2021-03-17 21:19:44 +00:00
def start ( self , total , n = 0 , divider = 1 , prefix = ' ' , unit = ' B ' ) :
2021-03-20 01:59:53 +00:00
if ( total < = 0 ) or ( n < 0 ) or ( divider < 1 ) : raise Exception ( ' Invalid arguments! ' )
2021-03-16 15:44:48 +00:00
2021-03-17 21:19:44 +00:00
self . n = n
2021-03-16 15:44:48 +00:00
self . total = total
2021-03-17 21:19:44 +00:00
self . divider = float ( divider )
self . total_div = ( float ( self . total ) / self . divider )
2021-03-16 15:44:48 +00:00
self . prefix = prefix
self . unit = unit
2021-03-17 21:19:44 +00:00
self . tk_pbar . configure ( maximum = self . total_div , mode = ' determinate ' )
2021-03-16 15:44:48 +00:00
self . start_time = time . time ( )
2021-03-16 03:28:06 +00:00
def update ( self , n ) :
2021-03-16 15:44:48 +00:00
cur_n = ( self . n + n )
2021-03-17 17:25:30 +00:00
if cur_n > self . total : return
2021-03-16 03:28:06 +00:00
2021-03-17 21:19:44 +00:00
cur_n_div = ( float ( cur_n ) / self . divider )
2021-03-16 15:44:48 +00:00
self . elapsed_time = ( time . time ( ) - self . start_time )
2021-03-16 03:28:06 +00:00
2021-03-17 21:19:44 +00:00
msg = tqdm . format_meter ( n = cur_n_div , total = self . total_div , elapsed = self . elapsed_time , prefix = self . prefix , unit = self . unit , bar_format = self . bar_format )
2021-03-16 03:28:06 +00:00
self . tk_text_var . set ( msg )
2021-03-17 21:19:44 +00:00
self . tk_n_var . set ( cur_n_div )
2021-03-16 03:28:06 +00:00
2021-03-16 15:44:48 +00:00
if self . withdrawn :
2021-03-20 01:59:53 +00:00
self . tk_window . geometry ( " + {} + {} " . format ( self . tk_parent . winfo_x ( ) , self . tk_parent . winfo_y ( ) ) )
2021-03-16 15:44:48 +00:00
self . tk_window . deiconify ( )
2021-03-20 01:59:53 +00:00
self . tk_window . grab_set ( )
if g_taskbar :
self . hwnd = int ( self . tk_window . wm_frame ( ) , 16 )
g_taskbar . ActivateTab ( self . hwnd )
g_taskbar . SetProgressState ( self . hwnd , g_tlb . TBPF_NORMAL )
2021-03-16 15:44:48 +00:00
self . withdrawn = False
2021-03-17 21:19:44 +00:00
if g_taskbar : g_taskbar . SetProgressValue ( self . hwnd , cur_n , self . total )
2021-03-20 01:59:53 +00:00
self . n = cur_n
2021-03-16 15:44:48 +00:00
def end ( self ) :
self . n = 0
self . total = 0
2021-03-17 21:19:44 +00:00
self . divider = 1
self . total_div = 0
2021-03-16 15:44:48 +00:00
self . prefix = ' '
self . unit = ' B '
self . start_time = 0
self . elapsed_time = 0
2021-03-16 03:28:06 +00:00
2021-03-17 21:19:44 +00:00
if g_taskbar :
g_taskbar . SetProgressState ( self . hwnd , g_tlb . TBPF_NOPROGRESS )
g_taskbar . UnregisterTab ( self . hwnd )
2021-03-20 01:59:53 +00:00
self . tk_window . grab_release ( )
2021-03-16 15:44:48 +00:00
self . tk_window . withdraw ( )
self . withdrawn = True
2021-03-16 03:28:06 +00:00
2021-03-16 15:44:48 +00:00
self . tk_pbar . configure ( maximum = 100 , mode = ' indeterminate ' )
def set_prefix ( self , prefix ) :
self . prefix = prefix
2021-03-16 03:28:06 +00:00
2021-03-15 15:31:52 +00:00
def utilsIsValueAlignedToEndpointPacketSize ( value ) :
return bool ( ( value & ( g_usbEpMaxPacketSize - 1 ) ) == 0 )
def utilsResetNspInfo ( ) :
2021-03-17 21:19:44 +00:00
global g_nspTransferMode , g_nspSize , g_nspHeaderSize , g_nspRemainingSize , g_nspFile , g_nspFilePath
2021-03-15 15:31:52 +00:00
# Reset NSP transfer mode info.
g_nspTransferMode = False
g_nspSize = 0
g_nspHeaderSize = 0
g_nspRemainingSize = 0
g_nspFile = None
g_nspFilePath = None
def utilsGetSizeUnitAndDivisor ( size ) :
size_suffixes = [ ' B ' , ' KiB ' , ' MiB ' , ' GiB ' ]
size_suffixes_count = len ( size_suffixes )
float_size = float ( size )
ret = None
for i in range ( size_suffixes_count ) :
if ( float_size < pow ( 1024 , i + 1 ) ) or ( ( i + 1 ) > = size_suffixes_count ) :
ret = ( size_suffixes [ i ] , pow ( 1024 , i ) )
break
return ret
def usbGetDeviceEndpoints ( ) :
global g_usbEpIn , g_usbEpOut , g_usbEpMaxPacketSize
prev_dev = cur_dev = None
usb_ep_in_lambda = lambda ep : usb . util . endpoint_direction ( ep . bEndpointAddress ) == usb . util . ENDPOINT_IN
usb_ep_out_lambda = lambda ep : usb . util . endpoint_direction ( ep . bEndpointAddress ) == usb . util . ENDPOINT_OUT
2021-03-20 01:59:53 +00:00
usb_version = 0
2021-03-15 15:31:52 +00:00
while True :
# Check if the user decided to stop the server.
if g_stopEvent . is_set ( ) :
g_stopEvent . clear ( )
return False
# Find a connected USB device with a matching VID/PID pair.
cur_dev = usb . core . find ( idVendor = USB_DEV_VID , idProduct = USB_DEV_PID )
if ( cur_dev is None ) or ( ( prev_dev is not None ) and ( cur_dev . bus == prev_dev . bus ) and ( cur_dev . address == prev_dev . address ) ) : # Using == here would also compare the backend.
time . sleep ( 0.1 )
continue
# Update previous device.
prev_dev = cur_dev
# Check if the product and manufacturer strings match the ones used by nxdumptool.
#if (cur_dev.manufacturer != USB_DEV_MANUFACTURER) or (cur_dev.product != USB_DEV_PRODUCT):
if cur_dev . manufacturer != USB_DEV_MANUFACTURER :
g_Logger . error ( ' Invalid manufacturer/product strings! (bus %u , address %u ). ' % ( cur_dev . bus , cur_dev . address ) )
time . sleep ( 0.1 )
continue
# Reset device.
cur_dev . reset ( )
# Set default device configuration, then get the active configuration descriptor.
cur_dev . set_configuration ( )
cfg = cur_dev . get_active_configuration ( )
# Get default interface descriptor.
intf = cfg [ ( 0 , 0 ) ]
# Retrieve endpoints.
g_usbEpIn = usb . util . find_descriptor ( intf , custom_match = usb_ep_in_lambda )
g_usbEpOut = usb . util . find_descriptor ( intf , custom_match = usb_ep_out_lambda )
if ( g_usbEpIn is None ) or ( g_usbEpOut is None ) :
g_Logger . error ( ' Invalid endpoint addresses! (bus %u , address %u ). ' % ( cur_dev . bus , cur_dev . address ) )
time . sleep ( 0.1 )
continue
# Save endpoint max packet size and USB version.
g_usbEpMaxPacketSize = g_usbEpIn . wMaxPacketSize
usb_version = cur_dev . bcdUSB
break
g_Logger . debug ( ' Successfully retrieved USB endpoints! (bus %u , address %u ). ' % ( cur_dev . bus , cur_dev . address ) )
g_Logger . debug ( ' Max packet size: 0x %X (USB %u . %u ). \n ' % ( g_usbEpMaxPacketSize , usb_version >> 8 , ( usb_version & 0xFF ) >> 4 ) )
return True
def usbRead ( size , timeout = - 1 ) :
rd = None
try :
# Convert read data to a bytes object for easier handling.
rd = bytes ( g_usbEpIn . read ( size , timeout ) )
except :
traceback . print_exc ( )
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' USB timeout triggered or console disconnected. ' )
2021-03-15 15:31:52 +00:00
return rd
def usbWrite ( data , timeout = - 1 ) :
wr = 0
try :
wr = g_usbEpOut . write ( data , timeout )
except :
traceback . print_exc ( )
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' USB timeout triggered or console disconnected. ' )
2021-03-15 15:31:52 +00:00
return wr
def usbSendStatus ( code ) :
status = struct . pack ( ' <4sIH6p ' , USB_MAGIC_WORD , code , g_usbEpMaxPacketSize , b ' ' )
return usbWrite ( status , USB_TRANSFER_TIMEOUT ) == len ( status )
def usbHandleStartSession ( cmd_block ) :
2021-03-16 05:08:38 +00:00
global g_nxdtVersionMajor , g_nxdtVersionMinor , g_nxdtVersionMicro , g_nxdtAbiVersion , g_nxdtGitCommit
2021-03-15 15:31:52 +00:00
g_Logger . debug ( ' Received StartSession ( %02X ) command. ' % ( USB_CMD_START_SESSION ) )
# Parse command block.
2021-03-16 05:08:38 +00:00
( g_nxdtVersionMajor , g_nxdtVersionMinor , g_nxdtVersionMicro , g_nxdtAbiVersion , g_nxdtGitCommit ) = struct . unpack_from ( ' <BBBB8s ' , cmd_block , 0 )
g_nxdtGitCommit = g_nxdtGitCommit . decode ( ' utf-8 ' ) . strip ( ' \x00 ' )
2021-03-15 15:31:52 +00:00
# Print client info.
2021-03-16 05:08:38 +00:00
g_Logger . info ( ' Client info: nxdumptool v %u . %u . %u , ABI v %u (commit %s ). \n ' % ( g_nxdtVersionMajor , g_nxdtVersionMinor , g_nxdtVersionMicro , g_nxdtAbiVersion , g_nxdtGitCommit ) )
2021-03-15 15:31:52 +00:00
# Check if we support this ABI version.
if g_nxdtAbiVersion != USB_ABI_VERSION :
g_Logger . error ( ' Unsupported ABI version! ' )
return USB_STATUS_UNSUPPORTED_ABI_VERSION
# Return status code
return USB_STATUS_SUCCESS
def usbHandleSendFileProperties ( cmd_block ) :
2021-03-17 21:19:44 +00:00
global g_nspTransferMode , g_nspSize , g_nspHeaderSize , g_nspRemainingSize , g_nspFile , g_nspFilePath , g_outputDir , g_tkRoot , g_progressBarWindow
2021-03-15 15:31:52 +00:00
g_Logger . debug ( ' Received SendFileProperties ( %02X ) command. ' % ( USB_CMD_SEND_FILE_PROPERTIES ) )
# Parse command block.
( file_size , filename_length , nsp_header_size , raw_filename ) = struct . unpack_from ( ' <QII {} s ' . format ( USB_FILE_PROPERTIES_MAX_NAME_LENGTH ) , cmd_block , 0 )
filename = raw_filename . decode ( ' utf-8 ' ) . strip ( ' \x00 ' )
# Print info.
2021-03-20 01:59:53 +00:00
dbg_str = ( ' File size: 0x %X | Filename length: 0x %X ' % ( file_size , filename_length ) )
if nsp_header_size > 0 : dbg_str + = ( ' | NSP header size: 0x %X ' % ( nsp_header_size ) )
dbg_str + = ' . '
g_Logger . debug ( dbg_str )
2021-03-15 15:31:52 +00:00
2021-03-20 01:59:53 +00:00
file_type_str = ( ' file ' if ( not g_nspTransferMode ) else ' NSP file entry ' )
g_Logger . info ( ' Receiving %s : " %s " . ' % ( file_type_str , filename ) )
2021-03-15 15:31:52 +00:00
# Perform integrity checks
2021-03-17 17:25:30 +00:00
if ( not g_nspTransferMode ) and file_size and ( nsp_header_size > = file_size ) :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' NSP header size must be smaller than the full NSP size! \n ' )
2021-03-15 15:31:52 +00:00
return USB_STATUS_MALFORMED_CMD
2021-03-17 17:25:30 +00:00
if g_nspTransferMode and nsp_header_size :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Received non-zero NSP header size during NSP transfer mode! \n ' )
2021-03-15 15:31:52 +00:00
return USB_STATUS_MALFORMED_CMD
2021-03-17 17:25:30 +00:00
if ( not filename_length ) or ( filename_length > USB_FILE_PROPERTIES_MAX_NAME_LENGTH ) :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Invalid filename length! \n ' )
2021-03-15 15:31:52 +00:00
return USB_STATUS_MALFORMED_CMD
# Enable NSP transfer mode (if needed).
2021-03-17 17:25:30 +00:00
if ( not g_nspTransferMode ) and file_size and nsp_header_size :
2021-03-15 15:31:52 +00:00
g_nspTransferMode = True
g_nspSize = file_size
g_nspHeaderSize = nsp_header_size
2021-03-16 15:44:48 +00:00
g_nspRemainingSize = ( file_size - nsp_header_size )
2021-03-15 15:31:52 +00:00
g_nspFile = None
g_nspFilePath = None
g_Logger . debug ( ' NSP transfer mode enabled! \n ' )
# Perform additional integrity checks and get a file object to work with.
2021-03-17 17:25:30 +00:00
if ( not g_nspTransferMode ) or ( g_nspFile is None ) :
2021-03-15 15:31:52 +00:00
# Generate full, absolute path to the destination file.
fullpath = os . path . abspath ( g_outputDir + os . path . sep + filename )
# Get parent directory path.
dirpath = os . path . dirname ( fullpath )
# Create full directory tree.
os . makedirs ( dirpath , exist_ok = True )
# Make sure the output filepath doesn't point to an existing directory.
2021-03-17 17:25:30 +00:00
if os . path . exists ( fullpath ) and ( not os . path . isfile ( fullpath ) ) :
2021-03-15 15:31:52 +00:00
utilsResetNspInfo ( )
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Output filepath points to an existing directory! ( " %s " ). \n ' % ( fullpath ) )
2021-03-15 15:31:52 +00:00
return USB_STATUS_HOST_IO_ERROR
# Make sure we have enough free space.
( total_space , used_space , free_space ) = shutil . disk_usage ( dirpath )
if free_space < = file_size :
utilsResetNspInfo ( )
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Not enough free space available in output volume! \n ' )
2021-03-15 15:31:52 +00:00
return USB_STATUS_HOST_IO_ERROR
# Get file object.
file = open ( fullpath , " wb " )
2021-03-17 17:25:30 +00:00
if g_nspTransferMode :
2021-03-15 15:31:52 +00:00
# Update NSP file object.
g_nspFile = file
# Update NSP file path.
g_nspFilePath = fullpath
# Write NSP header padding right away.
file . write ( b ' \0 ' * g_nspHeaderSize )
else :
# Retrieve what we need using global variables.
file = g_nspFile
fullpath = g_nspFilePath
dirpath = os . path . dirname ( fullpath )
# Check if we're dealing with an empty file or with the first SendFileProperties command from a NSP.
2021-03-17 17:25:30 +00:00
if ( not file_size ) or ( g_nspTransferMode and file_size == g_nspSize ) :
2021-03-15 15:31:52 +00:00
# Close file (if needed).
2021-03-17 17:25:30 +00:00
if not g_nspTransferMode : file . close ( )
2021-03-15 15:31:52 +00:00
# Let the command handler take care of sending the status response for us.
return USB_STATUS_SUCCESS
# Send status response before entering the data transfer stage.
usbSendStatus ( USB_STATUS_SUCCESS )
# Start data transfer stage.
2021-03-20 01:59:53 +00:00
g_Logger . debug ( ' Data transfer started. Saving %s to: " %s " . ' % ( file_type_str , fullpath ) )
2021-03-15 15:31:52 +00:00
offset = 0
blksize = USB_TRANSFER_BLOCK_SIZE
2021-03-17 21:19:44 +00:00
# Check if we should use the progress bar window.
2021-03-17 17:25:30 +00:00
use_pbar = ( ( ( not g_nspTransferMode ) and ( file_size > USB_TRANSFER_THRESHOLD ) ) or ( g_nspTransferMode and ( g_nspSize > USB_TRANSFER_THRESHOLD ) ) )
if use_pbar :
idx = filename . rfind ( os . path . sep )
prefix_filename = ( filename [ idx + 1 : ] if ( idx > = 0 ) else filename )
prefix = ( ' Current %s : " %s " . \n ' % ( file_type_str , prefix_filename ) )
2021-03-20 01:59:53 +00:00
prefix + = ' Use your console to cancel the file transfer if you wish to do so. '
2021-03-17 17:25:30 +00:00
if ( not g_nspTransferMode ) or g_nspRemainingSize == ( g_nspSize - g_nspHeaderSize ) :
if not g_nspTransferMode :
# Set current progress to zero and the maximum value to the provided file size.
pbar_n = 0
pbar_file_size = file_size
else :
# Set current progress to the NSP header size and the maximum value to the provided NSP size.
pbar_n = g_nspHeaderSize
pbar_file_size = g_nspSize
# Get progress bar unit and unit divider. These will be used to display and calculate size values using a specific size unit (B, KiB, MiB, GiB).
( unit , unit_divider ) = utilsGetSizeUnitAndDivisor ( pbar_file_size )
2021-03-20 01:59:53 +00:00
# Display progress bar window.
2021-03-17 21:19:44 +00:00
g_progressBarWindow . start ( pbar_file_size , pbar_n , unit_divider , prefix , unit )
2021-03-16 15:44:48 +00:00
else :
2021-03-17 21:19:44 +00:00
# Set current prefix (holds the filename for the current NSP file entry).
g_progressBarWindow . set_prefix ( prefix )
2021-03-15 15:31:52 +00:00
def cancelTransfer ( ) :
# Cancel file transfer.
file . close ( )
os . remove ( fullpath )
utilsResetNspInfo ( )
2021-03-17 21:19:44 +00:00
if use_pbar : g_progressBarWindow . end ( )
2021-03-15 15:31:52 +00:00
2021-03-16 15:44:48 +00:00
# Start transfer process.
2021-03-17 17:25:30 +00:00
start_time = time . time ( )
2021-03-15 15:31:52 +00:00
while offset < file_size :
# Update block size (if needed).
diff = ( file_size - offset )
2021-03-17 17:25:30 +00:00
if blksize > diff : blksize = diff
2021-03-15 15:31:52 +00:00
2021-03-17 17:25:30 +00:00
# Set block size and handle Zero-Length Termination packet (if needed).
rd_size = blksize
if ( ( offset + blksize ) > = file_size ) and utilsIsValueAlignedToEndpointPacketSize ( blksize ) : rd_size + = 1
2021-03-15 15:31:52 +00:00
# Read current chunk.
chunk = usbRead ( rd_size , USB_TRANSFER_TIMEOUT )
2021-03-17 17:25:30 +00:00
if chunk is None :
2021-03-16 15:52:10 +00:00
g_Logger . error ( ' Failed to read 0x %X -byte long data chunk! ' % ( rd_size ) )
2021-03-15 15:31:52 +00:00
# Cancel file transfer.
cancelTransfer ( )
# Returning None will make the command handler exit right away.
return None
chunk_size = len ( chunk )
# Check if we're dealing with a CancelFileTransfer command.
if chunk_size == USB_CMD_HEADER_SIZE :
( magic , cmd_id , cmd_block_size ) = struct . unpack_from ( ' <4sII ' , chunk , 0 )
if ( magic == USB_MAGIC_WORD ) and ( cmd_id == USB_CMD_CANCEL_FILE_TRANSFER ) :
2021-03-20 01:59:53 +00:00
g_Logger . debug ( ' \n Received CancelFileTransfer ( %02X ) command. ' % ( USB_CMD_CANCEL_FILE_TRANSFER ) )
g_Logger . warning ( ' Transfer cancelled. ' )
2021-03-15 15:31:52 +00:00
# Cancel file transfer.
cancelTransfer ( )
# Let the command handler take care of sending the status response for us.
return USB_STATUS_SUCCESS
# Write current chunk.
file . write ( chunk )
file . flush ( )
# Update current offset.
offset = ( offset + chunk_size )
# Update remaining NSP data size.
2021-03-17 17:25:30 +00:00
if g_nspTransferMode : g_nspRemainingSize - = chunk_size
2021-03-15 15:31:52 +00:00
2021-03-17 21:19:44 +00:00
# Update progress bar window (if needed).
if use_pbar : g_progressBarWindow . update ( chunk_size )
2021-03-16 03:28:06 +00:00
2021-03-17 17:25:30 +00:00
elapsed_time = round ( time . time ( ) - start_time )
2021-03-20 01:59:53 +00:00
g_Logger . debug ( ' File transfer successfully completed in %s ! \n ' % ( tqdm . format_interval ( elapsed_time ) ) )
2021-03-15 15:31:52 +00:00
# Close file handle (if needed).
2021-03-17 17:25:30 +00:00
if not g_nspTransferMode : file . close ( )
2021-03-15 15:31:52 +00:00
2021-03-17 21:19:44 +00:00
# Hide progress bar window (if needed).
if use_pbar and ( ( not g_nspTransferMode ) or ( not g_nspRemainingSize ) ) : g_progressBarWindow . end ( )
2021-03-16 15:44:48 +00:00
2021-03-15 15:31:52 +00:00
return USB_STATUS_SUCCESS
def usbHandleSendNspHeader ( cmd_block ) :
global g_nspTransferMode , g_nspHeaderSize , g_nspRemainingSize , g_nspFile , g_nspFilePath
nsp_header_size = len ( cmd_block )
g_Logger . debug ( ' Received SendNspHeader ( %02X ) command. ' % ( USB_CMD_SEND_NSP_HEADER ) )
# Integrity checks.
2021-03-17 17:25:30 +00:00
if not g_nspTransferMode :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Received NSP header out of NSP transfer mode! \n ' )
2021-03-15 15:31:52 +00:00
return USB_STATUS_MALFORMED_CMD
2021-03-17 17:25:30 +00:00
if g_nspRemainingSize :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Received NSP header before receiving all NSP data! (missing 0x %X byte[s]). \n ' % ( g_nspRemainingSize ) )
2021-03-15 15:31:52 +00:00
return USB_STATUS_MALFORMED_CMD
if nsp_header_size != g_nspHeaderSize :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' NSP header size mismatch! (0x %X != 0x %X ). \n ' % ( nsp_header_size , g_nspHeaderSize ) )
2021-03-15 15:31:52 +00:00
return USB_STATUS_MALFORMED_CMD
# Write NSP header.
g_nspFile . seek ( 0 )
g_nspFile . write ( cmd_block )
g_nspFile . close ( )
2021-03-16 15:52:10 +00:00
g_Logger . debug ( ' Successfully wrote 0x %X -byte long NSP header to " %s " . \n ' % ( nsp_header_size , g_nspFilePath ) )
2021-03-15 15:31:52 +00:00
# Disable NSP transfer mode.
utilsResetNspInfo ( )
return USB_STATUS_SUCCESS
def usbHandleEndSession ( cmd_block ) :
g_Logger . debug ( ' Received EndSession ( %02X ) command. ' % ( USB_CMD_END_SESSION ) )
return USB_STATUS_SUCCESS
def usbCommandHandler ( ) :
# CancelFileTransfer is handled in usbHandleSendFileProperties().
cmd_dict = {
USB_CMD_START_SESSION : usbHandleStartSession ,
USB_CMD_SEND_FILE_PROPERTIES : usbHandleSendFileProperties ,
USB_CMD_SEND_NSP_HEADER : usbHandleSendNspHeader ,
USB_CMD_END_SESSION : usbHandleEndSession
}
# Get device endpoints.
2021-03-17 17:25:30 +00:00
if not usbGetDeviceEndpoints ( ) :
2021-03-15 15:31:52 +00:00
# Update UI and return.
uiToggleElements ( True )
return
2021-03-20 01:59:53 +00:00
# Update UI.
g_tkCanvas . itemconfigure ( g_tkTipMessage , state = ' normal ' , text = SERVER_STOP_MSG )
2021-03-15 15:31:52 +00:00
g_tkServerButton . configure ( state = ' disabled ' )
# Reset NSP info.
utilsResetNspInfo ( )
while True :
# Read command header.
cmd_header = usbRead ( USB_CMD_HEADER_SIZE )
if ( cmd_header is None ) or ( len ( cmd_header ) != USB_CMD_HEADER_SIZE ) :
2021-03-16 15:52:10 +00:00
g_Logger . error ( ' Failed to read 0x %X -byte long command header! ' % ( USB_CMD_HEADER_SIZE ) )
2021-03-15 15:31:52 +00:00
break
# Parse command header.
( magic , cmd_id , cmd_block_size ) = struct . unpack_from ( ' <4sII ' , cmd_header , 0 )
# Read command block right away (if needed).
# nxdumptool expects us to read it right after sending the command header.
cmd_block = None
2021-03-17 17:25:30 +00:00
if cmd_block_size :
2021-03-15 15:31:52 +00:00
# Handle Zero-Length Termination packet (if needed).
2021-03-17 17:25:30 +00:00
if utilsIsValueAlignedToEndpointPacketSize ( cmd_block_size ) :
2021-03-15 15:31:52 +00:00
rd_size = ( cmd_block_size + 1 )
else :
rd_size = cmd_block_size
cmd_block = usbRead ( rd_size , USB_TRANSFER_TIMEOUT )
if ( cmd_block is None ) or ( len ( cmd_block ) != cmd_block_size ) :
2021-03-16 15:52:10 +00:00
g_Logger . error ( ' Failed to read 0x %X -byte long command block for command ID %02X ! ' % ( cmd_block_size , cmd_id ) )
2021-03-15 15:31:52 +00:00
break
# Verify magic word.
if magic != USB_MAGIC_WORD :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Received command header with invalid magic word! \n ' )
2021-03-15 15:31:52 +00:00
usbSendStatus ( USB_STATUS_INVALID_MAGIC_WORD )
continue
# Get command handler function.
cmd_func = cmd_dict . get ( cmd_id , None )
if cmd_func is None :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Received command header with unsupported ID %02X . \n ' % ( cmd_id ) )
2021-03-15 15:31:52 +00:00
usbSendStatus ( USB_STATUS_UNSUPPORTED_CMD )
continue
# Verify command block size.
2021-03-17 17:25:30 +00:00
if ( cmd_id == USB_CMD_START_SESSION and cmd_block_size != USB_CMD_BLOCK_SIZE_START_SESSION ) or \
( cmd_id == USB_CMD_SEND_FILE_PROPERTIES and cmd_block_size != USB_CMD_BLOCK_SIZE_SEND_FILE_PROPERTIES ) or \
( cmd_id == USB_CMD_SEND_NSP_HEADER and not cmd_block_size ) :
2021-03-16 15:44:48 +00:00
g_Logger . error ( ' Invalid command block size for command ID %02X ! (0x %X ). \n ' % ( cmd_id , cmd_block_size ) )
2021-03-15 15:31:52 +00:00
usbSendStatus ( USB_STATUS_MALFORMED_COMMAND )
continue
# Run command handler function.
# Send status response afterwards. Bail out if requested.
status = cmd_func ( cmd_block )
2021-03-17 17:25:30 +00:00
if ( status is None ) or ( not usbSendStatus ( status ) ) or ( cmd_id == USB_CMD_END_SESSION ) or ( status == USB_STATUS_UNSUPPORTED_ABI_VERSION ) :
2021-03-15 15:31:52 +00:00
break
2021-03-20 01:59:53 +00:00
g_Logger . info ( ' \n Stopping server. ' )
2021-03-15 15:31:52 +00:00
# Update UI.
uiToggleElements ( True )
def uiStopServer ( ) :
# Signal the shared stop event.
g_stopEvent . set ( )
def uiStartServer ( ) :
global g_outputDir
g_outputDir = g_tkDirText . get ( ' 1.0 ' , tk . END ) . strip ( )
if not g_outputDir :
# We should never reach this, honestly.
messagebox . showerror ( ' Error ' , ' You must provide an output directory! ' , parent = g_tkRoot )
return
# Make sure the full directory tree exists.
try :
os . makedirs ( g_outputDir , exist_ok = True )
except :
traceback . print_exc ( )
messagebox . showerror ( ' Error ' , ' Unable to create full output directory tree! ' , parent = g_tkRoot )
return
# Update UI.
uiToggleElements ( False )
# Create background server thread.
server_thread = threading . Thread ( target = usbCommandHandler , daemon = True )
server_thread . start ( )
def uiToggleElements ( enable ) :
2021-03-17 17:25:30 +00:00
if enable :
2021-03-15 15:31:52 +00:00
g_tkRoot . protocol ( ' WM_DELETE_WINDOW ' , uiHandleExitProtocol )
g_tkChooseDirButton . configure ( state = ' normal ' )
g_tkServerButton . configure ( text = ' Start server ' , command = uiStartServer , state = ' normal ' )
g_tkCanvas . itemconfigure ( g_tkTipMessage , state = ' hidden ' , text = ' ' )
else :
g_tkRoot . protocol ( ' WM_DELETE_WINDOW ' , uiHandleExitProtocolStub )
g_tkChooseDirButton . configure ( state = ' disabled ' )
g_tkServerButton . configure ( text = ' Stop server ' , command = uiStopServer , state = ' normal ' )
g_tkCanvas . itemconfigure ( g_tkTipMessage , state = ' normal ' , text = SERVER_START_MSG )
g_tkScrolledTextLog . configure ( state = ' normal ' )
g_tkScrolledTextLog . delete ( ' 1.0 ' , tk . END )
g_tkScrolledTextLog . configure ( state = ' disabled ' )
def uiChooseDirectory ( ) :
dir = filedialog . askdirectory ( parent = g_tkRoot , title = ' Select an output directory ' , initialdir = INITIAL_DIR , mustexist = True )
2021-03-17 17:25:30 +00:00
if dir : uiUpdateDirectoryField ( os . path . abspath ( dir ) )
2021-03-15 15:31:52 +00:00
def uiUpdateDirectoryField ( dir ) :
g_tkDirText . configure ( state = ' normal ' )
g_tkDirText . delete ( ' 1.0 ' , tk . END )
g_tkDirText . insert ( ' 1.0 ' , dir )
g_tkDirText . configure ( state = ' disabled ' )
def uiHandleExitProtocol ( ) :
2021-03-16 15:54:17 +00:00
g_tkRoot . destroy ( )
2021-03-15 15:31:52 +00:00
def uiHandleExitProtocolStub ( ) :
pass
def uiScaleMeasure ( measure ) :
return round ( float ( measure ) * SCALE )
2021-03-20 01:59:53 +00:00
def uiInitialize ( ) :
global SCALE
global g_tkRoot , g_tkCanvas , g_tkDirText , g_tkChooseDirButton , g_tkServerButton , g_tkTipMessage , g_tkScrolledTextLog
global g_tlb , g_taskbar , g_progressBarWindow
2021-03-15 15:31:52 +00:00
2021-03-20 01:59:53 +00:00
# Enable high DPI scaling under Windows (if possible).
2021-03-15 15:31:52 +00:00
dpi_aware = False
2021-03-20 01:59:53 +00:00
if g_isWindowsVista :
2021-03-15 15:31:52 +00:00
try :
2021-03-20 01:59:53 +00:00
import ctypes
2021-03-15 15:31:52 +00:00
dpi_aware = ( ctypes . windll . user32 . SetProcessDPIAware ( ) == 1 )
2021-03-17 17:25:30 +00:00
if not dpi_aware : dpi_aware = ( ctypes . windll . shcore . SetProcessDpiAwareness ( 1 ) == 0 )
2021-03-15 15:31:52 +00:00
except :
traceback . print_exc ( )
2021-03-20 01:59:53 +00:00
# Enable taskbar features under Windows (if possible).
g_tlb = g_taskbar = None
del_tlb = False
if g_isWindows7 :
try :
import comtypes . client as cc
tlb_fp = open ( TASKBAR_LIB_NAME , ' wb ' )
tlb_fp . write ( base64 . b64decode ( TASKBAR_LIB ) )
tlb_fp . close ( )
del_tlb = True
g_tlb = cc . GetModule ( TASKBAR_LIB_NAME )
g_taskbar = cc . CreateObject ( ' { 56FDF344-FD6D-11D0-958A-006097C9A090} ' , interface = g_tlb . ITaskbarList3 )
g_taskbar . HrInit ( )
except :
traceback . print_exc ( )
if del_tlb : os . remove ( TASKBAR_LIB_NAME )
2021-03-15 15:31:52 +00:00
# Create root Tkinter object.
g_tkRoot = tk . Tk ( )
2021-03-20 01:59:53 +00:00
g_tkRoot . title ( " {} host app v {} " . format ( USB_DEV_PRODUCT , APP_VERSION ) )
g_tkRoot . protocol ( ' WM_DELETE_WINDOW ' , uiHandleExitProtocol )
g_tkRoot . resizable ( False , False )
# Set window icon.
try :
icon_image = tk . PhotoImage ( data = APP_ICON )
g_tkRoot . wm_iconphoto ( True , icon_image )
except :
traceback . print_exc ( )
2021-03-15 15:31:52 +00:00
# Get screen resolution.
screen_width_px = g_tkRoot . winfo_screenwidth ( )
screen_height_px = g_tkRoot . winfo_screenheight ( )
# Get pixel density (DPI).
screen_dpi = round ( g_tkRoot . winfo_fpixels ( ' 1i ' ) )
# Update scaling factor (if needed).
2021-03-20 01:59:53 +00:00
if g_isWindowsVista and dpi_aware : SCALE = ( float ( screen_dpi ) / WINDOWS_SCALING_FACTOR )
2021-03-15 15:31:52 +00:00
# Determine window size.
window_width_px = uiScaleMeasure ( WINDOW_WIDTH )
window_height_px = uiScaleMeasure ( WINDOW_HEIGHT )
# Center window.
pos_hor = int ( ( screen_width_px / 2 ) - ( window_width_px / 2 ) )
pos_ver = int ( ( screen_height_px / 2 ) - ( window_height_px / 2 ) )
2021-03-20 01:59:53 +00:00
g_tkRoot . geometry ( " {} x {} + {} + {} " . format ( window_width_px , window_height_px , pos_hor , pos_ver ) )
2021-03-15 15:31:52 +00:00
# Create canvas and fill it with window elements.
g_tkCanvas = tk . Canvas ( g_tkRoot , width = window_width_px , height = window_height_px )
g_tkCanvas . pack ( )
g_tkCanvas . create_text ( uiScaleMeasure ( 60 ) , uiScaleMeasure ( 30 ) , text = ' Output directory: ' , anchor = tk . CENTER )
g_tkDirText = tk . Text ( g_tkRoot , height = 1 , width = 45 , font = font . nametofont ( ' TkDefaultFont ' ) , wrap = ' none ' , state = ' disabled ' , bg = ' #F0F0F0 ' )
uiUpdateDirectoryField ( DEFAULT_DIR )
g_tkCanvas . create_window ( uiScaleMeasure ( 260 ) , uiScaleMeasure ( 30 ) , window = g_tkDirText , anchor = tk . CENTER )
g_tkChooseDirButton = tk . Button ( g_tkRoot , text = ' Choose ' , width = 10 , command = uiChooseDirectory )
g_tkCanvas . create_window ( uiScaleMeasure ( 450 ) , uiScaleMeasure ( 30 ) , window = g_tkChooseDirButton , anchor = tk . CENTER )
g_tkServerButton = tk . Button ( g_tkRoot , text = ' Start server ' , width = 15 , command = uiStartServer )
g_tkCanvas . create_window ( uiScaleMeasure ( WINDOW_WIDTH / 2 ) , uiScaleMeasure ( 70 ) , window = g_tkServerButton , anchor = tk . CENTER )
g_tkTipMessage = g_tkCanvas . create_text ( uiScaleMeasure ( WINDOW_WIDTH / 2 ) , uiScaleMeasure ( 100 ) , anchor = tk . CENTER )
g_tkCanvas . itemconfigure ( g_tkTipMessage , state = ' hidden ' , text = ' ' )
g_tkScrolledTextLog = scrolledtext . ScrolledText ( g_tkRoot , height = 20 , width = 65 , font = font . nametofont ( ' TkDefaultFont ' ) , wrap = tk . WORD , state = ' disabled ' )
g_tkScrolledTextLog . tag_config ( ' DEBUG ' , foreground = ' gray ' )
2021-03-17 21:19:44 +00:00
g_tkScrolledTextLog . tag_config ( ' INFO ' , foreground = ' black ' )
2021-03-15 15:31:52 +00:00
g_tkScrolledTextLog . tag_config ( ' WARNING ' , foreground = ' orange ' )
g_tkScrolledTextLog . tag_config ( ' ERROR ' , foreground = ' red ' )
g_tkScrolledTextLog . tag_config ( ' CRITICAL ' , foreground = ' red ' , underline = 1 )
g_tkCanvas . create_window ( uiScaleMeasure ( WINDOW_WIDTH / 2 ) , uiScaleMeasure ( 280 ) , window = g_tkScrolledTextLog , anchor = tk . CENTER )
g_tkCanvas . create_text ( uiScaleMeasure ( 5 ) , uiScaleMeasure ( WINDOW_HEIGHT - 10 ) , text = " Copyright (c) {} , {} " . format ( COPYRIGHT_YEAR , USB_DEV_MANUFACTURER ) , anchor = tk . W )
2021-03-17 17:25:30 +00:00
# Initialize console logger.
2021-03-15 15:31:52 +00:00
console = LogConsole ( g_tkScrolledTextLog )
2021-03-20 01:59:53 +00:00
# Initialize progress bar window object.
bar_format = ' {desc} \n \n {percentage:.2f} % - {n:.2f} / {total:.2f} {unit} \n Elapsed time: {elapsed} . Remaining time: {remaining} . \n Speed: {rate_fmt} . '
2021-03-17 21:19:44 +00:00
g_progressBarWindow = ProgressBarWindow ( bar_format , g_tkRoot , ' File transfer ' , False , uiHandleExitProtocolStub )
2021-03-16 15:44:48 +00:00
2021-03-15 15:31:52 +00:00
# Enter Tkinter main loop.
2021-03-20 01:59:53 +00:00
g_tkRoot . lift ( )
2021-03-15 15:31:52 +00:00
g_tkRoot . mainloop ( )
2021-03-20 01:59:53 +00:00
def main ( ) :
global g_Logger , g_stopEvent , g_osType , g_osVersion , g_isWindows , g_isWindowsVista , g_isWindows7
# Disable warnings.
warnings . filterwarnings ( " ignore " )
# Setup logging mechanism.
logging . basicConfig ( level = logging . INFO )
g_Logger = logging . getLogger ( )
if len ( g_Logger . handlers ) :
# Remove stderr output handler from logger.
log_stderr = g_Logger . handlers [ 0 ]
g_Logger . removeHandler ( log_stderr )
# Setup thread event.
g_stopEvent = threading . Event ( )
# Get OS information.
g_osType = platform . system ( )
g_osVersion = platform . version ( )
# Get Windows information.
g_isWindows = ( g_osType == ' Windows ' )
g_isWindowsVista = g_isWindows7 = False
if g_isWindows :
win_ver = g_osVersion . split ( ' . ' )
win_ver_major = int ( win_ver [ 0 ] )
win_ver_minor = int ( win_ver [ 1 ] )
g_isWindowsVista = ( win_ver_major > = 6 )
g_isWindows7 = ( True if ( win_ver_major > 6 ) else ( win_ver_major == 6 and win_ver_minor > 0 ) )
# Initialize UI.
uiInitialize ( )
2021-03-15 15:31:52 +00:00
if __name__ == " __main__ " :
try :
main ( )
except KeyboardInterrupt :
pass