Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Neferences / resources for Nativ apps on XP

OSR_Community_UserOSR_Community_User Member Posts: 110,217
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 );
}

Comments

  • Lyndon_J._Clarke-2Lyndon_J._Clarke-2 Member Posts: 1,013
    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:[email protected]
    >
    > 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 );
    > }
    >
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    > 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: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
    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
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 12 September 2022 Live, Online
Internals & Software Drivers 23 October 2022 Live, Online
Kernel Debugging 14 November 2022 Live, Online
Developing Minifilters 5 December 2022 Live, Online