SolvedDLL Memory scan not working

Posts 1–2 of 2 · Page 1 of 1
DLL Memory scan not working
main.cpp
Code:
#include "memlib.h"

bool Done = false;

DWORD Run(){
	if (Done == true){
		return 0;
	}
	BYTE b1[4] = { 0x48, 0x65, 0x61, 0x64 };
	BYTE b2[4] = { 0x44, 0x65, 0x61, 0x64 };
	AOBSwap(b1, b2, 4);
	Done = true;
	return 0;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved){
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Run, 0, 0, 0);
		break;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
memlib.h
Code:
#include<iostream>
#include<Windows.h>
#include<vector>
#include<streambuf>

int start = 0x01000000;
int end = 0x70000000;

/*bool Compare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
	for (; *szMask; ++szMask, ++pData, ++bMask)
		if (*szMask == 'x' && *pData != *bMask)   return 0;
	return (*szMask) == NULL;
}
DWORD Pattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char * szMask)
{
	for (DWORD i = 0; i < dwLen; i++)
		if (Compare((BYTE*)(dwAddress + i), bMask, szMask))  return (DWORD)(dwAddress + i);
	return 0;
}*/

void WriteString(int adr, std::string newvalue){
	memcpy((void*)adr, (void*)&newvalue, sizeof(newvalue));
}

void WriteInt(int adr, int newvalue){
	memcpy((void*)adr, (void*)&newvalue, sizeof(newvalue));
}

void WriteFloat(int adr, float newvalue){
	memcpy((void*)adr, (void*)&newvalue, sizeof(newvalue));
}

void WriteDouble(int adr, float newvalue){
	memcpy((void*)adr, (void*)&newvalue, sizeof(newvalue));
}

void WriteBytes(int adr, int newvalue, int numofbytes){
	memcpy((void*)adr, (void*)newvalue, numofbytes * sizeof(BYTE));
}

std::string ReadString(int adr){
	std::string readvalue;
	memcpy((void*)&readvalue, (void*)adr, sizeof(&adr));
	return readvalue;
}

int ReadInt(int adr){
	int readvalue;
	memcpy((void*)&readvalue, (void*)adr, sizeof(&adr));
	return readvalue;
}

float ReadFloat(int adr){
	float readvalue = adr;
	memcpy((void*)&readvalue, (void*)adr, sizeof(&adr));
	return readvalue;
}

double ReadDouble(int adr){
	double readvalue = adr;
	memcpy((void*)&readvalue, (void*)adr, sizeof(&adr));
	return readvalue;
}

BYTE ReadBytes(int adr){
	BYTE *ptr = (BYTE*)adr;
	return *ptr;
}

void StringSwap(std::string searching, std::string replacement){
	int times = 0;
	int found = 0;
	int a = start;
	while (true){
		if (a >= end)
			break;
		a = a + 1;
		if (times >= 10){
			times = 0;
			Sleep(1);
		}
		std::string result = ReadString(a);
		if (result.find(searching) != std::string::npos){
			result.replace(result.find(searching), searching.length(), replacement);
			WriteString(a, result);
			found++;
		}
		times++;
	}
}

void AOBSwap(BYTE b1[],BYTE b2[], int sizeofarr){
	int times = 0;
	int found = 0;
	int a = start;
	while (true){
		if (a >= end)
			break;
		a = a + 1;
		if (times >= 10){
			times = 0;
			Sleep(1);
		}
		BYTE* result = (BYTE*)ReadBytes(a);
		for (int i = 0; i < 16; i++){
			if (result[i] == b1[0]){
				bool ok = true;
				for (int x = 0; x < sizeofarr; i++){
					if (result[i] != b1[x]){
						ok = false;
					}
				}
				if (ok == true){
					BYTE newb[16];
					int x = 0;
					for (int i = 0; i < 16; i++){
						if (result[i] != b1[i])
							newb[i] = result[i];
						else{
							newb[i] = b2[x];
							x++;
						}
					}
					WriteBytes(a, (int)&newb, 16);
				}
			}
		}
		times++;
	}
}
The problem is when I use AOBSwap or StringSwap they only replace 1 but they don't replace the rest. These function should search for the values that should be replaced once they are found, they get replaced.
These 2 functions are in memlib.h. If you can only help me with 1 function I would be really happy, I am trying to fix them for about 1-3 hours..
Then how about you do a repeated check for that?

while( ResultsFound )
replaceStuff();
Posts 1–2 of 2 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us