Skip to content

Scan Logic

This document describes the scanning logic implemented in the Xdows Security Scan Page (targeting developers).

Feature Overview

Offers four virus-scanning modes: Quick, Full, File, and Folder, with support for multi-engine parallel scanning and asynchronous streaming UI updates.

InputOutput
Scan Mode + User Path + Engine TogglesReal-time progress, threat list, statistics, log entries

Sequence Overview

Engine Priority

ts
async function scanFile(path: string): Promise<string | null> {
  if (useSouXiao)        return await souXiaoScan(path);
  if (useLocal)          return await localScan(path, deep, extra);
  if (useJiSuSafeAXMode) return await AXScan(path);
  if (useCloud)          return await cloudScan(path);
  if (useCzkCloud)       return await czkCloudScan(path, apiKey);
  return null;                                       // safe
}

Enumeration Strategy

ModeScopeKey Implementation
QuickCritical system folders + executable extensionsEnumerateQuickScanFiles()
FullAll local drivesSafeEnumerateFiles() skips inaccessible nodes
FileSingle filePickSingleFileAsync()
FolderRecursive directorySafeEnumerateFolder() uses stack + try-catch

State Machine

StateTriggerUI Indication
IdleInitial / Scan finishedButtons enabled, radar stopped
RunningStartScanAsyncButtons disabled, radar spinning
PausedOnPauseScanClickRadar paused, resume button shown
Canceledtoken.Cancel()Status shows "Scan canceled"

Exception & Cancellation

csharp
catch (OperationCanceledException)
{
    StatusText.Text = "Scan canceled";
}
catch (Exception ex)
{
    LogText.AddNewLog(4, "Security - Failed", ex.Message);
}

Note

Exceptions affect only the current file; the queue continues.

Performance & Threading

ItemStrategy
ConcurrencyOne Task.Run(...) per file, loop delays 1 ms
UI RefreshDispatcherQueue.TryEnqueue ensures thread safety
I/O BlockingSafeEnumerate* patterns pre-catch permission issues

Log Format

LevelModuleEventDetails
1Security - StartScanUse LocalScan-DeepScan CloudScan
1Security - ScanFileC:\Windows\notepad.exe
1Security - FindMEMZUAC.Cloud.VirusFile

FAQ

How to add a new scan engine?
  1. Register a toggle in settings.
  2. Read the toggle inside StartScanAsync.
  3. Append if (useNewEngine) result = await NewScanAsync(path); in the engine chain.
  4. Update the "Engine Priority" section of this doc.
Why does the UI stay responsive during large scans?

All heavy work runs on the ThreadPool; UI updates are marshaled via DispatcherQueue.

Need incremental scanning?

Cache LastScanTime and compare with LastWriteTime during enumeration to skip unchanged files.