diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-09-19 13:22:28 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-09-19 13:22:28 +0200 |
| commit | bfd9f79267156c71e2451b847a89479941a98d3b (patch) | |
| tree | c1c3fc1ed3a4d93806b8b0d75041223fb269db52 /src | |
| parent | f7c596317bf6f08f687f696ed16f394384e01abd (diff) | |
| download | box64-bfd9f79267156c71e2451b847a89479941a98d3b.tar.gz box64-bfd9f79267156c71e2451b847a89479941a98d3b.zip | |
[WRAPPER] Some rework on a few wrapped function foor glib2, libxcb and libxcb-private
Diffstat (limited to 'src')
| -rw-r--r-- | src/include/bridge.h | 1 | ||||
| -rw-r--r-- | src/tools/bridge.c | 21 | ||||
| -rw-r--r-- | src/wrapped/generated/functions_list.txt | 2 | ||||
| -rw-r--r-- | src/wrapped/generated/wrapper.c | 4 | ||||
| -rw-r--r-- | src/wrapped/generated/wrapper.h | 2 | ||||
| -rw-r--r-- | src/wrapped/wrappedglib2.c | 61 | ||||
| -rw-r--r-- | src/wrapped/wrappedlibxcb_private.h | 2 | ||||
| -rw-r--r-- | src/wrapped/wrappedlibxcbxinput_private.h | 6 |
8 files changed, 50 insertions, 49 deletions
diff --git a/src/include/bridge.h b/src/include/bridge.h index a01a5b67..8a760939 100644 --- a/src/include/bridge.h +++ b/src/include/bridge.h @@ -16,6 +16,7 @@ uintptr_t AddCheckBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const uintptr_t AddAutomaticBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, const char* name); void* GetNativeFnc(uintptr_t fnc); void* GetNativeFncOrFnc(uintptr_t fnc); +void* GetNativeOrAlt(void* fnc, void* alt); uintptr_t AddVSyscall(bridge_t* bridge, int num); diff --git a/src/tools/bridge.c b/src/tools/bridge.c index 1c5bde99..23b3a728 100644 --- a/src/tools/bridge.c +++ b/src/tools/bridge.c @@ -155,22 +155,22 @@ uintptr_t AddAutomaticBridge(bridge_t* bridge, wrapper_t w, void* fnc, int N, co return ret; } -void* GetNativeFnc(uintptr_t fnc) +void* GetNativeOrAlt(void* fnc, void* alt) { if(!fnc) return NULL; // check if function exist in some loaded lib - if(!FindElfAddress(my_context, fnc)) { + if(!FindElfAddress(my_context, (uintptr_t)fnc)) { Dl_info info; - if(dladdr((void*)fnc, &info)) - return (void*)fnc; + if(dladdr(fnc, &info)) + return fnc; } - if(!getProtection(fnc)) - return NULL; + if(!getProtection((uintptr_t)fnc)) + return alt; // check if it's an indirect jump #define PK(a) *(uint8_t*)(fnc+a) #define PK32(a) *(uint32_t*)(fnc+a) if(PK(0)==0xff && PK(1)==0x25) { // "absolute" jump, maybe the GOT (it's a RIP+relative in fact) - uintptr_t a1 = fnc+6+(PK32(2)); // need to add a check to see if the address is from the GOT ! + uintptr_t a1 = (uintptr_t)fnc+6+(PK32(2)); // need to add a check to see if the address is from the GOT ! a1 = *(uintptr_t*)a1; if(a1 && a1>0x10000) { a1 = (uintptr_t)GetNativeFnc(a1); @@ -183,10 +183,13 @@ void* GetNativeFnc(uintptr_t fnc) // check if bridge exist onebridge_t *b = (onebridge_t*)fnc; if(b->CC != 0xCC || b->S!='S' || b->C!='C' || (b->C3!=0xC3 && b->C3!=0xC2)) - return NULL; // not a bridge?! + return alt; // not a bridge?! return (void*)b->f; } - +void* GetNativeFnc(uintptr_t fnc) +{ + return GetNativeOrAlt((void*)fnc, NULL); +} void* GetNativeFncOrFnc(uintptr_t fnc) { onebridge_t *b = (onebridge_t*)fnc; diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index 820c548a..150f8924 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -115,6 +115,7 @@ #() SFv #() HFi #() HFp +#() HFH #() xFx #() XFX #() YFY @@ -359,7 +360,6 @@ #() HFII #() HFll #() HFpi -#() HFpp #() xFxx #() XFXX #() YFYY diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c index a4c7b375..03523e26 100644 --- a/src/wrapped/generated/wrapper.c +++ b/src/wrapped/generated/wrapper.c @@ -162,6 +162,7 @@ typedef void* (*pFb_t)(void*); typedef void* (*SFv_t)(void); typedef unsigned __int128 (*HFi_t)(int32_t); typedef unsigned __int128 (*HFp_t)(void*); +typedef unsigned __int128 (*HFH_t)(unsigned __int128); typedef complexf_t (*xFx_t)(complexf_t); typedef complex_t (*XFX_t)(complex_t); typedef void (*vWp_t)(void*); @@ -396,7 +397,6 @@ typedef void* (*SFpp_t)(void*, void*); typedef unsigned __int128 (*HFII_t)(int64_t, int64_t); typedef unsigned __int128 (*HFll_t)(intptr_t, intptr_t); typedef unsigned __int128 (*HFpi_t)(void*, int32_t); -typedef unsigned __int128 (*HFpp_t)(void*, void*); typedef complexf_t (*xFxx_t)(complexf_t, complexf_t); typedef complex_t (*XFXX_t)(complex_t, complex_t); typedef int32_t (*iWpi_t)(void*, int32_t); @@ -3367,6 +3367,7 @@ void pFb(x64emu_t *emu, uintptr_t fcn) { pFb_t fn = (pFb_t)fcn; void *aligned_xc void SFv(x64emu_t *emu, uintptr_t fcn) { SFv_t fn = (SFv_t)fcn; R_RAX=(uintptr_t)io_convert_back(fn()); } void HFi(x64emu_t *emu, uintptr_t fcn) { HFi_t fn = (HFi_t)fcn; unsigned __int128 u128 = fn((int32_t)R_RDI); R_RAX=(u128&0xFFFFFFFFFFFFFFFFL); R_RDX=(u128>>64)&0xFFFFFFFFFFFFFFFFL; } void HFp(x64emu_t *emu, uintptr_t fcn) { HFp_t fn = (HFp_t)fcn; unsigned __int128 u128 = fn((void*)R_RDI); R_RAX=(u128&0xFFFFFFFFFFFFFFFFL); R_RDX=(u128>>64)&0xFFFFFFFFFFFFFFFFL; } +void HFH(x64emu_t *emu, uintptr_t fcn) { HFH_t fn = (HFH_t)fcn; unsigned __int128 u128 = fn((unsigned __int128)R_RDI + ((unsigned __int128)R_RSI << 64)); R_RAX=(u128&0xFFFFFFFFFFFFFFFFL); R_RDX=(u128>>64)&0xFFFFFFFFFFFFFFFFL; } void xFx(x64emu_t *emu, uintptr_t fcn) { xFx_t fn = (xFx_t)fcn; from_complexf(emu, fn(to_complexf(emu, 0))); } void XFX(x64emu_t *emu, uintptr_t fcn) { XFX_t fn = (XFX_t)fcn; from_complex(emu, fn(to_complex(emu, 0))); } void vWp(x64emu_t *emu, uintptr_t fcn) { vWp_t fn = (vWp_t)fcn; fn((void*)R_RCX); } @@ -3601,7 +3602,6 @@ void SFpp(x64emu_t *emu, uintptr_t fcn) { SFpp_t fn = (SFpp_t)fcn; R_RAX=(uintpt void HFII(x64emu_t *emu, uintptr_t fcn) { HFII_t fn = (HFII_t)fcn; unsigned __int128 u128 = fn((int64_t)R_RDI, (int64_t)R_RSI); R_RAX=(u128&0xFFFFFFFFFFFFFFFFL); R_RDX=(u128>>64)&0xFFFFFFFFFFFFFFFFL; } void HFll(x64emu_t *emu, uintptr_t fcn) { HFll_t fn = (HFll_t)fcn; unsigned __int128 u128 = fn((intptr_t)R_RDI, (intptr_t)R_RSI); R_RAX=(u128&0xFFFFFFFFFFFFFFFFL); R_RDX=(u128>>64)&0xFFFFFFFFFFFFFFFFL; } void HFpi(x64emu_t *emu, uintptr_t fcn) { HFpi_t fn = (HFpi_t)fcn; unsigned __int128 u128 = fn((void*)R_RDI, (int32_t)R_RSI); R_RAX=(u128&0xFFFFFFFFFFFFFFFFL); R_RDX=(u128>>64)&0xFFFFFFFFFFFFFFFFL; } -void HFpp(x64emu_t *emu, uintptr_t fcn) { HFpp_t fn = (HFpp_t)fcn; unsigned __int128 u128 = fn((void*)R_RDI, (void*)R_RSI); R_RAX=(u128&0xFFFFFFFFFFFFFFFFL); R_RDX=(u128>>64)&0xFFFFFFFFFFFFFFFFL; } void xFxx(x64emu_t *emu, uintptr_t fcn) { xFxx_t fn = (xFxx_t)fcn; from_complexf(emu, fn(to_complexf(emu, 0), to_complexf(emu, 1))); } void XFXX(x64emu_t *emu, uintptr_t fcn) { XFXX_t fn = (XFXX_t)fcn; from_complex(emu, fn(to_complex(emu, 0), to_complex(emu, 2))); } void iWpi(x64emu_t *emu, uintptr_t fcn) { iWpi_t fn = (iWpi_t)fcn; R_RAX=(int32_t)fn((void*)R_RCX, (int32_t)R_RDX); } diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h index 17acf119..c91b5345 100644 --- a/src/wrapped/generated/wrapper.h +++ b/src/wrapped/generated/wrapper.h @@ -152,6 +152,7 @@ void pFb(x64emu_t *emu, uintptr_t fnc); void SFv(x64emu_t *emu, uintptr_t fnc); void HFi(x64emu_t *emu, uintptr_t fnc); void HFp(x64emu_t *emu, uintptr_t fnc); +void HFH(x64emu_t *emu, uintptr_t fnc); void xFx(x64emu_t *emu, uintptr_t fnc); void XFX(x64emu_t *emu, uintptr_t fnc); void YFY(x64emu_t *emu, uintptr_t fnc); @@ -396,7 +397,6 @@ void SFpp(x64emu_t *emu, uintptr_t fnc); void HFII(x64emu_t *emu, uintptr_t fnc); void HFll(x64emu_t *emu, uintptr_t fnc); void HFpi(x64emu_t *emu, uintptr_t fnc); -void HFpp(x64emu_t *emu, uintptr_t fnc); void xFxx(x64emu_t *emu, uintptr_t fnc); void XFXX(x64emu_t *emu, uintptr_t fnc); void YFYY(x64emu_t *emu, uintptr_t fnc); diff --git a/src/wrapped/wrappedglib2.c b/src/wrapped/wrappedglib2.c index 0917ed42..ea534019 100644 --- a/src/wrapped/wrappedglib2.c +++ b/src/wrapped/wrappedglib2.c @@ -175,28 +175,27 @@ SUPER() #undef GO // then the static functions callback that may be used with the structure, but dispatch also have a callback... #define GO(A) \ -static uintptr_t fct_funcs_prepare_##A = 0; \ -static int my_funcs_prepare_##A(void* source, int *timeout_) { \ - return (int)RunFunctionFmt(fct_funcs_prepare_##A, "pp", source, timeout_); \ -} \ -static uintptr_t fct_funcs_check_##A = 0; \ -static int my_funcs_check_##A(void* source) { \ - return (int)RunFunctionFmt(fct_funcs_check_##A, "p", source); \ -} \ -static uintptr_t fct_funcs_dispatch_cb_##A = 0; \ -static int my_funcs_dispatch_cb_##A(void* a, void* b, void* c, void* d) { \ - return (int)RunFunctionFmt(fct_funcs_dispatch_cb_##A, "pppp", a, b, c, d); \ -} \ -static uintptr_t fct_funcs_dispatch_##A = 0; \ -static int my_funcs_dispatch_##A(void* source, void* cb, void* data) { \ - uintptr_t old = fct_funcs_dispatch_cb_##A; \ - fct_funcs_dispatch_cb_##A = (uintptr_t)cb; \ - return (int)RunFunctionFmt(fct_funcs_dispatch_##A, "ppp", source, cb?my_funcs_dispatch_cb_##A:NULL, data); \ - fct_funcs_dispatch_cb_##A = old; \ -} \ -static uintptr_t fct_funcs_finalize_##A = 0; \ -static int my_funcs_finalize_##A(void* source) { \ - return (int)RunFunctionFmt(fct_funcs_finalize_##A, "p", source); \ +static int my_funcs_prepare_##A(void* source, int *timeout_) { \ + return (int)RunFunctionFmt((uintptr_t)ref_gsourcefuncs_##A->prepare, "pp", source, timeout_); \ +} \ +static uintptr_t fct_funcs_check_##A = 0; \ +static int my_funcs_check_##A(void* source) { \ + return (int)RunFunctionFmt((uintptr_t)ref_gsourcefuncs_##A->check, "p", source); \ +} \ +static uintptr_t fct_funcs_dispatch_cb_##A = 0; \ +static int my_funcs_dispatch_cb_##A(void* a, void* b, void* c, void* d) { \ + return (int)RunFunctionFmt(fct_funcs_dispatch_cb_##A, "pppp", a, b, c, d); \ +} \ +static uintptr_t fct_funcs_dispatch_##A = 0; \ +static int my_funcs_dispatch_##A(void* source, void* cb, void* data) { \ + uintptr_t old = fct_funcs_dispatch_cb_##A; \ + fct_funcs_dispatch_cb_##A = (uintptr_t)cb; \ + return (int)RunFunctionFmt((uintptr_t)ref_gsourcefuncs_##A->dispatch, "ppp", source, cb?my_funcs_dispatch_cb_##A:NULL, data); \ + fct_funcs_dispatch_cb_##A = old; \ +} \ +static uintptr_t fct_funcs_finalize_##A = 0; \ +static int my_funcs_finalize_##A(void* source) { \ + return (int)RunFunctionFmt((uintptr_t)ref_gsourcefuncs_##A->finalize, "p", source); \ } SUPER() #undef GO @@ -207,16 +206,14 @@ static my_GSourceFuncs_t* findFreeGSourceFuncs(my_GSourceFuncs_t* fcts) #define GO(A) if(ref_gsourcefuncs_##A == fcts) return &my_gsourcefuncs_##A; SUPER() #undef GO - #define GO(A) if(ref_gsourcefuncs_##A == 0) { \ - ref_gsourcefuncs_##A = fcts; \ - my_gsourcefuncs_##A.prepare = (fcts->prepare)?((GetNativeFnc((uintptr_t)fcts->prepare))?GetNativeFnc((uintptr_t)fcts->prepare):my_funcs_prepare_##A):NULL; \ - fct_funcs_prepare_##A = (uintptr_t)fcts->prepare; \ - my_gsourcefuncs_##A.check = (fcts->check)?((GetNativeFnc((uintptr_t)fcts->check))?GetNativeFnc((uintptr_t)fcts->check):my_funcs_check_##A):NULL; \ - fct_funcs_check_##A = (uintptr_t)fcts->check; \ - my_gsourcefuncs_##A.dispatch = (fcts->dispatch)?((GetNativeFnc((uintptr_t)fcts->dispatch))?GetNativeFnc((uintptr_t)fcts->dispatch):my_funcs_dispatch_##A):NULL; \ - fct_funcs_dispatch_##A = (uintptr_t)fcts->dispatch; \ - my_gsourcefuncs_##A.finalize = (fcts->finalize)?((GetNativeFnc((uintptr_t)fcts->finalize))?GetNativeFnc((uintptr_t)fcts->finalize):my_funcs_finalize_##A):NULL; \ - fct_funcs_finalize_##A = (uintptr_t)fcts->finalize; \ + #define GO(A) if(ref_gsourcefuncs_##A == 0) { \ + ref_gsourcefuncs_##A = fcts; \ + my_gsourcefuncs_##A.closure = fcts->closure; \ + my_gsourcefuncs_##A.marshal = fcts->marshal; \ + my_gsourcefuncs_##A.prepare = (fcts->prepare)?GetNativeOrAlt(fcts->prepare, my_funcs_prepare_##A):NULL; \ + my_gsourcefuncs_##A.check = (fcts->check)?GetNativeOrAlt(fcts->check, my_funcs_check_##A):NULL; \ + my_gsourcefuncs_##A.dispatch = (fcts->dispatch)?GetNativeOrAlt(fcts->dispatch, my_funcs_dispatch_##A):NULL; \ + my_gsourcefuncs_##A.finalize = (fcts->finalize)?GetNativeOrAlt(fcts->finalize, my_funcs_finalize_##A):NULL; \ return &my_gsourcefuncs_##A; \ } SUPER() diff --git a/src/wrapped/wrappedlibxcb_private.h b/src/wrapped/wrappedlibxcb_private.h index 9c43273b..f3cb01e5 100644 --- a/src/wrapped/wrappedlibxcb_private.h +++ b/src/wrapped/wrappedlibxcb_private.h @@ -417,7 +417,7 @@ GO(xcb_poly_arc, pFbuuup) //GO(xcb_poly_fill_arc_checked, //GO(xcb_poly_fill_arc_sizeof, GO(xcb_poly_fill_rectangle, pFbuuup) -//GO(xcb_poly_fill_rectangle_checked, +GO(xcb_poly_fill_rectangle_checked, pFbuuup) //GO(xcb_poly_fill_rectangle_rectangles, //GO(xcb_poly_fill_rectangle_rectangles_iterator, //GO(xcb_poly_fill_rectangle_rectangles_length, diff --git a/src/wrapped/wrappedlibxcbxinput_private.h b/src/wrapped/wrappedlibxcbxinput_private.h index 57325506..993fc235 100644 --- a/src/wrapped/wrappedlibxcbxinput_private.h +++ b/src/wrapped/wrappedlibxcbxinput_private.h @@ -335,7 +335,7 @@ GO(xcb_input_xi_query_version, uFbWW) GO(xcb_input_xi_query_version_reply, pFbup) //GO(xcb_input_button_class_state, GO(xcb_input_button_class_labels_length, iFp) -GO(xcb_input_button_class_labels_end, pFp) +GO(xcb_input_button_class_labels_end, HFp) GO(xcb_input_button_class_labels, pFp) //GO(xcb_input_button_class_next, //GO(xcb_input_button_class_end, @@ -359,14 +359,14 @@ GO(xcb_input_button_class_labels, pFp) //GO(xcb_input_device_class_data_serialize, //GO(xcb_input_device_class_data_unpack, GO(xcb_input_device_class_next, vFp) -GO(xcb_input_device_class_end, HFpp) +GO(xcb_input_device_class_end, HFH) GO(xcb_input_xi_device_info_classes_length, iFp) GO(xcb_input_xi_device_info_classes_iterator, HFp) GO(xcb_input_xi_device_info_name, pFp) GO(xcb_input_xi_device_info_name_length, iFp) GO(xcb_input_xi_device_info_name_end, pFp) GO(xcb_input_xi_device_info_next, vFp) -GO(xcb_input_xi_device_info_end, HFpp) +GO(xcb_input_xi_device_info_end, HFH) GO(xcb_input_xi_query_device, uFbu) GO(xcb_input_xi_query_device_unchecked, uFbu) GO(xcb_input_xi_query_device_infos_length, iFp) |