msgpackr-extract 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/download-prebuilds.js +2 -0
- package/package.json +7 -7
- package/src/extract.cpp +33 -32
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msgpackr-extract",
|
|
3
3
|
"author": "Kris Zyp",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"description": "Node addon for string extraction for msgpackr",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"download-msgpackr-prebuilds": "./bin/download-prebuilds.js"
|
|
35
35
|
},
|
|
36
36
|
"optionalDependencies": {
|
|
37
|
-
"@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.
|
|
38
|
-
"@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.
|
|
39
|
-
"@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.
|
|
40
|
-
"@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.
|
|
41
|
-
"@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.
|
|
42
|
-
"@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.
|
|
37
|
+
"@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.1",
|
|
38
|
+
"@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.1",
|
|
39
|
+
"@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.1",
|
|
40
|
+
"@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.1",
|
|
41
|
+
"@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.1",
|
|
42
|
+
"@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"prebuildify-platform-packages": "5.0.2",
|
package/src/extract.cpp
CHANGED
|
@@ -23,7 +23,8 @@ find the string tokens and determine their position and length. All strings are
|
|
|
23
23
|
#endif
|
|
24
24
|
|
|
25
25
|
const int MAX_TARGET_SIZE = 255;
|
|
26
|
-
|
|
26
|
+
const uint UNEXPECTED_END = 0xffffffff;
|
|
27
|
+
typedef uint32_t (*token_handler)(uint8_t* source, uint32_t position, uint32_t size);
|
|
27
28
|
token_handler tokenTable[256] = {};
|
|
28
29
|
napi_value unexpectedEnd(napi_env env) {
|
|
29
30
|
napi_value returnValue;
|
|
@@ -37,14 +38,14 @@ public:
|
|
|
37
38
|
// napi_ref targetArray; // could consider reenabling this optimization for napi
|
|
38
39
|
bool hasTargetArray = false;
|
|
39
40
|
uint8_t* source;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
uint32_t position = 0;
|
|
42
|
+
uint32_t writePosition = 0;
|
|
43
|
+
uint32_t stringStart = 0;
|
|
44
|
+
uint32_t lastStringEnd = 0;
|
|
44
45
|
|
|
45
|
-
void readString(napi_env env,
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
void readString(napi_env env, uint32_t length, bool allowStringBlocks, napi_value* target) {
|
|
47
|
+
uint32_t start = position;
|
|
48
|
+
uint32_t end = position + length;
|
|
48
49
|
if (allowStringBlocks) { // for larger strings, we don't bother to check every character for being latin, and just go right to creating a new string
|
|
49
50
|
while(position < end) {
|
|
50
51
|
if (source[position] < 0x80) // ensure we character is latin and can be decoded as one byte
|
|
@@ -83,7 +84,7 @@ public:
|
|
|
83
84
|
lastStringEnd = end;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
napi_value extractStrings(napi_env env,
|
|
87
|
+
napi_value extractStrings(napi_env env, uint32_t startingPosition, uint32_t size, uint8_t* inputSource) {
|
|
87
88
|
napi_value target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
|
|
88
89
|
writePosition = 0;
|
|
89
90
|
lastStringEnd = 0;
|
|
@@ -107,7 +108,7 @@ public:
|
|
|
107
108
|
if (position >= size) {
|
|
108
109
|
return unexpectedEnd(env);
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
+
uint32_t length = source[position++];
|
|
111
112
|
if (length + position > size) {
|
|
112
113
|
return unexpectedEnd(env);
|
|
113
114
|
}
|
|
@@ -116,7 +117,7 @@ public:
|
|
|
116
117
|
if (2 + position > size) {
|
|
117
118
|
return unexpectedEnd(env);
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
+
uint32_t length = source[position++] << 8;
|
|
120
121
|
length += source[position++];
|
|
121
122
|
if (length + position > size) {
|
|
122
123
|
return unexpectedEnd(env);
|
|
@@ -126,7 +127,7 @@ public:
|
|
|
126
127
|
if (4 + position > size) {
|
|
127
128
|
return unexpectedEnd(env);
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
+
uint32_t length = source[position++] << 24;
|
|
130
131
|
length += source[position++] << 16;
|
|
131
132
|
length += source[position++] << 8;
|
|
132
133
|
length += source[position++];
|
|
@@ -143,7 +144,7 @@ public:
|
|
|
143
144
|
position += (size_t ) handle;
|
|
144
145
|
} else {
|
|
145
146
|
position = tokenTable[token](source, position, size);
|
|
146
|
-
if (position
|
|
147
|
+
if (position == UNEXPECTED_END) {
|
|
147
148
|
return unexpectedEnd(env);
|
|
148
149
|
}
|
|
149
150
|
}
|
|
@@ -166,7 +167,7 @@ public:
|
|
|
166
167
|
memcpy(&array, &v8Array, sizeof(array));
|
|
167
168
|
#else
|
|
168
169
|
napi_create_array_with_length(env, writePosition, &array);
|
|
169
|
-
for (
|
|
170
|
+
for (uint32_t i = 0; i < writePosition; i++) {
|
|
170
171
|
napi_set_element(env, array, i, target[i]);
|
|
171
172
|
}
|
|
172
173
|
#endif
|
|
@@ -195,54 +196,54 @@ void setupTokenTable() {
|
|
|
195
196
|
// fixext 16
|
|
196
197
|
tokenTable[0xd8] = (token_handler) 17;
|
|
197
198
|
// bin 8
|
|
198
|
-
tokenTable[0xc4] = ([](uint8_t* source,
|
|
199
|
+
tokenTable[0xc4] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
|
|
199
200
|
if (position >= size) {
|
|
200
|
-
return
|
|
201
|
+
return UNEXPECTED_END;
|
|
201
202
|
}
|
|
202
|
-
|
|
203
|
+
uint32_t length = source[position++];
|
|
203
204
|
return position + length;
|
|
204
205
|
});
|
|
205
206
|
// bin 16
|
|
206
|
-
tokenTable[0xc5] = ([](uint8_t* source,
|
|
207
|
+
tokenTable[0xc5] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
|
|
207
208
|
if (position + 2 > size) {
|
|
208
|
-
return
|
|
209
|
+
return UNEXPECTED_END;
|
|
209
210
|
}
|
|
210
|
-
|
|
211
|
+
uint32_t length = source[position++] << 8;
|
|
211
212
|
length += source[position++];
|
|
212
213
|
return position + length;
|
|
213
214
|
});
|
|
214
215
|
// bin 32
|
|
215
|
-
tokenTable[0xc6] = ([](uint8_t* source,
|
|
216
|
+
tokenTable[0xc6] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
|
|
216
217
|
if (position + 4 > size)
|
|
217
|
-
return
|
|
218
|
-
|
|
218
|
+
return UNEXPECTED_END;
|
|
219
|
+
uint32_t length = source[position++] << 24;
|
|
219
220
|
length += source[position++] << 16;
|
|
220
221
|
length += source[position++] << 8;
|
|
221
222
|
length += source[position++];
|
|
222
223
|
return position + length;
|
|
223
224
|
});
|
|
224
225
|
// ext 8
|
|
225
|
-
tokenTable[0xc7] = ([](uint8_t* source,
|
|
226
|
+
tokenTable[0xc7] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
|
|
226
227
|
if (position >= size)
|
|
227
|
-
return
|
|
228
|
-
|
|
228
|
+
return UNEXPECTED_END;
|
|
229
|
+
uint32_t length = source[position++];
|
|
229
230
|
position++;
|
|
230
231
|
return position + length;
|
|
231
232
|
});
|
|
232
233
|
// ext 16
|
|
233
|
-
tokenTable[0xc8] = ([](uint8_t* source,
|
|
234
|
+
tokenTable[0xc8] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
|
|
234
235
|
if (position + 2 > size)
|
|
235
|
-
return
|
|
236
|
-
|
|
236
|
+
return UNEXPECTED_END;
|
|
237
|
+
uint32_t length = source[position++] << 8;
|
|
237
238
|
length += source[position++];
|
|
238
239
|
position++;
|
|
239
240
|
return position + length;
|
|
240
241
|
});
|
|
241
242
|
// ext 32
|
|
242
|
-
tokenTable[0xc9] = ([](uint8_t* source,
|
|
243
|
+
tokenTable[0xc9] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
|
|
243
244
|
if (position + 4 > size)
|
|
244
|
-
return
|
|
245
|
-
|
|
245
|
+
return UNEXPECTED_END;
|
|
246
|
+
uint32_t length = source[position++] << 24;
|
|
246
247
|
length += source[position++] << 16;
|
|
247
248
|
length += source[position++] << 8;
|
|
248
249
|
length += source[position++];
|