13,871
社区成员




add eax,HookExceptionNo * 08h + 04h//这一行里的HookExceptionNo 是一个宏,值为3
//改为:
add eax,HookExceptionNo * 08h + 04h//这一行里的HookExceptionNo 是一个宏,值为3
bool GetDiskInfo_9x(int iDriver,unsigned short *DiskData)
{
const unsigned char cBusy=0x80;
const unsigned short BaseAddress[4]={0x01f0,0x0170,0x01e8,0x0168}; //IDE插槽口号
const unsigned int MastOrSalve[2]={0x0a0,0x0b0}; //Master or Salve
unsigned short OutData[256];
unsigned short BaseAddr = BaseAddress[iDriver/2];
unsigned char MOS = MastOrSalve[iDriver%2];
unsigned char idtr[6];
unsigned long oldExceptionHook;
bool bSuccess;
__asm
{
mov bSuccess,0
jmp EnterRing0
WaitWhileBusy:
mov ebx,100000
mov dx,BaseAddr
add dx,7
LoopWhileBusy:
dec ebx
cmp ebx,0
jz Timeout
in al,dx
test al,cBusy
jnz LoopWhileBusy
jmp DriveReady
Timeout:
jmp LeaveRing0_wait
DriveReady:
ret
LeaveRing0_wait:
popad
iretd
SelectDevice:
mov dx,BaseAddr
add dx,6
mov al,MOS
out dx,al
ret
SendCmd:
mov dx,BaseAddr
add dx,7
mov al,bl
out dx,al
ret
Ring0Proc:
pushad
mov dx,BaseAddr
add dx,7
in al,dx
cmp al,0ffh
jz LeaveRing0
cmp al,07fh
jz LeaveRing0
call WaitWhileBusy
call SelectDevice
call WaitWhileBusy
test al,040h
jz LeaveRing0
call WaitWhileBusy
call SelectDevice
mov bl,0ech
call SendCmd
call WaitWhileBusy
mov dx, BaseAddr
add dx,7
in al,dx
test al,01h
jz ReadDiskInfo
call WaitWhileBusy
call SelectDevice
mov bl,0a1h
call SendCmd
call WaitWhileBusy
mov dx,BaseAddr
add dx,7
in al,dx
test al,01h
jz ReadDiskInfo
jmp LeaveRing0
ReadDiskInfo:
lea edi,OutData
mov ecx,256
mov dx,BaseAddr
cld
rep insw
mov bSuccess,1
LeaveRing0:
popad
iretd
EnterRing0:
sidt fword ptr idtr
mov eax,dword ptr idtr + 02h
add eax,HookExceptionNo * 08h + 04h//这一行里的HookExceptionNo 是一个宏,值为3
cli
mov ecx,dword ptr [eax]
mov cx,word ptr [eax-04h]
mov oldExceptionHook,ecx
lea ebx,Ring0Proc
mov word ptr [eax-04h],bx
shr ebx,10h
mov word ptr[eax+02h],bx
int HookExceptionNo
mov ecx,oldExceptionHook
mov word ptr[eax-04h],cx
shr ecx,10h
mov word ptr[eax+02h],cx
sti
}
for(int i=0;i<256;i++)
{
DiskData[i]=OutData[i];
OutData[i]=0;
}
return bSuccess;
}