[BLUE] Formatting, no code change

This commit is contained in:
Timo Kreuzer 2018-07-01 10:13:18 +02:00
parent 3904fd6257
commit 64f46045af

View file

@ -24,22 +24,23 @@ VOID LoadFont(PUCHAR Bitplane, PUCHAR FontBitfield);
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
VOID VOID
ScrLoadFontTable(UINT32 CodePage) ScrLoadFontTable(
UINT32 CodePage)
{ {
PHYSICAL_ADDRESS BaseAddress; PHYSICAL_ADDRESS BaseAddress;
PUCHAR Bitplane; PUCHAR Bitplane;
PUCHAR FontBitfield = NULL; PUCHAR FontBitfield = NULL;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
FontBitfield = (PUCHAR) ExAllocatePoolWithTag(NonPagedPool, 2048, TAG_BLUE); FontBitfield = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, 2048, TAG_BLUE);
if(FontBitfield) if (FontBitfield)
{ {
/* open bit plane for font table access */ /* open bit plane for font table access */
OpenBitPlane(); OpenBitPlane();
/* get pointer to video memory */ /* get pointer to video memory */
BaseAddress.QuadPart = BITPLANE_BASE; BaseAddress.QuadPart = BITPLANE_BASE;
Bitplane = (PUCHAR)MmMapIoSpace (BaseAddress, 0xFFFF, MmNonCached); Bitplane = (PUCHAR)MmMapIoSpace(BaseAddress, 0xFFFF, MmNonCached);
Status = ExtractFont(CodePage, FontBitfield); Status = ExtractFont(CodePage, FontBitfield);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
@ -55,7 +56,10 @@ ScrLoadFontTable(UINT32 CodePage)
/* PRIVATE FUNCTIONS *********************************************************/ /* PRIVATE FUNCTIONS *********************************************************/
NTSTATUS ExtractFont(UINT32 CodePage, PUCHAR FontBitField) NTSTATUS
ExtractFont(
UINT32 CodePage,
PUCHAR FontBitField)
{ {
BOOLEAN bFoundFile = FALSE; BOOLEAN bFoundFile = FALSE;
HANDLE Handle; HANDLE Handle;
@ -69,10 +73,10 @@ NTSTATUS ExtractFont(UINT32 CodePage, PUCHAR FontBitField)
CFFILE CabFile; CFFILE CabFile;
ULONG CabFileOffset = 0; ULONG CabFileOffset = 0;
LARGE_INTEGER ByteOffset; LARGE_INTEGER ByteOffset;
WCHAR SourceBuffer[MAX_PATH] = {L'\0'}; WCHAR SourceBuffer[MAX_PATH] = { L'\0' };
ULONG ReadCP; ULONG ReadCP;
if(KeGetCurrentIrql() != PASSIVE_LEVEL) if (KeGetCurrentIrql() != PASSIVE_LEVEL)
return STATUS_INVALID_DEVICE_STATE; return STATUS_INVALID_DEVICE_STATE;
RtlInitUnicodeString(&LinkName, RtlInitUnicodeString(&LinkName,
@ -96,56 +100,82 @@ NTSTATUS ExtractFont(UINT32 CodePage, PUCHAR FontBitField)
SourceName.Buffer = SourceBuffer; SourceName.Buffer = SourceBuffer;
Status = ZwQuerySymbolicLinkObject(Handle, Status = ZwQuerySymbolicLinkObject(Handle,
&SourceName, &SourceName,
NULL); NULL);
ZwClose(Handle); ZwClose(Handle);
Status = RtlAppendUnicodeToString(&SourceName, L"\\vgafonts.cab"); Status = RtlAppendUnicodeToString(&SourceName, L"\\vgafonts.cab");
InitializeObjectAttributes(&ObjectAttributes, &SourceName, InitializeObjectAttributes(&ObjectAttributes,
&SourceName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL, NULL); NULL,
NULL);
Status = ZwCreateFile(&Handle, Status = ZwCreateFile(&Handle,
GENERIC_READ, GENERIC_READ,
&ObjectAttributes, &IoStatusBlock, NULL, &ObjectAttributes,
&IoStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL,
0, 0,
FILE_OPEN, FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT, FILE_SYNCHRONOUS_IO_NONALERT,
NULL, 0); NULL,
0);
ByteOffset.LowPart = ByteOffset.HighPart = 0; ByteOffset.LowPart = ByteOffset.HighPart = 0;
if(NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
Status = ZwReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Status = ZwReadFile(Handle,
&CabFileHeader, sizeof(CabFileHeader), &ByteOffset, NULL); NULL,
NULL,
NULL,
&IoStatusBlock,
&CabFileHeader,
sizeof(CabFileHeader),
&ByteOffset,
NULL);
if(NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
if(CabFileHeader.Signature == CAB_SIGNATURE) if (CabFileHeader.Signature == CAB_SIGNATURE)
{ {
// We have a valid CAB file! // We have a valid CAB file!
// Read the file table now and decrement the file count on every file. When it's zero, we read the complete table. // Read the file table now and decrement the file count on every file. When it's zero, we read the complete table.
ByteOffset.LowPart = CabFileHeader.FileTableOffset; ByteOffset.LowPart = CabFileHeader.FileTableOffset;
while(CabFileHeader.FileCount) while (CabFileHeader.FileCount)
{ {
Status = ZwReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Status = ZwReadFile(Handle,
&CabFile, sizeof(CabFile), &ByteOffset, NULL); NULL,
NULL,
NULL,
&IoStatusBlock,
&CabFile,
sizeof(CabFile),
&ByteOffset,
NULL);
if(NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
ByteOffset.LowPart += sizeof(CabFile); ByteOffset.LowPart += sizeof(CabFile);
// We assume here that the file name is max. 19 characters (+ 1 NULL character) long. // We assume here that the file name is max. 19 characters (+ 1 NULL character) long.
// This should be enough for our purpose. // This should be enough for our purpose.
Status = ZwReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Status = ZwReadFile(Handle,
FileName, sizeof(FileName), &ByteOffset, NULL); NULL,
NULL,
NULL,
&IoStatusBlock,
FileName,
sizeof(FileName),
&ByteOffset,
NULL);
if(NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
if(!bFoundFile) if (!bFoundFile)
{ {
Status = RtlCharToInteger(FileName, 0, &ReadCP); Status = RtlCharToInteger(FileName, 0, &ReadCP);
if (NT_SUCCESS(Status) && ReadCP == CodePage) if (NT_SUCCESS(Status) && ReadCP == CodePage)
@ -169,8 +199,15 @@ NTSTATUS ExtractFont(UINT32 CodePage, PUCHAR FontBitField)
ByteOffset.LowPart += CabFileOffset; ByteOffset.LowPart += CabFileOffset;
// ByteOffset now contains the offset of the actual data, so we can read the RAW font // ByteOffset now contains the offset of the actual data, so we can read the RAW font
Status = ZwReadFile(Handle, NULL, NULL, NULL, &IoStatusBlock, Status = ZwReadFile(Handle,
FontBitField, 2048, &ByteOffset, NULL); NULL,
NULL,
NULL,
&IoStatusBlock,
FontBitField,
2048,
&ByteOffset,
NULL);
ZwClose(Handle); ZwClose(Handle);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -201,15 +238,15 @@ OpenBitPlane(VOID)
_disable(); _disable();
/* sequence reg */ /* sequence reg */
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR (SEQ_DATA, 0x01); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR(SEQ_DATA, 0x01);
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_ENABLE_WRT_PLANE); WRITE_PORT_UCHAR (SEQ_DATA, 0x04); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_ENABLE_WRT_PLANE); WRITE_PORT_UCHAR(SEQ_DATA, 0x04);
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_MEM_MODE); WRITE_PORT_UCHAR (SEQ_DATA, 0x07); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_MEM_MODE); WRITE_PORT_UCHAR(SEQ_DATA, 0x07);
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR (SEQ_DATA, 0x03); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR(SEQ_DATA, 0x03);
/* graphic reg */ /* graphic reg */
WRITE_PORT_UCHAR (GCT_COMMAND, GCT_READ_PLANE); WRITE_PORT_UCHAR (GCT_DATA, 0x02); WRITE_PORT_UCHAR(GCT_COMMAND, GCT_READ_PLANE); WRITE_PORT_UCHAR(GCT_DATA, 0x02);
WRITE_PORT_UCHAR (GCT_COMMAND, GCT_RW_MODES); WRITE_PORT_UCHAR (GCT_DATA, 0x00); WRITE_PORT_UCHAR(GCT_COMMAND, GCT_RW_MODES); WRITE_PORT_UCHAR(GCT_DATA, 0x00);
WRITE_PORT_UCHAR (GCT_COMMAND, GCT_GRAPH_MODE); WRITE_PORT_UCHAR (GCT_DATA, 0x00); WRITE_PORT_UCHAR(GCT_COMMAND, GCT_GRAPH_MODE); WRITE_PORT_UCHAR(GCT_DATA, 0x00);
/* enable interrupts */ /* enable interrupts */
_enable(); _enable();
@ -222,35 +259,37 @@ CloseBitPlane(VOID)
_disable(); _disable();
/* sequence reg */ /* sequence reg */
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR (SEQ_DATA, 0x01); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR(SEQ_DATA, 0x01);
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_ENABLE_WRT_PLANE); WRITE_PORT_UCHAR (SEQ_DATA, 0x03); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_ENABLE_WRT_PLANE); WRITE_PORT_UCHAR(SEQ_DATA, 0x03);
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_MEM_MODE); WRITE_PORT_UCHAR (SEQ_DATA, 0x03); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_MEM_MODE); WRITE_PORT_UCHAR(SEQ_DATA, 0x03);
WRITE_PORT_UCHAR (SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR (SEQ_DATA, 0x03); WRITE_PORT_UCHAR(SEQ_COMMAND, SEQ_RESET); WRITE_PORT_UCHAR(SEQ_DATA, 0x03);
/* graphic reg */ /* graphic reg */
WRITE_PORT_UCHAR (GCT_COMMAND, GCT_READ_PLANE); WRITE_PORT_UCHAR (GCT_DATA, 0x00); WRITE_PORT_UCHAR(GCT_COMMAND, GCT_READ_PLANE); WRITE_PORT_UCHAR(GCT_DATA, 0x00);
WRITE_PORT_UCHAR (GCT_COMMAND, GCT_RW_MODES); WRITE_PORT_UCHAR (GCT_DATA, 0x10); WRITE_PORT_UCHAR(GCT_COMMAND, GCT_RW_MODES); WRITE_PORT_UCHAR(GCT_DATA, 0x10);
WRITE_PORT_UCHAR (GCT_COMMAND, GCT_GRAPH_MODE); WRITE_PORT_UCHAR (GCT_DATA, 0x0e); WRITE_PORT_UCHAR(GCT_COMMAND, GCT_GRAPH_MODE); WRITE_PORT_UCHAR(GCT_DATA, 0x0e);
/* enable interrupts */ /* enable interrupts */
_enable(); _enable();
} }
VOID VOID
LoadFont(PUCHAR Bitplane, PUCHAR FontBitfield) LoadFont(
PUCHAR Bitplane,
PUCHAR FontBitfield)
{ {
UINT32 i,j; UINT32 i, j;
for (i=0; i<256; i++) for (i = 0; i < 256; i++)
{ {
for (j=0; j<8; j++) for (j = 0; j < 8; j++)
{ {
*Bitplane = FontBitfield[i*8+j]; *Bitplane = FontBitfield[i * 8 + j];
Bitplane++; Bitplane++;
} }
// padding // padding
for (j=8; j<32; j++) for (j = 8; j < 32; j++)
{ {
*Bitplane = 0; *Bitplane = 0;
Bitplane++; Bitplane++;