|
|
@ -8,6 +8,9 @@
|
|
|
|
#include "../loadup.hpp"
|
|
|
|
#include "../loadup.hpp"
|
|
|
|
#include "../raw_driver.hpp"
|
|
|
|
#include "../raw_driver.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAP_PHYSICAL_MEMORY 0xC3502004
|
|
|
|
|
|
|
|
#define UNMAP_PHYSICAL_MEMORY 0xC3502008
|
|
|
|
|
|
|
|
|
|
|
|
#pragma pack ( push, 1 )
|
|
|
|
#pragma pack ( push, 1 )
|
|
|
|
typedef struct _GIOMAP
|
|
|
|
typedef struct _GIOMAP
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -23,7 +26,6 @@ namespace nasa
|
|
|
|
{
|
|
|
|
{
|
|
|
|
inline std::string drv_key;
|
|
|
|
inline std::string drv_key;
|
|
|
|
inline HANDLE drv_handle = NULL;
|
|
|
|
inline HANDLE drv_handle = NULL;
|
|
|
|
inline std::vector<std::pair<std::uintptr_t, std::uint32_t >> virtual_mappings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline bool load_drv()
|
|
|
|
inline bool load_drv()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -51,38 +53,43 @@ namespace nasa
|
|
|
|
return CloseHandle(drv_handle) && driver::unload(drv_key);
|
|
|
|
return CloseHandle(drv_handle) && driver::unload(drv_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline std::uintptr_t map_phys(
|
|
|
|
inline std::uintptr_t map_phys(std::uintptr_t addr, std::size_t size)
|
|
|
|
std::uintptr_t addr,
|
|
|
|
|
|
|
|
std::size_t size
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GIOMAP in_buffer = { 0, 0, addr, 0, size };
|
|
|
|
GIOMAP in_buffer = { 0, 0, addr, 0, size };
|
|
|
|
uintptr_t out_buffer[2] = { 0 };
|
|
|
|
uintptr_t out_buffer[2] = { 0 };
|
|
|
|
unsigned long returned = 0;
|
|
|
|
unsigned long returned = 0;
|
|
|
|
DeviceIoControl(drv_handle, 0xC3502004, reinterpret_cast<LPVOID>(&in_buffer), sizeof(in_buffer),
|
|
|
|
|
|
|
|
reinterpret_cast<LPVOID>(out_buffer), sizeof(out_buffer), &returned, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual_mappings.push_back({ out_buffer[0], size });
|
|
|
|
if (!DeviceIoControl(
|
|
|
|
|
|
|
|
drv_handle,
|
|
|
|
|
|
|
|
MAP_PHYSICAL_MEMORY,
|
|
|
|
|
|
|
|
reinterpret_cast<LPVOID>(&in_buffer),
|
|
|
|
|
|
|
|
sizeof(in_buffer),
|
|
|
|
|
|
|
|
reinterpret_cast<LPVOID>(out_buffer),
|
|
|
|
|
|
|
|
sizeof(out_buffer),
|
|
|
|
|
|
|
|
&returned, NULL
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
return out_buffer[0];
|
|
|
|
return out_buffer[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool unmap_phys(
|
|
|
|
inline bool unmap_phys(std::uintptr_t addr, std::size_t size)
|
|
|
|
std::uintptr_t addr,
|
|
|
|
|
|
|
|
std::size_t size
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uintptr_t in_buffer = addr;
|
|
|
|
uintptr_t in_buffer = addr;
|
|
|
|
uintptr_t out_buffer[2] = { sizeof(out_buffer) };
|
|
|
|
uintptr_t out_buffer[2] = { sizeof(out_buffer) };
|
|
|
|
|
|
|
|
|
|
|
|
unsigned long returned = NULL;
|
|
|
|
unsigned long returned = NULL;
|
|
|
|
DeviceIoControl(drv_handle, 0xC3502008, reinterpret_cast<LPVOID>(&in_buffer), sizeof(in_buffer),
|
|
|
|
|
|
|
|
reinterpret_cast<LPVOID>(out_buffer), sizeof(out_buffer), &returned, NULL);
|
|
|
|
|
|
|
|
return out_buffer[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void unmap_all()
|
|
|
|
if (!DeviceIoControl(
|
|
|
|
{
|
|
|
|
drv_handle,
|
|
|
|
for (auto idx = 0u; idx < virtual_mappings.size(); ++idx)
|
|
|
|
UNMAP_PHYSICAL_MEMORY,
|
|
|
|
unmap_phys(virtual_mappings[idx].first, virtual_mappings[idx].second);
|
|
|
|
reinterpret_cast<LPVOID>(&in_buffer),
|
|
|
|
|
|
|
|
sizeof(in_buffer),
|
|
|
|
|
|
|
|
reinterpret_cast<LPVOID>(out_buffer),
|
|
|
|
|
|
|
|
sizeof(out_buffer),
|
|
|
|
|
|
|
|
&returned, NULL
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return out_buffer[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|