Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
markfsanderson committed Apr 18, 2018
1 parent 75c9fa0 commit d927eab
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 66 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
42 changes: 42 additions & 0 deletions control/win-kernel/WinVirtUE.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,64 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinVirtUE Package", "WinVir
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|ARM.ActiveCfg = Debug|ARM
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|ARM.Build.0 = Debug|ARM
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|ARM.Deploy.0 = Debug|ARM
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|ARM64.ActiveCfg = Debug|ARM64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|ARM64.Build.0 = Debug|ARM64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|ARM64.Deploy.0 = Debug|ARM64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|x64.ActiveCfg = Debug|x64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|x64.Build.0 = Debug|x64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|x64.Deploy.0 = Debug|x64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|x86.ActiveCfg = Debug|Win32
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|x86.Build.0 = Debug|Win32
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Debug|x86.Deploy.0 = Debug|Win32
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|ARM.ActiveCfg = Release|ARM
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|ARM.Build.0 = Release|ARM
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|ARM.Deploy.0 = Release|ARM
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|ARM64.ActiveCfg = Release|ARM64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|ARM64.Build.0 = Release|ARM64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|ARM64.Deploy.0 = Release|ARM64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|x64.ActiveCfg = Release|x64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|x64.Build.0 = Release|x64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|x64.Deploy.0 = Release|x64
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|x86.ActiveCfg = Release|Win32
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|x86.Build.0 = Release|Win32
{F0873F2B-AFBE-480C-9355-71D073A9CCDB}.Release|x86.Deploy.0 = Release|Win32
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|ARM.ActiveCfg = Debug|ARM
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|ARM.Build.0 = Debug|ARM
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|ARM.Deploy.0 = Debug|ARM
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|ARM64.ActiveCfg = Debug|ARM64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|ARM64.Build.0 = Debug|ARM64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|ARM64.Deploy.0 = Debug|ARM64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|x64.ActiveCfg = Debug|x64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|x64.Build.0 = Debug|x64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|x64.Deploy.0 = Debug|x64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|x86.ActiveCfg = Debug|Win32
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|x86.Build.0 = Debug|Win32
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Debug|x86.Deploy.0 = Debug|Win32
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|ARM.ActiveCfg = Release|ARM
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|ARM.Build.0 = Release|ARM
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|ARM.Deploy.0 = Release|ARM
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|ARM64.ActiveCfg = Release|ARM64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|ARM64.Build.0 = Release|ARM64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|ARM64.Deploy.0 = Release|ARM64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|x64.ActiveCfg = Release|x64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|x64.Build.0 = Release|x64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|x64.Deploy.0 = Release|x64
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|x86.ActiveCfg = Release|Win32
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|x86.Build.0 = Release|Win32
{0D62BA54-B404-4087-98E6-5DC74FD0549C}.Release|x86.Deploy.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 4 additions & 4 deletions control/win-kernel/WinVirtUE/Common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#pragma warning( pop )

#include "config.h"
#include "trace.h"
#include "CPPRuntime.h"
#include "cmn_pool_tag.h"
#include "types.h"
Expand Down Expand Up @@ -55,9 +56,6 @@
#define MILLISECONDS( milli ) \
(((signed __int64) (milli)) * MICROSECONDS(1000L))

_When_((PoolType & NonPagedPoolMustSucceed) != 0,
__drv_reportError("Must succeed pool allocations are forbidden. "
"Allocation failures cause a system crash"))
#define ALLOC_POOL(PoolType, Size) ExAllocatePoolWithTag(PoolType, Size, COMMON_POOL_TAG)
#define FREE_POOL(Buffer) ExFreePoolWithTag(Buffer, COMMON_POOL_TAG);

Expand All @@ -69,4 +67,6 @@ CONST ULONG ENCRYPT_PAGE_SIZE = 512;
/** When File Allocation Stream Size is Not Applicable */
CONST LONGLONG FILE_ALLOCATION_NA = 0;
/** When File Attributes are not used */
CONST ULONG FILE_ATTRIBUTES_NA = 0;
CONST ULONG FILE_ATTRIBUTES_NA = 0;


32 changes: 16 additions & 16 deletions control/win-kernel/WinVirtUE/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
#define DPFLTR_MASK 0x80000000

