C/C++ question
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: C/C++ question

  1. #1
    Senior Member
    Join Date
    Jun 2003
    Posts
    772

    C/C++ question

    Is there a way in C/C++ to put code explicitly at a specified memory adress (code to be executed)? Does that have to be shellcode? (Stack or heap doesn't matter)
    (In windows)
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

    www.elhalf.com

  2. #2
    A few tutorials for specific memory handling in C and C++, both Windows and nix based.

    http://www.cpp-home.com/tutorial.php?16_4

    http://atrevida.comprenica.com/atrtut04.html

    http://www.juicystudio.com/tutorial/cpp/index.asp


    edit: fixed links

  3. #3
    Senior Member
    Join Date
    Jun 2003
    Posts
    772
    Thanks alot!

    I tried using it in its most simple way:
    Code:
    #include <dos.h>
    
    void pokeb (unsigned int segment, unsigned int offset, char value);
    
    int main() {
    
      pokeb (0x760F, 0x00AE, 125);
    
     return 0;
      
    }
    (From the 2nd link)

    But when linking this error occurs (Borland C++ 5.5):

    Error: Unresolved external 'pokeb(unsigned int, unsigned int, char)' referenced
    from C:\WINDOWS\DESKTOP\UNTITLED.OBJ

    Do I have to link it with another file or something?
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

    www.elhalf.com

  4. #4
    Try:

    #include <iostream.h>
    int main()
    {
    int x; //A normal integer
    int *pointer; //A pointer to an integer
    pointer=&x; //Read it, "pointer equals the address of x"
    cin>>x; //Reads in x
    cout<<*pointer; //Note the use of the * to output the actual number stored in x
    return 0;
    }

    That's as simple as it can get, honestly. If the problem still occurs, not sure what to say, as I am a visual .net user, being unfamiliar with borland.

  5. #5
    Senior Member
    Join Date
    Jun 2003
    Posts
    772
    Yes, but here you rely on the adress of x, I want to write explicitly to an adress I chose.
    But thx anyway
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

    www.elhalf.com

  6. #6
    So have x == your memory address and define a variable each time?

  7. #7
    Senior Member
    Join Date
    Jun 2003
    Posts
    772
    A yes /me slaps self lol, thanks pooh sun tzu

    EDIT:

    I created 2 proggies:

    Program 1:
    Code:
    #include <iostream.h>
    
    int i = 2;
    
    int main()
    {
    cout << &i;
    int stuff;
    cin >> stuff;
    
    return 0;
    }
    Program 2:
    Code:
    #include <iostream.h>
    
    int main() {
    
      int *pointer;
      pointer = (int*)0x0041C178;
      cout << "Value1: " << *pointer << endl;  /*<- this is supposed to print  the value of i from program 1*/ 
    *pointer = 3;                                                           
      cout << "Value2: " << *pointer;
      return 0;
    }
    Now, what I want to do is modify the value of i in program 2.
    So I run program 1 which shows the adress of where i is stored.
    The variable i stays in memory right? I use cin to pause the program (yes I know, stupid way but I don't know any other (yet)).
    Thus in program 2 I create a pointer to that adress. But whenthe it displays the value of that location it is not the value of i from program 1 which is still running. In this case it is 0 (with me). If I declare the integer in program 1 inside main() it's some number like 570577 (something like that).
    Anyone know what is wrong with this?

    EDIT2:
    I know this is supposed to be impossible as the kernel (should) manages memory and thus that memory adress would normally be protected as it is already in use.
    But these programs run without any errors and it's clearly not some form of shared memory (Win98)
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

    www.elhalf.com

  8. #8
    just out of curiousity why do you want to write to a specific address?
    and why not use assembly?
    and I only mean that it's faster and more direct.

  9. #9
    Junior Member
    Join Date
    Feb 2004
    Posts
    5
    i'm not sure why u would need to do that but it has been my exp. that c/c++ has no way to write data to a exat mem adderss because the os loads the program and then a var are offset to the start of the program

    but how about this i'm not at home right now i will look though my commads book for c++ and see if there is that i didn't think of.

    u could alway write it in assembly most c++ compiler will let u write a function in ASM(assmbly)
    :-) Raven :-)

  10. #10
    Well Im pretty noobyish at both assembly and c++ but one of the reasons I could think of was that person wanted to execute code affecting the memory would be @ h04 or h20 and that would be for the purposes of a .com virus replicating it self. But that would be indiginious to intel family 86 cpu's only , dont know about amd.

    and thats not to say what hes thinking of, becuase im sure that there are other good reasons for accessing memory directly with a program in c++,like cleaning it same thing that reg edit does...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •