Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 17th, 2006, 1:49 AM   #1
heapwalker
Newbie
 
Join Date: Apr 2006
Posts: 11
Rep Power: 0 heapwalker is on a distinguished road
Question direct memory byte veiwing

I am not a programmer. however, I wish to know
how to take contents from my pc's memory and
place into a variable. I have slapped together something
that looked promising but I just get some error like

"....c++ forbids the comparison of pointer and integers"

could some one explain how i can grab byte from anywhere
in pc memory.

no code required just conceptual explanation.

I attempted to use a pointer to point to some byte in
memory and copy the byte value to a variable. is this the
right approach?
heapwalker is offline   Reply With Quote
Old Apr 17th, 2006, 3:05 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5 grumpy is on a distinguished road
Modern operating systems don't allow unfettered access to computer memory from user-mode programs --- in fact, they are deliberately designed to prevent such access.
grumpy is offline   Reply With Quote
Old Apr 17th, 2006, 8:15 AM   #3
heapwalker
Newbie
 
Join Date: Apr 2006
Posts: 11
Rep Power: 0 heapwalker is on a distinguished road
You response is difficult to accept. i presume you are refering to the x86 protected mode.
heapwalker is offline   Reply With Quote
Old Apr 17th, 2006, 8:38 AM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5 grumpy is on a distinguished road
You finding it unacceptable doesn't change the answer. No, I wasn't referring to x86 protected mode, I was talking generically. However, modern operating systems (windows NT, linux, solaris, BSD, etc) that run on x86 architecture do, AFAIK, make use of protected mode.
grumpy is offline   Reply With Quote
Old Apr 17th, 2006, 8:58 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
ROFL! I found if difficult to accept, when she said, "No", but I still didn't get any.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 17th, 2006, 9:08 AM   #6
heapwalker
Newbie
 
Join Date: Apr 2006
Posts: 11
Rep Power: 0 heapwalker is on a distinguished road
could I use some thing like:



int *memory_location,memory_value;
memory_location=0x00000000;
&(memory_value)=memory_location;


i.e. intialize a pointer and pass the pointers' value as
address to a varible and then using the variable as normal byte int.
heapwalker is offline   Reply With Quote
Old Apr 17th, 2006, 9:23 AM   #7
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5 grumpy is on a distinguished road
I assume you mean;
int *memory_location,memory_value;
memory_location= (int *)0x00000000;
memory_value= *memory_location;
This actually gives undefined behaviour in C/C++, as it is dereferencing a NULL pointer. Undefined behaviour means anything is allowed to happen eg a program crash, absolutely nothing, a segmentation fault (under unix), a general protection fault (under windows), a "blue screen of death" (windows), etc etc.

In practice, on a modern OS, this code might actually tell you what data is available at some specified zero address. However, on those same systems, that specified zero address will be part of the address space for the process that is executing your program, which is different from actual physical memory on your machine. As I said, a design goal of a modern OS is to keep a running program from directly accessing physical memory.
grumpy is offline   Reply With Quote
Old Apr 17th, 2006, 9:27 AM   #8
heapwalker
Newbie
 
Join Date: Apr 2006
Posts: 11
Rep Power: 0 heapwalker is on a distinguished road
ahh! I see. mmmm...
heapwalker is offline   Reply With Quote
Old Apr 17th, 2006, 9:29 AM   #9
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5 grumpy is on a distinguished road
No you don't. You are assuming I have given you the solution you want. What I have given you is a bit of code that you think will give you what you want, and it won't. Even worse, it could corrupt your system. I suppose having to reinstall your OS might be a way to get the message across to you.
grumpy is offline   Reply With Quote
Old Apr 17th, 2006, 10:30 AM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Let me put it like this: on a primitive machine, or working at a primitive level, you may do whatever you wish, including trash the machine. By trash, I even include physical damage, as well as just causing the machine to go belly-up out in the weeds. On a typical, modern machine, you are presumed to be one of a half-scad of users. If you were allowed to do what you desire, nothing would prevent you from accessing and messing with another's app. You might trash it entirely. You might just mess with the answers it gives. Would you want me doing that to your program, if you're computing the critical mass of a radioactive material, and are going to test the results your very own lowly, expendable, self? I'm thinnking, "NOT!". If you are entirely serious, you need to get under the hood and learn how things work. In the meantime, please wear bright red if you are working in the local hospital when I suddenly need to get an appendectomy. I'd rather choose to die my own way.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:48 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC