Skip to content

Commit

Permalink
[BOX32][WRAPPER] Added some more 32bits libc functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Sep 28, 2024
1 parent 11724fd commit 0f9dac5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/wrapped32/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
#() iFhi -> iFhi
#() iFhp -> iFhp
#() iFhh -> iFhh
#() iFSU -> iFSU
#() iFSp -> iFSp
#() iFXi -> iFXi
#() iFXL -> iFXL
Expand Down Expand Up @@ -547,6 +548,7 @@
#() iFiill -> iFiill
#() iFiuui -> iFiuui
#() iFipii -> iFipii
#() iFipui -> iFipui
#() iFipup -> iFipup
#() iFippi -> iFippi
#() iFuiup -> iFuiup
Expand Down Expand Up @@ -1253,6 +1255,8 @@ wrappedlibc:
- iFivpV:
- iFiiip:
- iFipii:
- iFippi:
- utimensat
- iFLLLL:
- iFpipp:
- iFpupV:
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 @@ -74,6 +74,7 @@ typedef void (*vFpppp_t)(void*, void*, void*, void*);
typedef int32_t (*iFivpV_t)(int32_t, void, void*, ...);
typedef int32_t (*iFiiip_t)(int32_t, int32_t, int32_t, void*);
typedef int32_t (*iFipii_t)(int32_t, void*, int32_t, int32_t);
typedef int32_t (*iFippi_t)(int32_t, void*, void*, int32_t);
typedef int32_t (*iFLLLL_t)(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
typedef int32_t (*iFpipp_t)(void*, int32_t, void*, void*);
typedef int32_t (*iFpupV_t)(void*, uint32_t, void*, ...);
Expand Down Expand Up @@ -149,6 +150,7 @@ typedef void* (*pFiiiiiiiiilt_t)(int32_t, int32_t, int32_t, int32_t, int32_t, in
GO(writev, lFipi_t) \
GO(__realpath_chk, pFppv_t) \
GO(__libc_init, vFpppp_t) \
GO(utimensat, iFippi_t) \
GO(getaddrinfo, iFpppp_t) \
GO(getgrgid_r, iFuppup_t) \
GO(getpwuid_r, iFuppLp_t) \
Expand Down
4 changes: 4 additions & 0 deletions src/wrapped32/generated/wrapper32.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ typedef int32_t (*iFpS_t)(void*, void*);
typedef int32_t (*iFhi_t)(uintptr_t, int32_t);
typedef int32_t (*iFhp_t)(uintptr_t, void*);
typedef int32_t (*iFhh_t)(uintptr_t, uintptr_t);
typedef int32_t (*iFSU_t)(void*, uint64_t);
typedef int32_t (*iFSp_t)(void*, void*);
typedef int32_t (*iFXi_t)(void*, int32_t);
typedef int32_t (*iFXL_t)(void*, uintptr_t);
Expand Down Expand Up @@ -637,6 +638,7 @@ typedef int32_t (*iFiiiN_t)(int32_t, int32_t, int32_t, ...);
typedef int32_t (*iFiill_t)(int32_t, int32_t, intptr_t, intptr_t);
typedef int32_t (*iFiuui_t)(int32_t, uint32_t, uint32_t, int32_t);
typedef int32_t (*iFipii_t)(int32_t, void*, int32_t, int32_t);
typedef int32_t (*iFipui_t)(int32_t, void*, uint32_t, int32_t);
typedef int32_t (*iFipup_t)(int32_t, void*, uint32_t, void*);
typedef int32_t (*iFippi_t)(int32_t, void*, void*, int32_t);
typedef int32_t (*iFuiup_t)(uint32_t, int32_t, uint32_t, void*);
Expand Down Expand Up @@ -1310,6 +1312,7 @@ void iFpS_32(x64emu_t *emu, uintptr_t fcn) { iFpS_t fn = (iFpS_t)fcn; R_EAX = fn
void iFhi_32(x64emu_t *emu, uintptr_t fcn) { iFhi_t fn = (iFhi_t)fcn; R_EAX = fn(from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptri(int32_t, R_ESP + 8)); }
void iFhp_32(x64emu_t *emu, uintptr_t fcn) { iFhp_t fn = (iFhp_t)fcn; R_EAX = fn(from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 8)); }
void iFhh_32(x64emu_t *emu, uintptr_t fcn) { iFhh_t fn = (iFhh_t)fcn; R_EAX = fn(from_hash(from_ptri(ptr_t, R_ESP + 4)), from_hash(from_ptri(ptr_t, R_ESP + 8))); }
void iFSU_32(x64emu_t *emu, uintptr_t fcn) { iFSU_t fn = (iFSU_t)fcn; R_EAX = fn(io_convert32(from_ptriv(R_ESP + 4)), from_ptri(uint64_t, R_ESP + 8)); }
void iFSp_32(x64emu_t *emu, uintptr_t fcn) { iFSp_t fn = (iFSp_t)fcn; R_EAX = fn(io_convert32(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8)); }
void iFXi_32(x64emu_t *emu, uintptr_t fcn) { iFXi_t fn = (iFXi_t)fcn; R_EAX = fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptri(int32_t, R_ESP + 8)); }
void iFXL_32(x64emu_t *emu, uintptr_t fcn) { iFXL_t fn = (iFXL_t)fcn; R_EAX = fn(getDisplay(from_ptriv(R_ESP + 4)), to_ulong(from_ptri(ulong_t, R_ESP + 8))); }
Expand Down Expand Up @@ -1711,6 +1714,7 @@ void iFiiiN_32(x64emu_t *emu, uintptr_t fcn) { iFiiiN_t fn = (iFiiiN_t)fcn; R_EA
void iFiill_32(x64emu_t *emu, uintptr_t fcn) { iFiill_t fn = (iFiill_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), to_long(from_ptri(long_t, R_ESP + 12)), to_long(from_ptri(long_t, R_ESP + 16))); }
void iFiuui_32(x64emu_t *emu, uintptr_t fcn) { iFiuui_t fn = (iFiuui_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); }
void iFipii_32(x64emu_t *emu, uintptr_t fcn) { iFipii_t fn = (iFipii_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); }
void iFipui_32(x64emu_t *emu, uintptr_t fcn) { iFipui_t fn = (iFipui_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); }
void iFipup_32(x64emu_t *emu, uintptr_t fcn) { iFipup_t fn = (iFipup_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptriv(R_ESP + 16)); }
void iFippi_32(x64emu_t *emu, uintptr_t fcn) { iFippi_t fn = (iFippi_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); }
void iFuiup_32(x64emu_t *emu, uintptr_t fcn) { iFuiup_t fn = (iFuiup_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_ptriv(R_ESP + 16)); }
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 @@ -187,6 +187,7 @@ void iFpS_32(x64emu_t *emu, uintptr_t fnc);
void iFhi_32(x64emu_t *emu, uintptr_t fnc);
void iFhp_32(x64emu_t *emu, uintptr_t fnc);
void iFhh_32(x64emu_t *emu, uintptr_t fnc);
void iFSU_32(x64emu_t *emu, uintptr_t fnc);
void iFSp_32(x64emu_t *emu, uintptr_t fnc);
void iFXi_32(x64emu_t *emu, uintptr_t fnc);
void iFXL_32(x64emu_t *emu, uintptr_t fnc);
Expand Down Expand Up @@ -588,6 +589,7 @@ void iFiiiN_32(x64emu_t *emu, uintptr_t fnc);
void iFiill_32(x64emu_t *emu, uintptr_t fnc);
void iFiuui_32(x64emu_t *emu, uintptr_t fnc);
void iFipii_32(x64emu_t *emu, uintptr_t fnc);
void iFipui_32(x64emu_t *emu, uintptr_t fnc);
void iFipup_32(x64emu_t *emu, uintptr_t fnc);
void iFippi_32(x64emu_t *emu, uintptr_t fnc);
void iFuiup_32(x64emu_t *emu, uintptr_t fnc);
Expand Down
2 changes: 1 addition & 1 deletion src/wrapped32/wrappedcrashhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const char* crashhandlerName = "crashhandler.so";
#define LIBNAME crashhandler

#define PRE_INIT \
if(!(box64_steam || box64_steamcmd)) \
if(!box64_dummy_crashhandler) \
return -1; \
if(1) \
lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);\
Expand Down
31 changes: 31 additions & 0 deletions src/wrapped32/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,37 @@ EXPORT void* my32_asctime(void* t)
return &ret;
}

EXPORT int my32_utimensat(int dirfd, void* name, void* times, int flags)
{
struct timespec times_l[2] = {0};
from_struct_LL((struct_LL_t*)&times_l[0], to_ptrv(times));
from_struct_LL((struct_LL_t*)&times_l[1], to_ptrv(times)+8);
return utimensat(dirfd, name, times_l, flags);
}


struct mallinfo {
int arena;
int ordblks;
int smblks;
int hblks;
int hblkhd;
int usmblks;
int fsmblks;
int uordblks;
int fordblks;
int keepcost;
};
EXPORT void* my32_mallinfo(x86emu_t* emu, void* p)
{
(void)emu;
static struct mallinfo(*p_mallinfo)() = NULL;
if(!p_mallinfo) p_mallinfo = dlsym(NULL, "mallinfo");
*((struct mallinfo*)p) = p_mallinfo();
return p;
}


#if 0
EXPORT int32_t my32_getrandom(x64emu_t* emu, void* buf, uint32_t buflen, uint32_t flags)
{
Expand Down
12 changes: 6 additions & 6 deletions src/wrapped32/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ GOWM(backtrace_symbols, pFEpi)
// bdflush
GOW(bind, iFipu)
// bindresvport
//GOW(bindtextdomain, pFpp)
GOW(bindtextdomain, pFpp)
GOW(bind_textdomain_codeset, pFpp)
//GOW(brk, iFp)
// __bsd_getpgrp
Expand Down Expand Up @@ -187,7 +187,7 @@ GOM(__cxa_atexit, iFEppp) //%%
GOM(atexit, iFEp) //%% just in case
GOM(__cxa_finalize, vFEp) //%%
DATAM(__cpu_model, 16)
//GOM(__cxa_thread_atexit_impl, iFEppp) //%%
GOM(__cxa_thread_atexit_impl, iFEppp) //%%
// __cyg_profile_func_enter
// __cyg_profile_func_exit
// daemon
Expand Down Expand Up @@ -302,7 +302,7 @@ GO(faccessat, iFipii)
GOW(fchdir, iFi)
// fchflags
GOW(fchmod, iFiu)
//GO(fchmodat, iFipui)
GO(fchmodat, iFipui)
GOW(fchown, iFiuu)
//GO(fchownat, iFipuii)
GO(fclose, iFS)
Expand Down Expand Up @@ -527,7 +527,7 @@ GO(getnameinfo, iFpupLpLi)
// getnetgrent
// getnetgrent_r // Weak
// getnetname
//GOW(get_nprocs, iFv)
GOW(get_nprocs, iFv)
//GOW(get_nprocs_conf, iFv)
//GOM(getopt, iFipp) //%noE
//GOM(getopt_long, iFipppp) //%noE
Expand Down Expand Up @@ -1835,7 +1835,7 @@ GO(__towupper_l, iFia)
GOW(towupper_l, iFia)
// tr_break
//GOW(truncate, iFpu)
//GO(truncate64, iFpU)
GO(truncate64, iFSU)
// tsearch // Weak
//GO(ttyname, pFi)
//GOW(ttyname_r, iFipu)
Expand Down Expand Up @@ -1870,7 +1870,7 @@ GO(__uselocale, aFa)
GO(usleep, iFu)
// ustat
GO(utime, iFprLL_)
//GO(utimensat, iFippi)
GOM(utimensat, iFippi) //%noE
GOWM(utimes, iFEpp)
//GOW(utmpname, iFp)
// utmpxname
Expand Down

0 comments on commit 0f9dac5

Please sign in to comment.