ljx197926
驱动牛犊
驱动牛犊
  • 注册日期2002-12-17
  • 最后登录2004-02-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1452回复:0

<font color=red>给出内核中调用其它设备的测试函数</font>

楼主#
更多 发布于:2003-04-11 11:28
过程:
  1.在内核中获得设备对象指针路径为\\\\Device\\\\XINTPCI1
   这里根据你设备路径不同而不同具体可指你的其它设备的驱程的
   AddDevice函数
  2.构造IRP请求
    方法有多种此处我用IoBuildDeviceIoControlRequest
  3.设备对应location,根据调用的函数不同,MajorFunction 有所不同
  4.调用IoCallDriver给指定设备发送IRP

void TestJMK()
{

UNICODE_STRING      JMKName;//加密卡设备名字
PFILE_OBJECT        pFileObject;// 驱程的文件设备对象指针
PDEVICE_OBJECT      pDeviceObject;//内核中代表加密卡设备对象指针
NTSTATUS status;

PIRP   pIRP = NULL;
IO_STATUS_BLOCK IoStatus;
PIO_STACK_LOCATION pIoStackLocation;

char* pInBuf ;
ULONG  InLen =1024 ;
char* pOutBuf;
ULONG OutLen =1024;
    IO_MSG* msg;

int i = 0;

pInBuf = (char*)ExAllocatePool(NonPagedPool,1500);
if ( pInBuf == NULL)
{
DbgPrint(\"Allocate memory failed!\\n\");
return;
}

pOutBuf = (char*)ExAllocatePool(NonPagedPool,1500);
if ( pOutBuf == NULL)
{
DbgPrint(\"Allocate memory failed!\\n\");
return;
}

NdisZeroMemory(pInBuf,1500);
NdisZeroMemory(pOutBuf,1500);

msg = (IO_MSG*)pInBuf;

msg->no1 = 1040;
msg->no2 = 1040;
msg->Type = 27;
msg->Length = 1024;
for (i = 0; i< 1024; i++)
msg->Data = \'A\';

DbgPrint(\"IN test uSb jmk\\n\");
KeSetPriorityThread( KeGetCurrentThread(), LOW_REALTIME_PRIORITY);

RtlInitUnicodeString(&JMKName, L\"\\\\Device\\\\XINTPCI1\");
    status = IoGetDeviceObjectPointer(&JMKName,
FILE_READ_DATA|FILE_WRITE_DATA,
&pFileObject,
&pDeviceObject);
    if (status != STATUS_SUCCESS)
{
DbgPrint(\"Failed  to Get Device Object pointer!\\n\");
return;
}

DbgPrint(\"pDeviceObject = %x\\n\", pDeviceObject);

pIRP = IoBuildDeviceIoControlRequest(IOCTL_DATA_DO,
                                        pDeviceObject,
(PVOID)pInBuf,
InLen,
(PVOID)pOutBuf,
OutLen ,
FALSE,
NULL,
&IoStatus);
if (pIRP == NULL)
{
DbgPrint(\"Failed to build IRP!\\n\");
return ;
}

pIoStackLocation = IoGetNextIrpStackLocation(pIRP);
pIoStackLocation->MajorFunction = IRP_MJ_DEVICE_CONTROL ;

status = IoCallDriver(pDeviceObject,pIRP);
if (status != STATUS_SUCCESS)
{
DbgPrint(\"Failed  to EnDescrypt!\\n\");
return ;
}

ExFreePool((PVOID)pInBuf);
ExFreePool((PVOID)pOutBuf);


return;
}

[编辑 -  4/11/03 by  ljx197926]

最新喜欢:

ljmmaryljmmar...
游客

返回顶部