python类c_buffer()的实例源码

certificate.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_name(self, nametype=gdef.CERT_NAME_SIMPLE_DISPLAY_TYPE, flags=0):
        """Retrieve the subject or issuer name of the certificate. See ``CertGetNameStringA``

        :returns: :class:`str`
        """
        size = winproxy.CertGetNameStringA(self, nametype, flags, None, None, 0)
        namebuff = ctypes.c_buffer(size)
        size = winproxy.CertGetNameStringA(self, nametype, flags, None, namebuff, size)
        return namebuff[:-1]
cryptmsg.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_param(self, param_type, index=0):
        data_size = gdef.DWORD()
        # https://msdn.microsoft.com/en-us/library/windows/desktop/aa380227(v=vs.85).aspx
        winproxy.CryptMsgGetParam(self, param_type, index, None, data_size)
        buffer = ctypes.c_buffer(data_size.value)
        winproxy.CryptMsgGetParam(self, param_type, index, buffer, data_size)

        if param_type in self.MSG_PARAM_KNOW_TYPES:
            buffer = self.MSG_PARAM_KNOW_TYPES[param_type].from_buffer(buffer)
        if isinstance(buffer, gdef.DWORD): # DWORD -> return the Python int
            return buffer.value
        return buffer


    # Certificate accessors
winutils.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_long_path(path):
    """Return the long path form for ``path``

        :returns: :class:`str`
    """
    size = 0x1000
    buffer = ctypes.c_buffer(size)
    rsize = winproxy.GetLongPathNameA(path, buffer, size)
    return buffer[:rsize]
winutils.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_short_path(path):
    """Return the short path form for ``path``

        :returns: :class:`str`
    """
    size = 0x1000
    buffer = ctypes.c_buffer(size)
    rsize = winproxy.GetShortPathNameA(path, buffer, size)
    return buffer[:rsize]
winutils.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def decompress_buffer(comptype, buffer, uncompress_size=None):
    if uncompress_size is None:
        uncompress_size = len(buffer) * 10
    result_size = DWORD()
    uncompressed = ctypes.c_buffer(uncompress_size)
    windows.winproxy.RtlDecompressBuffer(comptype, uncompressed, uncompress_size, buffer, len(buffer), result_size)
    return uncompressed[:result_size.value]


# sid.py + real SID type ?
winutils.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_known_sid(sid_type):
    size = DWORD()
    try:
        windows.winproxy.CreateWellKnownSid(sid_type, None, None, size)
    except WindowsError:
        pass
    buffer = ctypes.c_buffer(size.value)
    windows.winproxy.CreateWellKnownSid(sid_type, None, buffer, size)
    return ctypes.cast(buffer, PSID)
ftd2xx.py 文件源码 项目:crescendo 作者: AriaFallah 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def getDeviceInfoDetail(devnum=0):
    """Get an entry from the internal device info list. """
    f = _ft.DWORD()
    t = _ft.DWORD()
    i = _ft.DWORD()
    l = _ft.DWORD()
    h = _ft.FT_HANDLE()
    n = c.c_buffer(MAX_DESCRIPTION_SIZE)
    d = c.c_buffer(MAX_DESCRIPTION_SIZE)
    createDeviceInfoList()
    call_ft(_ft.FT_GetDeviceInfoDetail, _ft.DWORD(devnum),
            c.byref(f), c.byref(t), c.byref(i), c.byref(l), n, d, c.byref(h))
    return {'index': devnum, 'flags': f.value, 'type': t.value,
            'id': i.value, 'location': l.value, 'serial': n.value,
            'description': d.value, 'handle': h}
ftd2xx.py 文件源码 项目:crescendo 作者: AriaFallah 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def read(self, nchars, raw=True):
        """Read up to nchars bytes of data from the device. Can return fewer if
        timedout. Use getQueueStatus to find how many bytes are available"""
        b_read = _ft.DWORD()
        b = c.c_buffer(nchars)
        call_ft(_ft.FT_Read, self.handle, b, nchars, c.byref(b_read))
        return b.raw[:b_read.value] if raw else b.value[:b_read.value]
ftd2xx.py 文件源码 项目:crescendo 作者: AriaFallah 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def getDeviceInfo(self):
        """Returns a dictionary describing the device. """
        deviceType = _ft.DWORD()
        deviceId = _ft.DWORD()
        desc = c.c_buffer(MAX_DESCRIPTION_SIZE)
        serial = c.c_buffer(MAX_DESCRIPTION_SIZE)

        call_ft(_ft.FT_GetDeviceInfo, self.handle, c.byref(deviceType),
                c.byref(deviceId), serial, desc, None)
        return {'type': deviceType.value, 'id': deviceId.value,
                'description': desc.value, 'serial': serial.value}
windows.py 文件源码 项目:Comictagger 作者: dickloraine 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def __init__(self, ArcName=None, ArcNameW=u'', OpenMode=RAR_OM_LIST):
        self.CmtBuf = ctypes.c_buffer(64*1024)
        ctypes.Structure.__init__(self, ArcName=ArcName, ArcNameW=ArcNameW, OpenMode=OpenMode, _CmtBuf=ctypes.addressof(self.CmtBuf), CmtBufSize=ctypes.sizeof(self.CmtBuf))
