www.pudn.com > hookN.zip > func.cpp


extern "C" 
{ 
 
#include  
#include "func.h" 
#include "debug.h" 
 
int func_is_good_read_ptr(PVOID buf,ULONG size); 
} //extern "C" 
 
/* 
 this function checks user buffer for read access  
 returns true if the buffer is ok 
*/ 
 
int func_is_good_read_ptr(PVOID buf,ULONG size) 
{ 
  DbgMsg("func.cpp: func_is_good_read_ptr(buf:0x%.8X;size:0x%.8X)",buf,size); 
 
  int res=TRUE; 
 
  __try 
  { 
    ProbeForRead(buf,size,sizeof(char)); 
    ULONG sum=0; 
    PULONG p=(PULONG)buf; 
    int i; 
    for (i=0;i<(int)(size/sizeof(ULONG));i++) sum+=p[i]; 
    for (int j=0;j<(int)(size%sizeof(ULONG));j++) sum+=*((UCHAR*)&p[i]+j); 
  } __except(EXCEPTION_EXECUTE_HANDLER) 
  { 
    DbgPrint("func.cpp: func_is_good_read_ptr error: exception occurred"); 
    res=FALSE; 
  } 
 
  DbgMsg("func.cpp: func_is_good_read_ptr(-):%d",res); 
  return res; 
}