Skip to content

Commit

Permalink
Wrap sqlite3_exec for libsqlite3 (ptitSeb#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coekjan authored and Javier97sm committed Aug 16, 2024
1 parent 51b3aed commit 30f658f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/wrapped/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4760,6 +4760,8 @@ wrappedlibsndfile:
- pFpipp:
- sf_open_virtual
wrappedlibsqlite3:
- iFppppp:
- sqlite3_exec
wrappedlibssh2:
wrappedlibssl:
- pFp:
Expand Down
4 changes: 3 additions & 1 deletion src/wrapped/generated/wrappedlibsqlite3types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#define ADDED_FUNCTIONS()
#endif

typedef int32_t (*iFppppp_t)(void*, void*, void*, void*, void*);

#define SUPER() ADDED_FUNCTIONS()
#define SUPER() ADDED_FUNCTIONS() \
GO(sqlite3_exec, iFppppp_t)

#endif // __wrappedlibsqlite3TYPES_H_
36 changes: 34 additions & 2 deletions src/wrapped/wrappedlibsqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,40 @@ const char* libsqlite3Name = "libsqlite3.so.0";

#include "generated/wrappedlibsqlite3types.h"

//#include "wrappercallback.h"
#include "wrappercallback.h"

// Insert my_* functions here...
#define SUPER() \
GO(0) \
GO(1) \
GO(2) \
GO(3) \
GO(4)

// sqlite3_exec ...
#define GO(A) \
static uintptr_t my_sqlite3_exec_fct_##A = 0; \
static int my_sqlite3_exec_##A(void* a, int b, char** c, char** d) { \
return RunFunctionFmt(my_sqlite3_exec_fct_##A, "pipp", a, b, c, d); \
}
SUPER()
#undef GO
static void *find_sqlite3_exec_fct(void *fct) {
if (!fct) return fct;
if (GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if (my_sqlite3_exec_fct_##A == (uintptr_t)fct) return my_sqlite3_exec_##A;
SUPER()
#undef GO
#define GO(A) if (my_sqlite3_exec_fct_##A == 0) {my_sqlite3_exec_fct_##A = (uintptr_t)fct; return my_sqlite3_exec_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for sqlite3_exec callback\n");
return NULL;
}
#undef SUPER

EXPORT int my_sqlite3_exec(x64emu_t* emu, void *db, char *sql, void* callback, void* data, char **errmsg)
{
return my->sqlite3_exec(db, sql, find_sqlite3_exec_fct(callback), data, errmsg);
}

#include "wrappedlib_init.h"
2 changes: 1 addition & 1 deletion src/wrapped/wrappedlibsqlite3_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GO(sqlite3_errcode, iFp)
GO(sqlite3_errmsg, pFp)
GO(sqlite3_errmsg16, pFp)
GO(sqlite3_errstr, pFi)
// GO(sqlite3_exec,
GOM(sqlite3_exec, iFEppppp)
GO(sqlite3_expanded_sql, pFp)
GO(sqlite3_extended_errcode, iFp)
GO(sqlite3_extended_result_codes, iFpi)
Expand Down

0 comments on commit 30f658f

Please sign in to comment.