Direct memory access?

This is a discussion on Direct memory access? within the C++ Programming forums, part of the General Programming Boards category; Is there ANY way using C, C++, and/or assembly that lets you directly access memory of a computer? Like the ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    67

    Direct memory access?

    Is there ANY way using C, C++, and/or assembly that lets you directly access memory of a computer? Like the actual basic hard drive in bytes or something. I'm interested in OSs and the very ground-level stuff, like memory and stuff, so yeah.. I'm all about manipulating the lowest-level stuff.

    As a side note, I'm very interested in security. Does anybody have any very simple firewall code? (not so much antivirus.. although that is interesting). Firewall or any GameGuard/XTrap type stuff?

    Thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Physical memory? No.
    Virtual memory? Yes.
    Just use a pointer to a specific address, but it won't work unless you've allocated that page you're trying to read/write to.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    Oh I was hoping for physical memory. Thanks anyway

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    No, you can't access Physical Memory because that would severely bork the OS.
    Thankfully virtual memory is implemented in today's processors, so even if you bypass the OS, you can't do it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    o_O "bork"?

    I guess that'll work too. I just kinda thought creating files by scrolling through and editing HEX would be kinda cool

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Yes, you can have direct access to the physical memory, just not with a user space application. It's a pretty advanced topic though, and the implementation is heavily dependent on what OS you are using.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    It would be a major security risk. That is why this kind of code produces segfault -
    Code:
    int a[10];
    a[100000] = 3;
    as for accessing harddrive in bytes, in Linux, assuming you have root priviledge, you can just open /dev/hda (or the name of your harddrive) in binary mode. I am not sure how one would do that in Windows.

    Actually, on a second thought, it is possible on Linux too, to access physical memory. Just open /dev/mem in binary. Again, you will need root priviledge to do that. Not sure about Windows though.
    Last edited by cyberfish; 01-06-2008 at 12:43 PM.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    you can have direct access to the physical memory, just not with a user space application
    I just tried "sudo head /dev/mem" on my Linux box and it worked

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Quote Originally Posted by bithub View Post
    Yes, you can have direct access to the physical memory, just not with a user space application. It's a pretty advanced topic though, and the implementation is heavily dependent on what OS you are using.
    In Windows, you must at least be in kernel mode.
    The thing about physical memory is that the OS works on virtual memory - giving X amount to each application and then mapping that into physical memory or the page file. All applications are sharing this. You can't just go in and write stuff all over the place - you'll crash the other applications, and perhaps even the OS itself!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    The thing about physical memory is that the OS works on virtual memory
    Not all operating systems use virtual memory.

    You can't just go in and write stuff all over the place - you'll crash the other applications, and perhaps even the OS itself!
    From the guy's posts, it appears he is more interested in writing to hard drive memory, not RAM.

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Quote Originally Posted by bithub View Post
    Not all operating systems use virtual memory.
    That would be a rather poor operating system, if I may say so.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I just kinda thought creating files by scrolling through and editing HEX would be kinda cool
    It's possible to directly manipulate the bytes of the HDD, but you'll need hours just to look up and recalculate all the values that you have to change in order to create a real file without screwing everything up. (And during these hours, the OS will probably do some routine job, change a small thing and invalidate all your calculations.) Hard disks have an organization, you know.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #13
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    True, very true. I just thought it'd be interesting.

  14. #14
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    There's nothing interesting about endless amounts of hex digits, believe me.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  15. #15
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    That would be a rather poor operating system, if I may say so.
    Any OS running off ROM would not have any virtual memory (since there is nothing to page the physical memory to). It has absolutely nothing to do with being a "poor operating system".

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  4. quick question on direct file access
    By Stevek in forum C++ Programming
    Replies: 2
    Last Post: 03-21-2003, 12:33 AM
  5. Memory Access Error when using Strcpy()
    By fgs3124 in forum C Programming
    Replies: 2
    Last Post: 03-15-2002, 02:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21