#include <windows.h>
#include <stdio.h>
// Define a function pointer type for ShellExec
typedef void (*SHELLEXEC_FUNC)();
int main() {
// Path to the DLL on disk (relative to current executable path)
const char* dllPath = "BadDll.dll";
// Load the DLL
HMODULE hDll = LoadLibraryA(dllPath);
if (hDll == NULL) {
printf("[-] Failed to load the DLL. Error: %lu\n", GetLastError());
return 1;
}
printf("[+] DLL loaded successfully.\n");
// Get the address of the exported ShellExec function
SHELLEXEC_FUNC ShellExecFunc = (SHELLEXEC_FUNC)GetProcAddress(hDll, "ShellExec");
if (ShellExecFunc == NULL) {
printf("[-] Failed to find the ShellExec function. Error: %lu\n", GetLastError());
FreeLibrary(hDll);
return 1;
}
printf("[+] ShellExec function found successfully.\n");
// Call the ShellExec function
printf("[*] Calling ShellExec function...\n");
ShellExecFunc();
// Unload the DLL
FreeLibrary(hDll);
return 0;
}