Files
WechatExplorer/src/shared/personal-wechat-mac-runtime.ts
T
2026-11-18 11:31:50 +08:00

130 lines
3.7 KiB
TypeScript

/**
* Wire types for the built-in macOS native WeChat runtime
* (tm-wechat-host + libtmwechat.dylib), managed by MacWechatRuntimeManager.
*
* Binding lifecycle is "bind once per WeChat process": frida's unload/detach
* inside WeChat is unreliable, so rebind is NOT a product path. When the host
* dies while bound, the WeChat process keeps an orphaned agent and must be
* restarted before binding again — surfaced as wechatRestartRequired.
*/
export type MacWechatRuntimeLifecycle =
| 'stopped' // host not running (or never started)
| 'starting' // spawn issued, waiting for /healthz
| 'online' // host answering; WeChat NOT touched (lazy)
| 'crashed_unbound' // died while unbound — safe to auto-restart
| 'crashed_bound' // died while bound — WeChat keeps an orphan agent
export type MacWechatSendRuntimeAvailability = 'unavailable' | 'component_error' | 'available'
export interface MacWechatSendRuntimeAvailabilityResult {
state: MacWechatSendRuntimeAvailability
message: string
}
export interface MacWechatResidualProcess {
pid: number
name: string
state?: string
/** 明确处于内核不可中断等待状态。 */
uninterruptible?: boolean
targets: Array<'wechat' | 'host' | 'port_4290' | 'frida_helper'>
confirmationToken: string
}
export interface MacWechatResidualCleanupResult {
stopped: MacWechatResidualProcess[]
remaining: MacWechatResidualProcess[]
runtimeStopped: boolean
}
export type MacWechatHostRuntimeState =
| 'not_initialized'
| 'wechat_not_running'
| 'not_logged_in'
| 'unsupported_version'
| 'initializing'
| 'ready'
| 'error'
| 'unknown'
export type MacWechatBindingState =
| 'unbound'
| 'binding'
| 'bound'
| 'ready'
| 'failed'
| 'stale'
| 'unknown'
export interface MacWechatRuntimeManifest {
runtime: 'tm-wechat-native'
version: string
platform: 'darwin-arm64'
architecture: 'arm64'
protocolVersion: number
buildCommit: string
tmSendSourceSha256: string
addressProfileSha256: string
supportedWechatVersions: string[]
capabilities: Array<'text' | 'image' | 'voice' | 'file'>
capabilitiesByVersion?: Record<
string,
{
text?: 'verified' | 'addresses-only' | 'unsupported'
image?: 'verified' | 'addresses-only' | 'unsupported'
voice?: 'verified' | 'addresses-only' | 'unsupported'
file?: 'verified' | 'addresses-only' | 'unsupported'
downloadImage?: 'verified' | 'addresses-only' | 'unsupported'
textMechanism?: string
}
>
}
export interface MacWechatBindingStatus {
runtime: boolean
hostPid?: number
runtimeState: MacWechatHostRuntimeState
runtimeVersion?: string
embeddedAgentSha256?: string
embeddedAddressProfileSha256?: string
abiVersion?: number
dylibPath?: string
wechatRunning: boolean
wechatPid: number
wechatVersion?: string
supported: boolean
bindingState: MacWechatBindingState
bound: boolean
boundWechatPid: number
sessionAttached: boolean
scriptLoaded: boolean
sendContextReady: boolean
canSendText?: boolean
canSendImage?: boolean
canSendVoice?: boolean
attachCount: number
lastAttachAt?: string
lastDetachReason?: string
}
export interface MacWechatRuntimeSnapshot {
lifecycle: MacWechatRuntimeLifecycle
/** True when the last host death happened while bound: WeChat must be restarted. */
wechatRestartRequired: boolean
endpoint: string
port: number
/** 自动切换端口时记录首选端口。 */
portFallbackFrom?: number
runtimeDir?: string
error?: string
binding?: MacWechatBindingStatus
}
export interface MacWechatBindResult {
ok: boolean
attached: boolean
state?: 'wechat_restart_required' | 'runtime_offline' | 'host_error' | 'bad_response'
message: string
}