• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-60  評論-111  文章-0  trackbacks-0

             

              1 NTSTATUS
              2 NTAPI
              3 NtProtectVirtualMemory(IN HANDLE ProcessHandle,
              4                        IN OUT PVOID *UnsafeBaseAddress,
              5                        IN OUT SIZE_T *UnsafeNumberOfBytesToProtect,
              6                        IN ULONG NewAccessProtection,
              7                        OUT PULONG UnsafeOldAccessProtection)
              8 {
              9     PEPROCESS Process;
             10     ULONG OldAccessProtection;
             11     ULONG Protection;
             12     PEPROCESS CurrentProcess = PsGetCurrentProcess();
             13     PVOID BaseAddress = NULL;
             14     SIZE_T NumberOfBytesToProtect = 0;
             15     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
             16     NTSTATUS Status;
             17     BOOLEAN Attached = FALSE;
             18     KAPC_STATE ApcState;
             19     PAGED_CODE();
             20 
             21     //
             22     // Check for valid protection flags
             23     //
             24     Protection = NewAccessProtection & ~(PAGE_GUARD|PAGE_NOCACHE);
             25     if (Protection != PAGE_NOACCESS &&
             26         Protection != PAGE_READONLY &&
             27         Protection != PAGE_READWRITE &&
             28         Protection != PAGE_WRITECOPY &&
             29         Protection != PAGE_EXECUTE &&
             30         Protection != PAGE_EXECUTE_READ &&
             31         Protection != PAGE_EXECUTE_READWRITE &&
             32         Protection != PAGE_EXECUTE_WRITECOPY)
             33     {
             34         //
             35         // Fail
             36         //
             37         return STATUS_INVALID_PAGE_PROTECTION;
             38     }
             39 
             40     //
             41     // Check if we came from user mode
             42     //
             43     if (PreviousMode != KernelMode)
             44     {
             45         //
             46         // Enter SEH for probing
             47         //
             48         _SEH2_TRY
             49         {
             50             //
             51             // Validate all outputs
             52             //
             53             ProbeForWritePointer(UnsafeBaseAddress);
             54             ProbeForWriteSize_t(UnsafeNumberOfBytesToProtect);
             55             ProbeForWriteUlong(UnsafeOldAccessProtection);
             56 
             57             //
             58             // Capture them
             59             //
             60             BaseAddress = *UnsafeBaseAddress;
             61             NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect;
             62         }
             63         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
             64         {
             65             //
             66             // Get exception code
             67             //
             68             _SEH2_YIELD(return _SEH2_GetExceptionCode());
             69         }
             70         _SEH2_END;
             71     }
             72     else
             73     {
             74         //
             75         // Capture directly
             76         //
             77         BaseAddress = *UnsafeBaseAddress;
             78         NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect;
             79     }
             80 
             81     //
             82     // Catch illegal base address
             83     //
             84     if (BaseAddress > MM_HIGHEST_USER_ADDRESS) return STATUS_INVALID_PARAMETER_2;
             85 
             86     //
             87     // Catch illegal region size
             88     //
             89     if ((MmUserProbeAddress - (ULONG_PTR)BaseAddress) < NumberOfBytesToProtect)
             90     {
             91         //
             92         // Fail
             93         //
             94         return STATUS_INVALID_PARAMETER_3;
             95     }
             96 
             97     //
             98     // 0 is also illegal
             99     //
            100     if (!NumberOfBytesToProtect) return STATUS_INVALID_PARAMETER_3;
            101 
            102     //
            103     // Get a reference to the process
            104     //
            105     Status = ObReferenceObjectByHandle(ProcessHandle,
            106                                        PROCESS_VM_OPERATION,
            107                                        PsProcessType,
            108                                        PreviousMode,
            109                                        (PVOID*)(&Process),
            110                                        NULL);
            111     if (!NT_SUCCESS(Status)) return Status;
            112 
            113     //
            114     // Check if we should attach
            115     //
            116     if (CurrentProcess != Process)
            117     {
            118         //
            119         // Do it
            120         //
            121         KeStackAttachProcess(&Process->Pcb, &ApcState);
            122         Attached = TRUE;
            123     }
            124 
            125     //
            126     // Do the actual work
            127     //
            128     Status = MiProtectVirtualMemory(Process,
            129                                     &BaseAddress,
            130                                     &NumberOfBytesToProtect,
            131                                     NewAccessProtection,
            132                                     &OldAccessProtection);
            133 
            134     //
            135     // Detach if needed
            136     //
            137     if (Attached) KeUnstackDetachProcess(&ApcState);
            138 
            139     //
            140     // Release reference
            141     //
            142     ObDereferenceObject(Process);
            143 
            144     //
            145     // Enter SEH to return data
            146     //
            147     _SEH2_TRY
            148     {
            149         //
            150         // Return data to user
            151         //
            152         *UnsafeOldAccessProtection = OldAccessProtection;
            153         *UnsafeBaseAddress = BaseAddress;
            154         *UnsafeNumberOfBytesToProtect = NumberOfBytesToProtect;
            155     }
            156     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
            157     {
            158     }
            159     _SEH2_END;
            160 
            161     //
            162     // Return status
            163     //
            164     return Status;
            165 }
            posted on 2011-03-23 10:01 shaker(太子) 閱讀(6609) 評論(1)  編輯 收藏 引用 所屬分類: C++

            評論:
            # re: NtProtectVirtualMemory[未登錄] 2011-10-31 21:20 | kevin
            請問MiProtectVirtualMemory()的unresolved external symbol如何解決?謝謝。  回復  更多評論
              
            久久久久人妻精品一区| 久久久久久久久久免免费精品| 一本一道久久综合狠狠老| 久久国产综合精品五月天| 2020国产成人久久精品| 久久人人爽人人爽人人片av高请| 乱亲女H秽乱长久久久| 久久精品国产99国产精品澳门| 国产成人久久激情91| 久久精品成人| 亚洲国产美女精品久久久久∴| 狠色狠色狠狠色综合久久| 亚洲国产日韩综合久久精品| 99999久久久久久亚洲| 国产99久久久国产精品小说| 久久99精品国产麻豆宅宅| 久久精品国产亚洲AV蜜臀色欲| 国产精品美女久久久久网| 亚洲国产高清精品线久久| 国产精品美女久久久久| 波多野结衣久久一区二区| 99久久精品免费国产大片| 久久久亚洲欧洲日产国码二区 | 国产精品伦理久久久久久| 久久黄视频| 国产精品久久久久乳精品爆 | 久久天天躁狠狠躁夜夜96流白浆| 91精品国产色综久久| 色狠狠久久AV五月综合| 香蕉久久夜色精品国产尤物| 办公室久久精品| 国产精品久久久天天影视香蕉| 97久久精品人妻人人搡人人玩| 欧美一区二区久久精品| 久久精品国产精品亚洲下载| 国产精品免费久久久久久久久| 精品午夜久久福利大片| 久久精品无码一区二区无码| 中文国产成人精品久久不卡| 久久精品国产99久久久古代| 日韩av无码久久精品免费|