Beispiel #1
0
def resolveMUITimeZone(spec):
    """Resolve a multilingual user interface resource for the time zone name
	>>> #some pre-amble for the doc-tests to be py2k and py3k aware)
	>>> try: unicode and None
	... except NameError: unicode=str
	...
	>>> import sys
	>>> result = resolveMUITimeZone('@tzres.dll,-110')
	>>> expectedResultType = [type(None),unicode][sys.getwindowsversion() >= (6,)]
	>>> type(result) is expectedResultType
	True

	spec should be of the format @path,-stringID[;comment]
	see http://msdn2.microsoft.com/en-us/library/ms725481.aspx for details
	"""
    pattern = re.compile(
        '@(?P<dllname>.*),-(?P<index>\d+)(?:;(?P<comment>.*))?')
    matcher = pattern.match(spec)
    assert matcher, 'Could not parse MUI spec'

    try:
        handle = DLLCache[matcher.groupdict()['dllname']]
        result = win32api.LoadString(handle, int(matcher.groupdict()['index']))
    except win32api.error:
        result = None
    return result
Beispiel #2
0
 def get_text(self, text_id):
     if win32api is None or pywintypes is None:
         return None
     try:
         return win32api.LoadString(self.library, text_id)
     except pywintypes.error:
         return None
Beispiel #3
0
def load_string_resource(pointer):
    """Resolve a @dllname,ordinal string resource pointer"""

    if pointer[0] != "@":
        return pointer

    resfile, resid = pointer[1:].split(",")
    resid = int(resid)

    hRes = Api.LoadLibraryEx(resfile, 0, Con.LOAD_LIBRARY_AS_DATAFILE)
    val = Api.LoadString(hRes, -resid, 1024)
    Api.FreeLibrary(hRes)

    return val.split('\x00', 1)[0]
Beispiel #4
0
 def get(self, ids):
     """get(self, ids)
     Returns the string and html resources for the specified ids as a
     tuple(string, string)
     """
     ids = ids % _MAXI
     # pylint: disable=E1101
     try:
         string = w32.LoadString(self._dll, ids)
     except pywintypes.error:
         string = None
     try:
         html = unicode(w32.LoadResource(self._dll, 23, ids, 1033),
                        encoding='UTF-16')
     except pywintypes.error:
         html = None
     return string, html
def read_mui_string_from_dll(id):
    assert id.startswith("@") and ",-" in id, \
           "id has invalid format. Expected format is '@dllfilename,-id'"

    m = re.match("@([^,]+),-([0-9]+)(;.*)?", id)
    if m:
        dll_filename = _expand_path_variables(m.group(1))
        string_id = long(m.group(2))
    else:
        raise Exception("Error parsing dll-filename and string-resource-id from '%s'" % id)

    h = win32api.LoadLibraryEx(
        dll_filename,
        None,
        win32con.LOAD_LIBRARY_AS_DATAFILE | win32con.DONT_RESOLVE_DLL_REFERENCES)
    if h:
        s = win32api.LoadString(h, string_id)
        return s
    return None
def extract_strings_from_dll(dll_filename, output_filename):
    if os.path.isfile(output_filename):
        print "ERROR: File %s already exists." % output_filename
        return 0

    h = win32api.LoadLibraryEx(
        dll_filename,
        None,
        win32con.LOAD_LIBRARY_AS_DATAFILE | win32con.DONT_RESOLVE_DLL_REFERENCES)
    if not h:
        return 0

    dll_filename = os.path.basename(dll_filename)

    extracted = 0
    #strings = []

    with open(output_filename, "w+") as output_file:
        #for id in win32api.EnumResourceNames(h, win32con.RT_STRING):
        for id in range(0, 9999999):
            try:
                s = win32api.LoadString(h, id)
                if s == "%s":
                    continue
            except Exception, e:
                continue
            s = unicodedata.normalize(
                'NFKD',
                s
                ).encode('ascii', 'ignore').lower()

            if "&" in s:
                s = s.replace("&", "")
            #print id, s
            #strings.append((id, s))
            output_file.write("%d: %s\n" % (id, s))

            extracted += 1
                        # Descriptions are in Unicode
                        name = newcplinfo.u.szStringsW.szName.decode("utf-8")
                        info = newcplinfo.u.szStringsW.szInfo.decode("utf-8")

                if not name and not info:
                    cplinfo = self.CPLINFO()
                    try:
                        cpl_applet(0, self.CPL_INQUIRE, dialog_i, ctypes.byref(cplinfo))
                    except Exception, e:
                        print "4:", filename, e

                    handle = None
                    result = None
                    try:
                        handle = win32api.LoadLibrary(filename)
                        name = win32api.LoadString(handle, cplinfo.idName).strip(" \n\0")
                        info = win32api.LoadString(handle, cplinfo.idInfo).strip(" \n\0")
                    finally:
                        if handle:
                            win32api.FreeLibrary(handle)

                result = (
                    os.path.basename(filename),
                    name,
                    info,
                    dialog_i)
                yield result
        except Exception, e:
            print e
            pass
        finally: