status_t read_config_file( vmi_instance_t vmi, FILE* config_file) { status_t ret = VMI_SUCCESS; yyin = config_file; if (vmi_parse_config(vmi->image_type) != 0) { errprint("Failed to read config file.\n"); ret = VMI_FAILURE; goto error_exit; } vmi->config = vmi_get_config(); if (vmi->config == NULL) { errprint("No entry in config file for %s.\n", vmi->image_type); ret = VMI_FAILURE; goto error_exit; } else { ret = VMI_SUCCESS; } #ifdef VMI_DEBUG if (vmi->os_type == VMI_OS_LINUX) { dbprint(VMI_DEBUG_CORE, "**set os_type to Linux.\n"); } else if (vmi->os_type == VMI_OS_WINDOWS) { dbprint(VMI_DEBUG_CORE, "**set os_type to Windows.\n"); } else { dbprint(VMI_DEBUG_CORE, "**set os_type to unknown.\n"); } #endif error_exit: if (config_file) fclose(config_file); return ret; }
status_t read_config_file( vmi_instance_t vmi) { status_t ret = VMI_SUCCESS; vmi_config_entry_t *entry; char *configstr = (char *)vmi->config; char *tmp = NULL; yyin = NULL; if (configstr) { yyin = fmemopen(configstr, strlen(configstr), "r"); } if (NULL == yyin) { yyin = open_config_file(); if (NULL == yyin) { fprintf(stderr, "ERROR: config file not found.\n"); ret = VMI_FAILURE; goto error_exit; } } if (vmi_parse_config(vmi->image_type) != 0) { errprint("Failed to read config file.\n"); ret = VMI_FAILURE; goto error_exit; } entry = vmi_get_config(); /* copy the values from entry into instance struct */ vmi->sysmap = strdup(entry->sysmap); dbprint("--got sysmap from config (%s).\n", vmi->sysmap); if (strncmp(entry->ostype, "Linux", CONFIG_STR_LENGTH) == 0) { vmi->os_type = VMI_OS_LINUX; } else if (strncmp(entry->ostype, "Windows", CONFIG_STR_LENGTH) == 0) { vmi->os_type = VMI_OS_WINDOWS; } else { errprint("Unknown or undefined OS type.\n"); ret = VMI_FAILURE; goto error_exit; } /* Copy config info based on OS type */ if (VMI_OS_LINUX == vmi->os_type) { dbprint("--reading in linux offsets from config file.\n"); if (entry->offsets.linux_offsets.tasks) { vmi->os.linux_instance.tasks_offset = entry->offsets.linux_offsets.tasks; } if (entry->offsets.linux_offsets.mm) { vmi->os.linux_instance.mm_offset = entry->offsets.linux_offsets.mm; } if (entry->offsets.linux_offsets.pid) { vmi->os.linux_instance.pid_offset = entry->offsets.linux_offsets.pid; } if (entry->offsets.linux_offsets.name) { vmi->os.linux_instance.name_offset = entry->offsets.linux_offsets.name; } if (entry->offsets.linux_offsets.pgd) { vmi->os.linux_instance.pgd_offset = entry->offsets.linux_offsets.pgd; } } else if (VMI_OS_WINDOWS == vmi->os_type) { dbprint("--reading in windows offsets from config file.\n"); if (entry->offsets.windows_offsets.ntoskrnl) { vmi->os.windows_instance.ntoskrnl = entry->offsets.windows_offsets.ntoskrnl; } if (entry->offsets.windows_offsets.tasks) { vmi->os.windows_instance.tasks_offset = entry->offsets.windows_offsets.tasks; } if (entry->offsets.windows_offsets.pdbase) { vmi->os.windows_instance.pdbase_offset = entry->offsets.windows_offsets.pdbase; } if (entry->offsets.windows_offsets.pid) { vmi->os.windows_instance.pid_offset = entry->offsets.windows_offsets.pid; } if (entry->offsets.windows_offsets.pname) { vmi->os.windows_instance.pname_offset = entry->offsets.windows_offsets.pname; } if (entry->offsets.windows_offsets.kdvb) { vmi->os.windows_instance.kdversion_block = entry->offsets.windows_offsets.kdvb; } if (entry->offsets.windows_offsets.sysproc) { vmi->os.windows_instance.sysproc = entry->offsets.windows_offsets.sysproc; } } #ifdef VMI_DEBUG dbprint("--got ostype from config (%s).\n", entry->ostype); if (vmi->os_type == VMI_OS_LINUX) { dbprint("**set os_type to Linux.\n"); } else if (vmi->os_type == VMI_OS_WINDOWS) { dbprint("**set os_type to Windows.\n"); } else { dbprint("**set os_type to unknown.\n"); } #endif error_exit: if (tmp) free(tmp); if (yyin) fclose(yyin); return ret; }