Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap sqlite3_exec for libsqlite3 #1674

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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