Skip to content

Commit

Permalink
Added many wrapped symbols to libgmp (for Steam beta client)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Aug 15, 2023
1 parent cef87f7 commit 771ff1b
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 49 deletions.
6 changes: 6 additions & 0 deletions src/wrapped/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,11 @@
#() LFpLpp
#() LFppii
#() LFppip
#() LFppLu
#() LFppLL
#() LFppLp
#() LFpppi
#() LFpppL
#() LFpppp
#() pFEipi
#() pFEipp
Expand Down Expand Up @@ -1336,6 +1339,7 @@
#() lFppiip
#() LFEpppp
#() LFuiCiu
#() LFLpppL
#() LFLpppp
#() LFpuipp
#() LFpuppi
Expand Down Expand Up @@ -2775,6 +2779,8 @@ wrappedglib2:
- g_spawn_async_with_pipes
wrappedgmodule2:
wrappedgmp:
- vFppp:
- __gmp_get_memory_functions
wrappedgnutls:
- vFp:
- gnutls_global_set_log_function
Expand Down
4 changes: 3 additions & 1 deletion src/wrapped/generated/wrappedgmptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#define ADDED_FUNCTIONS()
#endif

typedef void (*vFppp_t)(void*, void*, void*);

#define SUPER() ADDED_FUNCTIONS()
#define SUPER() ADDED_FUNCTIONS() \
GO(__gmp_get_memory_functions, vFppp_t)

#endif // __wrappedgmpTYPES_H_
8 changes: 8 additions & 0 deletions src/wrapped/generated/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,11 @@ typedef uintptr_t (*LFpLpL_t)(void*, uintptr_t, void*, uintptr_t);
typedef uintptr_t (*LFpLpp_t)(void*, uintptr_t, void*, void*);
typedef uintptr_t (*LFppii_t)(void*, void*, int32_t, int32_t);
typedef uintptr_t (*LFppip_t)(void*, void*, int32_t, void*);
typedef uintptr_t (*LFppLu_t)(void*, void*, uintptr_t, uint32_t);
typedef uintptr_t (*LFppLL_t)(void*, void*, uintptr_t, uintptr_t);
typedef uintptr_t (*LFppLp_t)(void*, void*, uintptr_t, void*);
typedef uintptr_t (*LFpppi_t)(void*, void*, void*, int32_t);
typedef uintptr_t (*LFpppL_t)(void*, void*, void*, uintptr_t);
typedef uintptr_t (*LFpppp_t)(void*, void*, void*, void*);
typedef void* (*pFEipi_t)(x86emu_t*, int32_t, void*, int32_t);
typedef void* (*pFEipp_t)(x86emu_t*, int32_t, void*, void*);
Expand Down Expand Up @@ -1408,6 +1411,7 @@ typedef intptr_t (*lFpuipC_t)(void*, uint32_t, int32_t, void*, uint8_t);
typedef intptr_t (*lFppiip_t)(void*, void*, int32_t, int32_t, void*);
typedef uintptr_t (*LFEpppp_t)(x86emu_t*, void*, void*, void*, void*);
typedef uintptr_t (*LFuiCiu_t)(uint32_t, int32_t, uint8_t, int32_t, uint32_t);
typedef uintptr_t (*LFLpppL_t)(uintptr_t, void*, void*, void*, uintptr_t);
typedef uintptr_t (*LFLpppp_t)(uintptr_t, void*, void*, void*, void*);
typedef uintptr_t (*LFpuipp_t)(void*, uint32_t, int32_t, void*, void*);
typedef uintptr_t (*LFpuppi_t)(void*, uint32_t, void*, void*, int32_t);
Expand Down Expand Up @@ -3424,8 +3428,11 @@ void LFpLpL(x86emu_t *emu, uintptr_t fcn) { LFpLpL_t fn = (LFpLpL_t)fcn; R_EAX=(
void LFpLpp(x86emu_t *emu, uintptr_t fcn) { LFpLpp_t fn = (LFpLpp_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(uintptr_t*)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16)); }
void LFppii(x86emu_t *emu, uintptr_t fcn) { LFppii_t fn = (LFppii_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(int32_t*)(R_ESP + 12), *(int32_t*)(R_ESP + 16)); }
void LFppip(x86emu_t *emu, uintptr_t fcn) { LFppip_t fn = (LFppip_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(int32_t*)(R_ESP + 12), *(void**)(R_ESP + 16)); }
void LFppLu(x86emu_t *emu, uintptr_t fcn) { LFppLu_t fn = (LFppLu_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uintptr_t*)(R_ESP + 12), *(uint32_t*)(R_ESP + 16)); }
void LFppLL(x86emu_t *emu, uintptr_t fcn) { LFppLL_t fn = (LFppLL_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uintptr_t*)(R_ESP + 12), *(uintptr_t*)(R_ESP + 16)); }
void LFppLp(x86emu_t *emu, uintptr_t fcn) { LFppLp_t fn = (LFppLp_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(uintptr_t*)(R_ESP + 12), *(void**)(R_ESP + 16)); }
void LFpppi(x86emu_t *emu, uintptr_t fcn) { LFpppi_t fn = (LFpppi_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(int32_t*)(R_ESP + 16)); }
void LFpppL(x86emu_t *emu, uintptr_t fcn) { LFpppL_t fn = (LFpppL_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(uintptr_t*)(R_ESP + 16)); }
void LFpppp(x86emu_t *emu, uintptr_t fcn) { LFpppp_t fn = (LFpppp_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16)); }
void pFEipi(x86emu_t *emu, uintptr_t fcn) { pFEipi_t fn = (pFEipi_t)fcn; R_EAX=(uintptr_t)fn(emu, *(int32_t*)(R_ESP + 4), *(void**)(R_ESP + 8), *(int32_t*)(R_ESP + 12)); }
void pFEipp(x86emu_t *emu, uintptr_t fcn) { pFEipp_t fn = (pFEipp_t)fcn; R_EAX=(uintptr_t)fn(emu, *(int32_t*)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12)); }
Expand Down Expand Up @@ -3799,6 +3806,7 @@ void lFpuipC(x86emu_t *emu, uintptr_t fcn) { lFpuipC_t fn = (lFpuipC_t)fcn; R_EA
void lFppiip(x86emu_t *emu, uintptr_t fcn) { lFppiip_t fn = (lFppiip_t)fcn; R_EAX=(intptr_t)fn(*(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(int32_t*)(R_ESP + 12), *(int32_t*)(R_ESP + 16), *(void**)(R_ESP + 20)); }
void LFEpppp(x86emu_t *emu, uintptr_t fcn) { LFEpppp_t fn = (LFEpppp_t)fcn; R_EAX=(uintptr_t)fn(emu, *(void**)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16)); }
void LFuiCiu(x86emu_t *emu, uintptr_t fcn) { LFuiCiu_t fn = (LFuiCiu_t)fcn; R_EAX=(uintptr_t)fn(*(uint32_t*)(R_ESP + 4), *(int32_t*)(R_ESP + 8), *(uint8_t*)(R_ESP + 12), *(int32_t*)(R_ESP + 16), *(uint32_t*)(R_ESP + 20)); }
void LFLpppL(x86emu_t *emu, uintptr_t fcn) { LFLpppL_t fn = (LFLpppL_t)fcn; R_EAX=(uintptr_t)fn(*(uintptr_t*)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16), *(uintptr_t*)(R_ESP + 20)); }
void LFLpppp(x86emu_t *emu, uintptr_t fcn) { LFLpppp_t fn = (LFLpppp_t)fcn; R_EAX=(uintptr_t)fn(*(uintptr_t*)(R_ESP + 4), *(void**)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16), *(void**)(R_ESP + 20)); }
void LFpuipp(x86emu_t *emu, uintptr_t fcn) { LFpuipp_t fn = (LFpuipp_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(uint32_t*)(R_ESP + 8), *(int32_t*)(R_ESP + 12), *(void**)(R_ESP + 16), *(void**)(R_ESP + 20)); }
void LFpuppi(x86emu_t *emu, uintptr_t fcn) { LFpuppi_t fn = (LFpuppi_t)fcn; R_EAX=(uintptr_t)fn(*(void**)(R_ESP + 4), *(uint32_t*)(R_ESP + 8), *(void**)(R_ESP + 12), *(void**)(R_ESP + 16), *(int32_t*)(R_ESP + 20)); }
Expand Down
4 changes: 4 additions & 0 deletions src/wrapped/generated/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,11 @@ void LFpLpL(x86emu_t *emu, uintptr_t fnc);
void LFpLpp(x86emu_t *emu, uintptr_t fnc);
void LFppii(x86emu_t *emu, uintptr_t fnc);
void LFppip(x86emu_t *emu, uintptr_t fnc);
void LFppLu(x86emu_t *emu, uintptr_t fnc);
void LFppLL(x86emu_t *emu, uintptr_t fnc);
void LFppLp(x86emu_t *emu, uintptr_t fnc);
void LFpppi(x86emu_t *emu, uintptr_t fnc);
void LFpppL(x86emu_t *emu, uintptr_t fnc);
void LFpppp(x86emu_t *emu, uintptr_t fnc);
void pFEipi(x86emu_t *emu, uintptr_t fnc);
void pFEipp(x86emu_t *emu, uintptr_t fnc);
Expand Down Expand Up @@ -1368,6 +1371,7 @@ void lFpuipC(x86emu_t *emu, uintptr_t fnc);
void lFppiip(x86emu_t *emu, uintptr_t fnc);
void LFEpppp(x86emu_t *emu, uintptr_t fnc);
void LFuiCiu(x86emu_t *emu, uintptr_t fnc);
void LFLpppL(x86emu_t *emu, uintptr_t fnc);
void LFLpppp(x86emu_t *emu, uintptr_t fnc);
void LFpuipp(x86emu_t *emu, uintptr_t fnc);
void LFpuppi(x86emu_t *emu, uintptr_t fnc);
Expand Down
101 changes: 101 additions & 0 deletions src/wrapped/wrappedgmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,109 @@
#include "bridge.h"
#include "librarian/library_private.h"
#include "x86emu.h"
#include "emu/x86emu_private.h"
#include "callback.h"
#include "librarian.h"
#include "box86context.h"
#include "emu/x86emu_private.h"
#include "callback.h"

