V45.38: suppress iZotope 0x7E dialog
- _is_vst2_dll: pure-Python PE export-table check (magic-aware dd offset PE32+112) -> IZOzone11Core.dll (runtime lib, no VSTPluginMain) dropped from VST2 lists in _scan_plugins and list_scan_all; plugins.py same. - _hidden_desktop_startupinfo: scan subprocess runs on hidden desktop (user32 CreateDesktopW, HDESK restype) -> third-party MessageBox invisible. - SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX) in all 4 bridge mains: missing dependency DLL fails silently instead of blocking.
This commit is contained in:
+135
-2
@@ -7,6 +7,7 @@ import time as _time
|
||||
import functools
|
||||
import threading
|
||||
from ctypes import c_char_p
|
||||
import struct
|
||||
import subprocess
|
||||
|
||||
|
||||
@@ -38,6 +39,121 @@ def _ensure_fluidsynth_dll_on_path():
|
||||
_ensure_fluidsynth_dll_on_path()
|
||||
|
||||
|
||||
def _is_vst2_dll(path: str) -> bool:
|
||||
"""True nếu .dll export entry VST2 (VSTPluginMain hoặc main) — plugin
|
||||
VST2 thật (Kong Audio Qin_RV_x64.dll...). Các thư viện runtime đặt cạnh
|
||||
plugin (vd iZotope Cores/IZOzone11Core.dll — core của Ozone, KHÔNG phải
|
||||
plugin) không export entry VST2 → loại khỏi danh sách plugin: load chúng
|
||||
như VST2 gây lỗi dependency 0x7E. Đọc export table PE thuần Python, không
|
||||
load DLL vào process."""
|
||||
if not path.lower().endswith(".dll"):
|
||||
return False
|
||||
try:
|
||||
f = open(path, "rb")
|
||||
except OSError:
|
||||
return False
|
||||
try:
|
||||
head = f.read(0x1000)
|
||||
if len(head) < 0x40 or head[:2] != b"MZ":
|
||||
return False
|
||||
e_lfanew = struct.unpack_from("<I", head, 0x3C)[0]
|
||||
if e_lfanew + 24 + 120 + 8 > len(head):
|
||||
return False
|
||||
if head[e_lfanew:e_lfanew + 4] != b"PE" + bytes(2):
|
||||
return False
|
||||
num_sections = struct.unpack_from("<H", head, e_lfanew + 6)[0]
|
||||
opt_size = struct.unpack_from("<H", head, e_lfanew + 20)[0]
|
||||
sec_start = e_lfanew + 24 + opt_size
|
||||
if sec_start + num_sections * 40 > len(head):
|
||||
return False
|
||||
# Data directory 0 = export table (RVA, size): PE32 -> opt+96,
|
||||
# PE32+ (x64) -> opt+112 (magic 0x10B / 0x20B).
|
||||
magic = struct.unpack_from("<H", head, e_lfanew + 24)[0]
|
||||
dd = 96 if magic == 0x10B else (112 if magic == 0x20B else 0)
|
||||
if dd == 0:
|
||||
return False
|
||||
exp_rva = struct.unpack_from("<I", head, e_lfanew + 24 + dd)[0]
|
||||
exp_size = struct.unpack_from("<I", head, e_lfanew + 24 + dd + 4)[0]
|
||||
if exp_rva == 0 or exp_size == 0:
|
||||
return False
|
||||
secs = []
|
||||
for i in range(num_sections):
|
||||
off = sec_start + i * 40
|
||||
va = struct.unpack_from("<I", head, off + 12)[0]
|
||||
raw_size = struct.unpack_from("<I", head, off + 16)[0]
|
||||
raw_ptr = struct.unpack_from("<I", head, off + 20)[0]
|
||||
secs.append((va, raw_size, raw_ptr))
|
||||
|
||||
def rva_to_off(rva):
|
||||
for va, raw_size, raw_ptr in secs:
|
||||
if va <= rva < va + raw_size:
|
||||
return raw_ptr + (rva - va)
|
||||
return None
|
||||
|
||||
exp_off = rva_to_off(exp_rva)
|
||||
if exp_off is None:
|
||||
return False
|
||||
f.seek(exp_off)
|
||||
exp = f.read(40)
|
||||
if len(exp) < 40:
|
||||
return False
|
||||
num_names = struct.unpack_from("<I", exp, 24)[0]
|
||||
if num_names == 0 or num_names > 65536:
|
||||
return False
|
||||
names_off = rva_to_off(struct.unpack_from("<I", exp, 32)[0])
|
||||
if names_off is None:
|
||||
return False
|
||||
f.seek(names_off)
|
||||
name_ptrs = f.read(num_names * 4)
|
||||
if len(name_ptrs) < num_names * 4:
|
||||
return False
|
||||
for i in range(num_names):
|
||||
noff = rva_to_off(struct.unpack_from("<I", name_ptrs, i * 4)[0])
|
||||
if noff is None:
|
||||
continue
|
||||
f.seek(noff)
|
||||
raw = f.read(64)
|
||||
nm = raw.split(bytes(1), 1)[0].decode("ascii", "replace")
|
||||
if nm in ("VSTPluginMain", "main"):
|
||||
return True
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
|
||||
def _hidden_desktop_startupinfo():
|
||||
"""STARTUPINFO cho process con chạy trên DESKTOP ẨN mới tạo: dialog của
|
||||
plugin bên thứ ba (vd iZotope MessageBox [0x7E] khi core load fail trong
|
||||
--scan) hiện trên desktop vô hình → user không bị chặn, scan bỏ module sau
|
||||
timeout 4s như cũ. Trả (startupinfo, desktop_handle) — handle phải đóng
|
||||
sau khi process con kết thúc; (None, None) khi không tạo được (fallback
|
||||
desktop thường)."""
|
||||
if os.name != "nt":
|
||||
return None, None
|
||||
try:
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
u32 = ctypes.windll.user32 # CreateDesktopW/CloseDesktop thuộc USER32
|
||||
u32.CreateDesktopW.restype = ctypes.c_void_p # HDESK 64-bit, không cắt
|
||||
u32.CreateDesktopW.argtypes = [wintypes.LPCWSTR, wintypes.LPCWSTR,
|
||||
wintypes.LPVOID, wintypes.DWORD,
|
||||
wintypes.DWORD, wintypes.LPVOID]
|
||||
u32.CloseDesktop.restype = wintypes.BOOL
|
||||
u32.CloseDesktop.argtypes = [wintypes.HANDLE]
|
||||
name = "SF_Scan_%d_%d" % (os.getpid(), int(_time.time() * 1000) % 1000000)
|
||||
# DESKTOP_ALL_ACCESS (0x000F01FF) — handle chỉ để giữ desktop sống.
|
||||
h = u32.CreateDesktopW(name, None, None, 0, 0x000F01FF, None)
|
||||
if not h:
|
||||
return None, None
|
||||
si = subprocess.STARTUPINFO()
|
||||
si.lpDesktop = name
|
||||
return si, h
|
||||
except Exception:
|
||||
return None, None
|
||||
|
||||
|
||||
def midi_note_to_freq(note_number: int) -> float:
|
||||
return 440.0 * (2.0 ** ((note_number - 69) / 12.0))
|
||||
|
||||
@@ -378,7 +494,8 @@ class PluginManager:
|
||||
plugin_name = os.path.splitext(file)[0]
|
||||
if plugin_name not in plugins:
|
||||
plugins[plugin_name] = plugin_path
|
||||
elif low.endswith(".dll") and not has_vst3_file:
|
||||
elif (low.endswith(".dll") and not has_vst3_file
|
||||
and _is_vst2_dll(os.path.join(root, file))):
|
||||
plugin_path = os.path.join(root, file)
|
||||
plugin_name = os.path.splitext(file)[0]
|
||||
if plugin_name not in plugins:
|
||||
@@ -582,12 +699,20 @@ class PluginManager:
|
||||
if exe:
|
||||
dirs = [d for d in self._vst_scan_dirs() if d and os.path.isdir(d)]
|
||||
for d in dirs:
|
||||
si, hdesk = _hidden_desktop_startupinfo()
|
||||
try:
|
||||
r = subprocess.run([exe, "--scan", d], capture_output=True,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0,
|
||||
text=True, timeout=300)
|
||||
text=True, timeout=300, startupinfo=si)
|
||||
except Exception:
|
||||
continue
|
||||
finally:
|
||||
if hdesk:
|
||||
try:
|
||||
import ctypes
|
||||
ctypes.windll.user32.CloseDesktop(hdesk)
|
||||
except Exception:
|
||||
pass
|
||||
if r.returncode != 0:
|
||||
continue
|
||||
try:
|
||||
@@ -620,6 +745,14 @@ class PluginManager:
|
||||
continue
|
||||
seen.add(e["path"])
|
||||
uniq.append(e)
|
||||
# Loại .dll KHÔNG phải VST2 thật (không export VSTPluginMain/main —
|
||||
# vd iZotope Cores/IZOzone11Core.dll là runtime lib, không phải
|
||||
# plugin): bridge scan emit mọi .dll thành VST2 instrument → load như
|
||||
# plugin gây 0x7E. Kiểm export table thuần Python, không load DLL.
|
||||
uniq = [e for e in uniq
|
||||
if not (e.get("type") == "VST2"
|
||||
and (e.get("path") or "").lower().endswith(".dll")
|
||||
and not _is_vst2_dll(e["path"]))]
|
||||
# Chỉ cache khi bridge tồn tại: kết quả (kể cả rỗng — dir không có
|
||||
# FX) là đáng tin; khi thiếu bridge thì trả [] nhưng KHÔNG cache.
|
||||
if exe:
|
||||
|
||||
Reference in New Issue
Block a user