python类REG_EXPAND_SZ的实例源码

test_win32api.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def testValues(self):
        key_name = r'PythonTestHarness\win32api'
        ## tuples containing value name, value type, data
        values=(
            (None, win32con.REG_SZ, 'This is default unnamed value'),
            ('REG_SZ', win32con.REG_SZ,'REG_SZ text data'),
            ('REG_EXPAND_SZ', win32con.REG_EXPAND_SZ, '%systemdir%'),
            ## REG_MULTI_SZ value needs to be a list since strings are returned as a list
            ('REG_MULTI_SZ', win32con.REG_MULTI_SZ, ['string 1','string 2','string 3','string 4']),
            ('REG_MULTI_SZ_empty', win32con.REG_MULTI_SZ, []),
            ('REG_DWORD', win32con.REG_DWORD, 666),
            ('REG_QWORD', win32con.REG_QWORD, 2**33),
            ('REG_BINARY', win32con.REG_BINARY, str2bytes('\x00\x01\x02\x03\x04\x05\x06\x07\x08\x01\x00')),
            )

        hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, key_name)
        for value_name, reg_type, data in values:
            win32api.RegSetValueEx(hkey, value_name, None, reg_type, data)

        for value_name, orig_type, orig_data in values:
            data, typ=win32api.RegQueryValueEx(hkey, value_name)
            self.assertEqual(typ, orig_type)
            self.assertEqual(data, orig_data)
selecttlb.py 文件源码 项目:OSPTF 作者: xSploited 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        try:
            item = win32api.RegEnumKey(root, index)
        except win32api.error:
            break
        try:
            # Note this doesn't handle REG_EXPAND_SZ, but the implementation
            # here doesn't need to - that is handled as the data is read.
            val = win32api.RegQueryValue(root, item)
        except win32api.error:
            val = "" # code using this assumes a string.

        ret.append((item, val))
        index = index + 1
    return ret
selecttlb.py 文件源码 项目:pupy 作者: ru-faraon 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        try:
            item = win32api.RegEnumKey(root, index)
        except win32api.error:
            break
        try:
            # Note this doesn't handle REG_EXPAND_SZ, but the implementation
            # here doesn't need to - that is handled as the data is read.
            val = win32api.RegQueryValue(root, item)
        except win32api.error:
            val = "" # code using this assumes a string.

        ret.append((item, val))
        index = index + 1
    return ret
selecttlb.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        try:
            item = win32api.RegEnumKey(root, index)
        except win32api.error:
            break
        try:
            # Note this doesn't handle REG_EXPAND_SZ, but the implementation
            # here doesn't need to - that is handled as the data is read.
            val = win32api.RegQueryValue(root, item)
        except win32api.error:
            val = "" # code using this assumes a string.

        ret.append((item, val))
        index = index + 1
    return ret
test_win32api.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testValues(self):
        key_name = r'PythonTestHarness\win32api'
        ## tuples containing value name, value type, data
        values=(
            (None, win32con.REG_SZ, 'This is default unnamed value'),
            ('REG_SZ', win32con.REG_SZ,'REG_SZ text data'),
            ('REG_EXPAND_SZ', win32con.REG_EXPAND_SZ, '%systemdir%'),
            ## REG_MULTI_SZ value needs to be a list since strings are returned as a list
            ('REG_MULTI_SZ', win32con.REG_MULTI_SZ, ['string 1','string 2','string 3','string 4']),
            ('REG_MULTI_SZ_empty', win32con.REG_MULTI_SZ, []),
            ('REG_DWORD', win32con.REG_DWORD, 666),
            ('REG_QWORD', win32con.REG_QWORD, 2**33),
            ('REG_BINARY', win32con.REG_BINARY, str2bytes('\x00\x01\x02\x03\x04\x05\x06\x07\x08\x01\x00')),
            )

        hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, key_name)
        for value_name, reg_type, data in values:
            win32api.RegSetValueEx(hkey, value_name, None, reg_type, data)

        for value_name, orig_type, orig_data in values:
            data, typ=win32api.RegQueryValueEx(hkey, value_name)
            self.assertEqual(typ, orig_type)
            self.assertEqual(data, orig_data)
