Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you looked at creating your own private heap via <a href="http://msdn.microsoft.com/en-us/library/aa366599%28VS.85%29.aspx" rel="nofollow noreferrer"><code>HeapCreate</code></a>? You could set the heap to your desired buffer size. The only remaining problem is then how to get <code>MapViewOfFile</code>to use your private heap instead of the default heap. </p> <p>I'd assume that <code>MapViewOfFile</code> internally calls <code>GetProcessHeap</code> to get the default heap and then it requests a contiguous block of memory. You can surround the call to <code>MapViewOfFile</code> with a detour, i.e., you rewire the <code>GetProcessHeap</code> call by overwriting the method in memory effectively inserting a jump to your own code which can return your private heap. </p> <p>Microsoft has published the <a href="http://research.microsoft.com/en-us/projects/detours/" rel="nofollow noreferrer">Detour Library</a> that I'm not directly familiar with however. I know that detouring is surprisingly common. Security software, virus scanners etc all use such frameworks. It's not pretty, but may work:</p> <pre><code>HANDLE g_hndPrivateHeap; HANDLE WINAPI GetProcessHeapImpl() { return g_hndPrivateHeap; } struct SDetourGetProcessHeap { // object for exception safety SDetourGetProcessHeap() { // put detour in place } ~SDetourGetProcessHeap() { // remove detour again } }; void MapFile() { g_hndPrivateHeap = HeapCreate( ... ); { SDetourGetProcessHeap d; MapViewOfFile(...); } } </code></pre> <p>These may also help:</p> <p><a href="https://stackoverflow.com/questions/60641/how-to-replace-winapi-functions-calls-in-the-ms-vc-project-with-my-own-implemen">How to replace WinAPI functions calls in the MS VC++ project with my own implementation (name and parameters set are the same)?</a></p> <p><a href="https://stackoverflow.com/questions/873658/how-can-i-hook-windows-functions-in-c-c">How can I hook Windows functions in C/C++?</a></p> <p><a href="http://research.microsoft.com/pubs/68568/huntusenixnt99.pdf" rel="nofollow noreferrer">http://research.microsoft.com/pubs/68568/huntusenixnt99.pdf</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload