about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-05-16 10:55:51 +0200
committerptitSeb <sebastien.chev@gmail.com>2021-05-16 10:55:51 +0200
commitc56c991bf7541d4a3a151ee1859f32406a4f43c0 (patch)
tree26ba42745e73130aeb2cfe756e05cf628e400192
parent5ea4b796a5fac103f9b5c88ea8e543e65600ab23 (diff)
downloadbox64-c56c991bf7541d4a3a151ee1859f32406a4f43c0.tar.gz
box64-c56c991bf7541d4a3a151ee1859f32406a4f43c0.zip
Added wrapped libexpat (for torchlight2)
-rwxr-xr-xCMakeLists.txt1
-rwxr-xr-xsrc/library_list.h1
-rw-r--r--src/wrapped/generated/wrappedexpattypes.h21
-rwxr-xr-xsrc/wrapped/wrappedexpat.c145
-rwxr-xr-xsrc/wrapped/wrappedexpat_private.h71
5 files changed, 239 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45402436..bdb4d234 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -191,6 +191,7 @@ set(WRAPPEDS
     "${BOX64_ROOT}/src/wrapped/wrappedcrypto.c"
     "${BOX64_ROOT}/src/wrapped/wrappedcurl.c"
     "${BOX64_ROOT}/src/wrapped/wrappeddbus.c"
+    "${BOX64_ROOT}/src/wrapped/wrappedexpat.c"
     "${BOX64_ROOT}/src/wrapped/wrappedflac.c"
     "${BOX64_ROOT}/src/wrapped/wrappedfontconfig.c"
     "${BOX64_ROOT}/src/wrapped/wrappedfreetype.c"
diff --git a/src/library_list.h b/src/library_list.h
index 4492a2ee..0ee58037 100755
--- a/src/library_list.h
+++ b/src/library_list.h
@@ -83,6 +83,7 @@ GO("libudev.so.1", udev1)
 GO("libdbus-1.so.3", dbus)
 //GO("libiconv.so.2", iconv)
 //GO("libdrm.so.2", libdrm)
+GO("libexpat.so.1", expat)
 GO("libcrypto.so.1", crypto)
 GO("libssl.so.1", libssl)
 GO("libcrypt.so.1", libcrypt)
diff --git a/src/wrapped/generated/wrappedexpattypes.h b/src/wrapped/generated/wrappedexpattypes.h
new file mode 100644
index 00000000..c168a1ca
--- /dev/null
+++ b/src/wrapped/generated/wrappedexpattypes.h
@@ -0,0 +1,21 @@
+/*******************************************************************
+ * File automatically generated by rebuild_wrappers.py (v1.3.0.11) *
+ *******************************************************************/
+#ifndef __wrappedexpatTYPES_H_
+#define __wrappedexpatTYPES_H_
+
+#ifndef LIBNAME
+#error You should only #include this file inside a wrapped*.c file
+#endif
+#ifndef ADDED_FUNCTIONS
+#define ADDED_FUNCTIONS() 
+#endif
+
+typedef void (*vFpp_t)(void*, void*);
+typedef void (*vFppp_t)(void*, void*, void*);
+
+#define SUPER() ADDED_FUNCTIONS() \
+	GO(XML_SetCharacterDataHandler, vFpp_t) \
+	GO(XML_SetElementHandler, vFppp_t)
+
+#endif // __wrappedexpatTYPES_H_
diff --git a/src/wrapped/wrappedexpat.c b/src/wrapped/wrappedexpat.c
new file mode 100755
index 00000000..713482e9
--- /dev/null
+++ b/src/wrapped/wrappedexpat.c
@@ -0,0 +1,145 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#define _GNU_SOURCE         /* See feature_test_macros(7) */
+#include <dlfcn.h>
+
+#include "wrappedlibs.h"
+
+#include "debug.h"
+#include "wrapper.h"
+#include "bridge.h"
+#include "librarian/library_private.h"
+#include "x64emu.h"
+#include "emu/x64emu_private.h"
+#include "callback.h"
+#include "librarian.h"
+#include "box64context.h"
+#include "emu/x64emu_private.h"
+#include "myalign.h"
+
+const char* expatName = "libexpat.so.1";
+#define LIBNAME expat
+static library_t* my_lib = NULL;
+
+#include "generated/wrappedexpattypes.h"
+
+typedef struct expat_my_s {
+    // functions
+    #define GO(A, B)    B   A;
+    SUPER()
+    #undef GO
+} expat_my_t;
+
+void* getExpatMy(library_t* lib)
+{
+    expat_my_t* my = (expat_my_t*)calloc(1, sizeof(expat_my_t));
+    #define GO(A, W) my->A = (W)dlsym(lib->priv.w.lib, #A);
+    SUPER()
+    #undef GO
+    return my;
+}
+#undef SUPER
+
+void freeExpatMy(void* lib)
+{
+    //expat_my_t *my = (expat_my_t *)lib;
+}
+
+#define SUPER() \
+GO(0)   \
+GO(1)   \
+GO(2)   \
+GO(3)   \
+GO(4)
+
+// Start ...
+#define GO(A)   \
+static uintptr_t my_Start_fct_##A = 0;                                              \
+static void* my_Start_##A(void* data, void* name, void* attr)                       \
+{                                                                                   \
+    return (void*)RunFunction(my_context, my_Start_fct_##A, 3, data, name, attr);   \
+}
+SUPER()
+#undef GO
+static void* find_Start_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_Start_fct_##A == (uintptr_t)fct) return my_Start_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_Start_fct_##A == 0) {my_Start_fct_##A = (uintptr_t)fct; return my_Start_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for expat Start callback\n");
+    return NULL;
+}
+// End ...
+#define GO(A)   \
+static uintptr_t my_End_fct_##A = 0;                       \
+static void my_End_##A(void* data, void* name)             \
+{                                                          \
+    RunFunction(my_context, my_End_fct_##A, 2, data, name);\
+}
+SUPER()
+#undef GO
+static void* find_End_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_End_fct_##A == (uintptr_t)fct) return my_End_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_End_fct_##A == 0) {my_End_fct_##A = (uintptr_t)fct; return my_End_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for expat End callback\n");
+    return NULL;
+}
+// CharData ...
+#define GO(A)   \
+static uintptr_t my_CharData_fct_##A = 0;                       \
+static void my_CharData_##A(void* data, void* s, int l)         \
+{                                                               \
+    RunFunction(my_context, my_CharData_fct_##A, 3, data, s, l);\
+}
+SUPER()
+#undef GO
+static void* find_CharData_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_CharData_fct_##A == (uintptr_t)fct) return my_CharData_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_CharData_fct_##A == 0) {my_CharData_fct_##A = (uintptr_t)fct; return my_CharData_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for expat CharData callback\n");
+    return NULL;
+}
+#undef SUPER
+
+EXPORT void my_XML_SetElementHandler(x64emu_t* emu, void* p, void* start, void* end)
+{
+    expat_my_t *my = (expat_my_t*)my_lib->priv.w.p2;
+    my->XML_SetElementHandler(p, find_Start_Fct(start), find_End_Fct(end));
+}
+
+EXPORT void my_XML_SetCharacterDataHandler(x64emu_t* emu, void* p, void* h)
+{
+    expat_my_t *my = (expat_my_t*)my_lib->priv.w.p2;
+    my->XML_SetCharacterDataHandler(p, find_CharData_Fct(h));
+}
+
+#define CUSTOM_INIT \
+    lib->priv.w.p2 = getExpatMy(lib); \
+    my_lib = lib;
+
+#define CUSTOM_FINI \
+    freeExpatMy(lib->priv.w.p2);  \
+    free(lib->priv.w.p2);       \
+    my_lib = NULL;
+
+#include "wrappedlib_init.h"
diff --git a/src/wrapped/wrappedexpat_private.h b/src/wrapped/wrappedexpat_private.h
new file mode 100755
index 00000000..0fe1ba80
--- /dev/null
+++ b/src/wrapped/wrappedexpat_private.h
@@ -0,0 +1,71 @@
+#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA))
+#error meh!
+#endif
+
+//GO(_INTERNAL_trim_to_complete_utf8_characters, 
+//GO(XML_DefaultCurrent, 
+GO(XML_ErrorString, pFi)
+//GO(XML_ExpatVersion, 
+//GO(XML_ExpatVersionInfo, 
+//GO(XML_ExternalEntityParserCreate, 
+//GO(XML_FreeContentModel, 
+//GO(XML_GetBase, 
+//GO(XML_GetBuffer, 
+//GO(XML_GetCurrentByteCount, 
+//GO(XML_GetCurrentByteIndex, 
+//GO(XML_GetCurrentColumnNumber, 
+GO(XML_GetCurrentLineNumber, iFp)
+GO(XML_GetErrorCode, iFp)
+//GO(XML_GetFeatureList, 
+//GO(XML_GetIdAttributeIndex, 
+//GO(XML_GetInputContext, 
+//GO(XML_GetParsingStatus, 
+//GO(XML_GetSpecifiedAttributeCount, 
+//GO(XML_MemFree, 
+//GO(XML_MemMalloc, 
+//GO(XML_MemRealloc, 
+GO(XML_Parse, iFppii)
+//GO(XML_ParseBuffer, 
+GO(XML_ParserCreate, pFp)
+//GO(XML_ParserCreate_MM, 
+//GO(XML_ParserCreateNS, 
+GO(XML_ParserFree, vFp)
+//GO(XML_ParserReset, 
+//GO(XML_ResumeParser, 
+//GO(XML_SetAttlistDeclHandler, 
+//GO(XML_SetBase, 
+//GO(XML_SetCdataSectionHandler, 
+GOM(XML_SetCharacterDataHandler, vFEpp)
+//GO(XML_SetCommentHandler, 
+//GO(XML_SetDefaultHandler, 
+//GO(XML_SetDefaultHandlerExpand, 
+//GO(XML_SetDoctypeDeclHandler, 
+//GO(XML_SetElementDeclHandler, 
+GOM(XML_SetElementHandler, vFEppp)
+//GO(XML_SetEncoding, 
+//GO(XML_SetEndCdataSectionHandler, 
+//GO(XML_SetEndDoctypeDeclHandler, 
+//GO(XML_SetEndElementHandler, 
+//GO(XML_SetEndNamespaceDeclHandler, 
+//GO(XML_SetEntityDeclHandler, 
+//GO(XML_SetExternalEntityRefHandler, 
+//GO(XML_SetExternalEntityRefHandlerArg, 
+//GO(XML_SetHashSalt, 
+//GO(XML_SetNamespaceDeclHandler, 
+//GO(XML_SetNotationDeclHandler, 
+//GO(XML_SetNotStandaloneHandler, 
+//GO(XML_SetParamEntityParsing, 
+//GO(XML_SetProcessingInstructionHandler, 
+//GO(XML_SetReturnNSTriplet, 
+//GO(XML_SetSkippedEntityHandler, 
+//GO(XML_SetStartCdataSectionHandler, 
+//GO(XML_SetStartDoctypeDeclHandler, 
+//GO(XML_SetStartElementHandler, 
+//GO(XML_SetStartNamespaceDeclHandler, 
+//GO(XML_SetUnknownEncodingHandler, 
+//GO(XML_SetUnparsedEntityDeclHandler, 
+GO(XML_SetUserData, vFpp)
+//GO(XML_SetXmlDeclHandler, 
+//GO(XML_StopParser, 
+//GO(XML_UseForeignDTD, 
+//GO(XML_UseParserAsHandlerArg,