#ifndef _KEXT_TOOLS_UTIL_H
#define _KEXT_TOOLS_UTIL_H
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/kext/OSKext.h>
#include <mach/mach_error.h>
#include <getopt.h>
#include <sysexits.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#pragma mark Types
typedef int ExitStatus;
typedef enum {
kUsageLevelBrief = 0,
kUsageLevelFull = 1
} UsageLevel;
typedef struct {
CFURLRef saveDirURL;
Boolean overwrite;
Boolean fatal;
} SaveFileContext;
#pragma mark Constants
#define _kKextPropertyValuesCacheBasename "KextPropertyValues_"
#define __kOSKextApplePrefix CFSTR("com.apple.")
#define kAppleInternalPath "/AppleInternal"
#define kDefaultDevKernelPath "/System/Library/Kernels/kernel.development"
#define kDefaultDevKernelSuffix ".development"
#pragma mark Macros
#define SAFE_FREE(ptr) do { \
if (ptr) free(ptr); \
} while (0)
#define SAFE_FREE_NULL(ptr) do { \
if (ptr) free(ptr); \
(ptr) = NULL; \
} while (0)
#define SAFE_RELEASE(ptr) do { \
if (ptr) CFRelease(ptr); \
} while (0)
#define SAFE_RELEASE_NULL(ptr) do { \
if (ptr) CFRelease(ptr); \
(ptr) = NULL; \
} while (0)
#define RANGE_ALL(a) CFRangeMake(0, CFArrayGetCount(a))
#define COMPILE_TIME_ASSERT(pred) switch(0){case 0:case pred:;}
#define kDefaultServiceLogFilter ((OSKextLogSpec) kOSKextLogBasicLevel | \
kOSKextLogVerboseFlagsMask)
#pragma mark Shared Command-line Option Definitions
#define kOptNameArch "arch"
#define kOptNameBundleIdentifier "bundle-id"
#define kOptNameRepository "repository"
#define kOptNameSafeBoot "safe-boot"
#define kOptNameSystemExtensions "system-extensions"
#define kOptNameKernel "kernel"
#define kOptNameNoAuthentication "no-authentication"
#define kOptNameHelp "help"
#define kOptNameQuiet "quiet"
#define kOptNameVerbose "verbose"
#define kOptNameLayoutMap "layout"
#define kOptNameLongindexHack "________"
#define kOptBundleIdentifier 'b'
#define kOptNoAuthentication 'z'
#define kOptHelp 'h'
#define kOptQuiet 'q'
#define kOptVerbose 'v'
#define kOptLayoutMap 'l'
#pragma mark Function Protos
Boolean createCFMutableArray(CFMutableArrayRef * arrayOut,
const CFArrayCallBacks * callbacks);
Boolean createCFMutableDictionary(CFMutableDictionaryRef * dictionaryOut);
Boolean createCFMutableSet(CFMutableSetRef * setOut,
const CFSetCallBacks * callbacks);
Boolean createCFDataFromFile(CFDataRef *dataRefOut,
const char *filePath);
void addToArrayIfAbsent(CFMutableArrayRef array, const void * value);
ExitStatus checkPath(
const char * path,
const char * suffix, Boolean directoryRequired,
Boolean writableRequired);
ExitStatus setLogFilterForOpt(
int argc,
char * const * argv,
OSKextLogSpec forceOnFlags);
void beQuiet(void);
FILE * g_log_stream;
void tool_openlog(const char * name);
void tool_log(
OSKextRef aKext,
OSKextLogSpec logSpec,
const char * format,
...);
void log_CFError(
OSKextRef aKext __unused,
OSKextLogSpec msgLogSpec,
CFErrorRef error);
const char * safe_mach_error_string(mach_error_t error_code);
#define REPLY_ERROR (-1)
#define REPLY_NO (0)
#define REPLY_YES (1)
#define REPLY_ALL (2)
int user_approve(Boolean ask_all, int default_answer, const char * format, ...);
const char * user_input(Boolean * eof, const char * format, ...);
void saveFile(const void * vKey, const void * vValue, void * vContext);
CFStringRef copyKextPath(OSKextRef aKext);
Boolean readSystemKextPropertyValues(
CFStringRef propertyKey,
const NXArchInfo * arch,
Boolean forceUpdateFlag,
CFArrayRef * valuesOut);
ExitStatus writeToFile(
int fileDescriptor,
const UInt8 * data,
CFIndex length);
ExitStatus statURL(CFURLRef anURL, struct stat * statBuffer);
ExitStatus statPath(const char *path, struct stat *statBuffer);
ExitStatus statParentPath(const char *thePath, struct stat *statBuffer);
ExitStatus getLatestTimesFromCFURLArray(
CFArrayRef fileURLArray,
struct timeval fileTimes[2]);
ExitStatus getLatestTimesFromDirURL(
CFURLRef dirURL,
struct timeval dirTimeVals[2]);
ExitStatus getLatestTimesFromDirPath(
const char * dirPath,
struct timeval dirTimeVals[2]);
ExitStatus getFilePathTimes(
const char * filePath,
struct timeval cacheFileTimes[2]);
ExitStatus getFileDescriptorTimes(
int the_fd,
struct timeval cacheFileTimes[2]);
ExitStatus getParentPathTimes(
const char * thePath,
struct timeval cacheFileTimes[2] );
void postNoteAboutKexts(
CFStringRef theNotificationCenterName,
CFMutableDictionaryRef theDict );
void postNoteAboutKextLoadsMT(
CFStringRef theNotificationCenterName,
CFMutableArrayRef theKextPathArray );
void addKextToAlertDict(
CFMutableDictionaryRef *theDictPtr,
OSKextRef theKext );
char * getPathExtension(const char * pathPtr);
int getFileDevAndInoWith_fd(int the_fd, dev_t * the_dev_t, ino_t * the_ino_t);
int getFileDevAndIno(const char * thePath, dev_t * the_dev_t, ino_t * the_ino_t);
Boolean isSameFileDevAndIno(int the_fd,
const char * thePath,
dev_t the_dev_t,
ino_t the_ino_t);
Boolean isSameFileDevAndInoWith_fd(int the_fd,
dev_t the_dev_t,
ino_t the_ino_t);
CFDictionaryRef copyBootCachesDictForURL(CFURLRef theVolRootURL);
Boolean getKernelPathForURL(
CFURLRef theVolRootURL,
char * theBuffer,
int theBufferSize );
Boolean useDevelopmentKernel(const char * theKernelPath);
Boolean isDebugSetInBootargs(void);
extern char * createUTF8CStringForCFString(CFStringRef aString);
#endif