• <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(太子) 閱讀(6655) 評論(1)  編輯 收藏 引用 所屬分類: C++

            評論:
            # re: NtProtectVirtualMemory[未登錄] 2011-10-31 21:20 | kevin
            請問MiProtectVirtualMemory()的unresolved external symbol如何解決?謝謝。  回復  更多評論
              
            久久久青草青青国产亚洲免观| 婷婷久久综合九色综合九七| 精品久久久无码人妻中文字幕豆芽 | 久久婷婷五月综合成人D啪| 久久人人爽人人澡人人高潮AV| 久久水蜜桃亚洲av无码精品麻豆| 亚洲欧美日韩精品久久| 久久男人中文字幕资源站| 亚洲午夜久久久久久久久电影网 | 亚洲国产精品成人久久蜜臀| 国产成人无码精品久久久性色| 香蕉久久夜色精品国产小说| 一本色道久久HEZYO无码| 久久毛片免费看一区二区三区| 99久久久国产精品免费无卡顿| 97精品依人久久久大香线蕉97| 久久精品免费大片国产大片| 久久99精品国产一区二区三区| 久久人做人爽一区二区三区| 久久毛片免费看一区二区三区| 欧美日韩中文字幕久久伊人| 亚洲精品国精品久久99热一| 狠狠色婷婷久久综合频道日韩 | 日韩精品无码久久久久久| 亚洲国产精品成人AV无码久久综合影院 | 久久综合九色综合97_久久久| 久久热这里只有精品在线观看| 亚洲国产精品无码久久久久久曰| 国产精品99久久精品爆乳| 91秦先生久久久久久久| 久久综合久久久| 精品久久久久久无码中文野结衣| 亚洲国产成人久久综合碰碰动漫3d | 色天使久久综合网天天| 人人妻久久人人澡人人爽人人精品 | 国产精品久久99| 久久99精品国产99久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 欧美777精品久久久久网| 国产成人精品免费久久久久| 久久av无码专区亚洲av桃花岛|