From ee561da549fb6f47f4b301466f2f751a085fa6d5 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 28 Mar 2021 15:54:51 +0200 Subject: Added more libc and pthreads wrapped functions --- src/include/myalign.h | 18 ++++++++ src/libtools/myalign.c | 18 -------- src/wrapped/generated/functions_list.txt | 2 + src/wrapped/generated/wrapper.c | 4 ++ src/wrapped/generated/wrapper.h | 2 + src/wrapped/wrappedlibc.c | 77 ++++---------------------------- src/wrapped/wrappedlibc_private.h | 20 ++++----- src/wrapped/wrappedlibpthread_private.h | 2 +- 8 files changed, 45 insertions(+), 98 deletions(-) (limited to 'src') diff --git a/src/include/myalign.h b/src/include/myalign.h index 9ffc42d9..6822ec26 100755 --- a/src/include/myalign.h +++ b/src/include/myalign.h @@ -90,6 +90,24 @@ void myStackAlignScanf(x64emu_t* emu, const char* fmt, uint64_t* st, uint64_t* m void myStackAlignGVariantNew(x64emu_t* emu, const char* fmt, uint64_t* st, uint64_t* mystack, int xmm, int pos); void myStackAlignW(x64emu_t* emu, const char* fmt, uint64_t* st, uint64_t* mystack, int xmm, int pos); +struct x64_stat64 { /* x86_64 arm64 */ + uint64_t st_dev; /* 0 */ /* 0 */ + uint64_t st_ino; /* 8 */ /* 8 */ + uint64_t st_nlink; /* 16 */ /* 20 */ + uint32_t st_mode; /* 24 */ /* 16 */ + uint32_t st_uid; /* 28 */ /* 24 */ + uint32_t st_gid; /* 32 */ /* 28 */ + int __pad0; /* 36 */ /* --- */ + uint64_t st_rdev; /* 40 */ /* 32 */ + int64_t st_size; /* 48 */ /* 48 */ + int64_t st_blksize; /* 56 */ /* 56 */ + uint64_t st_blocks; /* 64 */ /* 64 */ + struct timespec st_atim; /* 72 */ /* 72 */ + struct timespec st_mtim; /* 88 */ /* 88 */ + struct timespec st_ctim; /* 104 */ /* 104 */ + uint64_t __glibc_reserved[3]; /* 120 */ /* 120 */ +} __attribute__((packed)); /* 144 */ /* 128 */ + void UnalignStat64(const void* source, void* dest); // defined in wrapperlibc.c diff --git a/src/libtools/myalign.c b/src/libtools/myalign.c index 9f98e159..0998f18f 100755 --- a/src/libtools/myalign.c +++ b/src/libtools/myalign.c @@ -551,24 +551,6 @@ void myStackAlignGVariantNew(const char* fmt, uint32_t* st, uint32_t* mystack) #undef st_mtime #undef st_ctime -struct x64_stat64 { /* x86_64 arm64 */ - uint64_t st_dev; /* 0 */ /* 0 */ - uint64_t st_ino; /* 8 */ /* 8 */ - uint64_t st_nlink; /* 16 */ /* 20 */ - uint32_t st_mode; /* 24 */ /* 16 */ - uint32_t st_uid; /* 28 */ /* 24 */ - uint32_t st_gid; /* 32 */ /* 28 */ - int __pad0; /* 36 */ /* --- */ - uint64_t st_rdev; /* 40 */ /* 32 */ - int64_t st_size; /* 48 */ /* 48 */ - int64_t st_blksize; /* 56 */ /* 56 */ - uint64_t st_blocks; /* 64 */ /* 64 */ - struct timespec st_atim; /* 72 */ /* 72 */ - struct timespec st_mtim; /* 88 */ /* 88 */ - struct timespec st_ctim; /* 104 */ /* 104 */ - uint64_t __glibc_reserved[3]; /* 120 */ /* 120 */ -} __attribute__((packed)); /* 144 */ /* 128 */ - void UnalignStat64(const void* source, void* dest) { struct x64_stat64 *x64st = (struct x64_stat64*)dest; diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index 74c88e76..d3d4bfa1 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -130,6 +130,7 @@ #() uFpL #() uFpp #() UFEp +#() UFii #() UFUp #() UFpp #() fFif @@ -612,6 +613,7 @@ #() iFEpipV #() iFEpLpp #() iFEpLpV +#() iFEppii #() iFEppip #() iFEppiV #() iFEpplp diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c index 1989b4d0..b718a606 100644 --- a/src/wrapped/generated/wrapper.c +++ b/src/wrapped/generated/wrapper.c @@ -163,6 +163,7 @@ typedef uint32_t (*uFpU_t)(void*, uint64_t); typedef uint32_t (*uFpL_t)(void*, uintptr_t); typedef uint32_t (*uFpp_t)(void*, void*); typedef uint64_t (*UFEp_t)(x64emu_t*, void*); +typedef uint64_t (*UFii_t)(int32_t, int32_t); typedef uint64_t (*UFUp_t)(uint64_t, void*); typedef uint64_t (*UFpp_t)(void*, void*); typedef float (*fFif_t)(int32_t, float); @@ -645,6 +646,7 @@ typedef int32_t (*iFEpipp_t)(x64emu_t*, void*, int32_t, void*, void*); typedef int32_t (*iFEpipV_t)(x64emu_t*, void*, int32_t, void*, void*); typedef int32_t (*iFEpLpp_t)(x64emu_t*, void*, uintptr_t, void*, void*); typedef int32_t (*iFEpLpV_t)(x64emu_t*, void*, uintptr_t, void*, void*); +typedef int32_t (*iFEppii_t)(x64emu_t*, void*, void*, int32_t, int32_t); typedef int32_t (*iFEppip_t)(x64emu_t*, void*, void*, int32_t, void*); typedef int32_t (*iFEppiV_t)(x64emu_t*, void*, void*, int32_t, void*); typedef int32_t (*iFEpplp_t)(x64emu_t*, void*, void*, intptr_t, void*); @@ -1243,6 +1245,7 @@ void uFpU(x64emu_t *emu, uintptr_t fcn) { uFpU_t fn = (uFpU_t)fcn; R_RAX=(uint32 void uFpL(x64emu_t *emu, uintptr_t fcn) { uFpL_t fn = (uFpL_t)fcn; R_RAX=(uint32_t)fn((void*)R_RDI, (uintptr_t)R_RSI); } void uFpp(x64emu_t *emu, uintptr_t fcn) { uFpp_t fn = (uFpp_t)fcn; R_RAX=(uint32_t)fn((void*)R_RDI, (void*)R_RSI); } void UFEp(x64emu_t *emu, uintptr_t fcn) { UFEp_t fn = (UFEp_t)fcn; R_RAX=fn(emu, (void*)R_RDI); } +void UFii(x64emu_t *emu, uintptr_t fcn) { UFii_t fn = (UFii_t)fcn; R_RAX=fn((int32_t)R_RDI, (int32_t)R_RSI); } void UFUp(x64emu_t *emu, uintptr_t fcn) { UFUp_t fn = (UFUp_t)fcn; R_RAX=fn((uint64_t)R_RDI, (void*)R_RSI); } void UFpp(x64emu_t *emu, uintptr_t fcn) { UFpp_t fn = (UFpp_t)fcn; R_RAX=fn((void*)R_RDI, (void*)R_RSI); } void fFif(x64emu_t *emu, uintptr_t fcn) { fFif_t fn = (fFif_t)fcn; emu->xmm[0].f[0]=fn((int32_t)R_RDI, emu->xmm[0].f[0]); } @@ -1725,6 +1728,7 @@ void iFEpipp(x64emu_t *emu, uintptr_t fcn) { iFEpipp_t fn = (iFEpipp_t)fcn; R_RA void iFEpipV(x64emu_t *emu, uintptr_t fcn) { iFEpipV_t fn = (iFEpipV_t)fcn; R_RAX=fn(emu, (void*)R_RDI, (int32_t)R_RSI, (void*)R_RDX, (void*)(R_RSP + 8)); } void iFEpLpp(x64emu_t *emu, uintptr_t fcn) { iFEpLpp_t fn = (iFEpLpp_t)fcn; R_RAX=fn(emu, (void*)R_RDI, (uintptr_t)R_RSI, (void*)R_RDX, (void*)R_RCX); } void iFEpLpV(x64emu_t *emu, uintptr_t fcn) { iFEpLpV_t fn = (iFEpLpV_t)fcn; R_RAX=fn(emu, (void*)R_RDI, (uintptr_t)R_RSI, (void*)R_RDX, (void*)(R_RSP + 8)); } +void iFEppii(x64emu_t *emu, uintptr_t fcn) { iFEppii_t fn = (iFEppii_t)fcn; R_RAX=fn(emu, (void*)R_RDI, (void*)R_RSI, (int32_t)R_RDX, (int32_t)R_RCX); } void iFEppip(x64emu_t *emu, uintptr_t fcn) { iFEppip_t fn = (iFEppip_t)fcn; R_RAX=fn(emu, (void*)R_RDI, (void*)R_RSI, (int32_t)R_RDX, (void*)R_RCX); } void iFEppiV(x64emu_t *emu, uintptr_t fcn) { iFEppiV_t fn = (iFEppiV_t)fcn; R_RAX=fn(emu, (void*)R_RDI, (void*)R_RSI, (int32_t)R_RDX, (void*)(R_RSP + 8)); } void iFEpplp(x64emu_t *emu, uintptr_t fcn) { iFEpplp_t fn = (iFEpplp_t)fcn; R_RAX=fn(emu, (void*)R_RDI, (void*)R_RSI, (intptr_t)R_RDX, (void*)R_RCX); } diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h index 405e8085..e574cd42 100644 --- a/src/wrapped/generated/wrapper.h +++ b/src/wrapped/generated/wrapper.h @@ -160,6 +160,7 @@ void uFpU(x64emu_t *emu, uintptr_t fnc); void uFpL(x64emu_t *emu, uintptr_t fnc); void uFpp(x64emu_t *emu, uintptr_t fnc); void UFEp(x64emu_t *emu, uintptr_t fnc); +void UFii(x64emu_t *emu, uintptr_t fnc); void UFUp(x64emu_t *emu, uintptr_t fnc); void UFpp(x64emu_t *emu, uintptr_t fnc); void fFif(x64emu_t *emu, uintptr_t fnc); @@ -642,6 +643,7 @@ void iFEpipp(x64emu_t *emu, uintptr_t fnc); void iFEpipV(x64emu_t *emu, uintptr_t fnc); void iFEpLpp(x64emu_t *emu, uintptr_t fnc); void iFEpLpV(x64emu_t *emu, uintptr_t fnc); +void iFEppii(x64emu_t *emu, uintptr_t fnc); void iFEppip(x64emu_t *emu, uintptr_t fnc); void iFEppiV(x64emu_t *emu, uintptr_t fnc); void iFEpplp(x64emu_t *emu, uintptr_t fnc); diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 529a2f70..a52fd186 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -159,40 +159,15 @@ static void* findcompareFct(void* fct) printf_log(LOG_NONE, "Warning, no more slot for libc compare callback\n"); return NULL; } -#if 0 - -// ftw -#define GO(A) \ -static uintptr_t my_ftw_fct_##A = 0; \ -static int my_ftw_##A(void* fpath, void* sb, int flag) \ -{ \ - return (int)RunFunction(my_context, my_ftw_fct_##A, 3, fpath, sb, flag); \ -} -SUPER() -#undef GO -static void* findftwFct(void* fct) -{ - if(!fct) return NULL; - void* p; - if((p = GetNativeFnc((uintptr_t)fct))) return p; - #define GO(A) if(my_ftw_fct_##A == (uintptr_t)fct) return my_ftw_##A; - SUPER() - #undef GO - #define GO(A) if(my_ftw_fct_##A == 0) {my_ftw_fct_##A = (uintptr_t)fct; return my_ftw_##A; } - SUPER() - #undef GO - printf_log(LOG_NONE, "Warning, no more slot for libc ftw callback\n"); - return NULL; -} // ftw64 #define GO(A) \ static uintptr_t my_ftw64_fct_##A = 0; \ static int my_ftw64_##A(void* fpath, void* sb, int flag) \ { \ - struct i386_stat64 i386st; \ - UnalignStat64(sb, &i386st); \ - return (int)RunFunction(my_context, my_ftw64_fct_##A, 3, fpath, &i386st, flag); \ + struct x64_stat64 x64st; \ + UnalignStat64(sb, &x64st); \ + return (int)RunFunction(my_context, my_ftw64_fct_##A, 3, fpath, &x64st, flag); \ } SUPER() #undef GO @@ -209,38 +184,14 @@ static void* findftw64Fct(void* fct) return NULL; } -// nftw -#define GO(A) \ -static uintptr_t my_nftw_fct_##A = 0; \ -static int my_nftw_##A(void* fpath, void* sb, int flag, void* ftwbuff) \ -{ \ - return (int)RunFunction(my_context, my_nftw_fct_##A, 4, fpath, sb, flag, ftwbuff); \ -} -SUPER() -#undef GO -static void* findnftwFct(void* fct) -{ - if(!fct) return NULL; - void* p; - if((p = GetNativeFnc((uintptr_t)fct))) return p; - #define GO(A) if(my_nftw_fct_##A == (uintptr_t)fct) return my_nftw_##A; - SUPER() - #undef GO - #define GO(A) if(my_nftw_fct_##A == 0) {my_nftw_fct_##A = (uintptr_t)fct; return my_nftw_##A; } - SUPER() - #undef GO - printf_log(LOG_NONE, "Warning, no more slot for libc nftw callback\n"); - return NULL; -} - // nftw64 #define GO(A) \ static uintptr_t my_nftw64_fct_##A = 0; \ static int my_nftw64_##A(void* fpath, void* sb, int flag, void* ftwbuff) \ { \ - struct i386_stat64 i386st; \ - UnalignStat64(sb, &i386st); \ - return (int)RunFunction(my_context, my_nftw64_fct_##A, 4, fpath, &i386st, flag, ftwbuff); \ + struct x64_stat64 x64st; \ + UnalignStat64(sb, &x64st); \ + return (int)RunFunction(my_context, my_nftw64_fct_##A, 4, fpath, &x64st, flag, ftwbuff); \ } SUPER() #undef GO @@ -256,7 +207,7 @@ static void* findnftw64Fct(void* fct) printf_log(LOG_NONE, "Warning, no more slot for libc nftw64 callback\n"); return NULL; } - +#if 0 // globerr #define GO(A) \ static uintptr_t my_globerr_fct_##A = 0; \ @@ -1495,18 +1446,6 @@ EXPORT int my_scandir64(x64emu_t *emu, void* dir, void* namelist, void* sel, voi { return scandir64(dir, namelist, findfilter64Fct(sel), findcompare64Fct(comp)); } -#if 0 -EXPORT int my_scandir(x64emu_t *emu, void* dir, void* namelist, void* sel, void* comp) -{ - static iFpppp_t f = NULL; - if(!f) { - library_t* lib = my_lib; - if(!lib) return 0; - f = (iFpppp_t)dlsym(lib->priv.w.lib, "scandir"); - } - - return f(dir, namelist, findfilter_dirFct(sel), findcompare_dirFct(comp)); -} EXPORT int my_ftw64(x64emu_t* emu, void* filename, void* func, int descriptors) { @@ -1517,7 +1456,7 @@ EXPORT int32_t my_nftw64(x64emu_t* emu, void* pathname, void* B, int32_t nopenfd { return nftw64(pathname, findnftw64Fct(B), nopenfd, flags); } -#endif + EXPORT int32_t my_execv(x64emu_t* emu, const char* path, char* const argv[]) { int self = isProcSelf(path, "exe"); diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index f8b93a1e..c4716f7e 100755 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -200,7 +200,7 @@ GOM(__cxa_finalize, vFEp) GO(difftime, dFLL) //GO(dirfd, GO(dirname, pFp) -//GO(div, +GO(div, UFii) //GO(_dl_addr, //GO(_dl_catch_error, //GO(_dl_catch_exception, @@ -237,7 +237,7 @@ GOW(duplocale, pFp) //GOW(endmntent, //GO(endnetent, //GO(endnetgrent, -//GO(endprotoent, +GO(endprotoent, vFv) //GO(endpwent, //GO(endrpcent, //GO(endservent, @@ -443,7 +443,7 @@ GOW(ftruncate64, iFiI) //GO(fts_read, //GO(fts_set, //GO(ftw, -//GOW(ftw64, +GOM(ftw64, iFEppi) //GOW(funlockfile, //GO(futimens, //GOW(futimes, @@ -521,7 +521,7 @@ GO(getgrent, pFv) //GO(gethostid, GOW(gethostname, iFpL) //GO(__gethostname_chk, -//GOW(getifaddrs, +GOW(getifaddrs, iFp) //GO(getipv4sourcefilter, //GOW(getitimer, //GO(get_kernel_syms, @@ -563,11 +563,11 @@ GO(getpid, uFv) //GO(getpmsg, //GOW(getppid, GOW(getpriority, iFii) -//GO(getprotobyname, +GO(getprotobyname, pFp) //GO(getprotobyname_r, -//GO(getprotobynumber, +GO(getprotobynumber, pFp) //GO(getprotobynumber_r, -//GO(getprotoent, +GO(getprotoent, pFv) //GO(getprotoent_r, //GOW(getpt, //GO(getpublickey, @@ -1190,7 +1190,7 @@ GOM(mremap, pFEpLLiN) //weal //GO(msgget, //GOW(msgrcv, //GOW(msgsnd, -//GO(msync, +GO(msync, iFpLi) //GO(mtrace, //GO(munlock, //GO(munlockall, @@ -1209,7 +1209,7 @@ GOW(newlocale, pFipp) //GO(nfsservctl, //GO(nftw, //GO(nftw, -//GO(nftw64, +GOM(nftw64, iFEppii) //GO(nftw64, //GOW(ngettext, //GO(nice, @@ -1632,7 +1632,7 @@ GO(setlocale, pFip) //GOW(setpgid, //GO(setpgrp, GOW(setpriority, iFiii) -//GO(setprotoent, +GO(setprotoent, vFi) //GO(setpwent, //GOW(setregid, //GOW(setresgid, diff --git a/src/wrapped/wrappedlibpthread_private.h b/src/wrapped/wrappedlibpthread_private.h index f80d3e15..facad12d 100755 --- a/src/wrapped/wrappedlibpthread_private.h +++ b/src/wrapped/wrappedlibpthread_private.h @@ -72,7 +72,7 @@ GOM(pthread_cond_wait, iFEpp) GOM(pthread_create, iFEpppp) GO(pthread_detach, iFL) GO(pthread_equal, iFLL) -//GOM(pthread_exit, vFEp) +GOM(pthread_exit, vFEp) //GOM(pthread_getaffinity_np, iFEpup) GO(pthread_getattr_np, iFLp) //GO(pthread_getconcurrency, iFv) -- cgit 1.4.1