Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
RenardDev authored Sep 18, 2024
1 parent 15be6fa commit 9da721b
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,49 +1767,74 @@ TEST_SUITE("Detours::Hook") {
void* pData = Page.Alloc(Page.GetPageCapacity());
CHECK(pData != nullptr);

static const unsigned int pSourceArray[] = {
static const unsigned int pSourceMultiArray[] = {
1, 2, 3, 4, 5, 0, // first array
1, 2, 3, 4, 5, 6, 0 // second array
};

memcpy(pData, pSourceArray, sizeof(pSourceArray));
memcpy(pData, pSourceMultiArray, sizeof(pSourceMultiArray));

printf("Before MemoryHook:\n");

printf("\n");
for (unsigned int i = 0; reinterpret_cast<unsigned int*>(pData)[i] != 0; ++i) {
printf("pData[%02X] (FIRST ARRAY) = 0x%08X\n", i, reinterpret_cast<unsigned int*>(pData)[i]);

unsigned int* pMultiArrays = reinterpret_cast<unsigned int*>(pData);
unsigned int unCount = 0;
unsigned int unValue = 0;
while ((unValue = pMultiArrays[unCount]) != 0) {
printf("pData[%02X] (FIRST ARRAY) = 0x%08X\n", unCount, unValue);
++unCount;
}

printf("\n");
for (unsigned int i = 6; reinterpret_cast<unsigned int*>(pData)[i] != 0; ++i) {
printf("pData[%02X] (SECOND ARRAY) = 0x%08X\n", i, reinterpret_cast<unsigned int*>(pData)[i]);

unCount = 0;
unValue = 0;
while ((unValue = pMultiArrays[unCount]) != 0) {
printf("pData[%02X] (SECOND ARRAY) = 0x%08X\n", unCount, unValue);
++unCount;
}

CHECK(Detours::Hook::HookMemory(MemoryArrayHook, &reinterpret_cast<unsigned int*>(pData)[5], sizeof(int) * 11) == true);

printf("\nAfter MemoryHook:\n");

printf("\n");
for (unsigned int i = 0; reinterpret_cast<unsigned int*>(pData)[i] != 0; ++i) {
printf("pData[%02X] (FIRST ARRAY) = 0x%08X\n", i, reinterpret_cast<unsigned int*>(pData)[i]);

unCount = 0;
unValue = 0;
while ((unValue = pMultiArrays[unCount]) != 0) {
printf("pData[%02X] (FIRST ARRAY) = 0x%08X\n", unCount, unValue);
++unCount;
}

printf("\n");
for (unsigned int i = 6; reinterpret_cast<unsigned int*>(pData)[i] != 0; ++i) {
printf("pData[%02X] (SECOND ARRAY) = 0x%08X\n", i, reinterpret_cast<unsigned int*>(pData)[i]);

unCount = 0;
unValue = 0;
while ((unValue = pMultiArrays[unCount]) != 0) {
printf("pData[%02X] (SECOND ARRAY) = 0x%08X\n", unCount, unValue);
++unCount;
}

printf("\nAfter MemoryHook #2:\n");

printf("\n");
for (unsigned int i = 0; reinterpret_cast<unsigned int*>(pData)[i] != 0; ++i) {
printf("pData[%02X] (FIRST ARRAY) = 0x%08X\n", i, reinterpret_cast<unsigned int*>(pData)[i]);

unCount = 0;
unValue = 0;
while ((unValue = pMultiArrays[unCount]) != 0) {
printf("pData[%02X] (FIRST ARRAY) = 0x%08X\n", unCount, unValue);
++unCount;
}

printf("\n");
for (unsigned int i = 6; reinterpret_cast<unsigned int*>(pData)[i] != 0; ++i) {
printf("pData[%02X] (SECOND ARRAY) = 0x%08X\n", i, reinterpret_cast<unsigned int*>(pData)[i]);

unCount = 0;
unValue = 0;
while ((unValue = pMultiArrays[unCount]) != 0) {
printf("pData[%02X] (SECOND ARRAY) = 0x%08X\n", unCount, unValue);
++unCount;
}

CHECK(Detours::Hook::UnHookMemory(MemoryArrayHook) == true);
Expand Down

0 comments on commit 9da721b

Please sign in to comment.