diff --git a/include/vmprofiler.hpp b/include/vmprofiler.hpp index 80808b2..f2e5fad 100644 --- a/include/vmprofiler.hpp +++ b/include/vmprofiler.hpp @@ -33,10 +33,6 @@ namespace vm WRITEDW, WRITEW, - READQ, - READDW, - READW, - PUSHVSP, ADDQ, @@ -47,6 +43,7 @@ namespace vm DIVQ, NANDQ, + NANDDW, JMP, @@ -71,959 +68,37 @@ namespace vm namespace profile { - inline vm::handler::profile_t sregq = - { - // MOV RDX, [RBP] - // ADD RBP, 8 - // MOV [RAX+RDI], RDX - "SREGQ", SREGQ, 8, - { - { - // MOV RDX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // ADD RBP, 8 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 8; - }, - // MOV [RAX+RDI], RDX or MOV [RDI+RAX], RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - (instr.operands[0].mem.base == ZYDIS_REGISTER_RAX || - instr.operands[0].mem.base == ZYDIS_REGISTER_RDI) && - (instr.operands[0].mem.index == ZYDIS_REGISTER_RDI || - instr.operands[0].mem.index == ZYDIS_REGISTER_RAX) && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; - } - } - } - }; - - inline vm::handler::profile_t sregdw = - { - // MOV EDX, [RBP] - // ADD RBP, 0x4 - // MOV [RAX+RDI], EDX - "SREGDW", SREGDW, 8, - { - { - // MOV EDX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_EDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // ADD RBP, 0x4 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x4; - }, - // MOV [RAX+RDI], EDX or MOV [RDI+RAX], EDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - (instr.operands[0].mem.base == ZYDIS_REGISTER_RAX || - instr.operands[0].mem.base == ZYDIS_REGISTER_RDI) && - (instr.operands[0].mem.index == ZYDIS_REGISTER_RAX || - instr.operands[0].mem.index == ZYDIS_REGISTER_RDI) && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_EDX; - } - } - } - }; - - inline vm::handler::profile_t sregw = - { - // MOV DX, [RBP] - // ADD RBP, 0x2 - // MOV [RAX+RDI], DX - "SREGW", SREGW, 8, - { - { - // MOV DX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_DX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // ADD RBP, 0x2 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x2; - }, - // MOV [RAX+RDI], DX or MOV [RDI+RAX], DX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - (instr.operands[0].mem.base == ZYDIS_REGISTER_RAX || - instr.operands[0].mem.base == ZYDIS_REGISTER_RDI) && - (instr.operands[0].mem.index == ZYDIS_REGISTER_RDI || - instr.operands[0].mem.index == ZYDIS_REGISTER_RAX) && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_DX; - } - } - } - }; - - inline vm::handler::profile_t lregq = - { - // MOV RDX, [RAX+RDI] - // SUB RBP, 8 - // MOV [RBP], RDX - "LREGQ", LREGQ, 8, - { - { - // MOV RDX, [RAX+RDI] or MOV RDX, [RDI+RAX] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - (instr.operands[1].mem.base == ZYDIS_REGISTER_RAX || - instr.operands[1].mem.base == ZYDIS_REGISTER_RDI) && - (instr.operands[1].mem.index == ZYDIS_REGISTER_RDI || - instr.operands[1].mem.index == ZYDIS_REGISTER_RAX); - }, - // SUB RBP, 8 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x8; - }, - // MOV [RBP], RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; - } - } - } - }; - - inline vm::handler::profile_t lregdw = - { - // MOVZX AL, [RSI] - // MOV RDX, [RAX + RDI] - // SUB RBP, 0x4 - // MOV [RBP], EDX - "LREGDW", LREGDW, 8, - { - { - // MOV RDX, [RAX + RDI] or MOV RDX, [RDI + RAX] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_EDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - (instr.operands[1].mem.base == ZYDIS_REGISTER_RAX || - instr.operands[1].mem.base == ZYDIS_REGISTER_RDI) && - (instr.operands[1].mem.index == ZYDIS_REGISTER_RAX || - instr.operands[1].mem.index == ZYDIS_REGISTER_RDI); - }, - // SUB RBP, 0x4 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x4; - }, - // MOV [RBP], EDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_EDX; - } - } - } - }; - - inline vm::handler::profile_t lconstq = - { - // MOV RAX, [RSI] - // SUB RBP, 8 - // MOV [RBP], RAX - "LCONSTQ", LCONSTQ, 64, - { - { - // SUB RBP, 8 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x8; - }, - // MOV [RBP], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - } - } - } - }; - - inline vm::handler::profile_t lconstbzxw = - { - // MOV AL, [RSI] - // SUB RBP, 2 - // MOV [RBP], AX - "LCONSTBZXW", LCONSTBZXW, 8, - { - { - // SUB RBP, 2 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x2; - }, - // MOV [RBP], AX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_AX; - } - } - } - }; - - inline vm::handler::profile_t lconstbsxdw = - { - // CWDE - // SUB RBP, 4 - // MOV [RBP], EAX - "LCONSTBSXDW", LCONSTBSXDW, 8, - { - { - // CWDE - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_CWDE; - }, - // SUB RBP, 4 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x4; - }, - // MOV [RBP], EAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_EAX; - } - } - }, - vm::handler::extention_t::sign_extend - }; - - inline vm::handler::profile_t lconstdwsxq = - { - // CDQE - // SUB RBP, 8 - // MOV [RBP], RAX - "LCONSTDWSXQ", LCONSTDWSXQ, 32, - { - // CDQE - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_CDQE; - }, - // SUB RBP, 8 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x8; - }, - // MOV [RBP], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - } - }, - vm::handler::extention_t::sign_extend - }; - - inline vm::handler::profile_t lconstwsxq = - { - // CDQE - // SUB RBP, 8 - // MOV [RBP], RAX - "LCONSTWSXQ", LCONSTWSXQ, 16, - { - { - // CDQE - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_CDQE; - }, - // SUB RBP, 8 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x8; - }, - // MOV [RBP], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - } - } - }, - vm::handler::extention_t::sign_extend - }; - - inline vm::handler::profile_t lconstdw = - { - // SUB RBP, 4 - // MOV [RBP], EAX - "LCONSTDW", LCONSTDW, 32, - { - { - // SUB RBP, 4 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x4; - }, - // MOV [RBP], EAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_EAX; - } - } - } - }; - - inline vm::handler::profile_t pushvsp = - { - // MOV RAX, RBP - // SUB RBP, 8 - "PUSHVSP", PUSHVSP, NULL, - { - { - // MOV RAX, RBP - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RBP; - }, - // SUB RBP, 8 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x8; - }, - // MOV [RBP], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - } - } - } - }; + extern vm::handler::profile_t sregq; + extern vm::handler::profile_t sregdw; + extern vm::handler::profile_t sregw; - inline vm::handler::profile_t addq = - { - // ADD [RBP+8], RAX - // PUSHFQ - // POP [RBP] - "ADDQ", ADDQ, NULL, - { - { - // ADD [RBP+8], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - }, - // PUSHFQ - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; - }, - // POP [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_POP && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; - } - } - } - }; - - inline vm::handler::profile_t adddw = - { - // ADD [RBP+8], EAX - // PUSHFQ - // POP [RBP] - "ADDDW", ADDDW, NULL, - { - { - // ADD [RBP+8], EAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_EAX; - }, - // PUSHFQ - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; - }, - // POP [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_POP && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; - } - } - } - }; - - inline vm::handler::profile_t mulq = - { - // MOV RAX, [RBP+0x8] - // SUB RBP, 0x8 - // MUL RDX - // MOV [RBP+0x8], RDX - // MOV [RBP+0x10], RAX - // PUSHFQ - // POP [RBP] - "MULQ", MULQ, NULL, - { - { - // MOV RAX, [RBP+0x8] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].mem.index == 0x8; - }, - // SUB RBP, 0x8 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_SUB && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x8; - }, - // MUL RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MUL && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RDX; - }, - // MOV [RBP+0x8], RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[0].mem.index == 0x8 && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; - }, - // MOV [RBP+0x10], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[0].mem.index == 0x10 && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - }, - // PUSHFQ - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; - }, - // POP [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_POP && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; - } - } - } - }; + extern vm::handler::profile_t lregq; + extern vm::handler::profile_t lregdw; - inline vm::handler::profile_t divq = - { - // MOV RDX, [RBP] - // MOV RAX, [RBP+0x8] - // DIV [RBP+0x10] - // MOV [RBP+0x8], RDX - // MOV [RBP+0x10], RAX - // PUSHFQ - // POP [RBP] - "DIVQ", DIVQ, NULL, - { - { - // MOV RDX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // MOV RAX, [RBP+0x8] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].mem.index == 0x8; - }, - // DIV [RBP+0x10] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_DIV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[0].mem.index == 0x10; - }, - // MOV [RBP+0x8], RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[0].mem.index == 0x8 && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; - }, - // MOV [RBP+0x10], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[0].mem.index == 0x10 && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - }, - // PUSHFQ - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; - }, - // POP [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_POP && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; - } - } - } - }; + extern vm::handler::profile_t lconstq; + extern vm::handler::profile_t lconstbzxw; + extern vm::handler::profile_t lconstbsxdw; + extern vm::handler::profile_t lconstdwsxq; + extern vm::handler::profile_t lconstwsxq; + extern vm::handler::profile_t lconstdw; - inline vm::handler::profile_t nandq = - { - // MOV RAX, [RBP] - // MOV RDX, [RBP+8] - // NOT RAX - // NOT RDX - // AND RAX, RDX - // MOV [RBP], RAX - // PUSHFQ - // POP [RBP] - "NANDQ", NANDQ, NULL, - { - { - // MOV RAX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // MOV RDX, [RBP+8] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].mem.index == 0x8; - }, - // NOT RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_NOT && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX; - }, - // NOT RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_NOT && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RDX; - }, - // AND RAX, RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_AND && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; - }, - // MOV [RBP], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - }, - // PUSHFQ - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; - }, - // POP [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_POP && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; - } - } - } - }; + extern vm::handler::profile_t pushvsp; - inline vm::handler::profile_t jmp = - { - // MOV ESI, [RBP] - // ADD RSI, RAX - // MOV RBX, RSI - // ADD RSI, [RBP] - "JMP", JMP, NULL, - { - { - // MOV ESI, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_ESI && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // ADD RSI, RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RSI && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - }, - // MOV RBX, RSI - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RSI; - }, - // ADD RSI, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RSI && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - } - } - } - }; + extern vm::handler::profile_t addq; + extern vm::handler::profile_t adddw; - inline vm::handler::profile_t writeq = - { - // MOV RAX, [RBP] - // MOV RDX, [RBP+0x8] - // ADD RBP, 0x10 - // MOV [RAX], RDX - "WRITEQ", WRITEQ, NULL, - { - { - // MOV RAX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // MOV RDX, [RBP+0x8] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].mem.index == 0x8; - }, - // ADD RBP, 0x10 - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0x10; - }, - // MOV [RAX], RDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; - } - } - } - }; + extern vm::handler::profile_t nandq; + extern vm::handler::profile_t nanddw; - inline vm::handler::profile_t writedw = - { - // MOV RAX, [RBP] - // MOV EDX, [RBP+0x8] - // ADD RBP, 0xC - // MOV [RAX], EDX - "WRITEDW", WRITEDW, NULL, - { - { - // MOV RAX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // MOV EDX, [RBP+0x8] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_EDX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].mem.index == 0x8; - }, - // ADD RBP, 0xC - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_ADD && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && - instr.operands[1].imm.value.u == 0xC; - }, - // MOV [RAX], EDX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_EDX; - } - } - } - }; + extern vm::handler::profile_t mulq; + extern vm::handler::profile_t divq; + extern vm::handler::profile_t jmp; - inline vm::handler::profile_t readq = - { - // MOV RAX, [RBP] - // MOV RAX, [RAX] - // MOV [RBP], RAX - "READQ", READQ, NULL, - { - { - // MOV RAX, [RBP] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; - }, - // MOV RAX, [RAX] - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[1].mem.base == ZYDIS_REGISTER_RAX; - }, - // MOV [RBP], RAX - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && - instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; - } - } - } - }; + extern vm::handler::profile_t writeq; + extern vm::handler::profile_t writedw; - inline vm::handler::profile_t vmexit = - { - // MOV RAX, RBP - // POPFQ - // RET - "VMEXIT", VMEXIT, NULL, - { - { - // MOV RAX, RBP - [](const zydis_decoded_instr_t& instr) -> bool - { - return instr.mnemonic == ZYDIS_MNEMONIC_MOV && - instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && - instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && - instr.operands[1].reg.value == ZYDIS_REGISTER_RBP; - }, - // POPFQ - [](const zydis_decoded_instr_t& instr) -> bool - { return instr.mnemonic == ZYDIS_MNEMONIC_POPFQ; }, - // RET - [](const zydis_decoded_instr_t& instr) -> bool - { return instr.mnemonic == ZYDIS_MNEMONIC_RET; } - } - } - }; + extern vm::handler::profile_t readq; + extern vm::handler::profile_t vmexit; inline std::vector all = { @@ -1045,7 +120,7 @@ namespace vm &readq, - &nandq, + &nandq, &nanddw, &jmp, diff --git a/src/vmprofiler.vcxproj b/src/vmprofiler.vcxproj index b22d99f..407d106 100644 --- a/src/vmprofiler.vcxproj +++ b/src/vmprofiler.vcxproj @@ -102,6 +102,18 @@ + + + + + + + + + + + + diff --git a/src/vmprofiler.vcxproj.filters b/src/vmprofiler.vcxproj.filters index 31436fc..3dd0543 100644 --- a/src/vmprofiler.vcxproj.filters +++ b/src/vmprofiler.vcxproj.filters @@ -24,6 +24,9 @@ {a4d9e340-8f8c-4606-bce8-58b86119c829} + + {388154c1-cb08-493f-88fb-7e16cfffa010} + @@ -35,6 +38,42 @@ Source Files + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + + + Source Files\vmprofiles + diff --git a/src/vmprofiles/add.cpp b/src/vmprofiles/add.cpp new file mode 100644 index 0000000..9b848e2 --- /dev/null +++ b/src/vmprofiles/add.cpp @@ -0,0 +1,76 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t addq = + { + // ADD [RBP+8], RAX + // PUSHFQ + // POP [RBP] + "ADDQ", ADDQ, NULL, + { + { + // ADD [RBP+8], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + }, + // PUSHFQ + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; + }, + // POP [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_POP && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; + } + } + } + }; + + vm::handler::profile_t adddw = + { + // ADD [RBP+8], EAX + // PUSHFQ + // POP [RBP] + "ADDDW", ADDDW, NULL, + { + { + // ADD [RBP+8], EAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_EAX; + }, + // PUSHFQ + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; + }, + // POP [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_POP && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/div.cpp b/src/vmprofiles/div.cpp new file mode 100644 index 0000000..1e53563 --- /dev/null +++ b/src/vmprofiles/div.cpp @@ -0,0 +1,85 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t divq = + { + // MOV RDX, [RBP] + // MOV RAX, [RBP+0x8] + // DIV [RBP+0x10] + // MOV [RBP+0x8], RDX + // MOV [RBP+0x10], RAX + // PUSHFQ + // POP [RBP] + "DIVQ", DIVQ, NULL, + { + { + // MOV RDX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // MOV RAX, [RBP+0x8] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].mem.index == 0x8; + }, + // DIV [RBP+0x10] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_DIV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[0].mem.index == 0x10; + }, + // MOV [RBP+0x8], RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[0].mem.index == 0x8 && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; + }, + // MOV [RBP+0x10], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[0].mem.index == 0x10 && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + }, + // PUSHFQ + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; + }, + // POP [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_POP && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/jmp.cpp b/src/vmprofiles/jmp.cpp new file mode 100644 index 0000000..9aca0db --- /dev/null +++ b/src/vmprofiles/jmp.cpp @@ -0,0 +1,59 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t jmp = + { + // MOV ESI, [RBP] + // ADD RSI, RAX + // MOV RBX, RSI + // ADD RSI, [RBP] + "JMP", JMP, NULL, + { + { + // MOV ESI, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_ESI && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // ADD RSI, RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RSI && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + }, + // MOV RBX, RSI + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RSI; + }, + // ADD RSI, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RSI && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/lconst.cpp b/src/vmprofiles/lconst.cpp new file mode 100644 index 0000000..83991f2 --- /dev/null +++ b/src/vmprofiles/lconst.cpp @@ -0,0 +1,205 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t lconstq = + { + // MOV RAX, [RSI] + // SUB RBP, 8 + // MOV [RBP], RAX + "LCONSTQ", LCONSTQ, 64, + { + { + // SUB RBP, 8 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x8; + }, + // MOV [RBP], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + } + } + } + }; + + vm::handler::profile_t lconstbzxw = + { + // MOV AL, [RSI] + // SUB RBP, 2 + // MOV [RBP], AX + "LCONSTBZXW", LCONSTBZXW, 8, + { + { + // SUB RBP, 2 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x2; + }, + // MOV [RBP], AX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_AX; + } + } + } + }; + + vm::handler::profile_t lconstbsxdw = + { + // CWDE + // SUB RBP, 4 + // MOV [RBP], EAX + "LCONSTBSXDW", LCONSTBSXDW, 8, + { + { + // CWDE + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_CWDE; + }, + // SUB RBP, 4 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x4; + }, + // MOV [RBP], EAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_EAX; + } + } + }, + vm::handler::extention_t::sign_extend + }; + + vm::handler::profile_t lconstdwsxq = + { + // CDQE + // SUB RBP, 8 + // MOV [RBP], RAX + "LCONSTDWSXQ", LCONSTDWSXQ, 32, + { + // CDQE + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_CDQE; + }, + // SUB RBP, 8 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x8; + }, + // MOV [RBP], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + } + }, + vm::handler::extention_t::sign_extend + }; + + vm::handler::profile_t lconstwsxq = + { + // CDQE + // SUB RBP, 8 + // MOV [RBP], RAX + "LCONSTWSXQ", LCONSTWSXQ, 16, + { + { + // CDQE + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_CDQE; + }, + // SUB RBP, 8 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x8; + }, + // MOV [RBP], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + } + } + }, + vm::handler::extention_t::sign_extend + }; + + vm::handler::profile_t lconstdw = + { + // SUB RBP, 4 + // MOV [RBP], EAX + "LCONSTDW", LCONSTDW, 32, + { + { + // SUB RBP, 4 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x4; + }, + // MOV [RBP], EAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_EAX; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/lreg.cpp b/src/vmprofiles/lreg.cpp new file mode 100644 index 0000000..847e598 --- /dev/null +++ b/src/vmprofiles/lreg.cpp @@ -0,0 +1,95 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t lregq = + { + // MOV RDX, [RAX+RDI] + // SUB RBP, 8 + // MOV [RBP], RDX + "LREGQ", LREGQ, 8, + { + { + // MOV RDX, [RAX+RDI] or MOV RDX, [RDI+RAX] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + (instr.operands[1].mem.base == ZYDIS_REGISTER_RAX || + instr.operands[1].mem.base == ZYDIS_REGISTER_RDI) && + (instr.operands[1].mem.index == ZYDIS_REGISTER_RDI || + instr.operands[1].mem.index == ZYDIS_REGISTER_RAX); + }, + // SUB RBP, 8 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x8; + }, + // MOV [RBP], RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; + } + } + } + }; + + vm::handler::profile_t lregdw = + { + // MOVZX AL, [RSI] + // MOV RDX, [RAX + RDI] + // SUB RBP, 0x4 + // MOV [RBP], EDX + "LREGDW", LREGDW, 8, + { + { + // MOV RDX, [RAX + RDI] or MOV RDX, [RDI + RAX] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_EDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + (instr.operands[1].mem.base == ZYDIS_REGISTER_RAX || + instr.operands[1].mem.base == ZYDIS_REGISTER_RDI) && + (instr.operands[1].mem.index == ZYDIS_REGISTER_RAX || + instr.operands[1].mem.index == ZYDIS_REGISTER_RDI); + }, + // SUB RBP, 0x4 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x4; + }, + // MOV [RBP], EDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_EDX; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/mul.cpp b/src/vmprofiles/mul.cpp new file mode 100644 index 0000000..6b73a40 --- /dev/null +++ b/src/vmprofiles/mul.cpp @@ -0,0 +1,84 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t mulq = + { + // MOV RAX, [RBP+0x8] + // SUB RBP, 0x8 + // MUL RDX + // MOV [RBP+0x8], RDX + // MOV [RBP+0x10], RAX + // PUSHFQ + // POP [RBP] + "MULQ", MULQ, NULL, + { + { + // MOV RAX, [RBP+0x8] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].mem.index == 0x8; + }, + // SUB RBP, 0x8 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x8; + }, + // MUL RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MUL && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RDX; + }, + // MOV [RBP+0x8], RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[0].mem.index == 0x8 && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; + }, + // MOV [RBP+0x10], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[0].mem.index == 0x10 && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + }, + // PUSHFQ + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; + }, + // POP [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_POP && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/nand.cpp b/src/vmprofiles/nand.cpp new file mode 100644 index 0000000..0934e20 --- /dev/null +++ b/src/vmprofiles/nand.cpp @@ -0,0 +1,153 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t nandq = + { + // MOV RAX, [RBP] + // MOV RDX, [RBP+8] + // NOT RAX + // NOT RDX + // AND RAX, RDX + // MOV [RBP], RAX + // PUSHFQ + // POP [RBP] + "NANDQ", NANDQ, NULL, + { + { + // MOV RAX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // MOV RDX, [RBP+8] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].mem.index == 0x8; + }, + // NOT RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_NOT && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX; + }, + // NOT RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_NOT && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RDX; + }, + // AND RAX, RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_AND && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; + }, + // MOV [RBP], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + }, + // PUSHFQ + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; + }, + // POP [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_POP && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; + } + } + } + }; + + vm::handler::profile_t nanddw = + { + // NOT DWORD PTR [RBP] + // MOV AX, [RBP] + // SUB RBP, 0x6 + // AND [RBP+0x8], AX + // PUSHFQ + // POP [RBP] + "NANDDW", NANDDW, NULL, + { + { + // NOT DWORD PTR [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_NOT && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].size == 32 && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; + }, + // MOV AX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_AX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // SUB RBP, 0x6 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x6; + }, + // AND [RBP+0x8], AX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_AND && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[0].mem.index == 0x8 && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_AX; + }, + // PUSHFQ + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_PUSHFQ; + }, + // POP [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_POP && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/pushvsp.cpp b/src/vmprofiles/pushvsp.cpp new file mode 100644 index 0000000..56e2d08 --- /dev/null +++ b/src/vmprofiles/pushvsp.cpp @@ -0,0 +1,48 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t pushvsp = + { + // MOV RAX, RBP + // SUB RBP, 8 + "PUSHVSP", PUSHVSP, NULL, + { + { + // MOV RAX, RBP + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RBP; + }, + // SUB RBP, 8 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_SUB && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x8; + }, + // MOV [RBP], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/read.cpp b/src/vmprofiles/read.cpp new file mode 100644 index 0000000..0d8570e --- /dev/null +++ b/src/vmprofiles/read.cpp @@ -0,0 +1,49 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t readq = + { + // MOV RAX, [RBP] + // MOV RAX, [RAX] + // MOV [RBP], RAX + "READQ", READQ, NULL, + { + { + // MOV RAX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // MOV RAX, [RAX] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RAX; + }, + // MOV [RBP], RAX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RAX; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/sreg.cpp b/src/vmprofiles/sreg.cpp new file mode 100644 index 0000000..4ff111c --- /dev/null +++ b/src/vmprofiles/sreg.cpp @@ -0,0 +1,136 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t sregq = + { + // MOV RDX, [RBP] + // ADD RBP, 8 + // MOV [RAX+RDI], RDX + "SREGQ", SREGQ, 8, + { + { + // MOV RDX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // ADD RBP, 8 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 8; + }, + // MOV [RAX+RDI], RDX or MOV [RDI+RAX], RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + (instr.operands[0].mem.base == ZYDIS_REGISTER_RAX || + instr.operands[0].mem.base == ZYDIS_REGISTER_RDI) && + (instr.operands[0].mem.index == ZYDIS_REGISTER_RDI || + instr.operands[0].mem.index == ZYDIS_REGISTER_RAX) && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; + } + } + } + }; + + vm::handler::profile_t sregdw = + { + // MOV EDX, [RBP] + // ADD RBP, 0x4 + // MOV [RAX+RDI], EDX + "SREGDW", SREGDW, 8, + { + { + // MOV EDX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_EDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // ADD RBP, 0x4 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x4; + }, + // MOV [RAX+RDI], EDX or MOV [RDI+RAX], EDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + (instr.operands[0].mem.base == ZYDIS_REGISTER_RAX || + instr.operands[0].mem.base == ZYDIS_REGISTER_RDI) && + (instr.operands[0].mem.index == ZYDIS_REGISTER_RAX || + instr.operands[0].mem.index == ZYDIS_REGISTER_RDI) && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_EDX; + } + } + } + }; + + vm::handler::profile_t sregw = + { + // MOV DX, [RBP] + // ADD RBP, 0x2 + // MOV [RAX+RDI], DX + "SREGW", SREGW, 8, + { + { + // MOV DX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_DX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // ADD RBP, 0x2 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x2; + }, + // MOV [RAX+RDI], DX or MOV [RDI+RAX], DX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + (instr.operands[0].mem.base == ZYDIS_REGISTER_RAX || + instr.operands[0].mem.base == ZYDIS_REGISTER_RDI) && + (instr.operands[0].mem.index == ZYDIS_REGISTER_RDI || + instr.operands[0].mem.index == ZYDIS_REGISTER_RAX) && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_DX; + } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/vmexit.cpp b/src/vmprofiles/vmexit.cpp new file mode 100644 index 0000000..f7d9825 --- /dev/null +++ b/src/vmprofiles/vmexit.cpp @@ -0,0 +1,37 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t vmexit = + { + // MOV RAX, RBP + // POPFQ + // RET + "VMEXIT", VMEXIT, NULL, + { + { + // MOV RAX, RBP + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RBP; + }, + // POPFQ + [](const zydis_decoded_instr_t& instr) -> bool + { return instr.mnemonic == ZYDIS_MNEMONIC_POPFQ; }, + // RET + [](const zydis_decoded_instr_t& instr) -> bool + { return instr.mnemonic == ZYDIS_MNEMONIC_RET; } + } + } + }; + } + } +} \ No newline at end of file diff --git a/src/vmprofiles/write.cpp b/src/vmprofiles/write.cpp new file mode 100644 index 0000000..cf4044d --- /dev/null +++ b/src/vmprofiles/write.cpp @@ -0,0 +1,110 @@ +#include "../../include/vmprofiler.hpp" + +namespace vm +{ + namespace handler + { + namespace profile + { + vm::handler::profile_t writeq = + { + // MOV RAX, [RBP] + // MOV RDX, [RBP+0x8] + // ADD RBP, 0x10 + // MOV [RAX], RDX + "WRITEQ", WRITEQ, NULL, + { + { + // MOV RAX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // MOV RDX, [RBP+0x8] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].mem.index == 0x8; + }, + // ADD RBP, 0x10 + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0x10; + }, + // MOV [RAX], RDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_RDX; + } + } + } + }; + + vm::handler::profile_t writedw = + { + // MOV RAX, [RBP] + // MOV EDX, [RBP+0x8] + // ADD RBP, 0xC + // MOV [RAX], EDX + "WRITEDW", WRITEDW, NULL, + { + { + // MOV RAX, [RBP] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP; + }, + // MOV EDX, [RBP+0x8] + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_EDX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[1].mem.base == ZYDIS_REGISTER_RBP && + instr.operands[1].mem.index == 0x8; + }, + // ADD RBP, 0xC + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_ADD && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[0].reg.value == ZYDIS_REGISTER_RBP && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_IMMEDIATE && + instr.operands[1].imm.value.u == 0xC; + }, + // MOV [RAX], EDX + [](const zydis_decoded_instr_t& instr) -> bool + { + return instr.mnemonic == ZYDIS_MNEMONIC_MOV && + instr.operands[0].type == ZYDIS_OPERAND_TYPE_MEMORY && + instr.operands[0].mem.base == ZYDIS_REGISTER_RAX && + instr.operands[1].type == ZYDIS_OPERAND_TYPE_REGISTER && + instr.operands[1].reg.value == ZYDIS_REGISTER_EDX; + } + } + } + }; + } + } +} \ No newline at end of file