Skip to content

Commit

Permalink
split hvpp into two parts: hvppdrv (driver) and hvpp (static lib)
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Sep 16, 2018
1 parent 60e61ee commit cfcbd46
Show file tree
Hide file tree
Showing 80 changed files with 497 additions and 413 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ read and navigate through 5000 pages with browser's built-in PDF reader.
- Ability to run in VMWare (tested even with KVM - I advise to turn off [Hyper-V Enlightenments][kvm-hv-enlightenments],
as it can [cause conflicts][ddimon-issue22]). VMWare's nested virtualization makes development and debugging of
hypervisors much easier.
- Simple custom memory manager ([see mm.cpp](src/hvpp/lib/mm.cpp)). The need for custom memory manager emerges from the
- Simple custom memory manager ([see mm.cpp](src/hvpp/hvpp/lib/mm.cpp)). The need for custom memory manager emerges from the
fact that you should think twice before calling any kernel function from VM-exit handler, because many of them can be
called at IRQL <= DISPATCH_LEVEL (such as `ExAllocatePoolWithTag`). But in VM-exit handler, interrupts are disabled
and your [IRQL is effectively HIGH_LEVEL][irql-in-vmx].
Expand All @@ -78,10 +78,12 @@ read and navigate through 5000 pages with browser's built-in PDF reader.

### Code workflow

