📄 virtual.c
字号:
/*
This is a C++ run-time library for Windows kernel-mode drivers.
Copyright (C) 2004 Bo Brant閚.
*/
/*
The following is a modified subset of wine/dlls/kernel/virtual.c
from version wine20040505.
*/
/* * Win32 virtual memory functions * * Copyright 1997 Alexandre Julliard * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ntddk.h>
#if (VER_PRODUCTBUILD < 2195)
typedef ULONG ULONG_PTR;
#endif // (VER_PRODUCTBUILD < 2195)
/*********************************************************************** * IsBadReadPtr (KERNEL32.@) * * RETURNS * FALSE: Process has read access to entire block * TRUE: Otherwise */
BOOLEAN
NTAPI
IsBadReadPtr(
IN CONST PVOID ptr, /* [in] Address of memory block */
IN ULONG_PTR size /* [in] Size of block */
)
{
if (!size) return FALSE; /* handle 0 size case w/o reference */ __try { volatile const char *p = ptr; char dummy; ULONG count = size; while (count > PAGE_SIZE) { dummy = *p; p += PAGE_SIZE; count -= PAGE_SIZE; } dummy = p[0]; dummy = p[count - 1]; } __except(EXCEPTION_EXECUTE_HANDLER) { return TRUE; } return FALSE;}/*********************************************************************** * IsBadWritePtr (KERNEL32.@) * * RETURNS * FALSE: Process has write access to entire block * TRUE: Otherwise */
BOOLEAN
NTAPI
IsBadWritePtr(
IN PVOID ptr, /* [in] Address of memory block */
IN ULONG_PTR size /* [in] Size of block in bytes */
)
{ if (!size) return FALSE; /* handle 0 size case w/o reference */ __try { volatile char *p = ptr; ULONG count = size; while (count > PAGE_SIZE) { *p |= 0; p += PAGE_SIZE; count -= PAGE_SIZE; } p[0] |= 0; p[count - 1] |= 0; } __except(EXCEPTION_EXECUTE_HANDLER) { return TRUE; } return FALSE;}
/*********************************************************************** * IsBadCodePtr (KERNEL32.@) * * RETURNS * FALSE: Process has read access to specified memory * TRUE: Otherwise */BOOLEAN
NTAPI
IsBadCodePtr(
IN int (NTAPI *ptr)(VOID) /* [in] Address of function */
)
{ return IsBadReadPtr( ptr, 1 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -