Native API

https://technet.microsoft.com/en-us/sysinternals/bb897447.aspx

http://www.rohitab.com/discuss/topic/39956-my-first-native-application/

以前没注意过这里

HKLMSystemCurrentControlSetControlSession ManagerBootExecute

代价只是向这里写入一个路径,

为什么我就没有注意过这里。

代码:

内部使用Nt系列函数,而且要十分注意最后需要手动结束当前进程,否则它是不会自动结束的

 1 #include <Windows.h>
 2 #include <ntdef.h>
 3  
 4 void NTAPI RtlInitUnicodeString(PUNICODE_STRING,PCWSTR);
 5  
 6 NTSTATUS NTAPI NtDisplayString(PUNICODE_STRING);
 7 NTSTATUS NTAPI NtDelayExecution(BOOLEAN,PLARGE_INTEGER);
 8 NTSTATUS NTAPI NtTerminateProcess(HANDLE,NTSTATUS);
 9  
10 void NtProcessStartup()
11 {
12     UNICODE_STRING us;
13     LARGE_INTEGER delay;
14  
15     delay.QuadPart=-10000000;
16  
17     RtlInitUnicodeString(&us,L"Message from native application.");
18     NtDisplayString(&us);
19     NtDelayExecution(FALSE,&delay);
20     NtTerminateProcess((HANDLE)-1,0);
21 }
View Code

编译方法:

gcc main.c -o nt.exe -lntdll -nostdlib -Wl,--subsystem,native -e _NtProcessStartup

使用的库是 MinGW

网上给出的标准编译方法是使用WDK来编译,但是这里既然能用MinGW的话,那么是不是也可以用VS来编译?

原文地址:https://www.cnblogs.com/suanguade/p/5883845.html