15 const size_t instr_size = 2;
16 if (!peconv::validate_ptr(this->patchedCode, this->codeSize, patch_ptr, instr_size)) {
19 BYTE *lval = (BYTE*)((ULONGLONG)patch_ptr + 1);
20 ULONGLONG addr = getJmpDestAddr<BYTE>(patch_va, instr_size, (*lval));
28 const size_t instr_size = 5;
29 if (!peconv::validate_ptr(this->patchedCode, this->codeSize, patch_ptr, instr_size)) {
32 DWORD *lval = (DWORD*)((ULONGLONG) patch_ptr + 1);
33 ULONGLONG addr = getJmpDestAddr<DWORD>(patch_va, instr_size, (*lval));
57 size_t mov_instr_len = is_long ? 9 : 5;
58 if (!peconv::validate_ptr(this->patchedCode, this->codeSize, patch_ptr, mov_instr_len + 2)) {
62 PBYTE jmp_ptr = patch_ptr + mov_instr_len;
63 if (is64Modifier(*patch_ptr)) {
69 DWORD reg_id0 = patch_ptr[0] - 0xB8;
72 if (is64Modifier(*jmp_ptr)) {
76 if (!peconv::validate_ptr(this->patchedCode, this->codeSize, jmp_ptr, 2)) {
80 if (jmp_ptr[0] == 0xFF && jmp_ptr[1] >= 0xE0 && jmp_ptr[1] <= 0xEF ) {
82 reg_id1 = jmp_ptr[1] - 0xE0;
83 }
else if (jmp_ptr[0] == 0xFF && jmp_ptr[1] >= 0xD0 && jmp_ptr[1] <= 0xDF ) {
85 reg_id1 = jmp_ptr[1] - 0xD0;
88 std::cerr <<
"It is not MOV->JMP" << std::hex << (DWORD)jmp_ptr[0] << std::endl;
93 if (reg_id1 != reg_id0) {
95 std::cerr <<
"MOV->JMP : reg mismatch" << std::endl;
99 size_t patch_size = mov_instr_len;
100 ULONGLONG addr = NULL;
102 DWORD *lval = (DWORD*)((ULONGLONG) patch_ptr + 1);
105 ULONGLONG *lval = (ULONGLONG*)((ULONGLONG) patch_ptr + 1);
111 std::cout <<
"----> Target: " << std::hex << addr << std::endl;
152 BYTE op = patch_ptr[0];
153 if (op == OP_JMP || op == OP_CALL_DWORD) {
154 return parseJmp(patch, patch_ptr, patch_va);
156 if (op == OP_SHORTJMP) {
157 return parseShortJmp(patch, patch_ptr, patch_va);
159 if (op == OP_PUSH_DWORD) {
160 return parsePushRet(patch, patch_ptr);
162 if (op == OP_JMP_VIA_ADDR_B1 && patch_ptr[1] == OP_JMP_VIA_ADDR_B2) {
163 return parseJmpViaAddr(patch, patch_ptr, patch_va);
166 bool is_long =
false;
167 if (is64Modifier(op)) {
168 if (isLongModifier(op)) {
174 if (op >= 0xB8 && op <= 0xBF) {
175 return parseMovJmp(patch, patch_ptr, is_long);
182 if (this->relocs.find(patch.
startRva) == this->relocs.end()) {
186 const size_t fieldSize = (this->moduleData.is64bit()) ?
sizeof(ULONGLONG) :
sizeof(DWORD);
187 if (!peconv::validate_ptr(this->patchedCode, this->codeSize, patch_ptr, fieldSize)) {
190 ULONGLONG field = (this->moduleData.is64bit()) ? *((ULONGLONG*)patch_ptr) : *((DWORD*)patch_ptr);
224 const ULONGLONG patch_va = moduleData.rvaToVa(patch.
startRva);
225 const size_t patch_offset = patch.
startRva - sectionRVA;
226 BYTE* patch_ptr = this->patchedCode + patch_offset;
228 size_t size = _analyzeRelocated(patch, patch_ptr);
232 const size_t kMinSize = 3;
233 if (!peconv::validate_ptr(this->patchedCode, this->codeSize, patch_ptr, kMinSize)) {
236 size = _analyzeHook(patch, patch_ptr, patch_va);
237 if (size == 0 && patch_offset > 0) {
240 size = _analyzeHook(patch, patch_ptr -1, patch_va - 1);