[ASM][c++] problem with asm address

12/30/2016 00:17 forsatus#1
Hi, i got a problem with the variable DWORD when i use asm

Code:
DWORD dwSendFunction = PathernSendFunc();
	DWORD tmp = PathernNetwork();

	__asm
	{
		MOV EAX, DWORD PTR DS : [tmp]
		MOV EAX, DWORD PTR DS : [EAX]
		MOV EDX, szPacket
		CALL dwSendFunction
	}
The pathern return the good value, but nostale crash.
I also trie to put value like this :

Code:
DWORD dwSendFunction = 0x00518AC4;
	DWORD tmp = 0x0069630C;

	__asm
	{
		MOV EAX, DWORD PTR DS : [tmp]
		MOV EAX, DWORD PTR DS : [EAX]
		MOV EDX, szPacket
		CALL dwSendFunction
	}
And same, nostale crash it work only when i use it

Code:
#define tmp 0x0069630C
#define dwSendFunction 0x00518AC4
Thanks in advance ;)
12/30/2016 00:34 xopy#2
Quote:
Originally Posted by forsatus View Post
Hi, i got a problem with the variable DWORD when i use asm

DWORD dwSendFunction = PathernSendFunc();
DWORD tmp = PathernNetwork();

__asm
{
MOV EAX, DWORD PTR DS : [tmp]
MOV EAX, DWORD PTR DS : [EAX]
MOV EDX, szPacket
CALL dwSendFunction
}

...

Thanks in advance ;)
it's logical because you are referencing here not of the values themselves.
12/30/2016 02:14 forsatus#3
Quote:
Originally Posted by xopy View Post
it's logical because you are referencing here not of the values themselves.
i don't understand what you mean
12/30/2016 02:29 Jeoni#4
With
Code:
DWORD tmp = PathernNetwork();
there is a part of memory somewhere that holds 4 byte (some address).
If you now execute
Code:
MOV EAX, DWORD PTR DS : [tmp]
you access that part of the memory and read it. So the content (value) of tmp is put into eax. With
Code:
MOV EAX, DWORD PTR DS : [EAX]
you're dereferencing and read the content located at the address specified by eax (which is the value of tmp). So on this part what you now did translated to C pseudocode is
Code:
eax = *(DWORD*)tmp
or
Code:
eax = *(DWORD*)PathernNetwork()
.

Now let's take a look why it works with defines. Defines does not translate to variables, so are not actually located somewhere in the memory. Instead it's like a synonym for the thing defined (addresses in this case). So with
Code:
MOV EAX, DWORD PTR DS : [tmp]
you're not accessing a variable first but directly dereferencing the "target" address. With the second dereferencation with
Code:
MOV EAX, DWORD PTR DS : [EAX]
you'd get something like this in pseudocode:
Code:
eax = **(DWORD**)tmp
(note that tmp is the define now not a variable) or
Code:
eax = **(DWORD**)0x0069630C
.

I guess you see the difference? One dereferencation. That's easy to fix, the solution is trivial and I hope you don't need spoonfeeding after this detailed explanation? ;)
With best regards
Jeoni
12/30/2016 03:21 forsatus#5
Ok, it's a stupid error xD
Thanks to help me to see the error, know i understand how to work the DR

#closerequest