码迷,mamicode.com
首页 > 其他好文 > 详细

记两个用于修改用户态内存的函数

时间:2016-03-09 06:56:02      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

//用于在LoadImageRoutine中使用,修改用户态内存
PMDL MapUserModeAddrWritable(PVOID BaseAddr,ULONG Length, PVOID *pNewAddr);
VOID UnmapMemory(PVOID pAddr, PMDL pMdl);

PMDL MapUserModeAddrWritable(PVOID BaseAddr,ULONG Length, PVOID *pNewAddr)
{
    PVOID pMapedAddr = NULL ;
    //创建一个MDL
    PMDL pMdl = IoAllocateMdl(BaseAddr,Length,FALSE,FALSE,NULL);
    if (pMdl == NULL)
    {
        dprintf("pMDL == NULL\n");
        return NULL;
    }
    
    __try
    {
        MmProbeAndLockPages(pMdl,UserMode,IoReadAccess);
    }
    __except(EXCEPTION_EXECUTE_HANDLER)
    {
        dprintf("MmProbeAndLockPages exception. Code  = 0x%08X\n",GetExceptionCode());
        IoFreeMdl(pMdl);
        return NULL;
    }
    
    
    pMapedAddr = MmMapLockedPagesSpecifyCache(pMdl,KernelMode,MmCached,NULL,FALSE,NormalPagePriority);
    if (!pMapedAddr)
    {
        dprintf("pMapedAdd == NULL\n");
        MmUnlockPages(pMdl);
        IoFreeMdl(pMdl);
        return NULL;
    }
    
    *pNewAddr = pMapedAddr ;
    return pMdl;
    
}

VOID UnmapMemory(PVOID pAddr, PMDL pMdl)
{
    if (pAddr != NULL)
    {
        MmUnmapLockedPages(pAddr,pMdl);
    }
    
    if (pMdl != NULL)
    {
        MmUnlockPages(pMdl);
        IoFreeMdl(pMdl);
    }
    
}

 

记两个用于修改用户态内存的函数

标签:

原文地址:http://www.cnblogs.com/achillis/p/5256573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!