MCPcopy Create free account
hub / github.com/Compiled-Code/eac-mapper / vdm_ctx

Class vdm_ctx

dependencies/vdm/vdm_ctx/vdm_ctx.hpp:24–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 using write_phys_t = std::function<decltype(vdm::write_phys)>;
23
24 class vdm_ctx
25 {
26 public:
27 explicit vdm_ctx();
28 void set_read(read_phys_t& read_func);
29 void set_write(write_phys_t& write_func);
30 void rkm(void* dst, void* src, std::size_t size);
31 void* wkm(void* dst, void* src, std::size_t size);
32
33 template <class T, class ... Ts>
34 __forceinline std::invoke_result_t<T, Ts...> syscall(void* addr, Ts... args) const
35 {
36 static const auto proc =
37 GetProcAddress(
38 LoadLibraryA(syscall_hook.second),
39 syscall_hook.first
40 );
41
42 static std::mutex syscall_mutex;
43 syscall_mutex.lock();
44
45 // jmp [rip+0x0]
46 std::uint8_t jmp_code[] =
47 {
48 0xff, 0x25, 0x00, 0x00,
49 0x00, 0x00, 0x00, 0x00,
50 0x00, 0x00, 0x00, 0x00,
51 0x00, 0x00
52 };
53
54 std::uint8_t orig_bytes[sizeof jmp_code];
55 *reinterpret_cast<void**>(jmp_code + 6) = addr;
56 read_phys(vdm::syscall_address.load(), orig_bytes, sizeof orig_bytes);
57
58 // execute hook...
59 write_phys(vdm::syscall_address.load(), jmp_code, sizeof jmp_code);
60 auto result = reinterpret_cast<T>(proc)(args...);
61 write_phys(vdm::syscall_address.load(), orig_bytes, sizeof orig_bytes);
62
63 syscall_mutex.unlock();
64 return result;
65 }
66
67 template <class T>
68 __forceinline auto rkm(std::uintptr_t addr) -> T
69 {
70 T buffer;
71 rkm((void*)&buffer, (void*)addr, sizeof T);
72 return buffer;
73 }
74
75 template <class T>
76 __forceinline void* wkm(std::uintptr_t addr, const T& value)
77 {
78 return wkm((void*)addr, (void*)&value, sizeof T);
79 }
80
81 __forceinline auto get_peprocess(std::uint32_t pid) -> PEPROCESS

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected