> 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/plugins/plugin-system.md).

# Plugin System

The Plugin Bridge Architecture allows developers to extend the security core with modular native and managed plugins without modifying the core SDK source code.

## Architectural Model

```
+-------------------------------------------------------------+
|                     C# Application Layer                    |
|                (EasyAuth-CS-Example / .NET 8.0)             |
+-------------------------------------------------------------+
                              |
                     [P/Invoke C-ABI]
                              |
+-------------------------------------------------------------+
|                 qPapelEasyAuth Native Core                  |
|                 (Plugin Manager & Dispatcher)               |
+-------------------------------------------------------------+
         |                                           |
         v                                           v
+------------------------+              +------------------------+
|   BinaryTrace Plugin   |              |  qPAnalyzer AI Plugin  |
| (Execution Trace & PE) |              | (Forensics & Vision AI)|
+------------------------+              +------------------------+
```

## Plugin Lifecycle Events

Plugins subscribe to lifecycle events dispatched by the `PluginManager`:

| Event Type                | ID  | Trigger Point                                           |
| ------------------------- | --- | ------------------------------------------------------- |
| `PreInitSession`          | `0` | Immediately before transmitting session init to server. |
| `PostInitSession`         | `1` | After session init payload is validated.                |
| `PreAuthenticate`         | `2` | Before transmitting user license key.                   |
| `PostAuthenticateSuccess` | `3` | Immediately after license is validated successfully.    |
| `PostAuthenticateFailed`  | `4` | When license validation fails or is rejected.           |
| `PeriodicWatchdogTick`    | `5` | Triggered every watchdog interval (e.g. every 500 ms).  |

## C# Implementation

{% tabs %}
{% tab title="Listing & Enabling Plugins" %}

```csharp
using System;
using qPapelEasyAuth;

public class PluginController
{
    public static void InitializePlugins()
    {
        // 1. Enable built-in plugins
        qPapelEasyAuth.qPapelEasyAuth.EnablePlugin("binary_trace");
        qPapelEasyAuth.qPapelEasyAuth.EnablePlugin("qpanalyzer");

        Console.WriteLine("[+] Security plugins activated in runtime.");
    }
}
```

{% endtab %}

{% tab title="Querying Plugin Status" %}

```csharp
bool traceActive = qPapelEasyAuth.qPapelEasyAuth.IsPluginActive("binary_trace");
bool qpActive = qPapelEasyAuth.qPapelEasyAuth.IsPluginActive("qpanalyzer");

Console.WriteLine($"[+] BinaryTrace Status : {(traceActive ? "ACTIVE" : "DISABLED")}");
Console.WriteLine($"[+] qPAnalyzer Status  : {(qpActive ? "ACTIVE" : "DISABLED")}");
```

{% endtab %}
{% endtabs %}

## Plugin Interface Requirements

Native plugins export a standard factory entry point:

```cpp
extern "C" __declspec(dllexport) ieasyauth_plugin* create_plugin();
```

The core plugin manager invokes `create_plugin()`, validates the plugin hash signature, and registers event callbacks into the event loop.

{% hint style="info" %}
Plugins compiled into the native build are linked into the in-memory core and injected together via `qPapelPacker`.
{% endhint %}