windows.py 文件源码 项目:Comictagger 作者: dickloraine 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self):
        self.CmtBuf = ctypes.c_buffer(64*1024)
        ctypes.Structure.__init__(self, _CmtBuf=ctypes.addressof(self.CmtBuf), CmtBufSize=ctypes.sizeof(self.CmtBuf))
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def struct(cls, ea, **sid):
        """Return the structure_t at address ``ea`` as a dict of ctypes.
        If the structure ``sid`` is specified, then use that specific structure type.
        """
        ea = interface.address.within(ea)

        if any(n in sid for n in ('sid','struc','structure','id')):
            res = sid['sid'] if 'sid' in sid else sid['struc'] if 'struc' in sid else sid['structure'] if 'structure' in sid else sid['id'] if 'id' in sid else None
            sid = res.id if isinstance(res, structure.structure_t) else res
        else:
            sid = type.structure.id(ea)

        st = structure.instance(sid, offset=ea)
        typelookup = {
            (int,-1) : ctypes.c_int8, (int,1) : ctypes.c_uint8,
            (int,-2) : ctypes.c_int16, (int,2) : ctypes.c_uint16,
            (int,-4) : ctypes.c_int32, (int,4) : ctypes.c_uint32,
            (int,-8) : ctypes.c_int64, (int,8) : ctypes.c_uint64,
            (float,4) : ctypes.c_float, (float,8) : ctypes.c_double,
        }

        res = {}
        for m in st.members:
            t, val = m.type, read(m.offset, m.size) or ''
            try:
                ct = typelookup[t]
            except KeyError:
                ty, sz = t if isinstance(t, __builtin__.tuple) else (m.type, 0)
                if isinstance(t, __builtin__.list):
                    t = typelookup[tuple(ty)]
                    ct = t*sz
                elif ty in (chr,str):
                    ct = ctypes.c_char*sz
                else:
                    ct = None
            finally:
                res[m.name] = val if any(_ is None for _ in (ct,val)) else ctypes.cast(ctypes.pointer(ctypes.c_buffer(val)),ctypes.POINTER(ct)).contents
        return res
SystemHealth.py 文件源码 项目:opc-rest-api 作者: matzpersson 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _task_list():
    psapi = ctypes.windll.psapi
    kernel = ctypes.windll.kernel32

    hModule = ctypes.c_ulong()
    count = ctypes.c_ulong()
    modname = ctypes.c_buffer(30)
    PROCESS_QUERY_INFORMATION = 0x0400
    PROCESS_VM_READ = 0x0010

    pid_list = win32process.EnumProcesses()
    info_list = []

    for pid in pid_list:

        hProcess = kernel.OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, pid)
        if hProcess:
            psapi.EnumProcessModules(hProcess, ctypes.byref(hModule), ctypes.sizeof(hModule), ctypes.byref(count))
            psapi.GetModuleBaseNameA(hProcess, hModule.value, modname, ctypes.sizeof(modname))
            pname = ctypes.string_at(modname)

            procmeminfo = win32process.GetProcessMemoryInfo(hProcess)
            procmemusage = (procmeminfo["WorkingSetSize"]/1024)
            info_list.append((pid, pname, procmemusage))

            kernel.CloseHandle(hProcess)

    return info_list
carbon_hid.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def cfstring_to_string(value_string):
    value_length = carbon.CFStringGetLength(value_string)
    buffer_length = carbon.CFStringGetMaximumSizeForEncoding(
        value_length, kCFStringEncodingUTF8)
    buffer = ctypes.c_buffer(buffer_length + 1)
    result = carbon.CFStringGetCString(value_string, 
                                       buffer, 
                                       len(buffer),
                                       kCFStringEncodingUTF8)
    if not result:
        return
    return buffer.value
carbon_hid.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def cfstring_to_string(value_string):
    value_length = carbon.CFStringGetLength(value_string)
    buffer_length = carbon.CFStringGetMaximumSizeForEncoding(
        value_length, kCFStringEncodingUTF8)
    buffer = ctypes.c_buffer(buffer_length + 1)
    result = carbon.CFStringGetCString(value_string, 
                                       buffer, 
                                       len(buffer),
                                       kCFStringEncodingUTF8)
    if not result:
        return
    return buffer.value
aptmotor.py 文件源码 项目:qudi 作者: Ulm-IQO 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def getHardwareInformation(self):
        ''' Get information from the hardware'''
        model = c_buffer(255)
        softwareVersion = c_buffer(255)
        hardwareNotes = c_buffer(255)
        self.aptdll.GetHWInfo(self.SerialNum, model, 255, softwareVersion, 255, hardwareNotes, 255)
        hwinfo = [model.value, softwareVersion.value, hardwareNotes.value]
        return hwinfo
provider.py 文件源码 项目:MacHeap 作者: blankwall 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_memory_read():
            data = 'A'*0x40
            buf = ctypes.c_buffer(data)
            ea = ctypes.addressof(buf)
            z = provider.memory()
            z.seek(ea)
            if z.consume(len(data)) == data:
                raise Success
            raise Failure
provider.py 文件源码 项目:MacHeap 作者: blankwall 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_memory_write():
            data = 'A'*0x40
            buf = ctypes.c_buffer(data)
            ea = ctypes.addressof(buf)
            z = provider.memory()
            z.seek(ea)
            z.store('B'*len(data))
            if buf.value == 'B'*len(data):
                raise Success
            raise Failure
provider.py 文件源码 项目:MacHeap 作者: blankwall 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_memory_readwrite():
            data = 'A'*0x40
            buf = ctypes.c_buffer(data)
            ea = ctypes.addressof(buf)
            z = provider.memory()
            z.seek(ea)
            z.store('B'*len(data))
            z.seek(ea)
            if z.consume(len(data)) == 'B'*len(data):
                raise Success
__init__.py 文件源码 项目:mlib 作者: mak 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def decrypt(cls, data, key):
        clen = cls.align_size(len(data))
        ckey = c_buffer(key)
        cin = c_buffer(data)
        cout = c_buffer(clen)
        cls.LIB.decrypt(cin, clen, ckey, cout)
        return cout.raw


问题


面经


文章

微信
公众号

扫码关注公众号