Hopper 除錯器
目標:透過 mcporter 將 Hopper 當作可查詢的反組譯工具,再將結果與本機原始碼、LLDB、日誌和焦點重現 (focused repro) 結合使用。
快速開始
驗證 MCP 伺服器:
MCPORTER_LIST_TIMEOUT=15000 timeout 20 mcporter list hopper --brief
列出已開啟的 Hopper 文件:
MCPORTER_CALL_TIMEOUT=20000 timeout 30 mcporter call hopper.list_documents --output json
如果沒有文件開啟,請先在 Hopper 中開啟二進位檔/框架:
open -a "Hopper Disassembler" /path/to/Binary
Hopper 可能會顯示首次開啟/匯入對話框。讓使用者點擊確認按鈕,然後重試 MCP 呼叫。避免並行執行 Hopper MCP 呼叫;伺服器可能會在匯入程序尚未穩定時關閉傳輸通道或導致 Hopper 當機。
Apple 框架
若已存在 dyld 快取框架二進位檔,優先使用:
/tmp/dsc-appkit/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
/tmp/dsc-appkit/System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
在除錯 SwiftUI/AppKit 邊界問題時,一次開啟一個:
open -a "Hopper Disassembler" /tmp/dsc-appkit/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
mcporter call hopper.list_documents --output json
open -a "Hopper Disassembler" /tmp/dsc-appkit/System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
mcporter call hopper.list_documents --output json
驗證存取:
mcporter call hopper.list_documents --output json
mcporter call hopper.current_document --output json
mcporter call hopper.search_strings pattern=SwiftUI --output json
mcporter call hopper.search_strings pattern=NSStatusItem --output json
文件名稱可能以 Untitled 開頭;在 Hopper 完成匯入後重試。使用 current_document、符號/字串搜尋以及視窗標題變化來區分 AppKit 與 SwiftUI。
查詢工作流程
- 從您試圖解釋的本機原始碼路徑或執行時期符號開始。
- 搜尋名稱/程序/字串:
mcporter call hopper.search_procedures pattern='NSStatusBar' --output json
mcporter call hopper.search_name pattern='NSStatusBarButtonCell' --output json
mcporter call hopper.search_strings pattern='NSStatusItem' --output json
- 一次檢查一個小目標:
mcporter call hopper.procedure_info procedure='<symbol>' --output json
mcporter call hopper.procedure_assembly procedure='<symbol>' --output json
mcporter call hopper.procedure_pseudo_code procedure='<symbol>' --output json
mcporter call hopper.procedure_callers procedure='<symbol>' --output json
mcporter call hopper.procedure_callees procedure='<symbol>' --output json
mcporter call hopper.xrefs address=0x12345678 --output json
- 總結相關的控制流程;不要貼上大量的反組譯內容。
- 在修改應用程式程式碼之前,先透過 LLDB/日誌/重現 (repro) 驗證假設。
狀態列項目 / 選單點擊錯誤
實用的 AppKit/SwiftUI 搜尋:
mcporter call hopper.search_strings pattern='NSStatusItem_Private_ForSwiftUI' --output json
mcporter call hopper.search_procedures pattern='popUpStatusBarMenu' --output json
mcporter call hopper.search_procedures pattern='trackMouse' --output json
mcporter call hopper.search_name pattern='NSStatusBarButtonCell' --output json
mcporter call hopper.search_name pattern='NSStatusItem' --output json
當選單列點擊無反應時,值得檢查的符號:
-[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:]-[NSStatusBarButtonCell _sendActionFrom:]-[NSStatusItem popUpStatusBarMenu:]-[NSApplication sendAction:to:from:]- 引用
NSStatusItem_Private_ForSwiftUI的 SwiftUI 狀態/選單符號
將反組譯結果與執行時期狀態進行比對:
pgrep -af "App.app/Contents/MacOS/App"
lldb /path/to/debug/Binary
對於有強化簽章的應用程式,如果沒有 get-task-allow 授權,附加 (attach) 可能會失敗;必要時請在 LLDB 下直接啟動原始除錯二進位檔。
失敗處理
- 使用
timeout包裝 Hopper 呼叫;模態對話框、匯入中或已關閉的文件可能導致傳輸通道卡住。 - 在匯入期間不要同時送出 Hopper MCP 請求。如果查詢耗時較長,請等待它完成後再開始下一個。
- 如果呼叫回報
Connection closed,請檢查 Hopper 是否有模態對話框,然後在確認後重試。 - 如果 Hopper 當機,請重新開啟單一文件,等待匯入/分析完成,並在進行更深層搜尋前重新執行
list_documents。 - 如果 mcporter 卡住,請先檢查程序再進行終止:
pgrep -af 'mcporter|HopperMCPServer|Hopper Disassembler'
- 優先選擇重新啟動 mcporter 守護行程,而不是大規模終止程序:
mcporter daemon stop
mcporter daemon start