目前共有6篇帖子。 字體大小:較小 - 100% (默認)▼  內容轉換:不轉換▼
 
點擊 回復
30 5
我的第一个windows xp设备驱动程序
一派掌門 二十級
1樓 發表于:2025-6-17 19:09
一派掌門 二十級
2樓 發表于:2025-6-17 19:09

 
一派掌門 二十級
3樓 發表于:2025-6-17 19:09
 
一派掌門 二十級
4樓 發表于:2025-6-17 19:10
【HelloWDM.inf】
[Version]
Signature="$CHICAGO$"
Provider=Zhangfan_Device
DriverVer=11/1/2007,3.0.0.3
Class=ZhangfanDevice
ClassGUID={EF2962F0-0D55-4bff-B8AA-2221EE8A79B0}

[SourceDisksNames]
1 = "HelloWDM",Disk1,,

[SourceDisksFiles]
HelloWDM.sys = 1,MyDriver_Check,

[ClassInstall]
Addreg=Class_AddReg

[ClassInstall32]
Addreg=Class_AddReg

[Class_AddReg]
HKR,,,,%DeviceClassName%
HKR,,Icon,,"-5"

[DestinationDirs]
YouMark_Files_Driver = 10,System32\Drivers

[Manufacturer]
%MfgName%=Mfg0

[Mfg0]
%DeviceDesc%=YouMark_DDI, PCI\VEN_9999&DEV_9999

[YouMark_DDI]
CopyFiles=YouMark_Files_Driver
AddReg=YouMark_9X_AddReg

[YouMark_9X_AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,HelloWDM.sys
HKR, "Parameters", "BreakOnEntry", 0x00010001, 0

[YouMark_DDI.NT]
CopyFiles=YouMark_Files_Driver
AddReg=YouMark_NT_AddReg

[YouMark_DDI.NT.Services]
Addservice = HelloWDM, 0x00000002, YouMark_AddService

[YouMark_AddService]
DisplayName = %SvcDesc%
ServiceType = 1
StartType = 3
ErrorControl = 1
ServiceBinary = %10%\System32\Drivers\HelloWDM.sys

[YouMark_NT_AddReg]
HKLM, "System\CurrentControlSet\Services\HelloWDM\Parameters",\
"BreakOnEntry", 0x00010001, 0

[YouMark_Files_Driver]
HelloWDM.sys

[Strings]
ProviderName="Zhangfan."
MfgName="Zhangfan Soft"
DeviceDesc="Hello World WDM!"
DeviceClassName="Zhangfan_Device"
SvcDesc="Zhangfan"
 
一派掌門 二十級
5樓 發表于:2025-6-17 19:12
【main.c】
#include <wdm.h>

struct device_extension
{
        PDEVICE_OBJECT device;
        PDEVICE_OBJECT next_stack_device;
        UNICODE_STRING device_name;
        UNICODE_STRING symlink_name;
};

NTSTATUS hello_add_device(PDRIVER_OBJECT driver, PDEVICE_OBJECT physical_device)
{
    struct device_extension *ext;
    NTSTATUS status;
    PDEVICE_OBJECT device;
    UNICODE_STRING device_name;
   
    RtlInitUnicodeString(&device_name, L"\\Device\\MyWDMDevice");
    status = IoCreateDevice(driver, sizeof(struct device_extension), &device_name, FILE_DEVICE_UNKNOWN, 0, FALSE, &device);
    if (!NT_SUCCESS(status))
        return status;
    device->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
    ext = device->DeviceExtension;
    ext->device = device;
    ext->next_stack_device = IoAttachDeviceToDeviceStack(device, physical_device);
    ext->device_name = device_name;
   
    RtlInitUnicodeString(&ext->symlink_name, L"\\DosDevices\\HelloDDK");
    status = IoCreateSymbolicLink(&ext->symlink_name, &device_name);
    if (!NT_SUCCESS(status))
    {
        IoDeleteDevice(device);
        return status;
    }
   
    device->Flags &= ~DO_DEVICE_INITIALIZING;
    return STATUS_SUCCESS;
}

void hello_unload(PDRIVER_OBJECT driver)
{
    KdPrint(("Enter hello_unload\n"));
    KdPrint(("Leave hello_unload\n"));
}

NTSTATUS hello_default_pnp_handler(struct device_extension *ext, PIRP irp)
{
    KdPrint(("default pnp handler\n"));
    IoSkipCurrentIrpStackLocation(irp);
    return IoCallDriver(ext->next_stack_device, irp);
}

NTSTATUS hello_pnp(PDEVICE_OBJECT device, PIRP irp)
{
    struct device_extension *ext;
    PIO_STACK_LOCATION stack;
    NTSTATUS status;
   
    KdPrint(("Enter hello_pnp\n"));
    ext = device->DeviceExtension;
    stack = IoGetCurrentIrpStackLocation(irp);
    if (stack->MinorFunction == 2)
    {
        KdPrint(("handle remove device\n"));
        status = hello_default_pnp_handler(ext, irp);
        IoDeleteSymbolicLink(&ext->symlink_name);
        if (ext->next_stack_device)
            IoDetachDevice(ext->next_stack_device);
        IoDeleteDevice(ext->device);
    }
    else
        status = hello_default_pnp_handler(ext, irp);
   
    KdPrint(("Leave hello_pnp\n"));
    return status;
}

NTSTATUS hello_proc(PDEVICE_OBJECT device, PIRP irp)
{
    KdPrint(("Enter hello_proc\n"));
    irp->IoStatus.Status = STATUS_SUCCESS;
    irp->IoStatus.Information = 0; // bytes transfered
    IoCompleteRequest(irp, IO_NO_INCREMENT);
    KdPrint(("Leave hello_proc\n"));
    return STATUS_SUCCESS;
}

NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING registry_path)
{
    KdPrint(("Enter DriverEntry\n"));
    driver->DriverExtension->AddDevice = hello_add_device;
    driver->DriverUnload = hello_unload;
    driver->MajorFunction[IRP_MJ_PNP] = hello_pnp;
    driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = hello_proc;
    driver->MajorFunction[IRP_MJ_CREATE] = hello_proc;
    driver->MajorFunction[IRP_MJ_WRITE] = hello_proc;
    driver->MajorFunction[IRP_MJ_READ] = hello_proc;
   
    KdPrint(("Leave DriverEntry\n"));
    return STATUS_SUCCESS;
}

 
一派掌門 二十級
6樓 發表于:2025-6-17 19:12
【Sources】
TARGETNAME=HelloWDM
TARGETTYPE=DRIVER
DRIVERTYPE=WDM
TARGETPATH=OBJ

INCLUDES=$(BASEDIR)\inc;$(BASEDIR)\inc\ddk

SOURCES=main.c
 

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:30 回複數:5
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2025-6-17 19:12
 
©2010-2025 Purasbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。