列舉裝置棧

2021-07-10 01:40:38 字數 3416 閱讀 2571

hello.h

#pragma once

#include #define countarray(array) ( sizeof(array) / sizeof(array[0]) )

typedef struct _device_extension

device_extension,*pdevice_extension;

#ifdef __cplusplus

extern "c"

#endif

typedef struct _object_create_information

object_create_information, * pobject_create_information;

typedef struct _object_header

; pobject_type type;

uchar nameinfooffset;

uchar handleinfooffset;

uchar quotainfooffset;

uchar flags;

union

; psecurity_descriptor securitydescriptor;

quad body;

} object_header, * pobject_header;

#define number_hash_buckets 37

typedef struct _object_directory

object_directory, * pobject_directory;

typedef struct _object_header_name_info

object_header_name_info, * pobject_header_name_info;

#define object_to_object_header( o ) \

containing_record( (o), object_header, body )

#define object_header_to_name_info( oh ) ((pobject_header_name_info) \

((oh)->nameinfooffset == 0 ? null : ((pchar)(oh) - (oh)->nameinfooffset)))

#ifdef __cplusplus

extern "c" ntstatus driverentry(in pdriver_object driverobject, in punicode_string registrypath);

#endif

void hellounload(in pdriver_object driverobject); //解除安裝函式

ntstatus createdevice(pdriver_object pdevobj); //建立裝置

ntstatus helloddkdispatchroutine(in pdevice_object pdevobj,in pirp pirp); //派遣函式

ntstatus helloddkcontrol(in pdevice_object pdevobj,in pirp pirp); //irp_mj_directory_control

driver.cpp

#include "hello.h"

//獲取裝置資訊

void getdeviceobjectinfo( pdevice_object devobj)

else if ( devobj->driverobject )

}}//獲取過濾裝置資訊

void getattacheddeviceinfo( pdevice_object devobj )

}//列舉裝置棧

pdriver_object enumdevicestack( pwstr pwszdevicename )

// 進一步判斷當前裝置上 vpb 中的裝置

if ( deviceobject->vpb && deviceobject->vpb->deviceobject )

}// 得到建立在此驅動上的下乙個裝置 device_object

deviceobject = deviceobject->nextdevice;

} return driverobject;

}ntstatus driverentry(in pdriver_object driverobject, in punicode_string registrypath)

//建立裝置

createdevice(driverobject);

enumdevicestack(l"\\driver\\kbdclass");

return status_success;

}//解除安裝函式

void hellounload(in pdriver_object driverobject)

}//建立裝置

ntstatus createdevice(pdriver_object pdriver_object)

pdevobje->flags |= do_direct_io;

pdevext=(pdevice_extension)pdevobje->deviceextension;

pdevext->pdevice=pdevobje;

pdevext->ustrdevicename=devname;

pdevext->ustrsymlinkname=symlinkname;

//建立符號連線

if (iocreatesymboliclink(&symlinkname,&devname)!=status_success )

return status_success;

}//派遣函式

ntstatus helloddkdispatchroutine(in pdevice_object pdevobj,in pirp pirp)

; uchar type = stack->majorfunction;

if (type >= countarray(irpname))

kdprint(("無效的irp型別 %x\n", type));

else

kdprint(("%s\n", irpname[type]));

pirp->iostatus.status=status_success; //設定完成狀態

pirp->iostatus.information=0; //設定操作位元組為0

iocompleterequest(pirp,io_no_increment); //結束irp派遣函式,第二個引數表示不增加優先順序

return status_success;

}

列舉系統裝置

方法一 include include include include include include pragma comment lib,setupapi.lib define bufsize 1024 define sm serverr 289 intmain enumerate throug...

Linux USB Gadget 裝置列舉

linux usb gadget 裝置列舉 自 前面介紹了linux usb gadget的軟體結構與各軟體層的整合過程。經過各種註冊函式,gadget功能驅動層,usb裝置層與udc底層結合在了一起形成了乙個完整的usb裝置。而這個裝置已經準備好了接受主機的列舉。在介紹usb裝置列舉之前。先熟悉一...

vc 列舉USB裝置

include pragma comment lib,shlwapi.lib include pragma comment lib,setupapi.lib 函式名稱 enumusbdev 函式功能 列舉裝置 參 數 acdevpath 存放裝置路徑 ndevnum 裝置數量 返 回 值 成功返回t...