- Bootstrap of the driver ([driver.cpp](src/hvpp/lib/win32/driver.cpp))
> Note: **hvpp** is compiled as a static library, which is linked with the **hvppdrv** project.
- Bootstrap of the driver (hvpp, [driver.cpp](src/hvpp/hvpp/lib/win32/driver.cpp))
- preallocate enough memory and initialize the **hvpp** memory manager
- initialize the logger
- Bootstrap of the hypervisor ([main.cpp](src/hvpp/main.cpp))
- Bootstrap of the hypervisor (hvppdrv, [main.cpp](src/hvppdrv/main.cpp))
- create **hvpp** instance
- create **vmexit_handler** instance
- Start the hypervisor with provided VM-exit handler (`hypervisor::start(vmexit_handler* handler)`)
Expand All @@ -90,7 +92,7 @@ read and navigate through 5000 pages with browser's built-in PDF reader.
- assign provided `vmexit_handler` instance to each VCPU
- launch all VCPUs - for each VCPU `vmexit_handler::setup()` is called within `vcpu_t::launch()` method, which
allows anyone to initialize the VM-exit handler and/or modify the VMCS before the launch (see `custom_vmexit_handler::setup()`
in [custom_vmexit.cpp](src/hvpp/custom_vmexit.cpp))
in hvppdrv, [custom_vmexit.cpp](src/hvppdrv/custom_vmexit.cpp))
- Hypervisor is now running and handling VM-exits via provided VM-exit handler
- Terminate the hypervisor (`hypervisor::destroy()`)
- destroy each VCPU via IPI - for each VCPU `vmexit_handler::invoke_termination()` is called within `vcpu_t::destroy()`
Expand All @@ -113,7 +115,7 @@ Enable [Test-Signing][test-signing] boot configuration option (note that you'll

[Register driver][sc-create] with Service Control Manager (yes, it's important to leave these spaces):

`sc create hvpp type= kernel binPath= "C:\full\path\to\hvpp.sys"`
`sc create hvpp type= kernel binPath= "C:\full\path\to\hvppdrv.sys"`

Now you should restart your computer for **testsigning** to take effect, otherwise you'll be unable to start the driver.
But before you do, you might want to prepare [DebugView][tools-debugview] from SysInternals and
Expand All @@ -122,7 +124,7 @@ But before you do, you might want to prepare [DebugView][tools-debugview] from S
After restart, launch `DebugView` and `TraceView`. In `TraceView`:
- go to `File -> Create New Log Session`, click on `Add Provider`
- pick `Manually Entered Control GUID or Hashed Name`
- paste `916fcd3e-673b-4610-aaba-0b71e28acd40` (arbitrarily chosen, see [lib/win32/tracelog.cpp](src/hvpp/lib/win32/tracelog.cpp))
- paste `916fcd3e-673b-4610-aaba-0b71e28acd40` (arbitrarily chosen, see [lib/win32/tracelog.cpp](src/hvpp/hvpp/lib/win32/tracelog.cpp))
- click `OK`
- in the next dialog, leave the `Source Of WPP Format Information` set to `Auto`
- click `OK`
Expand Down Expand Up @@ -152,7 +154,7 @@ Run **hvppctrl**:


- **hvppctrl** performs `CPUID` instruction with `EAX = 0x70707668 ('hvpp')` which **hvpp** should intercept and return
string `hello from hvpp` in EAX, EBX, ECX and EDX registers (see [custom_vmexit.cpp](src/hvpp/custom_vmexit.cpp)).
string `hello from hvpp` in EAX, EBX, ECX and EDX registers (see [custom_vmexit.cpp](src/hvppdrv/custom_vmexit.cpp)).
**hvppctrl** should print this string.

- **hvppctrl** tries to "stealthily" hook `ntdll!ZwClose` function using EPT. The exact process is described
Expand Down
16 changes: 10 additions & 6 deletions hvpp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2000
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hvpp", "src\hvpp\hvpp.vcxproj", "{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hvppctrl", "src\hvppctrl\hvppctrl.vcxproj", "{A72DAEF5-C739-4E70-B57E-4310ABA03749}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{01B84E09-7D4F-4415-95AD-C9291497D28C}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hvpp", "src\hvpp\hvpp.vcxproj", "{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hvppdrv", "src\hvppdrv\hvppdrv.vcxproj", "{46A74761-6CFA-41AF-A536-47F08E2C7B48}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hvppctrl", "src\hvppctrl\hvppctrl.vcxproj", "{A72DAEF5-C739-4E70-B57E-4310ABA03749}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -20,10 +22,12 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}.Debug|x64.ActiveCfg = Debug|x64
{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}.Debug|x64.Build.0 = Debug|x64
{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}.Debug|x64.Deploy.0 = Debug|x64
{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}.Release|x64.ActiveCfg = Release|x64
{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}.Release|x64.Build.0 = Release|x64
{2FC6C155-2BDF-4761-B9B5-7DFE9C2BB4F4}.Release|x64.Deploy.0 = Release|x64
{46A74761-6CFA-41AF-A536-47F08E2C7B48}.Debug|x64.ActiveCfg = Debug|x64
{46A74761-6CFA-41AF-A536-47F08E2C7B48}.Debug|x64.Build.0 = Debug|x64
{46A74761-6CFA-41AF-A536-47F08E2C7B48}.Release|x64.ActiveCfg = Release|x64
{46A74761-6CFA-41AF-A536-47F08E2C7B48}.Release|x64.Build.0 = Release|x64
{A72DAEF5-C739-4E70-B57E-4310ABA03749}.Debug|x64.ActiveCfg = Debug|x64
{A72DAEF5-C739-4E70-B57E-4310ABA03749}.Debug|x64.Build.0 = Debug|x64
{A72DAEF5-C739-4E70-B57E-4310ABA03749}.Release|x64.ActiveCfg = Release|x64
Expand Down
141 changes: 67 additions & 74 deletions src/hvpp/hvpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<TargetVersion>Windows7</TargetVersion>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<DriverType>WDM</DriverType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<TargetVersion>Windows7</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<DriverType>WDM</DriverType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down Expand Up @@ -67,12 +67,12 @@
<SupportJustMyCode>false</SupportJustMyCode>
</ClCompile>
<Inf />
<Inf />
<MASM />
<Link>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
</Link>
<PostBuildEvent />
<Lib />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -90,17 +90,14 @@
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<PostBuildEvent />
<Lib>
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<Inf Include="hvpp.inf">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</Inf>
</ItemGroup>
<ItemGroup>
<FilesToPackage Include="$(TargetPath)" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="device_custom.cpp" />
<ClCompile Include="hvpp\ept.cpp" />
<ClCompile Include="hvpp\hypervisor.cpp" />
<ClCompile Include="hvpp\vcpu.cpp" />
Expand All @@ -111,29 +108,25 @@
<ClCompile Include="hvpp\vmexit\vmexit_dbgbreak.cpp" />
<ClCompile Include="hvpp\vmexit\vmexit_passthrough.cpp" />
<ClCompile Include="hvpp\vmexit\vmexit_stats.cpp" />
<ClCompile Include="ia32\win32\memory.cpp" />
<ClCompile Include="lib\bitmap.cpp" />
<ClCompile Include="lib\driver.cpp" />
<ClCompile Include="lib\log.cpp" />
<ClCompile Include="lib\mm.cpp" />
<ClCompile Include="lib\vmware\vmware.cpp" />
<ClCompile Include="lib\win32\cr3_guard.cpp" />
<ClCompile Include="lib\win32\debugger.cpp" />
<ClCompile Include="lib\win32\device.cpp" />
<ClCompile Include="lib\win32\driver.cpp" />
<ClCompile Include="lib\win32\log.cpp" />
<ClCompile Include="lib\win32\mm.cpp" />
<ClCompile Include="lib\win32\mp.cpp" />
<ClCompile Include="lib\win32\tracelog.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="vmexit_custom.cpp" />
<ClCompile Include="hvpp\ia32\win32\memory.cpp" />
<ClCompile Include="hvpp\lib\bitmap.cpp" />
<ClCompile Include="hvpp\lib\driver.cpp" />
<ClCompile Include="hvpp\lib\log.cpp" />
<ClCompile Include="hvpp\lib\mm.cpp" />
<ClCompile Include="hvpp\lib\vmware\vmware.cpp" />
<ClCompile Include="hvpp\lib\win32\cr3_guard.cpp" />
<ClCompile Include="hvpp\lib\win32\debugger.cpp" />
<ClCompile Include="hvpp\lib\win32\device.cpp" />
<ClCompile Include="hvpp\lib\win32\driver.cpp" />
<ClCompile Include="hvpp\lib\win32\log.cpp" />
<ClCompile Include="hvpp\lib\win32\mm.cpp" />
<ClCompile Include="hvpp\lib\win32\mp.cpp" />
<ClCompile Include="hvpp\lib\win32\tracelog.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="device_custom.h" />
<ClInclude Include="lib\debugger.h" />
<ClInclude Include="lib\device.h" />
<ClInclude Include="lib\ioctl.h" />
<ClInclude Include="vmexit_custom.h" />
<ClInclude Include="hvpp\lib\debugger.h" />
<ClInclude Include="hvpp\lib\device.h" />
<ClInclude Include="hvpp\lib\ioctl.h" />
<ClInclude Include="hvpp\config.h" />
<ClInclude Include="hvpp\ept.h" />
<ClInclude Include="hvpp\hypervisor.h" />
Expand All @@ -143,56 +136,56 @@
<ClInclude Include="hvpp\vmexit\vmexit_passthrough.h" />
<ClInclude Include="hvpp\vmexit\vmexit_stats.h" />
<ClInclude Include="hvpp\vmexit_compositor.h" />
<ClInclude Include="ia32\arch.h" />
<ClInclude Include="ia32\arch\cr.h" />
<ClInclude Include="ia32\arch\dr.h" />
<ClInclude Include="ia32\arch\rflags.h" />
<ClInclude Include="ia32\arch\segment.h" />
<ClInclude Include="ia32\arch\xsave.h" />
<ClInclude Include="ia32\asm.h" />
<ClInclude Include="ia32\cpuid\cpuid_eax_01.h" />
<ClInclude Include="ia32\ept.h" />
<ClInclude Include="ia32\exception.h" />
<ClInclude Include="ia32\memory.h" />
<ClInclude Include="ia32\msr.h" />
<ClInclude Include="ia32\msr\arch.h" />
<ClInclude Include="ia32\msr\mtrr.h" />
<ClInclude Include="ia32\msr\vmx.h" />
<ClInclude Include="ia32\mtrr.h" />
<ClInclude Include="ia32\paging.h" />
<ClInclude Include="ia32\vmx.h" />
<ClInclude Include="ia32\vmx\exception_bitmap.h" />
<ClInclude Include="ia32\vmx\instruction_info.h" />
<ClInclude Include="ia32\vmx\instruction_error.h" />
<ClInclude Include="ia32\vmx\exit_qualification.h" />
<ClInclude Include="ia32\vmx\exit_reason.h" />
<ClInclude Include="ia32\vmx\interrupt.h" />
<ClInclude Include="ia32\vmx\io_bitmap.h" />
<ClInclude Include="ia32\vmx\msr_bitmap.h" />
<ClInclude Include="ia32\vmx\vmcs.h" />
<ClInclude Include="ia32\win32\asm.h" />
<ClInclude Include="lib\assert.h" />
<ClInclude Include="lib\bitmap.h" />
<ClInclude Include="lib\cr3_guard.h" />
<ClInclude Include="lib\driver.h" />
<ClInclude Include="lib\error.h" />
<ClInclude Include="lib\log.h" />
<ClInclude Include="lib\mm.h" />
<ClInclude Include="lib\mp.h" />
<ClInclude Include="lib\object.h" />
<ClInclude Include="lib\spinlock.h" />
<ClInclude Include="lib\typelist.h" />
<ClInclude Include="lib\vmware\vmware.h" />
<ClInclude Include="hvpp\ia32\arch.h" />
<ClInclude Include="hvpp\ia32\arch\cr.h" />
<ClInclude Include="hvpp\ia32\arch\dr.h" />
<ClInclude Include="hvpp\ia32\arch\rflags.h" />
<ClInclude Include="hvpp\ia32\arch\segment.h" />
<ClInclude Include="hvpp\ia32\arch\xsave.h" />
<ClInclude Include="hvpp\ia32\asm.h" />
<ClInclude Include="hvpp\ia32\cpuid\cpuid_eax_01.h" />
<ClInclude Include="hvpp\ia32\ept.h" />
<ClInclude Include="hvpp\ia32\exception.h" />
<ClInclude Include="hvpp\ia32\memory.h" />
<ClInclude Include="hvpp\ia32\msr.h" />
<ClInclude Include="hvpp\ia32\msr\arch.h" />
<ClInclude Include="hvpp\ia32\msr\mtrr.h" />
<ClInclude Include="hvpp\ia32\msr\vmx.h" />
<ClInclude Include="hvpp\ia32\mtrr.h" />
<ClInclude Include="hvpp\ia32\paging.h" />
<ClInclude Include="hvpp\ia32\vmx.h" />
<ClInclude Include="hvpp\ia32\vmx\exception_bitmap.h" />
<ClInclude Include="hvpp\ia32\vmx\instruction_info.h" />
<ClInclude Include="hvpp\ia32\vmx\instruction_error.h" />
<ClInclude Include="hvpp\ia32\vmx\exit_qualification.h" />
<ClInclude Include="hvpp\ia32\vmx\exit_reason.h" />
<ClInclude Include="hvpp\ia32\vmx\interrupt.h" />
<ClInclude Include="hvpp\ia32\vmx\io_bitmap.h" />
<ClInclude Include="hvpp\ia32\vmx\msr_bitmap.h" />
<ClInclude Include="hvpp\ia32\vmx\vmcs.h" />
<ClInclude Include="hvpp\ia32\win32\asm.h" />
<ClInclude Include="hvpp\lib\assert.h" />
<ClInclude Include="hvpp\lib\bitmap.h" />
<ClInclude Include="hvpp\lib\cr3_guard.h" />
<ClInclude Include="hvpp\lib\driver.h" />
<ClInclude Include="hvpp\lib\error.h" />
<ClInclude Include="hvpp\lib\log.h" />
<ClInclude Include="hvpp\lib\mm.h" />
<ClInclude Include="hvpp\lib\mp.h" />
<ClInclude Include="hvpp\lib\object.h" />
<ClInclude Include="hvpp\lib\spinlock.h" />
<ClInclude Include="hvpp\lib\typelist.h" />
<ClInclude Include="hvpp\lib\vmware\vmware.h" />
</ItemGroup>
<ItemGroup>
<MASM Include="hvpp\vcpu.asm" />
<MASM Include="ia32\context.asm" />
<MASM Include="ia32\asm.asm" />
<MASM Include="lib\vmware\ioctx.asm" />
<MASM Include="hvpp\ia32\context.asm" />
<MASM Include="hvpp\ia32\asm.asm" />
<MASM Include="hvpp\lib\vmware\ioctx.asm" />
</ItemGroup>
<ItemGroup>
<None Include="hvpp\vcpu.inl" />
<None Include="ia32\common.inc" />
<None Include="hvpp\ia32\common.inc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
Loading

0 comments on commit cfcbd46

Please sign in to comment.