Js-ctypes char readString() makes Mozilla crash
-
25-06-2021 - |
Question
I am using js-sctypes to connect to a shared library in Linux from Firefox. I am declaring a function from the library as follows:
var read_memory = libc.declare("read_memory", ctypes.default_abi, ctypes.int,
ctypes.uint32_t, ctypes.char.ptr, ctypes.int, ctypes.int);
In C++ library this function is declared as follows:
read_memory(unsigned int address, char *buf, int unit_size, int unit_count)
I am calling the read_memory
function in the following way:
var my = new ctypes.char().address();
read_memory(0, my, 4, 1);
st = st + my.readString();
And it works fine, but when I am calling the function with greater unit_size
and unit_count
, for example read_memory(0, my, 4, 10)
, the Firefox crashes.
Is it because ctypes.char
is limited in size, or there is another reason for this fault?
Any help on this matter would be appreciated.
Thank you.
Solution
I had the same problem and the problem is because of character encoding. In my problem I need to convert them from windows-1250 to utf-8.
I used code below:
result = myFunctionToInvoke();
var util = priv.Load("LibToConvert.dll");
var wi12502utf8 = util.declare("win12502utf8", ctypes.default_abi, ctypes.char.ptr, ctypes.char.ptr);
var val = wi12502utf8(result);
result = val.readString();
In this code I created my own lib (LibToConvert.dll) in C++ to convert characters.