about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-10-30 11:23:30 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-10-30 11:23:30 +0100
commit74acad36288d9433d3d0d24bf0eb74c5a239bb1f (patch)
tree1acc3812417309d9a28572d941188a2afefdbdda /src
parent541adff4d40db9d32076c222c8e1289c5fceb84c (diff)
downloadbox64-74acad36288d9433d3d0d24bf0eb74c5a239bb1f.tar.gz
box64-74acad36288d9433d3d0d24bf0eb74c5a239bb1f.zip
[WRAPPER] Wrapped remaining 2 function to libbrotidec (for #1860)
Diffstat (limited to 'src')
-rw-r--r--src/wrapped/generated/functions_list.txt4
-rw-r--r--src/wrapped/generated/wrappedbrotlidectypes.h6
-rw-r--r--src/wrapped/wrappedbrotlidec.c102
-rw-r--r--src/wrapped/wrappedbrotlidec_private.h4
4 files changed, 111 insertions, 5 deletions
diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt
index 250b8f67..adba69c9 100644
--- a/src/wrapped/generated/functions_list.txt
+++ b/src/wrapped/generated/functions_list.txt
@@ -3319,6 +3319,10 @@ wrappedatspi:
   - atspi_event_listener_new
 wrappedayatanaappindicator3:
 wrappedbrotlidec:
+- pFppp:
+  - BrotliDecoderCreateInstance
+- vFpppp:
+  - BrotliDecoderSetMetadataCallbacks
 wrappedbz2:
 - iFp:
   - BZ2_bzCompressEnd
diff --git a/src/wrapped/generated/wrappedbrotlidectypes.h b/src/wrapped/generated/wrappedbrotlidectypes.h
index 9d7f3b4d..eb0d1560 100644
--- a/src/wrapped/generated/wrappedbrotlidectypes.h
+++ b/src/wrapped/generated/wrappedbrotlidectypes.h
@@ -11,7 +11,11 @@
 #define ADDED_FUNCTIONS() 
 #endif
 
+typedef void* (*pFppp_t)(void*, void*, void*);
+typedef void (*vFpppp_t)(void*, void*, void*, void*);
 
-#define SUPER() ADDED_FUNCTIONS()
+#define SUPER() ADDED_FUNCTIONS() \
+	GO(BrotliDecoderCreateInstance, pFppp_t) \
+	GO(BrotliDecoderSetMetadataCallbacks, vFpppp_t)
 
 #endif // __wrappedbrotlidecTYPES_H_
diff --git a/src/wrapped/wrappedbrotlidec.c b/src/wrapped/wrappedbrotlidec.c
index 02868917..2e95d1fd 100644
--- a/src/wrapped/wrappedbrotlidec.c
+++ b/src/wrapped/wrappedbrotlidec.c
@@ -21,9 +21,9 @@ const char* brotlidecName = "libbrotlidec.so.1";
 
 #define ADDED_FUNCTIONS()           \
 
-//#include "generated/wrappedbrotlidectypes.h"
+#include "generated/wrappedbrotlidectypes.h"
 
-//#include "wrappercallback.h"
+#include "wrappercallback.h"
 
 #define SUPER() \
 GO(0)   \
@@ -32,6 +32,104 @@ GO(2)   \
 GO(3)   \
 GO(4)
 
+// brotli_alloc_func ...
+#define GO(A)   \
+static uintptr_t my_brotli_alloc_func_fct_##A = 0;                          \
+static void* my_brotli_alloc_func_##A(void* a, size_t b)                    \
+{                                                                           \
+    return (void*)RunFunctionFmt(my_brotli_alloc_func_fct_##A, "pL", a, b); \
+}
+SUPER()
+#undef GO
+static void* find_brotli_alloc_func_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_brotli_alloc_func_fct_##A == (uintptr_t)fct) return my_brotli_alloc_func_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_brotli_alloc_func_fct_##A == 0) {my_brotli_alloc_func_fct_##A = (uintptr_t)fct; return my_brotli_alloc_func_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for brotidec brotli_alloc_func callback\n");
+    return NULL;
+}
+// brotli_free_func ...
+#define GO(A)   \
+static uintptr_t my_brotli_free_func_fct_##A = 0;               \
+static void my_brotli_free_func_##A(void* a, void* b)           \
+{                                                               \
+    RunFunctionFmt(my_brotli_free_func_fct_##A, "pp", a, b);    \
+}
+SUPER()
+#undef GO
+static void* find_brotli_free_func_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_brotli_free_func_fct_##A == (uintptr_t)fct) return my_brotli_free_func_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_brotli_free_func_fct_##A == 0) {my_brotli_free_func_fct_##A = (uintptr_t)fct; return my_brotli_free_func_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for brotidec brotli_free_func callback\n");
+    return NULL;
+}
+// brotli_decoder_metadata_start_func ...
+#define GO(A)   \
+static uintptr_t my_brotli_decoder_metadata_start_func_fct_##A = 0;             \
+static void my_brotli_decoder_metadata_start_func_##A(void* a, size_t b)        \
+{                                                                               \
+    RunFunctionFmt(my_brotli_decoder_metadata_start_func_fct_##A, "pL", a, b);  \
+}
+SUPER()
+#undef GO
+static void* find_brotli_decoder_metadata_start_func_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_brotli_decoder_metadata_start_func_fct_##A == (uintptr_t)fct) return my_brotli_decoder_metadata_start_func_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_brotli_decoder_metadata_start_func_fct_##A == 0) {my_brotli_decoder_metadata_start_func_fct_##A = (uintptr_t)fct; return my_brotli_decoder_metadata_start_func_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for brotidec brotli_decoder_metadata_start_func callback\n");
+    return NULL;
+}
+// brotli_decoder_metadata_chunk_func ...
+#define GO(A)   \
+static uintptr_t my_brotli_decoder_metadata_chunk_func_fct_##A = 0;                 \
+static void my_brotli_decoder_metadata_chunk_func_##A(void* a, void* b, size_t c)   \
+{                                                                                   \
+    RunFunctionFmt(my_brotli_decoder_metadata_chunk_func_fct_##A, "ppL", a, b, c);  \
+}
+SUPER()
+#undef GO
+static void* find_brotli_decoder_metadata_chunk_func_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_brotli_decoder_metadata_chunk_func_fct_##A == (uintptr_t)fct) return my_brotli_decoder_metadata_chunk_func_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_brotli_decoder_metadata_chunk_func_fct_##A == 0) {my_brotli_decoder_metadata_chunk_func_fct_##A = (uintptr_t)fct; return my_brotli_decoder_metadata_chunk_func_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for brotidec brotli_decoder_metadata_chunk_func callback\n");
+    return NULL;
+}
 #undef SUPER
 
+EXPORT void* my_BrotliDecoderCreateInstance(x64emu_t, void* m, void* f, void* d)
+{
+    return my->BrotliDecoderCreateInstance(find_brotli_alloc_func_Fct(m), find_brotli_free_func_Fct(f), d);
+}
+
+EXPORT void my_BrotliDecoderSetMetadataCallbacks(x64emu_t* emu, void* state, void* start, void* chunk, void* d)
+{
+    my->BrotliDecoderSetMetadataCallbacks(state, find_brotli_decoder_metadata_start_func_Fct(start), find_brotli_decoder_metadata_chunk_func_Fct(chunk), d);
+}
+
 #include "wrappedlib_init.h"
diff --git a/src/wrapped/wrappedbrotlidec_private.h b/src/wrapped/wrappedbrotlidec_private.h
index b63c3b01..952985d4 100644
--- a/src/wrapped/wrappedbrotlidec_private.h
+++ b/src/wrapped/wrappedbrotlidec_private.h
@@ -3,7 +3,7 @@
 #endif
 
 GO(BrotliDecoderAttachDictionary, iFpuLp)
-//GOM(BrotliDecoderCreateInstance, pFEppp)
+GOM(BrotliDecoderCreateInstance, pFEppp)
 GO(BrotliDecoderDecompress, uFLppp)
 GO(BrotliDecoderDecompressStream, uFpppppp)
 GO(BrotliDecoderDestroyInstance, vFp)
@@ -12,7 +12,7 @@ GO(BrotliDecoderGetErrorCode, iFp)
 GO(BrotliDecoderHasMoreOutput, iFp)
 GO(BrotliDecoderIsFinished, iFp)
 GO(BrotliDecoderIsUsed, iFp)
-//GOM(BrotliDecoderSetMetadataCallbacks, vFEpppp)
+GOM(BrotliDecoderSetMetadataCallbacks, vFEpppp)
 GO(BrotliDecoderSetParameter, iFpuu)
 GO(BrotliDecoderTakeOutput, pFpp)
 GO(BrotliDecoderVersion, uFv)