Why is the kernel pre loading not only the system32\ntdll.dll but also the syswow64\ntdll.dll into x86 processes?

David Xanatos 6 Reputation points
2022-03-20T23:05:23.977+00:00

Why is the kernel pre loading not only the system32\ntdll.dll but also the syswow64\ntdll.dll into x86 processes?
Why can't the native ntdll.dll just load the wow version on its own in LdrpInitializeProcess?

I am asking because I was looking into hooking of system functions on ARM64 when running as a x86 process, and have noticed that the CHPE versions of the system dll's unlike for x64 on arm do not seam to take the control flow through the x86 stubs when doing things internally.

So I can't for example hook NtCreateFile and expect that hook to be triggered when calling CreateFileW, this is a problem.

I have noticed that when I delete the SyChpe32 directory windows is loading the x86 version of the ntdll which can be hooked just fine.

But obviously this is a unpractical solution, so I was wondering if I could hook LdrpInitializeProcess of the native arm64 ntdll.dll and unload the SyChpe32\ntdll.dll in my target process and instead load the SysWOW64\ntdll.dll in its place, but given that the other ntdll is pre loaded by the kernel I wonder if this approach is even feasible or if there is something that will prevent it from working?

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,921 Reputation points
    2022-03-24T17:51:26.55+00:00

    Hi @David Xanatos

    I don't believe that this approach is feasible. You could try the concepts and ideas in this article:

    https://learn.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details

    --------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.