Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

hyper-reV

> 开发工具
Open source

memory introspection and reverse engineering hypervisor powered by leveraging Hyper-V

727 stars0 likes3 views
WebsiteGitHub

About

memory introspection and reverse engineering hypervisor powered by leveraging Hyper-V

Contents

  1. Introduction
  2. Prior to boot
  3. Boot process
    • 3.1. Restoration of bootmgfw.efi
    • 3.2. Heap
    • 3.3. Starting bootmgfw.efi
    • 3.4. winload.efi
    • 3.5. hvloader.dll & Hyper-V launch hook
      • 3.5.1. Loading hyperv-attachment
  4. hyperv-attachment/post Hyper-V launch info
    • 4.1. How does it support different architectures?
    • 4.2. Entry point (pre Hyper-V launch)
    • 4.3. First VM exit
    • 4.4. APIC
    • 4.5. SLAT
      • 4.5.1. Code hooks on Intel
      • 4.5.2. Code hooks on AMD
      • 4.5.3. Code hook features common to both AMD and Intel
        • 4.5.3.1. Page split/merge
        • 4.5.3.2. Synchronization using NMIs
          • 4.5.3.2.1. NMIs in host state
          • 4.5.3.2.2. NMIs in guest state
        • 4.5.3.3. Deep copy of Hyper-V SLAT CR3
    • 4.6. Returning execution to Hyper-V
    • 4.7. Hypercalls
      • 4.7.1 Hypercalls list & descriptions
  5. Avoiding detection
  6. Usermode app information
    • 6.1. Command usages and descriptions list
    • 6.2. Kernel hooks
    • 6.3. Command aliases
    • 6.4. Flushing logs
  7. How to compile / use
    • 7.1. 'uefi-boot' compilation
    • 7.2. Architecture-specific compilation
    • 7.3. Load script
    • 7.4. Usage with Secure Boot
    • 7.5. Usage with TPM
  8. Source code
  9. Tested Windows versions
  10. Credits

1. Introduction

hyper-reV is memory introspection and reverse engineering hypervisor powered by leveraging Hyper-V. There is also a usermode component The project provides the following abilities for the guest - meaning the Windows operating system virtualized by Hyper-V - to: read and write to guest virtual memory and physical memory, translate guest virtual addresses to their corresponding guest physical addresses, SLAT code hooks (also known as EPT/NPT hooks), and hiding entire pages of physical memory from the guest. The fact that it leverages Hyper-V means that it will also work under systems protected by HVCI.

There is also a usermode component which serves as a kernel debugger.

2. Prior to boot

The 'uefi-boot' module is hyper-reV's UEFI driver. A copy of bootmgfw.efi is made. The contents of bootmgfw.efi are then replaced with the 'uefi-boot' module so that it will be executed at the next boot. The hyperv-attachment (the module inserted into Hyper-V) is also saved on disk in the same directory as bootmgfw.efi.

3. Boot process

3.1. Restoration of bootmgfw.efi

Once the 'uefi-boot' module is started, the original bootmgfw.efi file and any timestamp related metadata are restored to hide that the file has been tampered with.

3.2. Heap

A heap is also allocated using UEFI boot_services!AllocatePages (so it is 4kB aligned, rather than using boot_services!AllocatePool which does not guarantee that alignment).

This heap is used for allocating:

  • The hyperv-attachment runtime image buffer (then the hyperv-attachment file is deleted from disk as soon as it has been loaded into memory).
  • The PML4 and PDPT for the identity map which is later used.
  • The hyperv-attachment's internal heap.
  • The deep copy of Hyper-V's SLAT CR3 (see 4.5).

All of this memory is later hidden from the guest by pointing each page in guest SLAT mappings to a dummy page.

3.3. Starting bootmgfw.efi

The original bootmgfw.efi image is then loaded through UEFI boot_services!LoadImage. A hook on bootmgfw.efi!ImgpLoadPEImage (a routine which loads a portable executable image) is applied. bootmgfw.efi is started using UEFI boot_services!StartImage.

3.4. winload.efi

Once the winload.efi image is being loaded by bootmgfw.efi, it is intercepted by the bootmgfw.efi!ImgpLoadPEImage hook. The bootmgfw.efi hooks are then fully removed before applying a hook to winload.efi!ImgpLoadPEImage. This winload.efi!ImgpLoadPEImage hook allows the loading of hvloader.dll to be intercepted once winload.efi loads it.

3.5. hvloader.dll & Hyper-V launch

Once the loading of hvloader.dll is intercepted via the winload.efi!ImgpLoadPEImage hook, a hook is applied deep in the Hyper-V launch routine within hvloader.dll after removing the hooks on winload.efi. Below is a stripped down decompilation of the Hyper-V launch routine that is hooked (it is called within hvloader.dll!HvlLaunchHypervisor):

cpp
void __fastcall hv_launch(std::uint64_t hyperv_cr3, std::uint8_t* hyperv_entry_point, std::uint8_t* entry_point_gadget, std::uint64_t guest_kernel_cr3)
{
	__writecr3(guest_kernel_cr3);
	__asm { jmp entry_point_gadget }
}

This hooked Hyper-V launch routine will jump to a gadget which will end up in Hyper-V's entry point. The parameters are as follows:

  • rcx = a CR3 which Hyper-V copies certain PML4es from.
  • rdx = the virtual address of the relocated Hyper-V's entry point.
  • r8 = the address of the gadget which jumps to Hyper-V's entry point.
  • r9 = the guest's kernel CR3 (e.g. 0x1AE000 on Windows 11 24H2).

3.5.1. Loading hyperv-attachment

Continuing with the hook, a PML4e is inserted into the CR3 held in rcx. This PML4e contains an identity map of host physical memory. The physical memory backing the hyperv-attachment is also mapped in by this identity map, so there is a valid virtual mapping of the hyperv-attachment in Hyper-V's address space. The loaded hyperv-attachment image is relocated by (virtual base of the PML4e/identity map + physical base address of hyperv-attachment image). This relocation means that the hyperv-attachment will be able to execute under Hyper-V's address space once it is launched.

As @Iraq1337 described in his post, there are a few copies of Hyper-V in physical memory which are not SLAT protected (the guest can read them). Only the final Hyper-V image buffer is hidden from the guest. In the hypervisor launch hook, rdx holds a virtual address backing the final image buffer, which WILL be SLAT protected, so patches can be applied to it without them being disclosed to the guest. In the launch routine hook, a hook is placed on Hyper-V's VM exit handler, pointing it to a code cave where a far/long jump instruction will detour to the hyperv-attachment's VM exit handler. All of this is done after the Hyper-V launch routine hook is removed.

4. hyperv-attachment/post Hyper-V launch info

4.1. How does it support different architectures?

The hyperv-attachment supports both Intel and AMD. This is possible through some abstraction of architecture-specific code and a few #ifdefs, meaning both architectures are supported in the same codebase. The steps to compile the hyperv-attachment for Intel or AMD are described in '7. How to compile / use'.

4.2. Entry point (pre Hyper-V launch)

The hyperv-attachment's entry point is called in the Hyper-V launch detour and does the following:

  • Sets up a heap manager.
  • Sets up initial SLAT context allocations.
  • Sets up processor state logs context.
  • Intakes some info from the uefi-boot image module for later usage (e.g. the physical base address and size of the uefi-boot image).

Host (the hypervisor running on the hardware which controls the guest) physical memory is accessed by the hyperv-attachment through the identity map that was set up before.

4.3. First VM exit

In the first VM exit, the hyperv-attachment does the following:

  • Sets up a NMI (non maskable interrupt) handler in Hyper-V's global IDT (interrupt descriptor table).
  • Sets up the APIC (Advanced Programmable Interrupt Controller), which is later used to fire NMIs to all host logical processors to synchronize SLAT caches.
  • Nulls out the uefi-boot image to prevent the guest from searching for it.

Some processes cannot be done in the first VM exit (especially ones relating to SLAT), as Hyper-V has not fully finished initializing yet. After a certain amount of VM exits have taken place, the hyperv-attachment hides the heap (the one that was set up originally in the uefi-boot image) via SLAT. The hidden uefi-boot heap memory includes hyperv-attachment's internal heap, image allocation and identity map page table structures that were allocated. This is achieved by setting the page frame numbers of all the page table entries to that of a free dummy page in the heap.

4.4. APIC

At the first VM exit, basic information of APIC is fetched through the 'APIC base' located at the MSR 0x1B. If APIC is already enabled, then it is checked whether xAPIC or x2APIC is used. If APIC is not already enabled, then the highest possible version of APIC is enabled. For xAPIC, the ICR (interrupt command register) can be accessed through its host physical address at the Local APIC. For x2APIC, the ICR is accessed through the MSRs representing the Local APIC.

Through the ICR, commands can be sent to the Local APIC. This is later used to send Non Maskable Interrupts to all processors but the currently executing one by formulating an ICR request. Later on in the post, it is described how those NMIs are used for synchronizing SLAT code hooks (EPT/NPT hooks). The APIC library which was internally developed for this project and released separately can be found here.

4.5. SLAT

A SLAT CR3 is a CR3 which describes SLAT/translations of guest physical memory to host physical memory. On AMD this is called a nested CR3. On Intel this is called an EPT pointer.

The Hyper-V SLAT CR3 is the global SLAT CR3 created by Hyper-V. This is shared by all logical processors in Hyper-V in both Intel and AMD.

The hook SLAT CR3 is explained 4.5.3.3. It is the SLAT CR3 that the hyperv-attachment creates by making a deep copy of the Hyper-V SLAT CR3.

The SLAT code hooks were implemented as follows:

4.5.1. Code hooks on Intel

There is only 1 pointer (Intel's SLAT CR3), shared by all logical processors in Hyper-V.

The current core's EPT pointer changes between the hook SLAT CR3 and the Hyper-V SLAT CR3 in the EPT violation handler as needed. This is because both these SLAT CR3s hold mappings for the target page, but with different permissions.

When a hook is added, the following happens to the target page:

  • The page is made --x (non readable, non writable, but is executable) in the Hyper-V SLAT CR3.
  • The page's page frame number is set to that of the shadow page in the Hyper-V SLAT CR3.
  • The page is made rw- (is readable, is writable, but non executable) in the hook SLAT CR3.
  • The page's page frame number i

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++amddebuggerepthyper-rev

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具