When I'm stepping through a debuggee process with IDA+WinDbg (as a debugger), I need to track one parameter by executing the following API (from within the breakpoint):
//C++ code
SCROLLINFO s;
s.cbSize = sizeof(s); //0x1C
s.fMask = SIF_POS | SIF_TRACKPOS; //0x4 | 0x10
GetScrollInfo(hWnd, SB_VERT, &s); //SB_VERT = 1
printf("pos=%d, track=%d", s.nPos, s.nTrackPos);
So I came up with the following Python script to do this from a breakpoint in IDA:
import ctypes
from ctypes import wintypes
hwnd = 0x00020208
user32 = ctypes.WinDLL('user32', use_last_error=True)
class SCROLLINFO(ctypes.Structure):
_fields_ = (("cbSize", wintypes.DWORD),
("fMask", wintypes.DWORD),
("nMin", wintypes.LONG),
("nMax", wintypes.LONG),
("nPage", wintypes.DWORD),
("nPos", wintypes.LONG),
("nTrackPos", wintypes.LONG))
s = SCROLLINFO(cbSize=0x1C,
fMask=0x14,
nPos=-1,
nTrackPos=-1)
user32.GetScrollInfo(hwnd, 1, ctypes.byref(s))
print s.nPos, s.nTrackPos
Which I thought seemed to work and gave me some values:
But then when I got to the actual code in the process that was doing the same:
The result it received for s.nTrackPos
was 1 instead of 8 that is reported by my Python script. Here's the memory dump for the SCROLLINFO struct:
So what am I doing wrong here? Why is the Python script returning the wrong value?