name in textbox help

hello i'm trying to make a name grabber for a game. the name is supposed to show in the textbox once the game is open. i am able to make the amount of money i have in the textbox but i am having trouble making it show a name in the textbox

Memory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#include <Windows.h>
#include <vector>

#define ROUND_UP(p, align)   (((DWORD)(p) + (align)-1) & ~((align)-1))
#define ROUND_DOWN(p, align) ((DWORD)(p) & ~((align)-1))

class Memory {
public:
	Memory();
	~Memory();
public:
	int _stdcall WriteMemory(void* pvAddress, void* pvWriteBuffer, size_t Size);
	ULONG_PTR ReadPtr(DWORD dwBase, INT iOffset);
	std::string ReadStr(DWORD dwBase, INT iOffset);
	BOOL WritePtr(unsigned long ulBase, INT iOffset, int iValue);
	BOOL WriteStr(unsigned long ulBase, INT iOffset, std::string sValue);
public:
	class Pointer {
	private:
		ULONG_PTR* mBase;
		std::vector< INT > mvOffsets;
	public:
		//CONSTRUCTORS
		Pointer();
		Pointer(DWORD Base, INT Offset);
		Pointer(DWORD Base, UINT Level, ...);
		//DESTRUCTOR
		~Pointer();
	private:
		DWORD GetPointedAddress(ULONG_PTR* ulBase, INT OFF_1) {
			__try {
				return *(DWORD*)ulBase + OFF_1;
			}
			__except (EXCEPTION_EXECUTE_HANDLER) {
				return NULL;
			}
		}
	public:
		//READ_PTR
		template< typename T > T Read() {
			if (this->mBase == NULL) {
				return 0;
			}
			else if (this->mvOffsets.size() == 0) {
				return 0;
			}
			else if (IsBadReadPtr((LPVOID)this->mBase, sizeof(ULONG_PTR))) {
				return 0;
			}

			ULONG_PTR Ret = *(ULONG_PTR*)((*(ULONG_PTR*)this->mBase) + this->mvOffsets[0]);

			if (mvOffsets.size() > 1) {
				for (UINT I = 1; I != mvOffsets.size(); ++I) {
					Ret = *(ULONG_PTR*)(Ret + mvOffsets[I]);
					if (IsBadReadPtr((LPVOID)(this->mBase + mvOffsets[I]), sizeof(ULONG_PTR)))
					{
						return 0;
					}
				}
			}
			return (T)Ret;
		};


		//WRITE_PTR
		template< typename T > BOOL Write(T Val) {
			if (this->mBase == NULL) {
				return FALSE;
			}
			else if (this->mvOffsets.size() == 0) {
				return FALSE;
			}
			else if (IsBadReadPtr((LPVOID)this->mBase, sizeof(ULONG_PTR))) {
				return FALSE;
			}

			if (mvOffsets.size() > 1) {
				DWORD O = GetPointedAddress(this->mBase, this->mvOffsets[0]);
				for (UINT I = 1; I != mvOffsets.size() - 1; ++I) {
					O = GetPointedAddress((LPDWORD)O, this->mvOffsets[I]);
				}
				*(LPDWORD)(*(LPDWORD(O)) + this->mvOffsets[this->mvOffsets.size() - 1]) = Val;
			}
			else {
				//SINGLE_PTR
			}
			return TRUE;
		};
	};
};


