首页
社区
课程
招聘
[求助]驱动里有无与wsprintf这个函数差不多的?
发表于: 2009-12-2 09:46 6436

[求助]驱动里有无与wsprintf这个函数差不多的?

2009-12-2 09:46
6436
我想创建多个设备,并用设备的nextdevice指向下一个设备。组成一个设备连。再把第一个设备传给driver对象的那个device域

现在我的设备名这里有点不好搞,有直接把数字格式到字符串中的函数么?

#include <ntddk.h>
//#include <winuser.h>
#include <wchar.h>
#define AllDeviceNum 10

typedef struct _MY_DEVICEEXTEN
{
PDEVICE_OBJECT MyDevice;
UNICODE_STRING MyDeviceName;
UNICODE_STRING MySybolic;
ULONG MyDeviceNum;
}MY_DEVICEEXTEN,*PMY_DEVICEEXTEN;

VOID MyUnload(IN PDRIVER_OBJECT mydriver);
NTSTATUS CrDevice(IN PDRIVER_OBJECT mydriver);


用前插法~~~

#include "head.h"

NTSTATUS DriverEntry(IN PDRIVER_OBJECT mydriver,IN PUNICODE_STRING myregpath)
{
mydriver->DriverUnload=MyUnload;
CrDevice(mydriver);
return STATUS_SUCCESS;

}
NTSTATUS CrDevice(IN PDRIVER_OBJECT mydriver)
{
NTSTATUS status;
ULONG i;
PDEVICE_OBJECT PNextDevice;
PDEVICE_OBJECT PDevice;
UNICODE_STRING DeviceName[AllDeviceNum];//array
UNICODE_STRING DeviceSymbolic[AllDeviceNum];
LPWSTR Buffer;
LPWSTR SBuffer;
PMY_DEVICEEXTEN PDevExten;
PDevice=NULL;//point device of createdevice
PDevExten=NULL;//point exent
Buffer=NULL;//point devicename
SBuffer=NULL; //point symbolic
PNextDevice=NULL;//point next device

for (i=0;i<AllDeviceNum;i++)
{//

Buffer=(PWSTR)ExAllocatePool(PagedPool,512);
memset(Buffer,0,512);
// wsprintfW(Buffer,L"\\Device\\MyDevice%d",i);
swprintf(Buffer,L"\\Device\\MyDevice%d",i);
RtlInitUnicodeString(&DeviceName,Buffer);
//------------------------------------------------------------
SBuffer=(PWSTR)ExAllocatePool(PagedPool,512);
memset(SBuffer,0,512);
swprintf(SBuffer,L"\\??\\MyDevice%d",i);
RtlInitUnicodeString(&DeviceSymbolic,SBuffer);
//------------------------------------------------------------
status=IoCreateDevice(mydriver,sizeof(MY_DEVICEEXTEN),&DeviceName,FILE_DEVICE_UNKNOWN,0,TRUE,&PDevice);
if (!NT_SUCCESS(status))
{
KdPrint(("Error\n"));
return status;
}
KdPrint(("%wZ\n",&DeviceName));

PDevExten=(PMY_DEVICEEXTEN)PDevice->DeviceExtension;
memset(PDevExten,0,sizeof(MY_DEVICEEXTEN));
PDevExten->MyDevice=PDevice; //save deviceobject
PDevExten->MyDeviceName=DeviceName;//save devicename
PDevExten->MySybolic=DeviceSymbolic;//save devicesymbolic
PDevExten->MyDeviceNum=i;//save num
status=IoCreateSymbolicLink(&DeviceSymbolic,&DeviceName);
if (!NT_SUCCESS(status))
{
IoDeleteDevice(PDevice);
return status;
}
KdPrint(("%wZ\n",&DeviceSymbolic));
ExFreePool(Buffer);
ExFreePool(SBuffer);
Buffer=NULL;
SBuffer=NULL;
PDevice->NextDevice=PNextDevice;
PNextDevice=PDevice;
}//
mydriver->DeviceObject=PNextDevice; //point first device
return STATUS_SUCCESS;
}

VOID MyUnload(IN PDRIVER_OBJECT mydriver)
{
PDEVICE_OBJECT UnDevice;
PMY_DEVICEEXTEN UnDevExten;

UnDevice=mydriver->DeviceObject;//first device
KdPrint(("Start Unload\n"));
while (UnDevice!=NULL)
{
PDEVICE_OBJECT UnLoadDevice;
UnDevExten=(PMY_DEVICEEXTEN)UnDevice->DeviceExtension;
UnLoadDevice=UnDevExten->MyDevice;
KdPrint(("%wZ\n",&UnDevExten->MyDeviceName)); //devicename
KdPrint(("第%d个设备!\n",UnDevExten->MyDeviceNum)); //devicenum
IoDeleteSymbolicLink(&UnDevExten->MySybolic);//delete symbolic
IoDeleteDevice(UnLoadDevice); //delete device
UnDevice=UnDevice->NextDevice;
}

KdPrint(("End Unload\n"));
}

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 202
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
只能先把数字转为unicode 然后再复制到另一个字符串中了。
2009-12-2 09:52
0
雪    币: 202
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
Buffer=(PWSTR)ExAllocatePool(PagedPool,512);
wsprintfW(Buffer,L"\\Device\\MyDevice%d",i);
RtlInitUnicodeString(&DeviceName[i],Buffer);
加了头文件出错,
这个wsprintf的变量列表可以直接整数型的吧?

Compiling - onepc.c for i386
d:\winddk\2600\inc\crt\winuser.h(59) : error C2143: syntax error : missing ')' b
efore '*'
都是在文件里出错,,
2009-12-2 11:01
0
雪    币: 4583
活跃值: (3567)
能力值: ( LV12,RANK:230 )
在线值:
发帖
回帖
粉丝
4
swprintf()被内核导出
2009-12-2 12:25
0
雪    币: 202
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
谢谢小四大侠~~~
2009-12-2 13:36
0
雪    币: 202
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
6
再问一下关于数组地址的问题,      基础感觉太差,,,学得有些力不从心

RtlInitUnicodeString(&DeviceName[i],Buffer);
        IoCreateDevice(mydriver,NULL,&DeviceName[i],FILE_DEVICE_UNKNOWN,NULL,TRUE,&PDevice);
             
第一条rtlini的语句不报错,但是iocreatedevice会报错
onepc.c(34) : error C2220: warning treated as error - no object file generated
onepc.c(34) : error C4047: 'function' : 'ULONG' differs in levels of indirection
from 'void *'
onepc.c(34) : error C4047: 'function' : 'ULONG' differs in levels of indirection
from 'void *'
BUILD: Compile errors: not linking d:\winddk\code\create directory
BUILD: Done
在不同的级别引用??
这个取unicode_string地址不能&这样么?但是第一条rtlini的语句不报错~
2009-12-2 13:50
0
雪    币: 202
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
7
NULL,TRUE,&PDevice);
原来是这里。扩展设备大小。。我一直还以为是汇编那里定义的null=0。看了一下。原来null 是(void *)0
2009-12-2 15:18
0
游客
登录 | 注册 方可回帖
返回
//