mirror of
https://github.com/momo5502/hypervisor.git
synced 2025-04-19 05:32:55 +00:00
Fix formatting
This commit is contained in:
parent
90e2c262ad
commit
965dd3a5bc
10
.editorconfig
Normal file
10
.editorconfig
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[*.{cpp,hpp}]
|
||||||
|
end_of_line = crlf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
charset = utf-8
|
||||||
|
brace_style = next_line
|
||||||
|
namespace_indentation = all
|
||||||
|
cpp_indent_namespace_contents = true
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "std_include.hpp"
|
#include "std_include.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
void _sldt(uint16_t* ldtr);
|
void _sldt(uint16_t* ldtr);
|
||||||
void _ltr(uint16_t tr);
|
void _ltr(uint16_t tr);
|
||||||
void _str(uint16_t* tr);
|
void _str(uint16_t* tr);
|
||||||
@ -15,5 +15,4 @@ void __invept(size_t type, invept_descriptor* descriptor);
|
|||||||
[[ noreturn ]] void vm_launch();
|
[[ noreturn ]] void vm_launch();
|
||||||
[[ noreturn ]] void vm_exit();
|
[[ noreturn ]] void vm_exit();
|
||||||
[[ noreturn ]] void restore_context(CONTEXT* context);
|
[[ noreturn ]] void restore_context(CONTEXT* context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,8 @@ namespace vmx
|
|||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
void install_hook(const void* destination, const void* source, size_t length, ept_translation_hint* translation_hint = nullptr);
|
void install_hook(const void* destination, const void* source, size_t length,
|
||||||
|
ept_translation_hint* translation_hint = nullptr);
|
||||||
void disable_all_hooks() const;
|
void disable_all_hooks() const;
|
||||||
|
|
||||||
void handle_violation(guest_context& guest_context) const;
|
void handle_violation(guest_context& guest_context) const;
|
||||||
@ -95,6 +96,7 @@ namespace vmx
|
|||||||
|
|
||||||
void split_large_page(uint64_t physical_address);
|
void split_large_page(uint64_t physical_address);
|
||||||
|
|
||||||
void install_page_hook(void* destination, const void* source, size_t length, ept_translation_hint* translation_hint = nullptr);
|
void install_page_hook(void* destination, const void* source, size_t length,
|
||||||
|
ept_translation_hint* translation_hint = nullptr);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ namespace
|
|||||||
|
|
||||||
// This absolutely needs to be inlined. Otherwise the stack might be broken upon restoration
|
// This absolutely needs to be inlined. Otherwise the stack might be broken upon restoration
|
||||||
// See: https://github.com/ionescu007/SimpleVisor/issues/48
|
// See: https://github.com/ionescu007/SimpleVisor/issues/48
|
||||||
#define capture_cpu_context(launch_context) \
|
#define capture_cpu_context(launch_context) \
|
||||||
cpature_special_registers((launch_context).special_registers);\
|
cpature_special_registers((launch_context).special_registers);\
|
||||||
RtlCaptureContext(&(launch_context).context_frame);
|
RtlCaptureContext(&(launch_context).context_frame);
|
||||||
|
|
||||||
@ -303,7 +303,6 @@ void enter_root_mode_on_cpu(vmx::state& vm_state)
|
|||||||
|
|
||||||
if (__vmx_vmclear(&launch_context->vmcs_physical_address))
|
if (__vmx_vmclear(&launch_context->vmcs_physical_address))
|
||||||
{
|
{
|
||||||
|
|
||||||
throw std::runtime_error("Failed to clear vmcs");
|
throw std::runtime_error("Failed to clear vmcs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ public:
|
|||||||
|
|
||||||
bool is_enabled() const;
|
bool is_enabled() const;
|
||||||
|
|
||||||
bool install_ept_hook(const void* destination, const void* source, size_t length, vmx::ept_translation_hint* translation_hint = nullptr);
|
bool install_ept_hook(const void* destination, const void* source, size_t length,
|
||||||
|
vmx::ept_translation_hint* translation_hint = nullptr);
|
||||||
void disable_all_ept_hooks() const;
|
void disable_all_ept_hooks() const;
|
||||||
|
|
||||||
static hypervisor* get_instance();
|
static hypervisor* get_instance();
|
||||||
@ -35,8 +36,10 @@ private:
|
|||||||
void allocate_vm_states();
|
void allocate_vm_states();
|
||||||
void free_vm_states();
|
void free_vm_states();
|
||||||
|
|
||||||
bool try_install_ept_hook_on_core(const void* destination, const void* source, size_t length, vmx::ept_translation_hint* translation_hint = nullptr);
|
bool try_install_ept_hook_on_core(const void* destination, const void* source, size_t length,
|
||||||
void install_ept_hook_on_core(const void* destination, const void* source, size_t length, vmx::ept_translation_hint* translation_hint = nullptr);
|
vmx::ept_translation_hint* translation_hint = nullptr);
|
||||||
|
void install_ept_hook_on_core(const void* destination, const void* source, size_t length,
|
||||||
|
vmx::ept_translation_hint* translation_hint = nullptr);
|
||||||
|
|
||||||
vmx::state* get_current_vm_state() const;
|
vmx::state* get_current_vm_state() const;
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ namespace
|
|||||||
memcpy(buffer, request.source_data, request.source_data_size);
|
memcpy(buffer, request.source_data, request.source_data_size);
|
||||||
|
|
||||||
auto* hypervisor = hypervisor::get_instance();
|
auto* hypervisor = hypervisor::get_instance();
|
||||||
if(!hypervisor)
|
if (!hypervisor)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Hypervisor not installed");
|
throw std::runtime_error("Hypervisor not installed");
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ namespace
|
|||||||
void unhook()
|
void unhook()
|
||||||
{
|
{
|
||||||
const auto instance = hypervisor::get_instance();
|
const auto instance = hypervisor::get_instance();
|
||||||
if(instance)
|
if (instance)
|
||||||
{
|
{
|
||||||
instance->disable_all_ept_hooks();
|
instance->disable_all_ept_hooks();
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ namespace
|
|||||||
|
|
||||||
void try_apply_hook(const PIO_STACK_LOCATION irp_sp)
|
void try_apply_hook(const PIO_STACK_LOCATION irp_sp)
|
||||||
{
|
{
|
||||||
if(irp_sp->Parameters.DeviceIoControl.InputBufferLength < sizeof(hook_request))
|
if (irp_sp->Parameters.DeviceIoControl.InputBufferLength < sizeof(hook_request))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid hook request");
|
throw std::runtime_error("Invalid hook request");
|
||||||
}
|
}
|
||||||
@ -155,12 +155,12 @@ namespace
|
|||||||
{
|
{
|
||||||
handle_irp(irp);
|
handle_irp(irp);
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
debug_log("Handling IRP failed: %s\n", e.what());
|
debug_log("Handling IRP failed: %s\n", e.what());
|
||||||
irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch (...)
|
||||||
{
|
{
|
||||||
debug_log("Handling IRP failed\n");
|
debug_log("Handling IRP failed\n");
|
||||||
irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
|
@ -120,7 +120,8 @@ namespace memory
|
|||||||
|
|
||||||
void assert_readability(const void* address, const size_t length, const uint64_t alignment)
|
void assert_readability(const void* address, const size_t length, const uint64_t alignment)
|
||||||
{
|
{
|
||||||
if(!prope_for_read(address, length, alignment)) {
|
if (!prope_for_read(address, length, alignment))
|
||||||
|
{
|
||||||
throw std::runtime_error("Access violation");
|
throw std::runtime_error("Access violation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,7 +141,8 @@ namespace memory
|
|||||||
|
|
||||||
void assert_writability(const void* address, const size_t length, const uint64_t alignment)
|
void assert_writability(const void* address, const size_t length, const uint64_t alignment)
|
||||||
{
|
{
|
||||||
if (!prope_for_write(address, length, alignment)) {
|
if (!prope_for_write(address, length, alignment))
|
||||||
|
{
|
||||||
throw std::runtime_error("Access violation");
|
throw std::runtime_error("Access violation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
@ -14,7 +15,7 @@ VOID
|
|||||||
KeGenericCallDpc(
|
KeGenericCallDpc(
|
||||||
_In_ PKDEFERRED_ROUTINE Routine,
|
_In_ PKDEFERRED_ROUTINE Routine,
|
||||||
_In_opt_ PVOID Context
|
_In_opt_ PVOID Context
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ _IRQL_requires_same_
|
|||||||
VOID
|
VOID
|
||||||
KeSignalCallDpcDone(
|
KeSignalCallDpcDone(
|
||||||
_In_ PVOID SystemArgument1
|
_In_ PVOID SystemArgument1
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ _IRQL_requires_same_
|
|||||||
LOGICAL
|
LOGICAL
|
||||||
KeSignalCallDpcSynchronize(
|
KeSignalCallDpcSynchronize(
|
||||||
_In_ PVOID SystemArgument2
|
_In_ PVOID SystemArgument2
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ MmAllocateContiguousNodeMemory(
|
|||||||
_In_opt_ PHYSICAL_ADDRESS BoundaryAddressMultiple,
|
_In_opt_ PHYSICAL_ADDRESS BoundaryAddressMultiple,
|
||||||
_In_ ULONG Protect,
|
_In_ ULONG Protect,
|
||||||
_In_ NODE_REQUIREMENT PreferredNode
|
_In_ NODE_REQUIREMENT PreferredNode
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
@ -60,7 +61,7 @@ VOID
|
|||||||
NTAPI
|
NTAPI
|
||||||
RtlCaptureContext(
|
RtlCaptureContext(
|
||||||
_Out_ PCONTEXT ContextRecord
|
_Out_ PCONTEXT ContextRecord
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ VOID
|
|||||||
KeStackAttachProcess(
|
KeStackAttachProcess(
|
||||||
__inout PEPROCESS PROCESS,
|
__inout PEPROCESS PROCESS,
|
||||||
__out PRKAPC_STATE ApcState
|
__out PRKAPC_STATE ApcState
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ NTKERNELAPI
|
|||||||
VOID
|
VOID
|
||||||
KeUnstackDetachProcess(
|
KeUnstackDetachProcess(
|
||||||
__in PRKAPC_STATE ApcState
|
__in PRKAPC_STATE ApcState
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ NTSTATUS
|
|||||||
PsLookupProcessByProcessId(
|
PsLookupProcessByProcessId(
|
||||||
IN HANDLE ProcessId,
|
IN HANDLE ProcessId,
|
||||||
OUT PEPROCESS* Process
|
OUT PEPROCESS* Process
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ NTKERNELAPI
|
|||||||
PVOID
|
PVOID
|
||||||
PsGetProcessSectionBaseAddress(
|
PsGetProcessSectionBaseAddress(
|
||||||
__in PEPROCESS Process
|
__in PEPROCESS Process
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -114,15 +115,15 @@ PPEB
|
|||||||
NTAPI
|
NTAPI
|
||||||
PsGetProcessPeb(
|
PsGetProcessPeb(
|
||||||
IN PEPROCESS Process
|
IN PEPROCESS Process
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
NTKERNELAPI
|
NTKERNELAPI
|
||||||
PCSTR
|
PCSTR
|
||||||
PsGetProcessImageFileName(
|
PsGetProcessImageFileName(
|
||||||
__in PEPROCESS Process
|
__in PEPROCESS Process
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
@ -141,7 +142,7 @@ NtCreateFile(
|
|||||||
_In_ ULONG CreateOptions,
|
_In_ ULONG CreateOptions,
|
||||||
_In_reads_bytes_opt_(EaLength) PVOID EaBuffer,
|
_In_reads_bytes_opt_(EaLength) PVOID EaBuffer,
|
||||||
_In_ ULONG EaLength
|
_In_ ULONG EaLength
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace process
|
|||||||
|
|
||||||
bool process_handle::is_alive() const
|
bool process_handle::is_alive() const
|
||||||
{
|
{
|
||||||
if(!this->handle_)
|
if (!this->handle_)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ namespace process
|
|||||||
|
|
||||||
uint32_t process_handle::get_id() const
|
uint32_t process_handle::get_id() const
|
||||||
{
|
{
|
||||||
if(!this->handle_)
|
if (!this->handle_)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ void sleep_callback::dispatcher(const type type) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
_Function_class_(CALLBACK_FUNCTION)
|
_Function_class_(CALLBACK_FUNCTION)
|
||||||
|
|
||||||
void sleep_callback::static_callback(void* context, void* argument1, void* argument2)
|
void sleep_callback::static_callback(void* context, void* argument1, void* argument2)
|
||||||
{
|
{
|
||||||
if (!context || argument1 != reinterpret_cast<PVOID>(PO_CB_SYSTEM_STATE_LOCK))
|
if (!context || argument1 != reinterpret_cast<PVOID>(PO_CB_SYSTEM_STATE_LOCK))
|
||||||
|
@ -10,7 +10,7 @@ namespace string
|
|||||||
|
|
||||||
char* get_va_buffer();
|
char* get_va_buffer();
|
||||||
|
|
||||||
template<typename ...Args>
|
template <typename ...Args>
|
||||||
const char* va(const char* message, Args&&... args)
|
const char* va(const char* message, Args&&... args)
|
||||||
{
|
{
|
||||||
auto* buffer = get_va_buffer();
|
auto* buffer = get_va_buffer();
|
||||||
|
@ -37,7 +37,6 @@ namespace std
|
|||||||
|
|
||||||
// TEMPLATE FUNCTION forward
|
// TEMPLATE FUNCTION forward
|
||||||
template <class _Ty>
|
template <class _Ty>
|
||||||
inline
|
|
||||||
constexpr _Ty&& forward(
|
constexpr _Ty&& forward(
|
||||||
typename remove_reference<_Ty>::type& _Arg)
|
typename remove_reference<_Ty>::type& _Arg)
|
||||||
{
|
{
|
||||||
@ -46,7 +45,6 @@ namespace std
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class _Ty>
|
template <class _Ty>
|
||||||
inline
|
|
||||||
constexpr _Ty&& forward(
|
constexpr _Ty&& forward(
|
||||||
typename remove_reference<_Ty>::type&& _Arg)
|
typename remove_reference<_Ty>::type&& _Arg)
|
||||||
{
|
{
|
||||||
|
@ -73,9 +73,9 @@ namespace std
|
|||||||
static constexpr auto is_array_type = is_array<T>::value;
|
static constexpr auto is_array_type = is_array<T>::value;
|
||||||
T* pointer_{nullptr};
|
T* pointer_{nullptr};
|
||||||
|
|
||||||
void delete_pointer()
|
void delete_pointer() const
|
||||||
{
|
{
|
||||||
if(is_array_type)
|
if (is_array_type)
|
||||||
{
|
{
|
||||||
delete[] this->pointer_;
|
delete[] this->pointer_;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,7 @@ driver_device::driver_device(const std::string& driver_device)
|
|||||||
nullptr,
|
nullptr,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
NULL,
|
NULL,
|
||||||
nullptr
|
nullptr);
|
||||||
);
|
|
||||||
|
|
||||||
if (!this->device_)
|
if (!this->device_)
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
|
||||||
#include "std_include.hpp"
|
#include "std_include.hpp"
|
||||||
#include "finally.hpp"
|
|
||||||
#include "driver.hpp"
|
#include "driver.hpp"
|
||||||
#include "driver_device.hpp"
|
#include "driver_device.hpp"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user