-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathns_tagged_pointer_string.cc
More file actions
132 lines (113 loc) · 3.71 KB
/
ns_tagged_pointer_string.cc
File metadata and controls
132 lines (113 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <sstream>
#include <cstdint>
#include <cstring>
using namespace std;
// macos
static string decode_macos_tagged_pointer_string_0_7(uint64_t a) {
int length = (a >> 4) & 15;
string result;
for (int i = 0; i < length; ++i) {
result += (char)((a >> (8 + i * 8)) & 255);
}
return result;
}
static string decode_macos_tagged_pointer_string_8_9(uint64_t a) {
int length = (a >> 4) & 15;
string result;
for (int i = 0; i < length; ++i) {
result += "eilotrm.apdnsIc ufkMShjTRxgC4013bDNvwyUL2O856P-B79AFKEWV_zGJ/HYX"[(a >> (8 + (length - i - 1) * 6)) & 63];
}
return result;
}
static string decode_macos_tagged_pointer_string_10_11(uint64_t a) {
int length = (a >> 4) & 15;
string result;
for (int i = 0; i < length; ++i) {
result += "eilotrm.apdnsIc ufkMShjTRxgC4013"[(a >> (8 + (length - i - 1) * 5)) & 31];
}
return result;
}
static string decode_macos_tagged_pointer_string(uint64_t a) {
if ((a & 15) != 5) {
return "";
}
int length = (a >> 4) & 15;
switch (length) {
case 1: case 2: case 3: case 4:
case 5: case 6: case 7:
return decode_macos_tagged_pointer_string_0_7(a);
case 8: case 9:
return decode_macos_tagged_pointer_string_8_9(a);
case 10: case 11:
return decode_macos_tagged_pointer_string_10_11(a);
}
return "";
}
// ios
static string decode_ios_tagged_pointer_string_0_7(uint64_t a) {
int length = a & 15;
string result;
for (int i = 0; i < length; ++i) {
result += (char)((a >> (4 + i * 8)) & 255);
}
return result;
}
static string decode_ios_tagged_pointer_string_8_9(uint64_t a) {
int length = a & 15;
string result;
for (int i = 0; i < length; ++i) {
result += "eilotrm.apdnsIc ufkMShjTRxgC4013bDNvwyUL2O856P-B79AFKEWV_zGJ/HYX"[(a >> (4 + (length - i - 1) * 6)) & 63];
}
return result;
}
static string decode_ios_tagged_pointer_string_10_11(uint64_t a) {
int length = a & 15;
string result;
for (int i = 0; i < length; ++i) {
result += "eilotrm.apdnsIc ufkMShjTRxgC4013"[(a >> (4 + (length - i - 1) * 5)) & 31];
}
return result;
}
static string decode_ios_tagged_pointer_string(uint64_t a) {
if ((a & 0xa000000000000000) != 0xa000000000000000) {
return "";
}
int length = a & 15;
switch (length) {
case 1: case 2: case 3: case 4:
case 5: case 6: case 7:
return decode_ios_tagged_pointer_string_0_7(a);
case 8: case 9:
return decode_ios_tagged_pointer_string_8_9(a);
case 10: case 11:
return decode_ios_tagged_pointer_string_10_11(a);
}
return "";
}
// test
static bool test_decode_macos_tagged_pointer_string(uint64_t a, const string &s) {
string result = decode_macos_tagged_pointer_string(a);
printf("0x%016llx -> %s\n", a, result.c_str());
return s == result;
}
static bool test_decode_ios_tagged_pointer_string(uint64_t a, const string &s) {
string result = decode_ios_tagged_pointer_string(a);
printf("0x%016llx -> %s\n", a, result.c_str());
return s == result;
}
int main(int argc, char *argv[], char *envp[]) {
test_decode_macos_tagged_pointer_string(0x0000000000006115, "a");
test_decode_macos_tagged_pointer_string(0x0000000063626135, "abc");
test_decode_macos_tagged_pointer_string(0x6766656463626175, "abcdefg");
test_decode_macos_tagged_pointer_string(0x0022038a01169585, "abcdefgh");
test_decode_macos_tagged_pointer_string(0x0880e28045a54195, "abcdefghi");
test_decode_macos_tagged_pointer_string(0x39408eaa1b4846b5, "cdefghijklm");
test_decode_ios_tagged_pointer_string(0xa000000000000611, "a");
test_decode_ios_tagged_pointer_string(0xa0022038a0116958, "abcdefgh");
test_decode_ios_tagged_pointer_string(0xa0880e28045a5419, "abcdefghi");
test_decode_ios_tagged_pointer_string(0xa02a01087500843a, "hellohello");
//s NSTaggedPointerString * @"abcdefghi" 0xc94c01116118ff83
// p [(NSObject *)[@"abcdefgh" mutableCopy] copy]
return 0;
}