|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Setup CoreEntitlements V2 headers from KDK |
| 4 | +# This script creates the necessary directory structure and copies KDK headers |
| 5 | + |
| 6 | +EXTERNAL_HEADERS="./EXTERNAL_HEADERS" |
| 7 | +KDK_CE_PATH="/Library/Developer/KDKs/KDK_26.0_25A353.kdk/System/Library/Frameworks/Kernel.framework/Versions/A/PrivateHeaders/platform/CoreEntitlements" |
| 8 | + |
| 9 | +echo "Setting up CoreEntitlements V2 headers..." |
| 10 | + |
| 11 | +# Create V2 directory if it doesn't exist |
| 12 | +mkdir -p "${EXTERNAL_HEADERS}/CoreEntitlements/V2" |
| 13 | + |
| 14 | +# Copy Context.h and API.h from KDK (these exist in KDK) |
| 15 | +if [ -f "${KDK_CE_PATH}/V2/Context.h" ]; then |
| 16 | + echo " Copying Context.h from KDK..." |
| 17 | + cp "${KDK_CE_PATH}/V2/Context.h" "${EXTERNAL_HEADERS}/CoreEntitlements/V2/" |
| 18 | +fi |
| 19 | + |
| 20 | +if [ -f "${KDK_CE_PATH}/V2/API.h" ]; then |
| 21 | + echo " Copying API.h from KDK..." |
| 22 | + cp "${KDK_CE_PATH}/V2/API.h" "${EXTERNAL_HEADERS}/CoreEntitlements/V2/" |
| 23 | +fi |
| 24 | + |
| 25 | +if [ -f "${KDK_CE_PATH}/V2/Return.h" ]; then |
| 26 | + echo " Copying Return.h from KDK..." |
| 27 | + cp "${KDK_CE_PATH}/V2/Return.h" "${EXTERNAL_HEADERS}/CoreEntitlements/V2/" |
| 28 | +fi |
| 29 | + |
| 30 | +# Create minimal Kernel.h stub (not in KDK, needed by amfi.h) |
| 31 | +echo " Creating Kernel.h stub..." |
| 32 | +cat > "${EXTERNAL_HEADERS}/CoreEntitlements/V2/Kernel.h" <<'EOF' |
| 33 | +#ifndef CORE_ENTITLEMENTS_V2_KERNEL_H |
| 34 | +#define CORE_ENTITLEMENTS_V2_KERNEL_H |
| 35 | +
|
| 36 | +#include <stdbool.h> |
| 37 | +#include <stdint.h> |
| 38 | +#include <CoreEntitlements/CoreEntitlements.h> |
| 39 | +#include <CoreEntitlements/der_vm.h> |
| 40 | +
|
| 41 | +struct CEQueryContext; |
| 42 | +
|
| 43 | +#ifdef __cplusplus |
| 44 | +extern "C" { |
| 45 | +#endif |
| 46 | +
|
| 47 | +typedef struct coreentitlements_kernel_api { |
| 48 | + uint32_t version; |
| 49 | + CEError_t kNoError; |
| 50 | + CEError_t kMalformedEntitlements; |
| 51 | + CEError_t kNotEligibleForAcceleration; |
| 52 | +
|
| 53 | + const char *(*GetErrorString)(CEError_t error); |
| 54 | +
|
| 55 | + CEError_t (*ContextQuery)(CEQueryContext_t ctx, |
| 56 | + const CEQueryOperation_t *__counted_by(queryLength) query, |
| 57 | + size_t queryLength); |
| 58 | +
|
| 59 | + CEError_t (*Validate)(const CERuntime_t rt, |
| 60 | + CEValidationResult *result, |
| 61 | + const uint8_t *__ended_by(blob_end) blob, |
| 62 | + const uint8_t *blob_end); |
| 63 | +
|
| 64 | + CEError_t (*AcquireUnmanagedContext)(const CERuntime_t rt, |
| 65 | + CEValidationResult validationResult, |
| 66 | + struct CEQueryContext *ctx); |
| 67 | +
|
| 68 | + der_vm_context_t (*der_vm_context_create)(const CERuntime_t rt, |
| 69 | + ccder_tag dictionary_tag, |
| 70 | + bool sorted_keys, |
| 71 | + const uint8_t *__ended_by(der_end) der, |
| 72 | + const uint8_t *der_end); |
| 73 | +
|
| 74 | + der_vm_context_t (*der_vm_execute)(der_vm_context_t context, |
| 75 | + CEQueryOperation_t op); |
| 76 | +
|
| 77 | + der_vm_context_t (*der_vm_execute_seq)(der_vm_context_t context, |
| 78 | + const CEQueryOperation_t *__counted_by(queryLength) query, |
| 79 | + size_t queryLength); |
| 80 | +
|
| 81 | + bool (*der_vm_context_is_valid)(der_vm_context_t context); |
| 82 | + bool (*der_vm_bool_from_context)(der_vm_context_t context); |
| 83 | +
|
| 84 | + CEError_t (*IndexSizeForContext)(CEQueryContext_t ctx, size_t *size); |
| 85 | + CEError_t (*BuildIndexForContext)(CEQueryContext_t ctx); |
| 86 | + bool (*ContextIsAccelerated)(CEQueryContext_t ctx); |
| 87 | +} coreentitlements_kernel_api; |
| 88 | +
|
| 89 | +typedef struct coreentitlements_kernel_api CEKernelAPI_t; |
| 90 | +
|
| 91 | +#ifdef __cplusplus |
| 92 | +} |
| 93 | +#endif |
| 94 | +
|
| 95 | +#endif /* CORE_ENTITLEMENTS_V2_KERNEL_H */ |
| 96 | +EOF |
| 97 | + |
| 98 | +# Create os directory for firehose header if needed |
| 99 | +mkdir -p "${EXTERNAL_HEADERS}/os" |
| 100 | + |
| 101 | +# Create firehose_buffer_private.h stub |
| 102 | +echo " Creating firehose_buffer_private.h stub..." |
| 103 | +cat > "${EXTERNAL_HEADERS}/os/firehose_buffer_private.h" <<'EOF' |
| 104 | +#ifndef _OS_FIREHOSE_BUFFER_PRIVATE_H_ |
| 105 | +#define _OS_FIREHOSE_BUFFER_PRIVATE_H_ |
| 106 | +
|
| 107 | +#include <stdbool.h> |
| 108 | +#include <stdint.h> |
| 109 | +#include <mach/vm_types.h> |
| 110 | +#include <firehose/firehose_types_private.h> |
| 111 | +
|
| 112 | +struct firehose_buffer_range_s { |
| 113 | + uint16_t fbr_offset; |
| 114 | + uint16_t fbr_length; |
| 115 | +}; |
| 116 | +
|
| 117 | +#define FIREHOSE_BUFFER_KERNEL_CHUNK_COUNT 1 |
| 118 | +#define FIREHOSE_BUFFER_KERNEL_DEFAULT_CHUNK_COUNT 64 |
| 119 | +#define FIREHOSE_BUFFER_KERNEL_DEFAULT_IO_PAGES 0 |
| 120 | +
|
| 121 | +__BEGIN_DECLS |
| 122 | +
|
| 123 | +firehose_tracepoint_t __firehose_buffer_tracepoint_reserve(uint64_t timestamp, |
| 124 | + firehose_stream_t stream, |
| 125 | + uint16_t pub_size, |
| 126 | + uint16_t priv_size, |
| 127 | + uint8_t **priv_data_out); |
| 128 | +
|
| 129 | +void __firehose_buffer_tracepoint_flush(firehose_tracepoint_t ft, |
| 130 | + firehose_tracepoint_id_u ftid); |
| 131 | +
|
| 132 | +void __firehose_buffer_push_to_logd(firehose_buffer_t fb, bool for_io); |
| 133 | +void __firehose_allocate(vm_offset_t *addr, vm_size_t size); |
| 134 | +void __firehose_critical_region_enter(void); |
| 135 | +void __firehose_critical_region_leave(void); |
| 136 | +
|
| 137 | +bool __firehose_kernel_configuration_valid(uint32_t chunk_count, uint32_t io_pages); |
| 138 | +firehose_buffer_t __firehose_buffer_create(size_t *size); |
| 139 | +bool __firehose_merge_updates(firehose_push_reply_t reply); |
| 140 | +
|
| 141 | +__END_DECLS |
| 142 | +
|
| 143 | +#endif /* _OS_FIREHOSE_BUFFER_PRIVATE_H */ |
| 144 | +EOF |
| 145 | + |
| 146 | +echo "CoreEntitlements V2 setup complete." |
0 commit comments