Skip to content

Commit 8e257f9

Browse files
committed
Added some code resulting from exploration in COM/remote ctypes
1 parent 34254df commit 8e257f9

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

windows/com.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,46 @@ def init():
2929
except WindowsError as e:
3030
t = e.winerror
3131
if t:
32-
return t
32+
return t & 0xffffffff
3333
return initsecurity()
3434

3535
def initsecurity(): # Should take some parameters..
3636
return winproxy.CoInitializeSecurity(0, -1, None, 0, 0, RPC_C_IMP_LEVEL_IMPERSONATE, 0,0,0)
3737

3838

39+
class Dispatch(interfaces.IDispatch):
40+
def TypeInfoCount(self):
41+
count = gdef.UINT()
42+
self.GetTypeInfoCount(count)
43+
return count
44+
45+
def type_info(self, idx):
46+
type_info = TypeInfo()
47+
self.GetTypeInfo(idx, 0, type_info)
48+
return type_info
49+
50+
class TypeInfo(interfaces.ITypeInfo):
51+
def func(self, idx):
52+
res = gdef.LPFUNCDESC()
53+
self.GetFuncDesc(idx, res)
54+
return res
55+
56+
def attr(self):
57+
res = gdef.LPTYPEATTR()
58+
self.GetTypeAttr(res)
59+
return res
60+
61+
def names(self, memid):
62+
size = gdef.UINT()
63+
x = (gdef.BSTR * 10)(*tuple(gdef.BSTR() for i in range(10)))
64+
self.GetNames(memid, x, 10, size)
65+
return x[:size.value]
66+
67+
def docu(self, id):
68+
res = gdef.BSTR()
69+
self.GetDocumentation(id, res, None, None, None)
70+
return res
71+
3972
def create_instance(clsiid, targetinterface, custom_iid=None, context=CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER):
4073
"""A simple wrapper around ``CoCreateInstance <https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615(v=vs.85).aspx>``"""
4174
if custom_iid is None:
@@ -196,6 +229,12 @@ def get_value_based_on_type(self):
196229
attr = self.QUICK_CHECK_TYPE[rawvt]
197230
if attr is None:
198231
return None
232+
if attr == "punkVal":
233+
# Quick hack for COM interface type
234+
# Do something clean with CHECK_TYPE ?
235+
x = gdef.IUnknown(self.punkVal)
236+
x.AddRef()
237+
return x
199238
return getattr(self, attr)
200239

201240
def guess_type_and_set_value(self, value):

windows/remotectypes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ def from_buffer_with_target_and_ptr_type(cls, buffer, offset=0, target=None, ptr
301301

302302
@property
303303
def contents(self):
304+
# What if we have a non-struct pointer
305+
# Like a Ptr(DWORD) we would like to get the underlying value
306+
realtype = self.real_pointer_type._sub_ctypes_
307+
# if _SimpleCData in realtype.__bases__:
308+
# A ctypes original value.
309+
# Returnthe real pointed value
310+
# Kind of a tricks for now compared to the real ctypes behavior
311+
# import pdb;pdb.set_trace()
312+
# if not self.value:
313+
# return None
314+
# targetptr = self.target.read_ptr(self.value)
315+
# if not targetptr:
316+
# return None
317+
# ss = self.target.read_memory(targetptr, ctypes.sizeof(realtype))
318+
# return realtype.from_buffer(bytearray(ss)).value
304319
remote_pointed_type = transform_type_to_remote32bits(self.real_pointer_type._sub_ctypes_)
305320
return remote_pointed_type(self.raw_value, self.target)
306321

0 commit comments

Comments
 (0)