diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-03-25 17:02:51 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-03-25 17:02:51 +0100 |
| commit | a701ff87ecb8c74d0a1da2e5b3d00c3ccde91aae (patch) | |
| tree | 03910bfb57e6c155c920b7f61f0dd1248d7911da /src | |
| parent | 6e78bc1726047f5462517d5fd1954fcbe080e1b4 (diff) | |
| download | box64-a701ff87ecb8c74d0a1da2e5b3d00c3ccde91aae.tar.gz box64-a701ff87ecb8c74d0a1da2e5b3d00c3ccde91aae.zip | |
More libc wrapped symbols
Diffstat (limited to 'src')
| -rwxr-xr-x | src/elfs/elfloader.c | 21 | ||||
| -rw-r--r-- | src/wrapped/generated/functions_list.txt | 1 | ||||
| -rw-r--r-- | src/wrapped/generated/wrapper.c | 2 | ||||
| -rw-r--r-- | src/wrapped/generated/wrapper.h | 1 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibc.c | 9 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibc_private.h | 15 |
6 files changed, 39 insertions, 10 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index 652ec253..e1dc2ca1 100755 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -552,6 +552,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c uintptr_t globoffs, globend; uint64_t* globp; uintptr_t tmp = 0; + intptr_t delta; switch(ELF64_R_TYPE(rela[i].r_info)) { case R_X86_64_NONE: case R_X86_64_PC32: @@ -646,6 +647,26 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c *p /*+*/= offs+rela[i].r_addend; } break; + case R_X86_64_TPOFF64: + // Negated offset in static TLS block + { + if(h_tls) + offs = sym->st_value; + else { + if(local_maplib) + h_tls = GetGlobalSymbolElf(local_maplib, symname); + if(!h_tls) + h_tls = GetGlobalSymbolElf(maplib, symname); + } + if(h_tls) { + delta = *(int*)p; + printf_log(LOG_DUMP, "Applying %s %s on %s @%p (%ld -> %ld)\n", (bind==STB_LOCAL)?"Local":"Global", DumpRelType(t), symname, p, delta, (int64_t)offs + h_tls->tlsbase); + *p = (uintptr_t)((int64_t)offs + h_tls->tlsbase); + } else { + printf_log(LOG_INFO, "Warning, cannot apply %s %s on %s @%p (%ld), no elf_header found\n", (bind==STB_LOCAL)?"Local":"Global", DumpRelType(t), symname, p, (int64_t)offs); + } + } + break; case R_X86_64_DTPMOD64: // ID of module containing symbol if(!symname || symname[0]=='\0' || bind==STB_LOCAL) diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index 1a50a2f1..7dcdcc32 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -256,7 +256,6 @@ #() iFppd #() iFppL #() iFppp -#() iFppV #() iFSpL #() IFiIi #() IFpIi diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c index 59db1f3e..6924df29 100644 --- a/src/wrapped/generated/wrapper.c +++ b/src/wrapped/generated/wrapper.c @@ -289,7 +289,6 @@ typedef int32_t (*iFppu_t)(void*, void*, uint32_t); typedef int32_t (*iFppd_t)(void*, void*, double); typedef int32_t (*iFppL_t)(void*, void*, uintptr_t); typedef int32_t (*iFppp_t)(void*, void*, void*); -typedef int32_t (*iFppV_t)(void*, void*, void*); typedef int32_t (*iFSpL_t)(void*, void*, uintptr_t); typedef int64_t (*IFiIi_t)(int32_t, int64_t, int32_t); typedef int64_t (*IFpIi_t)(void*, int64_t, int32_t); @@ -1320,7 +1319,6 @@ void iFppu(x64emu_t *emu, uintptr_t fcn) { iFppu_t fn = (iFppu_t)fcn; R_RAX=fn(( void iFppd(x64emu_t *emu, uintptr_t fcn) { iFppd_t fn = (iFppd_t)fcn; R_RAX=fn((void*)R_RDI, (void*)R_RSI, emu->xmm[0].d[0]); } void iFppL(x64emu_t *emu, uintptr_t fcn) { iFppL_t fn = (iFppL_t)fcn; R_RAX=fn((void*)R_RDI, (void*)R_RSI, (uintptr_t)R_RDX); } void iFppp(x64emu_t *emu, uintptr_t fcn) { iFppp_t fn = (iFppp_t)fcn; R_RAX=fn((void*)R_RDI, (void*)R_RSI, (void*)R_RDX); } -void iFppV(x64emu_t *emu, uintptr_t fcn) { iFppV_t fn = (iFppV_t)fcn; R_RAX=fn((void*)R_RDI, (void*)R_RSI, (void*)(R_RSP + 8)); } void iFSpL(x64emu_t *emu, uintptr_t fcn) { iFSpL_t fn = (iFSpL_t)fcn; R_RAX=fn(io_convert((void*)R_RDI), (void*)R_RSI, (uintptr_t)R_RDX); } void IFiIi(x64emu_t *emu, uintptr_t fcn) { IFiIi_t fn = (IFiIi_t)fcn; R_RAX=(uint64_t)fn((int32_t)R_RDI, (int64_t)R_RSI, (int32_t)R_RDX); } void IFpIi(x64emu_t *emu, uintptr_t fcn) { IFpIi_t fn = (IFpIi_t)fcn; R_RAX=(uint64_t)fn((void*)R_RDI, (int64_t)R_RSI, (int32_t)R_RDX); } diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h index a908a234..bd960aff 100644 --- a/src/wrapped/generated/wrapper.h +++ b/src/wrapped/generated/wrapper.h @@ -286,7 +286,6 @@ void iFppu(x64emu_t *emu, uintptr_t fnc); void iFppd(x64emu_t *emu, uintptr_t fnc); void iFppL(x64emu_t *emu, uintptr_t fnc); void iFppp(x64emu_t *emu, uintptr_t fnc); -void iFppV(x64emu_t *emu, uintptr_t fnc); void iFSpL(x64emu_t *emu, uintptr_t fnc); void IFiIi(x64emu_t *emu, uintptr_t fnc); void IFpIi(x64emu_t *emu, uintptr_t fnc); diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 21329bef..1662f1bf 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -758,8 +758,15 @@ EXPORT int my__IO_vfscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __att EXPORT int my___isoc99_vsscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my_vsscanf"))); EXPORT int my___isoc99_vfscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my_vfscanf"))); -EXPORT int my___isoc99_fscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my_vfscanf"))); #endif +EXPORT int my___isoc99_fscanf(x64emu_t* emu, void* stream, void* fmt, uint64_t* b) +{ + myStackAlignScanf(emu, (const char*)fmt, b, emu->scratch, 2); + PREPARE_VALIST; + + return vfscanf(stream, fmt, VARARGS); +} + EXPORT int my___isoc99_sscanf(x64emu_t* emu, void* stream, void* fmt, uint64_t* b) { myStackAlignScanf(emu, (const char*)fmt, b, emu->scratch, 2); diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index fc1273be..4e2666d7 100755 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -243,6 +243,7 @@ GOW(duplocale, pFp) //GO(endusershell, //GOW(endutent, //GO(endutxent, +DATA(environ, sizeof(void*)) DATAB(__environ, sizeof(void*)) //GO(envz_add, //GO(envz_entry, @@ -680,6 +681,8 @@ GO(iconv_open, LFpp) //GOW(if_nametoindex, //GOW(imaxabs, //GOW(imaxdiv, +DATA(in6addr_any, 16) // type V +DATA(in6addr_loopback, 16) //type V //GOI(index, //GO(inet6_opt_append, //GO(inet6_opt_find, @@ -903,10 +906,10 @@ GO(__isnanf, iFf) GOW(isnanf, iFf) //GO(__isnanl, //GOW(isnanl, -//GO(__isoc99_fscanf, +GOM(__isoc99_fscanf, iFEppV) //GO(__isoc99_fwscanf, //GO(__isoc99_scanf, -GOM(__isoc99_sscanf, iFppV) +GOM(__isoc99_sscanf, iFEppV) //GO(__isoc99_swscanf, //GO(__isoc99_vfscanf, //GO(__isoc99_vfwscanf, @@ -1357,8 +1360,8 @@ GOM(__printf_chk, iFEipV) //GO(process_vm_writev, //GOW(profil, //GO(__profile_frequency, -//DATA(__progname, -//DATA(__progname_full, +DATA(__progname, sizeof(void*)) +DATA(__progname_full, sizeof(void)) //GOW(pselect, //GO(psiginfo, //GO(psignal, @@ -1961,6 +1964,7 @@ GO(timerfd_settime, iFiipp) //GOW(times, //GO(timespec_get, DATAB(__timezone, sizeof(void*)) +DATAV(timezone, sizeof(void*)) //type V GO(tmpfile, pFv) GOW(tmpfile64, pFv) GO(tmpnam, pFp) @@ -1996,7 +2000,8 @@ GOW(truncate64, iFpI) //GO(ttyslot, //GO(__twalk, //GOW(twalk, -DATA(__tzname, 8) +DATA(__tzname, sizeof(void*)) +DATA(tzname, sizeof(void*)) //type V GOW(tzset, vFv) //GO(ualarm, //GO(__uflow, |