首页
社区
课程
招聘
[旧帖] [求助]R0强删文件问题(网络代码经个人修改无问题!求原因) 0.00雪花
发表于: 2011-11-28 03:50 2785

[旧帖] [求助]R0强删文件问题(网络代码经个人修改无问题!求原因) 0.00雪花

2011-11-28 03:50
2785
吧主见谅第一次发帖发错版面了,发到了编程板块如果违规严重就将编程板块的帖子删掉吧【求助】R0强删文件问题(网络代码经个人修改无问题!求原因)
  
BOOLEAN
SKillDeleteFile(IN HANDLE    FileHandle)
{
  NTSTATUS          ntStatus = STATUS_SUCCESS;
  PFILE_OBJECT      fileObject;
  PDEVICE_OBJECT    DeviceObject;
  PIRP              Irp;
  KEVENT            event;
  FILE_DISPOSITION_INFORMATION    FileInformation;
  IO_STATUS_BLOCK ioStatus;
  PIO_STACK_LOCATION irpSp;
  PSECTION_OBJECT_POINTERS pSectionObjectPointer;
  PVOID ceshi1=NULL;
  PVOID ceshi2=NULL;
  SKillStripFileAttributes( FileHandle);          //去掉只读属性,才能删除只读文件
  ntStatus = ObReferenceObjectByHandle(FileHandle,
    DELETE,
    *IoFileObjectType,
    KernelMode,
    &fileObject,
    NULL);                               //取对象指针
  if (!NT_SUCCESS(ntStatus))
  {
    return FALSE;
  }
  DeviceObject = MyIoGetRelatedDeviceObject(fileObject);//获取最高设备对象
  Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);//指定设备栈中申请irp
  if (Irp == NULL)
  {
    ObDereferenceObject(fileObject);
    return FALSE;
  }
  KeInitializeEvent(&event, SynchronizationEvent, FALSE);
  FileInformation.DeleteFile = TRUE;
  Irp->AssociatedIrp.SystemBuffer = &FileInformation;
  Irp->UserEvent = &event;
  Irp->UserIosb = &ioStatus;
  Irp->Tail.Overlay.OriginalFileObject = fileObject;
  Irp->Tail.Overlay.Thread = (PETHREAD)KeGetCurrentThread();
  Irp->RequestorMode = KernelMode;
  irpSp = IoGetNextIrpStackLocation(Irp);
  irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
  irpSp->DeviceObject = DeviceObject;
  irpSp->FileObject = fileObject;
  irpSp->Parameters.SetFile.Length = sizeof(FILE_DISPOSITION_INFORMATION);
  irpSp->Parameters.SetFile.FileInformationClass = FileDispositionInformation;
  irpSp->Parameters.SetFile.FileObject = fileObject;
  IoSetCompletionRoutine(
    Irp,
    SkillSetFileCompletion,
    &event,
    TRUE,
    TRUE,
    TRUE);
  pSectionObjectPointer = fileObject->SectionObjectPointer;
  pSectionObjectPointer->ImageSectionObject = 0;
  pSectionObjectPointer->DataSectionObject = 0;  IoCallDriver(DeviceObject, Irp);
  KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, NULL);
  ObDereferenceObject(fileObject);
  return TRUE;
}

[ATTACH] OK.jpg[/ATTACH]

-----------------------------------------------------------以下个人分析  虽然问题解决不蓝屏但确实不知具体细节原因所以来此一问-------------------------------------------
蓝屏代码

*** Fatal System Error: 0x0000000a
                       (0x00000023,0x00000002,0x00000000,0x8050D623)

Break instruction exception - code 80000003 (first chance)

A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.

A fatal system error has occurred.

*********************************************************************
* Symbols can not be loaded because symbol path is not initialized. *
*                                                                   *
* The Symbol Path can be set by:                                    *
*   using the _NT_SYMBOL_PATH environment variable.                 *
*   using the -y <symbol_path> argument when starting the debugger. *
*   using .sympath and .sympath+                                    *
*********************************************************************
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

Use !analyze -v to get detailed debugging information.

BugCheck A, {23, 2, 0, 8050d623}

***** Kernel symbols are WRONG. Please fix symbols to do analysis.

Probably caused by : memory_corruption ( nt!MmCommitSessionMappedView+4cf )

Followup: MachineOwner
---------

  pSectionObjectPointer->ImageSectionObject = 0;
  pSectionObjectPointer->DataSectionObject = 0;

