mirror of
https://github.com/momo5502/hypervisor.git
synced 2025-04-19 21:52:55 +00:00
Resource tests
This commit is contained in:
parent
93a88c5d7a
commit
28c9145268
@ -1,3 +1,4 @@
|
|||||||
add_subdirectory(shared)
|
add_subdirectory(shared)
|
||||||
add_subdirectory(driver)
|
add_subdirectory(driver)
|
||||||
|
add_subdirectory(driver_file)
|
||||||
add_subdirectory(runner)
|
add_subdirectory(runner)
|
12
src/driver_file/CMakeLists.txt
Normal file
12
src/driver_file/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
set(DRIVER_FILE "$<TARGET_FILE:driver>")
|
||||||
|
|
||||||
|
file (GENERATE
|
||||||
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/driver_file.h"
|
||||||
|
CONTENT "#define DRIVER_FILE \"${DRIVER_FILE}\"\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(driver_file INTERFACE)
|
||||||
|
|
||||||
|
target_include_directories(driver_file INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>)
|
||||||
|
|
||||||
|
add_dependencies(driver_file driver)
|
@ -12,8 +12,12 @@ target_precompile_headers(runner
|
|||||||
|
|
||||||
set_property(TARGET runner APPEND_STRING PROPERTY LINK_FLAGS " /MANIFESTUAC:\"level='requireAdministrator'\"")
|
set_property(TARGET runner APPEND_STRING PROPERTY LINK_FLAGS " /MANIFESTUAC:\"level='requireAdministrator'\"")
|
||||||
|
|
||||||
add_dependencies(runner driver)
|
|
||||||
|
|
||||||
target_link_libraries(runner
|
target_link_libraries(runner
|
||||||
shared
|
shared
|
||||||
|
driver_file
|
||||||
|
)
|
||||||
|
|
||||||
|
set_source_files_properties(resource.rc PROPERTIES LANGUAGE RC)
|
||||||
|
target_sources(runner PRIVATE
|
||||||
|
resource.rc
|
||||||
)
|
)
|
@ -1,5 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "std_include.hpp"
|
#include "std_include.hpp"
|
||||||
#include "driver.hpp"
|
#include "driver.hpp"
|
||||||
@ -7,19 +9,10 @@
|
|||||||
|
|
||||||
#include <irp_data.hpp>
|
#include <irp_data.hpp>
|
||||||
|
|
||||||
|
#include "resource.hpp"
|
||||||
|
|
||||||
#pragma comment(lib, "Shlwapi.lib")
|
#pragma comment(lib, "Shlwapi.lib")
|
||||||
|
|
||||||
std::filesystem::path get_current_path()
|
|
||||||
{
|
|
||||||
const auto module = GetModuleHandleA(nullptr);
|
|
||||||
|
|
||||||
char selfdir[MAX_PATH] = {0};
|
|
||||||
GetModuleFileNameA(module, selfdir, MAX_PATH);
|
|
||||||
PathRemoveFileSpecA(selfdir);
|
|
||||||
|
|
||||||
return selfdir;
|
|
||||||
}
|
|
||||||
|
|
||||||
void patch_data(const driver_device& driver_device, const uint32_t pid, const uint64_t addr, const uint8_t* buffer,
|
void patch_data(const driver_device& driver_device, const uint32_t pid, const uint64_t addr, const uint8_t* buffer,
|
||||||
const size_t length)
|
const size_t length)
|
||||||
{
|
{
|
||||||
@ -51,9 +44,41 @@ void remove_hooks(const driver_device& driver_device)
|
|||||||
(void)driver_device.send(UNHOOK_DRV_IOCTL, driver_device::data{});
|
(void)driver_device.send(UNHOOK_DRV_IOCTL, driver_device::data{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> load_resource(const int id)
|
||||||
|
{
|
||||||
|
auto* const res = FindResource(GetModuleHandleA(nullptr), MAKEINTRESOURCE(id), RT_RCDATA);
|
||||||
|
if (!res) return {};
|
||||||
|
|
||||||
|
auto* const handle = LoadResource(nullptr, res);
|
||||||
|
if (!handle) return {};
|
||||||
|
|
||||||
|
const auto* data_ptr =static_cast<uint8_t*>(LockResource(handle));
|
||||||
|
const auto data_size = SizeofResource(nullptr, res);
|
||||||
|
|
||||||
|
std::vector<uint8_t> data{};
|
||||||
|
data.assign(data_ptr, data_ptr + data_size);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path extract_driver()
|
||||||
|
{
|
||||||
|
const auto data = load_resource(DRIVER_BINARY);
|
||||||
|
|
||||||
|
auto driver_file = std::filesystem::temp_directory_path() / "driver.sys";
|
||||||
|
|
||||||
|
std::ofstream out_file{};
|
||||||
|
out_file.open(driver_file.generic_string(), std::ios::out | std::ios::binary);
|
||||||
|
out_file.write(reinterpret_cast<const char*>(data.data()), static_cast<std::streamsize>(data.size()));
|
||||||
|
out_file.close();
|
||||||
|
|
||||||
|
return driver_file;
|
||||||
|
}
|
||||||
|
|
||||||
void unsafe_main(const int /*argc*/, char* /*argv*/[])
|
void unsafe_main(const int /*argc*/, char* /*argv*/[])
|
||||||
{
|
{
|
||||||
driver driver{get_current_path() / "driver.sys", "MomoLul"};
|
const auto driver_file = extract_driver();
|
||||||
|
|
||||||
|
driver driver{ driver_file, "MomoLul"};
|
||||||
const driver_device driver_device{R"(\\.\HelloDev)"};
|
const driver_device driver_device{R"(\\.\HelloDev)"};
|
||||||
|
|
||||||
std::string pid_str{};
|
std::string pid_str{};
|
||||||
|
3
src/runner/resource.hpp
Normal file
3
src/runner/resource.hpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define DRIVER_BINARY 300
|
104
src/runner/resource.rc
Normal file
104
src/runner/resource.rc
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
// Microsoft Visual C++ generated resource script.
|
||||||
|
//
|
||||||
|
#pragma code_page(65001)
|
||||||
|
|
||||||
|
#define APSTUDIO_READONLY_SYMBOLS
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 2 resource.
|
||||||
|
//
|
||||||
|
#include "windows.h"
|
||||||
|
#include "resource.hpp"
|
||||||
|
#include <driver_file.h>
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// English (United States) resources
|
||||||
|
|
||||||
|
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||||
|
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||||
|
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// TEXTINCLUDE
|
||||||
|
//
|
||||||
|
|
||||||
|
1 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"#include ""windows.h""\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
2 TEXTINCLUDE
|
||||||
|
BEGIN
|
||||||
|
"\r\n"
|
||||||
|
"\0"
|
||||||
|
END
|
||||||
|
|
||||||
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Version
|
||||||
|
//
|
||||||
|
|
||||||
|
VS_VERSION_INFO VERSIONINFO
|
||||||
|
FILEVERSION 1,0,0,0
|
||||||
|
PRODUCTVERSION 1,0,0,0
|
||||||
|
FILEFLAGSMASK 0x3fL
|
||||||
|
#ifdef _DEBUG
|
||||||
|
FILEFLAGS 0x1L
|
||||||
|
#else
|
||||||
|
FILEFLAGS 0x0L
|
||||||
|
#endif
|
||||||
|
FILEOS 0x40004L
|
||||||
|
FILETYPE VFT_DLL
|
||||||
|
FILESUBTYPE 0x0L
|
||||||
|
BEGIN
|
||||||
|
BLOCK "StringFileInfo"
|
||||||
|
BEGIN
|
||||||
|
BLOCK "040904b0"
|
||||||
|
BEGIN
|
||||||
|
VALUE "CompanyName", "momo5502"
|
||||||
|
VALUE "FileDescription", "Open-IW5"
|
||||||
|
VALUE "FileVersion", "1.0.0.0"
|
||||||
|
VALUE "InternalName", "Open-IW5"
|
||||||
|
VALUE "LegalCopyright", "All rights reserved."
|
||||||
|
VALUE "OriginalFilename", "open-iw5.exe"
|
||||||
|
VALUE "ProductName", "open-iw5"
|
||||||
|
VALUE "ProductVersion", "1.0.0.0"
|
||||||
|
END
|
||||||
|
END
|
||||||
|
BLOCK "VarFileInfo"
|
||||||
|
BEGIN
|
||||||
|
VALUE "Translation", 0x409, 1200
|
||||||
|
END
|
||||||
|
END
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Binary Data
|
||||||
|
//
|
||||||
|
|
||||||
|
102 ICON "resources/icon.ico"
|
||||||
|
DRIVER_BINARY RCDATA DRIVER_FILE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // English (United States) resources
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef APSTUDIO_INVOKED
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Generated from the TEXTINCLUDE 3 resource.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif // not APSTUDIO_INVOKED
|
BIN
src/runner/resources/icon.ico
Normal file
BIN
src/runner/resources/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 159 KiB |
Loading…
x
Reference in New Issue
Block a user