From ee6e3a7a96ad7ee9aa3ffee3d0b3c2e4d9406f38 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 9 Nov 2024 16:13:18 +0100 Subject: [PATCH] [WRAPPER] Added a bunch of libc wrapped functions (for #2010) --- src/wrapped/generated/functions_list.txt | 4 ++++ src/wrapped/generated/wrappedlibctypes.h | 3 +++ src/wrapped/generated/wrapper.c | 2 ++ src/wrapped/generated/wrapper.h | 1 + src/wrapped/wrappedlibc.c | 7 ++++++- src/wrapped/wrappedlibc_private.h | 12 +++++++++--- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index 7518a6583..63e5f2c68 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -1787,6 +1787,7 @@ #() UFuiCiu #() lFEippL #() lFEuipp +#() lFEppLL #() lFipiIi #() lFipili #() lFipLli @@ -4461,6 +4462,7 @@ wrappedlibc: - sscanf - swscanf - iFppA: + - __isoc23_vsscanf - __isoc99_vfscanf - __isoc99_vsscanf - __isoc99_vswscanf @@ -4554,6 +4556,8 @@ wrappedlibc: - readlinkat - lFuipp: - ptrace +- lFppLL: + - __readlink_chk - vFpLLpp: - qsort_r - iFiipup: diff --git a/src/wrapped/generated/wrappedlibctypes.h b/src/wrapped/generated/wrappedlibctypes.h index ea45efdae..457a83276 100644 --- a/src/wrapped/generated/wrappedlibctypes.h +++ b/src/wrapped/generated/wrappedlibctypes.h @@ -82,6 +82,7 @@ typedef int32_t (*iFppii_t)(void*, void*, int32_t, int32_t); typedef int32_t (*iFpppp_t)(void*, void*, void*, void*); typedef intptr_t (*lFippL_t)(int32_t, void*, void*, uintptr_t); typedef intptr_t (*lFuipp_t)(uint32_t, int32_t, void*, void*); +typedef intptr_t (*lFppLL_t)(void*, void*, uintptr_t, uintptr_t); typedef void (*vFpLLpp_t)(void*, uintptr_t, uintptr_t, void*, void*); typedef int32_t (*iFiipup_t)(int32_t, int32_t, void*, uint32_t, void*); typedef int32_t (*iFiippi_t)(int32_t, int32_t, void*, void*, int32_t); @@ -229,6 +230,7 @@ typedef int32_t (*iFppipppp_t)(void*, void*, int32_t, void*, void*, void*, void* GO(sprintf, iFppV_t) \ GO(sscanf, iFppV_t) \ GO(swscanf, iFppV_t) \ + GO(__isoc23_vsscanf, iFppA_t) \ GO(__isoc99_vfscanf, iFppA_t) \ GO(__isoc99_vsscanf, iFppA_t) \ GO(__isoc99_vswscanf, iFppA_t) \ @@ -292,6 +294,7 @@ typedef int32_t (*iFppipppp_t)(void*, void*, int32_t, void*, void*, void*, void* GO(scandir64, iFpppp_t) \ GO(readlinkat, lFippL_t) \ GO(ptrace, lFuipp_t) \ + GO(__readlink_chk, lFppLL_t) \ GO(qsort_r, vFpLLpp_t) \ GO(__xmknodat, iFiipup_t) \ GO(__fxstatat, iFiippi_t) \ diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c index f254c5ad8..2e9067929 100644 --- a/src/wrapped/generated/wrapper.c +++ b/src/wrapped/generated/wrapper.c @@ -1816,6 +1816,7 @@ typedef uint32_t (*uFbuuup_t)(void*, uint32_t, uint32_t, uint32_t, void*); typedef uint64_t (*UFuiCiu_t)(uint32_t, int32_t, uint8_t, int32_t, uint32_t); typedef intptr_t (*lFEippL_t)(x64emu_t*, int32_t, void*, void*, uintptr_t); typedef intptr_t (*lFEuipp_t)(x64emu_t*, uint32_t, int32_t, void*, void*); +typedef intptr_t (*lFEppLL_t)(x64emu_t*, void*, void*, uintptr_t, uintptr_t); typedef intptr_t (*lFipiIi_t)(int32_t, void*, int32_t, int64_t, int32_t); typedef intptr_t (*lFipili_t)(int32_t, void*, int32_t, intptr_t, int32_t); typedef intptr_t (*lFipLli_t)(int32_t, void*, uintptr_t, intptr_t, int32_t); @@ -5151,6 +5152,7 @@ void uFbuuup(x64emu_t *emu, uintptr_t fcn) { uFbuuup_t fn = (uFbuuup_t)fcn; void void UFuiCiu(x64emu_t *emu, uintptr_t fcn) { UFuiCiu_t fn = (UFuiCiu_t)fcn; R_RAX=fn((uint32_t)R_RDI, (int32_t)R_RSI, (uint8_t)R_RDX, (int32_t)R_RCX, (uint32_t)R_R8); } void lFEippL(x64emu_t *emu, uintptr_t fcn) { lFEippL_t fn = (lFEippL_t)fcn; R_RAX=(intptr_t)fn(emu, (int32_t)R_RDI, (void*)R_RSI, (void*)R_RDX, (uintptr_t)R_RCX); } void lFEuipp(x64emu_t *emu, uintptr_t fcn) { lFEuipp_t fn = (lFEuipp_t)fcn; R_RAX=(intptr_t)fn(emu, (uint32_t)R_RDI, (int32_t)R_RSI, (void*)R_RDX, (void*)R_RCX); } +void lFEppLL(x64emu_t *emu, uintptr_t fcn) { lFEppLL_t fn = (lFEppLL_t)fcn; R_RAX=(intptr_t)fn(emu, (void*)R_RDI, (void*)R_RSI, (uintptr_t)R_RDX, (uintptr_t)R_RCX); } void lFipiIi(x64emu_t *emu, uintptr_t fcn) { lFipiIi_t fn = (lFipiIi_t)fcn; R_RAX=(intptr_t)fn((int32_t)R_RDI, (void*)R_RSI, (int32_t)R_RDX, (int64_t)R_RCX, (int32_t)R_R8); } void lFipili(x64emu_t *emu, uintptr_t fcn) { lFipili_t fn = (lFipili_t)fcn; R_RAX=(intptr_t)fn((int32_t)R_RDI, (void*)R_RSI, (int32_t)R_RDX, (intptr_t)R_RCX, (int32_t)R_R8); } void lFipLli(x64emu_t *emu, uintptr_t fcn) { lFipLli_t fn = (lFipLli_t)fcn; R_RAX=(intptr_t)fn((int32_t)R_RDI, (void*)R_RSI, (uintptr_t)R_RDX, (intptr_t)R_RCX, (int32_t)R_R8); } diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h index 7a6454cee..151210c85 100644 --- a/src/wrapped/generated/wrapper.h +++ b/src/wrapped/generated/wrapper.h @@ -1824,6 +1824,7 @@ void uFbuuup(x64emu_t *emu, uintptr_t fnc); void UFuiCiu(x64emu_t *emu, uintptr_t fnc); void lFEippL(x64emu_t *emu, uintptr_t fnc); void lFEuipp(x64emu_t *emu, uintptr_t fnc); +void lFEppLL(x64emu_t *emu, uintptr_t fnc); void lFipiIi(x64emu_t *emu, uintptr_t fnc); void lFipili(x64emu_t *emu, uintptr_t fnc); void lFipLli(x64emu_t *emu, uintptr_t fnc); diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index f341abaf0..ba56c7c1a 100644 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -1715,6 +1715,11 @@ EXPORT ssize_t my_readlink(x64emu_t* emu, void* path, void* buf, size_t sz) return readlink((const char*)path, (char*)buf, sz); } +EXPORT ssize_t my___readlink_chk(x64emu_t* emu, void* path, void* buf, size_t sz, size_t buflen) +{ + return my_readlink(emu, path, buf, sz); +} + int getNCpu(); // defined in my_cpuid.c const char* getBoxCpuName(); // defined in my_cpuid.c const char* getCpuName(); // defined in my_cpu_id.c @@ -3163,7 +3168,7 @@ EXPORT int my_mprotect(x64emu_t* emu, void *addr, unsigned long len, int prot) if(prot& PROT_EXEC) addDBFromAddressRange((uintptr_t)addr, len); else - cleanDBFromAddressRange((uintptr_t)addr, len, 1); + cleanDBFromAddressRange((uintptr_t)addr, len, (!prot)?1:0); } #endif if(!ret && len) { diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index 18eb894c3..9f63a9b49 100644 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -590,7 +590,7 @@ GO(gethostent, pFv) GO(gethostent_r, iFppLpp) GO(gethostid, lFv) GOW(gethostname, iFpL) -//GO(__gethostname_chk, +GO(__gethostname_chk, iFpLL) GOW(getifaddrs, iFp) GO(getipv4sourcefilter, iFiuuppp) GOW(getitimer, iFup) @@ -1601,7 +1601,7 @@ GOW(readdir_r, iFppp) GOWM(readlink, lFEppL) GOM(readlinkat, lFEippL) //GO(__readlinkat_chk, -//GO(__readlink_chk, +GOM(__readlink_chk, lFEppLL) //GO(__read_nocancel, GOW(readv, lFipi) GO(realloc, pFpL) @@ -2018,6 +2018,12 @@ GOW(strtof_l, fFppp) //GO(__strtof_nan, GO(strtoimax, IFppi) GO2(__isoc23_strtoimax, IFppi, strtoimax) +GO2(__isoc23_strtoll_l, IFppip, strtoll_l) +GO2(__isoc23_strtoull_l, UFppip, strtoull_l) +GO2(__isoc23_vsscanf, iFEppA, my_vsscanf) +GO2(__isoc23_wcstoll, IFppi, wcstoll) +GO2(__isoc23_wcstoul, LFppi, wcstoul) +GO2(__isoc23_wcstoull, UFppi, wcstoull) GO(strtok, pFpp) GO(__strtok_r, pFppp) GOW(strtok_r, pFppp) @@ -2399,7 +2405,7 @@ GOW(wcstoll, IFppi) //GOW(__wcstoll_l, GOW(wcstoll_l, IFppip) GO(wcstombs, LFppL) -//GO(__wcstombs_chk, +GO(__wcstombs_chk, LFppLL) GOW(wcstoq, IFppi) GO(wcstoul, LFppi) //GO(__wcstoul_internal,