From c53f70238f41e9c7f3b8b5b1fe43ee3437c8ccd0 Mon Sep 17 00:00:00 2001 From: Zhang Boyang Date: Fri, 22 Oct 2021 02:21:32 +0800 Subject: [PATCH] v1.1 --- audio_crc32.py | 37 +++++++++++++++++++++++++++++++----- llusbdac/llusbdac.h | 2 +- llusbdac/uac2.c | 40 ++++++++++++++++++++++++++++----------- llusbdac_installer.py | 27 ++++++++++++++++---------- userguide/USERGUIDE_EN.md | 6 ++++-- userguide/USERGUIDE_ZH.md | 4 +++- 6 files changed, 86 insertions(+), 30 deletions(-) diff --git a/audio_crc32.py b/audio_crc32.py index 79b76c5..168437a 100755 --- a/audio_crc32.py +++ b/audio_crc32.py @@ -6,6 +6,32 @@ import zlib import traceback import gc +if os.name == 'nt': + import msvcrt + import win32gui + import win32con + import win32console + files = sys.argv[1:] + if not files: + try: + ret = win32gui.GetOpenFileNameW( + hwndOwner=win32console.GetConsoleWindow(), + MaxFile=1048576, + Flags= + win32con.OFN_ALLOWMULTISELECT | + win32con.OFN_PATHMUSTEXIST | + win32con.OFN_FILEMUSTEXIST | + win32con.OFN_HIDEREADONLY | + win32con.OFN_EXPLORER | + win32con.OFN_DONTADDTORECENT | + win32con.OFN_NOCHANGEDIR) + files = ret[0].split('\0') + if len(files) > 1: + files = [os.path.join(files[0], file) for file in files[1:]] + except win32gui.error: + files = [] +else: + files = sys.argv[1:] if getattr(sys, "frozen", False): os.chdir(os.path.dirname(sys.executable)) @@ -94,15 +120,15 @@ def process(filename): finally: table.append(line) -for argv in sys.argv[1:]: - if os.path.isdir(argv): - for root, dirs, files in os.walk(argv): +for filepath in files: + if os.path.isdir(filepath): + for root, dirs, files in os.walk(filepath): dirs.sort() files.sort() for name in files: process(os.path.join(root, name)) else: - process(argv) + process(filepath) print("--------------+-------------------------------------------+-----------------") print(" TIME | S16LE S24_3LE S32LE | FILE") @@ -111,4 +137,5 @@ def process(filename): print("--------------+-------------------------------------------+-----------------") if os.name == "nt": - os.system("pause") + print(" press any key to exit ... ", end='', file=sys.stderr, flush=True) + msvcrt.getch() diff --git a/llusbdac/llusbdac.h b/llusbdac/llusbdac.h index c233b2c..cfc3b99 100644 --- a/llusbdac/llusbdac.h +++ b/llusbdac/llusbdac.h @@ -3,7 +3,7 @@ #include #include -#define LLUSBDAC_VERSTRING "1.0" +#define LLUSBDAC_VERSTRING "1.1" #define LLUSBDAC_IDVENDER 0x054C #define LLUSBDAC_IDPRODUCT 0x0B8B #define LLUSBDAC_NAME "LLUSBDAC (NW-ZX300A)" diff --git a/llusbdac/uac2.c b/llusbdac/uac2.c index e8d21ad..3ef3e05 100644 --- a/llusbdac/uac2.c +++ b/llusbdac/uac2.c @@ -28,11 +28,28 @@ #include "llusbdac.h" // dirty things -#include -#include #include +#include +#include static void (**p_pf_get_uac2_buf_status)(u32 *status); #define pf_get_uac2_buf_status (*p_pf_get_uac2_buf_status) +static void (*p_uac2_netlink_rcv)(struct sk_buff *__skb); +#define uac2_netlink_rcv p_uac2_netlink_rcv +static struct sock * uac2_netlink_init(void) +{ + struct sock *uac2sock; + struct netlink_kernel_cfg cfg = { + .input = uac2_netlink_rcv, + }; + uac2sock = netlink_kernel_create(&init_net, NETLINK_UAC2, &cfg); + //printk("uac2sock=%p\n", uac2sock); + return uac2sock; +} +static void uac2_netlink_exit(struct sock *sock) +{ + netlink_kernel_release(sock); +} + #ifndef __LITTLE_ENDIAN #error @@ -98,6 +115,8 @@ struct audio_dev { struct usb_ep *fb_ep; struct usb_function func; + struct sock *sock; + void *rbuf; unsigned max_psize; struct uac2_req ureq[USB_XFERS]; @@ -116,7 +135,7 @@ struct audio_dev *func_to_agdev(struct usb_function *f) return container_of(f, struct audio_dev, func); } -#define FEEDBACK_PERIOD 8 // xref: hs_epfb_desc.bInterval, do_dirty_musb_hook +#define FEEDBACK_PERIOD 8 // xref: hs_epfb_desc.bInterval static unsigned fb_low_limit, fb_high_limit; void set_feedback_limits_base10000(unsigned low_limit, unsigned high_limit) { @@ -442,7 +461,7 @@ struct usb_endpoint_descriptor hs_epfb_desc = { .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_USAGE_FEEDBACK, .wMaxPacketSize = 512, //.bInterval = 1, - .bInterval = 4, // xref: FEEDBACK_PERIOD, do_dirty_musb_hook + .bInterval = 4, // xref: FEEDBACK_PERIOD }; @@ -561,6 +580,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) agdev->as_out_intf = ret; agdev->as_out_alt = 0; + agdev->sock = uac2_netlink_init(); + agdev->out_ep = usb_ep_autoconfig(gadget, &hs_epout_desc); if (!agdev->out_ep) { pr_err( @@ -612,6 +633,8 @@ afunc_unbind(struct usb_configuration *cfg, struct usb_function *fn) printk("afunc_unbind\n"); struct audio_dev *agdev = func_to_agdev(fn); + uac2_netlink_exit(agdev->sock); + usb_free_all_descriptors(fn); if (agdev->out_ep) @@ -915,7 +938,6 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr) return value; } -//static void do_dirty_musb_hook(int en, struct musb *musb); int audio_bind_config(struct usb_configuration *cfg) { @@ -970,8 +992,6 @@ int audio_bind_config(struct usb_configuration *cfg) kfree(agdev_g); enable_gui(1); - - //do_dirty_musb_hook(1, gadget_to_musb(cfg->cdev->gadget)); return res; } @@ -979,7 +999,6 @@ int audio_bind_config(struct usb_configuration *cfg) void uac2_unbind_config(struct usb_configuration *cfg) { printk("uac2_unbind_config\n"); - //do_dirty_musb_hook(0, gadget_to_musb(cfg->cdev->gadget)); enable_gui(-1); kfree(agdev_g); @@ -996,9 +1015,8 @@ int gadget_enabled(void) } - - void uac2_init(void) { IMPORT_KALLSYMS(pf_get_uac2_buf_status); -} \ No newline at end of file + IMPORT_KALLSYMS(uac2_netlink_rcv); +} diff --git a/llusbdac_installer.py b/llusbdac_installer.py index a687904..99d7cd4 100644 --- a/llusbdac_installer.py +++ b/llusbdac_installer.py @@ -20,11 +20,6 @@ import win32event import wmi -try: - ctypes.windll.user32.SetProcessDPIAware() -except: - pass - def die(status): win32api.TerminateProcess(win32api.GetCurrentProcess(), status) def die_after(status, sec): @@ -33,8 +28,13 @@ def die_fn(): die(status) threading.Thread(target=die_fn).start() +try: + ctypes.windll.user32.SetProcessDPIAware() +except: + pass + -llusbdac_ver = "v1.0" +llusbdac_ver = "v1.1" if getattr(sys, "frozen", False): safeloader_dir = sys._MEIPASS @@ -127,6 +127,7 @@ class InstallerCorruptedError(Exception): "START": "开始安装", "LEAVE": "取消安装", "MULTI_INST": "安装工具已经在运行中,请勿多开。", + "INFORM_RISK": "安装 LLUSBDAC 需要修改播放器的固件。\n修改固件具有一定危险性,可能会导致失去保修,甚至损坏设备。\n本软件作者对任何损坏或损失不承担任何责任。\n\n是否继续?", "CANCEL": "取消", "ERROR": "错误", @@ -135,7 +136,7 @@ class InstallerCorruptedError(Exception): "VERIFY_PACKAGE": "正在验证固件升级包", "NO_PACKAGE": "未找到固件升级包,\n", "BAD_PACKAGE": "固件升级包已损坏,\n", - "ASK_DOWNLOAD": "要立即从 SONY 服务器上下载吗?", + "ASK_DOWNLOAD": "要立即从 SONY 服务器上下载吗?\n\n注意:下载固件即表示您同意固件随附的条款与条件。", "DOWNLOAD_PROGRESS": "已下载 %.0f%%", "DOWNLOAD_ERROR": "下载过程中发生错误。", "ERR_PACKAGE": "固件升级包验证失败,无法继续安装。", @@ -169,6 +170,7 @@ class InstallerCorruptedError(Exception): "START": "Start", "LEAVE": "Cancel", "MULTI_INST": "Installer is running. Please don't open multiple instances.", + "INFORM_RISK": "In order to install LLUSBDAC, installer will modify the firmware of your player.\nThis may void warranty or damage your device.\nPlease use at your own risk.\n\nContinue?", "CANCEL": "Cancel", "ERROR": "Error", @@ -177,7 +179,7 @@ class InstallerCorruptedError(Exception): "VERIFY_PACKAGE": "Verifying update package ...", "NO_PACKAGE": "Update package not found.\n", "BAD_PACKAGE": "Update package corrupted.\n", - "ASK_DOWNLOAD": "Download it from SONY server now?", + "ASK_DOWNLOAD": "Download it from SONY server now?\n\nNOTE: Downloading it means you agree its EULA.", "DOWNLOAD_PROGRESS": "Download progress %.0f%% ...", "DOWNLOAD_ERROR": "Download error:", "ERR_PACKAGE": "Can't verify update package, installation aborted.", @@ -246,17 +248,22 @@ def reporthook_fn(xferd, bs, count): c = wmi.WMI() -# single instance +# allow only one instance def single_instance(): mutex = win32event.CreateMutex(None, True, "LLUSBDAC_INSTALLER_MUTEX") ret = win32event.WaitForSingleObject(mutex, 2000) if ret != win32event.WAIT_OBJECT_0 and ret != win32event.WAIT_ABANDONED: - win32api.MessageBox(None, S["MULTI_INST"], S["TITLE"], win32con.MB_ICONERROR) + win32api.MessageBox(None, S["MULTI_INST"], S["TITLE"], win32con.MB_ICONERROR | win32con.MB_TOPMOST) die(1) mutex.Detach() single_instance() +# inform user the risk +if win32api.MessageBox(None, S["INFORM_RISK"], S["TITLE"], win32con.MB_ICONWARNING | win32con.MB_YESNO | win32con.MB_TOPMOST) != win32con.IDYES: + die(1) + + # ask user for installer options def ask_options(): class InstallerOptionsDialog: diff --git a/userguide/USERGUIDE_EN.md b/userguide/USERGUIDE_EN.md index 0fc685c..d0e14d8 100644 --- a/userguide/USERGUIDE_EN.md +++ b/userguide/USERGUIDE_EN.md @@ -12,7 +12,9 @@ Installer only supports Windows operating system. However, after installation in ## Installation -Connect your device to a computer as "USB mass storage device". Then run `llusbdac_installer.exe` and follow instructions on screen. +1. Download `NW-ZX300_V2_02.exe` from [sony website](https://www.sony.com/electronics/support/digital-music-players-nw-nwz-zx-series/nw-zx300/downloads/00016328), put it along with `llusbdac_installer.exe`. +2. Connect your device to a computer as "USB mass storage device". +3. Run `llusbdac_installer.exe` and follow instructions on screen. ## Usage @@ -57,4 +59,4 @@ Sample results: ## Source code -  This program is released under GPLv2. You can get the source code from [GitHub](https://github.com/zhangboyang/llusbdac). +This program is released under GPLv2. You can get the source code from [GitHub](https://github.com/zhangboyang/llusbdac). diff --git a/userguide/USERGUIDE_ZH.md b/userguide/USERGUIDE_ZH.md index 889d716..aa57b81 100644 --- a/userguide/USERGUIDE_ZH.md +++ b/userguide/USERGUIDE_ZH.md @@ -12,7 +12,9 @@ ## 安装方法 -  将设备以“USB 大容量存储”模式连接至计算机,运行 `llusbdac_installer.exe`,然后按屏幕指示操作即可。 +1. 从[索尼网站](https://service.sony.com.cn/download/firm/00002817.html)上下载 `NW-ZX300_V2_02.exe`,将它与 `llusbdac_installer.exe` 放置于同一目录下; +2. 将设备以“USB 大容量存储”模式连接至计算机; +3. 运行 `llusbdac_installer.exe`,然后按屏幕指示操作即可。 ## 使用方法