Created
January 12, 2025 13:50
-
-
Save CodeCouturiers/e194e336475383715acc02b8eeecc2e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "hokk.hpp" | |
using memcmp_t = int(__cdecl*)(const void* buf1, const void* buf2, size_t count); | |
int __cdecl hk_memcmp(const void* buf1, const void* buf2, size_t count) { | |
printf("[DEBUG] Hook called!\n"); | |
printf("[DEBUG] First buffer: %.*s\n", (int)count, (char*)buf1); | |
printf("[DEBUG] Second buffer: %.*s\n", (int)count, (char*)buf2); | |
printf("[DEBUG] Compare length: %zu\n", count); | |
printf("[DEBUG] Returning 0 (success)\n"); | |
return 0; | |
} | |
int main() { | |
printf("[DEBUG] Getting memcmp address...\n"); | |
auto memcmp_addr = reinterpret_cast<void*>(&memcmp); | |
printf("[DEBUG] memcmp address: %p\n", memcmp_addr); | |
printf("[DEBUG] Installing hook...\n"); | |
if (hk::instant(memcmp_addr, &hk_memcmp)) { | |
printf("[DEBUG] Hook installed successfully!\n"); | |
// Verify hook is active | |
if (hk::status(memcmp_addr)) { | |
printf("[DEBUG] Hook status verification: ACTIVE\n"); | |
} | |
else { | |
printf("[DEBUG] Hook status verification: INACTIVE!\n"); | |
return 1; | |
} | |
} | |
else { | |
printf("[DEBUG] Failed to install hook!\n"); | |
return 1; | |
} | |
char input[32]; | |
printf("\nEnter any password (it will work): "); | |
scanf_s("%31s", input, (unsigned)_countof(input)); | |
printf("\n[DEBUG] Testing hook with input...\n"); | |
// Test with different lengths and strings | |
printf("\n[DEBUG] Test 1 - comparing with 'anything'...\n"); | |
if (memcmp(input, "anything", 8) == 0) { | |
printf("[DEBUG] Test 1 passed - hook worked!\n"); | |
} | |
printf("\n[DEBUG] Test 2 - comparing with different string...\n"); | |
if (memcmp(input, "different_test", 13) == 0) { | |
printf("[DEBUG] Test 2 passed - hook worked!\n"); | |
} | |
printf("\n[DEBUG] Removing hook...\n"); | |
if (hk::destroy(memcmp_addr)) { | |
printf("[DEBUG] Hook removed successfully\n"); | |
// Verify hook is removed | |
if (!hk::status(memcmp_addr)) { | |
printf("[DEBUG] Hook status verification after removal: INACTIVE\n"); | |
} | |
else { | |
printf("[DEBUG] Warning: Hook still appears active after removal!\n"); | |
} | |
} | |
else { | |
printf("[DEBUG] Failed to remove hook!\n"); | |
} | |
// Test original behavior is restored | |
printf("\n[DEBUG] Testing original memcmp after hook removal...\n"); | |
if (memcmp("test1", "test2", 5) != 0) { | |
printf("[DEBUG] Original memcmp behavior verified - strings don't match\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment