FUA/core/windows/license_hook.c

194 lines
6 KiB
C

/*
* Maya License Hook Library - Windows Version
* Intercepts Autodesk licensing calls via DLL injection
*
* Target: Maya 2022-2027 (Windows)
* Build: MSVC or MinGW-w64
*/
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
/* Debug logging to file */
#define DEBUG_LOG 1
static FILE* g_logFile = NULL;
#define LOG(fmt, ...) do { \
if (DEBUG_LOG && g_logFile) { \
fprintf(g_logFile, "[MAYA-HOOK] " fmt, ##__VA_ARGS__); \
fflush(g_logFile); \
} \
} while(0)
/* Function pointer types for AdskLicensingSDK */
typedef void* (__cdecl *Fn_AdskLicensingInitialize)(void);
typedef void (__cdecl *Fn_AdskLicensingDiscover)(void* context);
typedef int (__cdecl *Fn_AdskLicensingAcquireContext)(void* context, const char* options);
typedef void (__cdecl *Fn_AdskLicensingReleaseContext)(void* context);
/* Original function pointers */
static Fn_AdskLicensingInitialize orig_AdskLicensingInitialize = NULL;
static Fn_AdskLicensingDiscover orig_AdskLicensingDiscover = NULL;
static Fn_AdskLicensingAcquireContext orig_AdskLicensingAcquireContext = NULL;
static Fn_AdskLicensingReleaseContext orig_AdskLicensingReleaseContext = NULL;
/* Hooked context storage */
static void* hooked_context = NULL;
static int context_initialized = 0;
static HMODULE sdk_handle = NULL;
/*
* Hook: AdskLicensingInitialize
*/
__declspec(dllexport) void* __cdecl AdskLicensingInitialize(void) {
LOG("AdskLicensingInitialize() called\n");
if (orig_AdskLicensingInitialize) {
void* result = orig_AdskLicensingInitialize();
if (result) {
hooked_context = result;
context_initialized = 1;
LOG(" -> Original returned: %p\n", result);
return result;
}
}
if (!hooked_context) {
hooked_context = malloc(1);
context_initialized = 1;
LOG(" -> Created hook context: %p\n", hooked_context);
}
return hooked_context;
}
/*
* Hook: AdskLicensingDiscover
*/
__declspec(dllexport) void __cdecl AdskLicensingDiscover(void* context) {
LOG("AdskLicensingDiscover() called with context: %p\n", context);
if (orig_AdskLicensingDiscover) {
orig_AdskLicensingDiscover(context);
}
LOG(" -> License discovery completed (hooked)\n");
}
/*
* Hook: AdskLicensingAcquireContext
*/
__declspec(dllexport) int __cdecl AdskLicensingAcquireContext(void* context, const char* options) {
LOG("AdskLicensingAcquireContext() called\n");
int result = 0;
if (orig_AdskLicensingAcquireContext) {
result = orig_AdskLicensingAcquireContext(context, options);
LOG(" -> Original returned: %d\n", result);
} else {
LOG(" -> Hooked: returning success (0)\n");
}
return result;
}
/*
* Hook: AdskLicensingReleaseContext
*/
__declspec(dllexport) void __cdecl AdskLicensingReleaseContext(void* context) {
LOG("AdskLicensingReleaseContext() called with context: %p\n", context);
if (orig_AdskLicensingReleaseContext) {
orig_AdskLicensingReleaseContext(context);
}
if (context == hooked_context) {
context_initialized = 0;
}
}
/*
* Hook: License validation
*/
__declspec(dllexport) int __cdecl AdskLicensingValidate(void* context) {
(void)context;
LOG("AdskLicensingValidate() called\n");
return 1;
}
__declspec(dllexport) int __cdecl AdskLicensingIsLicenseValid(void* context) {
(void)context;
LOG("AdskLicensingIsLicenseValid() called\n");
return 1;
}
/*
* DLL Entry Point
*/
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID reserved) {
switch (reason) {
case DLL_PROCESS_ATTACH:
LOG("=== Maya License Hook DLL Loading ===\n");
/* Open log file */
g_logFile = fopen("C:\\temp\\maya_hook.log", "a");
/* Load AdskLicensingSDK */
sdk_handle = LoadLibraryA("AdskLicensingSDK.dll");
if (!sdk_handle) {
sdk_handle = LoadLibraryA("AdskLicensingSDK_10.dll");
}
if (sdk_handle) {
LOG("Loaded AdskLicensingSDK.dll: %p\n", sdk_handle);
/* Get original function addresses */
orig_AdskLicensingInitialize = (Fn_AdskLicensingInitialize)
GetProcAddress(sdk_handle, "AdskLicensingInitialize");
orig_AdskLicensingDiscover = (Fn_AdskLicensingDiscover)
GetProcAddress(sdk_handle, "AdskLicensingDiscover");
orig_AdskLicensingAcquireContext = (Fn_AdskLicensingAcquireContext)
GetProcAddress(sdk_handle, "AdskLicensingAcquireContext");
orig_AdskLicensingReleaseContext = (Fn_AdskLicensingReleaseContext)
GetProcAddress(sdk_handle, "AdskLicensingReleaseContext");
LOG("Original functions loaded:\n");
LOG(" AdskLicensingInitialize: %p\n", (void*)orig_AdskLicensingInitialize);
LOG(" AdskLicensingDiscover: %p\n", (void*)orig_AdskLicensingDiscover);
LOG(" AdskLicensingAcquireContext: %p\n", (void*)orig_AdskLicensingAcquireContext);
LOG(" AdskLicensingReleaseContext: %p\n", (void*)orig_AdskLicensingReleaseContext);
} else {
LOG("Note: Could not load AdskLicensingSDK.dll (pure hook mode)\n");
}
LOG("=== Hook Initialization Complete ===\n");
break;
case DLL_PROCESS_DETACH:
LOG("=== Maya License Hook DLL Unloading ===\n");
if (hooked_context) {
free(hooked_context);
hooked_context = NULL;
}
if (sdk_handle) {
FreeLibrary(sdk_handle);
}
if (g_logFile) {
fclose(g_logFile);
}
LOG("Cleanup complete\n");
break;
}
return TRUE;
}