how can i access a direct (absolute, not the offset) memory address?

This is a discussion on how can i access a direct (absolute, not the offset) memory address? within the C Programming forums, part of the General Programming Boards category; how can i access a direct (absolute, not the offset) memory address? here is what i tried: wrote a program ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    1

    how can i access a direct (absolute, not the offset) memory address?

    how can i access a direct (absolute, not the offset) memory
    address?

    here is what i tried:
    wrote a program that ask's for an address from the user,
    creates a FAR pointer to that adress and shows it. then the
    user can increment/decrement the value in that address by
    pressing p(inc+) and m(dec-).

    NOW, i compiled that program and opened it twice (in 2
    different windows) and gave twice the same address to it.
    now look what happen - if i change the value in
    one "window" of the program, it DOES NOT change in the
    other! even if they point to the same address in the memory!

    here is the code snippet:
    Code:
    //------------------------------------------------------
    
    #include <stdio.h>        //INCLUDE EVERY KNOWN HEADER FILE
    #include <conio.h>        //FOR ANY CASE...
    #include <iostream.h>
    #include <dos.h>
    #include <process.h>
    
    
    main()
    {
     int far *ptr;         //FAR POINTER!!!
     long address;         
     char key=0;     //A KEY FROM THE KEYBOARD
     int temp=0;
    
     clrscr();
    
     cout<<"Enter Address:";
     cin>>hex>>address;           //GETS THE ADDRESS
     clrscr();
    
     (long)ptr=address; temp=*ptr; //PUTS THE ADDRESS IN THE PTR
    
     cout<<"["<<hex<<(unsigned long)ptr<<"]="<<*ptr<<"  =  "<<
    (char)(*ptr);    
    
    //SHOWS: [address]=value=ASCII symbol.
         
    
     while (key!=27)   //WHILE YOU DONT PRESS ESC.
     {
      while(!kbhit())  //WHILE KEY IS NOT PRESSED
      {
       if (temp!=*ptr) { temp=*ptr; clrscr();  cout<<"["<<hex<<
       (unsigned long)ptr<<"]="<<*ptr<<"  =  "<<(char)(*ptr); };
           
       //IF THE VALUE HAS CHANGED, CLEAR THE SCREEN AND SHOW 
       //AGAIN
    
       if (key=='p') {key=0; (*ptr)++; }   //INCREMENT VALUE
       if (key=='m') {key=0; (*ptr)--;       } //DEC. VALUE
      };
      key=getch(); //IF A KEY IS PRESSED, READ IT FROM THE 
                   //KEYBOARD
     };
     return 0;  //IF ESC WAS THE KEY, EXIT THE PROGRAM
    }
    //---------------------------------------------------------

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,544
    > even if they point to the same address in the memory!
    Does you changing a memory location affect that memory location on my machine (or anyone elses)?

    You said windows, so each of your little DOS boxes is in a completely separate virtual machine. There is nothing "real" about it, it's all smoke and mirrors.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by milon View Post
    Code:
    (long)ptr=address; temp=*ptr; //PUTS THE ADDRESS IN THE PTR
    Umm... what are you trying to do here?

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    Okay, I recognise a lame attempt to make a game cheat program. It would be better to spend time practicing the game than wasting time trying to cheat.

    It's not working because of a wonderful things called process isolation. Of course the busy-loop stealing away as much processing time from the game as possible wouldn't help either. I'm not going to tell you how to fix any of it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    NOW, i compiled that program and opened it twice (in 2
    different windows) and gave twice the same address to it.
    now look what happen - if i change the value in
    one "window" of the program, it DOES NOT change in the
    other! even if they point to the same address in the memory!
    That is because each DOS-box is essentially a separate process in Windows. It's a bit like having two PC's both running DOS - you can't affect one with the other [unless there is specific software on both machines to transfer data from one to the other, of course].

    There is no (easy) way to solve that in Windows.

    If you write a Windows application (instead of a DOS application) you could have two processes using the same physical address by creating a shared memory mapped file that both processes open.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Odd Mental Process Alexander's Avatar
    Join Date
    Aug 2008
    Posts
    22

    Wink

    Quote Originally Posted by iMalc View Post
    Okay, I recognize a lame attempt to make a game cheat program. It would be better to spend time practicing the game than wasting time trying to cheat.

    It's not working because of a wonderful thing called process isolation. Of course the busy-loop stealing away as much processing time from the game as possible wouldn't help either. I'm not going to tell you how to fix any of it.
    Hey, whatever inspires him to learn, right?
    "Some people just don't get my humor. I always think that I'm funny. I've decided that the main reason why I go on the internet and socialize, is to legitimately talk to myself."

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Missouri
    Posts
    1
    This would never work mainly because of memory management operations the OS uses swapping stuff in and out of memory. A good chunk of the translation from different memory addresses is done in hardware by the MMU. If you want to have shared memory between the applications you can do that lookup shmget() and shmat().

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mobp View Post
    This would never work mainly because of memory management operations the OS uses swapping stuff in and out of memory. A good chunk of the translation from different memory addresses is done in hardware by the MMU. If you want to have shared memory between the applications you can do that lookup shmget() and shmat().
    That assumes that it is Linux/Unix type system - shared memory is available in Windows too, but the calls are different.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well... actually, if you ever do any machine level programming or programming some embedded devices, you actually have to do stuff like: char *vram = (char *)0x00A4120;

    But on a PC, you are needing to do something a bit different. Particularly if you are working from within the Operating System. If you are trying to cheat at a game or whatever, you need to think more about reading another processes memory rather than attempting to grab an arbitrary memory address. The simple fact of life you need to realize is that each program is given its own virtual memory space so if my program access (char *)0x80000000 in an effort to access my hit points at that address in-game, I am actually attempting to access an entirely different memory address. Not to mention the fact your OS will tell your program "hell nah" and trigger a seg fault.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,544
    milon posted the same thing on at least 2 other boards. He hasn't bothered to engage in a discussion on any of them.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Seriously though Salem, do you google their questions, have an automated script, or are you just the most active programming forum guy on Earth?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  2. Relocation in .obj -files
    By willkoh in forum C++ Programming
    Replies: 6
    Last Post: 04-06-2005, 01:59 PM
  3. Memory Address of Array Question
    By Zeusbwr in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 09:58 AM
  4. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM
  5. Direct disk access in DOS
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-26-2002, 01:52 PM

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