frida框架hook常用字符串模板總結
ArrayBuffer轉String: 解決中文亂碼(模板)
function ab2str(buf) {
return new Uint16Array(buf)
// encodedString = String.fromCodePoint.apply(null, new Uint16Array(buf));
// // decodedString = encodeURI(encodedString);//沒有這一步中文會亂碼
// // console.log(decodedString);
// return encodedString
}
string轉ArrayBuffer(模板)
function str2ab(str) {
var buf = new ArrayBuffer(str.length * 2); // 每個字符占用2個字節
var bufView = new Uint16Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
字符串轉Uint8Array(模板)
function stringToUint8Array(str){
var arr = [];
for (var i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i));
}
var tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array
}
Uint8Array轉字符串(模板)
function Uint8ArrayToString(fileData){
console.log(fileData)
var dataString = "";
for (var i = 0; i < fileData.length; i++) {
dataString += String.fromCharCode(fileData[i]);
}
return dataString
}