Skip to content

Add \Device\KsecDD emulation and mask 32-bit syscall arguments#1

Closed
ELJoOker2004 wants to merge 6 commits into
AdvDebug:mainfrom
ELJoOker2004:fix/syscall-arg-masking-ksecdd
Closed

Add \Device\KsecDD emulation and mask 32-bit syscall arguments#1
ELJoOker2004 wants to merge 6 commits into
AdvDebug:mainfrom
ELJoOker2004:fix/syscall-arg-masking-ksecdd

Conversation

@ELJoOker2004
Copy link
Copy Markdown
Contributor

This fixes the issue I faced when testing where my ntdll version was newer, I think, so the process aborted during initialization and never reached main. Two root causes:

  • \Device\KsecDD wasn't emulated. bcrypt/CNG opens this device from its DllMain during process init; the failed open made the DllMain return FALSE, so the loader aborted the whole process with STATUS_DLL_INIT_FAILED.
  • Several 32‑bit (ULONG) syscall arguments were read as 64‑bit. Per the x64 syscall ABI the upper 32 bits of a 32‑bit argument are undefined, and on newer ntdll builds they contain garbage. Reading them as full 64‑bit values made handler checks (e.g. count != 0, protection/flag comparisons) see bogus values and return spurious errors like STATUS_INVALID_PARAMETER.

Can you please verify before merge?

- Emulate \Device\KsecDD (RNG + memory encrypt/decrypt) so the bcrypt/CNG
  DllMain succeeds during Windows PE process initialization.
- Mask ULONG syscall arguments that were read as 64-bit; some ntdll builds
  leave garbage in the upper 32 bits, which broke handler argument checks.
@AdvDebug
Copy link
Copy Markdown
Owner

AdvDebug commented Jun 4, 2026

Looks good to go. can you just remove the unnecessary comments in the code?

@AdvDebug
Copy link
Copy Markdown
Owner

AdvDebug commented Jun 4, 2026

Looks like the commit doesn't align with the latest changes in the repo, can you also fix that?

@AdvDebug AdvDebug closed this Jun 4, 2026
@AdvDebug
Copy link
Copy Markdown
Owner

AdvDebug commented Jun 4, 2026

Sorry but this breaks the build, can you re-fork it and add your changes again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants