DWORD combined with a pointer + using this in a function

Posts 1–10 of 10 · Page 1 of 1
DWORD combined with a pointer + using this in a function
I have one question:

Example:

Code:
    #include<windows.h>
    #define playerpointer 0xABC12375
    
    int main()
    {
        DWORD DllThePointerIsStoredIn = (DWORD*)GetModuleHandleA("example.dll");
        DWORD playerPtr = *(DWORD*)(playerpointer);
    }


I found this in MPGH and why using a cast to convert a value to a pointer in DWORD for a function?

so thanks for answering (and thanks for the answer before)
edit: misread. removed.

Which line are you referring to?
(DWORD*)GetModuleHandleA("example.dll")
or
*(DWORD*)(playerpointer)
Quote Originally Posted by abuckau907 View Post
edit: misread. removed.

Which line are you referring to?
(DWORD*)GetModuleHandleA("example.dll")
or
*(DWORD*)(playerpointer)

(DWORD*)GetModuleHandleA("example.dll")
Handles returned from GetModuleHandle are not true handles. GetModuleHandle returns the image base of the loaded image.
Quote Originally Posted by Fovea View Post
Handles returned from GetModuleHandle are not true handles. GetModuleHandle returns the image base of the loaded image.
Ah maybe I see what he means...

DWORD DllThePointerIsStoredIn = (DWORD*)GetModuleHandleA("example.dll");

DWORD == DWORD*

How can a DWORD be set equal to a DWORD Pointer ? (without using dereference operator) I'd expect it to throw some type of "invalid asignment" error, but I don't know C++ very well.

edit:tested, and got compiler errors : /


If you're wondering what the return value of GetModuleHandleA() is / what it could be converted to



 
No Compiler Errors



@OP To answer your question, it's invalid code and won't compile. (?) Though I don't have much of an explanation for you, sry.
Ofc this won't work

and what is this meaning?

Code:
DWORD pWeaponMgr = *(DWORD*)(CShell + WeaponMgr);
I mean what does this *(DWORD*) mean?
Quote Originally Posted by Nik08154 View Post
and what is this meaning?

Code:
DWORD pWeaponMgr = *(DWORD*)(CShell + WeaponMgr);
I mean what does this *(DWORD*) mean?
Dereference a pointer, you get the value of what CShell+WeaponMgr points to
Quote Originally Posted by Nik08154 View Post
and what is this meaning?

Code:
DWORD pWeaponMgr = *(DWORD*)(CShell + WeaponMgr);
I mean what does this *(DWORD*) mean?
DWORD = Read 4 Bytes // use for pointer,example = 0x11223344
WORD = Read 2 Bytes // use for offset, expamle = 0x1122

these two values ​​is use to read information from memory
Quote Originally Posted by Nik08154 View Post
and what is this meaning?

Code:
DWORD pWeaponMgr = *(DWORD*)(CShell + WeaponMgr);
I mean what does this *(DWORD*) mean?
*(TYPE*) is a 2 step process. (and with Cshell + WeaponMgr; 3 steps)

In the example, DWORD pWeaponMgr = *(DWORD*) (an addr);

step 1. numeric add CShell + weaponMgr --> the result is simply a numeric : a memory address.
step 2. read an address from the location in step 1. If 32 bit cpu, read 4 bytes; if 64 bit, read 8 bytes.
--the value we read is ANOTHER MEMORY ADDRESS.
step 3. read a value from the addr we got in step 2

assuming CShell + WeaponMgr == some number, let's say 0x11223344

step 1. add CShell + weaponMgr == 0x11223344
step 2. (assuming 32 bit..as most current/old games were 32 bit) Read 4 bytes starting at 0x11223344
-Pretend those 4 bytes hold the value 0x22446688
step 3. Since we're going to store this in a DWORD, and dword size is 4 bytes, we read 4 bytes starting at 0x22446688

We dereferenced the pointer at 0x11223344 : ) The type inside *(TYPE*) dictates how many bytes are read from the final addr (22446688) in step 3.

big_struct myObj = *(big_struct*)0x11223344; would read a different number of bytes starting at 0x22446688.
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us