Original Post
I am create a driver to get the Device ID, Vendor ID, LFB and VBE Mode. The driver that I create already get the Device ID, Vendor ID, LFB of the display adapters but don't get the VBE mode because the Int 0x10 is returning AL != 0x4f. This is the code with the VBE function returning an error:
What is wrong at this code???
#include <wdm.h>
#include <windef.h>
#include <Ntstrsafe.h>
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath);
VOID Example_Unload(PDRIVER_OBJECT DriverObject);
BOOL IsIO_MemoryAddress = FALSE;
BOOL IsMemoryAddress = FALSE;
BOOL IsVRAM_Addr = FALSE;
unsigned long BUF[16];
DWORD OFFSET;
WORD bus,device;
BYTE FUNC;
int cont;
unsigned long BARRAMENTO;
unsigned long DISPOSITIVO;
unsigned long BARRAMENTO2;
unsigned long DISPOSITIVO2;
unsigned long addr;
unsigned long DisplayControllerVGACompatible;
unsigned long DisplayController;
unsigned long ClassCodeOF_theDevice;
unsigned long BAR;
unsigned long BAR2;
unsigned long buf_OF_DEVICES[16];
unsigned long ret_VAL;
unsigned long ret_VALUE = 0;
int I;
#pragma alloc_text(INIT, DriverEntry)
#pragma alloc_text(PAGE, Example_Unload)
/////////////////////////////////
/////////////////////////////////
///
unsigned long _1046(unsigned short lbus, unsigned short lslot, unsigned short lfunc, unsigned short offset)
{
unsigned long address = (unsigned long)((lbus << 16) | (lslot << 11) |
(lfunc << 8) | (offset & 0xfc) | ((UINT32)0x80000000));
__asm
{
mov dx,0x0CF8
mov eax,address
out dx,eax
mov dx,0x0CFC
in eax,dx
mov ret_VAL,eax
}
return ret_VAL;
}
int GetVideoAdapterVendorDeviceAndLFB()
{
INT ITERATOR = 0;
cont=1;
for(bus=0;(bus<16)&&contbus++) {
for(device=0;(device<32)&&contdevice++)
{
for(FUNC=0;(FUNC<8)&&contFUNC++)
{
ClassCodeOF_theDevice = _1046(bus,device,0,8);
if(((ClassCodeOF_theDevice>>16)&0xffff)==0x0300)
{
BARRAMENTO = bus;
DISPOSITIVO = device;
goto FINAL;
}
}
}
}
FINAL:
DisplayController = _1046(BARRAMENTO,DISPOSITIVO,0,0);
I = 0;
cont=1;
for(bus=0;(bus<16)&&contbus++) {
for(device=0;(device<32)&&contdevice++)
{
for(FUNC=0;(FUNC<8)&&contFUNC++)
{
ClassCodeOF_theDevice = _1046(bus,device,0,8);
if((ClassCodeOF_theDevice&0x00ffffff) == 0x00000100)
{
BARRAMENTO2 = bus;
DISPOSITIVO2 = device;
goto FINAL2;
}
}
}
}
FINAL2:
DisplayControllerVGACompatible = _1046(BARRAMENTO,DISPOSITIVO,0,0);
OFFSET = 16;
I = 0;
while(OFFSET<37)
{
BAR = _1046(BARRAMENTO,DISPOSITIVO,0,OFFSET);
BUF = BAR2 = BAR;
if (((BAR<<3)&0xffff) == 0)
IsMemoryAddress = TRUE;
OFFSET += 4;
I++;
}
FINAL3:
buf_OF_DEVICES[0] = DisplayControllerVGACompatible;
buf_OF_DEVICES[1] = DisplayController;
BUF[0] = BUF[0] & 0xFFFFFFF0;
BUF[1] = BUF[1] & 0xFFFFFFF0;
BUF[2] = BUF[2] & 0xFFFFFFF0;
buf_OF_DEVICES[2] = BUF[0];
buf_OF_DEVICES[3] = BUF[1];
buf_OF_DEVICES[4] = BUF[2];
return buf_OF_DEVICES;
}
BOOL GetVbeMode(DWORD ModeNumber)
{
__asm
{
MOV BX,00
SMSW BX
MOV CX,BX
AND BX,0x3fff
XOR BX,1 OR CX,BX
LMSW CX
MOV AX,0x4f03
INT 0x10 ;VERY IMPORTANT THIS IS THE MOST IMPORTANT INTERRUPT FOR ME!!! THE VIDEO BIOS INTERRUPT(INT 0x10)
CMP AL,0x4f
JNZ FAILED
JMP FINAL
FAILED:
MOV BX,00
SMSW BX
MOV CX,BX
AND BX,0x3fff
OR BX,1
OR CX,BX
LMSW CX
XOR EDX,EDX
MOV ret_VALUE,EDX
JMP FINAL2
FINAL:
MOV BX,00
SMSW BX
MOV CX,BX
AND BX,0x3fff
OR BX,1
OR CX,BX
LMSW CX
AND BX,0x3fff
MOVZX ECX,BX
MOV ModeNumber,ECX
XOR EDX,EDX
INC EDX
MOV ret_VALUE,EDX
FINAL2:
}
return ret_VALUE;
}
/////////////////////////////////
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath)
{
NTSTATUS NtStatus = STATUS_SUCCESS;
NTSTATUS status;
UINT uiIndex = 0;
PDEVICE_OBJECT pDeviceObject = NULL;
UNICODE_STRING usDriverName, usDosDeviceName;
ULONG Mode = 0;
DbgPrint("DriverEntry Called \r\n");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RtlInitUnicodeString(&usDriverName, L"\\Device\\SVGA");
RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\SVGA");
NtStatus = IoCreateDevice(pDriverObject, 0, &usDriverName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &pDeviceObject);
if(NtStatus == STATUS_SUCCESS)
{
DbgPrint("IOCREATEDEVICE CALLED \r\n");
IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
ret_VALUE = GetVbeMode(Mode);
if(ret_VALUE==FALSE)
{
buf_OF_DEVICES[7] = -1;
}
else
{
buf_OF_DEVICES[5] = Mode;
}
ret_VAL = GetVideoAdapterVendorDeviceAndLFB();
if (ret_VAL)
{
DbgPrint(buf_OF_DEVICES);
}
}
pDriverObject->DriverUnload = Example_Unload;
return NtStatus;
}
VOID Example_Unload(PDRIVER_OBJECT DriverObject)
{
UNICODE_STRING usDosDeviceName;
DbgPrint("Example_Unload Called \r\n");
RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\SVGA");
IoDeleteSymbolicLink(&usDosDeviceName);
IoDeleteDevice(DriverObject->DeviceObject);
}
What is wrong at this code???