Skip to content

Instantly share code, notes, and snippets.

@dpnishant dpnishant/sqlite3.js Secret

Last active Oct 30, 2018
Embed
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));
}
});
@dpnishant

This comment has been minimized.

Copy link
Owner Author

dpnishant commented Mar 18, 2016

Signature of sqlite3_prepare_v2() // Doc: https://www.sqlite.org/c3ref/prepare.html

  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: http://www.sqlite.org/c3ref/sql.html
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)

@riverar

This comment has been minimized.

Copy link

riverar commented Mar 19, 2016

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

@dpnishant

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.