Solved

Direct Memory Access in C

Posted on 2006-06-22
6
3,000 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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:windows_programing
Comment Utility
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
Comment Utility
ah yes, that's the ticket.  Good luck with your debugger.

0
 

Author Comment

by:windows_programing
Comment Utility
Thanks for the help on this one!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
The goal of this video is to provide viewers with basic examples to understand opening and reading 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.

744 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

16 Experts available now in Live!

Get 1:1 Help Now