参数的高位字和低位字

High word and low word of parameter

我有这个简单程序的示例代码,可以检查鼠标位置、记下 X 和 Y 坐标并检查鼠标左键是否按下。

.386
.model  flat, stdcall
option  casemap :none

include     bones.inc

.code
start:
invoke  GetModuleHandle, NULL
mov hInstance, eax
invoke  InitCommonControls
invoke  DialogBoxParam, hInstance, IDD_MAIN, 0, offset DlgProc, 0
invoke  ExitProcess, eax

DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax,uMsg

.if eax == WM_INITDIALOG

.elseif eax == WM_LBUTTONDOWN ; when left button is down
    invoke SetDlgItemText, hWin, 1001, addr Msg1
.elseif eax == WM_LBUTTONUP ; when left button is up
    invoke SetDlgItemText, hWin, 1001, addr Msg2
.elseif eax == WM_MOUSEMOVE
    xor ecx, ecx ; clear ecx register
    mov cx, WORD PTR lParam ; copy low-word of lParam to cx  <---- this is line that is bothering me
    invoke SetDlgItemInt, hWin, 1002, ecx, FALSE ; set integer in control
    xor ecx, ecx ; zerujemy rejestr ecx
    mov cx, WORD PTR lParam+2 ; copy high-word of lParam to cx <--- this line is bothering me as well
    invoke SetDlgItemInt, hWin, 1003, ecx, FALSE ; set integer in control
.elseif eax == WM_CLOSE
    invoke  EndDialog, hWin, 0
.endif

xor eax,eax
ret
DlgProc endp

end start

这是我的 ollydebugger 屏幕截图,断点位于第一行:

我的问题是:

1) MOV CX,WORD PTR SS:[EBP+14] 这一行究竟是什么意思? 是:将单元格编号 EBP+14 的值复制到 CX 寄存器?因此,如果 EBP 显示单元格编号 1,则源单元格编号为 15?

2) 因此,如果以我的截图为例:EBP 值为 (0001 1001 1111 1011 1011 0000) (19FBB0h) 是低字 (0000 0000 0001 1001) 和高字 (1111 1011 1011 0000)?如果不是我该如何学习?

3) 作者是怎么知道高低字的正确值的?

4) 为什么要 mov cx, WORD PTR lParam+2?这个+2困扰着我。如果 lParam 是 DWORD(32 位),为什么 offset 是 +2?不是应该+16才能得到high word吗?

提前致谢

编辑:如果需要,这是 bones.inc 文件:

include     windows.inc
include     user32.inc
include     kernel32.inc
include     comctl32.inc    ;windows common controls

includelib  user32.lib
includelib  kernel32.lib
includelib  comctl32.lib    ;windows common controls

DlgProc     PROTO   :DWORD,:DWORD,:DWORD,:DWORD

.const
IDD_MAIN    equ 1000

.data
Msg1 db "Lewy przycisk myszy jest wciśnięty",0
Msg2 db "Lewy przycisk myszy jest zwolniony",0

.data?
hInstance   dd  ?
  1. 没有。 ebp=19FBB0h 所以 ebp+14h=19FBC4h, 那里面的内容就是 004200CFh.
  2. 作者已阅读documentation for WM_MOUSEMOVE
  3. 偏移量以字节而不是位为单位。 +2 字节是 +16 位,或 +1 字。