int main (int argc, char **argv) { vmi_instance_t vmi; char *memory = (char *) malloc(PAGE_SIZE); /* this is the VM or file that we are looking at */ char *name = argv[1]; /* this is the symbol to map */ char *symbol = argv[2]; /* initialize the libvmi library */ if (vmi_init(&vmi, VMI_AUTO | VMI_INIT_COMPLETE, name) == VMI_FAILURE){ printf("Failed to init LibVMI library.\n"); goto error_exit; } /* get memory starting at symbol for the next PAGE_SIZE bytes */ if (PAGE_SIZE != vmi_read_ksym(vmi, symbol, memory, PAGE_SIZE)){ printf("failed to get symbol's memory.\n"); goto error_exit; } vmi_print_hex(memory, PAGE_SIZE); error_exit: if (memory) free(memory); /* cleanup any memory associated with the libvmi instance */ vmi_destroy(vmi); return 0; }
int main( int argc, char **argv) { if ( argc != 3 ) return 1; vmi_instance_t vmi; unsigned char *memory = malloc(PAGE_SIZE); /* this is the VM or file that we are looking at */ char *name = argv[1]; /* this is the address to map */ char *addr_str = argv[2]; addr_t addr = (addr_t) strtoul(addr_str, NULL, 16); /* initialize the libvmi library */ if (VMI_FAILURE == vmi_init_complete(&vmi, name, VMI_INIT_DOMAINNAME, NULL, VMI_CONFIG_GLOBAL_FILE_ENTRY, NULL, NULL)) { printf("Failed to init LibVMI library.\n"); goto error_exit; } /* get the symbol's memory page */ if (VMI_FAILURE == vmi_read_va(vmi, addr, 0, PAGE_SIZE, memory, NULL)) { printf("failed to map memory.\n"); goto error_exit; } vmi_print_hex(memory, PAGE_SIZE); error_exit: if (memory) free(memory); /* cleanup any memory associated with the libvmi instance */ vmi_destroy(vmi); return 0; }