Results 1 to 11 of 11
  1. #1
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed

    Pointer Plus Dereferencer? [Solved]

    Ok, this is from kibbles aimbot tutorial and i have been building on it. I made an assault cube teleporter, but the only part i don't get is why when i make the class for the player i must do this to access the variables:


    Code:
    // player is the class
    player *me = *(player**)addie of player struct;

    I can understand the player *me part. It's just saying that me is going to be a pointer to the player class. I also understand that *().... is making a void pointer to something. What i don't understand is (player**)addie. I know it's dereferencing it, but why? I don't understand why it is needed to make a void pointer to the struct then dereference it. If anyone can explain this i would really appreciate it. THanks.

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    player *me needs to hold the player's data. Player's data is taken from a particular address using *(player**). How else you would have player's data in player *me ?

  3. The Following User Says Thank You to Hassan For This Useful Post:

    258456 (08-27-2011)

  4. #3
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Quote Originally Posted by Hassan View Post
    player *me needs to hold the player's data. Player's data is taken from a particular address using *(player**). How else you would have player's data in player *me ?
    Well what i don't understand is, why isn't *(player) enough? Why do you have to *(player**)?

  5. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by 258456 View Post
    Well what i don't understand is, why isn't *(player) enough? Why do you have to *(player**)?
    player** <- This is known as pointer-to-pointer. Where two asterisks show that two level of pointers are involved.

    Suppose you have two integers i and j. And two pointers x and y, that point to those integers. I can write this:

    [highlight=c]int **PointerToPointer;
    int i = 5, j = 10;
    int *ptint1 = &i;
    int *ptint2 = &j;[/highlight]

    Then I can assign PointerToPointer, the ptint1 pointer.

    [highlight=c]PointerToPointer = &ptint1;[/highlight]

    Now PointerToPointer points to ptint1 pointer, which in turn points to i [Value of 5].

    Now, if I write this:

    [highlight=c]PointerToPointer = &ptint2;[/highlight]

    I have changed the pointer pointed by PointerToPointer [Which was pointing at ptint1], to obtain a copy of ptint2, so that ptint1 now points at j [Value of 10] variable.

    PointerToPointer now references the pointer ptint1 and ptint1 references the variable i.

    So, your code uses two level of pointers to reach to the actual data, that the player class requires and then return the resulting pointer to the calling pointer variable that is; *me.

    If you still have confusion, feel free to ask.

  6. The Following User Says Thank You to Hassan For This Useful Post:

    258456 (08-27-2011)

  7. #5
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Quote Originally Posted by Hassan View Post


    player** <- This is known as pointer-to-pointer. Where two asterisks show that two level of pointers are involved.

    Suppose you have two integers i and j. And two pointers x and y, that point to those integers. I can write this:

    [highlight=c]int **PointerToPointer;
    int i = 5, j = 10;
    int *ptint1 = &i;
    int *ptint2 = &j;[/highlight]

    Then I can assign PointerToPointer, the ptint1 pointer.

    [highlight=c]PointerToPointer = &ptint1;[/highlight]

    Now PointerToPointer points to ptint1 pointer, which in turn points to i [Value of 5].

    Now, if I write this:

    [highlight=c]PointerToPointer = &ptint2;[/highlight]

    I have changed the pointer pointed by PointerToPointer [Which was pointing at ptint1], to obtain a copy of ptint2, so that ptint1 now points at j [Value of 10] variable.

    PointerToPointer now references the pointer ptint1 and ptint1 references the variable i.

    So, your code uses two level of pointers to reach to the actual data, that the player class requires and then return the resulting pointer to the calling pointer variable that is; *me.

    If you still have confusion, feel free to ask.

    so basically it's *(player) to say that i am making a void pointer to player, and then *(player*) means that i am making a void pointer to a player pointer, and then *(player**) means that i made a void pointer to a pointer to a player to another pointer. Lol, this is kind of confusing, but i think i understand it a little bit better.

  8. #6
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by 258456 View Post
    so basically it's *(player) to say that i am making a void pointer to player, and then *(player*) means that i am making a void pointer to a player pointer, and then *(player**) means that i made a void pointer to a pointer to a player to another pointer. Lol, this is kind of confusing, but i think i understand it a little bit better.
    Yes. I know this is confusing. Here's a very simple example that can help you understand it:

    [highlight=c]int **PointerToPointer;
    int i = 5, j = 10;
    int *ptint1 = &i;
    int *ptint2 = &j;
    PointerToPointer = &ptint1;
    cout << ptint1 << endl;
    cout << PointerToPointer << endl;
    cout << **PointerToPointer << endl;
    _getch();[/highlight]

    Here's the output of this:

    [highlight=c]0016FCB4 //Address of i variable.
    0016FC9C //Address of ptint1 (that points to variable i)
    5 //Using pointer to pointer to get the value stored in variable i[/highlight]

    Try playing with the above code. It will help you understand it better.
    Last edited by Hassan; 08-27-2011 at 07:06 PM.

  9. The Following User Says Thank You to Hassan For This Useful Post:

    258456 (08-27-2011)

  10. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    This:

    Code:
       *(player**)
    Is not making a void pointer, rather it's dereferencing a double level pointer (hence the player**), so basically it's gone up one level in the pointer, leaving you with just player*, rather than player**. The way I look at it is that the "pre-parenthesis" asterisks, cancel the asterisks inside the brackets, and if there is the same amount of "pre-parenthesis" asterisks, then you've dereferenced the whole thing.

    so:
    Code:
    *(player**) leaves you with a player*
    *(player***) leaves you with a player**
    **(player**) leaves you with a player
    **(player***) leaves you with a player*
    
    just like in this example:
    int *x = new int;
    *(int*)x = 15; //the int* cast was completely unnecessary here, but I used it to illustrate that complete deref occurred, and you're assigning the value of 15 to the base level int.
    Some more examples of multi-level pointers:
    [highlight=C]
    int *w = (int*)malloc(sizeof(int)); //sorry, C code. Can use "new int" if you want in C++.
    *w = 15; //dereference w and assign the value.
    int **x = &w; //second level pointer. pointer-to-pointer
    int ***y = &x; //move another level up. p2p2p now.
    int *z = **(int***)y; //dereference 2 levels of pointers, now back to p2p.
    *z = 20; //final dereference, back to base level. Assign 20.
    printf("%d\n", *w); //check whether x changed too after the multi-pointer deref.
    [/highlight]

    Hope that clarifies some stuff.
    Last edited by Jason; 08-27-2011 at 09:44 PM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  11. The Following User Says Thank You to Jason For This Useful Post:

    258456 (08-27-2011)

  12. #8
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Quote Originally Posted by Jason View Post
    This:

    Code:
       *(player**)
    Is not making a void pointer, rather it's dereferencing a double level pointer (hence the player**), so basically it's gone up one level in the pointer, leaving you with just player*, rather than player**. The way I look at it is that the "pre-parenthesis" asterisks, cancel the asterisks inside the brackets, and if there is the same amount of "pre-parenthesis" asterisks, then you've dereferenced the whole thing.

    so:
    Code:
    *(player**) leaves you with a player*
    *(player***) leaves you with a player**
    **(player**) leaves you with a player
    **(player***) leaves you with a player*
    
    just like in this example:
    int *x = new int;
    *(int*)x = 15; //the int* cast was completely unnecessary here, but I used it to illustrate that complete deref occurred, and you're assigning the value of 15 to the base level int.
    Some more examples of multi-level pointers:
    [highlight=C]
    int *w = (int*)malloc(sizeof(int)); //sorry, C code. Can use "new int" if you want in C++.
    *w = 15; //dereference w and assign the value.
    int **x = &w; //second level pointer. pointer-to-pointer
    int ***y = &x; //move another level up. p2p2p now.
    int *z = **(int***)y; //dereference 2 levels of pointers, now back to p2p.
    *z = 20; //final dereference, back to base level. Assign 20.
    printf("%d\n", *w); //check whether x changed too after the multi-pointer deref.
    [/highlight]

    Hope that clarifies some stuff.
    Oh ok, that makes more sense now. Thanks for that.

  13. #9
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    /Marked Solved. GJ Jason <3

  14. The Following User Says Thank You to Hassan For This Useful Post:

    258456 (08-27-2011)

  15. #10
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Quote Originally Posted by Hassan View Post
    /Marked Solved. GJ Jason <3
    GJ to you to Hassan. You and Jason are the most helpful people in this forum. I just saw the thread in which Liz was picking the new minion, and I gotta say, that nobody else stood a chance. No matter who posted there it was going to come down to you and Jason. Thanks a bunch guys, I really like what you've done with the C++ forum Hassan cuz now i can actually receive help to my problems and not flame. Congrats and thanks again Hassan and Jason.

  16. The Following User Says Thank You to 258456 For This Useful Post:

    Hassan (08-27-2011)

  17. #11
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Glad to be of use Started learning C this semester at Uni so I can actually help out with some C/C++ questions now.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

Similar Threads

  1. [Help] How to get the value of the address, a pointer is pointing at? [Solved]
    By Arnibold in forum C++/C Programming
    Replies: 12
    Last Post: 09-05-2011, 02:23 AM
  2. [Solved] Como colocar mais de um pointer.
    By GiroGun in forum Combat Arms BR Coding Help
    Replies: 0
    Last Post: 08-18-2011, 06:38 PM
  3. [Solved] Injector problem solved
    By NinjaKantana in forum CrossFire Help
    Replies: 1
    Last Post: 07-12-2011, 01:40 PM
  4. [Solved] my topic got closed but not solved!
    By Panda-kun in forum Call of Duty Black Ops Help
    Replies: 5
    Last Post: 06-15-2011, 05:28 PM
  5. [Solved] CAFlames and other hacks won't work... Solved
    By Hikatso in forum Combat Arms Help
    Replies: 17
    Last Post: 04-28-2011, 10:41 PM