首页
社区
课程
招聘
[求助]代码出错如何修改?
发表于: 2014-2-18 16:23 5749

[求助]代码出错如何修改?

2014-2-18 16:23
5749
#include "ntddk.h"

NTSYSAPI
NTSTATUS
NTAPI
ZwOpenProcess(
                          OUT PHANDLE ProcessHandle,
                          IN ACCESS_MASK DesiredAccess,
                          IN POBJECT_ATTRIBUTES ObjectAttributes,
                          IN PCLIENT_ID ClientId OPTIONAL
                          );

NTSYSAPI
NTSTATUS
NTAPI
ZwTerminateProcess(
                                   IN HANDLE ProcessHandle OPTIONAL,
                                   IN NTSTATUS ExitStatus
                                   );

VOID OnUnload(IN PDRIVER_OBJECT DriverObject);
NTSTATUS DriverEntry(IN PDRIVER_OBJECT theDriverObject,IN PUNICODE_STRING theRegistryPath)
{
DbgPrint("i am loaded!");
theDriverObject->DriverUnload=OnUnload;
OBJECT_ATTRIBUTES ObjectAtributes;
HANDLE hProcess=NULL;
CLIENT_ID clientid;
ULONG dwpid=1024;
InitializeObjectAttributes(&ObjectAtributes,0,0,0,0);
clientid.UniqueProcess=(HANDLE)dwpid;
clientid.UniqueThread=0;
ZwOpenProcess(&hProcess,PROCESS_ALL_ACCESS,&ObjectAtributes,&clientid);
ZwTerminateProcess(hProcess,0);
ZwClose(hProcess);

return STATUS_SUCCESS;

}
VOID OnUnload(IN PDRIVER_OBJECT DriverObject)
{

        DbgPrint("OnUnload called\n");
}

错误显示是:

1>1>Compiling - terminate.c for i386
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(27) : error C2275: 'OBJECT_ATTRIBUTES' : illegal use of this type as an expression
1>c:\winddk\2600\inc\wxp\ntdef.h(1261) : error see declaration of 'OBJECT_ATTRIBUTES'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(27) : error C2146: syntax error : missing ';' before identifier 'ObjectAtributes'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(27) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(27) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(27) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(27) : error C2065: 'ObjectAtributes' : undeclared identifier
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(28) : error C2275: 'HANDLE' : illegal use of this type as an expression
1>c:\winddk\2600\inc\wxp\ntdef.h(443) : error see declaration of 'HANDLE'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(28) : error C2146: syntax error : missing ';' before identifier 'hProcess'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(28) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(28) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(28) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(28) : error C2065: 'hProcess' : undeclared identifier
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(28) : error C4047: '=' : 'int' differs in levels of indirection from 'void *'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(29) : error C2275: 'CLIENT_ID' : illegal use of this type as an expression
1>c:\winddk\2600\inc\ddk\wxp\ntddk.h(5751) : error see declaration of 'CLIENT_ID'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(29) : error C2146: syntax error : missing ';' before identifier 'clientid'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(29) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(29) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(29) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(29) : error C2065: 'clientid' : undeclared identifier
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(30) : error C2275: 'ULONG' : illegal use of this type as an expression
1>c:\winddk\2600\inc\wxp\ntdef.h(411) : error see declaration of 'ULONG'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(30) : error C2146: syntax error : missing ';' before identifier 'dwpid'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(30) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(30) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(30) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(30) : error C2065: 'dwpid' : undeclared identifier
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(31) : error C2223: left of '->Length' must point to struct/union
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(31) : error C2223: left of '->RootDirectory' must point to struct/union
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(31) : error C2223: left of '->Attributes' must point to struct/union
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(31) : error C2223: left of '->ObjectName' must point to struct/union
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(31) : error C2223: left of '->SecurityDescriptor' must point to struct/union
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(31) : error C2223: left of '->SecurityQualityOfService' must point to struct/union
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(32) : error C2224: left of '.UniqueProcess' must have struct/union type
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(33) : error C2224: left of '.UniqueThread' must have struct/union type
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(34) : error C4047: 'function' : 'PHANDLE' differs in levels of indirection from 'int *'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(34) : error C4133: 'function' : incompatible types - from 'int *' to 'POBJECT_ATTRIBUTES'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(34) : error C4133: 'function' : incompatible types - from 'int *' to 'PCLIENT_ID'
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(35) : error C4022: 'ZwTerminateProcess' : pointer mismatch for actual parameter 1
1>f:\cdriver\zwterminateprocess\zwterminateprocess\terminate.c(36) : error C4022: 'ZwClose' : pointer mismatch for actual parameter 1
1>BUILD: Compile errors: not linking f:\cdriver\zwterm~2\zwterm~1 directory
1>BUILD: Done
1>    2 files compiled - 42 Errors
1>DDKBLD: ================ Build warnings =======================
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(27) : error C2275: 'OBJECT_ATTRIBUTES' : illegal use of this type as an expression
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(27) : error C2146: syntax error : missing ';' before identifier 'ObjectAtributes'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(27) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(27) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(27) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(27) : error C2065: 'ObjectAtributes' : undeclared identifier
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(28) : error C2275: 'HANDLE' : illegal use of this type as an expression
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(28) : error C2146: syntax error : missing ';' before identifier 'hProcess'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(28) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(28) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(28) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(28) : error C2065: 'hProcess' : undeclared identifier
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(28) : warning C4047: '=' : 'int' differs in levels of indirection from 'void *'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(29) : error C2275: 'CLIENT_ID' : illegal use of this type as an expression
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(29) : error C2146: syntax error : missing ';' before identifier 'clientid'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(29) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(29) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(29) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(29) : error C2065: 'clientid' : undeclared identifier
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(30) : error C2275: 'ULONG' : illegal use of this type as an expression
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(30) : error C2146: syntax error : missing ';' before identifier 'dwpid'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(30) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(30) : error C2144: syntax error : '<Unknown>' should be preceded by '<Unknown>'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(30) : error C2143: syntax error : missing ';' before 'identifier'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(30) : error C2065: 'dwpid' : undeclared identifier
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(31) : error C2223: left of '->Length' must point to struct/union
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(31) : error C2223: left of '->RootDirectory' must point to struct/union
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(31) : error C2223: left of '->Attributes' must point to struct/union
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(31) : error C2223: left of '->ObjectName' must point to struct/union
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(31) : error C2223: left of '->SecurityDescriptor' must point to struct/union
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(31) : error C2223: left of '->SecurityQualityOfService' must point to struct/union
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(32) : error C2224: left of '.UniqueProcess' must have struct/union type
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(33) : error C2224: left of '.UniqueThread' must have struct/union type
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(34) : warning C4047: 'function' : 'PHANDLE' differs in levels of indirection from 'int *'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(34) : warning C4133: 'function' : incompatible types - from 'int *' to 'POBJECT_ATTRIBUTES'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(34) : warning C4133: 'function' : incompatible types - from 'int *' to 'PCLIENT_ID'
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(35) : warning C4022: 'ZwTerminateProcess' : pointer mismatch for actual parameter 1
1>f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\terminate.c(36) : warning C4022: 'ZwClose' : pointer mismatch for actual parameter 1
1>DDKBLD: =======================================================
1>DDKBLD: Build complete
1>DDKBLD: Building browse information files
1>Build log was saved at "file://f:\Cdriver\ZwTerminateProcess\ZwTerminateProcess\BuildLog.htm"
1>ZwTerminateProcess.WXP - 71 error(s), 6 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

求解释哈

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 195
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
不好意思,原来是倒掉了。
VOID OnUnload(IN PDRIVER_OBJECT DriverObject);
NTSTATUS DriverEntry(IN PDRIVER_OBJECT theDriverObject,IN PUNICODE_STRING theRegistryPath)
{

OBJECT_ATTRIBUTES ObjectAtributes;
HANDLE hProcess=NULL;
CLIENT_ID clientid;
ULONG dwpid=1024;
InitializeObjectAttributes(&ObjectAtributes,0,0,0,0);
clientid.UniqueProcess=(HANDLE)dwpid;
clientid.UniqueThread=0;
ZwOpenProcess(&hProcess,PROCESS_ALL_ACCESS,&ObjectAtributes,&clientid);
ZwTerminateProcess(hProcess,0);
ZwClose(hProcess);

DbgPrint("i am loaded!");
theDriverObject->DriverUnload=OnUnload;

return STATUS_SUCCESS;

}

原来这个也有关系啊,汗!
2014-2-18 16:30
0
雪    币: 2664
活跃值: (3401)
能力值: ( LV13,RANK:1760 )
在线值:
发帖
回帖
粉丝
3
不然你以为
2014-2-18 16:33
0
雪    币: 25
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
C的规范,原来我也是这么写的,编译了才知道是错误的写法。。
2014-2-18 21:43
0
游客
登录 | 注册 方可回帖
返回
//