Skip to content


[nt inside Study] IopfCallDriver, IopfCompleteRequest, IopAllocateIrpPrivate, IopFreeIrp

오늘 무심결에 알게된건데 IopfCallDriver, IopfCompleteRequest, IopAllocateIrpPrivate, IopFreeIrp 라는 녀석들은 글로벌로 연속으로 Function Pointer가 선언이 되어 있는거 같습니다.  글로벌 변수인 pIofCallDriver의 주소만 바꿔치기하면 IoCallDriver가 자동으로 후킹이 되는걸까요 ?? Detours 방식으로 많이들 후킹하시는것 같던데 ..

lkd> dd nt!pIofCallDriver
8055c780 804e33b2 804e37c8 804ecd08 804ece61
8055c790 00000000 00000000 00000000 00000000
8055c7a0 00000000 00000000 00000000 00000000
8055c7b0 00000000 00000000 00000000 00000000
8055c7c0 00000000 00000000 00000000 00000000
8055c7d0 00000000 00000000 00000000 00000000
8055c7e0 00000000 00000000 00000000 00000000
8055c7f0 00000000 00000000 00000000 00000000
lkd> u 804e33b2
nt!IopfCallDriver:
804e33b2 fe4a23 dec byte ptr [edx+23h]
804e33b5 8a4223 mov al,byte ptr [edx+23h]
804e33b8 84c0 test al,al
804e33ba 0f8e50ed0300 jle nt!IopfCallDriver+0xa (80522110)
804e33c0 8b4260 mov eax,dword ptr [edx+60h]
804e33c3 83e824 sub eax,24h
804e33c6 56 push esi
804e33c7 894260 mov dword ptr [edx+60h],eax
lkd> u 804e37c8
nt!IopfCompleteRequest:

804e37c8 8bff mov edi,edi
804e37ca 55 push ebp
804e37cb 8bec mov ebp,esp
804e37cd 83ec10 sub esp,10h
804e37d0 53 push ebx
804e37d1 56 push esi
804e37d2 8bf1 mov esi,ecx
804e37d4 8a4e23 mov cl,byte ptr [esi+23h]
lkd> u 804ecd08
nt!IopAllocateIrpPrivate:
804ecd08 6a1c push 1Ch
804ecd0a 6850ce4e80 push offset nt!GUID_DOCK_INTERFACE+0×24 (804ece50)
804ecd0f e86f81ffff call nt!_SEH_prolog (804e4e83)
804ecd14 a1981c5680 mov eax,dword ptr [nt!IopIrpStackProfiler+0x98 (80561c98)]
804ecd19 83e003 and eax,3
804ecd1c 3c03 cmp al,3
804ecd1e 0f84dafc0200 je nt!IopAllocateIrpPrivate+0×18 (8051c9fe)
804ecd24 33db xor ebx,ebx
lkd> u 804ece61
nt!IopFreeIrp:

804ece61 8bff mov edi,edi
804ece63 55 push ebp
804ece64 8bec mov ebp,esp
804ece66 53 push ebx
804ece67 56 push esi
804ece68 8b7508 mov esi,dword ptr [ebp+8]
804ece6b 66833e06 cmp word ptr [esi],6
804ece6f 57 push edi

우리가 가장 많이 사용하는 IoCallDriver(IopfCallDrvier)를 C로 바꾸면 아래와 같습니다.  참고만하세요 ^^

NTSTATUS __fastcall IopfCallDriver( IN PDEVICE_OBJECT pDeviceObject, IN OUT PIRP pIrp )
{
PIO_STACK_LOCATION pIrpSp;
PDRIVER_OBJECT pDriverObject;
NTSTATUS ntStatus;
--(pIrp->CurrentLocation);

if ( pIrp->CurrentLocation <= 0 )
{
KeBugCheckEx( NO_MORE_IRP_STACK_LOCATIONS, (ULONG_PTR)pIrp, 0, 0, 0 );
}

pIrpSp = IoGetNextIrpStackLocation( pIrp );
pIrp->Tail.Overlay.CurrentStackLocation = pIrpSp;

pIrpSp->DeviceObject = pDeviceObject;

pDriverObject = pDeviceObject->DriverObject;

ntStatus = (pDriverObject->MajorFunction[pIrpSp->MajorFunction])( pDeviceObject, pIrp );

return ntStatus;
}

재미삼아…

Posted in Inside Windows.

2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Z said

    디투어를 쓰는 단 한가지 이유는 MS Research에서 제공하는 라입이라는 이유…
    다른 이유는 없음…ㅋ…
    점프코드 패치 방식이…아무래도… 다른 프로그램과의 충돌문제가 생길 소지가 크기 때문에….
    아슬아슬 하죠…쩝…
    Detour professional 라이센스 있는 버전이 릴리즈 됬던데… Windows 64버전에서 제대로 돌아갈지… 모르겠네요… 패치가드가 가만히 냅둘지… ㅡㅡa…

  2. x64에서 될꺼 같기도 하고 안될꺼 같기도하고 . 아직 해보지 않아서 ㅜ.ㅜ
    게으름을 이겨내고 꼭 한번 해봐야겠내요 후후 ..

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.