I wrote a small C library and compiled it into js. I am trying to interface the compiled code with node.js.
this is the header of the lib.
int myfunc (unsigned char *hexstring, const unsigned char *target, uint32_t seed, unsigned long *counter);
hexstring and counter will be passed by reference, the function should be able to read and modify them and return values when the function call is completed.
this is the binding that i try to write... however i have little idea with the api to deal with pointers.
myfunc = Module.cwrap('myfunc', 'number', ['string', 'string', 'number', 'number']);
exports.myfunc = function(hexstring, target, seed, callback){
var result;
var counter_ptr = Pointer_make([0], null, ALLOC_STACK);;
var hexstring_ptr = allocate(intArrayFromString(hexstring), 'i8', ALLOC_NORMAL);
var target_ptr = allocate(intArrayFromString(target), 'i8', ALLOC_NORMAL);
result = myfunc(hexstring_ptr, target_ptr, maxNonce, counter_ptr);
/* read the modified values and pass it back to JS interface */
/* but.. how do i access hexstring_ptr contents? and convert it back to ordinary js string? */
callback(data, target, maxNonce, counter, result);
Module._free(data_ptr);
Module._free(target_ptr);
}
the input should be something like this,
myfunc("ff03fecd1234", "1234", 99, function(...){});
Thanks!