Refined ptrace hacks around POKEUSER/PEEKUSER (should help Wine Unity3D games)

This commit is contained in:
ptitSeb 2023-11-07 15:33:37 +01:00
parent 72e917bb06
commit 236de084ea

View File

@ -3179,12 +3179,30 @@ EXPORT int my_semctl(x86emu_t* emu, int semid, int semnum, int cmd, union semun
return ((iFiiiV_t)f)(semid, semnum, cmd, b);
}
EXPORT int my_ptrace(x86emu_t* emu, int request, pid_t pid, void* addr, void* data)
EXPORT uint32_t userdata_sign = 0x12345987;
EXPORT uint32_t userdata[1024];
EXPORT long my_ptrace(x86emu_t* emu, int request, pid_t pid, void* addr, uint32_t* data)
{
if(request == PTRACE_POKEUSER) {
if(ptrace(PTRACE_PEEKDATA, pid, &userdata_sign, NULL)==userdata_sign && (uintptr_t)addr < sizeof(userdata)) {
ptrace(PTRACE_POKEDATA, pid, addr+(uintptr_t)userdata, data);
return 0;
}
// fallback to a generic local faking
if((uintptr_t)addr < sizeof(userdata))
*(uintptr_t*)(addr+(uintptr_t)userdata) = (uintptr_t)data;
// lets just ignore this for now!
return 0;
}
if(request == PTRACE_PEEKUSER) {
if(ptrace(PTRACE_PEEKDATA, pid, &userdata_sign, NULL)==userdata_sign && (uintptr_t)addr < sizeof(userdata)) {
return ptrace(PTRACE_PEEKDATA, pid, addr+(uintptr_t)userdata, data);
}
// fallback to a generic local faking
if((uintptr_t)addr < sizeof(userdata))
return *(uintptr_t*)(addr+(uintptr_t)userdata);
}
return ptrace(request, pid, addr, data);
}