Skip to content

Commit 7546dda

Browse files
committed
Improve execute_protocol_notifications
1 parent 0637504 commit 7546dda

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

qiling/os/uefi/utils.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,37 @@ def signal_event(ql: Qiling, event_id: int) -> None:
2525

2626
ql.loader.notify_list.append((event_id, notify_func, callback_args))
2727

28-
def execute_protocol_notifications(ql: Qiling, from_hook=False) -> bool:
28+
def execute_protocol_notifications(ql: Qiling, from_hook: bool = False) -> bool:
2929
if not ql.loader.notify_list:
3030
return False
3131

32-
next_hook = ql.loader.smm_context.heap.alloc(1)
32+
next_hook = ql.loader.smm_context.heap.alloc(ql.pointersize)
3333

34-
def exec_next(ql: Qiling):
34+
def __notify_next(ql: Qiling):
3535
if ql.loader.notify_list:
3636
event_id, notify_func, callback_args = ql.loader.notify_list.pop(0)
37-
ql.log.info(f'Notify event:{event_id} calling: 0x{notify_func:x} callback_args:{list(map(hex, callback_args))}')
37+
ql.log.info(f'Notify event: id = {event_id}, (*{notify_func:#x})({", ".join(f"{a:#x}" for a in callback_args)})')
38+
3839
ql.loader.call_function(notify_func, callback_args, next_hook)
3940
else:
41+
ql.log.info(f'Notify event: done')
42+
43+
# the last item on the list has been notified; tear down this hook
4044
ql.loader.smm_context.heap.free(next_hook)
41-
ql.hook_address(lambda q: None, next_hook)
45+
hret.remove()
46+
4247
ql.reg.rax = EFI_SUCCESS
48+
ql.reg.arch_sp += (4 * ql.pointersize)
4349
ql.reg.arch_pc = ql.stack_pop()
4450

45-
ql.hook_address(exec_next, next_hook, )
51+
hret = ql.hook_address(__notify_next, next_hook)
52+
53+
# functions with more than 4 parameters expect the extra parameters to appear on
54+
# the stack. allocate room for another 4 parameters, in case one of the fucntions
55+
# will need it
56+
ql.reg.arch_sp -= (4 * ql.pointersize)
4657

47-
# To avoid having two versions of the code the first notify function will also be called from the exec_next hook.
58+
# To avoid having two versions of the code the first notify function will also be called from the __notify_next hook.
4859
if from_hook:
4960
ql.stack_push(next_hook)
5061
else:

0 commit comments

Comments
 (0)