]>
Commit | Line | Data |
---|---|---|
3e170ce0 A |
1 | /* |
2 | * Copyright (c) 2015 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _KDD_H_ | |
30 | #define _KDD_H_ | |
31 | ||
39037602 A |
32 | #include <kcdata.h> |
33 | ||
3e170ce0 A |
34 | #import <Foundation/Foundation.h> |
35 | ||
36 | /*! | |
37 | * @class KCDataType | |
38 | * A basic abstraction that allows for parsing data provided by kernel chunked | |
39 | * data library. | |
40 | * | |
41 | * @discussion | |
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 | |
44 | * | |
45 | */ | |
46 | @interface KCDataType : NSObject | |
39037602 A |
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; | |
3e170ce0 A |
51 | @end |
52 | ||
53 | /*! | |
54 | * @function getKCDataTypeForID | |
55 | * | |
56 | * @abstract | |
57 | * Find a type description for give TypeID | |
58 | * | |
59 | * @param typeID | |
60 | * A unsinged int type specified by the KCDATA. | |
61 | * | |
62 | * @discussion | |
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[]. | |
65 | */ | |
39037602 | 66 | KCDataType * _Nullable getKCDataTypeForID(uint32_t typeID); |
3e170ce0 A |
67 | |
68 | /*! | |
69 | * @function KCDataTypeNameForID | |
70 | * | |
71 | * @abstract | |
72 | * Get a name for the type. | |
73 | * | |
74 | * @param typeID | |
75 | * A unsinged int type specified by the KCDATA. | |
76 | * | |
77 | * @return NSString * | |
78 | * Returns name of the type. If a type is not found the return | |
79 | * value will be string object of the passed value. | |
80 | */ | |
39037602 | 81 | NSString * _Nonnull KCDataTypeNameForID(uint32_t typeID) NS_RETURNS_NOT_RETAINED; |
3e170ce0 A |
82 | |
83 | /*! | |
84 | * @function parseKCDataArray | |
85 | * | |
86 | * @abstract | |
87 | * Parse the given KCDATA buffer as an Array of element. The buffer should begin with header | |
88 | * of type KCDATA_TYPE_ARRAY. | |
89 | * | |
39037602 A |
90 | * @param iter |
91 | * An iterator into the input buffer | |
92 | * | |
93 | * @param error | |
94 | * Error return. | |
3e170ce0 A |
95 | * |
96 | * @return | |
97 | * A dictionary with key specifying name of the type of each elements and value is an Array of data. | |
98 | * | |
99 | */ | |
100 | ||
39037602 | 101 | NSMutableDictionary * _Nullable parseKCDataArray(kcdata_iter_t iter, NSError * _Nullable * _Nullable error) NS_RETURNS_RETAINED; |
3e170ce0 A |
102 | |
103 | /*! | |
104 | * @function parseKCDataContainer | |
105 | * | |
106 | * @abstract | |
107 | * Parse the given KCDATA buffer as a container and convert each sub structures as fields in a dictionary. | |
108 | * | |
39037602 A |
109 | * @param iter |
110 | * A pointer to an iterator into the input buffer. The iterator will be updated | |
111 | * to point at the container end marker. | |
3e170ce0 | 112 | * |
39037602 A |
113 | * @param error |
114 | * Error return. | |
3e170ce0 A |
115 | * |
116 | * @return NSDictionary * | |
117 | * containing each field and potentially sub containers within the provided container. | |
118 | * | |
119 | * @discussion | |
120 | * This function tries to parse one container. If it encounters sub containers | |
121 | * they will be parsed and collected within the same dictionary. | |
39037602 A |
122 | * Other data type fields will also be parsed based on their type. |
123 | * | |
124 | */ | |
125 | ||
126 | NSMutableDictionary * _Nullable parseKCDataContainer(kcdata_iter_t * _Nonnull iter_p, NSError * _Nullable * _Nullable error) NS_RETURNS_RETAINED; | |
127 | ||
128 | /*! | |
129 | * @function parseKCDataBuffer | |
130 | * | |
131 | * @abstract | |
132 | * Parse complete KCDATA buffer into NSMutableDictionary. Depending on the size of buffer and elements | |
133 | * this routine makes allocations for objects and strings. | |
134 | * | |
135 | * @param dataBuffer | |
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) | |
138 | * | |
139 | * @param size | |
140 | * Size of the buffer as provided by kernel api. | |
141 | * | |
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" | |
145 | * as keys. | |
146 | * | |
147 | * @discussion | |
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. | |
150 | * | |
151 | * Iff the buffer does begin with a known kcdata magic number, the error code | |
152 | * will be KERN_INVALID_VALUE. | |
3e170ce0 A |
153 | * |
154 | */ | |
39037602 A |
155 | NSDictionary * _Nullable parseKCDataBuffer(void * _Nonnull dataBuffer, uint32_t size, NSError * _Nullable * _Nullable error) NS_RETURNS_RETAINED; |
156 | ||
3e170ce0 A |
157 | |
158 | #endif /* _KDD_H_ */ |