MCPcopy Create free account
hub / github.com/Artikash/Textractor / ProcessRecord

Class ProcessRecord

host/host.cpp:16–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14namespace
15{
16 class ProcessRecord
17 {
18 public:
19 ProcessRecord(DWORD processId, HANDLE pipe) :
20 pipe(pipe),
21 mappedFile(OpenFileMappingW(FILE_MAP_READ, FALSE, (ITH_SECTION_ + std::to_wstring(processId)).c_str())),
22 view(*(const TextHook(*)[MAX_HOOK])MapViewOfFile(mappedFile, FILE_MAP_READ, 0, 0, HOOK_SECTION_SIZE / 2)), // jichi 1/16/2015: Changed to half to hook section size
23 viewMutex(ITH_HOOKMAN_MUTEX_ + std::to_wstring(processId))
24 {}
25
26 ~ProcessRecord()
27 {
28 UnmapViewOfFile(view);
29 }
30
31 TextHook GetHook(uint64_t addr)
32 {
33 if (!view) return {};
34 std::scoped_lock lock(viewMutex);
35 for (auto hook : view) if (hook.address == addr) return hook;
36 return {};
37 }
38
39 template <typename T>
40 void Send(T data)
41 {
42 static_assert(sizeof(data) < PIPE_BUFFER_SIZE);
43 std::thread([=]
44 {
45 WriteFile(pipe, &data, sizeof(data), DUMMY, nullptr);
46 }).detach();
47 }
48
49 Host::HookEventHandler OnHookFound = [](HookParam hp, std::wstring text)
50 {
51 Host::AddConsoleOutput(HookCode::Generate(hp) + L": " + text);
52 };
53
54 private:
55 HANDLE pipe;
56 AutoHandle<> mappedFile;
57 const TextHook(&view)[MAX_HOOK];
58 WinMutex viewMutex;
59 };
60
61 size_t HashThreadParam(ThreadParam tp) { return std::hash<int64_t>()(tp.processId + tp.addr) + std::hash<int64_t>()(tp.ctx + tp.ctx2); }
62 Synchronized<std::unordered_map<ThreadParam, TextThread, Functor<HashThreadParam>>> textThreadsByParams;

Callers

nothing calls this directly

Calls 2

AddConsoleOutputFunction · 0.85
GenerateFunction · 0.85

Tested by

no test coverage detected