const char* gmpName = "libgmp.so.10";
#define LIBNAME gmp

#include "generated/wrappedgmptypes.h"

#include "wrappercallback.h"

// utility functions
#define SUPER() \
GO(0) \
GO(1) \
GO(2) \
GO(3) \
GO(4)

// alloc_func
#define GO(A) \
static uintptr_t my_alloc_func_fct_##A = 0; \
static void* my_alloc_func_##A(size_t a) \
{ \
return (void*)RunFunctionFmt(my_alloc_func_fct_##A, "L", a); \
}
SUPER()
#undef GO
static void* find_alloc_func_Fct(void* fct)
{
if(!fct) return NULL;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
#define GO(A) if(my_alloc_func_fct_##A == (uintptr_t)fct) return my_alloc_func_##A;
SUPER()
#undef GO
#define GO(A) if(my_alloc_func_fct_##A == 0) {my_alloc_func_fct_##A = (uintptr_t)fct; return my_alloc_func_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libgmp.so.10 alloc_func callback\n");
return NULL;
}
// realloc_func
#define GO(A) \
static uintptr_t my_realloc_func_fct_##A = 0; \
static void* my_realloc_func_##A(void* a, size_t b) \
{ \
return (void*)RunFunctionFmt(my_realloc_func_fct_##A, "pL", a, b); \
}
SUPER()
#undef GO
static void* find_realloc_func_Fct(void* fct)
{
if(!fct) return NULL;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
#define GO(A) if(my_realloc_func_fct_##A == (uintptr_t)fct) return my_realloc_func_##A;
SUPER()
#undef GO
#define GO(A) if(my_realloc_func_fct_##A == 0) {my_realloc_func_fct_##A = (uintptr_t)fct; return my_realloc_func_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libgmp.so.10 realloc_func callback\n");
return NULL;
}
// free_func
#define GO(A) \
static uintptr_t my_free_func_fct_##A = 0; \
static void my_free_func_##A(void* a) \
{ \
RunFunctionFmt(my_free_func_fct_##A, "p", a); \
}
SUPER()
#undef GO
static void* find_free_func_Fct(void* fct)
{
if(!fct) return NULL;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
#define GO(A) if(my_free_func_fct_##A == (uintptr_t)fct) return my_free_func_##A;
SUPER()
#undef GO
#define GO(A) if(my_free_func_fct_##A == 0) {my_free_func_fct_##A = (uintptr_t)fct; return my_free_func_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for libgmp.so.10 free_func callback\n");
return NULL;
}

#undef SUPER

EXPORT void my___gmp_get_memory_functions(x86emu_t* emu, void* f_alloc, void* f_realloc, void* f_free)
{
my->__gmp_get_memory_functions(find_alloc_func_Fct(f_alloc), find_realloc_func_Fct(f_realloc), find_free_func_Fct(f_free));
}

#define CUSTOM_INIT \
getMy(lib);

#define CUSTOM_FINI \
freeMy();

#include "wrappedlib_init.h"
Loading

0 comments on commit 771ff1b

Please sign in to comment.