Hallo,
kann mir jemand helfen ich finde irgendwie nichts passendes.
Ich habe einen Treiber welcher mit einem User-Programm kommunizieren soll.
So es funktioneirt soweit auch alles bislang, jedoch weiß ich nun nicht wie ich an eine gesendete Nachricht komme.
Also um alles anzugeben. Hier die wichtigen Stellen aus dem User-Mode-Programm:
So nun versuche ich über WriteFile() mit meinem Treiber zu kommuizieren.
Das funktioniert soweit einwandfrei.
So nun zum Treiber:
in der "Main":
SO diese Funktion wird nun aufgerufen, wenn ich im User-Mode-Programm WriteFile() benutze. Nun habe ich allerdings nichts in der MSDN gefunden. was mich weiter bringt, wo nun "this is a test" drinsteht.
Hier der Link für IRP_MJ_WRITE:
http://msdn.microsoft.com/en-us/library/ff549427(VS.85).aspx
ich habe den Mode auf Buffered mit
gesetzt.
Und so bekommt man Informationen in der Funktion zur IOCTL:
So nun einmal folgendes:
Dann bekomme ich so:
Die Länger herraus. Dort steht auch 14 drin so wie es seien sollte.
In Write.Key steht immer NULL.
Also wo steht nun mein String?
Hier ist die gesamte definition der Struktur wo alles drinstehen müsste:
EDIT:
folgendes hab ich noch gefunden:
http://msdn.microsoft.com/en-us/library/ms810023.aspx
Hier steht drin:
kann mir jemand helfen ich finde irgendwie nichts passendes.
Ich habe einen Treiber welcher mit einem User-Programm kommunizieren soll.
So es funktioneirt soweit auch alles bislang, jedoch weiß ich nun nicht wie ich an eine gesendete Nachricht komme.
Also um alles anzugeben. Hier die wichtigen Stellen aus dem User-Mode-Programm:
C++:
hDevice = CreateFile("\\\\.\\dosvicesys",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
So nun versuche ich über WriteFile() mit meinem Treiber zu kommuizieren.
C++:
WriteFile(hDevice, "this is a test", 14, &dwBytesWritten, NULL);
So nun zum Treiber:
in der "Main":
C:
DriverObject->MajorFunction[IRP_MJ_WRITE] = WriteProcessing;
C:
NTSTATUS WriteProcessing( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp )
{
DbgPrint("WriteProcessing called\n");
return STATUS_SUCCESS;
}
SO diese Funktion wird nun aufgerufen, wenn ich im User-Mode-Programm WriteFile() benutze. Nun habe ich allerdings nichts in der MSDN gefunden. was mich weiter bringt, wo nun "this is a test" drinsteht.
Hier der Link für IRP_MJ_WRITE:
http://msdn.microsoft.com/en-us/library/ff549427(VS.85).aspx
ich habe den Mode auf Buffered mit
C:
DriverObject->Flags |= DO_BUFFERED_IO;
Und so bekommt man Informationen in der Funktion zur IOCTL:
C:
PIO_STACK_LOCATION IrpSp;
ULONG FunctionCode;
IrpSp = IoGetCurrentIrpStackLocation(Irp);
FunctionCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
switch( FunctionCode )
{
// Mache irgendetwas
}
// als Beispiel
So nun einmal folgendes:
C:
//
// Parameters for IRP_MJ_WRITE
//
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT Key;
LARGE_INTEGER ByteOffset;
} Write;
Dann bekomme ich so:
C:
PIO_STACK_LOCATION IrpSp;
ULONG receiveLenght;
IrpSp = IoGetCurrentIrpStackLocation(Irp);
receiveLenght = IrpSp->Parameters.Write.Length;
Die Länger herraus. Dort steht auch 14 drin so wie es seien sollte.
In Write.Key steht immer NULL.
Also wo steht nun mein String?
Hier ist die gesamte definition der Struktur wo alles drinstehen müsste:
C:
typedef struct _IO_STACK_LOCATION {
UCHAR MajorFunction;
UCHAR MinorFunction;
UCHAR Flags;
UCHAR Control;
union {
//
// Parameters for IRP_MJ_CREATE
//
struct {
PIO_SECURITY_CONTEXT SecurityContext;
ULONG Options;
USHORT POINTER_ALIGNMENT FileAttributes;
USHORT ShareAccess;
ULONG POINTER_ALIGNMENT EaLength;
} Create;
//
// Parameters for IRP_MJ_READ
//
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT Key;
LARGE_INTEGER ByteOffset;
} Read;
//
// Parameters for IRP_MJ_WRITE
//
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT Key;
LARGE_INTEGER ByteOffset;
} Write;
//
// Parameters for IRP_MJ_QUERY_INFORMATION
//
struct {
ULONG Length;
FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
} QueryFile;
//
// Parameters for IRP_MJ_SET_INFORMATION
//
struct {
ULONG Length;
FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
PFILE_OBJECT FileObject;
union {
struct {
BOOLEAN ReplaceIfExists;
BOOLEAN AdvanceOnly;
};
ULONG ClusterCount;
HANDLE DeleteHandle;
};
} SetFile;
//
// Parameters for IRP_MJ_QUERY_VOLUME_INFORMATION
//
struct {
ULONG Length;
FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
} QueryVolume;
//
// Parameters for IRP_MJ_DEVICE_CONTROL and IRP_MJ_INTERNAL_DEVICE_CONTROL
//
struct {
ULONG OutputBufferLength;
ULONG POINTER_ALIGNMENT InputBufferLength;
ULONG POINTER_ALIGNMENT IoControlCode;
PVOID Type3InputBuffer;
} DeviceIoControl;
//
// Nonsystem service parameters.
//
// Parameters for IRP_MN_MOUNT_VOLUME
//
struct {
PVOID DoNotUse1;
PDEVICE_OBJECT DeviceObject;
} MountVolume;
//
// Parameters for IRP_MN_VERIFY_VOLUME
//
struct {
PVOID DoNotUse1;
PDEVICE_OBJECT DeviceObject;
} VerifyVolume;
//
// Parameters for Scsi using IRP_MJ_INTERNAL_DEVICE_CONTROL
//
struct {
struct _SCSI_REQUEST_BLOCK *Srb;
} Scsi;
//
// Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
//
struct {
DEVICE_RELATION_TYPE Type;
} QueryDeviceRelations;
//
// Parameters for IRP_MN_QUERY_INTERFACE
//
struct {
CONST GUID *InterfaceType;
USHORT Size;
USHORT Version;
PINTERFACE Interface;
PVOID InterfaceSpecificData;
} QueryInterface;
//
// Parameters for IRP_MN_QUERY_CAPABILITIES
//
struct {
PDEVICE_CAPABILITIES Capabilities;
} DeviceCapabilities;
//
// Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
//
struct {
PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
} FilterResourceRequirements;
//
// Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
//
struct {
ULONG WhichSpace;
PVOID Buffer;
ULONG Offset;
ULONG POINTER_ALIGNMENT Length;
} ReadWriteConfig;
//
// Parameters for IRP_MN_SET_LOCK
//
struct {
BOOLEAN Lock;
} SetLock;
//
// Parameters for IRP_MN_QUERY_ID
//
struct {
BUS_QUERY_ID_TYPE IdType;
} QueryId;
//
// Parameters for IRP_MN_QUERY_DEVICE_TEXT
//
struct {
DEVICE_TEXT_TYPE DeviceTextType;
LCID POINTER_ALIGNMENT LocaleId;
} QueryDeviceText;
//
// Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
//
struct {
BOOLEAN InPath;
BOOLEAN Reserved[3];
DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
} UsageNotification;
//
// Parameters for IRP_MN_WAIT_WAKE
//
struct {
SYSTEM_POWER_STATE PowerState;
} WaitWake;
//
// Parameter for IRP_MN_POWER_SEQUENCE
//
struct {
PPOWER_SEQUENCE PowerSequence;
} PowerSequence;
//
// Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
//
struct {
ULONG SystemContext;
POWER_STATE_TYPE POINTER_ALIGNMENT Type;
POWER_STATE POINTER_ALIGNMENT State;
POWER_ACTION POINTER_ALIGNMENT ShutdownType;
} Power;
//
// Parameters for IRP_MN_START_DEVICE
//
struct {
PCM_RESOURCE_LIST AllocatedResources;
PCM_RESOURCE_LIST AllocatedResourcesTranslated;
} StartDevice;
//
// Parameters for WMI Minor IRPs
//
struct {
ULONG_PTR ProviderId;
PVOID DataPath;
ULONG BufferSize;
PVOID Buffer;
} WMI;
//
// Others - driver-specific
//
struct {
PVOID Argument1;
PVOID Argument2;
PVOID Argument3;
PVOID Argument4;
} Others;
} Parameters;
PDEVICE_OBJECT DeviceObject;
PFILE_OBJECT FileObject;
.
.
.
} IO_STACK_LOCATION, *PIO_STACK_LOCATION;
EDIT:
folgendes hab ich noch gefunden:
http://msdn.microsoft.com/en-us/library/ms810023.aspx
Hier steht drin:
To receive read and write requests as buffered I/O, the driver sets the DO_BUFFERED_IO flag in the DeviceObject- >Flags field during initialization. When a driver receives a buffered I/O request, the Irp- >AssociatedIrp.SystemBuffer field contains the address of the kernel-mode buffer on which the driver should operate. The I/O Manager copies data from the kernel-mode buffer to the user-mode buffer during a read request, or from the user-mode buffer to the kernel-mode buffer during a write request.
Zuletzt bearbeitet: