162 lines
5 KiB
C
162 lines
5 KiB
C
/*
|
|
* Maya License Hook Library
|
|
* Intercepts Autodesk licensing calls via LD_PRELOAD
|
|
*
|
|
* Target: Maya 2022-2027 (Linux)
|
|
*/
|
|
|
|
#define _GNU_SOURCE
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <dlfcn.h>
|
|
#include <stdint.h>
|
|
|
|
#define DEBUG_LOG 1
|
|
#define LOG(fmt, ...) do { \
|
|
if (DEBUG_LOG) { \
|
|
fprintf(stderr, "[MAYA-HOOK] " fmt, ##__VA_ARGS__); \
|
|
fflush(stderr); \
|
|
} \
|
|
} while(0)
|
|
|
|
/* Function pointer types */
|
|
typedef void* (*Fn_AdskLicensingInitialize)(void);
|
|
typedef void (*Fn_AdskLicensingDiscover)(void* context);
|
|
typedef int (*Fn_AdskLicensingAcquireContext)(void* context, const char* options);
|
|
typedef void (*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;
|
|
|
|
void* 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;
|
|
}
|
|
|
|
void AdskLicensingDiscover(void* context) {
|
|
LOG("AdskLicensingDiscover() called with context: %p\n", context);
|
|
|
|
if (orig_AdskLicensingDiscover) {
|
|
orig_AdskLicensingDiscover(context);
|
|
}
|
|
|
|
LOG(" -> License discovery completed (hooked)\n");
|
|
}
|
|
|
|
int 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;
|
|
}
|
|
|
|
void AdskLicensingReleaseContext(void* context) {
|
|
LOG("AdskLicensingReleaseContext() called with context: %p\n", context);
|
|
|
|
if (orig_AdskLicensingReleaseContext) {
|
|
orig_AdskLicensingReleaseContext(context);
|
|
}
|
|
|
|
if (context == hooked_context) {
|
|
context_initialized = 0;
|
|
}
|
|
}
|
|
|
|
int AdskLicensingValidate(void* context) {
|
|
(void)context;
|
|
LOG("AdskLicensingValidate() called\n");
|
|
return 1;
|
|
}
|
|
|
|
int AdskLicensingIsLicenseValid(void* context) {
|
|
(void)context;
|
|
LOG("AdskLicensingIsLicenseValid() called\n");
|
|
return 1;
|
|
}
|
|
|
|
__attribute__((constructor))
|
|
void hook_init(void) {
|
|
LOG("=== Maya License Hook Initializing ===\n");
|
|
|
|
/* Try multiple library paths */
|
|
const char* lib_paths[] = {
|
|
"libAdskLicensingSDK.so.10",
|
|
"libAdskLicensingSDK.so.10.0.1.66",
|
|
"/usr/autodesk/maya2027/lib/libAdskLicensingSDK.so.10",
|
|
"/usr/autodesk/maya2027/lib/libAdskLicensingSDK.so.10.0.1.66",
|
|
"/usr/autodesk/maya2026/lib/libAdskLicensingSDK.so.10",
|
|
"/usr/autodesk/maya2025/lib/libAdskLicensingSDK.so.10",
|
|
NULL
|
|
};
|
|
|
|
void* handle = NULL;
|
|
for (int i = 0; lib_paths[i] != NULL; i++) {
|
|
handle = dlopen(lib_paths[i], RTLD_NOW | RTLD_GLOBAL);
|
|
if (handle) {
|
|
LOG("Loaded: %s at %p\n", lib_paths[i], handle);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (handle) {
|
|
orig_AdskLicensingInitialize = (Fn_AdskLicensingInitialize)dlsym(handle, "AdskLicensingInitialize");
|
|
orig_AdskLicensingDiscover = (Fn_AdskLicensingDiscover)dlsym(handle, "AdskLicensingDiscover");
|
|
orig_AdskLicensingAcquireContext = (Fn_AdskLicensingAcquireContext)dlsym(handle, "AdskLicensingAcquireContext");
|
|
orig_AdskLicensingReleaseContext = (Fn_AdskLicensingReleaseContext)dlsym(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 libAdskLicensingSDK (will use pure hook mode)\n");
|
|
}
|
|
|
|
LOG("=== Hook Initialization Complete ===\n");
|
|
}
|
|
|
|
__attribute__((destructor))
|
|
void hook_fini(void) {
|
|
LOG("=== Maya License Hook Cleanup ===\n");
|
|
|
|
if (hooked_context) {
|
|
free(hooked_context);
|
|
hooked_context = NULL;
|
|
}
|
|
|
|
LOG("Cleanup complete\n");
|
|
}
|