Solved

Direct Memory Access in C

Posted on 2006-06-22
6
3,004 Views
Last Modified: 2012-06-22
Hi all,

Is there a way to directly access memory in Windows with c.  I have tried several attempts but keep getting AV's.  Here's some code to show what I'm doing.

int main(int argc, char* argv[])
{
      
long* p = (long*) 0x00AFAED8; //Want to know the value at this address
long t = 0;

t = *p;
      
      return 0;
}
0
Comment
Question by:windows_programing
6 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 120 total points
ID: 16965510
Hi windows_programing,

You can do this kind of thing, but you need to keep a couple of things in mind.

1)  The address that you're reading is the memory within your address space, it is NOT the system address.
2)  If you attempt to read an address that's not assigned to your program, it will abort.
3)  You'll probably want to use (unsigned char *) instead of (long*).


But, Good Luck!
Kent
0
 
LVL 12

Assisted Solution

by:rajeev_devin
rajeev_devin earned 115 total points
ID: 16965814
>> Is there a way to directly access memory in Windows with c.
You can access but not the system address space. You can access the user address space.

A process is divided into two memory address space.
System address space // Kernel-mode program can access this address space.
& User address space // User-mode program can access this address space.

So be careful to avoid program crash.

For more details check this link
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q189327
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 115 total points
ID: 16967518
In Windows it never makes any sense to try to peek at some absolute memory address.   Windows is a 99% all-relocaatable and virtual system.  There are darned few absolute addresses that are of any significance.  And in your typical user program, the adddresses are all relative to the user data segment, not any absolute physical memory address.

SO I guess the better question is:  why do you want to peek at that address?    Maybe we can suggest a better way of doing whatever yuo're trying to do.

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:windows_programing
ID: 16972365
I'm trying to write an external debug routine (another software app.) that will give me info. on my software.

I think I've found something of interest from MSDN..
ReadProcessMemory()
0
 
LVL 22

Expert Comment

by:grg99
ID: 16975089
ah yes, that's the ticket.  Good luck with your debugger.

0
 

Author Comment

by:windows_programing
ID: 17010421
Thanks for the help on this one!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Which version of C should I use when Perl is too slow? 13 183
Pointer in one class to member in another 6 125
chcp 65001 File encoding 66 273
Need example 5 122
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question