Il2cppString.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {NativeStruct} from "../../struct/NativeStruct";
  2. import {il2cppApi} from "../../il2cppApi";
  3. export class Il2cppString extends NativeStruct {
  4. static parser(systemString){
  5. if (systemString.isNull()){
  6. return"指针空";
  7. }
  8. let length = il2cppApi.il2cpp_string_length(systemString);
  9. let il2cppStringChars = il2cppApi.il2cpp_string_chars(systemString);
  10. let content="";
  11. for (let i = 0; i < length; i++) {
  12. let offset = i * 2;
  13. let s = il2cppStringChars.add(offset).readU16().toString(16);
  14. if (s.toString().length === 2) {
  15. let s2 = il2cppStringChars.add(offset).readCString();
  16. content = content + s2;
  17. } else {
  18. //转换unicode
  19. let unicode = "\\u" + s.toString();
  20. let decodeUnicode1 = this.decodeUnicode(unicode);
  21. content = content + decodeUnicode1;
  22. }
  23. }
  24. return content;
  25. }
  26. getCString() {
  27. if (this.isNull()){
  28. return "指针空";
  29. }
  30. let length = this.getLength();
  31. //长度4字节本身偏移16 从20位开始
  32. let il2cppStringChars = il2cppApi.il2cpp_string_chars(this);
  33. let content="";
  34. for (let i = 0; i < length; i++) {
  35. let offset = i * 2;
  36. let s = il2cppStringChars.add(offset).readU16().toString(16);
  37. // console.log("il2cppStringChars:" + s);
  38. //转unicode
  39. if (s.toString().length === 2) {
  40. let s2 = il2cppStringChars.add(offset).readCString();
  41. // log("s2:"+s2);
  42. content = content + s2;
  43. } else {
  44. //转换unicode
  45. let unicode = "\\u" + s.toString();
  46. // log("unicode:" + unicode);
  47. let decodeUnicode1 = this.decodeUnicode(unicode);
  48. content = content + decodeUnicode1;
  49. // log("s2:"+this.decodeUnicode(unicode));
  50. }
  51. // let s1 = String.fromCharCode(unicode);
  52. }
  53. if (content === undefined) {
  54. return "";
  55. }
  56. return content;
  57. }
  58. getLength() {
  59. return il2cppApi.il2cpp_string_length(this);
  60. }
  61. static decodeUnicode(str) {
  62. let replace = str.replace(/\\/g, "%");
  63. return unescape(replace);
  64. }
  65. }