/* Module IDs */
#define LOG_NONE (1 << 0)
#define LOG_UTIL (1 << 1)
#define LOG_CTX (1 << 2)
#define LOG_WVU_MAIN (1 << 3)
#define LOG_CRYPTO (1 << 4)
#define LOG_REGISTRY (1 << 5)
#define LOG_FLT_MGR (1 << 6)
#define LOG_CACHE (1 << 7)
#define LOG_FILE_OP (1 << 8)
#define LOG_FILE_CREATE (1 << 9)
#define LOG_NOTIFY_PROCS (1 << 10)
#define LOG_WVU_MAINTHREAD (1 << 11)
#define LOG_WVU_CONTAINER (1 << 12)
#define LOG_WVU_IOCTL (1 << 13)
#define LOG_WVU_PROCESS (1 << 14)
#define LOG_WVU_OP_CALLBACKS (1 << 15)
#define LOG_NONE (1 << 0)
#define LOG_UTIL (1 << 1)
#define LOG_CTX (1 << 2)
#define LOG_MAIN (1 << 3)
#define LOG_CRYPTO (1 << 4)
#define LOG_REGISTRY (1 << 5)
#define LOG_FLT_MGR (1 << 6)
#define LOG_CACHE (1 << 7)
#define LOG_FILE_OP (1 << 8)
#define LOG_FILE_CREATE (1 << 9)
#define LOG_NOTIFY_PROCS (1 << 10)
#define LOG_MAINTHREAD (1 << 11)
#define LOG_CONTAINER (1 << 12)
#define LOG_IOCTL (1 << 13)
#define LOG_PROCESS (1 << 14)
#define LOG_OP_CALLBACKS (1 << 15)

