static void* getStubAddr() { #if __LP64__ uint64_t size; #else uint32_t size; #endif uintptr_t slide = (uintptr_t)&_mh_dylib_header; // assume dylib is zero-base so slide == load address #if __i386__ return getsectdatafromheader(&_mh_dylib_header, "__IMPORT", "__jump_table", &size) + slide; #elif __ppc__ return getsectdatafromheader(&_mh_dylib_header, "TEXT", "__picsymbolstub1", &size) + slide; #elif __ppc64__ return getsectdatafromheader_64(&_mh_dylib_header, "__TEXT", "__picsymbolstub1", &size) + slide; #elif __x86_64__ return getsectdatafromheader_64(&_mh_dylib_header, "__TEXT", "__symbol_stub1", &size) + slide; #elif __arm__ void* p = getsectdata("__TEXT", "__picsymbolstub4", (unsigned long*)&size); if ( p != NULL ) return getsectdatafromheader(&_mh_dylib_header, "__TEXT", "__picsymbolstub4", &size) + slide; return getsectdatafromheader(&_mh_dylib_header, "__TEXT", "__symbolstub1", &size) + slide; #else #error unknown arch #endif }
void read_section(const struct mach_header *mhp, unsigned long slide, const char *segname, const char *sectname) { u_int32_t size; char *sect = getsectdatafromheader(mhp, segname, sectname, &size); if(!sect) return; char *start = sect + slide; char *end = start + size; while(start != end) { gTempVal += *(char *)start; start++; } }
bool image_info_jump_table(uint32_t index, jump_table_t *table) { const struct mach_header *header; if (!image_info_ready()) { p0_logf(P0_ERR, "image info not currently ready"); return false; } if (index >= all_image_infos->infoArrayCount) { p0_logf(P0_ERR, "index out of range"); return false; } if (!table) { p0_logf(P0_ERR, "specified jump_table pointer is NULL"); return false; } header = all_image_infos->infoArray[index].imageLoadAddress; p0_logf(P0_INFO, "loading image '%s'", all_image_infos->infoArray[index].imageFilePath); if (!header) { p0_logf(P0_ERR, "failed to acquire header for %d", index); return false; } table->addr = (intptr_t) getsectdatafromheader(header, "__IMPORT", "__jump_table", (unsigned long *) &table->size); p0_logf(P0_INFO, "header: %p addr %p", header, table->addr); if (table->addr == 0) { p0_logf(P0_ERR, "jump table mapped at 0x0: bailing"); return false; } /* Make sure we can patch the table */ if (vm_protect(mach_task_self(), (vm_address_t)table->addr, table->size, false, VM_PROT_ALL) != KERN_SUCCESS) { /* we will keep on truckin' though. just in case! */ p0_logf(P0_WARN, "failed to change the protections on the jump table"); } return true; }
void load_linux(unsigned int args) { int i; char *ptr; kdesc_t kd; unsigned char szBootSect[BOOT_PARAM_MEMSIZE]; boot_params_t *bp = (boot_params_t*)szBootSect; char *cmdline = (char*)&szBootSect[BOOT_PARAM_MEMSIZE - 2048]; unsigned long kernel_len = 0; unsigned char *kernel_ptr = NULL; unsigned long initrd_len = 0; unsigned char *initrd_ptr = NULL; mach_bp = (mach_boot_parms*)args; vmode.width = mach_bp->video.rowb / 4; vmode.height = mach_bp->video.height; vmode.xmargin = 0; // clear the screen //sleep(10); memset((char*)mach_bp->video.addr, 0x00, vmode.width * vmode.height * 4); // VIDEO_CURSOR_POSX = 0; VIDEO_CURSOR_POSY = 0; VIDEO_ATTR = 0xffc8c8c8; // printk("ATV: ATV_BootLoader v0.8 (http://atv-bootloader.googlecode.com/)\n"); printk("ATV: Copyright (C) 2008 ATV Bootloader Team - Licensed under the GPL v2\n"); printk("ATV: FB Start 0x%08X, with %d height %d rowb %d depth %d\n", mach_bp->video.addr, mach_bp->video.width, mach_bp->video.height, mach_bp->video.rowb, mach_bp->video.depth); //printk("mach_bp->devtree_len=0x%08X, mach_bp->devtree_ptr=0x%08X", // mach_bp->devtree_len, mach_bp->devtree_ptr); //sleep(10); // find the kernel and load it in the proper location kernel_ptr = (unsigned char*)getsectdatafromheader(&_mh_execute_header, "__TEXT", "__vmlinuz", &kernel_len); //printk("ATV: kernel_ptr = 0x%08X, kernel_len = 0x%08X\n", kernel_ptr, kernel_len); // kernel integrity check if (kernel_ptr[0x1FE] != 0x55 || kernel_ptr[0x1FF] != 0xAA) { printk("ATV: kernel_ptr[0x1FE] = 0x%X, kernel_ptr[0x1FF] = 0x%X\n", kernel_ptr[0x1FE], kernel_ptr[0x1FF]); printk("ATV: Kernel is not a vmlinuz or bzImage kernel image.\n"); while(1); } // load kernel into it in the proper location (1M) kernel_start = (VOID*)0x00100000; // zero kernel destination in ram memory memset(kernel_start, 0x00, KERNEL_RESERVE_SIZE); // compute kernel size from actual kernel using zero-page setup_sectors (512 bytes per sector) kernel_size = kernel_len - ((kernel_ptr[0x1F1] + 1) * 512); // copy loaded kernel to base memory location memcpy(kernel_start, &kernel_ptr[ (kernel_ptr[0x1F1] + 1) * 512 ], kernel_size); // find possible initrd, start_kernel will handle loading into a proper location) initrd_ptr = (unsigned char*)getsectdatafromheader(&_mh_execute_header, "__TEXT", "__initrd", &initrd_len); //printk("ATV: initrd_ptr = 0x%08X, initrd_len = 0x%08X\n", initrd_ptr, initrd_len); initrd_start = initrd_ptr; initrd_size = initrd_len; // setup the kernel boot parameters // zero boot param structure memset(bp, 0x00, BOOT_PARAM_MEMSIZE); // copy the "zero page" from the kernel that was loaded (8192 bytes) memcpy(bp, kernel_ptr, 0x2000); // create linux kernel command line params from mach-o passed command line params // this comes from com.apple.Boot.plist under <key>Kernel Flags</key> sprintf(cmdline, "%s", mach_bp->cmdline); /* sprintf(cmdline, "%s video=imacfb:appletv,width:%d,height:%d,linelength:%d,base:%d", mach_bp->cmdline, mach_bp->video.width, mach_bp->video.height, mach_bp->video.rowb, mach_bp->video.addr); */ printk("ATV: kernel command line-> %s\n", cmdline); // now format the linux kernel boot params create_boot_params(bp, cmdline); //sleep(10); printk("ATV: starting Linux...\n"); // kernel_start = 0x100000 defined in system.c kd.kstart = kd.kentry = kernel_start; kd.kend = ((UINT8*)kd.kstart) + KERNEL_RESERVE_SIZE; start_kernel(kd.kentry, bp); printk("ATV: error something's is wrong\n"); while(1); }
static inline const fde * examine_objects (void *pc, struct dwarf_eh_bases *bases, int dont_alloc) { const fde *result = NULL; struct live_images *image; image = _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST); for (; image != NULL; image = image->next) if ((image->examined_p & EXAMINED_IMAGE_MASK) == 0) { char *fde = NULL; unsigned long sz; /* For ppc only check whether or not we have __DATA eh frames. */ #ifdef __ppc__ fde = getsectdatafromheader (image->mh, "__DATA", "__eh_frame", &sz); #endif if (fde == NULL) { #if __LP64__ fde = getsectdatafromheader_64 ((struct mach_header_64 *) image->mh, "__TEXT", "__eh_frame", &sz); #else fde = getsectdatafromheader (image->mh, "__TEXT", "__eh_frame", &sz); #endif if (fde != NULL) image->examined_p |= IMAGE_IS_TEXT_MASK; } /* If .eh_frame is empty, don't register at all. */ if (fde != NULL && sz > 0) { char *real_fde = (fde + image->vm_slide); struct object *ob = NULL; struct object panicob; if (! dont_alloc) ob = calloc (1, sizeof (struct object)); dont_alloc |= ob == NULL; if (dont_alloc) ob = &panicob; ob->pc_begin = (void *)-1; ob->tbase = 0; ob->dbase = 0; ob->u.single = (struct dwarf_fde *)real_fde; ob->s.i = 0; ob->s.b.encoding = DW_EH_PE_omit; ob->fde_end = real_fde + sz; image->fde = real_fde; result = search_object (ob, pc); if (! dont_alloc) { struct object **p; image->destructor = live_image_destructor; image->object_info = ob; image->examined_p |= (EXAMINED_IMAGE_MASK | DESTRUCTOR_MAY_BE_CALLED_LIVE); /* Insert the object into the classified list. */ for (p = &seen_objects; *p ; p = &(*p)->next) if ((*p)->pc_begin < ob->pc_begin) break; ob->next = *p; *p = ob; } if (result) { int encoding; _Unwind_Ptr func; bases->tbase = ob->tbase; bases->dbase = ob->dbase; encoding = ob->s.b.encoding; if (ob->s.b.mixed_encoding) encoding = get_fde_encoding (result); read_encoded_value_with_base (encoding, base_from_object (encoding, ob), result->pc_begin, &func); bases->func = (void *) func; break; } } else image->examined_p |= EXAMINED_IMAGE_MASK; } _keymgr_unlock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST); return result; }