> For the complete documentation index, see [llms.txt](https://easyauth.papelship.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easyauth.papelship.com/csharp-document/other-func/watchdog-clock.md).

# Watchdog Clock

The Background Watchdog operates as a hardened, hidden worker thread within the process. It continuously verifies system time validity, checks memory integrity, and guards against clock rollback exploits.

## Anti-Clock Tampering Engine

Software licenses with time-limited expirations (e.g. 30-day trials) are frequently targeted by changing the Windows system clock backwards.

The Watchdog Engine neutralizes clock manipulation through multiple synchronized sources:

{% stepper %}
{% step %}

### Server Authoritative Timestamp

Clock base is set during the initial Diffie-Hellman handshake.
{% endstep %}

{% step %}

### High-Resolution Monotonic Timers

Tracks elapsed time via `QueryPerformanceCounter` (QPC) and hardware RDTSC ticks, which cannot be modified by changing the Windows date/time.
{% endstep %}

{% step %}

### Rollback Detection

If the local system clock jumps backwards or QPC ticks diverge significantly from monotonic delta calculations, the engine flags a clock tamper event and invalidates the session.
{% endstep %}
{% endstepper %}

## C# Implementation

```csharp
using System;
using qPapelEasyAuth;

public class WatchdogService
{
    public static void InitializeWatchdog()
    {
        // Configure watchdog tick frequency (in milliseconds)
        qPapelEasyAuth.qPapelEasyAuth.SetWatchdogInterval(500);

        Console.WriteLine("[+] Background watchdog and monotonic clock monitor initialized.");
    }
}
```

## Watchdog Responsibilities

| Task                         | Frequency  | Action on Anomaly                                |
| ---------------------------- | ---------- | ------------------------------------------------ |
| **System Clock Delta**       | Continuous | Invalidate session if clock moves backwards.     |
| **Hardware Breakpoint Scan** | Every tick | Clear debug registers and terminate process.     |
| **Thread Context Audit**     | Every tick | Re-hide threads via `ThreadHideFromDebugger`.    |
| **Code Section Checksum**    | Every tick | Verify memory CRC32 hash against clean baseline. |

{% hint style="info" %}
The watchdog thread is hidden from debuggers at the kernel level and cannot be safely suspended or patched without triggering a timeout fail-safe.
{% endhint %}
