| 2 | #include "KittyMemoryEx.hpp" |
| 3 | |
| 4 | bool KittyMemoryMgr::initialize(pid_t pid, EKittyMemOP eMemOp, bool initMemPatch) |
| 5 | { |
| 6 | _init = false; |
| 7 | _pid = pid; |
| 8 | |
| 9 | if (_pid <= 0) |
| 10 | { |
| 11 | KITTY_LOGE("KittyMemoryMgr: Invalid arg (pid)."); |
| 12 | return false; |
| 13 | } |
| 14 | |
| 15 | _process_name = KittyMemoryEx::getProcessName(_pid); |
| 16 | |
| 17 | if (_pMemOp.get()) |
| 18 | _pMemOp.reset(); |
| 19 | |
| 20 | _eMemOp = eMemOp; |
| 21 | switch (eMemOp) |
| 22 | { |
| 23 | case EK_MEM_OP_SYSCALL: |
| 24 | _pMemOp = std::make_unique<KittyMemSys>(); |
| 25 | break; |
| 26 | case EK_MEM_OP_IO: |
| 27 | _pMemOp = std::make_unique<KittyMemIO>(); |
| 28 | break; |
| 29 | default: |
| 30 | KITTY_LOGE("KittyMemoryMgr: Unknown memory operation."); |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | if (!_pMemOp->init(_pid)) |
| 35 | { |
| 36 | KITTY_LOGE("KittyMemoryMgr: Couldn't initialize memory operation."); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | _init = true; |
| 41 | |
| 42 | // patching mem only avaialabe for IO operation |
| 43 | if (initMemPatch) |
| 44 | { |
| 45 | if (eMemOp == EK_MEM_OP_IO) |
| 46 | { |
| 47 | memPatch = MemoryPatchMgr(_pMemOp.get()); |
| 48 | memBackup = MemoryBackupMgr(_pMemOp.get()); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | if (_pMemOpPatch.get()) |
| 53 | _pMemOpPatch.reset(); |
| 54 | |
| 55 | _pMemOpPatch = std::make_unique<KittyMemIO>(); |
| 56 | if (_pMemOpPatch->init(pid)) |
| 57 | { |
| 58 | memPatch = MemoryPatchMgr(_pMemOpPatch.get()); |
| 59 | memBackup = MemoryBackupMgr(_pMemOpPatch.get()); |
| 60 | } |
| 61 | else |
no test coverage detected