Closed nymx closed 8 years ago
I don't think that replacing long by long long is the best way to solve the problem. I will try to find a proper way to adresse it.
For what it's worth, C++11 uses "unsigned long long int" rather than "unsigned long long" (even though I'm sure most compilers will probably support both equally.)
And, actually, if you're just talking about pointers and/or memory addresses, then replacing "unsigned long int" with "unsigned long long int" or "DWORD"/"uint" with "uint64_t", etc.. is probably all that's necessary (unless there are other things that need to be updated as well, of course.)
As far as I know, "long long" and "long long int" are the same. The first form is only a shortcut (like "long" and "long int"). DWORD and uint are not portable. And I don't want to impose 64-bits addresses in a 32-bits environment. I also want to avoid as much as possible ugly #ifdef, etc.
So can we just use void*? It's 4 bytes in 32bit and 8 bytes in 64bit.
void* is a pointer on data, not on code. So it is not portable enough (data and code pointers can have different sizes). My current try is something like:
using func_ptr_t = void(*)(); using func_ptr_integral = std::conditional<sizeof(func_ptr_t) == sizeof(long), long, long long>::type; func_ptrintegral f;
In other words, if a pointer to function has the same size than a long, it takes a long, otherwise a long long. Not 100% portable but I do not have other ideas for the moment.
I am checking that it is woking well on different platform and then I will publish an update.
Well according to C99 Spec, pointers can have different sizes. However flat memory model is widely used in different architectures. Either pointer to data or pointer to code has the same size. In addtion, the pointer to code can be 6 bytes or 4 bytes long, so personally I think the pointer size should be able to be specified by user or automatically set using tools like autoconf.
Fixed in the latest version. The actual integral type is determined at compile time (long or long long depending of the size of the code pointer)
This allows the obfuscated call mechanic to work in 64-bit mode.