# Behavior traces — 2dust/v2rayN

> Canonical page: https://codevetter.com/unpack/v2rayn/behavior-traces

# Behavior traces — 2dust/v2rayN

Scanned commit 28139853a8087d81e1ac7ffaf7013b937958f5d2 (2026-09-20). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

Three flows were traced end-to-end. Startup goes through single-instance guard, config load, SQLite table creation, ViewModel init, core init and a first Reload. Server activation goes through GetDefaultServer, CoreConfigContextBuilder.BuildAll, config generation, process spawn, system proxy update and an availability ping. Subscription update iterates SubItems, downloads with proxy fallback, parses into ProfileItem rows, and conditionally triggers Reload. Self-update and app-exit are also traced below.
- Startup (WPF): App.OnStartup -> Utils.GetMd5(GetExePath) EventWaitHandle single-instance check -> AppManager.InitApp (HasWritePermission fallback, Logging.Setup, ConfigHandler.LoadConfig, culture set, CreateTable x8) -> AppManager.InitComponents (StatePort/StatePort2 resolve, MigrateProfileExtra) -> MainWindowViewModel ctor -> Init(): InitBuiltinDNS, InitBuiltinFullConfigTemplate, ProfileExManager.Init, CoreManager.Init (copies bin/ when in local-appdata mode, chmods core exes on non-Windows), CertPemManager.Init, TaskManager.RegUpdateTask, StatisticsManager.Init -> RefreshServersDispatcherAsync -> Reload(). — [v2rayN/v2rayN/App.xaml.cs#L24-61](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/v2rayN/App.xaml.cs#L24-L61) [v2rayN/ServiceLib/Manager/AppManager.cs#L63-113](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/AppManager.cs#L63-L113) [v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L319-343](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L319-L343) [v2rayN/ServiceLib/Manager/CoreManager.cs#L21-61](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreManager.cs#L21-L61)
- Startup (Avalonia): Program.Main -> OnStartup (Windows EventWaitHandle or non-Windows Mutex 'v2rayN' single-instance, InitApp, WindowDialog) -> BuildAvaloniaApp(UsePlatformDetect, UseReactiveUI, macOS ShowInDock option) -> StartWithClassicDesktopLifetime -> App.OnFrameworkInitializationCompleted registers SimpleViewLocator DataTemplate, calls InitComponents, then constructs MainWindowViewModel + MainWindow. — [v2rayN/v2rayN.Desktop/Program.cs#L14-77](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/v2rayN.Desktop/Program.cs#L14-L77) [v2rayN/v2rayN.Desktop/App.axaml.cs#L16-41](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/v2rayN.Desktop/App.axaml.cs#L16-L41)
- Server activation (Reload): ConfigHandler.GetDefaultServer -> CoreConfigContextBuilder.BuildAll (main context + optional pre-socks) -> NoticeManager.NotifyValidatorResult (early-return on errors) -> CoreManager.LoadCore: CoreConfigHandler.GenerateClientConfig writes binConfigs/config.json -> CoreStop + 100ms delay -> Windows-only RemoveTunDevice when TUN -> CoreStart/RunProcess -> WaitForProxyPort does SOCKS5 greeting handshake with the pre-socks node -> CoreStartPreService writes and launches configPre.json -> SysProxyHandler.UpdateSysProxy -> StatusBarViewModel.TestServerAvailability -> SetSpeedTestResult -> optional ClashProxiesViewModel.ProxiesReload. — [v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L664-774](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L664-L774) [v2rayN/ServiceLib/Manager/CoreManager.cs#L65-212](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreManager.cs#L65-L212) [v2rayN/ServiceLib/Manager/CoreManager.cs#L219-286](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreManager.cs#L219-L286)
- Reload concurrency is guarded by a SemaphoreSlim: a concurrent Reload sets _hasNextReloadJob and returns; after the semaphore is released a queued reload runs once — so rapid toggles collapse to at most one extra pass. — [v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L661-751](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L661-L751)
- Subscription update: MainWindowViewModel.UpdateSubscriptionProcess -> Task.Run(SubscriptionHandler.UpdateProcess) -> per SubItem: IsValidSubscription (http/https only, id match, enabled) -> CreateDownloadHandler parses custom request headers (throws FormatException if invalid) -> DownloadSubscriptionContent via proxy then direct fallback -> ProcessDownloadResult -> ConfigHandler.AddBatchServers(isSub=true) -> UpdateTaskHandler refreshes the list and Reload()s only if the active profile's IndexId changed or belongs to the updated group. — [v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L574-577](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L574-L577) [v2rayN/ServiceLib/Handler/SubscriptionHandler.cs#L5-229](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs#L5-L229) [v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L359-387](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L359-L387)
- Clipboard/QR/image import: AddServerViaClipboardAsync reads text via ReadTextFromClipboardInteraction -> ConfigHandler.AddBatchServers -> RefreshSubscriptions + RefreshServersDispatcherAsync; scan flows go through ScanScreenInteraction/BrowseImageFileInteraction -> QRCodeUtils.ParseBarcode -> AddScanResultAsync -> same AddBatchServers path. — [v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L484-559](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs#L484-L559)
- Core process launch (normal): RunProcess -> CoreInfoManager.GetCoreExecFile finds first existing exe under bin/<coretype>/ -> RunProcessNormal formats Arguments template with the config path and env vars (e.g. XRAY_LOCATION_ASSET) -> ProcessService.StartAsync redirects stdout/stderr to UpdateFunc -> AddProcessJob attaches the handle to a Windows Job Object. — [v2rayN/ServiceLib/Manager/CoreManager.cs#L305-376](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreManager.cs#L305-L376) [v2rayN/ServiceLib/Manager/CoreInfoManager.cs#L32-51](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreInfoManager.cs#L32-L51) [v2rayN/ServiceLib/Services/ProcessService.cs#L56-71](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Services/ProcessService.cs#L56-L71)
- Core launch with TUN on Linux/macOS: ShouldRunAsSudo(isTunLaunch && coreType in {sing_box, mihomo, Xray} && IsNonWindows) -> CoreAdminManager.RunProcessAsLinuxSudo writes run_as_sudo.sh containing 'exec sudo -S -- env ... <core> <args>' -> ProcessService with redirectInput writes AppManager.LinuxSudoPwd to stdin -> CoreStop later calls KillProcessAsLinuxSudo which runs embedded kill_as_sudo_*_sh via bash -c with the saved PID and sudo -S. — [v2rayN/ServiceLib/Manager/CoreManager.cs#L298-322](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreManager.cs#L298-L322) [v2rayN/ServiceLib/Manager/CoreAdminManager.cs#L32-104](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreAdminManager.cs#L32-L104)
- Self-update: CheckUpdateGuiN -> CheckUpdateAsync -> GetRemoteVersion (GitHub releases API when preRelease/LockedMaxVersion, else /releases/latest redirect) -> ParseDownloadUrl picks arch URL and compares versions -> DownloadService.DownloadFileAsync to guiTemps/<guid> -> UpdateCompleted invokes updateFunc with UrlEncoded filename -> AmazTool launched with the path -> UpgradeApp.Upgrade kills v2rayN processes, extracts zip entries (strip first path segment, skip existing bin/*), restarts app. — [v2rayN/ServiceLib/Services/UpdateService.cs#L9-100](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Services/UpdateService.cs#L9-L100) [v2rayN/ServiceLib/Services/UpdateService.cs#L153-220](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Services/UpdateService.cs#L153-L220) [v2rayN/AmazTool/UpgradeApp.cs#L21-107](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/AmazTool/UpgradeApp.cs#L21-L107)
- App exit: AppManager.AppExitAsync -> SysProxyHandler.UpdateSysProxy(config, forceDisable:true) restores/clears system proxy -> AppEvents.AppExitRequested.Publish + 50ms wait -> ConfigHandler.SaveConfig -> ProfileExManager.SaveTo -> StatisticsManager.SaveTo -> CoreManager.CoreStop (sudo kill if needed, then ProcessService.StopAsync/Dispose) -> StatisticsManager.Close -> optionally Shutdown() publishing ShutdownRequested. — [v2rayN/ServiceLib/Manager/AppManager.cs#L122-159](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/AppManager.cs#L122-L159) [v2rayN/ServiceLib/Manager/CoreManager.cs#L147-175](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/CoreManager.cs#L147-L175)
- Reboot-as-admin path: RebootAsAdminCmd -> AppManager.RebootAsAdmin -> ProcUtils.RebootAsAdmin starts the exe with Verb='runas' and arg 'rebootas' -> AppExitAsync(true) shuts down; on the new process OnStartup sees Global.RebootAs in args and bypasses the single-instance exit so the elevated instance takes over. — [v2rayN/ServiceLib/Manager/AppManager.cs#L155-159](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Manager/AppManager.cs#L155-L159) [v2rayN/ServiceLib/Common/ProcUtils.cs#L49-67](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/ServiceLib/Common/ProcUtils.cs#L49-L67) [v2rayN/v2rayN/App.xaml.cs#L26-35](https://github.com/2dust/v2rayN/blob/28139853a8087d81e1ac7ffaf7013b937958f5d2/v2rayN/v2rayN/App.xaml.cs#L26-L35)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
