一
简介
wdk 7.1.0
)Wdk7600导航连接(https://learn.microsoft.com/en-us/windows-hardware/drivers/other-wdk-downloads)C:\WinDDK\7600.16385.1\inc\crt
C:\WinDDK\7600.16385.1\inc\ddk
C:\WinDDK\7600.16385.1\inc\api
TARGETNAME=TestDriver
TARGETPATH=.
TARGETTYPE=DRIVERMSC_WARNING_LEVEL= /W3 /WX
SOURCES= Driver.c
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath) {
DbgPrint("Hello, world!\n");
return STATUS_SUCCESS;
}
VsCode的开发环境已经配置好了,可以放心写代码了。
任务
在VsCode中有一个 终端,终端选项中有一个配置任务(task) 我们只需要生成一个task,然后将task替换为我给的即可。默认路径,
如果你修改过wdk的安装目录,请手动更改此json。{
"version": "2.0.0",
"tasks": [
{
"label": "BuildDebug64_Win7OrHigh",
"type": "shell",
"command": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/k",
"pushd \".\" && call \"C:\\WinDDK\\7600.16385.1\\bin\\setenv.bat \" C:\\WinDDK\\7600.16385.1\\ chk x64 WIN7\" && popd"
],
"group": "build",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "BuildRelease64_Win7OrHigh",
"type": "shell",
"command": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/k",
"pushd \".\" && call \"C:\\WinDDK\\7600.16385.1\\bin\\setenv.bat \" C:\\WinDDK\\7600.16385.1\\ fre x64 WIN7\" && popd"
],
"group": "build",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "BuildDebug32_Win7OrHigh",
"type": "shell",
"command": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/k",
"pushd \".\" && call \"C:\\WinDDK\\7600.16385.1\\bin\\setenv.bat \" C:\\WinDDK\\7600.16385.1\\ chk x86 WIN7\" && popd"
],
"group": "build",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "BuildRelease32_Win7OrHigh",
"type": "shell",
"command": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/k",
"pushd \".\" && call \"C:\\WinDDK\\7600.16385.1\\bin\\setenv.bat \" C:\\WinDDK\\7600.16385.1\\ fre x86 WIN7\" && popd"
],
"group": "build",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "BuildDebug_WinXP",
"type": "shell",
"command": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/k",
"pushd \".\" && call \"C:\\WinDDK\\7600.16385.1\\bin\\setenv.bat \" C:\\WinDDK\\7600.16385.1\\ chk x86 WXP \" && popd"
],
"group": "build",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
},
{
"label": "BuildRelease_WinXP",
"type": "shell",
"command": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/k",
"pushd \".\" && call \"C:\\WinDDK\\7600.16385.1\\bin\\setenv.bat \" C:\\WinDDK\\7600.16385.1\\ fre x86 WXP \" && popd"
],
"group": "build",
"presentation": {
"reveal": "always"
},
"problemMatcher": "$msCompile"
}
]
}
C:\Users\YourComputerName\AppData\Roaming\Code\User
二
Sources文件编程
TARGETNAME=testDriver1
TARGETPATH=.
TARGETTYPE=DRIVERMSC_WARNING_LEVEL= /W3 /WX
INCLUDES= \
./test1SOURCES= Driver.cpp\
test.cpp
INCLUDES
命令指明了 .h所在得目录。INCLUDES= $(INCLUDES) \
$(DDK_INC_PATH); \
..\common; \
..\..\util;INCLUDES = $(DDK_INC_PATH);\
DDK_INC_PATH == WDKROOT\inc\ddk
#ifdef __cplusplus
extern "C"
{
#endif#include <ntifs.h>
#include <ntddk.h>
#include <Ntstrsafe.h>
#include "ntimage.h"
#ifdef __cplusplus
}
#endifPVOID testprint();
INCLUDES
知名.则会报错,无法找到xxx.h 亦或者 .h和.cpp都放在同一目录下.(主目录下) 则不需要使用INCLUDES
VOID DriverUnLoad(
PDRIVER_OBJECT DriverObject)
{
KdPrint(("Exit"));
}extern "C" NTSTATUS DriverEntry(
PDRIVER_OBJECT pDriverObj,
PUNICODE_STRING pReg)
{
UNREFERENCED_PARAMETER(pDriverObj);
UNREFERENCED_PARAMETER(pReg);
KdBreakPoint();
test();
return STATUS_SUCCESS;
}
extern "C"
{
}PVOID test();
PVOID __declspec(naked) test()
{
_asm {
mov eax,eax
ret
}
}
I386_SOURCES= i386\test86.asm
extern "C" int __cdecl MyAdd(int x, int y);
.386
.model flat,stdcall
option casemap:none
.const
.data
.code
MyAdd proc c ,n1:DWORD,n2:DWORD
mov eax,n1
add eax,n2
ret
MyAdd endp
End
AMD64_SOURCES
TARGETNAME=UseX86AndX64Asm
TARGETPATH=Build
TARGETTYPE=DRIVERUSER_C_FLAGS=$(USER_C_FLAGS) /FAcs
LINKER_FLAGS=/INTEGRITYCHECKINCLUDES = .
C_DEFINES=$(C_DEFINES) /wd4996 /wd4995
AMD64_SOURCES = amd64\myAdd.asm
SOURCES=start.cpp \
.CODE myAdd PROC
add rcx,rdx
mov rax,rcx
ret
myAdd ENDPEND
VOID DriverUnload(PDRIVER_OBJECT pDriverObj)
{
KdPrint(("Unload Driver\n"));
}extern "C" long long myAdd(long long a, long long b);
extern "C" NTSTATUS DriverEntry(
IN PDRIVER_OBJECT pRootDriverObj,
IN PUNICODE_STRING pRegPath)
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
pRootDriverObj->DriverUnload = DriverUnload;
ULONG majIndex = 0;
KdBreakPoint();
myAdd(1, 2);
return status;
}
RootDir
amd64(DIR)
myadd.asm
start.cpp (驱动入口代码)
sources
文件.亦或者是新的DIRS
.DIRS
DIRS= \
A \
B \
C
MSC_WARNING_LEVEL= /W3 /WX
TARGETNAME=test
TARGETPATH=.
TARGETTYPE=LIBRARY
DRIVERTYPE=FSMSC_WARNING_LEVEL= /W3 /WX
INCLUDES= \
./testSOURCES= test.cpp
ROOTDIR
test(DIR)
test.h
test.cpp
extern "C"
{
}class test
{
private:
/* data */
public:
test(/* args */);
~test();
PVOID testprint();
};
test::test(/* args */)
{
}test::~test()
{
}PVOID test::testprint()
{
DbgPrint("testprint");
return NULL;
}
TARGETNAME=test1
TARGETPATH=.
TARGETTYPE=DRIVERMSC_WARNING_LEVEL= /W3 /WX
INCLUDES= \
./testTARGETLIBS = .\libs\test.lib
SOURCES= Driver.cpp
VOID DriverUnLoad(
PDRIVER_OBJECT DriverObject)
{
KdPrint(("Exit"));
}extern "C" NTSTATUS DriverEntry(
PDRIVER_OBJECT pDriverObj,
PUNICODE_STRING pReg)
{
UNREFERENCED_PARAMETER(pDriverObj);
UNREFERENCED_PARAMETER(pReg);
KdBreakPoint();
pDriverObj->DriverUnload = DriverUnLoad;
test t;
t.testprint();
return STATUS_SUCCESS;
}
TARGETLIBS = $(DDK_LIB_PATH)\xxx1.lib\
$(DDK_LIB_PATH)\xxx2.lib\
例如包含 ntstrsafe.lib库
TARGETLIBS= $(DDK_LIB_PATH)\ntstrsafe.lib系统提供的路径有如下:
DDK_LIB_PATH == WDKROOT\lib\Version\*
SDK_LIB_PATH == WDKROOT\lib\Version\*
CRT_LIB_PATH
TARGETNAME=test1
TARGETPATH=.
TARGETTYPE=DRIVERMSC_WARNING_LEVEL= /W3 /WX
!IFDEF DDKBUILDENV
C_DEFINES=$(C_DEFINES) -DDDK_BUILD
!ENDIFINCLUDES= \
./testTARGETLIBS = .\libs\test.lib
SOURCES= Driver.cpp
C_DEFINES=$(C_DEFINES) /wd4996
!
if
$(IA64)
xxxxx 条件使用 IA64
!endif
DIR_SOURCES
=
wacompen.c \
wacompen.rc \
oempen.c \
errcodes.mc
STB_SOURCES
=
hid.c \
pnp.c \
serial.c \
errlog.c
SOURCES
=
$(DIR_SOURCES) $(STB_SOURCES)
看雪ID:TkBinary
https://bbs.kanxue.com/user-home-302697.htm
# 往期推荐
3、安卓加固脱壳分享
球分享
球点赞
球在看
点击阅读原文查看更多