【问题标题】:How to disable Windows to create an automatic restore point when installing my kernel driver?安装内核驱动程序时如何禁用 Windows 以创建自动还原点?
【发布时间】:2016-03-01 09:17:26
【问题描述】:

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

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

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

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

我想禁用 Windows 为我的驱动程序自动创建还原点。最好的方法是什么?谢谢!

【问题讨论】:

    标签: windows driver nsis ndis system-restore


    【解决方案1】:

    SysRestore plug-inBEGIN_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
    

    【讨论】:

    • 我用你的方法成功了。但有时只是没有创建还原点。你知道为什么吗?
    • 不,我从未使用过此 API。 SRSetRestorePoint 失败时返回什么?在 SRSetRestorePoint 之后尝试 System::Call '*$SRSTATUS(${STATEMGRSTATUS})(.r6)',它应该将错误代码放在 $6 和 DetailPrint 中。
    【解决方案2】:

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

    无论如何,您都应该提前与您的用户沟通,并在完成时(重新)启动服务。

    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
    

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

    【讨论】:

    • 我无法停止服务。因为我的安装程序本身仍然需要创建自己的还原点。我猜如果服务停止,我的创建会失败?
    【解决方案3】:

    WSR 有一些替代品具有相同的功能(即 Comodo Time Machine、Shadow Defender、RollbackRx 等),您最好使用它们来拍摄快照,因为我确信它们不会被相同的限制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-11
      • 2011-10-11
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 2020-08-15
      • 1970-01-01
      相关资源
      最近更新 更多