无意中在WDK中看到这个函数,文档中给出的原型如下,捣鼓了一番怎么都不对,后来发现貌似最后一个参数MS写错了,应该是 OUT PVOID *Buffer,而且调用方式是 FASTCALL。
VOID
HalExamineMBR(
IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONG MBRTypeIdentifier,
OUT PVOID Buffer, // 应该是 OUT PVOID *Buffer
);
拿IDA看了一下,有个地方不明白,问什么要拿MBRTypeIdentifier和0x54,0x55比较呢,那两个常量我查了一下,不知所云。而且我的机器上MBR中启动分区的类型是 0x7,所以我的驱动调用HalExamineMBR一直不成功,请教一下这个函数到底怎么用?
54h OnTrack Disk Manager 6 Dyamic Drive Overlay (DDO)
55h MicroHouse / StorageSoft EZ-Drive EZ-Drive, Maxtor, MaxBlast, or DriveGuide INT 13h redirector volume
完整的分区类型列表在这里 http://en.wikipedia.org/wiki/Partition_type
.text:00415D6F 66 81 BE FE 01 00 00 55+ cmp word ptr [esi+1FEh], 0AA55h
.text:00415D78 75 BD jnz short loc_415D37
.text:00415D7A 8A 86 C2 01 00 00 mov al, [esi+1C2h]
.text:00415D80 0F B6 C8 movzx ecx, al
.text:00415D83 3B 4D 08 cmp ecx, [ebp+arg_0]; arg_0 is MBRTypeIdentifier
.text:00415D86 75 AF jnz short loc_415D37
.text:00415D88 3C 54 cmp al, 54h
.text:00415D8A 75 08 jnz short loc_415D94
.text:00415D8C C7 06 3F 00 00 00 mov dword ptr [esi], 3Fh
.text:00415D92 EB 04 jmp short loc_415D98
.text:00415D94 ; ---------------------------------------------------------------------------
.text:00415D94
.text:00415D94 loc_415D94: ; CODE XREF: HalExamineMBR(x,x,x,x)+CCj
.text:00415D94 3C 55 cmp al, 55h
.text:00415D96 75 05 jnz short loc_415D9D
.text:00415D98
.text:00415D98 loc_415D98: ; CODE XREF: HalExamineMBR(x,x,x,x)+D4j
.text:00415D98 8B 45 0C mov eax, [ebp+arg_4]
.text:00415D9B 89 30 mov [eax], esi
...
完整的函数如下, OS为Windows XP SP3:
public __fastcall HalExamineMBR(x, x, x, x)
.text:00415CBE __fastcall HalExamineMBR(x, x, x, x) proc near
.text:00415CBE ; CODE XREF: IoSetPartitionInformation(x,x,x,x)+2Cp
.text:00415CBE ; IoWritePartitionTable(x,x,x,x,x)+46p ...
.text:00415CBE
.text:00415CBE Event = _KEVENT ptr -24h
.text:00415CBE IoStatusBlock = _IO_STATUS_BLOCK ptr -14h
.text:00415CBE StartingOffset = LARGE_INTEGER ptr -0Ch
.text:00415CBE DeviceObject = dword ptr -4
.text:00415CBE arg_0 = dword ptr 8
.text:00415CBE arg_4 = dword ptr 0Ch
.text:00415CBE
.text:00415CBE 8B FF mov edi, edi
.text:00415CC0 55 push ebp
.text:00415CC1 8B EC mov ebp, esp
.text:00415CC3 83 EC 24 sub esp, 24h
.text:00415CC6 8B 45 0C mov eax, [ebp+arg_4]
.text:00415CC9 53 push ebx
.text:00415CCA 33 DB xor ebx, ebx
.text:00415CCC 89 18 mov [eax], ebx
.text:00415CCE 56 push esi
.text:00415CCF B8 00 02 00 00 mov eax, 200h
.text:00415CD4 3B D0 cmp edx, eax
.text:00415CD6 57 push edi
.text:00415CD7 89 4D FC mov [ebp+DeviceObject], ecx
.text:00415CDA 8B FA mov edi, edx
.text:00415CDC 73 02 jnb short loc_415CE0
.text:00415CDE 8B F8 mov edi, eax
.text:00415CE0
.text:00415CE0 loc_415CE0: ; CODE XREF: HalExamineMBR(x,x,x,x)+1Ej
.text:00415CE0 B8 00 10 00 00 mov eax, 1000h
.text:00415CE5 3B F8 cmp edi, eax
.text:00415CE7 89 5D F4 mov dword ptr [ebp+StartingOffset], ebx
.text:00415CEA 89 5D F8 mov dword ptr [ebp+StartingOffset+4], ebx
.text:00415CED 72 02 jb short loc_415CF1
.text:00415CEF 8B C7 mov eax, edi
.text:00415CF1
.text:00415CF1 loc_415CF1: ; CODE XREF: HalExamineMBR(x,x,x,x)+2Fj
.text:00415CF1 68 46 73 74 62 push 'btsF' ; Tag
.text:00415CF6 50 push eax ; NumberOfBytes
.text:00415CF7 6A 04 push 4 ; PoolType
.text:00415CF9 E8 82 73 05 00 call ExAllocatePoolWithTag(x,x,x)
.text:00415CFE 8B F0 mov esi, eax
.text:00415D00 3B F3 cmp esi, ebx
.text:00415D02 0F 84 95 00 00 00 jz loc_415D9D
.text:00415D08 8D 45 E4 lea eax, [ebp+Event.Header.WaitListHead]
.text:00415D0B 89 45 E8 mov [ebp+Event.Header.WaitListHead.Blink], eax
.text:00415D0E 89 45 E4 mov [ebp+Event.Header.WaitListHead.Flink], eax
.text:00415D11 8D 45 EC lea eax, [ebp+IoStatusBlock]
.text:00415D14 50 push eax ; IoStatusBlock
.text:00415D15 8D 45 DC lea eax, [ebp+Event]
.text:00415D18 50 push eax ; Event
.text:00415D19 8D 45 F4 lea eax, [ebp+StartingOffset]
.text:00415D1C 50 push eax ; StartingOffset
.text:00415D1D 57 push edi ; Length
.text:00415D1E 56 push esi ; Buffer
.text:00415D1F FF 75 FC push [ebp+DeviceObject] ; DeviceObject
.text:00415D22 88 5D DC mov [ebp+Event.Header.Type], bl
.text:00415D25 6A 03 push 3 ; MajorFunction
.text:00415D27 C6 45 DE 04 mov [ebp+Event.Header.Size], 4
.text:00415D2B 89 5D E0 mov [ebp+Event.Header.SignalState], ebx
.text:00415D2E E8 A3 34 00 00 call IoBuildSynchronousFsdRequest(x,x,x,x,x,x,x)
.text:00415D33 3B C3 cmp eax, ebx
.text:00415D35 75 09 jnz short loc_415D40
.text:00415D37
.text:00415D37 loc_415D37: ; CODE XREF: HalExamineMBR(x,x,x,x)+AFj
.text:00415D37 ; HalExamineMBR(x,x,x,x)+BAj ...
.text:00415D37 53 push ebx ; Tag
.text:00415D38 56 push esi ; P
.text:00415D39 E8 A8 6C 05 00 call ExFreePoolWithTag(x,x)
.text:00415D3E EB 5D jmp short loc_415D9D
.text:00415D40 ; ---------------------------------------------------------------------------
.text:00415D40
.text:00415D40 loc_415D40: ; CODE XREF: HalExamineMBR(x,x,x,x)+77j
.text:00415D40 8B 48 60 mov ecx, [eax+60h]
.text:00415D43 80 49 DE 02 or byte ptr [ecx-22h], 2
.text:00415D47 83 E9 24 sub ecx, 24h
.text:00415D4A 8B 4D FC mov ecx, [ebp+DeviceObject]
.text:00415D4D 8B D0 mov edx, eax
.text:00415D4F E8 AC 10 00 00 call IofCallDriver(x,x)
.text:00415D54 3D 03 01 00 00 cmp eax, 103h
.text:00415D59 75 10 jnz short loc_415D6B
.text:00415D5B 53 push ebx ; Timeout
.text:00415D5C 53 push ebx ; Alertable
.text:00415D5D 53 push ebx ; WaitMode
.text:00415D5E 53 push ebx ; WaitReason
.text:00415D5F 8D 45 DC lea eax, [ebp+Event]
.text:00415D62 50 push eax ; Object
.text:00415D63 E8 94 CA 00 00 call KeWaitForSingleObject(x,x,x,x,x)
.text:00415D68 8B 45 EC mov eax, dword ptr [ebp+IoStatusBlock.___u0]
.text:00415D6B
.text:00415D6B loc_415D6B: ; CODE XREF: HalExamineMBR(x,x,x,x)+9Bj
.text:00415D6B 3B C3 cmp eax, ebx
.text:00415D6D 7C C8 jl short loc_415D37
.text:00415D6F 66 81 BE FE 01 00 00 55+ cmp word ptr [esi+1FEh], 0AA55h
.text:00415D78 75 BD jnz short loc_415D37
.text:00415D7A 8A 86 C2 01 00 00 mov al, [esi+1C2h]
.text:00415D80 0F B6 C8 movzx ecx, al
.text:00415D83 3B 4D 08 cmp ecx, [ebp+arg_0]
.text:00415D86 75 AF jnz short loc_415D37
.text:00415D88 3C 54 cmp al, 54h
.text:00415D8A 75 08 jnz short loc_415D94
.text:00415D8C C7 06 3F 00 00 00 mov dword ptr [esi], 3Fh
.text:00415D92 EB 04 jmp short loc_415D98
.text:00415D94 ; ---------------------------------------------------------------------------
.text:00415D94
.text:00415D94 loc_415D94: ; CODE XREF: HalExamineMBR(x,x,x,x)+CCj
.text:00415D94 3C 55 cmp al, 55h
.text:00415D96 75 05 jnz short loc_415D9D
.text:00415D98
.text:00415D98 loc_415D98: ; CODE XREF: HalExamineMBR(x,x,x,x)+D4j
.text:00415D98 8B 45 0C mov eax, [ebp+arg_4]
.text:00415D9B 89 30 mov [eax], esi
.text:00415D9D
.text:00415D9D loc_415D9D: ; CODE XREF: HalExamineMBR(x,x,x,x)+44j
.text:00415D9D ; HalExamineMBR(x,x,x,x)+80j ...
.text:00415D9D 5F pop edi
.text:00415D9E 5E pop esi
.text:00415D9F 5B pop ebx
.text:00415DA0 C9 leave
.text:00415DA1 C2 08 00 retn 8
.text:00415DA1 __fastcall HalExamineMBR(x, x, x, x) endp
[课程]FART 脱壳王!加量不加价!FART作者讲授!