Scanner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class Scanner {

private:

	VOID CodeSectionInfo(IMAGE_DOS_HEADER* THIS_IMAGE_DOS_HEADER, DWORD* outCodeSectionStart, DWORD* outCodeSectionSize)
	{
		IMAGE_NT_HEADERS* e_lfanewPtr = (IMAGE_NT_HEADERS*)((DWORD)THIS_IMAGE_DOS_HEADER + THIS_IMAGE_DOS_HEADER->e_lfanew);
		*outCodeSectionStart = (DWORD)THIS_IMAGE_DOS_HEADER + e_lfanewPtr->OptionalHeader.BaseOfCode;
		*outCodeSectionSize = e_lfanewPtr->OptionalHeader.SizeOfCode;
	}

	BOOL CHECK(const BYTE* pData, const BYTE* bMask, const char* szMask)
	{
		for (; *szMask; ++szMask, ++pData, ++bMask)
			if (*szMask != '?' && *pData != *bMask)
				return false;

		return (*szMask) == NULL;
	}

public:

	DWORD findPattern(DWORD dwBegin, DWORD dwEnd, BYTE *bMask, char* szMask, BOOL dwSpecial = FALSE, INT iResult = 0)
	{
		DWORD dwAddress, dwLen;
		INT curResult = 0;
		if (!dwSpecial) {

			dwAddress = dwBegin;
			dwLen = dwEnd;
		}
		else
			CodeSectionInfo((IMAGE_DOS_HEADER*)GetModuleHandleA(NULL), &dwAddress, &dwLen);

		for (DWORD i = 0; i < dwLen; i++) {
			_try{


				if (CHECK((BYTE*)(dwAddress + i), bMask, szMask)) {
					if (iResult != 0) {
						if (curResult != iResult)
							curResult++;
						else
							return (DWORD)(dwAddress + i);
					}
					else
						return (DWORD)(dwAddress + i);
				}
			}
				__except (EXCEPTION_EXECUTE_HANDLER)
			{

			}
		}

		return dwBegin;
	}

	DWORD findBase(DWORD dwAddy) {

		if (dwAddy >= 0x01000000 && dwAddy < 0x02000000)
			return 0x01000000;
		if (dwAddy >= 0x02000000 && dwAddy < 0x03000000)
			return 0x02000000;
		if (dwAddy >= 0x03000000 && dwAddy < 0x04000000)
			return 0x03000000;
		if (dwAddy >= 0x04000000 && dwAddy < 0x05000000)
			return 0x04000000;
		if (dwAddy >= 0x05000000 && dwAddy < 0x06000000)
			return 0x05000000;
		if (dwAddy >= 0x06000000 && dwAddy < 0x07000000)
			return 0x06000000;
		if (dwAddy >= 0x07000000 && dwAddy < 0x08000000)
			return 0x07000000;
		if (dwAddy >= 0x08000000 && dwAddy < 0x09000000)
			return 0x08000000;
		if (dwAddy >= 0x09000000 && dwAddy < 0x0A000000)
			return 0x09000000;
		if (dwAddy >= 0x0A000000 && dwAddy < 0x0B000000)
			return 0x0A000000;
		if (dwAddy >= 0x0B000000 && dwAddy < 0x0C000000)
			return 0x0B000000;
		if (dwAddy >= 0x0C000000 && dwAddy < 0x0D000000)
			return 0x0C000000;
		if (dwAddy >= 0x0D000000 && dwAddy < 0x0E000000)
			return 0x0D000000;
		if (dwAddy >= 0x0E000000 && dwAddy < 0x0F000000)
			return 0x0E000000;
		if (dwAddy >= 0x0F000000 && dwAddy < 0x10000000)
			return 0x0F000000;

		return NULL;
	}
};


Memory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "Memory.h"
#pragma unmanaged

//DEFAULT_CONSTRUCTOR
Memory::Memory() {

};

//DESTRUCTOR
Memory::~Memory() {

};

//FUNCTIONAL
int _stdcall Memory::WriteMemory(void* pvAddress, void* pvWriteBuffer, size_t Size) {
	DWORD dwAddress, dwOldProtectionFlags, dwSize;

	int iReturnCode;

	iReturnCode = 0;

	dwAddress = ROUND_DOWN(pvAddress, 0x1000); // assume 4096 bytes of granularity for pages, otherwise use void* and GetSystemInfo to get page size for x64
	dwSize = ROUND_UP(Size, 0x1000);

	if (VirtualProtect((LPVOID)dwAddress, dwSize, PAGE_EXECUTE_READWRITE, &dwOldProtectionFlags))
	{
		memcpy(pvAddress, pvWriteBuffer, Size);

		if (VirtualProtect((LPVOID)dwAddress, dwSize, dwOldProtectionFlags, &dwOldProtectionFlags))
		{
			if (FlushInstructionCache(GetCurrentProcess(), (LPCVOID)dwAddress, dwSize))
			{
				iReturnCode = 0;
			}
			else
			{
				iReturnCode = GetLastError();
			}
		}
		else
		{
			iReturnCode = GetLastError();
		}
	}
	else
	{
		iReturnCode = GetLastError();
	}

	return iReturnCode;
};

