Added some code resulting from exploration in COM/remote ctypes

This commit is contained in:
hakril
2020-07-16 23:37:41 +02:00
parent 34254dfde2
commit 8e257f9678
2 changed files with 55 additions and 1 deletions
+40 -1
View File
@@ -29,13 +29,46 @@ def init():
except WindowsError as e:
t = e.winerror
if t:
return t
return t & 0xffffffff
return initsecurity()
def initsecurity(): # Should take some parameters..
return winproxy.CoInitializeSecurity(0, -1, None, 0, 0, RPC_C_IMP_LEVEL_IMPERSONATE, 0,0,0)
class Dispatch(interfaces.IDispatch):
def TypeInfoCount(self):
count = gdef.UINT()
self.GetTypeInfoCount(count)
return count
def type_info(self, idx):
type_info = TypeInfo()
self.GetTypeInfo(idx, 0, type_info)
return type_info
class TypeInfo(interfaces.ITypeInfo):
def func(self, idx):
res = gdef.LPFUNCDESC()
self.GetFuncDesc(idx, res)
return res
def attr(self):
res = gdef.LPTYPEATTR()
self.GetTypeAttr(res)
return res
def names(self, memid):
size = gdef.UINT()
x = (gdef.BSTR * 10)(*tuple(gdef.BSTR() for i in range(10)))
self.GetNames(memid, x, 10, size)
return x[:size.value]
def docu(self, id):
res = gdef.BSTR()
self.GetDocumentation(id, res, None, None, None)
return res
def create_instance(clsiid, targetinterface, custom_iid=None, context=CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER):
"""A simple wrapper around ``CoCreateInstance <https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615(v=vs.85).aspx>``"""
if custom_iid is None:
@@ -196,6 +229,12 @@ class Variant(VARIANT):
attr = self.QUICK_CHECK_TYPE[rawvt]
if attr is None:
return None
if attr == "punkVal":
# Quick hack for COM interface type
# Do something clean with CHECK_TYPE ?
x = gdef.IUnknown(self.punkVal)
x.AddRef()
return x
return getattr(self, attr)
def guess_type_and_set_value(self, value):
+15
View File
@@ -301,6 +301,21 @@ class RemoteStructurePointer32(Remote_c_void_p32):
@property
def contents(self):
# What if we have a non-struct pointer
# Like a Ptr(DWORD) we would like to get the underlying value
realtype = self.real_pointer_type._sub_ctypes_
# if _SimpleCData in realtype.__bases__:
# A ctypes original value.
# Returnthe real pointed value
# Kind of a tricks for now compared to the real ctypes behavior
# import pdb;pdb.set_trace()
# if not self.value:
# return None
# targetptr = self.target.read_ptr(self.value)
# if not targetptr:
# return None
# ss = self.target.read_memory(targetptr, ctypes.sizeof(realtype))
# return realtype.from_buffer(bytearray(ss)).value
remote_pointed_type = transform_type_to_remote32bits(self.real_pointer_type._sub_ctypes_)
return remote_pointed_type(self.raw_value, self.target)