привет, надо хукнуть функцию по патерну вот моя попытка которая к нечему не привела if (MH_CreateHook(PatternScan(GetModuleHandleA("hack.dll"), "55 8B ? ? 50 83 EC 44 A1 ? ? ? ? 33 C5 89 45 F0 50 "), &gggg, (LPVOID*)NULL) != MH_OK) { MessageBoxA(0, "Pizda rulu", "Error", 0); return FALSE; } C if (MH_CreateHook(PatternScan(GetModuleHandleA("hack.dll"), "55 8B ? ? 50 83 EC 44 A1 ? ? ? ? 33 C5 89 45 F0 50 "), &gggg, (LPVOID*)NULL) != MH_OK) { MessageBoxA(0, "Pizda rulu", "Error", 0); return FALSE; } std::uint8_t* PatternScan(void* module, const char* signature) { static auto pattern_to_byte = [](const char* pattern) { auto bytes = std::vector<int>{}; auto start = const_cast<char*>(pattern); auto end = const_cast<char*>(pattern) + strlen(pattern); for (auto current = start; current < end; ++current) { if (*current == '?') { ++current; if (*current == '?') ++current; bytes.push_back(-1); } else { bytes.push_back(strtoul(current, ¤t, 16)); } } return bytes; }; auto dosHeader = (PIMAGE_DOS_HEADER)module; auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)module + dosHeader->e_lfanew); auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage; auto patternBytes = pattern_to_byte(signature); auto scanBytes = reinterpret_cast<std::uint8_t*>(module); auto s = patternBytes.size(); auto d = patternBytes.data(); for (auto i = 0ul; i < sizeOfImage - s; ++i) { bool found = true; for (auto j = 0ul; j < s; ++j) { if (scanBytes[i + j] != d[j] && d[j] != -1) { found = false; break; } } if (found) { return &scanBytes[i]; } } return nullptr; } C std::uint8_t* PatternScan(void* module, const char* signature) { static auto pattern_to_byte = [](const char* pattern) { auto bytes = std::vector<int>{}; auto start = const_cast<char*>(pattern); auto end = const_cast<char*>(pattern) + strlen(pattern); for (auto current = start; current < end; ++current) { if (*current == '?') { ++current; if (*current == '?') ++current; bytes.push_back(-1); } else { bytes.push_back(strtoul(current, ¤t, 16)); } } return bytes; }; auto dosHeader = (PIMAGE_DOS_HEADER)module; auto ntHeaders = (PIMAGE_NT_HEADERS)((std::uint8_t*)module + dosHeader->e_lfanew); auto sizeOfImage = ntHeaders->OptionalHeader.SizeOfImage; auto patternBytes = pattern_to_byte(signature); auto scanBytes = reinterpret_cast<std::uint8_t*>(module); auto s = patternBytes.size(); auto d = patternBytes.data(); for (auto i = 0ul; i < sizeOfImage - s; ++i) { bool found = true; for (auto j = 0ul; j < s; ++j) { if (scanBytes[i + j] != d[j] && d[j] != -1) { found = false; break; } } if (found) { return &scanBytes[i]; } } return nullptr; }
здарова бро покажи на что идёт указатель &gggg, мне не совсем ясно а так в принципе твой код выглядит более чем правильно, но вопрос выше остается актуальным попробуй добавить проверку на нулевой указатель // тут вероятнее всего твой gggg void gggg() { // код этого указателя } if (auto module = GetModuleHandleA("hack.dll")) { if (MH_CreateHook(PatternScan(module, "55 8B ? ? 50 83 EC 44 A1 ? ? ? ? 33 C5 89 45 F0 50 "), &gggg, nullptr) == MH_OK) { MH_EnableHook(MH_ALL_HOOKS); // poebota } else { MessageBoxA(0, "пизда, хук не создался", "Error", 0); } } else { MessageBoxA(0, "нет нахуй дескриптора, иди нахуй", "Error", 0); } C // тут вероятнее всего твой gggg void gggg() { // код этого указателя } if (auto module = GetModuleHandleA("hack.dll")) { if (MH_CreateHook(PatternScan(module, "55 8B ? ? 50 83 EC 44 A1 ? ? ? ? 33 C5 89 45 F0 50 "), &gggg, nullptr) == MH_OK) { MH_EnableHook(MH_ALL_HOOKS); // poebota } else { MessageBoxA(0, "пизда, хук не создался", "Error", 0); } } else { MessageBoxA(0, "нет нахуй дескриптора, иди нахуй", "Error", 0); }
какая именно проблема у тебя возникает при хуке функции по паттерну? есть ли какие-то конкретные ошибки или просто не получается получить адрес функции?