From 541489da4d67e8a2d41d3b88a79daf7608fb4b89 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 28 Sep 2024 13:48:08 +0200 Subject: [BOX32][WRAPPER] Some fixes to libexpat 32bits wrapping and more other 32bits functions --- src/wrapped32/generated/functions_list.txt | 5 +- src/wrapped32/generated/wrappedexpattypes32.h | 4 +- src/wrapped32/generated/wrapper32.c | 7 +- src/wrapped32/generated/wrapper32.h | 3 +- src/wrapped32/wrappedexpat.c | 148 +++++++++++++++++++++----- src/wrapped32/wrappedexpat_private.h | 2 +- src/wrapped32/wrappedlibc_private.h | 10 +- 7 files changed, 142 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt index 37c2a21e..bdd2146d 100644 --- a/src/wrapped32/generated/functions_list.txt +++ b/src/wrapped32/generated/functions_list.txt @@ -364,7 +364,6 @@ #() uFuuu -> uFuuu #() uFuup -> uFuup #() uFupp -> uFupp -#() uFpii -> uFpii #() uFpuU -> uFpuU #() uFppu -> uFppu #() fFuii -> fFuii @@ -420,6 +419,7 @@ #() iFBp_pi -> iFBpi #() IFpBp_i -> IFpBi #() UFpBp_i -> UFpBi +#() fFpBp_p -> fFpBp #() fFpBp_a -> fFpBa #() dFpBp_i -> dFpBi #() dFpBp_a -> dFpBa @@ -567,6 +567,7 @@ #() iFXpip -> iFXpip #() iFXppp -> iFXppp #() CFuuff -> CFuuff +#() uFEpii -> uFEpii #() uFuuuu -> uFuuuu #() uFpCCC -> uFpCCC #() lFEipi -> lFEipi @@ -1073,6 +1074,8 @@ wrappedexpat: - vFppp: - XML_SetDoctypeDeclHandler - XML_SetElementHandler +- uFpii: + - XML_ParseBuffer wrappedfreetype: - iFp: - FT_Done_Face diff --git a/src/wrapped32/generated/wrappedexpattypes32.h b/src/wrapped32/generated/wrappedexpattypes32.h index b3bed412..edafb443 100644 --- a/src/wrapped32/generated/wrappedexpattypes32.h +++ b/src/wrapped32/generated/wrappedexpattypes32.h @@ -13,10 +13,12 @@ typedef void (*vFpp_t)(void*, void*); typedef void (*vFppp_t)(void*, void*, void*); +typedef uint32_t (*uFpii_t)(void*, int32_t, int32_t); #define SUPER() ADDED_FUNCTIONS() \ GO(XML_SetCharacterDataHandler, vFpp_t) \ GO(XML_SetDoctypeDeclHandler, vFppp_t) \ - GO(XML_SetElementHandler, vFppp_t) + GO(XML_SetElementHandler, vFppp_t) \ + GO(XML_ParseBuffer, uFpii_t) #endif // __wrappedexpatTYPES32_H_ diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c index 060788e5..85291cf2 100644 --- a/src/wrapped32/generated/wrapper32.c +++ b/src/wrapped32/generated/wrapper32.c @@ -454,7 +454,6 @@ typedef uint32_t (*uFuip_t)(uint32_t, int32_t, void*); typedef uint32_t (*uFuuu_t)(uint32_t, uint32_t, uint32_t); typedef uint32_t (*uFuup_t)(uint32_t, uint32_t, void*); typedef uint32_t (*uFupp_t)(uint32_t, void*, void*); -typedef uint32_t (*uFpii_t)(void*, int32_t, int32_t); typedef uint32_t (*uFpuU_t)(void*, uint32_t, uint64_t); typedef uint32_t (*uFppu_t)(void*, void*, uint32_t); typedef float (*fFuii_t)(uint32_t, int32_t, int32_t); @@ -510,6 +509,7 @@ typedef int32_t (*iFBp_LL_t)(struct_p_t*, uintptr_t, uintptr_t); typedef int32_t (*iFBp_pi_t)(struct_p_t*, void*, int32_t); typedef int64_t (*IFpBp_i_t)(void*, struct_p_t*, int32_t); typedef uint64_t (*UFpBp_i_t)(void*, struct_p_t*, int32_t); +typedef float (*fFpBp_p_t)(void*, struct_p_t*, void*); typedef float (*fFpBp_a_t)(void*, struct_p_t*, void*); typedef double (*dFpBp_i_t)(void*, struct_p_t*, int32_t); typedef double (*dFpBp_a_t)(void*, struct_p_t*, void*); @@ -657,6 +657,7 @@ typedef int32_t (*iFXLii_t)(void*, uintptr_t, int32_t, int32_t); typedef int32_t (*iFXpip_t)(void*, void*, int32_t, void*); typedef int32_t (*iFXppp_t)(void*, void*, void*, void*); typedef uint8_t (*CFuuff_t)(uint32_t, uint32_t, float, float); +typedef uint32_t (*uFEpii_t)(x64emu_t*, void*, int32_t, int32_t); typedef uint32_t (*uFuuuu_t)(uint32_t, uint32_t, uint32_t, uint32_t); typedef uint32_t (*uFpCCC_t)(void*, uint8_t, uint8_t, uint8_t); typedef intptr_t (*lFEipi_t)(x64emu_t*, int32_t, void*, int32_t); @@ -1522,7 +1523,6 @@ void uFuip_32(x64emu_t *emu, uintptr_t fcn) { uFuip_t fn = (uFuip_t)fcn; R_EAX = void uFuuu_32(x64emu_t *emu, uintptr_t fcn) { uFuuu_t fn = (uFuuu_t)fcn; R_EAX = (uint32_t)fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } void uFuup_32(x64emu_t *emu, uintptr_t fcn) { uFuup_t fn = (uFuup_t)fcn; R_EAX = (uint32_t)fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); } void uFupp_32(x64emu_t *emu, uintptr_t fcn) { uFupp_t fn = (uFupp_t)fcn; R_EAX = (uint32_t)fn(from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } -void uFpii_32(x64emu_t *emu, uintptr_t fcn) { uFpii_t fn = (uFpii_t)fcn; R_EAX = (uint32_t)fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); } void uFpuU_32(x64emu_t *emu, uintptr_t fcn) { uFpuU_t fn = (uFpuU_t)fcn; R_EAX = (uint32_t)fn(from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint64_t, R_ESP + 12)); } void uFppu_32(x64emu_t *emu, uintptr_t fcn) { uFppu_t fn = (uFppu_t)fcn; R_EAX = (uint32_t)fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } void fFuii_32(x64emu_t *emu, uintptr_t fcn) { fFuii_t fn = (fFuii_t)fcn; float fl = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); fpu_do_push(emu); ST0val = fl; } @@ -1578,6 +1578,7 @@ void iFBp_LL_32(x64emu_t *emu, uintptr_t fcn) { iFBp_LL_t fn = (iFBp_LL_t)fcn; s void iFBp_pi_32(x64emu_t *emu, uintptr_t fcn) { iFBp_pi_t fn = (iFBp_pi_t)fcn; struct_p_t arg_4={0}; R_EAX = fn(*(ptr_t*)(from_ptr((R_ESP + 4))) ? &arg_4 : NULL, from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); if (*(ptr_t*)(from_ptr((R_ESP + 4)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 4))), &arg_4); } void IFpBp_i_32(x64emu_t *emu, uintptr_t fcn) { IFpBp_i_t fn = (IFpBp_i_t)fcn; struct_p_t arg_8={0}; ui64_t r; r.i = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_ptri(int32_t, R_ESP + 12)); R_EAX = r.d[0]; R_EDX = r.d[1]; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } void UFpBp_i_32(x64emu_t *emu, uintptr_t fcn) { UFpBp_i_t fn = (UFpBp_i_t)fcn; struct_p_t arg_8={0}; ui64_t r; r.u = (uint64_t)fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_ptri(int32_t, R_ESP + 12)); R_EAX = r.d[0]; R_EDX = r.d[1]; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } +void fFpBp_p_32(x64emu_t *emu, uintptr_t fcn) { fFpBp_p_t fn = (fFpBp_p_t)fcn; struct_p_t arg_8={0}; float fl = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_ptriv(R_ESP + 12)); fpu_do_push(emu); ST0val = fl; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } void fFpBp_a_32(x64emu_t *emu, uintptr_t fcn) { fFpBp_a_t fn = (fFpBp_a_t)fcn; struct_p_t arg_8={0}; float fl = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_locale(from_ptri(ptr_t, R_ESP + 12))); fpu_do_push(emu); ST0val = fl; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } void dFpBp_i_32(x64emu_t *emu, uintptr_t fcn) { dFpBp_i_t fn = (dFpBp_i_t)fcn; struct_p_t arg_8={0}; double db = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_ptri(int32_t, R_ESP + 12)); fpu_do_push(emu); ST0val = db; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } void dFpBp_a_32(x64emu_t *emu, uintptr_t fcn) { dFpBp_a_t fn = (dFpBp_a_t)fcn; struct_p_t arg_8={0}; double db = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_locale(from_ptri(ptr_t, R_ESP + 12))); fpu_do_push(emu); ST0val = db; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } @@ -1725,6 +1726,7 @@ void iFXLii_32(x64emu_t *emu, uintptr_t fcn) { iFXLii_t fn = (iFXLii_t)fcn; R_EA void iFXpip_32(x64emu_t *emu, uintptr_t fcn) { iFXpip_t fn = (iFXpip_t)fcn; R_EAX = fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16)); } void iFXppp_32(x64emu_t *emu, uintptr_t fcn) { iFXppp_t fn = (iFXppp_t)fcn; R_EAX = fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16)); } void CFuuff_32(x64emu_t *emu, uintptr_t fcn) { CFuuff_t fn = (CFuuff_t)fcn; R_EAX = (unsigned char)fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(float, R_ESP + 12), from_ptri(float, R_ESP + 16)); } +void uFEpii_32(x64emu_t *emu, uintptr_t fcn) { uFEpii_t fn = (uFEpii_t)fcn; R_EAX = (uint32_t)fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); } void uFuuuu_32(x64emu_t *emu, uintptr_t fcn) { uFuuuu_t fn = (uFuuuu_t)fcn; R_EAX = (uint32_t)fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16)); } void uFpCCC_32(x64emu_t *emu, uintptr_t fcn) { uFpCCC_t fn = (uFpCCC_t)fcn; R_EAX = (uint32_t)fn(from_ptriv(R_ESP + 4), from_ptri(uint8_t, R_ESP + 8), from_ptri(uint8_t, R_ESP + 12), from_ptri(uint8_t, R_ESP + 16)); } void lFEipi_32(x64emu_t *emu, uintptr_t fcn) { lFEipi_t fn = (lFEipi_t)fcn; R_EAX = to_long(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); } @@ -2261,6 +2263,7 @@ int isRetX87Wrapper32(wrapper_t fun) { if (fun == &fFffp_32) return 1; if (fun == &dFddd_32) return 1; if (fun == &dFddp_32) return 1; + if (fun == &fFpBp_p_32) return 1; if (fun == &fFpBp_a_32) return 1; if (fun == &dFpBp_i_32) return 1; if (fun == &dFpBp_a_32) return 1; diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h index 1ef62f5c..fa52aa49 100644 --- a/src/wrapped32/generated/wrapper32.h +++ b/src/wrapped32/generated/wrapper32.h @@ -405,7 +405,6 @@ void uFuip_32(x64emu_t *emu, uintptr_t fnc); void uFuuu_32(x64emu_t *emu, uintptr_t fnc); void uFuup_32(x64emu_t *emu, uintptr_t fnc); void uFupp_32(x64emu_t *emu, uintptr_t fnc); -void uFpii_32(x64emu_t *emu, uintptr_t fnc); void uFpuU_32(x64emu_t *emu, uintptr_t fnc); void uFppu_32(x64emu_t *emu, uintptr_t fnc); void fFuii_32(x64emu_t *emu, uintptr_t fnc); @@ -461,6 +460,7 @@ void iFBp_LL_32(x64emu_t *emu, uintptr_t fnc); void iFBp_pi_32(x64emu_t *emu, uintptr_t fnc); void IFpBp_i_32(x64emu_t *emu, uintptr_t fnc); void UFpBp_i_32(x64emu_t *emu, uintptr_t fnc); +void fFpBp_p_32(x64emu_t *emu, uintptr_t fnc); void fFpBp_a_32(x64emu_t *emu, uintptr_t fnc); void dFpBp_i_32(x64emu_t *emu, uintptr_t fnc); void dFpBp_a_32(x64emu_t *emu, uintptr_t fnc); @@ -608,6 +608,7 @@ void iFXLii_32(x64emu_t *emu, uintptr_t fnc); void iFXpip_32(x64emu_t *emu, uintptr_t fnc); void iFXppp_32(x64emu_t *emu, uintptr_t fnc); void CFuuff_32(x64emu_t *emu, uintptr_t fnc); +void uFEpii_32(x64emu_t *emu, uintptr_t fnc); void uFuuuu_32(x64emu_t *emu, uintptr_t fnc); void uFpCCC_32(x64emu_t *emu, uintptr_t fnc); void lFEipi_32(x64emu_t *emu, uintptr_t fnc); diff --git a/src/wrapped32/wrappedexpat.c b/src/wrapped32/wrappedexpat.c index 1467aaaf..9475780c 100644 --- a/src/wrapped32/wrappedexpat.c +++ b/src/wrapped32/wrappedexpat.c @@ -3,6 +3,8 @@ #include #define _GNU_SOURCE /* See feature_test_macros(7) */ #include +#include +#include #include "wrappedlibs.h" @@ -32,6 +34,55 @@ GO(2) \ GO(3) \ GO(4) +// StartElementHandler ... +#define GO(A) \ +static uintptr_t my_StartElementHandler_fct_##A = 0; \ +static void* my_StartElementHandler_##A(void* data, void* name, void** attr) \ +{ \ + int cnt = 0; \ + while(attr[cnt]) cnt+=2; \ + ++cnt; \ + ptr_t attr_s[cnt]; \ + for(int i=0; iXML_SetElementHandler(p, find_Start_Fct(start), find_End_Fct(end)); + my->XML_SetElementHandler(p, find_StartElementHandler_Fct(start), find_End_Fct(end)); } EXPORT void my32_XML_SetCharacterDataHandler(x64emu_t* emu, void* p, void* h) @@ -690,7 +763,30 @@ EXPORT void my32_XML_SetCharacterDataHandler(x64emu_t* emu, void* p, void* h) EXPORT void my32_XML_SetDoctypeDeclHandler(x64emu_t* emu, void* p, void* start, void* end) { (void)emu; - my->XML_SetDoctypeDeclHandler(p, find_Start_Fct(start), find_End_Fct(end)); + my->XML_SetDoctypeDeclHandler(p, find_StartDoctypeDecl_Fct(start), find_EndDoctypeDecl_Fct(end)); +} + +// this function will call the callbacks with many structures created on the stack, wich might be a 64bits walue on the initial thred +// so using a swapcontext trick to use a 32bits stack temporarily +// TODO: generalise this on main? +static void func1(uint32_t* ret, void* p, int a, int b) +{ + *ret = my->XML_ParseBuffer(p, a, b); +} +ucontext_t uctx_main, uctx_func1; +EXPORT uint32_t my32_XML_ParseBuffer(x64emu_t* emu, void* p, int a, int b) +{ + getcontext(&uctx_func1); + size_t stack_size = 1024*1024; + void* func1_stack = mmap(NULL, stack_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_32BIT|MAP_ANONYMOUS|MAP_GROWSDOWN, -1, 0); + uctx_func1.uc_stack.ss_sp = func1_stack; + uctx_func1.uc_stack.ss_size = stack_size; + uctx_func1.uc_link = &uctx_main; + uint32_t ret = 0; + makecontext(&uctx_func1, (void*)func1, 4, &ret, p, a, b); + swapcontext(&uctx_main, &uctx_func1); + munmap(func1_stack, stack_size); + return ret; } #include "wrappedlib_init32.h" diff --git a/src/wrapped32/wrappedexpat_private.h b/src/wrapped32/wrappedexpat_private.h index 975de9d5..5de7b18f 100644 --- a/src/wrapped32/wrappedexpat_private.h +++ b/src/wrapped32/wrappedexpat_private.h @@ -25,7 +25,7 @@ GO(XML_GetErrorCode, uFp) //GO(XML_MemMalloc, pFpL) //GO(XML_MemRealloc, pFppL) //GO(XML_Parse, uFppii) -GO(XML_ParseBuffer, uFpii) +GOM(XML_ParseBuffer, uFEpii) GO(XML_ParserCreate, pFp) //GO(XML_ParserCreate_MM, pFpppp) // return a structure //GO(XML_ParserCreateNS, pFpc) diff --git a/src/wrapped32/wrappedlibc_private.h b/src/wrapped32/wrappedlibc_private.h index 05fc21e1..9fa0fe6e 100755 --- a/src/wrapped32/wrappedlibc_private.h +++ b/src/wrapped32/wrappedlibc_private.h @@ -1682,7 +1682,7 @@ GO(__strtod_internal, dFpBp_i) GO(__strtod_l, dFpBp_a) GOW(strtod_l, dFpBp_a) GO(strtof, fFpBp_) -//GO(__strtof_internal, fFppp) +GO(__strtof_internal, fFpBp_p) GO(__strtof_l, fFpBp_a) //GOW(strtof_l, fFppu) //GO(strtoimax, IFppi) @@ -1936,7 +1936,7 @@ GOW(wcscasecmp, iFpp) // __wcscasecmp_l //GOW(wcscasecmp_l, iFppp) GOW(wcscat, pFpp) -//GO(__wcscat_chk, pFppu) +GO(__wcscat_chk, pFppL) GO(wcschr, pFpi) // wcschrnul // Weak GO(wcscmp, iFpp) @@ -1955,7 +1955,7 @@ GOW(wcsncasecmp, iFppL) // __wcsncasecmp_l //GOW(wcsncasecmp_l, iFppup) GO(wcsncat, pFppL) -// __wcsncat_chk +GO(__wcsncat_chk, pFppLL) GO(wcsncmp, iFppL) GOW(wcsncpy, pFppL) GO(__wcsncpy_chk, pFppLL) @@ -1963,12 +1963,12 @@ GOW(wcsnlen, LFpL) GOW(wcsnrtombs, LFpBp_LLp) // __wcsnrtombs_chk //GO(wcspbrk, pFpp) -//GO(wcsrchr, pFpi) +GO(wcsrchr, pFpi) //GOW(wcsrtombs, uFppup) // __wcsrtombs_chk //GO(wcsspn, uFpp) GO(wcsstr, pFpp) -//GO(wcstod, dFpp) +GO(wcstod, dFpBp_) //GO(__wcstod_internal, dFppi) // __wcstod_l // wcstod_l // Weak -- cgit 1.4.1