HANDLE g_hClient;
IO_STATUS_BLOCK g_ioStatusBlock;
KEVENT g_event;
typedef struct
{
int
type
;
unsigned
long
address;
unsigned
long
buffer_data_len;
char buffer_data[
0
];
}Networkreport;
VOID NdisMSleep(IN ULONG MicrosecondsToSleep);
/
/
初始化管道
void init()
{
UNICODE_STRING uniName;
OBJECT_ATTRIBUTES objAttr;
RtlInitUnicodeString(&uniName, L
"\\DosDevices\\Pipe\\LySharkPipeConn"
);
InitializeObjectAttributes(&objAttr, &uniName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
ZwCreateFile(&g_hClient, GENERIC_READ | GENERIC_WRITE, &objAttr, &g_ioStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL,
0
, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL,
0
);
if
(!g_hClient)
{
return
;
}
KeInitializeEvent(&g_event, SynchronizationEvent, TRUE);
}
/
/
将数据传到R3应用层
/
/
PowerBy: LyShark.com
VOID ReportToR3(Networkreport
*
m_parameter,
int
lent)
{
if
(!NT_SUCCESS(ZwWriteFile(g_hClient, NULL, NULL, NULL, &g_ioStatusBlock, (void
*
)m_parameter, lent, NULL, NULL)))
{
DbgPrint(
"写出错误"
);
}
}
VOID UnDriver(PDRIVER_OBJECT driver)
{
DbgPrint(
"驱动卸载成功 \n"
);
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT Driver, PUNICODE_STRING RegistryPath)
{
init();
/
/
延时
3
秒
NdisMSleep(
3000000
);
DbgPrint(
"hello lyshark \n"
);
for
(
int
x
=
0
; x <
10
; x
+
+
)
{
/
/
分配空间
Networkreport
*
report
=
(Networkreport
*
)ExAllocatePoolWithTag(NonPagedPool,
4096
,
'lysh'
);
if
(report)
{
RtlZeroMemory(report,
4096
);
report
-
>
type
=
x;
report
-
>address
=
401000
+
x;
report
-
>buffer_data_len
=
13
;
/
/
定位到结构体最后一个元素上
unsigned char
*
tmp
=
(unsigned char
*
)report
+
sizeof(Networkreport);
memcpy(tmp,
"hello lyshark"
,
13
);
/
/
发送到应用层
ReportToR3(report,
4096
);
ExFreePool(report);
}
}
DbgPrint(
"驱动加载成功 \n"
);
Driver
-
>DriverUnload
=
UnDriver;
return
STATUS_SUCCESS;
}