Index: branches/meklort/i386/libsaio/hfs.c =================================================================== --- branches/meklort/i386/libsaio/hfs.c (revision 143) +++ branches/meklort/i386/libsaio/hfs.c (revision 144) @@ -602,7 +602,7 @@ // Read the BTree node and get the record for index. ReadExtent(extent, extentSize, kHFSCatalogFileID, - curNode * nodeSize, nodeSize, nodeBuf, 1); + (long long)curNode * nodeSize, nodeSize, nodeBuf, 1); GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &entry); GetCatalogEntryInfo(entry, flags, time, finderInfo, infoValid); @@ -732,7 +732,7 @@ while (1) { // Read the current node. ReadExtent(extent, extentSize, extentFile, - curNode * nodeSize, nodeSize, nodeBuf, 1); + (long long)curNode * nodeSize, nodeSize, nodeBuf, 1); // Find the matching key. lowerBound = 0; Index: branches/meklort/i386/libsaio/load.c =================================================================== --- branches/meklort/i386/libsaio/load.c (revision 143) +++ branches/meklort/i386/libsaio/load.c (revision 144) @@ -37,7 +37,7 @@ static long DecodeSymbolTable(long cmdBase); -static unsigned long gBinaryAddress; +unsigned long gBinaryAddress; bool gHaveKernelCache; /* XXX aserebln: uninitialized? and only set to true, never to false */ cpu_type_t archCpuType=CPU_TYPE_I386; Index: branches/meklort/i386/boot2/drivers.c =================================================================== --- branches/meklort/i386/boot2/drivers.c (revision 143) +++ branches/meklort/i386/boot2/drivers.c (revision 144) @@ -38,6 +38,7 @@ #include "bootstruct.h" #include "xml.h" #include "ramdisk.h" +#include "kernel_patcher.h" extern char gMacOSVersion; @@ -813,6 +814,8 @@ archCpuType=CPU_TYPE_I386; ret = DecodeMachO(binary, rentry, raddr, rsize); } + + patch_kernel(); return ret; } Index: branches/meklort/i386/boot2/kernel_patcher.c =================================================================== --- branches/meklort/i386/boot2/kernel_patcher.c (revision 143) +++ branches/meklort/i386/boot2/kernel_patcher.c (revision 144) @@ -29,8 +29,8 @@ }; -UInt32 textSection; -UInt32 textAddress; +UInt32 textSection = 0; +UInt32 textAddress = 0; extern unsigned long gBinaryAddress; @@ -42,6 +42,7 @@ case KERNEL_32: patch_kernel_32((void*)gBinaryAddress); break; + case KERNEL_64: default: patch_kernel_64((void*)gBinaryAddress); @@ -55,16 +56,16 @@ // At the moment, the kernel patching code fails when used // in 64bit mode, so we don't patch it. This is due to 32bit vs 64bit // pointers as well as changes in structure sizes - verbose("Unable to patch 64bit kernel. Please use arch=i386.\n"); + printf("Unable to patch 64bit kernel. Please use arch=i386.\n"); } + /** ** patch_kernel_32 ** Due to the way the _cpuid_set_info function is writtin, the first instance of _panic is called ** when an unsupported (read: non apple used cpu) is found. This routine locates that first _panic call ** and replaces the jump call (0xe8) with no ops (0x90). **/ - void patch_kernel_32(void* kernelData) { patch_pmCPUExitHaltToOff(kernelData); @@ -72,6 +73,7 @@ } + /** ** This functions located the following in the mach_kernel symbol table ** _panic @@ -92,6 +94,7 @@ if(((struct mach_header*)kernelData)->magic != MH_MAGIC) return KERNEL_64; + //printf("%d load commands beginning at 0x%X\n", (unsigned int)header->ncmds, (unsigned int)kernelIndex); //printf("Commands take up %d bytes\n", header->sizeofcmds); @@ -135,6 +138,7 @@ symbolIndexes[i] = symbolIndex; numSymbolsFound++; } + i++; } symbolString += strlen(symbolString) + 1; @@ -157,6 +161,7 @@ kernelSymbolAddresses[i] = (UInt32)symbolEntry->n_value; numSymbolsFound++; } + i++; } @@ -189,7 +194,7 @@ if(strcmp("__text", sect->sectname) == 0) { - // __TEXT,__text found, save the offset and address for when looking for the panic call. + // __TEXT,__text found, save the offset and address for when looking for the calls. textSection = sect->offset; textAddress = sect->addr; break; @@ -207,16 +212,27 @@ return KERNEL_32; } + /** ** Locate the fisrt instance of _panic inside of _cpuid_set_info, and remove it **/ void patch_cpuid_set_info(void* kernelData) { - UInt8* bytes = (void*)kernelData; + UInt8* bytes = (UInt8*)kernelData; UInt32 patchLocation = (kernelSymbolAddresses[SYMBOL_CPUID_SET_INFO] - textAddress + textSection); UInt32 panidAddr = kernelSymbolAddresses[SYMBOL_PANIC] - textAddress; + if(kernelSymbolAddresses[SYMBOL_CPUID_SET_INFO] == 0) + { + printf("Unable to locate _cpuid_set_info\n"); + return; + + } + if(kernelSymbolAddresses[SYMBOL_PANIC] == 0) + { + printf("Unable to locate _panic\n"); + return; + } - //TODO: don't assume it'll always work (Look for *next* function address in symtab and fail once it's been reached) while( (bytes[patchLocation -1] != 0xE8) || @@ -228,6 +244,7 @@ // (patchLocation < maxLocation) // max location is not known... assuming there is a panic call somewhere after cpuid_set_info ) { + //printf("Looking at 0x%X\n", patchLocation); patchLocation++; } @@ -237,19 +254,24 @@ bytes[patchLocation + 1] = 0x90; bytes[patchLocation + 2] = 0x90; bytes[patchLocation + 3] = 0x90; - - // Patching finished } + /** ** SleepEnabler.kext replacement (for those that need it) ** Located the KERN_INVALID_ARGUMENT return and replace it with KERN_SUCCESS **/ void patch_pmCPUExitHaltToOff(void* kernelData) { - UInt8* bytes = (void*)kernelData; + UInt8* bytes = (UInt8*)kernelData; UInt32 patchLocation = (kernelSymbolAddresses[SYMBOL_PMCPUEXITHALTTOOFF] - textAddress + textSection); + if(kernelSymbolAddresses[SYMBOL_PMCPUEXITHALTTOOFF] == 0) + { + printf("Unable to locate _pmCPUExitHaltToOff\n"); + return; + } + while(bytes[patchLocation - 1] != 0xB8 || bytes[patchLocation] != 0x04 || // KERN_INVALID_ARGUMENT (0x00000004) bytes[patchLocation + 1] != 0x00 || // KERN_INVALID_ARGUMENT @@ -260,5 +282,4 @@ patchLocation++; } bytes[patchLocation] = 0x00; // KERN_SUCCESS; - } Index: branches/meklort/i386/boot2/Makefile =================================================================== --- branches/meklort/i386/boot2/Makefile (revision 143) +++ branches/meklort/i386/boot2/Makefile (revision 144) @@ -42,7 +42,7 @@ # The ordering is important; # boot2.o must be first. OBJS = boot2.o boot.o graphics.o drivers.o prompt.o options.o lzss.o mboot.o \ - ramdisk.o picopng.o resume.o bmdecompress.o graphic_utils.o gui.o + ramdisk.o kernel_patcher.o picopng.o resume.o bmdecompress.o graphic_utils.o gui.o # button.o browser.o scrollbar.o == NOTYET UTILDIR = ../util