Add NT syscall wrappers, document coverage, and add console-logon utility#1
Add NT syscall wrappers, document coverage, and add console-logon utility#1thepanoc95 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces NT Native API syscall wrappers in ntos2nd and a PowerShell utility for toggling console logon. The review identifies several critical issues in the syscall wrapper implementation, specifically regarding incorrect syscall constant usage, improper mapping of Win32 return codes to NTSTATUS, and type safety mismatches in the header file. Furthermore, the PowerShell script lacks the necessary permission handling to modify system-protected files, and the documentation for the new C wrappers is incorrectly placed within the Rust-specific section of the README.
| NTSTATUS status = NTOS2NDHandleSyscall(NULL, SYSCALL_NtClose, params, 1, &result); | ||
| return NT_SUCCESS(status) ? (NTSTATUS)result : status; |
There was a problem hiding this comment.
There are several critical issues with the syscall wrapper implementation here:
- Syscall Number Mismatch:
NTOS2NDHandleSyscall(defined inkernel.c) handlesNTOS2ND_SYS_*constants, but this code passesSYSCALL_Nt*constants. These are handled by a different dispatcher insyscall.c. This will cause the wrappers to returnSTATUS_NOT_IMPLEMENTED. - Incorrect Return Value: For
NtClose,resultis a boolean (1 for success, 0 for failure) fromCloseHandle. Returning this as anNTSTATUSis incorrect; success should returnSTATUS_SUCCESS(0). - Win32 vs NTSTATUS:
NTOS2NDHandleSyscallreturns Win32 error codes (e.g., 5 for Access Denied). TheNT_SUCCESSmacro incorrectly treats these positive values as success, as it only checks if the value is non-negative.
| } | ||
|
|
||
| if ($PSCmdlet.ShouldProcess($Path, "Rename to $disabledPath")) { | ||
| Rename-Item -LiteralPath $Path -NewName ([System.IO.Path]::GetFileName($disabledPath)) -ErrorAction Stop |
There was a problem hiding this comment.
| NTSTATUS NTAPI NtOpenProcessWrap(PHANDLE ProcessHandle, ACCESS_MASK DesiredAccess, void* ObjectAttributes, void* ClientId); | ||
| NTSTATUS NTAPI NtReadFileWrap(HANDLE FileHandle, HANDLE Event, PVOID ApcRoutine, PVOID ApcContext, void* IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key); | ||
| NTSTATUS NTAPI NtWriteFileWrap(HANDLE FileHandle, HANDLE Event, PVOID ApcRoutine, PVOID ApcContext, void* IoStatusBlock, const VOID* Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key); | ||
| NTSTATUS NTAPI NtAllocateVirtualMemoryWrap(HANDLE ProcessHandle, PVOID* BaseAddress, ULONG_PTR ZeroBits, PSIZE_T RegionSize, ULONG AllocationType, ULONG Protect); |
There was a problem hiding this comment.
| ### NT Native Wrapper Coverage | ||
|
|
||
| `NTCall.c` provides direct wrapper entry points routed through `NTOS2NDHandleSyscall`. | ||
| Current wrappers include: | ||
|
|
||
| - `NtCloseWrap` | ||
| - `NtOpenProcessWrap` | ||
| - `NtReadFileWrap` | ||
| - `NtWriteFileWrap` | ||
| - `NtAllocateVirtualMemoryWrap` | ||
|
|
||
| These wrappers are declared in `NTCall.h` for consumers embedding ntos2nd. |
Motivation
NTOS2NDHandleSyscall.authui.dllfor online or offline Windows roots.Description
ntos2nd/NTCall.cwhich implementsNtCloseWrap,NtOpenProcessWrap,NtReadFileWrap,NtWriteFileWrap, andNtAllocateVirtualMemoryWrapusingNTOS2NDHandleSyscalland handle/pointer translation.ntos2nd/NTCall.hdeclaring the new wrappers for consumers embeddingntos2nd.ntos2nd/CMakeLists.txtto install the new header by addingNTCall.hto the headers list.ntos2nd/README.mdand top-levelREADME.mdto document the new NT wrapper coverage and to document the new utility scripts section.utils/Enable-ConsoleLogon.ps1, a PowerShell script that can disable or restoreauthui.dllinSystem32andSysWOW64for the current system or an offline Windows root.mswindows/shell/LibreNT.Shell.csprojby removing explicit<Compile>includes so the SDK auto-includes source files.Testing
Codex Task