Windows筛选器驱动程序上的32位_asm代码到64位汇编代码

时间:2014-08-17 05:19:11

标签: c windows 64-bit driver filter-driver

我有一个驱动程序代码,如果正在使用_asm(内联汇编)的汇编代码,当我在32位WDK中进行编译时它正常工作,但是它会抛出以下错误:

"error C4235: nonstandard extension used : '_asm' keyword not supported on this architecture"

请转换以下_asm代码进行64位编译。

_asm
{
    mov     ebx, cr0 
    push    ebx 
    and     ebx, ~010000h 
    mov     cr0, ebx
    sti
} 

我使用__writecr0()来设置cr0值但是如何在x64 windows驱动程序中设置中断标志(sti)? 我有这个功能

VOID RunHook(ULONG Service_Index,PVOID NewAddress,ULONG *OldAddress){
ULONG Address;

DbgPrint("RunHook - NewAddress:0x%00X - Service_Index:0x%0X",NewAddress,Service_Index);

Address = (ULONG)KeServiceDescriptorTable->ServiceTableBase + Service_Index * 4;

*OldAddress = *(ULONG*)Address;


/*__asm
{
    cli
        mov eax, cr0
        and eax, not 10000h
        mov cr0, eax
}*/
__writecr0(__readcr0() & ~0x10000);
// ÐÞ¸ÄSSDTÖÐNtOpenProcess·þÎñµÄµØÖ·
*((ULONG*)Address) = (ULONG)NewAddress;


__asm
{
    mov eax, cr0
        or eax, 10000h
        mov cr0, eax
        sti
}}

1 个答案:

答案 0 :(得分:0)

从Visual Studio 2013文档中的MASM for x64开始:

  

x64不支持内联ASM。使用MASM或编译器内在函数(x64内在函数)。

我不相信有任何支持的方法来操纵中断标志,因为设计内核模式驱动程序是Always Preemptible and Always Interruptible,所以要做到这一点你需要将代码放在一个单独的模块中并使用MASM。

但是,没有什么意义;在64位Windows中,Kernel Patch Protection阻止您修改服务表。您只能在应用程序级别挂钩API调用,如Havenard的评论中所述。