奇葩的编译器 ULONG 为啥要movsx byte ptr?
真的是第一次遇到这种编译器解释,年轻人,见识少啊。
if(*(DWORD*)&nInstructions[0] == 0x878af88bUL)
结果是:
1: kd> u b126f1e5
xxxxxx!TryToX+0x1c5 [e:\drv\xxxx\xxxx.c @ 639]:
b126f1e5 0fbe1590e926b1 movsx edx,byte ptr [xxxxxx!nInstructions (b126e990)]
b126f1ec 81fa8b000000 cmp edx,8Bh
b126f1f2 0f8598000000 jne xxxxxx!TryToHookNtWriteVirtualMemory+0x270 (b126f290)
b126f1f8 0fbe0591e926b1 movsx eax,byte ptr [xxxxxx!nInstructions+0x1 (b126e991)]
b126f1ff 3df8000000 cmp eax,0F8h
b126f204 0f8586000000 jne xxxxxx!TryToHookNtWriteVirtualMemory+0x270 (b126f290)
b126f20a 0fbe0d92e926b1 movsx ecx,byte ptr [xxxxxx!nInstructions+0x2 (b126e992)]
b126f211 81f98a000000 cmp ecx,8Ah
从movsx开始我就隐约有点蛋疼了,不是ULONG互相比较吗,为啥要一个字节一个字节的movsx + cmp?接着果然蛋疼了:
1: kd> db nInstructions
b126e990 8b f8 8a 87 40 01 00 00-00 00 00 00 94 53 5b 80 ....@........S[.
b126e9a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
b126e9b0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
果不其然:
Breakpoint 2 hit
xxxxxxx!TryX+0x1c5:
b138b1e5 0fbe1590a938b1 movsx edx,byte ptr [xxxxxxx!nInstructions (b138a990)]
1: kd> r edx
edx=ffffff8b
条件不满足,然后呢?改成这样就过了,你逗我?
if((ULONG)*(DWORD*)&nInstructions[0] == (ULONG)0x878af88bUL)
这回判断正常了:
1: kd> u b13931e5
xxxxxxx!TryX+0x1c5 [e:\drv\***.c @ 639]:
b13931e5 813d902939b18bf88a87 cmp dword ptr [xxxxxxx!nInstructions (b1392990)],878AF88Bh