Sign in to follow this  

Need help with strings!

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, you have a chunk of memory in a buffer, and you want to find a string? Its not really very difficult...

byte byBuffer[4096]; // Buffer from ReadProcessMemory()
char szSearch = "Hello World"; // String to search for
const int nSearchLen = strlen(szSearch)-1;
for(int i=0; i<4095; ++i)
{
if((byBuffer[i] == *szSearch) && (strncmp(byBuffer+i+1,szSearch+1,nSearchLen) == 0))
{
// Found string at byBuffer+i
}
}


Thats probably about the fastest way to do it. Bear in mind that if a string straddles to buffers (e.g. on a 4k boundary), it won't be found this way.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Why not just use strstr?

Because the buffer filled by ReadProcessMemory() will probably contain '\0' characters before the string, so strstr() will probably return NULL all the time. strstr() is only for strings, it won't work on a buffer.

Share this post


Link to post
Share on other sites
would this work?

bool compare(int start,char *s1, char *s2)
{
int len = strlen(s2);
for(int i = 0; i < len && s1[i+start] == s2[i]; i++);
if(i == len)
return true;
else
return false;
}

Share this post


Link to post
Share on other sites

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this