首页 文章

如何在安装内核驱动程序时禁用Windows以创建自动还原点?

提问于
浏览
1

我开发了一个NDIS 6.x LWF内核驱动程序,并使用NSIS 2.46将其打包到安装程序中 . 我发现安装完成后,Windows会自动创建一个名为 Device Driver Package Install: Nmap Project Network Service 的系统还原点 .

但实际上,事实证明Windows创建的这个还原点并不好 . 我尝试回滚到恢复点,我的软件仍然存在,包括驱动程序 .sys 文件和对系统的其他修改(如创建适配器,如 Windows Loopback Adapter ) .

这是可以理解的,因为我的安装程序确实在安装驱动程序之前进行了一些修改,而Windows只在安装驱动程序时才拍摄快照 . 因此,不包括驱动程序安装之前的更改 .

所以我决定在安装程序的所有实际安装步骤之前自己创建一个还原点(使用NSIS提供的 SysRestore ) .

我想 disable Windows to automatically create the restore point for my driver . 这样做最好的是什么?谢谢!

3 回答

  • 0

    SysRestore plug-in使用 BEGIN_SYSTEM_CHANGE 调用 SRSetRestorePoint 但是根据MSDN,您可以使用 BEGIN_NESTED_SYSTEM_CHANGE 调用它来仅创建一个还原点 . 我不知道这是否适用于单个进程,或者它是否也适用于您可能用于安装驱动程序的任何子进程,但它可能值得一试 . 代码可能如下所示:

    !define MAX_DESC 64
    !define MAX_DESC_W 256
    !define STATEMGRSTATUS i,l
    !define RESTOREPOINTINFOA i,i,l,&m${MAX_DESC}
    !define RESTOREPOINTINFOW i,i,l,&w${MAX_DESC_W}
    !if "${NSIS_CHAR_SIZE}" <= 1
    !define RESTOREPOINTINFO "${RESTOREPOINTINFOA}"
    !else
    !define RESTOREPOINTINFO "${RESTOREPOINTINFOW}"
    !endif
    !define BEGIN_NESTED_SYSTEM_CHANGE 102
    !define END_NESTED_SYSTEM_CHANGE 103
    !define DEVICE_DRIVER_INSTALL 10
    
    Section
    System::Call 'KERNEL32::LoadLibrary(t "$SysDir\SrClient.dll")'
    Var /Global SRSTATUS
    System::Call '*(${STATEMGRSTATUS})i.s'
    Pop $SRSTATUS
    System::Call '*(${RESTOREPOINTINFO})(${BEGIN_NESTED_SYSTEM_CHANGE},${DEVICE_DRIVER_INSTALL},0,&t${MAX_DESC} "Installed driver XYZ")i.r0'
    System::Call 'SrClient::SRSetRestorePoint(ir0,i$SRSTATUS)i.r1'
    IntCmpU $1 0 "" +2 +2
        System::Call '*$SRSTATUS(${STATEMGRSTATUS})(0)' ; Make sure nStatus is ERROR_SUCCESS
    System::Free $0
    DetailPrint "SRSetRestorePoint(BEGIN_NESTED_SYSTEM_CHANGE) returned $1"
    
    
    ; TODO: Install driver here
    
    
    System::Call '*$SRSTATUS(${STATEMGRSTATUS})(.r0,.r1)' ; Extract nStatus and llSequenceNumber
    IntCmpU $0 0 "" norpt norpt ; Did the first call to SRSetRestorePoint succeed?
        System::Call '*(${RESTOREPOINTINFO})(${END_NESTED_SYSTEM_CHANGE},${DEVICE_DRIVER_INSTALL},r1)i.r0'
        System::Call 'SrClient::SRSetRestorePoint(ir0,i$SRSTATUS)i.r1'
        System::Free $0
        DetailPrint "SRSetRestorePoint(END_NESTED_SYSTEM_CHANGE) returned $1"
    norpt:
    System::Free $SRSTATUS
    SectionEnd
    
  • 1

    我不知道这是否是最好的方法,但您可以随时停止系统还原服务 . 在我看来,这是一个微妙的问题,可能是一个比用户期望的驱动程序安装程序更大的干预 .

    在任何情况下,您都应该事先与用户沟通,并在完成后重新启动服务 .

    Section
        # Stop the service
        nsExec::Exec 'net.exe STOP "srservice"'  
    
        # Install kernel driver
    SectionEnd    
    
    # Restore original setting
    Function startSysRestore
        nsExec::Exec 'net.exe START "srservice"'  
    FunctionEnd    
    
    # Things go right
    Function .onInstSuccess
        Call startSysRestore
    FunctionEnd    
    
    # Things might go wrong
    Function .onUserAbort
        Call startSysRestore
    FunctionEnd    
    
    Function .onInstFailed
        Call startSysRestore
    FunctionEnd
    

    Edit: 此答案的先前版本描述了如何禁用ServiceRestore服务

  • 0

    有一些WSR的替代品可以使用相同的功能(即Comodo Time Machine,Shadow Defender,RollbackRx等),你可能最好使用它们拍摄快照,因为我确信它们没有受到相同的限制 .

相关问题