]>
git.saurik.com Git - apple/xnu.git/blob - libkdd/kcdata/kdd.h
ba9106d7373ed0cb49c8d7b4cbf7e945a97fadef
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@
32 #import <Foundation/Foundation.h>
36 * A basic abstraction that allows for parsing data provided by kernel chunked
40 * Each type object has a name and a method to parse and populate data in memory to
41 * a dictionary. The dictionary will have keys as NSStrings and values could be NSObject
44 @interface KCDataType
: NSObject
45 - (NSMutableDictionary
*)parseData
:(void *)dataBuffer ofLength
:(uint32_t)length
;
50 * @function getKCDataTypeForID
53 * Find a type description for give TypeID
56 * A unsinged int type specified by the KCDATA.
59 * This routine queries the system for a give type. If a known type description is found it will be used to
60 * initialize a KCDataType object. If no known type is found it assumes the data is uint8_t[].
62 KCDataType
* getKCDataTypeForID(uint32_t typeID
);
65 * @function KCDataTypeNameForID
68 * Get a name for the type.
71 * A unsinged int type specified by the KCDATA.
74 * Returns name of the type. If a type is not found the return
75 * value will be string object of the passed value.
77 NSString
* KCDataTypeNameForID(uint32_t typeID
);
80 * @function parseKCDataArray
83 * Parse the given KCDATA buffer as an Array of element. The buffer should begin with header
84 * of type KCDATA_TYPE_ARRAY.
87 * A pointer in memory where KCDATA is allocated.
90 * A dictionary with key specifying name of the type of each elements and value is an Array of data.
94 NSMutableDictionary
* parseKCDataArray(void * dataBuffer
);
97 * @function parseKCDataContainer
100 * Parse the given KCDATA buffer as a container and convert each sub structures as fields in a dictionary.
103 * A pointer in memory where KCDATA is allocated. The data should be pointing to
104 * kcdata_item_t of type KCDATA_TYPE_CONTAINER_BEGIN
107 * A pointer to uint32_t field where the routine will save the number of bytes parsed for this container.
109 * @return NSDictionary *
110 * containing each field and potentially sub containers within the provided container.
113 * This function tries to parse one container. If it encounters sub containers
114 * they will be parsed and collected within the same dictionary.
115 * Other data type fields will also be parsed based on their type. The bytesParsed
116 * param is populated with the number of bytes processed. With this return value the caller can
117 * advance its buffer_read position as
118 * buffer = (kcdata_item_t)((uintptr_t)buffer + bytesParsed); //advance to next KCDATA_HEADER.
119 * Note: Keep in mind that the next header may be KCDATA_TYPE_BUFFER_END.
121 * A sample usage call can be:
122 * KCDATA_ITEM_FOREACH(buffer) {
123 * if(KCDATA_ITEM_TYPE(buffer) == KCDATA_TYPE_CONTAINER_BEGIN) {
124 * uint32_t container_size = 0;
125 * NSMutableDictionary *parsedContainer = parseKCDataContainer(buffer, &container_size);
126 * NSLog(@"Parsed container has : %@", parsedContainer);
127 * buffer = (kcdata_item_t) ((uintptr_t)buffer + container_size);
128 * if(KCDATA_ITEM_TYPE(buffer) == KCDATA_TYPE_BUFFER_END)
134 NSMutableDictionary
* parseKCDataContainer(void * dataBuffer
, uint32_t * bytesParsed
);