�ڴ�����������ʱ���ں��е��ڴ������ģ�Ҫע���ֹ��������� 1.���ƻ������ij���
| 329 | // �ڴ�����������ʱ���ں��е��ڴ������ģ�Ҫע���ֹ��������� |
| 330 | // 1.���ƻ������ij��� |
| 331 | _Use_decl_annotations_ |
| 332 | NTSTATUS AntiRootkitDeviceControl(PDEVICE_OBJECT, PIRP Irp) { |
| 333 | // get our IO_STACK_LOCATION |
| 334 | auto status = STATUS_INVALID_DEVICE_REQUEST; |
| 335 | const auto& dic = IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl; |
| 336 | ULONG len = 0; |
| 337 | |
| 338 | switch (dic.IoControlCode) { |
| 339 | case IOCTL_ARK_GET_SHADOW_SERVICE_TABLE: |
| 340 | { |
| 341 | if (Irp->AssociatedIrp.SystemBuffer == nullptr) { |
| 342 | status = STATUS_INVALID_PARAMETER; |
| 343 | break; |
| 344 | } |
| 345 | if (dic.InputBufferLength < sizeof(void*)) { |
| 346 | status = STATUS_BUFFER_TOO_SMALL; |
| 347 | break; |
| 348 | } |
| 349 | void* p = *(PULONG*)Irp->AssociatedIrp.SystemBuffer; |
| 350 | if (!MmIsAddressValid(p)) |
| 351 | break; |
| 352 | SystemServiceTable* pSystemServiceTable = (SystemServiceTable*)p; |
| 353 | // �������������ij��� |
| 354 | if (dic.OutputBufferLength < sizeof(PULONG)) { |
| 355 | status = STATUS_BUFFER_TOO_SMALL; |
| 356 | break; |
| 357 | } |
| 358 | pSystemServiceTable += 1; |
| 359 | khook::_win32kTable = pSystemServiceTable; |
| 360 | *(PULONG*)Irp->AssociatedIrp.SystemBuffer = pSystemServiceTable->ServiceTableBase; |
| 361 | len = sizeof(PULONG); |
| 362 | status = STATUS_SUCCESS; |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | case IOCTL_ARK_GET_SSDT_API_ADDR: |
| 367 | { |
| 368 | if (Irp->AssociatedIrp.SystemBuffer == nullptr) { |
| 369 | status = STATUS_INVALID_PARAMETER; |
| 370 | break; |
| 371 | } |
| 372 | if (dic.InputBufferLength < sizeof(ULONG)) { |
| 373 | status = STATUS_BUFFER_TOO_SMALL; |
| 374 | break; |
| 375 | } |
| 376 | // �������������ij��� |
| 377 | if (dic.OutputBufferLength < sizeof(void*)) { |
| 378 | status = STATUS_BUFFER_TOO_SMALL; |
| 379 | break; |
| 380 | } |
| 381 | |
| 382 | PVOID address; |
| 383 | ULONG number = *(ULONG*)Irp->AssociatedIrp.SystemBuffer; |
| 384 | bool success = khook::GetApiAddress(number,&address); |
| 385 | if (success) { |
| 386 | *(PVOID*)Irp->AssociatedIrp.SystemBuffer = address; |
| 387 | len = sizeof(address); |
| 388 | status = STATUS_SUCCESS; |
nothing calls this directly
no test coverage detected