static status_t linux_system_map_symbol_to_address( vmi_instance_t vmi, const char *symbol, addr_t *address) { FILE *f = NULL; char *row = NULL; status_t ret = VMI_FAILURE; linux_instance_t linux_instance = vmi->os_data; if (linux_instance == NULL) { errprint("VMI_ERROR: OS instance not initialized\n"); goto done; } if ((NULL == linux_instance->sysmap) || (strlen(linux_instance->sysmap) == 0)) { errprint("VMI_WARNING: No linux sysmap configured\n"); goto done; } row = g_malloc0(MAX_ROW_LENGTH); if ( !row ) goto done; if ((f = fopen(linux_instance->sysmap, "r")) == NULL) { fprintf(stderr, "ERROR: could not find System.map file after checking:\n"); fprintf(stderr, "\t%s\n", linux_instance->sysmap); fprintf(stderr, "To fix this problem, add the correct sysmap entry to /etc/libvmi.conf\n"); address = 0; goto done; } if (get_symbol_row(f, row, symbol, 2) == VMI_FAILURE) { address = 0; goto done; } (*address) = (addr_t) strtoull(row, NULL, 16); ret = VMI_SUCCESS; done: if (row) free(row); if (f) fclose(f); return ret; }
int linux_system_map_symbol_to_address ( xa_instance_t *instance, char *symbol, uint32_t *address) { FILE *f = NULL; char *row = NULL; int ret = XA_SUCCESS; if ((NULL == instance->sysmap) || (strlen(instance->sysmap) == 0)){ #ifdef ENABLE_XEN instance->sysmap = linux_predict_sysmap_name(instance->m.xen.domain_id); #endif /* ENABLE_XEN */ } if ((row = malloc(MAX_ROW_LENGTH)) == NULL ){ ret = XA_FAILURE; goto error_exit; } if ((f = fopen(instance->sysmap, "r")) == NULL){ fprintf(stderr, "ERROR: could not find System.map file after checking:\n"); fprintf(stderr, "\t%s\n", instance->sysmap); fprintf(stderr, "To fix this problem, add the correct sysmap entry to /etc/xenaccess.conf\n"); ret = XA_FAILURE; goto error_exit; } if (get_symbol_row(f, row, symbol, 2) == XA_FAILURE){ ret = XA_FAILURE; goto error_exit; } *address = (uint32_t) strtoul(row, NULL, 16); error_exit: if (row) free(row); if (f) fclose(f); return ret; }
char* linux_system_map_address_to_symbol( vmi_instance_t vmi, addr_t address, const access_context_t *ctx) { FILE *f = NULL; char *row = NULL; char* address_str = NULL; char* it = NULL; char* symbol = NULL; int size = 0; linux_instance_t linux_instance = vmi->os_data; #ifdef ENABLE_SAFETY_CHECKS if (!linux_instance) { errprint("VMI_ERROR: OS instance not initialized\n"); goto done; } #endif address -= linux_instance->kaslr_offset; switch (ctx->translate_mechanism) { case VMI_TM_PROCESS_PID: if (ctx->pid != 0) goto err; break; case VMI_TM_PROCESS_DTB: if (ctx->dtb != vmi->kpgd) goto err; break; default: goto err; }; if ((NULL == linux_instance->sysmap) || (strlen(linux_instance->sysmap) == 0)) { errprint("VMI_WARNING: No linux sysmap configured\n"); goto done; } row = g_malloc0(MAX_ROW_LENGTH); if ( !row ) goto done; if ((f = fopen(linux_instance->sysmap, "r")) == NULL) { fprintf(stderr, "ERROR: could not find System.map file after checking:\n"); fprintf(stderr, "\t%s\n", linux_instance->sysmap); fprintf(stderr, "To fix this problem, add the correct sysmap entry to /etc/libvmi.conf\n"); goto done; } size = snprintf(NULL,0,"%"PRIx64"", address) + 1; address_str = g_malloc0(size); snprintf(address_str, size, "%"PRIx64"", address); if (get_symbol_row(f, row, address_str, 0) == VMI_FAILURE) { goto done; } // skip two columns for (it=row; *it!=0; it++); for (it++; *it!=0; it++); it++; symbol = strdup(it); done: if (row) free(row); if (f) fclose(f); if (address_str) free(address_str); return symbol; err: errprint("VMI_WARNING: Lookup is implemented for kernel symbols only\n"); return NULL; }