C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-09-2008, 01:53 AM   #1
Registered User
 
Join Date: Dec 2008
Posts: 3
Checking memory allocation

Okay, so I'm basically writing a c .dll that will iterate through memory of the target process and report if a certain value is true.

I have this working fine (through the use of pointers), however, when it hits region of memory that hasn't been allocated it crashes the process. I was looking for a method (preferably not through Windows API) to check whether or not the memory has being allocated.

Code looks something like this:

Code:
for(i=0x10000;i<0x7FFFFFFF;i+=0x10000)
{
			
	if(*(DWORD*)(i + 0xAC) == 0x16945630)
	{
		pdwMyAddr = (DWORD*)(i + 0xAC);
		//Abritrary code here.
	}
}
Thanks for any help .
JoeBloggs is offline   Reply With Quote
Old 12-09-2008, 02:28 AM   #2
Registered User
 
C_ntua's Avatar
 
Join Date: Jun 2008
Posts: 1,134
Well, it crashes as it owes to. I suppose you have a method to know exactly which memory address the process owns? Like from where the heap, the stack etc etc start end.
Well, the information is somewhere, but that depends on the OS. The OS is responsible for managing memory along processes. But I don't know where you can read that information. The sure think is that it would be TOTALLY unsafe if somebody could just read information from the memory without being owned by the process.
It would be also unsafe to find out where a process writes and just read that memory!
And finally, every time the process runs it won't have the same memory space. It would depend.
Now, if you have access to the code of the program it might be possible. You could probably just print the address of each variable, manually or with a certain function maybe? Then finding the "bounds" of the memory owned by the process you might get what you want. Probably not what you want 'cause I don't believe its possible for security reasons...
C_ntua is offline   Reply With Quote
Old 12-09-2008, 02:43 AM   #3
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,139
The days when such a thing was possible are long, long gone.

Basically you need to inject a DLL into the target process and then read the memory of the process via that DLL. I won't say anymore just incase it's against the rules (this sort of stuff is used by viruses and game cheats).
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim
zacs7 is offline   Reply With Quote
Old 12-09-2008, 03:04 AM   #4
Registered User
 
Join Date: Dec 2008
Posts: 3
Quote:
The sure think is that it would be TOTALLY unsafe if somebody could just read information from the memory without being owned by the process.
My dll creates a thread belonging to the process.

Quote:
And finally, every time the process runs it won't have the same memory space. It would depend.
Yep, I am aware of that, this function is for finding the address of a value within memory

Quote:
Basically you need to inject a DLL into the target process and then read the memory of the process via that DLL. I won't say anymore just incase it's against the rules (this sort of stuff is used by viruses and game cheats).
Yep, yep everything is working, other than when it hits a block of unallocated memory it crashes (as it is attempting to assign it to a DWORD, when there's nothing there)

Quote:
And finally, every time the process runs it won't have the same memory space. It would depend.
Oh, ohk, so I will have to resort to an api to check? :[.

Thanks for the quick replies
JoeBloggs is offline   Reply With Quote
Old 12-09-2008, 04:25 AM   #5
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Yes, you may want to look into the Virtual Memory functions of the Win32 API, more specifically VirtualQuery. Use it to query if the pages have been allocated or not.
But then again, why do you need to do this?
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 12-09-2008, 05:01 AM   #6
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
There was a discussion not so long ago, where we came up with a list of "Possible virtual addresses that the process may own".

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Reply

Tags
c programming, dll, memory allocation, windows

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
POSIX Threads and dynamic memory allocation PING Linux Programming 1 04-02-2009 10:28 AM
To find the memory leaks without using any tools asadullah C Programming 2 05-12-2008 07:54 AM
Assignment Operator, Memory and Scope SevenThunders C++ Programming 47 03-31-2008 06:22 AM
Checking for memory allocation... kinghajj C Programming 7 12-22-2004 10:42 PM
Memory allocation at runtime? electrolove C Programming 6 02-05-2003 11:39 AM


All times are GMT -6. The time now is 11:06 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22