But the syscall numbers on Windows, from release to release, are not stable.
For syscall table in Windows, see: https://github.com/j00ru/windows-syscalls
So I will try my luck for my version of Windows, by debugging two EXEs (PE 64-bit) using IDA Freeware 8.3.
Below is the normal code for a program to exit with errorlevel 7:
CODE
format PE64 console
entry start
include "win64a.inc"
section ".code" code executable readable
start:
mov rcx, 7
call [ExitProcess]
section ".idata" import readable
library kernel, "kernel32.dll"
import kernel, ExitProcess, "ExitProcess"
entry start
include "win64a.inc"
section ".code" code executable readable
start:
mov rcx, 7
call [ExitProcess]
section ".idata" import readable
library kernel, "kernel32.dll"
import kernel, ExitProcess, "ExitProcess"
As you see from above, there is an extra section called "idata", which is import table mandatory for every Win32 programs to be useful.
But today I will just hack it so that the newly created program will be even smaller, and without the import table at all.
After loading the exit.exe (source code listed above), I step into "call [ExitProcess]", and this is what I entered into, RtlExitUserProcess:
RtlExitUserProcess


If I further step into NtTerminateProcess, this is what we see:
Now it uses "syscall" with ID "0x2C" (the syscall number varies from one release of Windows to another)
NtTerminateProcess

After some investigation, I came up with this program, also exit with errorlevel 7:
CODE
format PE64 console
entry start
section ".code" code executable readable
start:
mov rdx, 7
or rcx, 0xFFFFFFFFFFFFFFFF
;xor rcx, rcx
mov r10, rcx
mov rax, 0x2C
syscall
entry start
section ".code" code executable readable
start:
mov rdx, 7
or rcx, 0xFFFFFFFFFFFFFFFF
;xor rcx, rcx
mov r10, rcx
mov rax, 0x2C
syscall
And after I load it in IDA Freeware, this is the output.
Disassembly of NtExit.exe (source code above):

The file size:
CODE
Directory of C:\Users\BOO\Projects
06/12/2023 10:48 PM 1,536 exit.EXE
06/12/2023 10:59 PM 1,024 ntexit.EXE
2 File(s) 2,560 bytes
0 Dir(s) 91,136,335,872 bytes free
06/12/2023 10:48 PM 1,536 exit.EXE
06/12/2023 10:59 PM 1,024 ntexit.EXE
2 File(s) 2,560 bytes
0 Dir(s) 91,136,335,872 bytes free
The NtExit.exe is without extra 512 bytes section of import table.
In summary, it is not practical to use syscall number directly in a Windows program, but I heard some malware are using it. @junyian @KLKS
Thank you for reading!
Jun 12 2023, 11:19 PM, updated 3y ago
Quote

0.0130sec
0.77
5 queries
GZIP Disabled