__init__.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:OSPTF 作者: xSploited 项目源码 文件源码
def CastTo(ob, target):
    """'Cast' a COM object to another interface"""
    # todo - should support target being an IID
    if hasattr(target, "index"): # string like
    # for now, we assume makepy for this to work.
        if "CLSID" not in ob.__class__.__dict__:
            # Eeek - no makepy support - try and build it.
            ob = gencache.EnsureDispatch(ob)
        if "CLSID" not in ob.__class__.__dict__:
            raise ValueError("Must be a makepy-able object for this to work")
        clsid = ob.CLSID
        # Lots of hoops to support "demand-build" - ie, generating
        # code for an interface first time it is used.  We assume the
        # interface name exists in the same library as the object.
        # This is generally the case - only referenced typelibs may be
        # a problem, and we can handle that later.  Maybe <wink>
        # So get the generated module for the library itself, then
        # find the interface CLSID there.
        mod = gencache.GetModuleForCLSID(clsid)
        # Get the 'root' module.
        mod = gencache.GetModuleForTypelib(mod.CLSID, mod.LCID,
                                           mod.MajorVersion, mod.MinorVersion)
        # Find the CLSID of the target
        target_clsid = mod.NamesToIIDMap.get(target)
        if target_clsid is None:
            raise ValueError("The interface name '%s' does not appear in the " \
                                "same library as object '%r'" % (target, ob))
        mod = gencache.GetModuleForCLSID(target_clsid)
        target_class = getattr(mod, target)
        # resolve coclass to interface
        target_class = getattr(target_class, "default_interface", target_class)
        return target_class(ob) # auto QI magic happens
    raise ValueError
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号