//此处疑问  看代码意思是将镜像对象 设置为0  我尝试将此处代码注销,
删除失效 不知道是不是 进行删除时 系统会对该对象进行检查此值如果不为0 不能删除  
但是源代码如此  却会造成后期蓝屏 (复制大量文件的时候会蓝屏)  Irql级别问题  
解决此问题时我个人 看来是因为访问的内存出现了问题 后 windbg 查看 以上蓝屏信息

我查看了一下0x8050D623 位置为一个函数头部

1: kd> u 0x8050D623   nt!MiRemoveImageSectionObject 这个函数里面

1: kd> u MiRemoveImageSectionObject
nt!MiRemoveImageSectionObject:
8050d614 8bff            mov     edi,edi
8050d616 55              push    ebp
8050d617 8bec            mov     ebp,esp
8050d619 56              push    esi
8050d61a 8b7508          mov     esi,dword ptr [ebp+8]
8050d61d 8b4e14          mov     ecx,dword ptr [esi+14h]
8050d620 8b4108          mov     eax,dword ptr [ecx+8]
8050d623 f6402310        test    byte ptr [eax+23h],10h//此处造成?

看代码是操作了第一个参数的一些成员然后成员内存出现问题?

wrk MiRemoveImageSectionObject 代码如下:

VOID
MiRemoveImageSectionObject(
    IN PFILE_OBJECT File,
    IN PCONTROL_AREA InputControlArea
    )

/*++

Routine Description:

    This function searches the control area chains (if any) for an existing
    cache of the specified image file.  For non-global control areas, there is
    no chain and the control area is shared for all callers and sessions.
    Likewise for systemwide global control areas.

    However, for global PER-SESSION control areas, we must do the walk.

    Upon finding the specified control area, we unlink it.

Arguments:

    File - Supplies the file object for the image file.

    InputControlArea - Supplies the control area to remove.

Return Value:

    None.

Environment:

    Must be holding the PFN lock.

--*/

{
#if DBG
    PLIST_ENTRY Head;
#endif
    PLIST_ENTRY Next;
    PLARGE_CONTROL_AREA ControlArea;
    PLARGE_CONTROL_AREA FirstControlArea;
    PLARGE_CONTROL_AREA NextControlArea;

    MM_PFN_LOCK_ASSERT();

    ControlArea = (PLARGE_CONTROL_AREA) InputControlArea;

    FirstControlArea = (PLARGE_CONTROL_AREA)(File->SectionObjectPointer->ImageSectionObject);

    //
    // Get a pointer to the first control area.  If this is not a
    // global-per-session control area, then there is no list, so we're done.
    //

    if (FirstControlArea->u.Flags.GlobalOnlyPerSession == 0) {//貌似是此处
        ASSERT (ControlArea->u.Flags.GlobalOnlyPerSession == 0);

        File->SectionObjectPointer->ImageSectionObject = NULL;
        return;
    }

    //
    // A list may exist.  Walk it as necessary and delete the requested entry.
    //

所以我认为之前删除的地方   pSectionObjectPointer->ImageSectionObject = 0; 会对后面调用这个函数是访问出现问题故此保留原始数据清空后再恢复原始数据解决方案代码修改如下:
  
  PVOID temp1=null;
  PVOID temp2=null;
  pSectionObjectPointer = fileObject->SectionObjectPointer;
  temp1=pSectionObjectPointer->ImageSectionObject;
  temp2=pSectionObjectPointer->DataSectionObject;
  pSectionObjectPointer->ImageSectionObject = 0;
  pSectionObjectPointer->DataSectionObject = 0;
  IoCallDriver(DeviceObject, Irp);
  KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, NULL);
  pSectionObjectPointer->ImageSectionObject=temp1;
  pSectionObjectPointer->ImageSectionObject=temp2;
-------------------------------------------------------以上为个人分析和修改信息---------------------------------------------------------------------------------------

个人疑问:

问题1: 主要请隔位大牛解释一下问题所在,为什么会蓝?  

问题2:虽然问题已经解决并且我已发布驱动给客户使用反映良好。但是确实不知自己分析是否正确 如BugCheck 蓝屏代码的信息我是否理解正确并请对各个参数给予解释(多谢)

问题3:此问题实属个人自私问题,如果哪位牛人有时间并且有空闲能帮小弟扫一下盲。请就帮小弟注释一下代码多谢了。。(如果没空也没事我自己继续学习)主要目的想对照看看自己理解是否有问题
以及一些不懂的地方参考一下

[课程]Android-CTF解题方法汇总!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 57
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
来人帮看啊  是否我提问方式有问题?没人回答?
2011-11-28 14:41
0
游客
登录 | 注册 方可回帖
返回
//