﻿{"id":793,"date":"2012-02-02T17:27:20","date_gmt":"2012-02-02T09:27:20","guid":{"rendered":"http:\/\/notes.zerobox.org\/?p=793"},"modified":"2012-02-02T17:27:20","modified_gmt":"2012-02-02T09:27:20","slug":"%e6%a0%87%e5%87%86mdl%e6%96%b9%e6%b3%95%e4%bf%ae%e6%94%b9page%e3%80%81nonpage%e5%86%85%e5%ad%98%e7%9a%84%e5%b1%9e%e6%80%a7","status":"publish","type":"post","link":"http:\/\/zerobox.org\/notes\/793.html","title":{"rendered":"\u6807\u51c6MDL\u65b9\u6cd5\u4fee\u6539Page\u3001NonPage\u5185\u5b58\u7684\u5c5e\u6027~"},"content":{"rendered":"<p>\u6765\u6e90\uff1a<a href=\"http:\/\/hi.baidu.com\/%E5%8F%AB%E6%88%91v%E6%A0%A1\/blog\/item\/018a6000e7f80b1d738da5f6.html\">http:\/\/hi.baidu.com\/%E5%8F%AB%E6%88%91v%E6%A0%A1\/blog\/item\/018a6000e7f80b1d738da5f6.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>typedef struct _REPROTECT_CONTEXT<br \/>\n{<br \/>\nPMDL\u00a0\u00a0 Mdl;<br \/>\nPUCHAR LockedVa;<br \/>\n} REPROTECT_CONTEXT, * PREPROTECT_CONTEXT;<\/p>\n<p>&nbsp;<\/p>\n<p>NTSTATUS<br \/>\nMmLockVaForWrite(<br \/>\n__in PVOID Va,<br \/>\n__in ULONG Length,<br \/>\n__out PREPROTECT_CONTEXT ReprotectContext<br \/>\n)<br \/>\n{<br \/>\nNTSTATUS Status;<\/p>\n<p>Status = STATUS_SUCCESS;<\/p>\n<p>ReprotectContext-&gt;Mdl\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;<br \/>\nReprotectContext-&gt;LockedVa = 0;<\/p>\n<p>ReprotectContext-&gt;Mdl = IoAllocateMdl(<br \/>\nVa,<br \/>\nLength,<br \/>\nFALSE,<br \/>\nFALSE,<br \/>\n0<br \/>\n);<\/p>\n<p>if (!ReprotectContext-&gt;Mdl)<br \/>\n{<br \/>\nreturn STATUS_INSUFFICIENT_RESOURCES;<br \/>\n}<\/p>\n<p>\/\/<br \/>\n\/\/ Retrieve a locked VA mapping.<br \/>\n\/\/<\/p>\n<p>__try<br \/>\n{<br \/>\nMmProbeAndLockPages(<br \/>\nReprotectContext-&gt;Mdl,<br \/>\nKernelMode,<br \/>\nIoModifyAccess<br \/>\n);<br \/>\n}<br \/>\n__except (EXCEPTION_EXECUTE_HANDLER)<br \/>\n{<br \/>\nreturn GetExceptionCode();<br \/>\n}<\/p>\n<p>ReprotectContext-&gt;LockedVa = (PUCHAR)MmMapLockedPagesSpecifyCache(<br \/>\nReprotectContext-&gt;Mdl,<br \/>\nKernelMode,<br \/>\nMmCached,<br \/>\n0,<br \/>\nFALSE,<br \/>\nNormalPagePriority<br \/>\n);<\/p>\n<p>if (!ReprotectContext-&gt;LockedVa)<br \/>\n{<\/p>\n<p>IoFreeMdl(<br \/>\nReprotectContext-&gt;Mdl<br \/>\n);<\/p>\n<p>ReprotectContext-&gt;Mdl = 0;<\/p>\n<p>return STATUS_ACCESS_VIOLATION;<br \/>\n}<\/p>\n<p>\/\/<br \/>\n\/\/ Reprotect.<br \/>\n\/\/<\/p>\n<p>Status = MmProtectMdlSystemAddress(<br \/>\nReprotectContext-&gt;Mdl,<br \/>\nPAGE_EXECUTE_READWRITE<br \/>\n);<\/p>\n<p>if (!NT_SUCCESS(Status))<br \/>\n{<\/p>\n<p>MmUnmapLockedPages(<br \/>\nReprotectContext-&gt;LockedVa,<br \/>\nReprotectContext-&gt;Mdl<br \/>\n);<br \/>\nMmUnlockPages(<br \/>\nReprotectContext-&gt;Mdl<br \/>\n);<br \/>\nIoFreeMdl(<br \/>\nReprotectContext-&gt;Mdl<br \/>\n);<\/p>\n<p>ReprotectContext-&gt;LockedVa = 0;<br \/>\nReprotectContext-&gt;Mdl\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;<br \/>\n}<\/p>\n<p>return Status;<br \/>\n}<\/p>\n<p>NTSTATUS<br \/>\nMmUnlockVaForWrite(<br \/>\n__in PREPROTECT_CONTEXT ReprotectContext<br \/>\n)<br \/>\n{<br \/>\nif (ReprotectContext-&gt;LockedVa)<br \/>\n{<br \/>\nMmUnmapLockedPages(<br \/>\nReprotectContext-&gt;LockedVa,<br \/>\nReprotectContext-&gt;Mdl<br \/>\n);<br \/>\nMmUnlockPages(<br \/>\nReprotectContext-&gt;Mdl<br \/>\n);<br \/>\nIoFreeMdl(<br \/>\nReprotectContext-&gt;Mdl<br \/>\n);<\/p>\n<p>ReprotectContext-&gt;LockedVa = 0;<br \/>\nReprotectContext-&gt;Mdl\u00a0\u00a0\u00a0\u00a0\u00a0 = 0;<br \/>\n}<\/p>\n<p>return STATUS_SUCCESS;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u6e90\uff1ahttp:\/\/hi.baidu.com\/%E5%8F%AB%E6%88%9 &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/zerobox.org\/notes\/793.html\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[188],"class_list":["post-793","post","type-post","status-publish","format-standard","hentry","tag-mdl"],"views":935,"_links":{"self":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/comments?post=793"}],"version-history":[{"count":0,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/793\/revisions"}],"wp:attachment":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media?parent=793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/categories?post=793"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/tags?post=793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}