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