WEB开发网
开发学院软件开发VC 文件过滤系统驱动开发Filemon学习笔 阅读

文件过滤系统驱动开发Filemon学习笔

 2007-12-30 21:37:20 来源:WEB开发网   
核心提示: 上面创建设备对象的代码为:ntStatus = IoCreateDevice ( DriverObject,sizeof(HOOK_EXTENSION),&deviceNameUnicodeString,FILE_DEVICE_FILEMON,0,TRUE,&guiDevice );///

上面创建设备对象的代码为:ntStatus = IoCreateDevice ( DriverObject,
                sizeof(HOOK_EXTENSION),
                &deviceNameUnicodeString,
                FILE_DEVICE_FILEMON,
                0,
                TRUE,
                &guiDevice );
  //
  // If successful, make a symbolic link that allows for the device
  // object's access from Win32 programs
  //
  if(NT_SUCCESS(ntStatus)) {
    //
    // Mark this as our GUI device
    //
    ((PHOOK_EXTENSION) guiDevice->DeviceExtension)->Type = GUIINTERFACE;
    //
    // Create a symbolic link that the GUI can specify to gain access
    // to this driver/device
    //
    RtlInitUnicodeString (&deviceLinkUnicodeString,
               deviceLinkBuffer );
    ntStatus = IoCreateSymbolicLink (&deviceLinkUnicodeString,
                     &deviceNameUnicodeString );
    if(!NT_SUCCESS(ntStatus)) {
      DbgPrint (("Filemon.SYS: IoCreateSymbolicLink failed
"));
      IoDeleteDevice( guiDevice );
      return ntStatus;      
    }
上面代码完成的功能为创建了用于与应用层交互的控制设备对象,名字在参数&deviceNameUnicodeString,中。设备对象创建成功后又调用IoCreateSymbolicLink创建了一个符号连接,以便于应用层交互。 在入口点函数DriverEntry代码中,还有一处代码: ProcessNameOffset = FilemonGetProcessNameOffset();//为了得到当前进程名字。此函数体如下:ULONG
FilemonGetProcessNameOffset(
  VOID
  )
{
  PEPROCESS    curproc;
  int       i;
  curproc = PsGetCurrentProcess();//调用PsGetCurrentProcess取得KPEB基址
  //然后搜索KPEB,得到ProcessName相对KPEB的偏移量
  // Scan for 12KB, hoping the KPEB never grows that big!
  //
  for( i = 0; i < 3*PAGE_SIZE; i++ ) {
  
    if( !strncmp( SYSNAME, (PCHAR) curproc + i, strlen(SYSNAME) )) {
      return i;
    }
  }
  //
  // Name not found - oh, well
  //
  return 0;

上一页  1 2 3 4 5 6  下一页

Tags:文件 过滤

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接