Skip to content

Instantly share code, notes, and snippets.


dpnishant/sqlite3.js Secret

Last active Dec 2, 2020
What would you like to do?
'use strict';
var func_sqlite3_prepare_v2 = Module.findExportByName('libsqlite3.dylib', 'sqlite3_prepare_v2');
var func_sqlite3_sql = Module.findExportByName('libsqlite3.dylib', 'sqlite3_sql');
var sqlite3_sql = new NativeFunction(func_sqlite3_sql, 'char', ['pointer']);
Interceptor.attach(func_sqlite3_prepare_v2, {
onEnter: function(args) {
var sqlite3_stmt = args[3];
var output = sqlite3_sql(sqlite3_stmt);
console.log('SQL: ' + output);
onLeave: function (retval) {
//console.log('Return Value: ' + Memory.readUtf8String(retval));

This comment has been minimized.

Copy link
Owner Author

@dpnishant dpnishant commented Mar 18, 2016

Signature of sqlite3_prepare_v2() // Doc:

  int sqlite3_prepare_v2(
    sqlite3 *db,            // Database handle 
    const char *zSql,       // SQL statement, UTF-8 encoded 
    int nByte,              // Maximum length of zSql in bytes.
    sqlite3_stmt **ppStmt,  // OUT: Statement handle
    const char **pzTail     // OUT: Pointer to unused portion of zSql

Signature of sqlite3_sql() // Doc:
const char *sqlite3_sql(sqlite3_stmt *pStmt);

Question: I want to call the sqlite3_sql() method, from the loaded libsqlite3.dylib, by passing the 4th argument of sqlite3_prepare_v2().
But I'm getting the following error:

TypeError: NativeFunction: bad argument count
    at TypeError (native)
    at [object Object].Interceptor.attach.onEnter (repl1.js:10:18)


This comment has been minimized.

Copy link

@riverar riverar commented Mar 19, 2016

Line 9 should be:
new NativeFunction(func_sqlite3_sql, 'char', ['pointer'])


This comment has been minimized.

Copy link
Owner Author

@dpnishant dpnishant commented Mar 21, 2016

Revised the script. Now works as expected. Thanks @riverar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment