Skip to content

Commit

Permalink
[BOX32] Added some posix_file_action wrapped function, and fixed posi…
Browse files Browse the repository at this point in the history
…x_spawn/exec function argument handling
  • Loading branch information
ptitSeb committed Oct 13, 2024
1 parent 9139ec3 commit 103ec5d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/wrapped32/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@
#() iFEiiN -> iFEiiN
#() iFEipp -> iFEipp
#() iFEipV -> iFEipV
#() iFEpii -> iFEpii
#() iFEpip -> iFEpip
#() iFEpui -> iFEpui
#() iFEpuu -> iFEpuu
Expand Down Expand Up @@ -1146,6 +1147,7 @@
#() iFEuppLp -> iFEuppLp
#() iFEpiuuu -> iFEpiuuu
#() iFEpiLpp -> iFEpiLpp
#() iFEpipOi -> iFEpipOi
#() iFEpuuup -> iFEpuuup
#() iFEplluu -> iFEplluu
#() iFEpLlpp -> iFEpLlpp
Expand Down Expand Up @@ -1595,6 +1597,8 @@ wrappedlibc:
- __close_nocancel
- iFL:
- iFp:
- posix_spawn_file_actions_destroy
- posix_spawn_file_actions_init
- sysinfo
- iFO:
- uFp:
Expand Down Expand Up @@ -1644,6 +1648,7 @@ wrappedlibc:
- setrlimit
- iFpi:
- backtrace
- posix_spawn_file_actions_addclose
- iFpL:
- iFpp:
- alphasort64
Expand Down Expand Up @@ -1677,6 +1682,8 @@ wrappedlibc:
- iFiip:
- iFiiN:
- iFipp:
- iFpii:
- posix_spawn_file_actions_adddup2
- iFpLi:
- iFppp:
- vswscanf
Expand Down Expand Up @@ -1728,6 +1735,8 @@ wrappedlibc:
- getpwuid_r
- iFpvvpV:
- iFpiLpp:
- iFpipOi:
- posix_spawn_file_actions_addopen
- iFpppLp:
- getgrnam_r
- getpwnam_r
Expand Down
7 changes: 7 additions & 0 deletions src/wrapped32/generated/wrappedlibctypes32.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef int32_t (*iFvpV_t)(void, void*, ...);
typedef int32_t (*iFiip_t)(int32_t, int32_t, void*);
typedef int32_t (*iFiiN_t)(int32_t, int32_t, ...);
typedef int32_t (*iFipp_t)(int32_t, void*, void*);
typedef int32_t (*iFpii_t)(void*, int32_t, int32_t);
typedef int32_t (*iFpLi_t)(void*, uintptr_t, int32_t);
typedef int32_t (*iFppp_t)(void*, void*, void*);
typedef int32_t (*iFppV_t)(void*, void*, ...);
Expand Down Expand Up @@ -93,6 +94,7 @@ typedef int32_t (*iFiippi_t)(int32_t, int32_t, void*, void*, int32_t);
typedef int32_t (*iFuppLp_t)(uint32_t, void*, void*, uintptr_t, void*);
typedef int32_t (*iFpvvpV_t)(void*, void, void, void*, ...);
typedef int32_t (*iFpiLpp_t)(void*, int32_t, uintptr_t, void*, void*);
typedef int32_t (*iFpipOi_t)(void*, int32_t, void*, int32_t, int32_t);
typedef int32_t (*iFpppLp_t)(void*, void*, void*, uintptr_t, void*);
typedef void* (*pFpLLiN_t)(void*, uintptr_t, uintptr_t, int32_t, ...);
typedef void* (*pFppLLp_t)(void*, void*, uintptr_t, uintptr_t, void*);
Expand All @@ -109,6 +111,8 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void
#define SUPER() ADDED_FUNCTIONS() \
GO(freeaddrinfo, vFp_t) \
GO(__close_nocancel, iFi_t) \
GO(posix_spawn_file_actions_destroy, iFp_t) \
GO(posix_spawn_file_actions_init, iFp_t) \
GO(sysinfo, iFp_t) \
GO(getwc, uFS_t) \
GO(__sysconf, lFi_t) \
Expand All @@ -135,6 +139,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void
GO(getrlimit, iFup_t) \
GO(setrlimit, iFup_t) \
GO(backtrace, iFpi_t) \
GO(posix_spawn_file_actions_addclose, iFpi_t) \
GO(alphasort64, iFpp_t) \
GO(execvp, iFpp_t) \
GO(statvfs, iFpp_t) \
Expand All @@ -149,6 +154,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void
GO(localtime_r, pFpp_t) \
GO(vsyslog, vFipp_t) \
GO(_ITM_addUserCommitAction, vFpup_t) \
GO(posix_spawn_file_actions_adddup2, iFpii_t) \
GO(vswscanf, iFppp_t) \
GO(swscanf, iFppV_t) \
GO(fscanf, iFSpV_t) \
Expand All @@ -166,6 +172,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void
GO(getaddrinfo, iFpppp_t) \
GO(getgrgid_r, iFuppLp_t) \
GO(getpwuid_r, iFuppLp_t) \
GO(posix_spawn_file_actions_addopen, iFpipOi_t) \
GO(getgrnam_r, iFpppLp_t) \
GO(getpwnam_r, iFpppLp_t) \
GO(gethostbyname_r, iFpppupp_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 @@ -795,6 +795,7 @@ typedef int32_t (*iFEiip_t)(x64emu_t*, int32_t, int32_t, void*);
typedef int32_t (*iFEiiN_t)(x64emu_t*, int32_t, int32_t, ...);
typedef int32_t (*iFEipp_t)(x64emu_t*, int32_t, void*, void*);
typedef int32_t (*iFEipV_t)(x64emu_t*, int32_t, void*, void*);
typedef int32_t (*iFEpii_t)(x64emu_t*, void*, int32_t, int32_t);
typedef int32_t (*iFEpip_t)(x64emu_t*, void*, int32_t, void*);
typedef int32_t (*iFEpui_t)(x64emu_t*, void*, uint32_t, int32_t);
typedef int32_t (*iFEpuu_t)(x64emu_t*, void*, uint32_t, uint32_t);
Expand Down Expand Up @@ -1236,6 +1237,7 @@ typedef int32_t (*iFEiippi_t)(x64emu_t*, int32_t, int32_t, void*, void*, int32_t
typedef int32_t (*iFEuppLp_t)(x64emu_t*, uint32_t, void*, void*, uintptr_t, void*);
typedef int32_t (*iFEpiuuu_t)(x64emu_t*, void*, int32_t, uint32_t, uint32_t, uint32_t);
typedef int32_t (*iFEpiLpp_t)(x64emu_t*, void*, int32_t, uintptr_t, void*, void*);
typedef int32_t (*iFEpipOi_t)(x64emu_t*, void*, int32_t, void*, int32_t, int32_t);
typedef int32_t (*iFEpuuup_t)(x64emu_t*, void*, uint32_t, uint32_t, uint32_t, void*);
typedef int32_t (*iFEplluu_t)(x64emu_t*, void*, intptr_t, intptr_t, uint32_t, uint32_t);
typedef int32_t (*iFEpLlpp_t)(x64emu_t*, void*, uintptr_t, intptr_t, void*, void*);
Expand Down Expand Up @@ -2293,6 +2295,7 @@ void iFEiip_32(x64emu_t *emu, uintptr_t fcn) { iFEiip_t fn = (iFEiip_t)fcn; R_EA
void iFEiiN_32(x64emu_t *emu, uintptr_t fcn) { iFEiiN_t fn = (iFEiiN_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); }
void iFEipp_32(x64emu_t *emu, uintptr_t fcn) { iFEipp_t fn = (iFEipp_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); }
void iFEipV_32(x64emu_t *emu, uintptr_t fcn) { iFEipV_t fn = (iFEipV_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptrv(R_ESP + 12)); }
void iFEpii_32(x64emu_t *emu, uintptr_t fcn) { iFEpii_t fn = (iFEpii_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); }
void iFEpip_32(x64emu_t *emu, uintptr_t fcn) { iFEpip_t fn = (iFEpip_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); }
void iFEpui_32(x64emu_t *emu, uintptr_t fcn) { iFEpui_t fn = (iFEpui_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); }
void iFEpuu_32(x64emu_t *emu, uintptr_t fcn) { iFEpuu_t fn = (iFEpuu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); }
Expand Down Expand Up @@ -2734,6 +2737,7 @@ void iFEiippi_32(x64emu_t *emu, uintptr_t fcn) { iFEiippi_t fn = (iFEiippi_t)fcn
void iFEuppLp_32(x64emu_t *emu, uintptr_t fcn) { iFEuppLp_t fn = (iFEuppLp_t)fcn; R_EAX = fn(emu, from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ptriv(R_ESP + 20)); }
void iFEpiuuu_32(x64emu_t *emu, uintptr_t fcn) { iFEpiuuu_t fn = (iFEpiuuu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); }
void iFEpiLpp_32(x64emu_t *emu, uintptr_t fcn) { iFEpiLpp_t fn = (iFEpiLpp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ulong(from_ptri(ulong_t, R_ESP + 12)), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); }
void iFEpipOi_32(x64emu_t *emu, uintptr_t fcn) { iFEpipOi_t fn = (iFEpipOi_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12), of_convert32(from_ptri(int32_t, R_ESP + 16)), from_ptri(int32_t, R_ESP + 20)); }
void iFEpuuup_32(x64emu_t *emu, uintptr_t fcn) { iFEpuuup_t fn = (iFEpuuup_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptriv(R_ESP + 20)); }
void iFEplluu_32(x64emu_t *emu, uintptr_t fcn) { iFEplluu_t fn = (iFEplluu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_long(from_ptri(long_t, R_ESP + 8)), from_long(from_ptri(long_t, R_ESP + 12)), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); }
void iFEpLlpp_32(x64emu_t *emu, uintptr_t fcn) { iFEpLlpp_t fn = (iFEpLlpp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_long(from_ptri(long_t, R_ESP + 12)), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); }
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 @@ -746,6 +746,7 @@ void iFEiip_32(x64emu_t *emu, uintptr_t fnc);
void iFEiiN_32(x64emu_t *emu, uintptr_t fnc);
void iFEipp_32(x64emu_t *emu, uintptr_t fnc);
void iFEipV_32(x64emu_t *emu, uintptr_t fnc);
void iFEpii_32(x64emu_t *emu, uintptr_t fnc);
void iFEpip_32(x64emu_t *emu, uintptr_t fnc);
void iFEpui_32(x64emu_t *emu, uintptr_t fnc);
void iFEpuu_32(x64emu_t *emu, uintptr_t fnc);
Expand Down Expand Up @@ -1187,6 +1188,7 @@ void iFEiippi_32(x64emu_t *emu, uintptr_t fnc);
void iFEuppLp_32(x64emu_t *emu, uintptr_t fnc);
void iFEpiuuu_32(x64emu_t *emu, uintptr_t fnc);
void iFEpiLpp_32(x64emu_t *emu, uintptr_t fnc);
void iFEpipOi_32(x64emu_t *emu, uintptr_t fnc);
void iFEpuuup_32(x64emu_t *emu, uintptr_t fnc);
void iFEplluu_32(x64emu_t *emu, uintptr_t fnc);
void iFEpLlpp_32(x64emu_t *emu, uintptr_t fnc);
Expand Down
82 changes: 69 additions & 13 deletions src/wrapped32/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ EXPORT int32_t my32_execv(x64emu_t* emu, const char* path, ptr_t argv[])
while(argv[n]) ++n;
char** newargv = (char**)calloc(n+1, sizeof(char*));
for(int i=0; i<=n; ++i)
newargv[i+1] = from_ptrv(argv[i]);
newargv[i] = from_ptrv(argv[i]);
return execv(path, (void*)newargv);
}

Expand Down Expand Up @@ -1692,7 +1692,7 @@ EXPORT int32_t my32_execve(x64emu_t* emu, const char* path, ptr_t argv[], ptr_t
while(argv[n]) ++n;
const char** newargv = (const char**)calloc(n+1, sizeof(char*));
for(int i=0; i<=n; ++i)
newargv[i+1] = from_ptrv(argv[i]);
newargv[i] = from_ptrv(argv[i]);

if(!strcmp(path + strlen(path) - strlen("/uname"), "/uname")
&& newargv[1] && (!strcmp(newargv[1], "-m") || !strcmp(newargv[1], "-p") || !strcmp(newargv[1], "-i"))
Expand Down Expand Up @@ -1738,7 +1738,7 @@ EXPORT int32_t my32_execvp(x64emu_t* emu, const char* path, ptr_t argv[])
while(argv[n]) ++n;
char** newargv = (char**)calloc(n+1, sizeof(char*));
for(int i=0; i<=n; ++i)
newargv[i+1] = from_ptrv(argv[i]);
newargv[i] = from_ptrv(argv[i]);
return execv(fullpath, (void*)newargv);
}
// execvp should use PATH to search for the program first
Expand All @@ -1750,16 +1750,74 @@ typedef struct
int __pad[16];
} posix_spawn_file_actions_32_t;

void convert_file_action_to_32(void* d, void* s)
{
posix_spawn_file_actions_32_t* dst = d;
posix_spawn_file_actions_t* src = s;
dst->__allocated = src->__allocated;
dst->__used = src->__used;
dst->__actions = to_ptrv(src->__actions);
}
void convert_file_action_to_64(void* d, void* s)
{
posix_spawn_file_actions_t* dst = d;
posix_spawn_file_actions_32_t* src = s;
dst->__actions = from_ptrv(src->__actions);
dst->__used = src->__used;
dst->__allocated = src->__allocated;
}

EXPORT int my32_posix_spawn_file_actions_init(x64emu_t* emu, posix_spawn_file_actions_32_t* action)
{
posix_spawn_file_actions_t action_l;
int ret = posix_spawn_file_actions_init(&action_l);
convert_file_action_to_32(action, &action_l);
return ret;
}
EXPORT int my32_posix_spawn_file_actions_addopen(x64emu_t* emu, posix_spawn_file_actions_32_t* action, int fides, const char* path, int oflag, int modes)
{
posix_spawn_file_actions_t action_l = {0};
convert_file_action_to_64(&action_l, action);
int ret = posix_spawn_file_actions_addopen(&action_l, fides, path, oflag, modes);
convert_file_action_to_32(action, &action_l);
return ret;
}

EXPORT int my32_posix_spawn_file_actions_addclose(x64emu_t* emu, posix_spawn_file_actions_32_t* action, int fides)
{
posix_spawn_file_actions_t action_l = {0};
convert_file_action_to_64(&action_l, action);
int ret = posix_spawn_file_actions_addclose(&action_l, fides);
convert_file_action_to_32(action, &action_l);
return ret;
}

EXPORT int my32_posix_spawn_file_actions_adddup2(x64emu_t* emu, posix_spawn_file_actions_32_t* action, int fides, int newfides)
{
posix_spawn_file_actions_t action_l = {0};
convert_file_action_to_64(&action_l, action);
int ret = posix_spawn_file_actions_adddup2(&action_l, fides, newfides);
convert_file_action_to_32(action, &action_l);
return ret;
}

EXPORT int my32_posix_spawn_file_actions_destroy(x64emu_t* emu, posix_spawn_file_actions_32_t* action)
{
posix_spawn_file_actions_t action_l;
convert_file_action_to_64(&action_l, action);
int ret = posix_spawn_file_actions_destroy(&action_l);
convert_file_action_to_32(action, &action_l); // just in case?
return ret;
}

EXPORT int32_t my32_posix_spawn(x64emu_t* emu, pid_t* pid, const char* fullpath,
const posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[])
posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[])
{
posix_spawn_file_actions_t actions_l = {0};
posix_spawn_file_actions_t *actions = NULL;
if(actions_s) {
actions = &actions_l;
actions->__allocated = actions_s->__allocated;
actions->__used = actions_s->__used;
actions->__actions = from_ptrv(actions_s->__actions);
convert_file_action_to_64(actions, actions_s);
}
// use fullpath...
int self = isProcSelf(fullpath, "exe");
Expand Down Expand Up @@ -1797,20 +1855,18 @@ EXPORT int32_t my32_posix_spawn(x64emu_t* emu, pid_t* pid, const char* fullpath,
while(argv[n]) ++n;
char** newargv = (char**)calloc(n+1, sizeof(char*));
for(int i=0; i<=n; ++i)
newargv[i+1] = from_ptrv(argv[i]);
newargv[i] = from_ptrv(argv[i]);
return posix_spawn(pid, fullpath, actions, attrp, newargv, newenvp);
}

EXPORT int32_t my32_posix_spawnp(x64emu_t* emu, pid_t* pid, const char* path,
const posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[])
posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[])
{
posix_spawn_file_actions_t actions_l = {0};
posix_spawn_file_actions_t *actions = NULL;
if(actions_s) {
actions = &actions_l;
actions->__allocated = actions_s->__allocated;
actions->__used = actions_s->__used;
actions->__actions = from_ptrv(actions_s->__actions);
convert_file_action_to_64(actions, actions_s);
}
// need to use BOX32_PATH / PATH here...
char* fullpath = ResolveFile(path, &my_context->box64_path);
Expand Down Expand Up @@ -1851,7 +1907,7 @@ EXPORT int32_t my32_posix_spawnp(x64emu_t* emu, pid_t* pid, const char* path,
while(argv[n]) ++n;
char** newargv = (char**)calloc(n+1, sizeof(char*));
for(int i=0; i<=n; ++i)
newargv[i+1] = from_ptrv(argv[i]);
newargv[i] = from_ptrv(argv[i]);
return posix_spawnp(pid, path, actions, attrp, newargv, newenvp);
}

Expand Down
10 changes: 5 additions & 5 deletions src/wrapped32/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1263,11 +1263,11 @@ GOM(posix_spawn, iFEpppppp)
// posix_spawnattr_setschedpolicy
// posix_spawnattr_setsigdefault
// posix_spawnattr_setsigmask
// posix_spawn_file_actions_addclose
//GO(posix_spawn_file_actions_adddup2, iFpii)
//GO(posix_spawn_file_actions_addopen, iFpipii)
//GO(posix_spawn_file_actions_destroy, iFp)
//GO(posix_spawn_file_actions_init, iFp)
GOM(posix_spawn_file_actions_addclose, iFEpi)
GOM(posix_spawn_file_actions_adddup2, iFEpii)
GOM(posix_spawn_file_actions_addopen, iFEpipOi)
GOM(posix_spawn_file_actions_destroy, iFEp)
GOM(posix_spawn_file_actions_init, iFEp)
GOM(posix_spawnp, iFEpppppp) //%%
GO(ppoll, iFpurLL_p)
GOW(prctl, iFiLLLL)
Expand Down

0 comments on commit 103ec5d

Please sign in to comment.