我有一个驱动程序代码,其中包含一个使用 _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/