rwfpl / rewolf-wow64ext

Helper library for x86 programs that runs under WOW64 layer on x64 versions of Microsoft Windows operating systems.
936 stars 299 forks source link

Restore support for pseudo handles #22

Closed m417z closed 2 years ago

m417z commented 2 years ago

As @injertao noticed here, my previous change broke support for pseudo handles.

therealdreg commented 2 years ago

good catch! and good fix!

Thx @m417z & @injertao

@rwfpl , Do you think we could release a new version with these changes? IMO LAA support its a good feature :-)

therealdreg commented 2 years ago

btw @m417z

jfyi pointer <--> integer is implementation defined, So take a look: sptr, uptr

https://docs.microsoft.com/en-us/cpp/cpp/sptr-uptr

m417z commented 2 years ago

In this case, the pointer is first converted to an integer of the same size, so there's no pointer to integer (sign or zero) extension. I think it's OK.

therealdreg commented 2 years ago

In this case, the pointer is first converted to an integer of the same size, so there's no pointer to integer (sign or zero) extension. I think it's OK.

I will try to explain myself better,

As I said pointer <--> integer conversion is implementation defined. HANDLE is **void***. The reason to use things like sptr or uptr is to be explicit about the conversion you are doing. But I am ok with your way, it was a jfyi comment :-)

therealdreg commented 2 years ago

My english sucks. So here an example:

/* compile as x86 32 bits program */
#include <stdio.h>
#include <stdint.h>

int main(void)
{
    void* ptr = (void*) 0xFFFFFFFF;
    int64_t val1 = ptr; // in VC val1 = 0xffffffffffffffff
    int64_t val2 = (void* __ptr32 __uptr) ptr; // in VC val2 = 0x00000000ffffffff
    int64_t val3 = (void* __ptr32 __sptr) ptr; // in VC val3 = 0xffffffffffffffff
    printf("val1 0x%016llx default\nval2 0x%016llx (void* __ptr32 __uptr)\nval3 0x%016llx (void* __ptr32 __sptr)\n", val1, val2, val3);

    return 0;
}

Output:

val1 0xffffffffffffffff default
val2 0x00000000ffffffff (void* __ptr32 __uptr)
val3 0xffffffffffffffff (void* __ptr32 __sptr)

IMO is better than your way:

((DWORD64)(LONG_PTR)(p))

Because with sptr/uptr I am being explicit about the SIGN conversion (no weird double cast + a comment to explaing why)

But please, keep your code as is

Dont worry, it was a jfyi comment x-)

therealdreg commented 2 years ago

@rwfpl can you merge this PR-fix please?