Neferences / resources for Nativ apps on XP

I was only able to find an old copy of a source file by Mark Russinovich, as an example of a Native Application.

Does anyone have any references or resources for writing Native Apps on XP, SP2?

thanks

//======================================================================
//
// Native.c
//
// Mark Russinovich
// http://www.ntinternals.com
//
// This is a demonstration of a Native NT program. These programs
// run outside of the Win32 environment and must rely on the raw
// services provided by NTDLL.DLL. AUTOCHK (the program that executes
// a chkdsk activity during the system boot) is an example of a
// native NT application.
//
// This example is a native ‘hello world’ program. When installed with
// the regedit file associated with it, you will see it print
// “hello world” on the initialization blue screen during the system
// boot. This program cannot be run from inside the Win32 environment.
//
//======================================================================
#include “ntddk.h” // include this for its native functions and defn’s
#include “stdio.h”
#include “native.h”

//
// Our heap
//
HANDLE Heap;

//----------------------------------------------------------------------
//
// NtProcessStartup
//
// Instead of a ‘main’ or ‘winmain’, NT applications are entered via
// this entry point.
//
//----------------------------------------------------------------------
void NtProcessStartup( PSTARTUP_ARGUMENT Argument )
{
PUNICODE_STRING commandLine;
PWCHAR stringBuffer, argPtr;
UNICODE_STRING helloWorld;
RTL_HEAP_DEFINITION heapParams;

//
// Initialize some heap
//
memset( &heapParams, 0, sizeof( RTL_HEAP_DEFINITION ));
heapParams.Length = sizeof( RTL_HEAP_DEFINITION );
Heap = RtlCreateHeap( 2, 0, 0x100000, 0x1000, 0, &heapParams );

//
// Point at command line
//
commandLine = &Argument->Environment->CommandLine;

//
// Locate the argument
//
argPtr = commandLine->Buffer;
while( *argPtr != L’ ’ ) argPtr++;
argPtr++;

//
// Print out the argument
//
stringBuffer = RtlAllocateHeap( Heap, 0, 256 );
swprintf( stringBuffer, L"\n%s", argPtr );
helloWorld.Buffer = stringBuffer;
helloWorld.Length = wcslen( stringBuffer ) * sizeof(WCHAR);
helloWorld.MaximumLength = helloWorld.Length + sizeof(WCHAR);
NtDisplayString( &helloWorld );

//
// Free heap
//
RtlFreeHeap( Heap, 0, stringBuffer );

//
// Terminate
//
NtTerminateProcess( NtCurrentProcess(), 0 );
}

You are in land of undocumentaed … if you must “do” then purchase and
refer to nebbet book and cross compare with ddk/wdk and hone your reverse
engineering skills … else do not “do” …

wrote in message news:xxxxx@ntdev…
>
> I was only able to find an old copy of a source file by Mark Russinovich,
> as an example of a Native Application.
>
> Does anyone have any references or resources for writing Native Apps on
> XP, SP2?
>
> thanks
>
>
> //======================================================================
> //
> // Native.c
> //
> // Mark Russinovich
> // http://www.ntinternals.com
> //
> // This is a demonstration of a Native NT program. These programs
> // run outside of the Win32 environment and must rely on the raw
> // services provided by NTDLL.DLL. AUTOCHK (the program that executes
> // a chkdsk activity during the system boot) is an example of a
> // native NT application.
> //
> // This example is a native ‘hello world’ program. When installed with
> // the regedit file associated with it, you will see it print
> // “hello world” on the initialization blue screen during the system
> // boot. This program cannot be run from inside the Win32 environment.
> //
> //======================================================================
> #include “ntddk.h” // include this for its native functions and defn’s
> #include “stdio.h”
> #include “native.h”
>
> //
> // Our heap
> //
> HANDLE Heap;
>
> //----------------------------------------------------------------------
> //
> // NtProcessStartup
> //
> // Instead of a ‘main’ or ‘winmain’, NT applications are entered via
> // this entry point.
> //
> //----------------------------------------------------------------------
> void NtProcessStartup( PSTARTUP_ARGUMENT Argument )
> {
> PUNICODE_STRING commandLine;
> PWCHAR stringBuffer, argPtr;
> UNICODE_STRING helloWorld;
> RTL_HEAP_DEFINITION heapParams;
>
> //
> // Initialize some heap
> //
> memset( &heapParams, 0, sizeof( RTL_HEAP_DEFINITION ));
> heapParams.Length = sizeof( RTL_HEAP_DEFINITION );
> Heap = RtlCreateHeap( 2, 0, 0x100000, 0x1000, 0, &heapParams );
>
> //
> // Point at command line
> //
> commandLine = &Argument->Environment->CommandLine;
>
> //
> // Locate the argument
> //
> argPtr = commandLine->Buffer;
> while( *argPtr != L’ ’ ) argPtr++;
> argPtr++;
>
> //
> // Print out the argument
> //
> stringBuffer = RtlAllocateHeap( Heap, 0, 256 );
> swprintf( stringBuffer, L"\n%s", argPtr );
> helloWorld.Buffer = stringBuffer;
> helloWorld.Length = wcslen( stringBuffer ) * sizeof(WCHAR);
> helloWorld.MaximumLength = helloWorld.Length + sizeof(WCHAR);
> NtDisplayString( &helloWorld );
>
> //
> // Free heap
> //
> RtlFreeHeap( Heap, 0, stringBuffer );
>
> //
> // Terminate
> //
> NtTerminateProcess( NtCurrentProcess(), 0 );
> }
>
>

