static BVRef newFDiskBVRef( int biosdev, int partno, unsigned int blkoff, const struct fdisk_part * part, FSInit initFunc, FSLoadFile loadFunc, FSReadFile readFunc, FSGetDirEntry getdirFunc, FSGetFileBlock getBlockFunc, BVGetDescription getDescriptionFunc, int probe, int type ) { BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); if ( bvr ) { bzero(bvr, sizeof(*bvr)); bvr->biosdev = biosdev; bvr->part_no = partno; bvr->part_boff = blkoff; bvr->part_type = part->systid; bvr->fs_loadfile = loadFunc; bvr->fs_readfile = readFunc; bvr->fs_getdirentry = getdirFunc; bvr->fs_getfileblock= getBlockFunc; bvr->description = getDescriptionFunc ? getDescriptionFunc : getVolumeDescription; bvr->type = type; if ( part->bootid & FDISK_ACTIVE ) bvr->flags |= kBVFlagPrimary; // Probe the filesystem. if ( initFunc ) { bvr->flags |= kBVFlagNativeBoot; if ( probe && initFunc( bvr ) != 0 ) { // filesystem probe failed. DEBUG_DISK(("%s: failed probe on dev %x part %d\n", __FUNCTION__, biosdev, partno)); free(bvr); bvr = NULL; } } else if ( readBootSector( biosdev, blkoff, (void *)0x7e00 ) == 0 ) { bvr->flags |= kBVFlagForeignBoot; } else { free(bvr); bvr = NULL; } } return bvr; }
static BVRef probeBVRef(BVRef bvr, unsigned int bvrFlags) { bvr->flags |= kBVFlagNativeBoot; // 0x02 if (readBootSector(bvr->biosdev, bvr->part_boff, (void *)0x7e00) == 0) { bvr->flags |= kBVFlagBootable; // 0x08 } bvr->flags |= bvrFlags; return bvr; }
int main(int argc, char* argv[]) { void* pointer = NULL; int shm_ID; if ((shm_ID = shmget(SHMKEY, SHMSIZE, IPC_CREAT | 0444)) < 0 ) { perror("Error getting SHM segment."); exit(-1); } if ((pointer = shmat(shm_ID, NULL, 0)) == NULL) { perror("Error including SHM address space."); exit(0); } shmStruct *value = (shmStruct*)pointer; //memcpy(&value, pointer, sizeof(pointer)); printf("pointer size: %i\n", sizeof(pointer)); loadFloppyImage(value->floppyName); if (shmdt(pointer) < 0) { perror("Error deallocating shared memory."); exit(-1); } readBootSector(); printBootSector(); return 0; }
int processBootOptions() { const char * cp = gBootArgs; const char * val = 0; const char * kernel; int cnt; int userCnt; int cntRemaining; char * argP; char uuidStr[64]; bool uuidSet = false; char * configKernelFlags; char * valueBuffer; valueBuffer = malloc(VALUE_SIZE); skipblanks( &cp ); // Update the unit and partition number. if ( gBootVolume ) { if (!( gBootVolume->flags & kBVFlagNativeBoot )) { readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 ); // // Setup edx, and signal intention to chain load the // foreign booter. // chainbootdev = gBootVolume->biosdev; chainbootflag = 1; return 1; } setRootVolume(gBootVolume); } // If no boot volume fail immediately because we're just going to fail // trying to load the config file anyway. else return -1; // Load config table specified by the user, or use the default. if (!getValueForBootKey(cp, "config", &val, &cnt)) { val = 0; cnt = 0; } // Load com.apple.Boot.plist from the selected volume // and use its contents to override default bootConfig. // This is not a mandatory operation anymore. loadOverrideConfig(&bootInfo->overrideConfig); // Use the kernel name specified by the user, or fetch the name // in the config table, or use the default if not specified. // Specifying a kernel name on the command line, or specifying // a non-default kernel name in the config file counts as // overriding the kernel, which causes the kernelcache not // to be used. gOverrideKernel = false; if (( kernel = extractKernelName((char **)&cp) )) { strcpy( bootInfo->bootFile, kernel ); gOverrideKernel = true; } else { if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) { strlcpy( bootInfo->bootFile, val, cnt+1 ); if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) { gOverrideKernel = true; } } else { strcpy( bootInfo->bootFile, kDefaultKernel ); } } cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space argP = bootArgs->CommandLine; // Get config table kernel flags, if not ignored. if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) { val = ""; cnt = 0; } configKernelFlags = malloc(cnt + 1); strlcpy(configKernelFlags, val, cnt + 1); if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) { // boot-uuid was set either on the command-line // or in the config file. uuidSet = true; } else { // // Try an alternate method for getting the root UUID on boot helper partitions. // if (gBootVolume->flags & kBVFlagBooter) { if((loadHelperConfig(&bootInfo->helperConfig) == 0) && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) ) { getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig); copyArgument(kBootUUIDKey, val, cnt, &argP, &cntRemaining); uuidSet = true; } } if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, uuidStr) == 0) { verbose("Setting boot-uuid to: %s\n", uuidStr); copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining); uuidSet = true; } } if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) { cnt = 0; if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) { valueBuffer[0] = '*'; cnt++; strlcpy(valueBuffer + 1, val, cnt); val = valueBuffer; } else { if (uuidSet) { val = "*uuid"; cnt = 5; } else { // Don't set "rd=.." if there is no boot device key // and no UUID. val = ""; cnt = 0; } } if (cnt > 0) { copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); } strlcpy( gRootDevice, val, (cnt + 1)); } /* * Removed. We don't need this anymore. * if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) { getPlatformName(gPlatformName); copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); } */ if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) { if (gBootMode & kBootModeSafe) { copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); } } // Store the merged kernel flags and boot args. cnt = strlen(configKernelFlags); if (cnt) { if (cnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); cnt = cntRemaining; } strncpy(argP, configKernelFlags, cnt); argP[cnt++] = ' '; cntRemaining -= cnt; } userCnt = strlen(cp); if (userCnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); userCnt = cntRemaining; } strncpy(&argP[cnt], cp, userCnt); argP[cnt+userCnt] = '\0'; if(!shouldboot) { gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) || getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig ); gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ? kBootModeSafe : kBootModeNormal; if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) { gBootMode = kBootModeSafe; } } if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) { strlcpy(gMKextName, val, cnt + 1); } free(configKernelFlags); free(valueBuffer); return 0; }
int processBootOptions() { const char *cp = gBootArgs; const char *val = 0; const char *kernel; int cnt; int userCnt; int cntRemaining; char *argP; char *configKernelFlags; char *valueBuffer; valueBuffer = malloc(VALUE_SIZE); skipblanks( &cp ); // Update the unit and partition number. if ( gBootVolume ) { if (!( gBootVolume->flags & kBVFlagNativeBoot )) { readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 ); // // Setup edx, and signal intention to chain load the // foreign booter. // chainbootdev = gBootVolume->biosdev; chainbootflag = 1; return 1; } setRootVolume(gBootVolume); } // If no boot volume fail immediately because we're just going to fail // trying to load the config file anyway. else { return -1; } // Find out which version mac os we're booting. strncpy(gMacOSVersion, gBootVolume->OSVersion, sizeof(gMacOSVersion)); // Load config table specified by the user, or use the default. if (!getValueForBootKey(cp, "config", &val, &cnt)) { val = 0; cnt = 0; } // Load com.apple.Boot.plist from the selected volume // and use its contents to override default bootConfig. loadSystemConfig(&bootInfo->bootConfig); loadChameleonConfig(&bootInfo->chameleonConfig, NULL); // Use the kernel name specified by the user, or fetch the name // in the config table, or use the default if not specified. // Specifying a kernel name on the command line, or specifying // a non-default kernel name in the config file counts as // overriding the kernel, which causes the kernelcache not // to be used. gOverrideKernel = false; if (( kernel = extractKernelName((char **)&cp) )) { strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) ); } else { if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) { strlcpy( bootInfo->bootFile, val, cnt+1 ); } else { if( YOSEMITE ) // is 10.10 { strlcpy( bootInfo->bootFile, kOSXKernel, sizeof(bootInfo->bootFile) ); //printf(HEADER "/System/Library/Kernels/%s\n", bootInfo->bootFile); } else { // OSX is not 10.10 strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) ); //printf(HEADER "/%s\n", bootInfo->bootFile); } } } if (!YOSEMITE) // not 10.10 so 10.9 and previus { if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) { //printf(HEADER "org.chameleon.Boot.plist found path for custom '%s' found!\n", bootInfo->bootFile); gOverrideKernel = true; } } else { // OSX is 10.10 if (strcmp( bootInfo->bootFile, kOSXKernel ) != 0) { //printf(HEADER "org.chameleon.Boot.plist found path for custom '%s' found!\n", bootInfo->bootFile); gOverrideKernel = true; } } // Ermac : Inject "kext-dev-mode=1" if OS X 10.10 is detected if( YOSEMITE ) // is 10.10 { addBootArg("kext-dev-mode=1"); } cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space argP = bootArgs->CommandLine; // Get config kernel flags, if not ignored. if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) { val = ""; cnt = 0; } configKernelFlags = malloc(cnt + 1); strlcpy(configKernelFlags, val, cnt + 1); // boot-uuid can be set either on the command-line or in the config file if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString))) { // // Try an alternate method for getting the root UUID on boot helper partitions. // if (gBootVolume->flags & kBVFlagBooter) { // Load the configuration store in the boot helper partition if (loadHelperConfig(&bootInfo->helperConfig) == 0) { val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig); if (val != NULL) { strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString)); } } } /* // Try to get the volume uuid string if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) { gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString); } */ // If we have the volume uuid add it to the commandline arguments if (strlen(gBootUUIDString)) { copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining); } // Try to get the volume uuid string if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) { gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString); DBG("boot-uuid: %s\n", gBootUUIDString); } } if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) { cnt = 0; if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) { valueBuffer[0] = '*'; cnt++; strlcpy(valueBuffer + 1, val, cnt); val = valueBuffer; } else { /* if (strlen(gBootUUIDString)) { val = "*uuid"; cnt = 5; } else { */ // Don't set "rd=.." if there is no boot device key // and no UUID. val = ""; cnt = 0; /* } */ } if (cnt > 0) { copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); } strlcpy( gRootDevice, val, (cnt + 1)); } /* * Removed. We don't need this anymore. * if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler))) { getPlatformName(gPlatformName); copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); } */ if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) { if (gBootMode & kBootModeSafe) { copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); } } // Store the merged kernel flags and boot args. cnt = strlen(configKernelFlags); if (cnt) { if (cnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); cnt = cntRemaining; } strncpy(argP, configKernelFlags, cnt); argP[cnt++] = ' '; cntRemaining -= cnt; } userCnt = strlen(cp); if (userCnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); userCnt = cntRemaining; } strncpy(&argP[cnt], cp, userCnt); argP[cnt+userCnt] = '\0'; if(!shouldboot) { gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) || getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig ); gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ? kBootModeSafe : kBootModeNormal; if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) { gBootMode = kBootModeSafe; } } if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) { strlcpy(gMKextName, val, cnt + 1); } else { gMKextName[0]=0; } free(configKernelFlags); free(valueBuffer); return 0; }
int main (int argc, char *argv[]) { FILE *fileImgPtr; Directory currentDir; OpenFileTable ofTable; unsigned int currentDirCluster; int flag = -1; int runLoop = 1; // Check for correct number of arguments. if (argc != 2) { printf("Error: Incorrect number of arguments.\n"); printf("Expected: osmagicFAT <file image>\n"); return 1; } // Open the file image. fileImgPtr = fopen(argv[1], "rb+"); if (fileImgPtr == NULL) { printf("Error: could not open file image\n."); return 1; } // Read and store the boot sector data. readBootSector(fileImgPtr); // Set current directory to the root directory. currentDirCluster = fsMetadata[ROOT_CLUSTER]; // Initialize open file table. ofTable.entries = (OpenFileEntry*) malloc(sizeof(OpenFileEntry)); ofTable.size = 0; printf("Please input a command. Type 'quit' to quit program.\n"); //Loop to perform commands until user exits. while(runLoop) { // Allocate memory to hold commands. char input[256]; // Save the number of tokens(arguments) in each input. int tokCount = 0; char **cmds = (char**) malloc(6*sizeof(char*)); for (int itr = 0; itr < 6; itr++) cmds[itr]=(char*) malloc(1*sizeof(char)); // Initialize current directory data currentDir.dirEntries = (unsigned char **) malloc(sizeof(unsigned char *)); currentDir.size = 0; // Read and store the current directory. getDirEntries(fileImgPtr, currentDirCluster, ¤tDir); // Print prompt and get user input. printf("=>"); if (fgets(input, 256, stdin) == NULL){ printf("Error! Invalid input!\n"); exit(-1); } tokCount = tokenize(input,cmds); // Compare first argument to perform command. if (strcmp(cmds[0], "quit") == 0){ runLoop = 0; } else if (strcmp(cmds[0], "open") == 0) { if (tokCount != 3) { printf("Error: Invalid arguments.\n"); printf("Expected: open <filename> <flag>\n"); } else { // Convert flag input string to int. if(strcmp(cmds[2], "r") == 0) flag = READ; else if(strcmp(cmds[2], "w") == 0) flag = WRITE; else if(strcmp(cmds[2], "rw") == 0) flag = READWRITE; else if(strcmp(cmds[2], "wr") == 0) flag = READWRITE; else { printf("Error: Invalid flag.\n"); continue; } open(currentDir, fileImgPtr, &ofTable, cmds[1], flag); } } else if (strcmp(cmds[0], "close") == 0) { if(tokCount != 2) { printf("Error: Invalid arguments.\n"); printf("Expected: close <filename>\n"); } else { if(!closeFile(&ofTable, cmds[1])) printf("Error: File has not been opened.\n"); } } // open else if (strcmp(cmds[0], "close") == 0) { } // close else if (strcmp(cmds[0], "create") == 0) { if (tokCount != 2) { printf("Error: Invalid arguments.\n"); printf("Expected: create <filename>.\n"); } // if else if (strcmp(cmds[1], ".") == 0 || strcmp(cmds[1], "..") == 0) { printf("Error: Invalid arguments.\n"); printf("\'%s\' is not a valid name\n", cmds[1]); } else { create(currentDir, currentDirCluster, fileImgPtr, cmds[1], 0); } } // create else if (strcmp(cmds[0], "rm") == 0) { if (tokCount != 2) { printf("Error: Invalid arguments.\n"); printf("Expected: create <dirname>.\n"); } // using . or .. is not allowed else if (strcmp(cmds[1], ".") == 0 || strcmp(cmds[1], "..") == 0) { printf("Error: Invalid arguments.\n"); printf("\'%s\' is not a valid name\n", cmds[1]); } else { int flag = 0; if(rm(currentDir, currentDirCluster, fileImgPtr, &ofTable, cmds[1], flag)) printf("File has been removed.\n"); } } // rm else if (strcmp(cmds[0], "size") == 0) { if(tokCount != 2) { printf("Error: Invalid arguments.\n"); printf("Expected: size <filename>\n"); } else { printf("%d bytes\n", size(currentDir, cmds[1])); } } // size else if (strcmp(cmds[0], "cd") == 0) { if(tokCount != 2) { printf("Error: Invalid arguments.\n"); printf("Expected: cd <directory>\n"); } else { // Find the cluster number of the desired directory and set the current // directory to that cluster. unsigned int newClusterNum = 0; unsigned int *newClusterPtr = &newClusterNum; if(cd(currentDir, cmds[1], newClusterPtr)) { currentDirCluster = *newClusterPtr; } } } // cd else if (strcmp(cmds[0], "ls") == 0) { //If only 1 argument, lists the current directory if(cmds[1] == NULL) ls(currentDir); else { unsigned int newDirCluster; //newDir will be populated with entries from the specified directory Directory newDir; newDir.dirEntries = (unsigned char **) malloc(sizeof(unsigned char *)); newDir.size = 0; unsigned int newClusterNum = 0; unsigned int *newClusterPtr = &newClusterNum; //Checks if specified directory exists if(cd(currentDir, cmds[1], newClusterPtr)) { newDirCluster = *newClusterPtr; getDirEntries(fileImgPtr, newDirCluster, &newDir); ls(newDir); } // Free the dynamically allocated new directory. for(int i = 0; i < newDir.size; ++i) { free(newDir.dirEntries[i]); } free(newDir.dirEntries); } } // ls else if (strcmp(cmds[0], "read") == 0) { if(tokCount != 4) { printf("Error: Invalid arguments.\n"); printf("Expected: read <filename> <position> <number of bytes>\n"); } else { int pos, numBytes; pos = atoi(cmds[2]); numBytes = atoi(cmds[3]); readFile(currentDir, &ofTable, fileImgPtr, cmds[1], pos, numBytes); } } // read else if (strcmp(cmds[0], "write") == 0) { if(tokCount != 5) { printf("Error: Invalid arguments.\n"); printf("Expected: write <filename> <position> <number of bytes> <string>\n"); } else { int pos, numBytes; pos = atoi(cmds[2]); numBytes = atoi(cmds[3]); writeFile(currentDir, currentDirCluster, &ofTable, fileImgPtr, cmds[1], pos, numBytes, cmds[4]); } } // write else if (strcmp(cmds[0], "mkdir") == 0) { if (tokCount != 2) { printf("Error: Invalid arguments.\n"); printf("Expected: create <dirname>.\n"); } else if (strcmp(cmds[1], ".") == 0 || strcmp(cmds[1], "..") == 0) { printf("Error: Invalid arguments.\n"); printf("\'%s\' is not a valid name\n", cmds[1]); } else { create(currentDir, currentDirCluster, fileImgPtr, cmds[1], 1); } } // mkdir else if (strcmp(cmds[0], "rmdir") == 0) { if (tokCount != 2) { printf("Error: Invalid arguments.\n"); printf("Expected: create <dirname>.\n"); } else if (strcmp(cmds[1], ".") == 0 || strcmp(cmds[1], "..") == 0) { printf("Error: Invalid arguments.\n"); printf("\'%s\' is not a valid name\n", cmds[1]); } else { int flag = 0; if(rmDirectory(currentDir, currentDirCluster, fileImgPtr, cmds[1], flag)) printf("Directory has been removed.\n"); } } // rmdir else { printf("Invalid command. Please try again.\n"); } // invalid // Free dynamically-allocated memory. for (int itr = 0; itr < 6; itr++) free(cmds[itr]); free(cmds); // Free the dynamically allocated current directory. for (int i = 0; i < currentDir.size; ++i) { free(currentDir.dirEntries[i]); } free(currentDir.dirEntries); } // while input //Close the file image. fclose(fileImgPtr); printf("Exiting program...\n"); // Free the dynamically allocated open file table. // Free the cluster chains. for (int i = 0; i < ofTable.size; ++i) { free(ofTable.entries[i].clusterOffsets); } // Free the table. free(ofTable.entries); return 0; }
int processBootOptions(void) { char *cp_cache = (char*)(uint32_t)get_env(envgBootArgs); if (cp_cache) { bzero(gBootArgs,sizeof(gBootArgs)); strlcpy(gBootArgs, cp_cache,sizeof(gBootArgs)); } const char * cp = gBootArgs; const char * val = 0; const char * kernel; int cnt; int userCnt; char * argP; char * configKernelFlags; int ArgCntRemaining; skipblanks( &cp ); // Update the unit and partition number. if ( ((BVRef)(uint32_t)get_env(envgBootVolume)) ) { #ifndef NO_MULTIBOOT_SUPPORT if (!( ((BVRef)(uint32_t)get_env(envgBootVolume))->flags & kBVFlagNativeBoot )) { readBootSector( ((BVRef)(uint32_t)get_env(envgBootVolume))->biosdev, ((BVRef)(uint32_t)get_env(envgBootVolume))->part_boff, (void *) 0x7c00 ); // // Setup edx, and signal intention to chain load the // foreign booter. // extern unsigned char chainbootdev; extern unsigned char chainbootflag; chainbootdev = ((BVRef)(uint32_t)get_env(envgBootVolume))->biosdev; chainbootflag = 1; return 1; } #endif setRootVolume(((BVRef)(uint32_t)get_env(envgBootVolume))); } // If no boot volume fail immediately because we're just going to fail // trying to load the config file anyway. else return -1; // Load config table specified by the user, or use the default. if (!getValueForBootKey(cp, "config", &val, &cnt)) { val = 0; cnt = 0; } // Load com.apple.Boot.plist from the selected volume // and use its contents to override default bootConfig. // This is not a mandatory opeartion anymore. loadOverrideConfig(); // Load System com.apple.boot.plist config file loadSystemConfig(); #if virtualM || PCI_FIX // we can simply make an option for this fix addBootArg("npci=0x2000"); #endif #if verbose addBootArg("-v"); #endif // Use the kernel name specified by the user, or fetch the name // in the config table, or use the default if not specified. // Specifying a kernel name on the command line, or specifying // a non-default kernel name in the config file counts as // overriding the kernel, which causes the kernelcache not // to be used. safe_set_env(envgOverrideKernel,false); if (( kernel = extractKernelName((char **)&cp) )) { strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) ); safe_set_env(envgOverrideKernel,true); } else { if ( getValueForKey( kKernelNameKey, &val, &cnt, DEFAULT_BOOT_CONFIG ) ) { strlcpy( bootInfo->bootFile, val, sizeof(bootInfo->bootFile) ); if (strncmp( bootInfo->bootFile, kDefaultKernel, sizeof(kDefaultKernel) ) != 0) { safe_set_env(envgOverrideKernel,true); } } else if (((BVRef)(uint32_t)get_env(envgBootVolume))->kernelfound == true) { strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) ); } else { printf("No kernel found on this volume : hd(%d,%d)\n", BIOS_DEV_UNIT(((BVRef)(uint32_t)get_env(envgBootVolume))), ((BVRef)(uint32_t)get_env(envgBootVolume))->part_no); sleep(1); return -1; } } ArgCntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space argP = bootArgs->CommandLine; // Get config table kernel flags, if not ignored. if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey( kKernelFlagsKey, &val, &cnt, DEFAULT_BOOT_CONFIG )) { val = ""; cnt = 0; } configKernelFlags = newString(val); { bool isSafeMode = false; if (configKernelFlags) { isSafeMode = getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt); } if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && (isSafeMode == false)) { if (get_env(envgBootMode) & kBootModeSafe) { copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &ArgCntRemaining); } } } if (configKernelFlags) { // Store the merged kernel flags and boot args. cnt = strlen(configKernelFlags); if (cnt) { if (cnt > ArgCntRemaining) { printf("Warning: boot arguments too long, truncating\n"); cnt = ArgCntRemaining; } strncpy(argP, configKernelFlags, cnt); argP[cnt++] = ' '; ArgCntRemaining -= cnt; } } userCnt = strlen(cp); if (userCnt > ArgCntRemaining) { printf("Warning: boot arguments too long, truncating\n"); userCnt = ArgCntRemaining; } strncpy(&argP[cnt], cp, userCnt); argP[cnt+userCnt] = '\0'; if(!get_env(envShouldboot)) { bool gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, DEFAULT_BOOT_CONFIG ) || getValueForKey( kSingleUserModeFlag, &val, &cnt, DEFAULT_BOOT_CONFIG ); safe_set_env(envgVerboseMode, gVerboseMode); long gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, DEFAULT_BOOT_CONFIG ) ) ? kBootModeSafe : kBootModeNormal; safe_set_env(envgBootMode,gBootMode); if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, DEFAULT_BOOT_CONFIG ) ) { gBootMode = kBootModeSafe; safe_set_env(envgBootMode,gBootMode); } } if ( getValueForKey( kMKextCacheKey, &val, &cnt, DEFAULT_BOOT_CONFIG ) ) { char * MKextName = (char*)(uint32_t)get_env(envMKextName); strlcpy(MKextName,val,Cache_len_name); } if (configKernelFlags) { free(configKernelFlags); } safe_set_env(envArgCntRemaining,ArgCntRemaining); return 0; }
static int getNextFDiskPartition( int biosdev, int * partno, const struct fdisk_part ** outPart ) { static int sBiosdev = -1; static int sNextPartNo; static unsigned int sFirstBase; static unsigned int sExtBase; static unsigned int sExtDepth; static struct fdisk_part * sExtPart; struct fdisk_part * part; if ( sBiosdev != biosdev || *partno < 0 ) { // Fetch MBR. if ( readBootSector( biosdev, DISK_BLK0, 0 ) ) return 0; sBiosdev = biosdev; sNextPartNo = 0; sFirstBase = 0; sExtBase = 0; sExtDepth = 0; sExtPart = NULL; } while (1) { part = NULL; if ( sNextPartNo < FDISK_NPART ) { part = (struct fdisk_part *) gBootSector->parts[sNextPartNo]; } else if ( sExtPart ) { unsigned int blkno = sExtPart->relsect + sFirstBase; // Save the block offset of the first extended partition. if (sExtDepth == 0) { sFirstBase = blkno; } sExtBase = blkno; // Load extended partition table. if ( readBootSector( biosdev, blkno, 0 ) == 0 ) { sNextPartNo = 0; sExtDepth++; sExtPart = NULL; continue; } // Fall through to part == NULL } if ( part == NULL ) break; // Reached end of partition chain. // Advance to next partition number. sNextPartNo++; if ( isExtendedFDiskPartition(part) ) { sExtPart = part; continue; } // Skip empty slots. if ( part->systid == 0x00 ) { continue; } // Change relative offset to an absolute offset. part->relsect += sExtBase; *outPart = part; *partno = sExtDepth ? (int)(sExtDepth + FDISK_NPART) : sNextPartNo; break; } return (part != NULL); }
int processBootOptions() { const char * cp = gBootArgs; const char * val = 0; const char * kernel; int cnt; int userCnt; int cntRemaining; char * argP; char uuidStr[64]; BOOL uuidSet = NO; char * configKernelFlags; char * valueBuffer; valueBuffer = (char *)malloc(VALUE_SIZE); skipblanks( &cp ); // Update the unit and partition number. if ( gBootVolume ) { if ( gBootVolume->flags & kBVFlagForeignBoot ) { readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 ); // // Setup edx, and signal intention to chain load the // foreign booter. // chainbootdev = gBootVolume->biosdev; chainbootflag = 1; return 1; } bootInfo->kernDev &= ~((B_UNITMASK << B_UNITSHIFT ) | (B_PARTITIONMASK << B_PARTITIONSHIFT)); bootInfo->kernDev |= MAKEKERNDEV( 0, /* unit */ BIOS_DEV_UNIT(gBootVolume), /* partition */ gBootVolume->part_no ); } // Load config table specified by the user, or use the default. if (getValueForBootKey( cp, "config", &val, &cnt ) == FALSE) { val = 0; cnt = 0; } loadSystemConfig(val, cnt); if ( !sysConfigValid ) return -1; // Use the kernel name specified by the user, or fetch the name // in the config table, or use the default if not specified. // Specifying a kernel name on the command line, or specifying // a non-default kernel name in the config file counts as // overriding the kernel, which causes the kernelcache not // to be used. gOverrideKernel = NO; if (( kernel = extractKernelName((char **)&cp) )) { strcpy( bootInfo->bootFile, kernel ); gOverrideKernel = YES; } else { if ( getValueForKey( kKernelNameKey, &val, &cnt ) ) { strlcpy( bootInfo->bootFile, val, cnt+1 ); if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) { gOverrideKernel = YES; } } else { strcpy( bootInfo->bootFile, kDefaultKernel ); } } cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space argP = bootArgs->CommandLine; // Get config table kernel flags, if not ignored. if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) == TRUE || getValueForKey( kKernelFlagsKey, &val, &cnt ) == FALSE) { val = ""; cnt = 0; } configKernelFlags = (char *)malloc(cnt + 1); strlcpy(configKernelFlags, val, cnt + 1); if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) { // boot-uuid was set either on the command-line // or in the config file. uuidSet = YES; } else { if (GetFSUUID(bootInfo->bootFile, uuidStr) == 0) { verbose("Setting boot-uuid to: %s\n", uuidStr); copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining); uuidSet = YES; } } if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) { cnt = 0; if ( getValueForKey( kBootDeviceKey, &val, &cnt)) { valueBuffer[0] = '*'; cnt++; strlcpy(valueBuffer + 1, val, cnt); val = valueBuffer; } else { if (uuidSet) { val = "*uuid"; cnt = 5; } else { // Don't set "rd=.." if there is no boot device key // and no UUID. val = ""; cnt = 0; } } if (cnt > 0) { copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); } strlcpy( gRootDevice, val, (cnt + 1)); } if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) { getPlatformName(gPlatformName); copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); } if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) { if (gBootMode & kBootModeSafe) { copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); } } // Store the merged kernel flags and boot args. cnt = strlen(configKernelFlags); if (cnt) { if (cnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); cnt = cntRemaining; } strncpy(argP, configKernelFlags, cnt); argP[cnt++] = ' '; cntRemaining -= cnt; } userCnt = strlen(cp); if (userCnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); userCnt = cntRemaining; } strncpy(&argP[cnt], cp, userCnt); argP[cnt+userCnt] = '\0'; gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt ) || getValueForKey( kSingleUserModeFlag, &val, &cnt ); gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt ) ) ? kBootModeSafe : kBootModeNormal; if ( getValueForKey( kOldSafeModeFlag, &val, &cnt ) ) { gBootMode = kBootModeSafe; } if ( getValueForKey( kMKextCacheKey, &val, &cnt ) ) { strlcpy(gMKextName, val, cnt + 1); } free(configKernelFlags); free(valueBuffer); return 0; }
int processBootOptions() { const char * cp = gBootArgs; const char * val = 0; const char * kernel; int cnt; int userCnt; int cntRemaining; char * argP; skipblanks( &cp ); // Update the unit and partition number. if ( gBootVolume ) { if ( gBootVolume->flags & kBVFlagForeignBoot ) { readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 ); // // Setup edx, and signal intention to chain load the // foreign booter. // chainbootdev = gBootVolume->biosdev; chainbootflag = 1; return 1; } bootArgs->kernDev &= ~((B_UNITMASK << B_UNITSHIFT ) | (B_PARTITIONMASK << B_PARTITIONSHIFT)); bootArgs->kernDev |= MAKEKERNDEV( 0, /* unit */ BIOS_DEV_UNIT(gBootVolume), /* partition */ gBootVolume->part_no ); } // Load config table specified by the user, or use the default. if (getValueForBootKey( cp, "config", &val, &cnt ) == FALSE) { val = 0; cnt = 0; } loadSystemConfig(val, cnt); if ( !sysConfigValid ) return -1; // Use the kernel name specified by the user, or fetch the name // in the config table, or use the default if not specified. // Specifying a kernel name on the command line, or specifying // a non-default kernel name in the config file counts as // overriding the kernel, which causes the kernelcache not // to be used. gOverrideKernel = NO; if (( kernel = extractKernelName((char **)&cp) )) { strcpy( bootArgs->bootFile, kernel ); gOverrideKernel = YES; } else { if ( getValueForKey( kKernelNameKey, &val, &cnt ) ) { strlcpy( bootArgs->bootFile, val, cnt+1 ); if (strcmp( bootArgs->bootFile, kDefaultKernel ) != 0) { gOverrideKernel = YES; } } else { strcpy( bootArgs->bootFile, kDefaultKernel ); } } cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space // Check to see if we need to specify root device. // If user types "rd=.." on the boot line, it overrides // the boot device key in the boot arguments file. // argP = bootArgs->bootString; if ( getValueForBootKey( cp, kRootDeviceKey, &val, &cnt ) == FALSE && getValueForKey( kRootDeviceKey, &val, &cnt ) == FALSE ) { if ( getValueForKey( kBootDeviceKey, &val, &cnt ) ) { strcpy( argP, "rd=*" ); argP += 4; strlcpy( argP, val, cnt+1); cntRemaining -= cnt; argP += cnt; *argP++ = ' '; } } // Check to see if we should ignore saved kernel flags. if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) == FALSE) { if (getValueForKey( kKernelFlagsKey, &val, &cnt ) == FALSE) { val = 0; cnt = 0; } } // Store the merged kernel flags and boot args. if (cnt > cntRemaining) { error("Warning: boot arguments too long, truncated\n"); cnt = cntRemaining; } if (cnt) { strncpy(argP, val, cnt); argP[cnt++] = ' '; } cntRemaining = cntRemaining - cnt; userCnt = strlen(cp); if (userCnt > cntRemaining) { error("Warning: boot arguments too long, truncated\n"); userCnt = cntRemaining; } strncpy(&argP[cnt], cp, userCnt); argP[cnt+userCnt] = '\0'; gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt ) || getValueForKey( kSingleUserModeFlag, &val, &cnt ); gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt ) ) ? kBootModeSafe : kBootModeNormal; if ( getValueForKey( kPlatformKey, &val, &cnt ) ) { strlcpy(gPlatformName, val, cnt + 1); } else { strcpy(gPlatformName, "ACPI"); } if ( getValueForKey( kMKextCacheKey, &val, &cnt ) ) { strlcpy(gMKextName, val, cnt + 1); } return 0; }
INT_PTR CALLBACK Dialog1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); PostQuitMessage(0); return (INT_PTR)TRUE; } switch (LOWORD(wParam)) { case IDC_VOLUME_INFO: { mBootSector mbs; //HWND val = GetDlgItem(hDlg, IDC_EDIT_VOLUME); //TCHAR temp[1024]; //char ctemp[1024]; /*GetDlgItemText(hDlg, IDC_EDIT_VOLUME, temp, 1024); for (int i = 0; i < lstrlen(temp); ++i) ctemp[i] = temp[i]; ctemp[lstrlen(temp)] = 0;*/ char vol[1024]; getVolumeName(hDlg, vol); if (readBootSector(vol, mbs)) { writeBootSectorToLog(mbs); CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)showLog, 0, 0, NULL); } else MessageBox(hDlg, L"Cannot open volume", L"Error", MB_OK); //system("notepad log.txt"); break; } case IDC_DRIVE_INFO: { mMBR mbr; //HWND val = GetDlgItem(hDlg, IDC_EDIT_PHYSICAL_DRIVE); int driveNumber;// = GetDlgItemInt(hDlg, IDC_EDIT_PHYSICAL_DRIVE, 0, false);//get getPhysicalNumber(hDlg, driveNumber); if (readMBR(driveNumber, mbr)) { writeMBRtoLog(mbr); CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)showLog, 0, 0, NULL); } else MessageBox(hDlg, L"Cannot open drive", L"Error", MB_OK); //system("notepad log.txt"); break; } case IDC_IMAGE_PHYDRIVE: { int num; char path[1024], dest[1024]; getPhysicalNumber(hDlg, num); getPathPhysicalDrive(num, path); srcdest* temp = new srcdest; temp->src = std::string(path); saveFile(hDlg, dest); temp->dest = std::string(dest); CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)makeImage, temp, 0, NULL); //CreateImage(path, "temp.img", NULL); break; } case IDC_IMAGE_VOLUME: { char vol[1024]; char path[1024], dest[1024]; getVolumeName(hDlg, vol); getPathVolume(vol, path); srcdest* temp = new srcdest; temp->src = std::string(path); saveFile(hDlg, dest); temp->dest = std::string(dest); CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)makeImage, temp, 0, NULL); //CreateImage(path, "temp.img", NULL); break; } default: return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }