diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-12-01 12:32:33 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-12-01 12:32:33 +0100 |
| commit | ab73969ea4c317bff252176ed3d57f45ccde6924 (patch) | |
| tree | 0d1d5c547de437f41e02a972e52ad0c962e1c5d5 /src | |
| parent | 93b371eb8cd2797a021103a4aad41ba7672cd32e (diff) | |
| download | box64-ab73969ea4c317bff252176ed3d57f45ccde6924.tar.gz box64-ab73969ea4c317bff252176ed3d57f45ccde6924.zip | |
[BOX32][WRAPPER] Improved networks functions
Diffstat (limited to 'src')
| -rw-r--r-- | src/emu/x64emu.c | 5 | ||||
| -rw-r--r-- | src/emu/x64emu_private.h | 2 | ||||
| -rw-r--r-- | src/libtools/libc_net32.c | 133 | ||||
| -rw-r--r-- | src/wrapped32/generated/functions_list.txt | 4 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrappedlibctypes32.h | 1 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrappedlibresolvtypes32.h | 3 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrapper32.c | 4 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrapper32.h | 2 | ||||
| -rwxr-xr-x | src/wrapped32/wrappedlibc_private.h | 2 | ||||
| -rw-r--r-- | src/wrapped32/wrappedlibresolv.c | 17 | ||||
| -rw-r--r-- | src/wrapped32/wrappedlibresolv_private.h | 4 |
11 files changed, 168 insertions, 9 deletions
diff --git a/src/emu/x64emu.c b/src/emu/x64emu.c index 4441ba53..f140cb99 100644 --- a/src/emu/x64emu.c +++ b/src/emu/x64emu.c @@ -204,6 +204,11 @@ static void internalFreeX64(x64emu_t* emu) { if(emu && emu->stack2free) !munmap(emu->stack2free, emu->size_stack); + #ifdef BOX32 + if(emu->res_state_32) + actual_free(emu->res_state_32); + emu->res_state_32 = NULL; + #endif } EXPORTDYN diff --git a/src/emu/x64emu_private.h b/src/emu/x64emu_private.h index 1976012a..caa92848 100644 --- a/src/emu/x64emu_private.h +++ b/src/emu/x64emu_private.h @@ -143,6 +143,8 @@ typedef struct x64emu_s { int libctoupper[384]; // copy from __ctype_b_toupper address might be too high const int* ref_toupper; const int* toupper; + void* res_state_32; //32bits version of res_state + void* res_state_64; #endif } x64emu_t; diff --git a/src/libtools/libc_net32.c b/src/libtools/libc_net32.c index d625b3a7..0b6ae083 100644 --- a/src/libtools/libc_net32.c +++ b/src/libtools/libc_net32.c @@ -20,6 +20,7 @@ #include <netdb.h> #include <ifaddrs.h> #include <net/if.h> +#include <resolv.h> #include "box64stack.h" #include "x64emu.h" @@ -35,6 +36,7 @@ #include "globalsymbols.h" #include "box32.h" #include "converter32.h" +#include "custommem.h" EXPORT ssize_t my32_recvmsg(x64emu_t* emu, int socket, struct i386_msghdr* msg, int flags) { @@ -177,6 +179,7 @@ EXPORT int my32_gethostbyname_r(x64emu_t* emu, void* name, struct i386_hostent* } strings[idx++] = 0; } + idx = 0; ret->h_addr_list = to_ptrv(result_l->h_addr_list); if(result_l->h_addr_list) { char** p = result_l->h_addr_list; @@ -217,6 +220,7 @@ EXPORT int my32_gethostbyaddr_r(x64emu_t* emu, void* addr, uint32_t len, int typ strings[idx++] = 0; } ret->h_addr_list = to_ptrv(result_l->h_addr_list); + idx = 0; if(result_l->h_addr_list) { char** p = result_l->h_addr_list; ptr_t* strings = from_ptrv(ret->h_addr_list); @@ -298,4 +302,131 @@ EXPORT void* my32_getprotobyname(x64emu_t* emu, void* name) my_protoent.p_aliases = 0; return &my_protoent; -} \ No newline at end of file +} + +typedef struct my_res_state_32_s { + int retrans; + int retry; + ulong_t options; + int nscount; + struct sockaddr_in + nsaddr_list[3]; + unsigned short id; + /* 2 byte hole here. */ + ptr_t dnsrch[7]; //char* + char defdname[256]; + ulong_t pfcode; + unsigned ndots:4; + unsigned nsort:4; + unsigned ipv6_unavail:1; + unsigned unused:23; + struct { + struct in_addr addr; + uint32_t mask; + } sort_list[10]; + /* 4 byte hole here on 64-bit architectures. */ + ptr_t __glibc_unused_qhook; //void* + ptr_t __glibc_unused_rhook; //void* + int res_h_errno; + int _vcsock; + unsigned int _flags; + /* 4 byte hole here on 64-bit architectures. */ + union { + char pad[52]; /* On an i386 this means 512b total. */ + struct { + uint16_t nscount; + uint16_t nsmap[3]; + int nssocks[3]; + uint16_t nscount6; + uint16_t nsinit; + ptr_t nsaddrs[3]; //struct sockaddr_in6* + unsigned int __glibc_reserved[2]; + } _ext; + } _u; +} my_res_state_32_t; + +void* convert_res_state_to_32(void* d, void* s) +{ + if(!d || !s) return NULL; + struct __res_state* src = s; + my_res_state_32_t* dst = d; + + dst->retrans = src->retrans; + dst->retry = src->retry; + dst->options = to_ulong(src->options); + memmove(dst->nsaddr_list, src->nsaddr_list, sizeof(dst->nsaddr_list)); + dst->id = src->id; + for(int i=0; i<7; ++i) + dst->dnsrch[i] = to_ptrv(src->dnsrch[i]); + memmove(dst->defdname, src->defdname, sizeof(dst->defdname)); + dst->pfcode = to_ulong(src->pfcode); + dst->ndots = src->ndots; + dst->nsort = src->nsort; + dst->ipv6_unavail = src->ipv6_unavail; + dst->unused = src->unused; + memmove(dst->sort_list, src->sort_list, sizeof(dst->sort_list)); + dst->__glibc_unused_qhook = to_ptrv(src->__glibc_unused_qhook); + dst->__glibc_unused_rhook = to_ptrv(src->__glibc_unused_rhook); + dst->res_h_errno = src->res_h_errno; + dst->_vcsock = src->_vcsock; + dst->_flags = src->_flags; + memmove(dst->_u.pad, src->_u.pad, sizeof(dst->_u.pad)); + + return dst; +} + +void* convert_res_state_to_64(void* d, void* s) +{ + if(!d || !s) return NULL; + my_res_state_32_t* src = s; + struct __res_state* dst = d; + + memmove(dst->_u.pad, src->_u.pad, sizeof(dst->_u.pad)); + dst->_flags = src->_flags; + dst->_vcsock = src->_vcsock; + dst->res_h_errno = src->res_h_errno; + dst->__glibc_unused_rhook = from_ptrv(src->__glibc_unused_rhook); + dst->__glibc_unused_qhook = from_ptrv(src->__glibc_unused_qhook); + memmove(dst->sort_list, src->sort_list, sizeof(dst->sort_list)); + dst->unused = src->unused; + dst->ipv6_unavail = src->ipv6_unavail; + dst->nsort = src->nsort; + dst->ndots = src->ndots; + dst->pfcode = from_ulong(src->pfcode); + memmove(dst->defdname, src->defdname, sizeof(dst->defdname)); + for(int i=6; i>=0; --i) + dst->dnsrch[i] = from_ptrv(src->dnsrch[i]); + dst->id = src->id; + memmove(dst->nsaddr_list, src->nsaddr_list, sizeof(dst->nsaddr_list)); + dst->options = from_ulong(src->options); + dst->retry = src->retry; + dst->retrans = src->retrans; + + return dst; +} + +EXPORT void* my32___res_state(x64emu_t* emu) +{ + if(emu->res_state_64) // update res? + convert_res_state_to_64(emu->res_state_64, emu->res_state_32); + void* ret = __res_state(); + if(!ret) + return ret; + if(emu->res_state_64!=ret) { + if(!emu->res_state_32) + emu->res_state_32 = actual_calloc(1, sizeof(my_res_state_32_t)); + emu->res_state_64 = ret; + } + convert_res_state_to_32(emu->res_state_32, emu->res_state_64); + return emu->res_state_32; +} + +/*EXPORT void my32___res_iclose(x64emu_t* emu, void* s, int f) +{ + if(emu->res_state_64==s) { + emu->res_state_64 = NULL; + actual_free(emu->res_state_32); + emu->res_state_32 = NULL; + } + __res_iclose(s, f); +}*/ \ No newline at end of file diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt index ef50d56b..f5443203 100644 --- a/src/wrapped32/generated/functions_list.txt +++ b/src/wrapped32/generated/functions_list.txt @@ -1132,7 +1132,6 @@ #() iEipppp -> iEipppp #() iFuiuup -> iFuiuup #() iFpiiuu -> iFpiiuu -#() iEpiipi -> iEpiipi #() iFpippp -> iFpippp #() iFpCCCC -> iFpCCCC #() iFpuipp -> iFpuipp @@ -1279,6 +1278,7 @@ #() iEEiippi -> iEEiippi #() iEEipiup -> iEEipiup #() iEEuppLp -> iEEuppLp +#() iEEpiipi -> iEEpiipi #() iEEpiipV -> iEEpiipV #() iFEpiuuu -> iFEpiuuu #() iEEpiLpp -> iEEpiLpp @@ -1766,6 +1766,7 @@ wrappedlibc: - __ctype_tolower_loc - __ctype_toupper_loc - __errno_location + - __res_state - localeconv - pFv: - __h_errno_location @@ -2194,6 +2195,7 @@ wrappedlibpthread: wrappedlibresolv: - iEpiipi: - __res_query + - res_query wrappedlibrt: - iEuBLL_: - __clock_gettime diff --git a/src/wrapped32/generated/wrappedlibctypes32.h b/src/wrapped32/generated/wrappedlibctypes32.h index 61534ccc..aa0683f0 100644 --- a/src/wrapped32/generated/wrappedlibctypes32.h +++ b/src/wrapped32/generated/wrappedlibctypes32.h @@ -143,6 +143,7 @@ typedef int32_t (*iEpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void GO(__ctype_tolower_loc, pEv_t) \ GO(__ctype_toupper_loc, pEv_t) \ GO(__errno_location, pEv_t) \ + GO(__res_state, pEv_t) \ GO(localeconv, pEv_t) \ GO(__h_errno_location, pFv_t) \ GO(getpwuid, pEu_t) \ diff --git a/src/wrapped32/generated/wrappedlibresolvtypes32.h b/src/wrapped32/generated/wrappedlibresolvtypes32.h index 23bd722a..548138a5 100644 --- a/src/wrapped32/generated/wrappedlibresolvtypes32.h +++ b/src/wrapped32/generated/wrappedlibresolvtypes32.h @@ -14,6 +14,7 @@ typedef int32_t (*iEpiipi_t)(void*, int32_t, int32_t, void*, int32_t); #define SUPER() ADDED_FUNCTIONS() \ - GO(__res_query, iEpiipi_t) + GO(__res_query, iEpiipi_t) \ + GO(res_query, iEpiipi_t) #endif // __wrappedlibresolvTYPES32_H_ diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c index 42929822..e8a936a8 100644 --- a/src/wrapped32/generated/wrapper32.c +++ b/src/wrapped32/generated/wrapper32.c @@ -1223,7 +1223,6 @@ typedef int32_t (*iEipppi_t)(int32_t, void*, void*, void*, int32_t); typedef int32_t (*iEipppp_t)(int32_t, void*, void*, void*, void*); typedef int32_t (*iFuiuup_t)(uint32_t, int32_t, uint32_t, uint32_t, void*); typedef int32_t (*iFpiiuu_t)(void*, int32_t, int32_t, uint32_t, uint32_t); -typedef int32_t (*iEpiipi_t)(void*, int32_t, int32_t, void*, int32_t); typedef int32_t (*iFpippp_t)(void*, int32_t, void*, void*, void*); typedef int32_t (*iFpCCCC_t)(void*, uint8_t, uint8_t, uint8_t, uint8_t); typedef int32_t (*iFpuipp_t)(void*, uint32_t, int32_t, void*, void*); @@ -1370,6 +1369,7 @@ typedef void (*vFXLpppi_t)(void*, uintptr_t, void*, void*, void*, int32_t); typedef int32_t (*iEEiippi_t)(x64emu_t*, int32_t, int32_t, void*, void*, int32_t); typedef int32_t (*iEEipiup_t)(x64emu_t*, int32_t, void*, int32_t, uint32_t, void*); typedef int32_t (*iEEuppLp_t)(x64emu_t*, uint32_t, void*, void*, uintptr_t, void*); +typedef int32_t (*iEEpiipi_t)(x64emu_t*, void*, int32_t, int32_t, void*, int32_t); typedef int32_t (*iEEpiipV_t)(x64emu_t*, void*, int32_t, int32_t, void*, void*); typedef int32_t (*iFEpiuuu_t)(x64emu_t*, void*, int32_t, uint32_t, uint32_t, uint32_t); typedef int32_t (*iEEpiLpp_t)(x64emu_t*, void*, int32_t, uintptr_t, void*, void*); @@ -2866,7 +2866,6 @@ void iEipppi_32(x64emu_t *emu, uintptr_t fcn) { iEipppi_t fn = (iEipppi_t)fcn; e void iEipppp_32(x64emu_t *emu, uintptr_t fcn) { iEipppp_t fn = (iEipppp_t)fcn; errno = emu->libc_err; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); emu->libc_err = errno; } void iFuiuup_32(x64emu_t *emu, uintptr_t fcn) { iFuiuup_t fn = (iFuiuup_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptriv(R_ESP + 20)); } void iFpiiuu_32(x64emu_t *emu, uintptr_t fcn) { iFpiiuu_t fn = (iFpiiuu_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); } -void iEpiipi_32(x64emu_t *emu, uintptr_t fcn) { iEpiipi_t fn = (iEpiipi_t)fcn; errno = emu->libc_err; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16), from_ptri(int32_t, R_ESP + 20)); emu->libc_err = errno; } void iFpippp_32(x64emu_t *emu, uintptr_t fcn) { iFpippp_t fn = (iFpippp_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); } void iFpCCCC_32(x64emu_t *emu, uintptr_t fcn) { iFpCCCC_t fn = (iFpCCCC_t)fcn; R_EAX = 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), from_ptri(uint8_t, R_ESP + 20)); } void iFpuipp_32(x64emu_t *emu, uintptr_t fcn) { iFpuipp_t fn = (iFpuipp_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); } @@ -3013,6 +3012,7 @@ void vFXLpppi_32(x64emu_t *emu, uintptr_t fcn) { vFXLpppi_t fn = (vFXLpppi_t)fcn void iEEiippi_32(x64emu_t *emu, uintptr_t fcn) { iEEiippi_t fn = (iEEiippi_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptri(int32_t, R_ESP + 20)); emu->libc_err = errno; } void iEEipiup_32(x64emu_t *emu, uintptr_t fcn) { iEEipiup_t fn = (iEEipiup_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptriv(R_ESP + 20)); emu->libc_err = errno; } void iEEuppLp_32(x64emu_t *emu, uintptr_t fcn) { iEEuppLp_t fn = (iEEuppLp_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ptriv(R_ESP + 20)); emu->libc_err = errno; } +void iEEpiipi_32(x64emu_t *emu, uintptr_t fcn) { iEEpiipi_t fn = (iEEpiipi_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16), from_ptri(int32_t, R_ESP + 20)); emu->libc_err = errno; } void iEEpiipV_32(x64emu_t *emu, uintptr_t fcn) { iEEpiipV_t fn = (iEEpiipV_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16), from_ptrv(R_ESP + 20)); emu->libc_err = errno; } void iFEpiuuu_32(x64emu_t *emu, uintptr_t fcn) { iFEpiuuu_t fn = (iFEpiuuu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); } void iEEpiLpp_32(x64emu_t *emu, uintptr_t fcn) { iEEpiLpp_t fn = (iEEpiLpp_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ulong(from_ptri(ulong_t, R_ESP + 12)), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); emu->libc_err = errno; } diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h index 4316305a..46dce8f2 100644 --- a/src/wrapped32/generated/wrapper32.h +++ b/src/wrapped32/generated/wrapper32.h @@ -1173,7 +1173,6 @@ void iEipppi_32(x64emu_t *emu, uintptr_t fnc); void iEipppp_32(x64emu_t *emu, uintptr_t fnc); void iFuiuup_32(x64emu_t *emu, uintptr_t fnc); void iFpiiuu_32(x64emu_t *emu, uintptr_t fnc); -void iEpiipi_32(x64emu_t *emu, uintptr_t fnc); void iFpippp_32(x64emu_t *emu, uintptr_t fnc); void iFpCCCC_32(x64emu_t *emu, uintptr_t fnc); void iFpuipp_32(x64emu_t *emu, uintptr_t fnc); @@ -1320,6 +1319,7 @@ void vFXLpppi_32(x64emu_t *emu, uintptr_t fnc); void iEEiippi_32(x64emu_t *emu, uintptr_t fnc); void iEEipiup_32(x64emu_t *emu, uintptr_t fnc); void iEEuppLp_32(x64emu_t *emu, uintptr_t fnc); +void iEEpiipi_32(x64emu_t *emu, uintptr_t fnc); void iEEpiipV_32(x64emu_t *emu, uintptr_t fnc); void iFEpiuuu_32(x64emu_t *emu, uintptr_t fnc); void iEEpiLpp_32(x64emu_t *emu, uintptr_t fnc); diff --git a/src/wrapped32/wrappedlibc_private.h b/src/wrapped32/wrappedlibc_private.h index 6b0fac79..2fefa65b 100755 --- a/src/wrapped32/wrappedlibc_private.h +++ b/src/wrapped32/wrappedlibc_private.h @@ -1412,7 +1412,7 @@ GO(__res_init, iEv) //GO(__res_ninit, iEp) //DATA(__resp, 4) // __res_randomid -GO(__res_state, pEv) // the returned struture certainly needs wrapping +GOM(__res_state, pEEv) //DATA(re_syntax_options, 4) // type B // revoke GO(rewind, vES) diff --git a/src/wrapped32/wrappedlibresolv.c b/src/wrapped32/wrappedlibresolv.c index 381b2f7d..7ef81e3a 100644 --- a/src/wrapped32/wrappedlibresolv.c +++ b/src/wrapped32/wrappedlibresolv.c @@ -3,6 +3,8 @@ #include <string.h> #define _GNU_SOURCE /* See feature_test_macros(7) */ #include <dlfcn.h> +#include <resolv.h> +#include <netdb.h> #include "wrappedlibs.h" @@ -21,4 +23,19 @@ static const char* libresolvName = "libresolv.so.2"; #define LIBNAME libresolv +#include "generated/wrappedlibresolvtypes32.h" + +#include "wrappercallback32.h" + +void* convert_res_state_to_32(void* d, void* s); +void* convert_res_state_to_64(void* d, void* s); + +EXPORT int my32_res_query(x64emu_t* emu, void* dname, int class, int type, void* answer, int anslen) +{ + convert_res_state_to_64(emu->res_state_64, emu->res_state_32); + int ret = my->__res_query(dname, class, type, answer, anslen); + emu->libc_herr = h_errno; + return ret; +} + #include "wrappedlib_init32.h" diff --git a/src/wrapped32/wrappedlibresolv_private.h b/src/wrapped32/wrappedlibresolv_private.h index 17fb9721..e5041815 100644 --- a/src/wrapped32/wrappedlibresolv_private.h +++ b/src/wrapped32/wrappedlibresolv_private.h @@ -92,8 +92,8 @@ //DATA(_res_opcodes, 4) //GO(__res_ownok, iFp) //GO(__res_queriesmatch, iFpppp) -GO2(__res_query, iEpiipi, res_query) -GOW(res_query, iEpiipi) +GO2(__res_query, iEEpiipi, my32_res_query) +GOWM(res_query, iEEpiipi) //GO2(__res_querydomain, iFppiipi, res_querydomain) //GOW(res_querydomain, iFppiipi) //GO2(__res_search, iFpiipi, res_search) |