Solved reading string from memory adress [external]

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Ex0rpl4net

Newbie
Full Member
Jun 28, 2015
11
92
0
Hello guided hacking,

i am currently coding my hacks in c++ but externally this time and i cannot get ReadProcessMemory to get me that "string" where i need it.



HTML:
        int singleadd = enemynum * enemyoffset;
	DWORD PlayerBase = (DWORD)(HWDLL + enemyBaseAddress + singleadd + 44); //store the value

	char cTemp[255];

	ReadProcessMemory(hProcHandle, (LPCVOID)PlayerBase, &cTemp, sizeof(cTemp), NULL);
this gives me a bunch of unreadable crap even tho im reading from the right address.

that same adress in CE gives me the correct value, so the code must be the reason im getting the wrong value

thanks alot
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
C++:
#ifdef UNICODE
#define ReadString ReadStringW
#else
#define ReadString ReadStringA
#endif

size_t ReadStringA(HANDLE hProc, void* pAddress, char* pOut, size_t MaxLength)
{
    DWORD Read;
    UINT Ret = ReadProcessMemory(hProc, pAddress, pOut, MaxLength, &Read);
    if (!Ret || !Read)
    {
        return 0;
    }

    Ret = 0;
    while (Ret != MaxLength)
    {
        if (!*pOut)
        {
            return Ret;
        }
        pOut++;
        Ret++;
    }
    return MaxLength;
}

size_t ReadStringW(HANDLE hProc, void* pAddress, wchar_t* pOut, size_t MaxLength)
{
    DWORD Read;
    UINT Ret = ReadProcessMemory(hProc, pAddress, pOut, MaxLength * 2, &Read);
    if (!Ret || !Read)
    {
        return 0;
    }

    Ret = 0;
    while (Ret != MaxLength)
    {
        if (!*pOut)
        {
            return Ret;
        }
        pOut++;
        Ret++;
    }
    return MaxLength;
}
Works flawless for me.

Edit: So much new posts in that time :dansgame:

for std::string:
https://guidedhacking.com/threads/how-to-readprocessmemory-std-string.14927/
 
Last edited by a moderator:

Ex0rpl4net

Newbie
Full Member
Jun 28, 2015
11
92
0
but in my internal hack it works

C++:
	int singleadd = enemynum * enemyoffset;
	DWORD PlayerBase = (DWORD)(HWDLL + enemyBaseAddress + singleadd + 44); //store the value

	char cTemp[255];
	string tempstring;

	sprintf_s(cTemp, "%s", PlayerBase);
	tempstring = std::string(cTemp);
 

Liduen

Hacker
Dank Tier VIP
May 19, 2013
702
8,478
33
but in my internal hack it works

C++:
	int singleadd = enemynum * enemyoffset;
	DWORD PlayerBase = (DWORD)(HWDLL + enemyBaseAddress + singleadd + 44); //store the value

	char cTemp[255];
	string tempstring;

	sprintf_s(cTemp, "%s", PlayerBase);
	tempstring = std::string(cTemp);
Does that even compile without errors?
C++:
int sprintf_s(
   char *buffer,
   size_t sizeOfBuffer,
   const char *format [,
   argument] ... 
);
Check this out: https://guidedhacking.com/showthread.php?6865-solved-thanks&p=34807&viewfull=1#post34807
 
Last edited:

Ex0rpl4net

Newbie
Full Member
Jun 28, 2015
11
92
0
Does that even compile without errors?
C++:
int sprintf_s(
   char *buffer,
   size_t sizeOfBuffer,
   const char *format [,
   argument] ... 
);


no errors whatsoever, works well actually.

did you do ReadProcessMemory from an adress CE shows a "string" before? i couldnt find anyone that did that - i probably didnt search for the right keywords
 

Ex0rpl4net

Newbie
Full Member
Jun 28, 2015
11
92
0
Вroihon;36096 said:
C++:
#ifdef UNICODE
#define ReadString ReadStringW
#else
#define ReadString ReadStringA
#endif

size_t ReadStringA(HANDLE hProc, void* pAddress, char* pOut, size_t MaxLength)
{
	DWORD Read;
	UINT Ret = ReadProcessMemory(hProc, pAddress, pOut, MaxLength, &Read);
	if (!Ret || !Read)
	{
		return 0;
	}

	Ret = 0;
	while (Ret != MaxLength)
	{
		if (!*pOut)
		{
			return Ret;
		}
		pOut++;
		Ret++;
	}
	return MaxLength;
}

size_t ReadStringW(HANDLE hProc, void* pAddress, wchar_t* pOut, size_t MaxLength)
{
	DWORD Read;
	UINT Ret = ReadProcessMemory(hProc, pAddress, pOut, MaxLength * 2, &Read);
	if (!Ret || !Read)
	{
		return 0;
	}

	Ret = 0;
	while (Ret != MaxLength)
	{
		if (!*pOut)
		{
			return Ret;
		}
		pOut++;
		Ret++;
	}
	return MaxLength;
}
Works flawless for me.

Edit: So much new posts in that time :dansgame:
what should this do? it returns size_t variables? never heared of that..

also how do these differ?

do many questions :smile:
 

Liduen

Hacker
Dank Tier VIP
May 19, 2013
702
8,478
33
what should this do? it returns size_t variables? never heared of that..

also how do these differ?

do many questions :smile:
Check the paramters of these methods again.
Both take pointers called pOut...
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
what should this do? it returns size_t variables? never heared of that..

also how do these differ?

do many questions :smile:
hProc = Handle to the process
pAddress = Address of the string
pOut = Pointer to a char* or wchar_t* string
MaxLength = Well, the max lengths of the buffer you passed as pOut

And size_t is just an unsigned 32 bit datatype. Like UINT or DWORD.

Edit:
C++:
//Example:
DWORD Address = 0x123456;
char Buffer[200] = {0};
size_t Length = ReadStringA(hProc, (void*)Address, Buffer, 200);
if(Length)
{
     std::cout << "Length: " << Length << std::endl;
     std::cout << Buffer << std::endl;
}
 
Last edited:

Ex0rpl4net

Newbie
Full Member
Jun 28, 2015
11
92
0
Вroihon;36099 said:
hProc = Handle to the process
pAddress = Address of the string
pOut = Pointer to a char* or wchar_t* string
MaxLength = Well, the max lengths of the buffer you passed as pOut

And size_t is just an unsigned 32 bit datatype. Like UINT or DWORD.

Edit:
C++:
//Example:
DWORD Address = 0x123456;
char Buffer[200] = {0};
size_t Length = ReadStringA(hProc, (void*)Address, Buffer, 200);
if(Length)
{
     std::cout << "Length: " << Length << std::endl;
     std::cout << Buffer << std::endl;
}
thanks, that solved it!

Check the paramters of these methods again.
Both take pointers called pOut...

thank you too
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
Glad it's working. Btw. I took another look on your first code:
HTML:
        int singleadd = enemynum * enemyoffset;
	DWORD PlayerBase = (DWORD)(HWDLL + enemyBaseAddress + singleadd + 44); //store the value

	char cTemp[255];

	ReadProcessMemory(hProcHandle, (LPCVOID)PlayerBase, &cTemp, sizeof(cTemp), NULL);
The problem is that you pass &cTemp to RPM (ReadProcessMemory).
So cTemp is a pointer to a bunch of chars. With &cTemp you're passing a pointer to a pointer to the chars but RPM only needs the pointer directly to the chars.
Correct would be ReadProcessMemory(hProcHandle, (LPCVOID)PlayerBase, cTemp, sizeof(cTemp), NULL); ^^
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods