Fix advanced memory search wrong results

This commit is contained in:
BullyWiiPlaza 2018-01-26 14:43:00 +01:00
parent 6b23b17d11
commit 45c4df406f
5 changed files with 19 additions and 6 deletions

View File

@ -184,7 +184,7 @@ void setDataBreakpoint(int address, bool read, bool write) {
// log_print("Setting DABR...\n"); // log_print("Setting DABR...\n");
OSSetDABR(1, address, read, write); OSSetDABR(1, address, read, write);
// log_print("DABR set\n"); // log_print("DABR set\n");
int enabled = OSIsInterruptEnabled(); // int enabled = OSIsInterruptEnabled();
// log_printf("Interrupts enabled: %i\n", enabled); // log_printf("Interrupts enabled: %i\n", enabled);
} }

View File

@ -99,7 +99,6 @@ int kernelMemoryCompare(const char *sourceBuffer,
} }
bool loopEntered = false; bool loopEntered = false;
while (kern_read(sourceBuffer) == kern_read(destinationBuffer)) { while (kern_read(sourceBuffer) == kern_read(destinationBuffer)) {
loopEntered = true; loopEntered = true;
sourceBuffer = (char *) sourceBuffer + KERNEL_MEMORY_COMPARE_STEP_SIZE; sourceBuffer = (char *) sourceBuffer + KERNEL_MEMORY_COMPARE_STEP_SIZE;

View File

@ -1252,12 +1252,14 @@ static int processCommands(struct pygecko_bss_t *bss, int clientfd) {
int comparisonResult; int comparisonResult;
if (kernelRead) { if (kernelRead) {
comparisonResult = kernelMemoryCompare((char *) currentAddress, searchBytes, searchBytesCount); comparisonResult = kernelMemoryCompare((char *) currentAddress,
searchBytes, searchBytesCount);
} else { } else {
comparisonResult = memcmp((void *) currentAddress, searchBytes, searchBytesCount); comparisonResult = memoryCompare((void *) currentAddress,
searchBytes, (size_t) searchBytesCount);
} }
if (comparisonResult == 0) { if (comparisonResult == 0) {
// Search bytes have been found // Search bytes have been found, add the addresses to the return buffer
((int *) buffer)[1 + searchBytesOccurrences] = currentAddress; ((int *) buffer)[1 + searchBytesOccurrences] = currentAddress;
searchBytesOccurrences++; searchBytesOccurrences++;

View File

@ -4,6 +4,7 @@
#include "../dynamic_libs/os_functions.h" #include "../dynamic_libs/os_functions.h"
#include "../utils/logger.h" #include "../utils/logger.h"
#include "kernel.h" #include "kernel.h"
#include <stddef.h> /* size_t */
void writeCode(u32 address, u32 instruction) { void writeCode(u32 address, u32 instruction) {
u32 *pointer = (u32 *) (address + 0xA0000000); u32 *pointer = (u32 *) (address + 0xA0000000);
@ -20,4 +21,15 @@ void patchFunction(char *function, char *patchBytes, unsigned int patchBytesSize
log_print("Successfully patched!\n"); log_print("Successfully patched!\n");
} }
int memoryCompare(const void *s1, const void *s2, size_t n) {
const unsigned char *p1 = static_cast<const unsigned char *>(s1);
const unsigned char *p2 = static_cast<const unsigned char *>(s2);
while (n--)
if (*p1 != *p2)
return *p1 - *p2;
else
p1++, p2++;
return 0;
}
#endif #endif

Binary file not shown.