1/* 2 * kernelcache.h 3 * kext_tools 4 * 5 * Created by Nik Gervae on 2010 10 04. 6 * Copyright 2010, 2012 Apple Computer, Inc. All rights reserved. 7 * 8 */ 9#ifndef _KERNELCACHE_H_ 10#define _KERNELCACHE_H_ 11 12#include <libc.h> 13#include "kext_tools_util.h" 14 15#define PLATFORM_NAME_LEN (64) 16#define ROOT_PATH_LEN (256) 17 18// prelinkVersion value >= 1 means KASLR supported 19typedef struct prelinked_kernel_header { 20 uint32_t signature; 21 uint32_t compressType; 22 uint32_t adler32; 23 uint32_t uncompressedSize; 24 uint32_t compressedSize; 25 uint32_t prelinkVersion; 26 uint32_t reserved[10]; 27 char platformName[PLATFORM_NAME_LEN]; // unused 28 char rootPath[ROOT_PATH_LEN]; // unused 29 char data[0]; 30} PrelinkedKernelHeader; 31 32typedef struct platform_info { 33 char platformName[PLATFORM_NAME_LEN]; 34 char rootPath[ROOT_PATH_LEN]; 35} PlatformInfo; 36 37/******************************************************************************* 38*******************************************************************************/ 39 40ExitStatus 41writeFatFile( 42 const char * filePath, 43 CFArrayRef fileSlices, 44 CFArrayRef fileArchs, 45 mode_t fileMode, 46 const struct timeval fileTimes[2]); 47void * mapAndSwapFatHeaderPage( 48 int fileDescriptor); 49void unmapFatHeaderPage( 50 void *headerPage); 51struct fat_arch * getFirstFatArch( 52 u_char *headerPage); 53struct fat_arch * getNextFatArch( 54 u_char *headerPage, 55 struct fat_arch *lastArch); 56struct fat_arch * getFatArchForArchInfo( 57 u_char *headerPage, 58 const NXArchInfo *archInfo); 59const NXArchInfo * 60getThinHeaderPageArch( 61 const void *headerPage); 62ExitStatus readFatFileArchsWithPath( 63 const char * filePath, 64 CFMutableArrayRef * archsOut); 65ExitStatus readFatFileArchsWithHeader( 66 u_char * headerPage, 67 CFMutableArrayRef * archsOut); 68ExitStatus readMachOSlices( 69 const char * filePath, 70 CFMutableArrayRef * slicesOut, 71 CFMutableArrayRef * archsOut, 72 mode_t * modeOut, 73 struct timeval machOTimesOut[2]); 74 75CF_RETURNS_RETAINED 76CFDataRef readMachOSliceForArch( 77 const char * filePath, 78 const NXArchInfo * archInfo, 79 Boolean checkArch); 80 81CF_RETURNS_RETAINED 82CFDataRef readMachOSlice( 83 int fileDescriptor, 84 off_t fileOffset, 85 size_t fileSliceSize); 86int readFileAtOffset( 87 int fileDescriptor, 88 off_t fileOffset, 89 size_t fileSize, 90 u_char * buf); 91int verifyMachOIsArch( 92 const UInt8 * fileBuf, 93 size_t size, 94 const NXArchInfo * archInfo); 95CF_RETURNS_RETAINED 96CFDataRef uncompressPrelinkedSlice( 97 CFDataRef prelinkImage); 98CF_RETURNS_RETAINED 99CFDataRef compressPrelinkedSlice( 100 CFDataRef prelinkImage, 101 Boolean hasRelocs); 102ExitStatus writePrelinkedSymbols( 103 CFURLRef symbolDirURL, 104 CFArrayRef prelinkSymbols, 105 CFArrayRef prelinkArchs); 106ExitStatus makeDirectoryWithURL( 107 CFURLRef dirURL); 108 109#endif /* _KERNELCACHE_H_ */ 110