selecttlb.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def EnumKeys(root):
    index = 0
    ret = []
    while 1:
        try:
            item = win32api.RegEnumKey(root, index)
        except win32api.error:
            break
        try:
            # Note this doesn't handle REG_EXPAND_SZ, but the implementation
            # here doesn't need to - that is handled as the data is read.
            val = win32api.RegQueryValue(root, item)
        except win32api.error:
            val = "" # code using this assumes a string.

        ret.append((item, val))
        index = index + 1
    return ret
win32evtlogutil.py 文件源码 项目:purelove 作者: hucmosin 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def AddSourceToRegistry(appName, msgDLL = None, eventLogType = "Application", eventLogFlags = None):
    """Add a source of messages to the event log.

    Allows Python program to register a custom source of messages in the
    registry.  You must also provide the DLL name that has the message table, so the
    full message text appears in the event log.

    Note that the win32evtlog.pyd file has a number of string entries with just "%1"
    built in, so many Python programs can simply use this DLL.  Disadvantages are that
    you do not get language translation, and the full text is stored in the event log,
    blowing the size of the log up.
    """

    # When an application uses the RegisterEventSource or OpenEventLog
    # function to get a handle of an event log, the event loggging service
    # searches for the specified source name in the registry. You can add a
    # new source name to the registry by opening a new registry subkey
    # under the Application key and adding registry values to the new
    # subkey.

    if msgDLL is None:
        msgDLL = win32evtlog.__file__

    # Create a new key for our application
    hkey = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, \
        "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (eventLogType, appName))

    # Add the Event-ID message-file name to the subkey.
    win32api.RegSetValueEx(hkey,
        "EventMessageFile",    # value name \
        0,                     # reserved \
        win32con.REG_EXPAND_SZ,# value type \
        msgDLL)

    # Set the supported types flags and add it to the subkey.
    if eventLogFlags is None:
        eventLogFlags = win32evtlog.EVENTLOG_ERROR_TYPE | win32evtlog.EVENTLOG_WARNING_TYPE | win32evtlog.EVENTLOG_INFORMATION_TYPE
    win32api.RegSetValueEx(hkey, # subkey handle \
        "TypesSupported",        # value name \
        0,                       # reserved \
        win32con.REG_DWORD,      # value type \
        eventLogFlags)
    win32api.RegCloseKey(hkey)
selecttlb.py 文件源码 项目:OSPTF 作者: xSploited 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def EnumTlbs(excludeFlags = 0):
    """Return a list of TypelibSpec objects, one for each registered library.
    """
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "Typelib")
    iids = EnumKeys(key)
    results = []
    for iid, crap in iids:
        try:
            key2 = win32api.RegOpenKey(key, str(iid))
        except win32api.error:
            # A few good reasons for this, including "access denied".
            continue
        for version, tlbdesc in EnumKeys(key2):
            major_minor = version.split('.', 1)
            if len(major_minor) < 2:
                major_minor.append('0')
            # For some reason, this code used to assume the values were hex.
            # This seems to not be true - particularly for CDO 1.21
            # *sigh* - it appears there are no rules here at all, so when we need
            # to know the info, we must load the tlb by filename and request it.
            # The Resolve() method on the TypelibSpec does this.
            # For this reason, keep the version numbers as strings - that
            # way we can't be wrong!  Let code that really needs an int to work
            # out what to do.  FWIW, http://support.microsoft.com/kb/816970 is
            # pretty clear that they *should* be hex.
            major = major_minor[0]
            minor = major_minor[1]
            key3 = win32api.RegOpenKey(key2, str(version))
            try:
                # The "FLAGS" are at this point
                flags = int(win32api.RegQueryValue(key3, "FLAGS"))
            except (win32api.error, ValueError):
                flags = 0
            if flags & excludeFlags==0:
                for lcid, crap in EnumKeys(key3):
                    try:
                        lcid = int(lcid)
                    except ValueError: # not an LCID entry
                        continue
                    # Only care about "{lcid}\win32" key - jump straight there.
                    try:
                        key4 = win32api.RegOpenKey(key3, "%s\\win32" % (lcid,))
                    except win32api.error:
                        continue
                    try:
                        dll, typ = win32api.RegQueryValueEx(key4, None)
                        if typ==win32con.REG_EXPAND_SZ:
                            dll = win32api.ExpandEnvironmentStrings(dll)
                    except win32api.error:
                        dll = None
                    spec = TypelibSpec(iid, lcid, major, minor, flags)
                    spec.dll = dll
                    spec.desc = tlbdesc
                    spec.ver_desc = tlbdesc + " (" + version + ")"
                    results.append(spec)
    return results
