1/*
2 *  kextstat_main.h
3 *  kext_tools
4 *
5 *  Created by Nik Gervae on 5/03/08.
6 *  Copyright 2008 Apple Inc. All rights reserved.
7 *
8 */
9#ifndef _KEXTSTAT_MAIN_H
10#define _KEXTSTAT_MAIN_H
11
12#include <CoreFoundation/CoreFoundation.h>
13#include <IOKit/kext/OSKext.h>
14
15#include <getopt.h>
16#include <sysexits.h>
17
18#include <mach-o/arch.h>
19
20#include "kext_tools_util.h"
21
22#pragma mark Basic Types & Constants
23/*******************************************************************************
24* Constants
25*******************************************************************************/
26enum {
27    kKextstatExitOK          = EX_OK,
28    kKextstatExitError  = 1,
29
30    // don't think we use it
31    kKextstatExitUnspecified = 11,
32
33    // don't actually exit with this, it's just a sentinel value
34    kKextstatExitHelp        = 33
35};
36
37#pragma mark Command-line Option Definitions
38/*******************************************************************************
39* Command-line options. This data is used by getopt_long_only().
40*
41* Options common to all kext tools are in kext_tools_util.h.
42*******************************************************************************/
43
44#define kOptNameNoKernelComponents  "no-kernel"
45#define kOptNameListOnly            "list-only"
46
47#define kOptNoKernelComponents      'k'
48#define kOptListOnly                'l'
49
50#if 0
51// bundle-id,version,compatible-version,is-kernel,is-interface,retaincount,path,uuid,started,prelinked,index,address,size,wired,dependencies,classes,cputype,cpusubtype
52CFBundleIdentifier
53CFBundleVersion
54kOSBundleCompatibleVersionKey
55kOSKernelResourceKey
56kOSBundleIsInterfaceKey
57kOSBundlePathKey
58kOSBundleUUIDKey
59kOSBundleStartedKey
60kOSBundlePrelinkedKey
61kOSBundleLoadTagKey
62kOSBundleLoadAddressKey
63kOSBundleLoadSizeKey
64kOSBundleWiredSizeKey
65kOSBundleDependenciesKey
66kOSBundleMetaClassesKey
67#endif
68
69#define kOptChars                "b:hkl"
70
71/* Options with no single-letter variant.  */
72// Do not use -1, that's getopt() end-of-args return value
73// and can cause confusion
74#define kLongOptLongindexHack (-2)
75
76int longopt = 0;
77
78struct option sOptInfo[] = {
79    { kOptNameHelp,               no_argument,        NULL,     kOptHelp },
80    { kOptNameBundleIdentifier,   required_argument,  NULL,     kOptBundleIdentifier },
81    { kOptNameNoKernelComponents, no_argument,        NULL,     kOptNoKernelComponents },
82    { kOptNameListOnly,           no_argument,        NULL,     kOptListOnly },
83
84    { NULL, 0, NULL, 0 }  // sentinel to terminate list
85};
86
87#pragma mark Tool Args Structure
88/*******************************************************************************
89* Tool Args Structure
90*******************************************************************************/
91typedef struct {
92    Boolean            flagNoKernelComponents;
93    Boolean            flagListOnly;
94    CFMutableArrayRef  bundleIDs;          // must release
95
96    CFDictionaryRef    loadedKextInfo;     // must release
97    const NXArchInfo * runningKernelArch;  // do not free
98} KextstatArgs;
99
100#pragma mark Function Prototypes
101/*******************************************************************************
102* Function Prototypes
103*******************************************************************************/
104ExitStatus readArgs(int argc, char * const * argv, KextstatArgs * toolArgs);
105void printKextInfo(CFDictionaryRef kextInfo, KextstatArgs * toolArgs);
106
107Boolean getNumValue(CFNumberRef aNumber, CFNumberType type, void * valueOut);
108int compareKextInfo(const void * vKextInfo1, const void * vKextInfo2);
109CFComparisonResult compareNumbers(
110    const void * val1,
111    const void * val2,
112          void * context);
113
114static void usage(UsageLevel usageLevel);
115
116#endif /* _KEXTSTAT_MAIN_H */
117