首页
社区
课程
招聘
[求助]想用DeviceIoControl调用驱动程序中的函数,请问高手怎么调用?
发表于: 2008-12-18 20:02 7298

[求助]想用DeviceIoControl调用驱动程序中的函数,请问高手怎么调用?

2008-12-18 20:02
7298
下面是驱动程序中的.几个函数:是关于串口(运用驱动监听串口数据)的

即不占用串口资源。

MHANDLE CSERMONDevice::TryConnectToSerialDevice(LPCTSTR Name)
{
    CUString str((PWCHAR) Name);
    PDEVICE_OBJECT pdo;
    NTSTATUS RC=Attach(&str.m_String,FILE_ALL_ACCESS,&pdo);
    if (RC==STATUS_SUCCESS)
        return (MHANDLE) pdo->DeviceExtension;
    else
        return NULL;
}

NTSTATUS CSERMONDevice::IoControl(PIRP Irp)
{
    PIO_STACK_LOCATION curIRPStack;

    curIRPStack = IoGetCurrentIrpStackLocation(Irp);
    switch (curIRPStack->Parameters.DeviceIoControl.IoControlCode)
    {
    case  IOCTL_SERMON_STARTMONITOR:
    {
        MHANDLE mh=TryConnectToSerialDevice(
            (LPCTSTR) Irp->AssociatedIrp.SystemBuffer);
        if (mh)
        {
            *((MHANDLE *) Irp->AssociatedIrp.SystemBuffer)=mh;
            Irp->IoStatus.Information = sizeof(MHANDLE);
            Irp->IoStatus.Status = STATUS_SUCCESS;
        } else
            Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
        break;
    }
    case IOCTL_SERMON_STOPMONITOR:
    {
        if (curIRPStack->Parameters.DeviceIoControl.InputBufferLength
            ==sizeof(MHANDLE))
        {
            MHANDLE mh=*((MHANDLE *) Irp->AssociatedIrp.SystemBuffer);
            CAttachedDevice *ptr=(CAttachedDevice *) mh;
            if (ptr && ptr->CheckValid())
            {
                Irp->IoStatus.Status = STATUS_SUCCESS;
                delete ptr;
            } else
                Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
        } else
            Irp->IoStatus.Status = STATUS_INVALID_HANDLE;

        Irp->IoStatus.Information = 0;
        break;
    }
    case IOCTL_SERMON_GETINFOSIZE:
    {
        if (curIRPStack->Parameters.DeviceIoControl.
            InputBufferLength==sizeof(MHANDLE))
        {
            MHANDLE mh=*((MHANDLE *)
                Irp->AssociatedIrp.SystemBuffer);
            CAttachedDevice *ptr=(CAttachedDevice *) mh;
            if (ptr && ptr->CheckValid() &&
                curIRPStack->Parameters.DeviceIoControl.
                OutputBufferLength==sizeof(ULONG))
            {
                return ptr->GetNextSize(Irp);
            } else
                Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
        } else
            Irp->IoStatus.Status = STATUS_INVALID_HANDLE;

        Irp->IoStatus.Information = 0;
        break;
    }
    case IOCTL_SERMON_GETINFO:
    {
        if (curIRPStack->Parameters.DeviceIoControl.
            InputBufferLength==sizeof(MHANDLE))
        {
            MHANDLE mh=*((MHANDLE *) Irp->AssociatedIrp.
                SystemBuffer);
            CAttachedDevice *ptr=(CAttachedDevice *) mh;
            if (ptr && ptr->CheckValid())
            {
                return ptr->GetNext(Irp);
            } else
                Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
        } else
            Irp->IoStatus.Status = STATUS_INVALID_HANDLE;

        Irp->IoStatus.Information = 0;
        break;
    }
    default:
        Irp->IoStatus.Status = STATUS_IO_DEVICE_ERROR;
        Irp->IoStatus.Information = 0;
        break;
    }

    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    return(Irp->IoStatus.Status);
}

NTSTATUS CAttachedDevice::GetNextSize(PIRP Irp)
{
    if (!io.IsEmpty())
    {
        LockExclusive();
        IOReq *q=io.RemoveHead();
        NTSTATUS ret=ProcessSize(Irp,q);
        Unlock();
        return ret;
    } else
    {
        ExIRP *irp=new (NonPagedPool) ExIRP;
        irp->Irp=Irp;
        pending.New(irp);

        Irp->IoStatus.Information=0;
        Irp->IoStatus.Status=STATUS_PENDING;
        IoMarkIrpPending(Irp);
        return STATUS_PENDING;
    }
}

NTSTATUS CAttachedDevice::GetNext(PIRP Irp)
{
    LockExclusive();
    if (!io.IsEmpty())
    {
        IOReq *q=io.RemoveHead();
        Unlock();
        return ProcessNext(Irp,q);
    } else
    {
        ExIRP *irp=new (NonPagedPool) ExIRP;
        irp->Irp=Irp;
        pending.New(irp);

        Irp->IoStatus.Information=0;
        Irp->IoStatus.Status=STATUS_PENDING;
        IoMarkIrpPending(Irp);
        Unlock();
        return STATUS_PENDING;
    }
}

现在我想用DeviceIoControl调用驱动程序中的函数,并用文本记录下捕捉到的串口数据,

请问高手怎么调用???参数是怎样的?????

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 200
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
有没有 人会 啊 ??求助 !!!!
2008-12-19 11:31
0
雪    币: 204
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
这里有一个helloworld的实例,参照一下你就应该知道怎么做了。如果还是不会,参照msdn和《Windows Driver Model》。
上传的附件:
2008-12-21 11:50
0
雪    币: 284
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
我也遇到同样的问题了。不知有没有大牛回答一下啊。帮助帮助我们这些菜鸟吧
2009-6-1 13:49
0
游客
登录 | 注册 方可回帖
返回
//