Last active
May 13, 2024 07:17
-
-
Save chrislattman/3e828429e653f36d465fc1dd588a4c3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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