selecttlb.py 文件源码 项目:pupy 作者: ru-faraon 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def EnumTlbs(excludeFlags = 0):
    """Return a list of TypelibSpec objects, one for each registered library.
    """
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "Typelib")
    iids = EnumKeys(key)
    results = []
    for iid, crap in iids:
        try:
            key2 = win32api.RegOpenKey(key, str(iid))
        except win32api.error:
            # A few good reasons for this, including "access denied".
            continue
        for version, tlbdesc in EnumKeys(key2):
            major_minor = version.split('.', 1)
            if len(major_minor) < 2:
                major_minor.append('0')
            # For some reason, this code used to assume the values were hex.
            # This seems to not be true - particularly for CDO 1.21
            # *sigh* - it appears there are no rules here at all, so when we need
            # to know the info, we must load the tlb by filename and request it.
            # The Resolve() method on the TypelibSpec does this.
            # For this reason, keep the version numbers as strings - that
            # way we can't be wrong!  Let code that really needs an int to work
            # out what to do.  FWIW, http://support.microsoft.com/kb/816970 is
            # pretty clear that they *should* be hex.
            major = major_minor[0]
            minor = major_minor[1]
            key3 = win32api.RegOpenKey(key2, str(version))
            try:
                # The "FLAGS" are at this point
                flags = int(win32api.RegQueryValue(key3, "FLAGS"))
            except (win32api.error, ValueError):
                flags = 0
            if flags & excludeFlags==0:
                for lcid, crap in EnumKeys(key3):
                    try:
                        lcid = int(lcid)
                    except ValueError: # not an LCID entry
                        continue
                    # Only care about "{lcid}\win32" key - jump straight there.
                    try:
                        key4 = win32api.RegOpenKey(key3, "%s\\win32" % (lcid,))
                    except win32api.error:
                        continue
                    try:
                        dll, typ = win32api.RegQueryValueEx(key4, None)
                        if typ==win32con.REG_EXPAND_SZ:
                            dll = win32api.ExpandEnvironmentStrings(dll)
                    except win32api.error:
                        dll = None
                    spec = TypelibSpec(iid, lcid, major, minor, flags)
                    spec.dll = dll
                    spec.desc = tlbdesc
                    spec.ver_desc = tlbdesc + " (" + version + ")"
                    results.append(spec)
    return results
win32evtlogutil.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def AddSourceToRegistry(appName, msgDLL = None, eventLogType = "Application", eventLogFlags = None):
    """Add a source of messages to the event log.

    Allows Python program to register a custom source of messages in the
    registry.  You must also provide the DLL name that has the message table, so the
    full message text appears in the event log.

    Note that the win32evtlog.pyd file has a number of string entries with just "%1"
    built in, so many Python programs can simply use this DLL.  Disadvantages are that
    you do not get language translation, and the full text is stored in the event log,
    blowing the size of the log up.
    """

    # When an application uses the RegisterEventSource or OpenEventLog
    # function to get a handle of an event log, the event loggging service
    # searches for the specified source name in the registry. You can add a
    # new source name to the registry by opening a new registry subkey
    # under the Application key and adding registry values to the new
    # subkey.

    if msgDLL is None:
        msgDLL = win32evtlog.__file__

    # Create a new key for our application
    hkey = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, \
        "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (eventLogType, appName))

    # Add the Event-ID message-file name to the subkey.
    win32api.RegSetValueEx(hkey,
        "EventMessageFile",    # value name \
        0,                     # reserved \
        win32con.REG_EXPAND_SZ,# value type \
        msgDLL)

    # Set the supported types flags and add it to the subkey.
    if eventLogFlags is None:
        eventLogFlags = win32evtlog.EVENTLOG_ERROR_TYPE | win32evtlog.EVENTLOG_WARNING_TYPE | win32evtlog.EVENTLOG_INFORMATION_TYPE
    win32api.RegSetValueEx(hkey, # subkey handle \
        "TypesSupported",        # value name \
        0,                       # reserved \
        win32con.REG_DWORD,      # value type \
        eventLogFlags)
    win32api.RegCloseKey(hkey)
selecttlb.py 文件源码 项目:remoteControlPPT 作者: htwenning 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def EnumTlbs(excludeFlags = 0):
    """Return a list of TypelibSpec objects, one for each registered library.
    """
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "Typelib")
    iids = EnumKeys(key)
    results = []
    for iid, crap in iids:
        try:
            key2 = win32api.RegOpenKey(key, str(iid))
        except win32api.error:
            # A few good reasons for this, including "access denied".
            continue
        for version, tlbdesc in EnumKeys(key2):
            major_minor = version.split('.', 1)
            if len(major_minor) < 2:
                major_minor.append('0')
            # For some reason, this code used to assume the values were hex.
            # This seems to not be true - particularly for CDO 1.21
            # *sigh* - it appears there are no rules here at all, so when we need
            # to know the info, we must load the tlb by filename and request it.
            # The Resolve() method on the TypelibSpec does this.
            # For this reason, keep the version numbers as strings - that
            # way we can't be wrong!  Let code that really needs an int to work
            # out what to do.  FWIW, http://support.microsoft.com/kb/816970 is
            # pretty clear that they *should* be hex.
            major = major_minor[0]
            minor = major_minor[1]
            key3 = win32api.RegOpenKey(key2, str(version))
            try:
                # The "FLAGS" are at this point
                flags = int(win32api.RegQueryValue(key3, "FLAGS"))
            except (win32api.error, ValueError):
                flags = 0
            if flags & excludeFlags==0:
                for lcid, crap in EnumKeys(key3):
                    try:
                        lcid = int(lcid)
                    except ValueError: # not an LCID entry
                        continue
                    # Only care about "{lcid}\win32" key - jump straight there.
                    try:
                        key4 = win32api.RegOpenKey(key3, "%s\\win32" % (lcid,))
                    except win32api.error:
                        continue
                    try:
                        dll, typ = win32api.RegQueryValueEx(key4, None)
                        if typ==win32con.REG_EXPAND_SZ:
                            dll = win32api.ExpandEnvironmentStrings(dll)
                    except win32api.error:
                        dll = None
                    spec = TypelibSpec(iid, lcid, major, minor, flags)
                    spec.dll = dll
                    spec.desc = tlbdesc
                    spec.ver_desc = tlbdesc + " (" + version + ")"
                    results.append(spec)
    return results
