[Ironpython-users] ctypes/struct: Why does this not work?
Jeff Hardy
jdhardy at gmail.com
Wed Dec 19 00:26:07 CET 2012
On Fri, Dec 14, 2012 at 6:35 PM, Michael van der Kolff
<mvanderkolff at gmail.com> wrote:
> For background, I'm trying to port paramiko to IronPython. With the
> IronPyCrypto, we seem to have everything working apart from Pageant support.
>
> The question is, why does this not work? This is a simplified version of
> what Paramiko does - but the point is, run it on CPython and we have
> different behaviour.
>
> Cheers,
>
> Michael
>
> import ctypes, ctypes.wintypes, array, mmap
>
> _WM_COPYDATA = 74
> _PAGEANT_MAGIC = 0x804e50ba
> _MAX_MSG_LEN = 8192
>
> class COPYDATASTRUCT(ctypes.Structure):
> _fields_ = [
> ('num_data', ctypes.c_uint32),
> ('data_size', ctypes.wintypes.DWORD),
> ('data_loc', ctypes.c_void_p),
> ]
>
> hWnd = ctypes.windll.user32.FindWindowA(b'Pageant', b'Pageant') #This works
> on IronPython
>
> tagname = "PageantRequest5"
> pymap = mmap.mmap(-1,_MAX_MSG_LEN,tagname=tagname, access=mmap.ACCESS_WRITE)
> pymap[0:5] = '\0\0\0\x01\x0b' #A request of length one asking for keys from
> pageant
>
> cbuf = array.array('c', bytes(tagname + '\0'))
> _addr, _size = cbuf.buffer_info()
> cds = COPYDATASTRUCT(_PAGEANT_MAGIC, _size, _addr)
> response = ctypes.windll.user32.SendMessageA(hWnd, _WM_COPYDATA,
> ctypes.sizeof(cds), ctypes.byref(cds))
> print response #On CPython 2.7, 1; on Ironpython, 0.
> #On CPython, at this stage we can read out the response just by manipulating
> the mmap object.
Hard to say. It could be a bug in ctypes (it's not perfect), but
debugging that could be tricky. I looped Dino in to see if he knows
more.
- Jeff
More information about the Ironpython-users
mailing list