Advertisement
Guest User

ctypes bug ?

a guest
Jan 17th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import sys
  2. from ctypes import c_void_p, c_uint, WINFUNCTYPE, CFUNCTYPE, windll, memmove, c_char_p
  3.  
  4. GlobalAlloc = windll.kernel32.GlobalAlloc
  5. GlobalAlloc.argtypes = [c_uint, c_uint]
  6. GlobalAlloc.restype = c_void_p
  7.  
  8.  
  9. if sys.argv[1] == 'b':
  10.     GlobalLock = windll.kernel32.GlobalLock
  11.     GlobalLock.argtypes = [c_void_p]
  12.     GlobalLock.restype = c_void_p
  13. elif sys.argv[1] == 'w':
  14.     GlobalLock = WINFUNCTYPE(c_void_p, c_void_p)(windll.kernel32.GlobalLock)
  15. elif sys.argv[1] == 'c':
  16.     GlobalLock = CFUNCTYPE(c_void_p, c_void_p)(windll.kernel32.GlobalLock)
  17. else:
  18.     assert False
  19.  
  20. hdl = GlobalAlloc(2,100)
  21. print(hdl)
  22.  
  23. buff   = GlobalLock(hdl)
  24. print(buff)
  25.  
  26. cbuf = c_char_p(buff)
  27. memmove(cbuf, c_char_p(b"TestTest"), 9)
  28.  
  29. print(cbuf.value)
  30.  
  31.  
  32.  
  33.  
  34. TRANS_SCRIPT = """
  35. ~/tmp $ py -3.7-32 alloc.py b
  36. 55640068
  37. 15507016
  38. b'TestTest'
  39. ~/tmp $ py -3.7-32 alloc.py c
  40. 58916868
  41. 18060520
  42. b'TestTest'
  43. ~/tmp $ py -3.7-32 alloc.py w
  44. 49807364
  45. 10973464
  46. b'TestTest'
  47. ~/tmp $ py -3.8-64 alloc.py b
  48. 1629464494088
  49. 1629430083152
  50. b'TestTest'
  51. ~/tmp $ py -3.8-64 alloc.py w
  52. 2574623965192
  53. Traceback (most recent call last):
  54.  File "_ctypes/callbacks.c", line 237, in 'calling callback function'
  55. ctypes.ArgumentError: argument 1: <class 'OverflowError'>: int too long to convert
  56. 2574591640016
  57. ~/tmp $ py -3.8-64 alloc.py c
  58. 2903999250440
  59. Traceback (most recent call last):
  60.  File "_ctypes/callbacks.c", line 237, in 'calling callback function'
  61. ctypes.ArgumentError: argument 1: <class 'OverflowError'>: int too long to convert
  62. 2903995302352
  63. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement