PDA

View Full Version : Void* x64 to 32bit integer, without loss of precision (last 4 bytes of 64bit offset)


freesoul
April 11th, 2012, 11:36
How can I do this? I have 64bit cpu and I need last 4 bytes of this offset to an unsigned long, I tried casting etc but i always get loss of precision in last 2 bytes
what can i do? thanks pd. my application MUST be x86

thanks

disavowed
April 11th, 2012, 14:17
If you're compiling for x86 then the void* is already 32-bits.

Extremist
April 11th, 2012, 17:37
^^
There's that... but if compiling for 64-bit (assuming little endian):

__int32 foo = * (__int32 *) &x64;

freesoul
April 12th, 2012, 06:16
You're right disawowed, however, i don't know why im getting loss of precision in the void* to long casting :S

Darkelf
April 12th, 2012, 09:17
Just use ULONG_PTR instead of long.
See here:

http://msdn.microsoft.com/en-us/library/cc230394(v=prot.10).aspx

and here:

http://msdn.microsoft.com/en-us/library/aa384255(v=vs.85).aspx

Hope that helps

Regards
darkelf

freesoul
April 12th, 2012, 10:03
Thaks for reply, but i still getting the same result:

2577

See how z =/= loadDll_end and zvoid =/=loadDll_end

Also I've to say that loadDll_end is __declspec(naked) void loadDll_end() { }

+ im in debug mode

Darkelf
April 12th, 2012, 16:59
Would you be so kind as to tell us the error/warning number?

Additionally try your example with the "PtrToUlong" macro.

Something like:

Code:

ULONG z = PtrToUlong(loadDLL_end);


Regards
darkelf

disavowed
April 16th, 2012, 23:50
You're not losing precision. One of those two addresses is a jmp to the other one (check the disassembly if you don't believe me). Change to release mode and you won't have that problem.