Pages

Monday, May 18, 2015

[C/C++] Native application

Inspired from Mark Russinovich's work - Sysinternals.
http://technet.microsoft.com/en-us/sysinternals/bb897447.aspx

 
#pragma comment(linker, "/ENTRY:NtProcessStartup")
#pragma comment(linker, "/SUBSYSTEM:NATIVE")

#include <ntdll.h>
#define msg L" Application\nHello from Native World!"

void NtProcessStartup() {
#ifdef _WIN64
    PWSTR nativeMsg = L"64-bit" msg;
#else
    PWSTR nativeMsg = L"32-bit" msg;
#endif

    UNICODE_STRING unicodeBuffer;
    LARGE_INTEGER Interval;

    RtlInitUnicodeString(
        &unicodeBuffer,
        nativeMsg);

    NtDisplayString(&unicodeBuffer);

    Interval.QuadPart = -150000000;
    NtDelayExecution(FALSE, &Interval);

    NtTerminateProcess(NtCurrentProcess(), 0);
}

Source:
http://www.mediafire.com/download/awlcenbw5um4wo6/native.rar