kernel_hack icon indicating copy to clipboard operation
kernel_hack copied to clipboard

fix*

Open Jiang-Night opened this issue 2 years ago • 0 comments

bool read_process_memory(pid_t pid, uintptr_t addr, void *buffer, size_t size) { struct task_struct *task; struct mm_struct *mm; struct pid *pid_struct; phys_addr_t pa;

pid_struct = find_get_pid(pid);
if (!pid_struct) {
	return false;
}
task = get_pid_task(pid_struct, PIDTYPE_PID);
if (!task) {
	return false;
}
mm = get_task_mm(task);
if (!mm) {
	return false;
}
mmput(mm);

while (size > 0) {
	//当前页剩余字节
	int diff = addr % PAGE_SIZE == 0 ? PAGE_SIZE :
					   PAGE_SIZE - addr % PAGE_SIZE;

	if (size < diff) {
		diff = size;
	}

	pa = translate_linear_address(mm, addr);
	if (!pa) {
		return false;
	}
	if (!read_physical_address(pa, buffer, diff)) {
		return false;
	}
	size -= diff;
	addr += diff;
	buffer += diff;
}
return true;

}

Jiang-Night avatar Feb 04 '23 22:02 Jiang-Night