|
12 | 12 | import importlib, os |
13 | 13 |
|
14 | 14 | from configparser import ConfigParser |
| 15 | +from types import ModuleType |
15 | 16 | from typing import TYPE_CHECKING, Any, Callable, Mapping, Optional, Tuple, TypeVar, Union |
16 | 17 |
|
17 | 18 | from unicorn import UC_ERR_READ_UNMAPPED, UC_ERR_FETCH_UNMAPPED |
@@ -66,24 +67,23 @@ def debugger_convert(debugger: str) -> Optional[QL_DEBUGGER]: |
66 | 67 | def arch_os_convert(arch: QL_ARCH) -> Optional[QL_OS]: |
67 | 68 | return arch_os_map.get(arch) |
68 | 69 |
|
69 | | -# Call `function_name` in `module_name`. |
70 | | -# e.g. map_syscall in qiling.os.linux.map_syscall |
71 | | -def ql_get_module_function(module_name: str, function_name: str): |
72 | | - |
| 70 | +def ql_get_module(module_name: str) -> ModuleType: |
73 | 71 | try: |
74 | | - imp_module = importlib.import_module(module_name, 'qiling') |
75 | | - except ModuleNotFoundError: |
76 | | - raise QlErrorModuleNotFound(f'Unable to import module {module_name}') |
77 | | - except KeyError: |
| 72 | + module = importlib.import_module(module_name, 'qiling') |
| 73 | + except (ModuleNotFoundError, KeyError): |
78 | 74 | raise QlErrorModuleNotFound(f'Unable to import module {module_name}') |
79 | 75 |
|
| 76 | + return module |
| 77 | + |
| 78 | +def ql_get_module_function(module_name: str, member_name: str): |
| 79 | + module = ql_get_module(module_name) |
| 80 | + |
80 | 81 | try: |
81 | | - module_function = getattr(imp_module, function_name) |
| 82 | + member = getattr(module, member_name) |
82 | 83 | except AttributeError: |
83 | | - raise QlErrorModuleFunctionNotFound(f'Unable to import {function_name} from {imp_module}') |
84 | | - |
85 | | - return module_function |
| 84 | + raise QlErrorModuleFunctionNotFound(f'Unable to import {member_name} from {module_name}') |
86 | 85 |
|
| 86 | + return member |
87 | 87 |
|
88 | 88 | def __emu_env_from_pathname(path: str) -> Tuple[Optional[QL_ARCH], Optional[QL_OS], Optional[QL_ENDIAN]]: |
89 | 89 | if os.path.isdir(path) and path.endswith('.kext'): |
|
0 commit comments