Skip to content

Commit

Permalink
[BOX32] Added a couple of 32bits function to libc
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Oct 7, 2024
1 parent f816772 commit 82c7d45
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 2 deletions.
78 changes: 78 additions & 0 deletions src/libtools/libc_net32.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,84 @@ EXPORT void* my32_gethostbyname(x64emu_t* emu, const char* a)
return &ret;
}

EXPORT int my32_gethostbyname_r(x64emu_t* emu, void* name, struct i386_hostent* ret, void* buff, size_t buflen, ptr_t* result, int* h_err)
{
struct hostent ret_l = {0};
struct hostent *result_l = NULL;
int r = gethostbyname_r(name, &ret_l, buff, buflen, &result_l, h_err);
if(!result_l)
*result = 0;
else
*result = to_ptrv(ret);
// convert result, all memory allocated should be in program space
if(result_l) {
ret->h_name = to_cstring(result_l->h_name);
ret->h_addrtype = result_l->h_addrtype;
ret->h_length = result_l->h_length;
int idx = 0;
ret->h_aliases = to_ptrv(result_l->h_aliases);
if(result_l->h_aliases) {
char** p = result_l->h_aliases;
ptr_t* strings = from_ptrv(ret->h_aliases);
while(*p) {
strings[idx++] = to_cstring(*p);
++p;
}
strings[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;
ptr_t* strings = from_ptrv(ret->h_addr_list);
while(*p) {
strings[idx++] = to_ptrv(*p);
++p;
}
strings[idx++] = 0;
}
}
return r;
}

EXPORT int my32_gethostbyaddr_r(x64emu_t* emu, void* addr, uint32_t len, int type, struct i386_hostent* ret, void* buff, size_t buflen, ptr_t* result, int* h_err)
{
struct hostent ret_l = {0};
struct hostent *result_l = NULL;
int r = gethostbyaddr_r(addr, len, type, &ret_l, buff, buflen, &result_l, h_err);
if(!result_l)
*result = 0;
else
*result = to_ptrv(ret);
// convert result, all memory allocated should be in program space
if(result_l) {
ret->h_name = to_cstring(result_l->h_name);
ret->h_addrtype = result_l->h_addrtype;
ret->h_length = result_l->h_length;
int idx = 0;
ret->h_aliases = to_ptrv(result_l->h_aliases);
if(result_l->h_aliases) {
char** p = result_l->h_aliases;
ptr_t* strings = from_ptrv(ret->h_aliases);
while(*p) {
strings[idx++] = to_cstring(*p);
++p;
}
strings[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;
ptr_t* strings = from_ptrv(ret->h_addr_list);
while(*p) {
strings[idx++] = to_ptrv(*p);
++p;
}
strings[idx++] = 0;
}
}
return r;
}

struct i386_ifaddrs
{
ptr_t ifa_next; // struct ifaddrs *
Expand Down
4 changes: 4 additions & 0 deletions src/wrapped32/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@
#() vFXppiiii -> vFXppiiii
#() iFEpLiipV -> iFEpLiipV
#() iFEpLiLpV -> iFEpLiLpV
#() iFEpppupp -> iFEpppupp
#() iFEpppppp -> iFEpppppp
#() iFEXLpiiL -> iFEXLpiiL
#() iFEXLpppp -> iFEXLpppp
Expand Down Expand Up @@ -1237,6 +1238,7 @@
#() iFEpippppp -> iFEpippppp
#() iFEpLiLppp -> iFEpLiLppp
#() iFuiiiiuup -> iFuiiiiuup
#() iFpuippupp -> iFpuippupp
#() iFXuupuupp -> iFXuupuupp
#() iFXLpipppp -> iFXLpipppp
#() iFXLppLpip -> iFXLppLpip
Expand Down Expand Up @@ -1628,6 +1630,8 @@ wrappedlibc:
- iFpLvvpp:
- iFpLiipV:
- iFpLiLpV:
- iFpppupp:
- gethostbyname_r
- iFpppppp:
- posix_spawn
- pFpLiiiI:
Expand Down
2 changes: 2 additions & 0 deletions src/wrapped32/generated/wrappedlibctypes32.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typedef void* (*pFppLLp_t)(void*, void*, uintptr_t, uintptr_t, void*);
typedef int32_t (*iFpLvvpp_t)(void*, uintptr_t, void, void, void*, void*);
typedef int32_t (*iFpLiipV_t)(void*, uintptr_t, int32_t, int32_t, void*, ...);
typedef int32_t (*iFpLiLpV_t)(void*, uintptr_t, int32_t, uintptr_t, void*, ...);
typedef int32_t (*iFpppupp_t)(void*, void*, void*, uint32_t, void*, void*);
typedef int32_t (*iFpppppp_t)(void*, void*, void*, void*, void*, void*);
typedef void* (*pFpLiiiI_t)(void*, uintptr_t, int32_t, int32_t, int32_t, int64_t);
typedef void* (*pFpLiiil_t)(void*, uintptr_t, int32_t, int32_t, int32_t, intptr_t);
Expand Down Expand Up @@ -163,6 +164,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void
GO(getpwuid_r, iFuppLp_t) \
GO(getgrnam_r, iFpppLp_t) \
GO(getpwnam_r, iFpppLp_t) \
GO(gethostbyname_r, iFpppupp_t) \
GO(posix_spawn, iFpppppp_t)

#endif // __wrappedlibcTYPES32_H_
4 changes: 4 additions & 0 deletions src/wrapped32/generated/wrapper32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ typedef void (*vFXpiipii_t)(void*, void*, int32_t, int32_t, void*, int32_t, int3
typedef void (*vFXppiiii_t)(void*, void*, void*, int32_t, int32_t, int32_t, int32_t);
typedef int32_t (*iFEpLiipV_t)(x64emu_t*, void*, uintptr_t, int32_t, int32_t, void*, void*);
typedef int32_t (*iFEpLiLpV_t)(x64emu_t*, void*, uintptr_t, int32_t, uintptr_t, void*, void*);
typedef int32_t (*iFEpppupp_t)(x64emu_t*, void*, void*, void*, uint32_t, void*, void*);
typedef int32_t (*iFEpppppp_t)(x64emu_t*, void*, void*, void*, void*, void*, void*);
typedef int32_t (*iFEXLpiiL_t)(x64emu_t*, void*, uintptr_t, void*, int32_t, int32_t, uintptr_t);
typedef int32_t (*iFEXLpppp_t)(x64emu_t*, void*, uintptr_t, void*, void*, void*, void*);
Expand Down Expand Up @@ -1327,6 +1328,7 @@ typedef void (*vFXLppiipi_t)(void*, uintptr_t, void*, void*, int32_t, int32_t, v
typedef int32_t (*iFEpippppp_t)(x64emu_t*, void*, int32_t, void*, void*, void*, void*, void*);
typedef int32_t (*iFEpLiLppp_t)(x64emu_t*, void*, uintptr_t, int32_t, uintptr_t, void*, void*, void*);
typedef int32_t (*iFuiiiiuup_t)(uint32_t, int32_t, int32_t, int32_t, int32_t, uint32_t, uint32_t, void*);
typedef int32_t (*iFpuippupp_t)(void*, uint32_t, int32_t, void*, void*, uint32_t, void*, void*);
typedef int32_t (*iFXuupuupp_t)(void*, uint32_t, uint32_t, void*, uint32_t, uint32_t, void*, void*);
typedef int32_t (*iFXLpipppp_t)(void*, uintptr_t, void*, int32_t, void*, void*, void*, void*);
typedef int32_t (*iFXLppLpip_t)(void*, uintptr_t, void*, void*, uintptr_t, void*, int32_t, void*);
Expand Down Expand Up @@ -2654,6 +2656,7 @@ void vFXpiipii_32(x64emu_t *emu, uintptr_t fcn) { vFXpiipii_t fn = (vFXpiipii_t)
void vFXppiiii_32(x64emu_t *emu, uintptr_t fcn) { vFXppiiii_t fn = (vFXppiiii_t)fcn; fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptri(int32_t, R_ESP + 16), from_ptri(int32_t, R_ESP + 20), from_ptri(int32_t, R_ESP + 24), from_ptri(int32_t, R_ESP + 28)); }
void iFEpLiipV_32(x64emu_t *emu, uintptr_t fcn) { iFEpLiipV_t fn = (iFEpLiipV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptri(int32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16), from_ptriv(R_ESP + 20), from_ptrv(R_ESP + 24)); }
void iFEpLiLpV_32(x64emu_t *emu, uintptr_t fcn) { iFEpLiLpV_t fn = (iFEpLiLpV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptri(int32_t, R_ESP + 12), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ptriv(R_ESP + 20), from_ptrv(R_ESP + 24)); }
void iFEpppupp_32(x64emu_t *emu, uintptr_t fcn) { iFEpppupp_t fn = (iFEpppupp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptriv(R_ESP + 20), from_ptriv(R_ESP + 24)); }
void iFEpppppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpppppp_t fn = (iFEpppppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20), from_ptriv(R_ESP + 24)); }
void iFEXLpiiL_32(x64emu_t *emu, uintptr_t fcn) { iFEXLpiiL_t fn = (iFEXLpiiL_t)fcn; R_EAX = fn(emu, getDisplay(from_ptriv(R_ESP + 4)), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptriv(R_ESP + 12), from_ptri(int32_t, R_ESP + 16), from_ptri(int32_t, R_ESP + 20), from_ulong(from_ptri(ulong_t, R_ESP + 24))); }
void iFEXLpppp_32(x64emu_t *emu, uintptr_t fcn) { iFEXLpppp_t fn = (iFEXLpppp_t)fcn; R_EAX = fn(emu, getDisplay(from_ptriv(R_ESP + 4)), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20), from_ptriv(R_ESP + 24)); }
Expand Down Expand Up @@ -2721,6 +2724,7 @@ void vFXLppiipi_32(x64emu_t *emu, uintptr_t fcn) { vFXLppiipi_t fn = (vFXLppiipi
void iFEpippppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpippppp_t fn = (iFEpippppp_t)fcn; R_EAX = fn(emu, 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), from_ptriv(R_ESP + 24), from_ptriv(R_ESP + 28)); }
void iFEpLiLppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpLiLppp_t fn = (iFEpLiLppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptri(int32_t, R_ESP + 12), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ptriv(R_ESP + 20), from_ptriv(R_ESP + 24), from_ptriv(R_ESP + 28)); }
void iFuiiiiuup_32(x64emu_t *emu, uintptr_t fcn) { iFuiiiiuup_t fn = (iFuiiiiuup_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16), from_ptri(int32_t, R_ESP + 20), from_ptri(uint32_t, R_ESP + 24), from_ptri(uint32_t, R_ESP + 28), from_ptriv(R_ESP + 32)); }
void iFpuippupp_32(x64emu_t *emu, uintptr_t fcn) { iFpuippupp_t fn = (iFpuippupp_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), from_ptri(uint32_t, R_ESP + 24), from_ptriv(R_ESP + 28), from_ptriv(R_ESP + 32)); }
void iFXuupuupp_32(x64emu_t *emu, uintptr_t fcn) { iFXuupuupp_t fn = (iFXuupuupp_t)fcn; R_EAX = fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptriv(R_ESP + 16), from_ptri(uint32_t, R_ESP + 20), from_ptri(uint32_t, R_ESP + 24), from_ptriv(R_ESP + 28), from_ptriv(R_ESP + 32)); }
void iFXLpipppp_32(x64emu_t *emu, uintptr_t fcn) { iFXLpipppp_t fn = (iFXLpipppp_t)fcn; R_EAX = fn(getDisplay(from_ptriv(R_ESP + 4)), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptriv(R_ESP + 12), from_ptri(int32_t, R_ESP + 16), from_ptriv(R_ESP + 20), from_ptriv(R_ESP + 24), from_ptriv(R_ESP + 28), from_ptriv(R_ESP + 32)); }
void iFXLppLpip_32(x64emu_t *emu, uintptr_t fcn) { iFXLppLpip_t fn = (iFXLppLpip_t)fcn; R_EAX = fn(getDisplay(from_ptriv(R_ESP + 4)), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ulong(from_ptri(ulong_t, R_ESP + 20)), from_ptriv(R_ESP + 24), from_ptri(int32_t, R_ESP + 28), from_ptriv(R_ESP + 32)); }
Expand Down
2 changes: 2 additions & 0 deletions src/wrapped32/generated/wrapper32.h
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ void vFXpiipii_32(x64emu_t *emu, uintptr_t fnc);
void vFXppiiii_32(x64emu_t *emu, uintptr_t fnc);
void iFEpLiipV_32(x64emu_t *emu, uintptr_t fnc);
void iFEpLiLpV_32(x64emu_t *emu, uintptr_t fnc);
void iFEpppupp_32(x64emu_t *emu, uintptr_t fnc);
void iFEpppppp_32(x64emu_t *emu, uintptr_t fnc);
void iFEXLpiiL_32(x64emu_t *emu, uintptr_t fnc);
void iFEXLpppp_32(x64emu_t *emu, uintptr_t fnc);
Expand Down Expand Up @@ -1278,6 +1279,7 @@ void vFXLppiipi_32(x64emu_t *emu, uintptr_t fnc);
void iFEpippppp_32(x64emu_t *emu, uintptr_t fnc);
void iFEpLiLppp_32(x64emu_t *emu, uintptr_t fnc);
void iFuiiiiuup_32(x64emu_t *emu, uintptr_t fnc);
void iFpuippupp_32(x64emu_t *emu, uintptr_t fnc);
void iFXuupuupp_32(x64emu_t *emu, uintptr_t fnc);
void iFXLpipppp_32(x64emu_t *emu, uintptr_t fnc);
void iFXLppLpip_32(x64emu_t *emu, uintptr_t fnc);
Expand Down
4 changes: 2 additions & 2 deletions src/wrapped32/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,11 @@ GOM(getgrnam_r, iFEpppLp)
GOW(getgroups, iFip)
// __getgroups_chk
//GO(gethostbyaddr, pFpui)
//GO(gethostbyaddr_r, iFpuippupp)
GO(gethostbyaddr_r, iFpuippupp)
GOM(gethostbyname, pFEp)
//GO(gethostbyname2, pFpi)
//GO(gethostbyname2_r, iFpippupp)
//GO(gethostbyname_r, iFpppupp)
GOM(gethostbyname_r, iFEpppupp)
//GO(gethostent, pFv)
//GO(gethostent_r, iFppupp)
// gethostid
Expand Down

0 comments on commit 82c7d45

Please sign in to comment.