📄 packet32.c
字号:
AdapterObject->hFile,
(DWORD)IOCTL_PROTOCOL_RESET,
NULL,
0,
NULL,
0,
&BytesReturned,
NULL
);
}
BOOL
PacketRequest(
LPADAPTER AdapterObject,
BOOLEAN Set,
PPACKET_OID_DATA OidData
)
/*++
Routine Description:
This routine sends issues a request to and adapter
Arguments:
AdapterObject - AdapterObject return by PacketOpenAdapter
Set - True means that the request is SET otherwise it is a query
OidData - Structure containing the details of the OID
Return Value:
SUCCESS -
FAILURE -
--*/
{
UINT BytesReturned;
BOOL Result;
Result=DeviceIoControl(
AdapterObject->hFile,
(DWORD) Set ? IOCTL_PROTOCOL_SET_OID : IOCTL_PROTOCOL_QUERY_OID,
OidData,
sizeof(PACKET_OID_DATA)-1+OidData->Length,
OidData,
sizeof(PACKET_OID_DATA)-1+OidData->Length,
&BytesReturned,
NULL
);
return Result;
}
BOOL
PacketSetFilter(
LPADAPTER AdapterObject,
ULONG Filter
)
/*++
Routine Description:
This rotine sets the adapters packet filter
Arguments:
AdapterObject - AdapterObject return by PacketOpenAdapter
Filter - filter to be set
Return Value:
SUCCESS -
FAILURE -
--*/
{
BOOL Status;
ULONG IoCtlBufferLength=(sizeof(PACKET_OID_DATA)+sizeof(ULONG)-1);
PPACKET_OID_DATA OidData;
OidData=GlobalAllocPtr(
GMEM_MOVEABLE | GMEM_ZEROINIT,
IoCtlBufferLength
);
if (OidData == NULL) {
return FALSE;
}
OidData->Oid=OID_GEN_CURRENT_PACKET_FILTER;
OidData->Length=sizeof(ULONG);
*((PULONG)OidData->Data)=Filter;
Status=PacketRequest(
AdapterObject,
TRUE,
OidData
);
GlobalFreePtr(OidData);
return Status;
}
BOOL
PacketStartDriver(
LPTSTR ServiceName
)
/*++
Routine Description:
This routine Atempts to start the kernel mode packet driver
Arguments:
ServiceName - Name of service to try to start
Return Value:
SUCCESS -
FAILURE -
--*/
{
BOOL Status = FALSE;
SERVICE_STATUS ServiceStatus;
SC_HANDLE SCManagerHandle = NULL;
SC_HANDLE SCServiceHandle = NULL;
/* Open a handle to the SC Manager database. */
SCManagerHandle = OpenSCManager(
NULL, /* local machine */
NULL, /* ServicesActive database */
SC_MANAGER_ALL_ACCESS); /* full access rights */
if (SCManagerHandle==NULL) {
MessageBox(NULL,TEXT("Could not open SC"),szWindowTitle,MB_OK);
goto CleanExit;
} else {
SCServiceHandle=OpenService(SCManagerHandle,
ServiceName,
SERVICE_START
);
if (SCServiceHandle == NULL) {
MessageBox(NULL,TEXT("Could not open service"),szWindowTitle,MB_OK);
goto CleanExit;
}
Status=StartService(
SCServiceHandle,
0,
NULL
);
if (!Status) {
if (GetLastError()==ERROR_SERVICE_ALREADY_RUNNING) {
ODS("Packet32: Packet service already started\n");
Status = TRUE;
goto CleanExit;
} else {
MessageBox(NULL,TEXT("Could not start service"),szWindowTitle,MB_OK);
goto CleanExit;
}
}
do { // loop until the service is fully started.
if (!QueryServiceStatus(SCServiceHandle, &ServiceStatus))
{
goto CleanExit;
}
switch(ServiceStatus.dwCurrentState)
{
case SERVICE_RUNNING:
Status = TRUE;
goto CleanExit;
break;
case SERVICE_START_PENDING:
Sleep(2000);
break;
default:
goto CleanExit;
break;
}
}while (TRUE);
}
CleanExit:
if(SCManagerHandle != NULL) {
(VOID) CloseServiceHandle(SCManagerHandle);
}
if(SCServiceHandle != NULL) {
(VOID) CloseServiceHandle(SCServiceHandle);
}
return(Status);
}
BOOL
PacketStopDriver(
IN LPCTSTR ServiceName
)
{
BOOL Status = FALSE;
SERVICE_STATUS ServiceStatus;
SC_HANDLE SCManagerHandle = NULL;
SC_HANDLE SCServiceHandle = NULL;
/* Open a handle to the SC Manager database. */
SCManagerHandle = OpenSCManager(
NULL, /* local machine */
NULL, /* ServicesActive database */
SC_MANAGER_ALL_ACCESS); /* full access rights */
if (SCManagerHandle==NULL) {
MessageBox(NULL,TEXT("Could not open SC"),szWindowTitle,MB_OK);
goto CleanExit;
} else {
SCServiceHandle=OpenService(SCManagerHandle,
ServiceName,
SERVICE_STOP
);
if (SCServiceHandle == NULL) {
MessageBox(NULL,TEXT("Could not open service"),szWindowTitle,MB_OK);
goto CleanExit;
}
//
// Request that the service stop.
//
if (ControlService(SCServiceHandle,
SERVICE_CONTROL_STOP,
&ServiceStatus
)) {
//
// Indicate success.
//
Status = TRUE;
} else {
//MessageBox(NULL,TEXT("Could not stop service"),szWindowTitle,MB_OK);
}
}
CleanExit:
if(SCManagerHandle != NULL) {
(VOID) CloseServiceHandle(SCManagerHandle);
}
if(SCServiceHandle != NULL) {
(VOID) CloseServiceHandle(SCServiceHandle);
}
return Status;
} // PacketStopDriver
#if 0 // Not used on Win2K
BOOL
PacketInit(
IN PVOID DllHandle,
IN ULONG Reason,
IN PCONTEXT Context OPTIONAL
)
/*++
Routine Description:
Arguments:
DllHandle - Not Used
Reason - Attach or Detach
Context - Not Used
Return Value:
SUCCESS - TRUE
FAILURE - FALSE
--*/
{
BOOLEAN Status=TRUE;
ODS("Packet32: DllEntry\n");
switch ( Reason ) {
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return Status;
}
ULONG
PacketGetAdapterNames(
PTSTR pStr,
PULONG BufferSize
)
/*++
Routine Description:
This routine returns the names all adapters availible
Arguments:
Pstr - Pointer to a buffer which recieves the UNICODE names
Each name is NULL terminated with a second NULL at the end
of the list.
BufferSize - Size of the buffer passed in
Return Value:
SUCCESS -
FAILURE -
--*/
{
HKEY SystemKey;
HKEY ControlSetKey;
HKEY ServicesKey;
HKEY NdisPerfKey;
HKEY LinkageKey;
LONG Status;
DWORD RegType;
Status=RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("SYSTEM"),
0,
KEY_READ,
&SystemKey
);
if (Status == ERROR_SUCCESS) {
Status=RegOpenKeyEx(
SystemKey,
TEXT("CurrentControlSet"),
0,
KEY_READ,
&ControlSetKey
);
if (Status == ERROR_SUCCESS) {
Status=RegOpenKeyEx(
ControlSetKey,
TEXT("Services"),
0,
KEY_READ,
&ServicesKey
);
if (Status == ERROR_SUCCESS) {
Status=RegOpenKeyEx(
ServicesKey,
TEXT("Packet"),
0,
KEY_READ,
&NdisPerfKey
);
if (Status == ERROR_SUCCESS) {
Status=RegOpenKeyEx(
NdisPerfKey,
TEXT("Linkage"),
0,
KEY_READ,
&LinkageKey
);
if (Status == ERROR_SUCCESS) {
Status=RegQueryValueEx(
LinkageKey,
TEXT("Export"),
NULL,
&RegType,
(LPBYTE)pStr,
BufferSize
);
RegCloseKey(LinkageKey);
}
RegCloseKey(NdisPerfKey);
}
RegCloseKey(ServicesKey);
}
RegCloseKey(ControlSetKey);
}
RegCloseKey(SystemKey);
}
return Status;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -