void convert_gvirt_to_gphys(long gvirt, long * gphys){ struct memdump_data data; memset(&data, 0, sizeof(struct memdump_data)); data.virtaddr = gvirt; int i, r; u64 ent[5]; int levels; u64 physaddr; memset(ent, 0, sizeof(ent)); get_control_regs((ulong *)&data.cr0, (ulong *)&data.cr3, (ulong *)&data.cr4, &data.efer); r = cpu_mmu_get_pte(data.virtaddr, (ulong)data.cr0, (ulong)data.cr3, (ulong)data.cr4, data.efer, true, false, false, ent, &levels); if (r == 0) { physaddr = (ent[0] & PTE_ADDR_MASK64) | ((data.virtaddr) & 0xFFF); *gphys = physaddr; } else{ printf("error!: r = %d\n", r); } }
int memdump_gvirt(struct memdump_data * dumpdata, void * value){ long gvirt = 0xffffffff81c0e000ULL - (0xffffffff81000000ULL - 0x0000000001000000ULL); struct memdump_data * data = dumpdata; int i, r; u64 ent[5]; int levels; u64 physaddr; int width = 8; char str[width]; memset(ent, 0, sizeof(ent)); get_control_regs((ulong *)&data->cr0, (ulong *)&data->cr3, (ulong *)&data->cr4, &data->efer); for (i = 0; i < data->sendlen; i += width) { r = cpu_mmu_get_pte(data->virtaddr+i, (ulong)data->cr0, (ulong)data->cr3, (ulong)data->cr4, data->efer, true, false, false, ent, &levels); if (r == VMMERR_SUCCESS) { physaddr = (ent[0] & PTE_ADDR_MASK64) | ((data->virtaddr+i) & 0xFFF); read_hphys_q(physaddr, str, 0); memcpy(value+i, str, width); printhex(str, width, physaddr); memset(str, 0, width); } else{ printf("error: r = %d\n", r); break; } } return r; }
char * read_str_va(u64 vaddr) { char * ret_val = NULL; char * ret_val1 = NULL; ret_val = (char *)alloc(24 * sizeof(char)); ret_val1 = (char *)alloc(24 * sizeof(char)); u64 x= 0x0ULL, y=0x0ULL, z=0x0ULL; struct memdump_data data; u64 ent[5]; int i, r, levels; memset(ent, 0, sizeof(ent)); memset(&data, 0, sizeof(struct memdump_data)); data.virtaddr = vaddr; get_control_regs((ulong *)&data.cr0, (ulong *)&data.cr3, (ulong *)&data.cr4, &data.efer); r = cpu_mmu_get_pte(data.virtaddr, (ulong)data.cr0, (ulong)data.cr3, (ulong)data.cr4, data.efer, false, false, false, ent, &levels); // printf("[%s r=%d 0x%016llx]\n", __func__, r, vaddr); int c=0; // parport_pcpc if (r == VMMERR_SUCCESS) { data.physaddr = (ent[0] & PTE_ADDR_MASK64) | ((data.virtaddr) & 0xFFF); read_hphys_q(data.physaddr, &x, 0); read_hphys_q(data.physaddr+8, &y, 0); read_hphys_q(data.physaddr+16, &z, 0); for(i=0;i<8;i++) { int t=x&0xff; // if (t==0) { // break; // } // printf("%c", t); ret_val[c++] = t; x=x>>8; } //printf("\t\t\t\t%lx\t\t\t\t\t",y); for(i=0;i<8;i++) { int t=y&0xff; // if (t==0) { // break; // } // printf("%c", t); ret_val[c++] = t; y=y>>8; } for(i=0;i<8;i++) { int t=z&0xff; // if (t==0) { // break; // } // printf("%c", t); ret_val[c++] = t; z=z>>8; } }
int virt_memcpy(ulong virtaddr, int nr_bytes, void * value){ struct memdump_data data; u64 ent[5]; int r, levels; memset(ent, 0, sizeof(ent)); memset(&data, 0, sizeof(struct memdump_data)); data.virtaddr = virtaddr; get_control_regs((ulong *)&data.cr0, (ulong *)&data.cr3, (ulong *)&data.cr4, &data.efer); r = cpu_mmu_get_pte(data.virtaddr, (ulong)data.cr0, (ulong)data.cr3, (ulong)data.cr4, data.efer, false, false, false, ent, &levels); if (r == VMMERR_SUCCESS) { data.physaddr = (ent[0] & PTE_ADDR_MASK64) | ((data.virtaddr) & 0xFFF); if(nr_bytes == 4) { read_hphys_l(data.physaddr, value, 0); } if(nr_bytes == 8) { read_hphys_q(data.physaddr, value, 0); } return 0; } return -1; }