The method is really simple. I added a new include file that looks like this (it's a little shorter than the real thing):
Code: Select all
; DEFINE DO_API_CHECK ; decomment to enable API checks
IFDEF DO_API_CHECK
ApiSaveEax Macro
push eax
Endm
ApiCheckEax Macro
local check_ok
push bp
mov bp,sp
pushf
cmp eax,[bp+2]
je check_ok
;
int 3
check_ok:
popf
pop bp
pop eax
Endm
ApiSaveEbx Macro
push ebx
Endm
ApiCheckEbx Macro
local check_ok
push bp
mov bp,sp
pushf
cmp ebx,[bp+2]
je check_ok
;
int 3
check_ok:
popf
pop bp
pop ebx
Endm
ELSE
ApiSaveEax Macro
Endm
ApiCheckEax Macro
Endm
ApiSaveEbx Macro
Endm
ApiCheckEbx Macro
Endm
ENDIF
Code: Select all
Somefunction Proc
ApiSaveEax
ApiSaveEbx
ApiSaveEcx
ApiSaveEdx
ApiSaveEsi
; do something
mov edi,1234h
ApiCheckEsi
ApiCheckEdx
ApiCheckEcx
ApiCheckEbx
ApiCheckEax
retf32
Somefunction Endp
If I had validated with a segmented memory-model I would have caught this problem very fast, but with paging only there is no simple way to find it.