ULONG_PTR Memory::ReadPtr(DWORD dwBase, INT iOffset) {
	ULONG_PTR* ulBase = (ULONG_PTR *)dwBase;
	if (!IsBadReadPtr((VOID*)ulBase, sizeof(ULONG_PTR)))
		if (!IsBadReadPtr((VOID*)((*(ULONG_PTR*)ulBase) + iOffset), sizeof(ULONG_PTR)))
			return *(ULONG_PTR*)((*(ULONG_PTR*)ulBase) + iOffset);
	return 0;
};

std::string Memory::ReadStr(DWORD dwBase, INT iOffset) {
	ULONG_PTR* ulBase = (ULONG_PTR *)dwBase;
	if (!IsBadReadPtr((VOID*)ulBase, sizeof(ULONG_PTR)))
		if (!IsBadReadPtr((VOID*)((*(ULONG_PTR*)ulBase) + iOffset), sizeof(ULONG_PTR)))
			return *(std::string*)((*(int*)ulBase) + iOffset);
	return 0;
};

BOOL Memory::WritePtr(unsigned long ulBase, INT iOffset, int iValue)
{
	__try { *(int*)(*(unsigned long*)ulBase + iOffset) = iValue; return TRUE; }
	__except (EXCEPTION_EXECUTE_HANDLER) { }

	return FALSE;
};

BOOL Memory::WriteStr(unsigned long ulBase, INT iOffset, std::string sValue)
{
	try { *(std::string*)(*(unsigned long*)ulBase + iOffset) = sValue; return TRUE; }
	catch (...) {}

	return FALSE;
};


hLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <Windows.h>
#include "Memory.h"
#include "Scanner.h"
#include <string>
#define Money 0x5C20D8
#define Money_Offset 0x37C8
using namespace std;

class Library {
private:
	Scanner *scan;
	Memory *mem;
public:
	Library(bool doInit) {

		if (doInit) {

			Initialize();
		}

	}
	void Initialize() {
		scan = new Scanner();
		mem = new Memory();
	}
	int getMoney() {

		int mMoney = 0;
		try {
			mMoney = mem->ReadPtr(Money, Money_Offset);
		}
		catch (...) {}
		return mMoney;
	}


MyForm.h
1
2
3
if (checkBox1->Checked) {
textBox1->Text = lib->getMoney().ToString();
}

in MyForm.h, i get the money value and it inputs it into the textbox. how can i do it with a name?
Last edited on
anyone?
Only spent a few minutes looking at this. I don't remember any of these APIs anyways.

Maybe this has something to do with it:
1
2
3
4
5
6
7
std::string Memory::ReadStr(DWORD dwBase, INT iOffset) {
	ULONG_PTR* ulBase = (ULONG_PTR *)dwBase;
	if (!IsBadReadPtr((VOID*)ulBase, sizeof(ULONG_PTR)))
		if (!IsBadReadPtr((VOID*)((*(ULONG_PTR*)ulBase) + iOffset), sizeof(ULONG_PTR)))
			return *(std::string*)((*(int*)ulBase) + iOffset);
	return 0;
};


You can't reinterpret a C-string as a std::string and expect it to be valid. Instead, construct a new one:
1
2
char const* cstring = reinterpret_cast<char const*>(*(int*)ulBase) + iOffset);
return std::string(cstring); 

Last edited on
i still get the same error with that code
'ToString': is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
 
textBox1->Text = lib->getName().ToString();
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
is just how the bad-UI compiler internally sees std::string.

So, that particular error is pretty clear: std::string does not have a method called ToString.

Are you using Microsoft's "C++\CLI"? .NET's Object::ToString() is a different beast than the standard library's std::strings. But you don't appear to be using C++\CLI, rather just the Win32 API, so I don't think you'll have access to .NET objects or methods.

I do not see your definition of "textBox1", or your definition of "lib". What are those? What types are they? What are they defined as?
Last edited on
sorry for late reply and yes im using c++/cli
 
Library *lib = new Library(false);

this defines lib
ideas anyone?
If you want to use the ToString() method, don't use std::strings. Use System::String^. Or, you can still use std::strings, but then convert each string to a System::String^ before calling ToString()

Here's an SO post about converting std::strings and C++/CLI strings https://stackoverflow.com/questions/946813/c-cli-converting-from-systemstring-to-stdstring
1
2
3
std::string model(lib->getIGN());
				String^ MyString = gcnew String(lib->getIGN().c_str());
				richTextBox1->Text = MyString;

thanks!!!!!!!!!! thanks a lot! i just converted std::string to System::String^
Topic archived. No new replies allowed.