win32evtlogutil.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def AddSourceToRegistry(appName, msgDLL = None, eventLogType = "Application", eventLogFlags = None):
    """Add a source of messages to the event log.

    Allows Python program to register a custom source of messages in the
    registry.  You must also provide the DLL name that has the message table, so the
    full message text appears in the event log.

    Note that the win32evtlog.pyd file has a number of string entries with just "%1"
    built in, so many Python programs can simply use this DLL.  Disadvantages are that
    you do not get language translation, and the full text is stored in the event log,
    blowing the size of the log up.
    """

    # When an application uses the RegisterEventSource or OpenEventLog
    # function to get a handle of an event log, the event loggging service
    # searches for the specified source name in the registry. You can add a
    # new source name to the registry by opening a new registry subkey
    # under the Application key and adding registry values to the new
    # subkey.

    if msgDLL is None:
        msgDLL = win32evtlog.__file__

    # Create a new key for our application
    hkey = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, \
        "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (eventLogType, appName))

    # Add the Event-ID message-file name to the subkey.
    win32api.RegSetValueEx(hkey,
        "EventMessageFile",    # value name \
        0,                     # reserved \
        win32con.REG_EXPAND_SZ,# value type \
        msgDLL)

    # Set the supported types flags and add it to the subkey.
    if eventLogFlags is None:
        eventLogFlags = win32evtlog.EVENTLOG_ERROR_TYPE | win32evtlog.EVENTLOG_WARNING_TYPE | win32evtlog.EVENTLOG_INFORMATION_TYPE
    win32api.RegSetValueEx(hkey, # subkey handle \
        "TypesSupported",        # value name \
        0,                       # reserved \
        win32con.REG_DWORD,      # value type \
        eventLogFlags)
    win32api.RegCloseKey(hkey)
selecttlb.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def EnumTlbs(excludeFlags = 0):
    """Return a list of TypelibSpec objects, one for each registered library.
    """
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, "Typelib")
    iids = EnumKeys(key)
    results = []
    for iid, crap in iids:
        try:
            key2 = win32api.RegOpenKey(key, str(iid))
        except win32api.error:
            # A few good reasons for this, including "access denied".
            continue
        for version, tlbdesc in EnumKeys(key2):
            major_minor = version.split('.', 1)
            if len(major_minor) < 2:
                major_minor.append('0')
            # For some reason, this code used to assume the values were hex.
            # This seems to not be true - particularly for CDO 1.21
            # *sigh* - it appears there are no rules here at all, so when we need
            # to know the info, we must load the tlb by filename and request it.
            # The Resolve() method on the TypelibSpec does this.
            # For this reason, keep the version numbers as strings - that
            # way we can't be wrong!  Let code that really needs an int to work
            # out what to do.  FWIW, http://support.microsoft.com/kb/816970 is
            # pretty clear that they *should* be hex.
            major = major_minor[0]
            minor = major_minor[1]
            key3 = win32api.RegOpenKey(key2, str(version))
            try:
                # The "FLAGS" are at this point
                flags = int(win32api.RegQueryValue(key3, "FLAGS"))
            except (win32api.error, ValueError):
                flags = 0
            if flags & excludeFlags==0:
                for lcid, crap in EnumKeys(key3):
                    try:
                        lcid = int(lcid)
                    except ValueError: # not an LCID entry
                        continue
                    # Only care about "{lcid}\win32" key - jump straight there.
                    try:
                        key4 = win32api.RegOpenKey(key3, "%s\\win32" % (lcid,))
                    except win32api.error:
                        continue
                    try:
                        dll, typ = win32api.RegQueryValueEx(key4, None)
                        if typ==win32con.REG_EXPAND_SZ:
                            dll = win32api.ExpandEnvironmentStrings(dll)
                    except win32api.error:
                        dll = None
                    spec = TypelibSpec(iid, lcid, major, minor, flags)
                    spec.dll = dll
                    spec.desc = tlbdesc
                    spec.ver_desc = tlbdesc + " (" + version + ")"
                    results.append(spec)
    return results


问题


面经


文章

微信
公众号

扫码关注公众号