/*
* These are meant to be used when you want to see the logs
Expand Down
36 changes: 18 additions & 18 deletions control/win-kernel/WinVirtUE/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ static NTSTATUS GetOsVersion()
goto Error;
}

WVU_DEBUG_PRINT(LOG_WVU_MAIN, INFO_LEVEL_ID, "******************************\n");
WVU_DEBUG_PRINT(LOG_MAIN, INFO_LEVEL_ID, "******************************\n");
// TODO: Generate a proper version number
WVU_DEBUG_PRINT(LOG_WVU_MAIN, INFO_LEVEL_ID, "***** WinVirtUE.sys Version %d.%d.%d\n", 0, 1, 0);
WVU_DEBUG_PRINT(LOG_WVU_MAIN, INFO_LEVEL_ID, "***** Windows Version %u.%u.%u Service Pack %u.%u\n",
WVU_DEBUG_PRINT(LOG_MAIN, INFO_LEVEL_ID, "***** WinVirtUE.sys Version %d.%d.%d\n", 0, 1, 0);
WVU_DEBUG_PRINT(LOG_MAIN, INFO_LEVEL_ID, "***** Windows Version %u.%u.%u Service Pack %u.%u\n",
Globals.lpVersionInformation.dwMajorVersion, Globals.lpVersionInformation.dwMinorVersion, Globals.lpVersionInformation.dwBuildNumber,
Globals.lpVersionInformation.wServicePackMajor, Globals.lpVersionInformation.wServicePackMinor);

if (Globals.lpVersionInformation.szCSDVersion[0] != (TCHAR)0)
{
WVU_DEBUG_PRINT(LOG_WVU_MAIN, INFO_LEVEL_ID, "***** Service Pack: %ws\n", Globals.lpVersionInformation.szCSDVersion);
WVU_DEBUG_PRINT(LOG_MAIN, INFO_LEVEL_ID, "***** Service Pack: %ws\n", Globals.lpVersionInformation.szCSDVersion);
}

WVU_DEBUG_PRINT(LOG_WVU_MAIN, INFO_LEVEL_ID, "******************************\n");
WVU_DEBUG_PRINT(LOG_MAIN, INFO_LEVEL_ID, "******************************\n");
Error:
return Status;
}
Expand Down Expand Up @@ -114,25 +114,25 @@ DriverEntry(

DriverObject->DriverUnload = DriverUnload; // For now, we unload by default

WVU_DEBUG_PRINT(LOG_WVU_MAIN, TRACE_LEVEL_ID, "About to call CallGlobalInitializers()!\n");
WVU_DEBUG_PRINT(LOG_MAIN, TRACE_LEVEL_ID, "About to call CallGlobalInitializers()!\n");

CallGlobalInitializers();

WVU_DEBUG_PRINT(LOG_WVU_MAIN, TRACE_LEVEL_ID, "CallGlobalInitializers() Completed!\n");
WVU_DEBUG_PRINT(LOG_MAIN, TRACE_LEVEL_ID, "CallGlobalInitializers() Completed!\n");

// initialize the waiter. Once the WVUThreadStart gets to the end of its
// intialization, it will signal and wait simultaneously. It will continue
// to wait until the DriverUnload routine signals it. When the thread
// continues the objects created will have their destructors called.
KeInitializeEvent(&Globals.WVUThreadStartEvent, EVENT_TYPE::SynchronizationEvent, FALSE);

WVU_DEBUG_PRINT(LOG_WVU_MAIN, TRACE_LEVEL_ID, "About to register filter manager callbacks!\n");
WVU_DEBUG_PRINT(LOG_MAIN, TRACE_LEVEL_ID, "About to register filter manager callbacks!\n");

// Register with FltMgr to tell it our callback routines
Status = FltRegisterFilter(DriverObject, &FilterRegistration, &Globals.FilterHandle);
if (FALSE == NT_SUCCESS(Status))
{
WVU_DEBUG_PRINT(LOG_WVU_MAIN, ERROR_LEVEL_ID, "FltRegisterFilter() FAIL=%08x\n", Status);
WVU_DEBUG_PRINT(LOG_MAIN, ERROR_LEVEL_ID, "FltRegisterFilter() FAIL=%08x\n", Status);
goto ErrorExit;
}

Expand All @@ -141,7 +141,7 @@ DriverEntry(
Status = GetOsVersion();
if (FALSE == NT_SUCCESS(Status))
{
WVU_DEBUG_PRINT(LOG_WVU_MAIN, WARNING_LEVEL_ID, "RtlGetVersion Failed! Status=%08x\n", Status);
WVU_DEBUG_PRINT(LOG_MAIN, WARNING_LEVEL_ID, "RtlGetVersion Failed! Status=%08x\n", Status);
}

//
Expand Down Expand Up @@ -186,14 +186,14 @@ DriverEntry(
Status = FltStartFiltering(Globals.FilterHandle);
if (FALSE == NT_SUCCESS(Status))
{
WVU_DEBUG_PRINT(LOG_WVU_MAIN, ERROR_LEVEL_ID, "FltStartFiltering() Failed! - FAIL=%08x\n", Status);
WVU_DEBUG_PRINT(LOG_MAIN, ERROR_LEVEL_ID, "FltStartFiltering() Failed! - FAIL=%08x\n", Status);
FltUnregisterFilter(Globals.FilterHandle);
goto ErrorExit;
}
}
else
{
WVU_DEBUG_PRINT(LOG_WVU_MAIN, ERROR_LEVEL_ID, "FltCreateCommunicationPort() Failed! - FAIL=%08x\n", Status);
WVU_DEBUG_PRINT(LOG_MAIN, ERROR_LEVEL_ID, "FltCreateCommunicationPort() Failed! - FAIL=%08x\n", Status);
goto ErrorExit;
}
}
Expand All @@ -204,33 +204,33 @@ DriverEntry(
Status = PsCreateSystemThread(&ThreadHandle, GENERIC_ALL, &WVUThdObjAttr, NULL, &ClientId, WVUMainThreadStart, &Globals.WVUThreadStartEvent);
if (FALSE == NT_SUCCESS(Status))
{
WVU_DEBUG_PRINT(LOG_WVU_MAIN, ERROR_LEVEL_ID, "PsCreateSystemThread() Failed! - FAIL=%08x\n", Status);
WVU_DEBUG_PRINT(LOG_MAIN, ERROR_LEVEL_ID, "PsCreateSystemThread() Failed! - FAIL=%08x\n", Status);
goto ErrorExit;
}

WVU_DEBUG_PRINT(LOG_WVU_MAIN, TRACE_LEVEL_ID, "PsCreateSystemThread(): Successfully created system thread %p process %p thread id %p\n",
WVU_DEBUG_PRINT(LOG_MAIN, TRACE_LEVEL_ID, "PsCreateSystemThread(): Successfully created system thread %p process %p thread id %p\n",
ThreadHandle, ClientId.UniqueProcess, ClientId.UniqueThread);

LARGE_INTEGER timeout;
timeout.QuadPart = -1000 * 1000 * 10 * 10; // ten second timeout
Status = KeWaitForSingleObject(&Globals.WVUThreadStartEvent, KWAIT_REASON::Executive, KernelMode, FALSE, &timeout);
if (FALSE == NT_SUCCESS(Status))
{
WVU_DEBUG_PRINT(LOG_WVU_MAINTHREAD, ERROR_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Failed! Status=%08x\n", Status);
WVU_DEBUG_PRINT(LOG_MAINTHREAD, ERROR_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Failed! Status=%08x\n", Status);
goto ErrorExit;
}
switch (Status)
{
case STATUS_SUCCESS:
WVU_DEBUG_PRINT(LOG_WVU_MAINTHREAD, TRACE_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Thread Returned SUCCESS\n");
WVU_DEBUG_PRINT(LOG_MAINTHREAD, TRACE_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Thread Returned SUCCESS\n");
break;
case STATUS_TIMEOUT:
WVU_DEBUG_PRINT(LOG_WVU_MAINTHREAD, TRACE_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Thread Has Just Timed Out\n");
WVU_DEBUG_PRINT(LOG_MAINTHREAD, TRACE_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Thread Has Just Timed Out\n");
Status = STATUS_TIMEOUT;
goto ErrorExit;
break;
default:
WVU_DEBUG_PRINT(LOG_WVU_MAINTHREAD, TRACE_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Thread Has Just Received Status=0x%08x\n", Status);
WVU_DEBUG_PRINT(LOG_MAINTHREAD, TRACE_LEVEL_ID, "KeWaitForSingleObject(WVUMainThreadStart,...) Thread Has Just Received Status=0x%08x\n", Status);
goto ErrorExit;
break;
}
Expand Down
12 changes: 6 additions & 6 deletions control/win-kernel/WinVirtUE/FltMgrCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ WinVirtUEPreOperation(
UNREFERENCED_PARAMETER(FltObjects);
UNREFERENCED_PARAMETER(CompletionContext);

WVU_DEBUG_PRINT(LOG_WVU_OP_CALLBACKS, TRACE_LEVEL_ID,
WVU_DEBUG_PRINT(LOG_OP_CALLBACKS, TRACE_LEVEL_ID,
"WinVirtUE!WinVirtUEPreOperation: Entered\n");

//
Expand All @@ -349,7 +349,7 @@ WinVirtUEPreOperation(
WinVirtUEOperationStatusCallback,
(PVOID)(++OperationStatusCtx));
if (!NT_SUCCESS(status)) {
WVU_DEBUG_PRINT(LOG_WVU_OP_CALLBACKS, TRACE_LEVEL_ID,
WVU_DEBUG_PRINT(LOG_OP_CALLBACKS, TRACE_LEVEL_ID,
"WinVirtUE!WinVirtUEPreOperation: FltRequestOperationStatusCallback Failed, status=%08x\n",
status);
}
Expand Down Expand Up @@ -388,10 +388,10 @@ WinVirtUEOperationStatusCallback(
{
UNREFERENCED_PARAMETER(FltObjects);

WVU_DEBUG_PRINT(LOG_WVU_OP_CALLBACKS, TRACE_LEVEL_ID,
WVU_DEBUG_PRINT(LOG_OP_CALLBACKS, TRACE_LEVEL_ID,
"WinVirtUE!WinVirtUEOperationStatusCallback: Entered\n");

WVU_DEBUG_PRINT(LOG_WVU_OP_CALLBACKS, TRACE_LEVEL_ID,
WVU_DEBUG_PRINT(LOG_OP_CALLBACKS, TRACE_LEVEL_ID,
"WinVirtUE!WinVirtUEOperationStatusCallback: Status=%08x ctx=%p IrpMj=%02x.%02x \"%s\"\n",
OperationStatus,
RequesterContext,
Expand Down Expand Up @@ -424,7 +424,7 @@ WinVirtUEPostOperation(
UNREFERENCED_PARAMETER(CompletionContext);
UNREFERENCED_PARAMETER(Flags);

WVU_DEBUG_PRINT(LOG_WVU_OP_CALLBACKS, TRACE_LEVEL_ID,
WVU_DEBUG_PRINT(LOG_OP_CALLBACKS, TRACE_LEVEL_ID,
"WinVirtUE!WinVirtUEPostOperation: Entered\n");

return FLT_POSTOP_FINISHED_PROCESSING;
Expand All @@ -451,7 +451,7 @@ WinVirtUEPreOperationNoPostOperation(
UNREFERENCED_PARAMETER(FltObjects);
UNREFERENCED_PARAMETER(CompletionContext);

WVU_DEBUG_PRINT(LOG_WVU_OP_CALLBACKS, TRACE_LEVEL_ID,
WVU_DEBUG_PRINT(LOG_OP_CALLBACKS, TRACE_LEVEL_ID,
"WinVirtUE!WinVirtUEPreOperationNoPostOperation: Entered\n");

return FLT_PREOP_SUCCESS_NO_CALLBACK;
Expand Down
Loading

0 comments on commit d927eab

Please sign in to comment.