ReadProcessMemory

Posts 1–15 of 18 · Page 1 of 2
ReadProcessMemory
Hello, i'm getting an error i havn't seen before. Any help would be appriciated.

Code:
HANDLE handle;

DWORD base = 0x00400000;
DWORD end = 0x7FFFFFFF;
long bSize = (end-base);

LPBYTE buffer = new byte[bSize];



void Read(DWORD value)
{
             ReadProcessMemory(handle,(LPVOID)base,buffer,bSize,0);
             for(int i = 0; i < bSize; i++ )
             {
                     if(buffer[i] == value)
                     {
                                  cout << hex << base + i << endl;
                     }
             }
             
           
     cout << "Done";
     getch();
}
Everytime i run the program it the console outputs:
"Application has requested the runtime to terminate it in an unusual way"

I have no idea why this is happening T.T

Thanks in advance.
Un autre canadienne. But anyway. That is really strange. I've never gotten console output as an error before. What IDE are you using, And what operating system?

That said, that's a quite a cool program your writing! Essentially it searches the memory for values and displays those addresses, right?.

However, even if you fix this bug i think you will run into access violations. and isn't the first parameter of the read process memory function supposed to be a handle to the process you are reading the memory of?
I'm using Dev C++ on Windows XP.

I got the handle from another part of the code, I made sure it wasn't that causing the problem. I've used readprocessmemory() before but not like this.

Maybe this will help but I think it might be the buffer size. I tryed making a buffer size of 3 bytes and scanned the value of addresses I got off cheatengine and it worked well. It out of the 3 addresses it scans, it outputed the right address.
Quote Originally Posted by Void View Post
I'm using Dev C++ on Windows XP.

I got the handle from another part of the code, I made sure it wasn't that causing the problem. I've used readprocessmemory() before but not like this.

Maybe this will help but I think it might be the buffer size. I tryed making a buffer size of 3 bytes and scanned the value of addresses I got off cheatengine and it worked well. It out of the 3 addresses it scans, it outputed the right address.
Maybe... Those are in fact a lot of bytes you are allocating. In fact, if a byte takes up a byte of memory, and you are trying to make an array of bytes the size of your available memory, i can see how that would be a problem :/
Do you think I could make the buffer size smaller, read that many bytes, then just add to the base address and scan again?

I don't know if that will work. >.>
Well maybe you could scan in parts?
Instead of having one big MASSIVE array. Have a relatively small array, search from there, delete it, then make another array for the next segment.

Oh, that's basically what you said. >_<. Except you already formed a way of doing it in your head. Kudos. So how is the handle part working? I thought you needed to have the handle to the process of the address space upon which you are intruding. But apparently you found someway to dance around that?
Having a small buffer size completely defeats the purpose of what i'm trying to do. Sorry, I didn't tell you what i was expecting this program to do. I'm trying to make a memory scanner, and at first tryed using ReadProcessMemory for each address which was extremely slow.

I'm still going to try your idea though, trying right now.
Thanks for your replies.
No problem I've got nothing to do. And i kinda figured you were doing a memory scanner. Why would a small buffer size be a problem? Well besides speed. I'm not exactly sure how much slower it would be.
Well I made a smaller buffer size and it scans, but I don't know what address to start scanning from.

You were right about smaller buffer sizes, it's pretty fast. Thanks
Your welcome. Your project seems interesting. If you have any more concerns feel free to ask so i can Fail at answering you =D
Wow. Haha. took me about 20min to figure this out xD.

Ok. so Im guessing you only set the buffer to the size of the value your scanning for. For instance if your scanning for a char value or bool set the buffer to 1byte. Or if your scanning for a int set it to 4bytes. Correct? or maybe it depends on what LPBYTE is? A long pointer to a byte? so basically long char* and your assigning it a value of a single byte.... Im confused again. :l
Quote Originally Posted by why06 View Post
Wow. Haha. took me about 20min to figure this out xD.

Ok. so Im guessing you only set the buffer to the size of the value your scanning for. For instance if your scanning for a char value or bool set the buffer to 1byte. Or if your scanning for a int set it to 4bytes. Correct? or maybe it depends on what LPBYTE is? A long pointer to a byte? so basically long char* and your assigning it a value of a single byte.... Im confused again. :l
Not quite why =D. He is scanning his entire memory space for a certain value. Like what is done in mhs/ce and the like. except kinda better in the way that it can be easily integrated into a program you write.
Thanks, I actually ran into a few more problems but i'm going to take a rest for today.

Good night.
Code:
Variable  Size(bytes)  Accuracy   Range
Short: 2 bytes  Exact  -32768 to 32767
int: 4 bytes   Exact  -2,147,483,648 to 2,147,483,647
long: 4 bytes   Exact -2,147,483,648 to 2,147,483,647
long long int: 8 bytes   Exact  -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float: 4 bytes  7 digits   +-3.4028 x 10+- 38
double:8 bytes  16 digits  +-1.7977 x 10 308
long double: 12 bytes  19 digits  +- 1.1897 x 10+-4932
i don't know if this helps but ill post it anyway.
Quote Originally Posted by cnttuchme View Post
Code:
Variable  Size(bytes)  Accuracy   Range
Short: 2 bytes  Exact  -32768 to 32767
int: 4 bytes   Exact  -2,147,483,648 to 2,147,483,647
long: 4 bytes   Exact -2,147,483,648 to 2,147,483,647
long long int: 8 bytes   Exact  -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float: 4 bytes  7 digits   +-3.4028 x 10+- 38
double:8 bytes  16 digits  +-1.7977 x 10 308
long double: 12 bytes  19 digits  +- 1.1897 x 10+-4932
i don't know if this helps but ill post it anyway.
Sizes are different from every OS. This looks like windows if I am correct....
Posts 1–15 of 18 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us