Skip to content

Commit 5eaea98

Browse files
authored
Merge pull request #1227 from ucgJhe/dev
allow user to build config from dictionary other than disk file
2 parents dd1aff9 + 0a74071 commit 5eaea98

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

qiling/utils.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,32 +404,35 @@ def select_os(ostype: QL_OS) -> QlClassInit['QlOs']:
404404

405405
return partial(obj)
406406

407-
def profile_setup(ostype: QL_OS, filename: Optional[str]):
407+
def profile_setup(ostype: QL_OS, user_config: Optional[Union[str, dict]]):
408408
# mcu uses a yaml-based config
409409
if ostype == QL_OS.MCU:
410410
import yaml
411411

412-
if filename:
413-
with open(filename) as f:
412+
if user_config:
413+
with open(user_config) as f:
414414
config = yaml.load(f, Loader=yaml.Loader)
415415
else:
416416
config = {}
417417

418418
else:
419+
# patch 'getint' to convert integers of all bases
420+
int_converter = partial(int, base=0)
421+
config = ConfigParser(converters={'int': int_converter})
422+
419423
qiling_home = Path(inspect.getfile(inspect.currentframe())).parent
420424
os_profile = qiling_home / 'profiles' / f'{ostype.name.lower()}.ql'
421425

422-
profiles = [os_profile]
423-
424-
if filename:
425-
profiles.append(filename)
426+
# read default profile first
427+
config.read(os_profile)
426428

427-
# patch 'getint' to convert integers of all bases
428-
int_converter = partial(int, base=0)
429-
430-
config = ConfigParser(converters={'int': int_converter})
431-
config.read(profiles)
429+
# user-specified profile adds or overrides existing setting
430+
if isinstance(user_config, dict):
431+
config.read_dict(user_config)
432432

433+
elif user_config:
434+
config.read(user_config)
435+
433436
return config
434437

435438
# verify if emulator returns properly

0 commit comments

Comments
 (0)