| 1265 | const NativeStruct_1 = require("../../struct/NativeStruct"); |
| 1266 | const il2cppApi_1 = require("../../il2cppApi"); |
| 1267 | class Il2cppString extends NativeStruct_1.NativeStruct { |
| 1268 | static parserString(str) { |
| 1269 | // 获取MonoString的长度 |
| 1270 | if (str.isNull()) { |
| 1271 | return "空"; |
| 1272 | } |
| 1273 | // logHHex(str) |
| 1274 | let il2CppBase = Process.pointerSize * 2; |
| 1275 | var length = Memory.readU32(str.add(il2CppBase)); |
| 1276 | // 获取MonoString的字符数据的指针(UTF-16编码) |
| 1277 | var charsPtr = str.add(il2CppBase + 0x4); |
| 1278 | // 从UTF-16编码的字符数据创建JavaScript字符串 |
| 1279 | return Memory.readUtf16String(charsPtr, length); |
| 1280 | } |
| 1281 | static parser(systemString) { |
| 1282 | if (systemString.isNull()) { |
| 1283 | return "指针空"; |
| 1284 | } |
| 1285 | let length = il2cppApi_1.il2cppApi.il2cpp_string_length(systemString); |
| 1286 | let il2cppStringChars = il2cppApi_1.il2cppApi.il2cpp_string_chars(systemString); |
| 1287 | let content = ""; |
| 1288 | for (let i = 0; i < length; i++) { |
| 1289 | let offset = i * 2; |
| 1290 | let s = il2cppStringChars.add(offset).readU16().toString(16); |
| 1291 | if (s.toString().length === 2) { |
| 1292 | let s2 = il2cppStringChars.add(offset).readCString(); |
| 1293 | content = content + s2; |
| 1294 | } |
| 1295 | else { |
| 1296 | //转换unicode |
| 1297 | let unicode = "\\u" + s.toString(); |
| 1298 | let decodeUnicode1 = this.decodeUnicode(unicode); |
| 1299 | content = content + decodeUnicode1; |
| 1300 | } |
| 1301 | } |
| 1302 | return content; |
| 1303 | } |
| 1304 | getCString() { |
| 1305 | if (this.isNull()) { |
| 1306 | return "指针空"; |
| 1307 | } |
| 1308 | let length = this.getLength(); |
| 1309 | //长度4字节本身偏移16 从20位开始 |
| 1310 | let il2cppStringChars = il2cppApi_1.il2cppApi.il2cpp_string_chars(this); |
| 1311 | let content = ""; |
| 1312 | for (let i = 0; i < length; i++) { |
| 1313 | let offset = i * 2; |
| 1314 | let s = il2cppStringChars.add(offset).readU16().toString(16); |
| 1315 | // console.log("il2cppStringChars:" + s); |
| 1316 | //转unicode |
| 1317 | if (s.toString().length === 2) { |
| 1318 | let s2 = il2cppStringChars.add(offset).readCString(); |
| 1319 | // log("s2:"+s2); |
| 1320 | content = content + s2; |
| 1321 | } |
| 1322 | else { |
| 1323 | //转换unicode |
| 1324 | let unicode = "\\u" + s.toString(); |
nothing calls this directly
no outgoing calls
no test coverage detected