c - Windows过滤器驱动上的32位_asm代码到64位汇编代码

标签 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
}}

最佳答案

来自MASM for x64在 Visual Studio 2013 文档中:

Inline ASM is not supported for x64. Use MASM or compiler intrinsics (x64 Intrinsics).

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

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

关于c - Windows过滤器驱动上的32位_asm代码到64位汇编代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25346510/

相关文章:

c++ - 如何判断在哪个.SO库中赋予了C函数?

将 ASCII 码转换为字符值

c++ - 使用 CREATE_NEW_CONSOLE 创建进程并保持控制台窗口打开

visual-studio-2008 - 64 位编程和编译 - Visual Studio 2008 还是 Visual Studio 2010?

c - 将 double 转换为 int 会返回向下舍入的数字吗?

c - Ruby C 扩展编译错误 : expected ‘)’ before ‘event’

windows - 是什么使 NTDLL!_KiUserApcDispatcher 跳转到不属于进程中模块的地址?

windows - 如何在 R 中获取屏幕分辨率

c++ - Visual C++ x64 带进位加法

c++ - 64 位浮点移植问题