NO

Author Topic: Do you use Native api?  (Read 3504 times)

Offline bitcoin

  • Member
  • *
  • Posts: 179
Do you use Native api?
« on: September 03, 2019, 05:25:45 PM »
I test to create native api program in Pelles C. There are manual in russian http://hex.pp.ua/native-stub.php but about visual studio.

1. Create new Console application. Change settins (delete all libs, set nodefault lib, change subsystem to NATIVE);
2. Download NDK includes , and change include-dir in project settings to folder with it. http://code.google.com/p/native-nt-toolkit/
3. put code
Code: [Select]
#define WIN32_NO_STATUS
#include <windows.h>
#include <ntndk.h>

 void winx_sleep(int msec)
    {
        LARGE_INTEGER Interval;
        Interval.QuadPart = -((signed long)msec * 10000);
        (void)NtDelayExecution(0/*FALSE*/,&Interval);
    }

void NtProcessStartup(void* StartupArgument)
{
  UNICODE_STRING str;
  PPEB pPeb = (PPEB)StartupArgument;
  RtlNormalizeProcessParams(pPeb->ProcessParameters);
   
  RtlInitUnicodeString(&str, L"Hello, world!\nCommand line is: ");
  NtDisplayString(&str);
  RtlInitUnicodeString(&str, pPeb->ProcessParameters->CommandLine.Buffer);
  NtDisplayString(&str);
   
  winx_sleep(5000);
 
  NtTerminateProcess(NtCurrentProcess(), 0);
}


4. this code not compile , because NDK (for some reasons, don't know it) , dont have ntnls.h and ntdll.lib . I get include from PH sources, and lib - from DDK (WDK) XP .

5. In linker settings set entry point to NtProcessStartup@4

6. So, you got exe. If you want to run it without reboot, you can use some small tool, to run native into win32.