Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Test_PanoptesDLL.cpp File Reference
#include <Windows.h>
#include <cstdio>
#include <cstring>

Go to the source code of this file.

Macros

#define HOOK_ARCH   "x86"
#define HOOK_DLL_NAME   "PanoptesDLL" HOOK_ARCH ".dll"

Functions

int main ()
 Loads the hook DLL for this architecture from bin/<config>, one directory above the tests folder this executable is placed in, and checks that its trampolines are placed on load and removed on unload.

Macro Definition Documentation

◆ HOOK_ARCH

#define HOOK_ARCH   "x86"

Definition at line 8 of file Test_PanoptesDLL.cpp.

◆ HOOK_DLL_NAME

#define HOOK_DLL_NAME   "PanoptesDLL" HOOK_ARCH ".dll"

Definition at line 11 of file Test_PanoptesDLL.cpp.

Function Documentation

◆ main()

int main ( )

Loads the hook DLL for this architecture from bin/<config>, one directory above the tests folder this executable is placed in, and checks that its trampolines are placed on load and removed on unload.

Definition at line 124 of file Test_PanoptesDLL.cpp.

124 {
125 printf("Hello World from the %s hook loader\n", HOOK_ARCH);
126
127 char dllPath[MAX_PATH];
128 DWORD length = GetModuleFileNameA(NULL, dllPath, MAX_PATH);
129 if (length == 0 || length == MAX_PATH) {
130 printf("Failed to get the executable path (error %lu)\n", GetLastError());
131 return 1;
132 }
133
134 // Replace the executable name with ..<dll name>
135 char* lastSlash = strrchr(dllPath, '\\');
136 if (lastSlash == NULL) {
137 printf("Unexpected executable path: %s\n", dllPath);
138 return 1;
139 }
140 *(lastSlash + 1) = '\0';
141 strcat_s(dllPath, MAX_PATH, "..\\" HOOK_DLL_NAME);
142
143 int failures = CheckHooks("before load", NULL, FALSE);
144
145 HMODULE hModule = LoadLibraryA(dllPath);
146 if (hModule == NULL) {
147 printf("Failed to load %s (error %lu)\n", dllPath, GetLastError());
148 return 1;
149 }
150
151 printf("\nLoaded %s at %p\n", dllPath, (void*)hModule);
152
153 failures += CheckHooks("after load", hModule, TRUE);
154
155 FreeLibrary(hModule);
156 printf("\nUnloaded %s\n", HOOK_DLL_NAME);
157
158 failures += CheckHooks("after unload", NULL, FALSE);
159
160 printf("\n%s\n", failures == 0 ? "PASS" : "FAIL");
161 return failures == 0 ? 0 : 1;
162}
#define MAX_PATH
Definition callbacks.h:7
#define HOOK_ARCH
#define HOOK_DLL_NAME

References HOOK_ARCH, HOOK_DLL_NAME, and MAX_PATH.