The right way to implement this is to use workarounds and a separate tool that works in its own process. The procedure looks something like this:
- Create memory allocation in a remote process.
- Put the code for the small loader that will load your DLL.
- Call the
CreateRemoteThread API, which will launch your bootloader. - Inside the loaded dll, workarounds (interceptors, interceptors) are set to the alloc / dealloc function.
- Handle calls, track activity.
If you implement your tool in this way, it will not matter from which DLL or directly from exe the memory allocation procedure is called. In addition, you can track actions from any process, it is not necessary that you compiled yourself.
MS Windows allows checking the contents of the virtual address space of a remote process. You can summarize the use of the virtual address space, which was thus collected in a histogram, as shown below:

In this picture you can see how many virtual distributions of what size exist in your target process.

The figure above shows an overview of the use of virtual address space in 32-bit MSVC DevEnv. The blue bar means the comma part of the emory, the magenta bar is reserved. Green is an unallocated part of the address space.
You can see that the lower addresses are quite fragmented, but the middle area is not. Blue lines at high addresses are various DLLs that are loaded into the process.
source share