> For the complete documentation index, see [llms.txt](https://qpapel.papelship.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://qpapel.papelship.com/documentation/tr-documentation/proje-ayarlama/qpapelpacker-1.md).

# qPapelPacker

`qPapelPacker` is a hardened PE section injector that embeds and secures your authentication payload (`qPapelAuth64.dll`) inside your target loader binary (either an EXE or DLL).

Without this step, the loader stub (`QP_StubInit()`) will not be able to find the `.******` section and the application will fail to run.

***

## Command Line Interface (CLI)

You can run `qPapelPacker` manually from PowerShell or Command Prompt:

```bash
qPapelPacker.exe --dll <path_to_auth_dll> --input <path_to_unpacked_binary> --output <path_to_packed_output> [options]
```

### Command Line Arguments

* `--dll <path>`: (Required) Path to the raw compiled authentication DLL (e.g., `qPapelAuth64.dll`).
* `--input <path>`: (Required) Path to your compiled loader application (e.g., `loader.exe` or `loader.dll`).
* `--output <path>`: (Required) The destination filename for the finalized, protected binary.
* `--fakes <N>`: Number of decoy sections to inject (default: 7, max: 9).
* `--no-fake`: Disable fake section generation entirely.

***

## Visual Studio Integration (Post-Build Event)

To automate the packing process so that every build generates the protected binary automatically, you can add `qPapelPacker` as a **Post-Build Event** in your Visual Studio project.

### Method A: Visual Studio GUI Configuration

{% stepper %}
{% step %}

## Open project properties

Right-click your project and select **Properties**.
{% endstep %}

{% step %}

## Go to the Post-Build Event settings

Navigate to **Configuration Properties → Build Events → Post-Build Event**.
{% endstep %}

{% step %}

## Set the Command Line

```cmd
if not exist "$(ProjectDir)dist" mkdir "$(ProjectDir)dist"
"$(ProjectDir)qPapelTools\qPapelPacker.exe" --dll "$(ProjectDir)qPapelTools\qPapelAuth64.dll" --input "$(OutDir)$(TargetName)$(TargetExt)" --output "$(ProjectDir)dist\$(TargetName)_final_x64.exe"
```

{% endstep %}

{% step %}

## Set the Description

```
Embedding qPapelAuth DLL into target executable...
```

{% endstep %}

{% step %}

## Apply the changes

Click **Apply** and **OK**.
{% endstep %}
{% endstepper %}

### Method B: XML Configuration (`.vcxproj` file)

You can also paste the configuration block directly into your `.vcxproj` file:

```xml
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  <PostBuildEvent>
    <Command>
      if not exist "$(ProjectDir)dist" mkdir "$(ProjectDir)dist"
      "$(ProjectDir)qPapelTools\qPapelPacker.exe" --dll "$(ProjectDir)qPapelTools\qPapelAuth64.dll" --input "$(OutDir)$(TargetName)$(TargetExt)" --output "$(ProjectDir)dist\$(TargetName)_final_x64.exe"
    </Command>
    <Message>Embedding qPapelAuth DLL into target executable...</Message>
  </PostBuildEvent>
</ItemDefinitionGroup>
```

***

## Packer with DLL Targets

If your loader is a DLL project instead of a Console/Window EXE (e.g., `loader.dll`), the packing process remains identical:

```bash
qPapelPacker.exe --dll qPapelAuth64.dll --input loader.dll --output dist\loader_packed.dll
```

### Important requirement when packing DLLs

Ensure that your loader DLL's source code retrieves its base address dynamically instead of using `GetModuleHandle(NULL)` to allow `QP_StubInit()` to correctly find `.qpdata` inside itself rather than in the host process:

```cpp
// Correct way inside a DLL loader:
HMODULE hMod = nullptr;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                   reinterpret_cast<LPCSTR>(QP_StubInit), &hMod);
auto* base = reinterpret_cast<const uint8_t*>(hMod);
```
