dump_clipboard.py 文件源码

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

项目:OSPTF 作者: xSploited 项目源码 文件源码
def DumpClipboard():
    do = pythoncom.OleGetClipboard()
    print "Dumping all clipboard formats..."
    for fe in do.EnumFormatEtc():
        fmt, td, aspect, index, tymed = fe
        tymeds_this = [getattr(pythoncom, t) for t in tymeds if tymed & getattr(pythoncom, t)]
        print "Clipboard format", format_name_map.get(fmt,str(fmt))
        for t_this in tymeds_this:
            # As we are enumerating there should be no need to call
            # QueryGetData, but we do anyway!
            fetc_query = fmt, td, aspect, index, t_this
            try:
                do.QueryGetData(fetc_query)
            except pythoncom.com_error:
                print "Eeek - QGD indicated failure for tymed", t_this
            # now actually get it.
            try:
                medium = do.GetData(fetc_query)
            except pythoncom.com_error, exc:
                print "Failed to get the clipboard data:", exc
                continue
            if medium.tymed==pythoncom.TYMED_GDI:
                data = "GDI handle %d" % medium.data
            elif medium.tymed==pythoncom.TYMED_MFPICT:
                data = "METAFILE handle %d" % medium.data
            elif medium.tymed==pythoncom.TYMED_ENHMF:
                data = "ENHMETAFILE handle %d" % medium.data
            elif medium.tymed==pythoncom.TYMED_HGLOBAL:
                data = "%d bytes via HGLOBAL" % len(medium.data)
            elif medium.tymed==pythoncom.TYMED_FILE:
                data = "filename '%s'" % data
            elif medium.tymed==pythoncom.TYMED_ISTREAM:
                stream = medium.data
                stream.Seek(0,0)
                bytes = 0
                while 1:
                    chunk = stream.Read(4096)
                    if not chunk:
                        break
                    bytes += len(chunk)
                data = "%d bytes via IStream" % bytes
            elif medium.tymed==pythoncom.TYMED_ISTORAGE:
                data = "a IStorage"
            else:
                data = "*** unknown tymed!"
            print " -> got", data
    do = None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号