Solved

Direct Memory Access in C

Posted on 2006-06-22
6
3,001 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:
Kdo 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now