-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (24 loc) · 681 Bytes
/
index.js
File metadata and controls
28 lines (24 loc) · 681 Bytes
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
const native = require("node-gyp-build")(__dirname);
/**
* @param {string} sig - The signature to convert to buffers. e.g. "C6 43 ?? ??"
* @returns {{ bytes: Buffer, mask: Buffer }} - An object containing the byte buffer and mask buffer.
*/
function sigToBufs(sig) {
const parts = sig.trim().split(/\s+/);
const bytes = Buffer.alloc(parts.length);
const mask = Buffer.alloc(parts.length);
parts.forEach((part, i) => {
if (part === "??" || part === "?") {
bytes[i] = 0x00;
mask[i] = 0;
} else {
bytes[i] = parseInt(part, 16);
mask[i] = 1;
}
});
return { bytes, mask };
}
module.exports = {
patch: native.patch,
sigToBufs
}