Skip to content

Commit 15e3c00

Browse files
committed
Add hook for EtwNotificationRegister
1 parent 462f68a commit 15e3c00

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

qiling/os/windows/dlls/ntdll.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,4 +718,41 @@ def __post_exception_filter(ql: Qiling):
718718
# doesn't rewind after it returns. However, this is not entirely intended
719719
# behavior of passthru, so this is a bit of a hack. Maybe find some
720720
# way to rewrite without passthru.
721-
ql.os.fcall.call_native(exception_filter, exception_filter_args, ret_addr)
721+
ql.os.fcall.call_native(exception_filter, exception_filter_args, ret_addr)
722+
723+
# NTSTATUS EtwNotificationRegister(
724+
# LPCGUID ProviderGuid,
725+
# ULONG Type,
726+
# PVOID CallbackFunction,
727+
# PVOID CallbackContext,
728+
# PVOID* RegistrationHandle
729+
# );
730+
@winsdkapi(cc=STDCALL, params={
731+
'ProviderGuid': PVOID,
732+
'Type': DWORD,
733+
'CallbackFunction': PVOID,
734+
'CallbackContext': PVOID,
735+
'RegistrationHandle': PVOID
736+
})
737+
def hook_EtwNotificationRegister(ql: Qiling, address: int, params):
738+
reg_handle_ptr = params['RegistrationHandle']
739+
740+
# It is very important to have a hook for this function
741+
# because it is called by some Windows DLLs (sechost.dll,
742+
# advapi32.dll) during initialization when the global
743+
# CRT lock is held.
744+
# If a DllMain aborts here, then the global CRT lock is never
745+
# freed and any attempt to lock the global CRT lock *anywhere*
746+
# will crash us.
747+
748+
# TODO: See if a more thorough implementation
749+
# is needed for this function.
750+
751+
# For now, just create a dummy handle, and return it.
752+
handle = Handle()
753+
ql.os.handle_manager.append(handle)
754+
755+
if reg_handle_ptr:
756+
ql.mem.write_ptr(reg_handle_ptr, handle.id)
757+
758+
return STATUS_SUCCESS

0 commit comments

Comments
 (0)