Solved

Direct Memory Access in C

Posted on 2006-06-22
6
3,009 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

688 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