Skip to content

Instantly share code, notes, and snippets.

@chrislattman
Last active May 13, 2024 07:17
Show Gist options
  • Save chrislattman/3e828429e653f36d465fc1dd588a4c3b to your computer and use it in GitHub Desktop.
Save chrislattman/3e828429e653f36d465fc1dd588a4c3b to your computer and use it in GitHub Desktop.
#include <winternl.h>
#include <Windows.h> // includes GetStdHandle()
#include <string.h>
// #include <stdio.h>
typedef VOID (NTAPI *PIO_APC_ROUTINE)(PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved);
typedef NTSTATUS (NTAPI *NtWriteFile_t)(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length,
PLARGE_INTEGER ByteOffset, PULONG Key);
static NtWriteFile_t write_file = NULL;
int main(void)
{
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
IO_STATUS_BLOCK ioStatus;
const char *str = "Hello, world!\n";
size_t len = strlen(str);
// printf("%s", str);
// WriteConsoleA(stdOut, str, len, NULL, NULL);
// WriteFile(stdOut, str, len, NULL, NULL);
*(void **)(&write_file) = GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtWriteFile");
write_file(stdOut, NULL, NULL, NULL, &ioStatus, (PVOID) str, len, NULL, NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment