2 * Copyright (c) 2015 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 #import <Foundation/Foundation.h>
38 * A basic abstraction that allows for parsing data provided by kernel chunked
42 * Each type object has a name and a method to parse and populate data in memory to
43 * a dictionary. The dictionary will have keys as NSStrings and values could be NSObject
46 @interface KCDataType
: NSObject
47 - (NSDictionary
* _Nullable
)parseData
:(void * _Nonnull
)dataBuffer ofLength
:(uint32_t)length NS_RETURNS_RETAINED
;
48 - (NSString
* _Nonnull
)name
;
49 - (unsigned int)typeID
;
50 - (BOOL
) shouldMergeData
;
54 * @function getKCDataTypeForID
57 * Find a type description for give TypeID
60 * A unsinged int type specified by the KCDATA.
63 * This routine queries the system for a give type. If a known type description is found it will be used to
64 * initialize a KCDataType object. If no known type is found it assumes the data is uint8_t[].
66 KCDataType
* _Nullable
getKCDataTypeForID(uint32_t typeID
);
69 * @function KCDataTypeNameForID
72 * Get a name for the type.
75 * A unsinged int type specified by the KCDATA.
78 * Returns name of the type. If a type is not found the return
79 * value will be string object of the passed value.
81 NSString
* _Nonnull
KCDataTypeNameForID(uint32_t typeID
) NS_RETURNS_NOT_RETAINED
;
84 * @function parseKCDataArray
87 * Parse the given KCDATA buffer as an Array of element. The buffer should begin with header
88 * of type KCDATA_TYPE_ARRAY.
91 * An iterator into the input buffer
97 * A dictionary with key specifying name of the type of each elements and value is an Array of data.
101 NSMutableDictionary
* _Nullable
parseKCDataArray(kcdata_iter_t iter
, NSError
* _Nullable
* _Nullable error
) NS_RETURNS_RETAINED
;
104 * @function parseKCDataContainer
107 * Parse the given KCDATA buffer as a container and convert each sub structures as fields in a dictionary.
110 * A pointer to an iterator into the input buffer. The iterator will be updated
111 * to point at the container end marker.
116 * @return NSDictionary *
117 * containing each field and potentially sub containers within the provided container.
120 * This function tries to parse one container. If it encounters sub containers
121 * they will be parsed and collected within the same dictionary.
122 * Other data type fields will also be parsed based on their type.
126 NSMutableDictionary
* _Nullable
parseKCDataContainer(kcdata_iter_t
* _Nonnull iter_p
, NSError
* _Nullable
* _Nullable error
) NS_RETURNS_RETAINED
;
129 * @function parseKCDataBuffer
132 * Parse complete KCDATA buffer into NSMutableDictionary. Depending on the size of buffer and elements
133 * this routine makes allocations for objects and strings.
136 * A pointer in memory where KCDATA is allocated. The data should be of type
137 * kcdata_item_t and have KCDATA_BUFFER_BEGIN_* tags (see kern_cdata.h)
140 * Size of the buffer as provided by kernel api.
142 * @return NSDictionary *
143 * Dictionary with key:value pairs for each data item. KCDATA_TYPE_ARRAY and KCDATA_TYPE_CONTAINERS will
144 * grouped and recursed as much possible. For unknown types NSData object is returned with "Type_0x123"
148 * This function tries to parse KCDATA buffer with known type description. If an error occurs,
149 * NULL is returned, and error (if not NULL) will have the error string.
151 * Iff the buffer does begin with a known kcdata magic number, the error code
152 * will be KERN_INVALID_VALUE.
155 NSDictionary
* _Nullable
parseKCDataBuffer(void * _Nonnull dataBuffer
, uint32_t size
, NSError
* _Nullable
* _Nullable error
) NS_RETURNS_RETAINED
;