@validate-sdk/v2 1.22.21 → 1.22.23
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/README.md +5 -11
- package/dist/bin/linux/validate-sdk +0 -0
- package/dist/loader.cjs +39 -7
- package/dist/loader.mjs +39 -6
- package/package.json +2 -5
- package/scripts/README.md +0 -81
package/README.md
CHANGED
|
@@ -75,19 +75,13 @@ Verification uses `crypto.timingSafeEqual` to prevent timing attacks.
|
|
|
75
75
|
|
|
76
76
|
---
|
|
77
77
|
|
|
78
|
+
## Publishing for Windows and Linux
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
1. **On Windows:** run `npm run build:sea` → creates `dist/bin/win/validate-sdk.exe` and copies loaders to `dist/`.
|
|
81
|
+
2. **On Linux:** build there (or copy a pre-built `validate-sdk` binary) into `dist/bin/linux/validate-sdk`.
|
|
82
|
+
3. **Publish:** with both binaries under `dist/bin/`, run `npm publish`.
|
|
80
83
|
|
|
81
|
-
The
|
|
82
|
-
|
|
83
|
-
**Requirements:** [Rust](https://rustup.rs/), Node 16+.
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
npm install
|
|
87
|
-
npm run build:node
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Produces `dist/index.<platform>-<arch>.node` for the current OS. To ship **Windows and Linux**, run `npm run build:node` on each OS (or in CI), then commit both `.node` files to `dist/` and publish.
|
|
84
|
+
The package includes a **postinstall** script that runs `chmod +x` on the Linux binary when installed on Linux/macOS, so the binary is executable after `npm install`.
|
|
91
85
|
|
|
92
86
|
## License
|
|
93
87
|
|
|
Binary file
|
package/dist/loader.cjs
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { spawn } = require("child_process");
|
|
3
3
|
const path = require("path");
|
|
4
|
-
const
|
|
4
|
+
const fs = require("fs");
|
|
5
5
|
|
|
6
6
|
const isWin = process.platform === "win32";
|
|
7
7
|
const binDir = path.join(__dirname, "bin", isWin ? "win" : "linux");
|
|
8
8
|
const binName = isWin ? "validate-sdk.exe" : "validate-sdk";
|
|
9
9
|
const binPath = path.join(binDir, binName);
|
|
10
10
|
|
|
11
|
+
function checkBinary() {
|
|
12
|
+
if (!fs.existsSync(binPath)) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`@validate-sdk/v2: binary not found for ${process.platform} at ${binPath}. Reinstall the package.`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
if (!isWin) {
|
|
18
|
+
try {
|
|
19
|
+
fs.accessSync(binPath, fs.constants.X_OK);
|
|
20
|
+
} catch (_) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`@validate-sdk/v2: Linux binary is not executable (${binPath}). Run: chmod +x "${binPath}" or reinstall.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
11
28
|
let nextId = 0;
|
|
12
29
|
const pending = new Map();
|
|
13
30
|
let proc = null;
|
|
14
31
|
let inputBuf = "";
|
|
15
32
|
|
|
33
|
+
function clearProc(err) {
|
|
34
|
+
if (!proc) return;
|
|
35
|
+
proc = null;
|
|
36
|
+
const msg = err ? err.message || String(err) : "Subprocess closed";
|
|
37
|
+
for (const [, p] of pending) p.reject(new Error(msg));
|
|
38
|
+
pending.clear();
|
|
39
|
+
}
|
|
40
|
+
|
|
16
41
|
function getProc() {
|
|
17
42
|
if (proc) return proc;
|
|
43
|
+
checkBinary();
|
|
18
44
|
proc = spawn(binPath, [], { stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
19
45
|
proc.stdout.setEncoding("utf8");
|
|
20
46
|
proc.stdout.on("data", (chunk) => {
|
|
@@ -34,11 +60,8 @@ function getProc() {
|
|
|
34
60
|
} catch (_) {}
|
|
35
61
|
}
|
|
36
62
|
});
|
|
37
|
-
proc.on("
|
|
38
|
-
|
|
39
|
-
for (const [, p] of pending) p.reject(new Error("Process exited: " + code));
|
|
40
|
-
pending.clear();
|
|
41
|
-
});
|
|
63
|
+
proc.stdin.on("error", (err) => clearProc(err));
|
|
64
|
+
proc.on("exit", (code) => clearProc(new Error("Process exited: " + code)));
|
|
42
65
|
return proc;
|
|
43
66
|
}
|
|
44
67
|
|
|
@@ -47,7 +70,16 @@ function call(method, params) {
|
|
|
47
70
|
const id = ++nextId;
|
|
48
71
|
pending.set(id, { resolve, reject });
|
|
49
72
|
try {
|
|
50
|
-
|
|
73
|
+
const p = getProc();
|
|
74
|
+
const ok = p.stdin.write(JSON.stringify({ id, method, params }) + "\n", (err) => {
|
|
75
|
+
if (err) {
|
|
76
|
+
pending.delete(id);
|
|
77
|
+
reject(err);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (!ok) {
|
|
81
|
+
p.stdin.once("drain", () => {});
|
|
82
|
+
}
|
|
51
83
|
} catch (e) {
|
|
52
84
|
pending.delete(id);
|
|
53
85
|
reject(e);
|
package/dist/loader.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
3
4
|
import { fileURLToPath } from "url";
|
|
4
5
|
|
|
5
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -8,13 +9,39 @@ const binDir = path.join(__dirname, "bin", isWin ? "win" : "linux");
|
|
|
8
9
|
const binName = isWin ? "validate-sdk.exe" : "validate-sdk";
|
|
9
10
|
const binPath = path.join(binDir, binName);
|
|
10
11
|
|
|
12
|
+
function checkBinary() {
|
|
13
|
+
if (!fs.existsSync(binPath)) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`@validate-sdk/v2: binary not found for ${process.platform} at ${binPath}. Reinstall the package.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
if (!isWin) {
|
|
19
|
+
try {
|
|
20
|
+
fs.accessSync(binPath, fs.constants.X_OK);
|
|
21
|
+
} catch (_) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`@validate-sdk/v2: Linux binary is not executable (${binPath}). Run: chmod +x "${binPath}" or reinstall.`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
11
29
|
let nextId = 0;
|
|
12
30
|
const pending = new Map();
|
|
13
31
|
let proc = null;
|
|
14
32
|
let inputBuf = "";
|
|
15
33
|
|
|
34
|
+
function clearProc(err) {
|
|
35
|
+
if (!proc) return;
|
|
36
|
+
proc = null;
|
|
37
|
+
const msg = err ? err.message || String(err) : "Subprocess closed";
|
|
38
|
+
for (const [, p] of pending) p.reject(new Error(msg));
|
|
39
|
+
pending.clear();
|
|
40
|
+
}
|
|
41
|
+
|
|
16
42
|
function getProc() {
|
|
17
43
|
if (proc) return proc;
|
|
44
|
+
checkBinary();
|
|
18
45
|
proc = spawn(binPath, [], { stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
19
46
|
proc.stdout.setEncoding("utf8");
|
|
20
47
|
proc.stdout.on("data", (chunk) => {
|
|
@@ -34,11 +61,8 @@ function getProc() {
|
|
|
34
61
|
} catch (_) {}
|
|
35
62
|
}
|
|
36
63
|
});
|
|
37
|
-
proc.on("
|
|
38
|
-
|
|
39
|
-
for (const [, p] of pending) p.reject(new Error("Process exited: " + code));
|
|
40
|
-
pending.clear();
|
|
41
|
-
});
|
|
64
|
+
proc.stdin.on("error", (err) => clearProc(err));
|
|
65
|
+
proc.on("exit", (code) => clearProc(new Error("Process exited: " + code)));
|
|
42
66
|
return proc;
|
|
43
67
|
}
|
|
44
68
|
|
|
@@ -47,7 +71,16 @@ function call(method, params) {
|
|
|
47
71
|
const id = ++nextId;
|
|
48
72
|
pending.set(id, { resolve, reject });
|
|
49
73
|
try {
|
|
50
|
-
|
|
74
|
+
const p = getProc();
|
|
75
|
+
const ok = p.stdin.write(JSON.stringify({ id, method, params }) + "\n", (err) => {
|
|
76
|
+
if (err) {
|
|
77
|
+
pending.delete(id);
|
|
78
|
+
reject(err);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (!ok) {
|
|
82
|
+
p.stdin.once("drain", () => {});
|
|
83
|
+
}
|
|
51
84
|
} catch (e) {
|
|
52
85
|
pending.delete(id);
|
|
53
86
|
reject(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@validate-sdk/v2",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.23",
|
|
4
4
|
"main": "dist/loader.cjs",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/loader.mjs",
|
|
@@ -13,10 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"dist/loader.cjs",
|
|
17
|
-
"dist/loader.mjs",
|
|
18
|
-
"dist/index.d.ts",
|
|
19
|
-
"dist/bin/**/*",
|
|
16
|
+
"dist/loader.cjs","dist/loader.mjs","dist/index.d.ts","dist/bin/**/*",
|
|
20
17
|
"scripts/postinstall.cjs",
|
|
21
18
|
"README.md"
|
|
22
19
|
],
|
package/scripts/README.md
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# Code Obfuscation/Deobfuscation Script
|
|
2
|
-
|
|
3
|
-
This script can both obfuscate and deobfuscate JavaScript/TypeScript code.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
### Obfuscation
|
|
8
|
-
- Base64 encodes string literals
|
|
9
|
-
- Renames variables to hexadecimal format (`_0x1`, `_0x2`, etc.)
|
|
10
|
-
- Minifies code (removes whitespace and comments)
|
|
11
|
-
|
|
12
|
-
### Deobfuscation
|
|
13
|
-
- Decodes base64 strings back to readable text
|
|
14
|
-
- Renames hex variables to readable names
|
|
15
|
-
- Formats code with proper indentation
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
### Via npm scripts:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
# Obfuscate a file
|
|
23
|
-
npm run obfuscate <input-file> [output-file]
|
|
24
|
-
|
|
25
|
-
# Deobfuscate a file
|
|
26
|
-
npm run deobfuscate <input-file> [output-file]
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Direct usage (JavaScript - no dependencies):
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
# Obfuscate
|
|
33
|
-
node scripts/obfuscate.js obfuscate src/util.ts dist/util.obf.js
|
|
34
|
-
|
|
35
|
-
# Deobfuscate
|
|
36
|
-
node scripts/obfuscate.js deobfuscate src/util.ts dist/util.deobf.ts
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Direct usage (TypeScript - requires tsx):
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
# Obfuscate
|
|
43
|
-
tsx scripts/obfuscate.ts obfuscate src/util.ts dist/util.obf.js
|
|
44
|
-
|
|
45
|
-
# Deobfuscate
|
|
46
|
-
tsx scripts/obfuscate.ts deobfuscate src/util.ts dist/util.deobf.ts
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Examples
|
|
50
|
-
|
|
51
|
-
### Obfuscate code:
|
|
52
|
-
```bash
|
|
53
|
-
npm run obfuscate src/util.ts dist/util.obf.js
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Deobfuscate code:
|
|
57
|
-
```bash
|
|
58
|
-
npm run deobfuscate src/util.ts dist/util.deobf.ts
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## How it works
|
|
62
|
-
|
|
63
|
-
### Obfuscation Process:
|
|
64
|
-
1. Extracts all string literals from the code
|
|
65
|
-
2. Encodes them to base64
|
|
66
|
-
3. Replaces strings with `Buffer.from('base64string','base64').toString()` calls
|
|
67
|
-
4. Renames variables to hex format (`_0x1`, `_0x2`, etc.)
|
|
68
|
-
5. Minifies the code
|
|
69
|
-
|
|
70
|
-
### Deobfuscation Process:
|
|
71
|
-
1. Finds all `Buffer.from('...','base64').toString()` patterns
|
|
72
|
-
2. Decodes base64 strings back to original text
|
|
73
|
-
3. Renames hex variables to readable names
|
|
74
|
-
4. Formats the code with proper indentation
|
|
75
|
-
|
|
76
|
-
## Limitations
|
|
77
|
-
|
|
78
|
-
- Variable name inference is basic - may not perfectly restore original names
|
|
79
|
-
- Complex obfuscation techniques (control flow flattening, etc.) are not handled
|
|
80
|
-
- Works best with simple obfuscation patterns (base64 strings + hex variables)
|
|
81
|
-
|