Repository navigation
Attach to the WeChat copy that owns the selected data folder - #46
Merged
Merged
Conversation
With two WeChat app copies running, preflight and capture could not pick between them (#43 made that a refusal), a single running copy was never checked against the data folder, and the re-attach after logout looked the process up by name again, so it could switch copies. The locator now lists only the invoking user's WeChat processes (pgrep -U, SUDO_UID under sudo) and describes each one by its main executable (proc_pidpath), enclosing .app bundle and CFBundleIdentifier. A data folder under ~/Library/Containers/<bundle id>/Data belongs to that bundle ID, and pure selection rules choose the one process running that app; no match or several matches block preflight. Data outside an app container needs the new --pid option, which is checked for the same user, a WeChat main executable and, where it can be told, the owning app. The capture re-attaches only to the same app path and bundle ID. Preflight reads version and signing from the selected process's app and prints the re-sign command for that copy. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Re-selection keeps the selected process while it still runs the same app (path, bundle ID, user), so --pid disambiguates two instances of one app on the first attach. Only after it exits must exactly one replacement run that app. The capture now follows each replacement. - Preflight resolves the database root once and uses that result for process selection, the database inventory and the capture, so the three can no longer diverge (and a failed first discovery can no longer yield ready without a target). - The re-sign command for a non-default app copy shows a placeholder instead of the app's path, in both the remediation and the blocker text, unless --include-paths is given. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- When --pid picks one of several instances of the same app, the other instances running at that moment are recorded on the target. After the chosen process exits, only a process that was not already running can replace it; while none qualifies the capture keeps waiting until its timeout, and two new ones are ambiguous. The exclusion carries over to each replacement. - After a successful preflight, the suggested capture command repeats the explicit --pid and --db-root, with a placeholder for the database path unless --include-paths is given. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Candidates and targets carry the process start time (proc_pidinfo PROC_PIDTBSDINFO pbi_start_tvsec/usec). The selected process is kept only while the same PID with the same start time runs, which also guards against PID reuse. - When the selected process is gone, the moment its exit was observed is recorded (by the capture when lldb reports the exit, otherwise on the first lookup that misses it). A replacement must run the same app and must have started strictly after that moment; an instance that started while the selected one was still running, or one whose start time is unknown, is never attached. While none qualifies the capture keeps waiting and fails closed at the timeout. The rule stays a pure function with injected times. - Database-root ownership canonicalizes the root and home first (F_GETPATH on an O_EVTONLY descriptor), so a root typed in another letter case or reached through a link maps to its container's on-disk bundle ID instead of becoming unknown. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The capture records the exit time at the moment it reads lldb's exit report and carries it out through lldb cleanup, which can take up to 3 seconds. A replacement that starts during cleanup is no longer rejected. - If the selected process (same PID and start time) is still listed but its app metadata is momentarily unreadable, the capture skips that attach without recording an exit. - Siblings excluded at selection are stored as PID plus start time, so a later process that reuses one of their PIDs can still be the replacement. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #45 (duplicate-container discovery). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- WeChatProcessLocator no longer calls the static bundleIdentifier(...) from inside the initializer of a local of the same name; older Swift (macos-15 CI) resolved the call to the local and failed to compile. - Automatic selection refuses when any live WeChat process of the user can't be classified (unknown user, app bundle or bundle ID), since it might own the database root; preflight asks for --pid instead. - Re-selection skips a poll, without recording an exit, while the selected PID is listed and nothing read proves it is a different process (for example when proc_pidinfo fails for one poll). It picks a replacement only from a conclusive list: with any unclassifiable live process of the user, it keeps waiting. - The capture takes the exit timestamp as soon as lldb's exit report is parsed, before verifying any candidate from the same batch. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Every PID pgrep lists stays a candidate. When neither proc_pidinfo nor proc_pidpath describes it, it is kept with no details (unclassified) unless kill(pid, 0) reports ESRCH. Selection then treats it as unresolved: preflight asks for --pid, re-selection keeps waiting, and a selected PID that is listed but unreadable skips the poll without recording an exit. - Container bundle IDs are compared with CFBundleIdentifier case-insensitively in automatic and --pid selection; several matches are still rejected. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #33 (query profiles, invoking-user file access). main.swift is rebuilt on #33's version: runPreflight resolves the database root once through #33's userDatabaseRoot (as the invoking user, realpath-checked) and uses that root for the owner lookup (also as the invoking user), process selection, the inventory and the capture; the locator counts only invokingUser.uid's processes. --pid is parsed beside --profile and added to #33's capture-command argument list, replacing the separate hint. #33's privilege switch, writer and profile code are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A process's Info.plist is read only when the kernel reports that it belongs to the invoking user, and then with that user's permissions (invokingUser.perform). The plist is opened without following a link at the final component and accepted only when the opened file is a regular file at <resolved app>/Contents/Info.plist (at most 1 MiB). Other users' and unverifiable processes stay unclassified. The selected app's build inspection also runs as the invoking user. - A failure to look up the database root's owner is now a preflight blocker, distinct from a successful lookup that places the root outside any app container. - pgrep statuses other than 0 and 1 are listing errors, not "no process". During capture a failed listing skips that poll without changing the recorded exit state. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ocking - Info.plist is opened with O_NONBLOCK as well, so a FIFO with no writer cannot block before the regular-file check rejects it. - WeChatProcessTarget and ProcessIdentity require a known start time; two missing start times are never the same process. A candidate without one is never turned into a target: automatic selection rejects it as unclassified (asks for --pid) and --pid reports that the process's identity can't be read. Refs #34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34, together with #45 (discovery of the second copy's container). The two PRs are independent and merge cleanly in either order. Merging #45 first lets this one close the issue fully.
What
greenbubbles-acquirenow picks the WeChat process from the app that owns the selecteddb_storageroot. Before, it took the lowest PID (later changed by #43 to refuse when several were running).~/Library/Containers/<bundle id>/Data/…belongs to<bundle id>. The tool reads each runningWeChatprocess's app bundle and uses the one that matches. If no process matches, or several do, preflight blocks; it never guesses.--pid <n>. Chooses the process explicitly. It must belong to the invoking user and be a WeChat main executable (<X>.app/Contents/MacOS/WeChat, with a matchingCFBundleExecutable). Where the owning app can be told from the root's path, the process must belong to that app.--pidis required for roots outside an app container, such as group containers, backups, or other locations. There is no override flag./Applications/WeChat.app(item 3). The re-sign hint names that copy's path. The process line shows the PID and bundle ID. The JSON report gainsselectedProcessID,selectedApplicationBundleIdentifieranddatabaseRootApplicationBundleIdentifier.pgrep -x -U <uid> WeChat, withSUDO_UIDunder sudo.Behaviour with only the standard copy and the standard container is unchanged: zero processes means "not running", and one process is selected.
How
WeChatProcessSelection.swift(new) holds the pure rules:DatabaseRootOwner.resolve(databaseRoot:homeDirectory:),WeChatProcessSelector.select,.validate(for--pid),.reselect(for re-attach) and.applicationPath(forExecutablePath:). They work onWeChatProcessCandidatevalues(pid, uid, exe path, app path, bundle ID), so they are tested without real processes.WeChatProcessLocatorbuilds the candidates:proc_pidinfofor the real UID,proc_pidpathfor the executable, then the enclosing.appand itsInfo.plist.LLDBPassphraseCapturegainsvar target: WeChatProcessTarget?. The only change to the capture loop is the one-line process lookup, to keep conflicts with fix(acquire): wait for the SQLCipher PBKDF call during capture #31 small. Withtarget == nilit behaves as before.main.swift:--pid, aselectProcessstep before the install/version check, and passing the target to capture.Tests
New
WeChatProcessSelectionTests(16 tests), all on synthetic candidate lists and paths:./..normalisation, group container, container root only, a non-Datasubfolder, a backup path, another user's home--pid--pid: accepted for the owning copy and for an unknown owner; rejected for the wrong copy, a missing PID, another user's process, a non-WeChat process, or an executable outside an app.apppath extraction,SUDO_UIDhandling, and reading theInfo.plistbundle ID from a temp.appAll tests were run with Command Line Tools only, in a scratch copy of the package with the SwiftUI
GreenBubblesHistoryApptarget removed (Package.swift is unchanged here). Results:swift build --product greenbubbles-acquiresucceeds in the worktreegreenbubbles-acquire helpand argument validation for--pid 0workNot tested live
No real WeChat, no debugger attach, no sudo, and no real
~/Librarydata were used. These parts are untested:pgrep -U,proc_pidpathandproc_pidinfoagainst a real duplicated WeChat. This includes whether a duplicate's main executable is stillContents/MacOS/WeChatwith a matchingCFBundleExecutable, which the issue reporter's setup suggests.A data folder outside
~/Library/Containersnow needs--pideven when a single WeChat is running. Before, the tool attached to that single process.🤖 Generated with Claude Code