Accessing Invalid Address
Considerations for accessing memory in different modes
Accessing memory could be challenging depending on the fact that HyperDbg tries to access memory from VMX-root mode. Generally, if you see the following error in HyperDbg, this page is to help you fix this problem.
As the code implies, HyperDbg couldn't determine whether the address is valid or invalid. It typically happens when the address may be paged out or unavailable on the page table due to 'demand paging' and since HyperDbg could not perform paging in the VMX-root mode, it throws this error.
Thus, two situations might happen here.
First, the address is invalid!
If the address is not valid and not allocated by OS, surely you cannot put a hook on it or view its content.
Second, the address is actually valid but still, we get this error.
Some addresses might not be available on the RAM (paged out by the operating system) or the operating system did not allocate a physical memory for the address as it brings the page into the RAM only when an attempt is made to access it.
Another scenario is that the page is already in the RAM but from the current view of the process (based on the current CR3 register), it is not present in the page-table. For example, the address might be located in the 'kernel32' or 'ntdll' memory but since the current process never accessed some of the functions (pages) it is not present based on their paging base of the memory.
In the second scenario, you have two options forcing the operating system to bring the page into the memory or make it present in both VMI Mode and the Debugger Mode.
Access invalid address from VMI Mode
In this mode, virtual memory reading commands like db, dc, dd, and dq or assembler commands like u, and u2, all access the memory from VMX non-root mode. This means that accessing the memory will trigger a page-fault and if the address is actually valid, the OS either brings it to the RAM or makes it present to the process.
For example, assume that we want to apply the following EPT hook (e.g., by using the '!epthook').
If you access this function directly using the memory access commands or assembler commands,
or
Then when you run your EPT hook again, the address is valid this time!
Access invalid address from Debugger Mode
If you are in the debugger mode, the debuggee cannot switch between processes. At this point, you can use the '.pagein' command to inject a page-fault (#PF) and force the operating system to bring the page into the memory or make it present in the paging tables of the current process.
In order to bring it to the memory, run the following command:
Once you run the 'g' command the OS finds a chance to bring the page into the memory or make it present in the memory and it immediately pauses the debuggee again, then you can apply your EPT hook.
Please remember that these techniques only apply when the address is actually valid, if the address is not allocated and invalid, then it does not make sense to access them!
Please note that technically, you could use the '.pagein' command on a large range of memory. However, in large memory ranges, there are often page entries that are already valid (paged in or never paged out by the OS). In those cases, if you bring them into memory (force the OS to page them in) using the '.pagein' command, it will disrupt the OS semantics. This command injects a #PF (page fault) into the OS, and if the address is already valid, the operating system does not expect to receive a page fault for an available page, which might or will cause a triple fault and consequently a system restart or crash.
Last updated