SolvedReading pointers

Posts 16–22 of 22 · Page 2 of 2
You're not doing it right, the pointer is read before the offset is added so you don't enclose the two within the brackets. Also note that LPWSTR and wchar_t* are the exact same thing

Code:
DWORD address = (DWORD)GetModuleHandle("AVA.exe") + 0x01BFC478;
address = *(DWORD*)address + 0x90;
address = *(DWORD*)address + 0x24;
LPWSTR value = (LPWSTR)address;
WOW! You are a genius!

But still, I don't understand what's the difference between my code and yours. Maybe if I'll look at it some more I'll know.

OK, now I understand what my problem was! But why the second parameter of the function MessageBox requires a pointer?
When we simply write a string to it, it accepts it without a question...
Quote Originally Posted by Jabberwock View Post
WOW! You are a genius!

But still, I don't understand what's the difference between my code and yours. Maybe if I'll look at it some more I'll know.

OK, now I understand what my problem was! But why the second parameter of the function MessageBox requires a pointer?
When we simply write a string to it, it accepts it without a question...
Erm no, the MessageBox bit was essentially the same, you were reading the pointers wrong. In your code, you added the offset before reading the pointer which screwed things up...

As for modifying the value for the address, try this:
Code:
*(wchar_t*)address = L"dfdf";
Note the double-quote, you used a single quote which might be the reason why only 1 character was appearing.
With your code I got an error "error C2440: '=' : cannot convert from 'const wchar_t [5]' to 'wchar_t'".

As I said before I tried the following:
Code:
*(wchar_t*)address = *(wchar_t*)L"dfdf";
It only changes the first letter.
And you got it wrong, I didn't say only 1 character was appearing. I said only 1 character was modified.

So if the word was: "abcdefg".
It became: "dbcdefg".

I think I figured it out myself. When I try to do:

Code:
*(wchar_t*)address = L'w';
*(wchar_t*)(address+2) = L'x';
*(wchar_t*)(address+4) = L'y';
Then "abcdefg" become "wxydefg".
Is there a more elegant method for this?
Could it be that when writing a string, the return type of it is a pointer?
What with an int type? Is it the same?

And what if I want to change the content of the pointer?

If I simply write:

Code:
DWORD address = (DWORD)GetModuleHandle("AVA.exe") + 0x01BFC478;
address = *(DWORD*)address + 0x90;
address = *(DWORD*)address + 0x24;
*(wchar_t*)address = L'dfdf';
It doesn't change to the whole word. Only the first letter changes.
And this does the same:

Code:
DWORD address = (DWORD)GetModuleHandle("AVA.exe") + 0x01BFC478;
address = *(DWORD*)address + 0x90;
address = *(DWORD*)address + 0x24;
*(wchar_t*)address = *(wchar_t*)L"dfdf";
Maybe it's like an array. But I'm not sure how to do it.
My bad, try this, I've tested it and it works:
Code:
*(wchar_t**)address = L"dfdf";
This is because previously, when we derefenced the pointer, it became a wchar_t, but what we really want to do it write an array of wchar_t which is why the extra * is needed since each * cancels each other out. It's hard to explain but it should work.
With that it's doing something strange. The first two letters became two squares. But don't worry about it now. I can make a function for this problem so it's marked as fixed for me.

You can close the thread now.
Posts 16–22 of 22 · Page 2 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us