123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import {NativeStruct} from "../../struct/NativeStruct";
- import {il2cppApi} from "../../il2cppApi";
- export class Il2cppString extends NativeStruct {
- static parser(systemString){
- if (systemString.isNull()){
- return"指针空";
- }
- let length = il2cppApi.il2cpp_string_length(systemString);
- let il2cppStringChars = il2cppApi.il2cpp_string_chars(systemString);
- let content="";
- for (let i = 0; i < length; i++) {
- let offset = i * 2;
- let s = il2cppStringChars.add(offset).readU16().toString(16);
- if (s.toString().length === 2) {
- let s2 = il2cppStringChars.add(offset).readCString();
- content = content + s2;
- } else {
- //转换unicode
- let unicode = "\\u" + s.toString();
- let decodeUnicode1 = this.decodeUnicode(unicode);
- content = content + decodeUnicode1;
- }
- }
- return content;
- }
- getCString() {
- if (this.isNull()){
- return "指针空";
- }
- let length = this.getLength();
- //长度4字节本身偏移16 从20位开始
- let il2cppStringChars = il2cppApi.il2cpp_string_chars(this);
- let content="";
- for (let i = 0; i < length; i++) {
- let offset = i * 2;
- let s = il2cppStringChars.add(offset).readU16().toString(16);
- // console.log("il2cppStringChars:" + s);
- //转unicode
- if (s.toString().length === 2) {
- let s2 = il2cppStringChars.add(offset).readCString();
- // log("s2:"+s2);
- content = content + s2;
- } else {
- //转换unicode
- let unicode = "\\u" + s.toString();
- // log("unicode:" + unicode);
- let decodeUnicode1 = this.decodeUnicode(unicode);
- content = content + decodeUnicode1;
- // log("s2:"+this.decodeUnicode(unicode));
- }
- // let s1 = String.fromCharCode(unicode);
- }
- if (content === undefined) {
- return "";
- }
- return content;
- }
- getLength() {
- return il2cppApi.il2cpp_string_length(this);
- }
- static decodeUnicode(str) {
- let replace = str.replace(/\\/g, "%");
- return unescape(replace);
- }
- }
|