> Does anyone have any references or resources for writing Native Apps on XP, SP2?
Some (I said “some”) of these work under XpSP2 (after some cleanup, IIRC):
http://ashedel.chat.ru/source/

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Friday, May 04, 2007 6:26 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Neferences / resources for Nativ apps on XP

I was only able to find an old copy of a source file by Mark Russinovich, as an example of a Native Application.

Does anyone have any references or resources for writing Native Apps on XP, SP2?

thanks

//======================================================================
//
// Native.c
//
// Mark Russinovich
// http://www.ntinternals.com
//
// This is a demonstration of a Native NT program. These programs
// run outside of the Win32 environment and must rely on the raw
// services provided by NTDLL.DLL. AUTOCHK (the program that executes
// a chkdsk activity during the system boot) is an example of a
// native NT application.
//
// This example is a native ‘hello world’ program. When installed with
// the regedit file associated with it, you will see it print
// “hello world” on the initialization blue screen during the system
// boot. This program cannot be run from inside the Win32 environment.
//
//======================================================================
#include “ntddk.h” // include this for its native functions and defn’s
#include “stdio.h”
#include “native.h”

//
// Our heap
//
HANDLE Heap;

//----------------------------------------------------------------------
//
// NtProcessStartup
//
// Instead of a ‘main’ or ‘winmain’, NT applications are entered via
// this entry point.
//
//----------------------------------------------------------------------
void NtProcessStartup( PSTARTUP_ARGUMENT Argument )
{
PUNICODE_STRING commandLine;
PWCHAR stringBuffer, argPtr;
UNICODE_STRING helloWorld;
RTL_HEAP_DEFINITION heapParams;

//
// Initialize some heap
//
memset( &heapParams, 0, sizeof( RTL_HEAP_DEFINITION ));
heapParams.Length = sizeof( RTL_HEAP_DEFINITION );
Heap = RtlCreateHeap( 2, 0, 0x100000, 0x1000, 0, &heapParams );

//
// Point at command line
//
commandLine = &Argument->Environment->CommandLine;

//
// Locate the argument
//
argPtr = commandLine->Buffer;
while( *argPtr != L’ ’ ) argPtr++;
argPtr++;

//
// Print out the argument
//
stringBuffer = RtlAllocateHeap( Heap, 0, 256 );
swprintf( stringBuffer, L"\n%s", argPtr );
helloWorld.Buffer = stringBuffer;
helloWorld.Length = wcslen( stringBuffer ) * sizeof(WCHAR);
helloWorld.MaximumLength = helloWorld.Length + sizeof(WCHAR);
NtDisplayString( &helloWorld );

//
// Free heap
//
RtlFreeHeap( Heap, 0, stringBuffer );

//
// Terminate
//
NtTerminateProcess( NtCurrentProcess(), 0 );
}


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer