privacy-brush 1.1.0 → 1.1.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/package.json +1 -1
- package/src/index.mjs +4 -5
- package/src/index.test.mjs +0 -18
- package/src/lib/iconv-lite.mjs +55 -0
- package/temp.txt +30 -0
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { createRequire } from "node:module"
|
|
4
4
|
import { defaultConfig } from "./lib/config.mjs"
|
|
5
|
+
import { tryDecode } from "./lib/iconv-lite.mjs"
|
|
5
6
|
import { verbose } from "./lib/parse-args.mjs"
|
|
6
7
|
|
|
7
8
|
export class PrivacyBrush {
|
|
@@ -299,14 +300,12 @@ export class PrivacyBrush {
|
|
|
299
300
|
// 实时流处理
|
|
300
301
|
async createMaskStream() {
|
|
301
302
|
const { Transform } = await import("node:stream")
|
|
302
|
-
// let count = 0
|
|
303
303
|
|
|
304
304
|
return new Transform({
|
|
305
|
-
transform: (chunk, encoding, callback) => {
|
|
306
|
-
const text = chunk
|
|
307
|
-
// console.log(`chunk${++count}:`, { chunk, text })
|
|
308
|
-
|
|
305
|
+
transform: (/** @type {Buffer} */ chunk, encoding, callback) => {
|
|
306
|
+
const text = tryDecode(chunk)
|
|
309
307
|
const masked = this.maskText(text)
|
|
308
|
+
|
|
310
309
|
callback(null, masked)
|
|
311
310
|
},
|
|
312
311
|
})
|
package/src/index.test.mjs
CHANGED
|
@@ -7,10 +7,8 @@ const GOOGLE_BROWSER_VERSION_SAMPLE = "144.0.1234.56"
|
|
|
7
7
|
const EDGE_BROWSER_VERSION_SAMPLE = "144.0.3421.12"
|
|
8
8
|
|
|
9
9
|
test("default configurations", () => {
|
|
10
|
-
// 使用示例
|
|
11
10
|
const masker = new PrivacyBrush()
|
|
12
11
|
|
|
13
|
-
// 处理终端输出
|
|
14
12
|
const terminalOutput = `❯ flutter devices
|
|
15
13
|
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
|
|
16
14
|
Found 4 connected devices:
|
|
@@ -49,13 +47,11 @@ troubleshooting tips.
|
|
|
49
47
|
})
|
|
50
48
|
|
|
51
49
|
test("use custom maskChar and not preserveFirstPart", () => {
|
|
52
|
-
// 使用示例
|
|
53
50
|
const masker = new PrivacyBrush({
|
|
54
51
|
maskChar: "░",
|
|
55
52
|
preserveFirstPart: false,
|
|
56
53
|
})
|
|
57
54
|
|
|
58
|
-
// 处理终端输出
|
|
59
55
|
const terminalOutput = `❯ flutter devices
|
|
60
56
|
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
|
|
61
57
|
Found 4 connected devices:
|
|
@@ -94,12 +90,10 @@ troubleshooting tips.
|
|
|
94
90
|
})
|
|
95
91
|
|
|
96
92
|
test("only mask browser_version", () => {
|
|
97
|
-
// 使用示例
|
|
98
93
|
const masker = new PrivacyBrush({
|
|
99
94
|
maskPatternNames: ["browser_version"],
|
|
100
95
|
})
|
|
101
96
|
|
|
102
|
-
// 处理终端输出
|
|
103
97
|
const terminalOutput = `❯ flutter devices
|
|
104
98
|
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
|
|
105
99
|
Found 4 connected devices:
|
|
@@ -138,26 +132,18 @@ troubleshooting tips.
|
|
|
138
132
|
})
|
|
139
133
|
|
|
140
134
|
test("mask username in path", () => {
|
|
141
|
-
// 使用示例
|
|
142
135
|
const masker = new PrivacyBrush()
|
|
143
136
|
|
|
144
|
-
// 处理终端输出
|
|
145
137
|
const input = `/c/Users/legend80s/AppData/ /Users/test/code/`
|
|
146
|
-
|
|
147
138
|
const safeOutput = masker.maskText(input)
|
|
148
|
-
|
|
149
|
-
// console.log("safeOutput3:", safeOutput)
|
|
150
|
-
|
|
151
139
|
const expectedOutput = `/c/Users/█████████/AppData/ /Users/████/code/`
|
|
152
140
|
|
|
153
141
|
assert.strictEqual(safeOutput, expectedOutput)
|
|
154
142
|
})
|
|
155
143
|
|
|
156
144
|
test("mask IP", () => {
|
|
157
|
-
// 使用示例
|
|
158
145
|
const masker = new PrivacyBrush()
|
|
159
146
|
|
|
160
|
-
// 处理终端输出
|
|
161
147
|
const terminalOutput = `Windows [Version 10.0.12345.1234]
|
|
162
148
|
Chrome 144.0.1234.12
|
|
163
149
|
User IP: 10.12.123.12`
|
|
@@ -174,10 +160,8 @@ User IP: 10.██.███.██`
|
|
|
174
160
|
})
|
|
175
161
|
|
|
176
162
|
test("mask uuid", () => {
|
|
177
|
-
// 使用示例
|
|
178
163
|
const masker = new PrivacyBrush()
|
|
179
164
|
|
|
180
|
-
// 处理终端输出
|
|
181
165
|
const terminalOutput = `
|
|
182
166
|
UUID v1: 11111111-1111-1111-8111-111111111111
|
|
183
167
|
UUID v2: 22222222-2222-2222-8222-222222222222
|
|
@@ -202,10 +186,8 @@ UUID v5: ████████-████-5███-████-███
|
|
|
202
186
|
})
|
|
203
187
|
|
|
204
188
|
test("mask mac address", () => {
|
|
205
|
-
// 使用示例
|
|
206
189
|
const masker = new PrivacyBrush()
|
|
207
190
|
|
|
208
|
-
// 处理终端输出
|
|
209
191
|
const input = `
|
|
210
192
|
CA:FE:BA:BE:12:34 # "Cafe Babe"
|
|
211
193
|
DE:AD:BE:EF:CA:FE # "Dead Beef Cafe"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { verbose } from "./parse-args.mjs"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {Buffer} chunk
|
|
7
|
+
* @returns {string}
|
|
8
|
+
* @example
|
|
9
|
+
* ❯ getmac -v | node src/cli.mjs # should decode gbk
|
|
10
|
+
* ❯ ipconfig -all | node src/cli.mjs # should decode gbk
|
|
11
|
+
*/
|
|
12
|
+
export function tryDecode(chunk) {
|
|
13
|
+
const utf8 = chunk.toString("utf8")
|
|
14
|
+
|
|
15
|
+
if (!isLikelyGibberish(utf8)) {
|
|
16
|
+
return utf8
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const decoder = new TextDecoder("gbk")
|
|
20
|
+
|
|
21
|
+
verbose &&
|
|
22
|
+
console.log("[transform] isLikelyGibberish try decoding with `gbk`")
|
|
23
|
+
|
|
24
|
+
const result = decoder.decode(chunk)
|
|
25
|
+
|
|
26
|
+
if (!isLikelyGibberish(result)) {
|
|
27
|
+
return result
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
verbose && console.log("[transform] still gibberish, using utf8")
|
|
31
|
+
|
|
32
|
+
return utf8
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 检查是否是乱码
|
|
37
|
+
* @param {string} text
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
function isLikelyGibberish(text) {
|
|
41
|
+
// Windows 命令行常见乱码模式
|
|
42
|
+
const patterns = [
|
|
43
|
+
/�/g, // Unicode 替换字符
|
|
44
|
+
// /涓/g, // 常见 UTF-8 转 GBK 乱码
|
|
45
|
+
// /嶏/g, // 常见乱码字符
|
|
46
|
+
// /[À-Å]/g, // 带重音的大写字母
|
|
47
|
+
// /[È-Ë]/g, // 更多重音字母
|
|
48
|
+
// /[Ì-Ï]/g,
|
|
49
|
+
// /å/g,
|
|
50
|
+
// /ä/g,
|
|
51
|
+
// /ö/g, // 北欧字符
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
return patterns.some(pattern => pattern.test(text))
|
|
55
|
+
}
|
package/temp.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
Windows IP ����
|
|
3
|
+
|
|
4
|
+
������ . . . . . . . . . . . . . : PC-LIUCHUANZONG
|
|
5
|
+
�� DNS �� . . . . . . . . . . . : CETHIK.COM
|
|
6
|
+
�ڵ����� . . . . . . . . . . . . : ���
|
|
7
|
+
IP ·�������� . . . . . . . . . . : ��
|
|
8
|
+
WINS ���������� . . . . . . . . . : ��
|
|
9
|
+
DNS �������б� . . . . . . . . : CETHIK.COM
|
|
10
|
+
NHY_INTERNET
|
|
11
|
+
|
|
12
|
+
��̫�������� ��̫��:
|
|
13
|
+
|
|
14
|
+
�����ض��� DNS �� . . . . . . . : NHY_INTERNET
|
|
15
|
+
����. . . . . . . . . . . . . . . : Realtek PCIe GbE Family Controller
|
|
16
|
+
������ַ. . . . . . . . . . . . . : F4-6B-8C-8F-CF-52
|
|
17
|
+
DHCP ������ . . . . . . . . . . . : ��
|
|
18
|
+
�Զ�����������. . . . . . . . . . : ��
|
|
19
|
+
�������� IPv6 ��ַ. . . . . . . . : fe80::b051:a4c7:c108:5ef0%14(��ѡ)
|
|
20
|
+
IPv4 ��ַ . . . . . . . . . . . . : 10.88.103.87(��ѡ)
|
|
21
|
+
�������� . . . . . . . . . . . . : 255.255.255.0
|
|
22
|
+
�����Լ��ʱ�� . . . . . . . . . : 2026��1��28�� 8:31:05
|
|
23
|
+
��Լ���ڵ�ʱ�� . . . . . . . . . : 2162��3��6�� 17:56:12
|
|
24
|
+
Ĭ������. . . . . . . . . . . . . : 10.88.103.254
|
|
25
|
+
DHCP ������ . . . . . . . . . . . : 10.88.103.254
|
|
26
|
+
DHCPv6 IAID . . . . . . . . . . . : 250899340
|
|
27
|
+
DHCPv6 �ͻ��� DUID . . . . . . . : 00-01-00-01-2B-6D-1A-B3-F4-6B-8C-8F-CF-52
|
|
28
|
+
DNS ������ . . . . . . . . . . . : 10.88.250.2
|
|
29
|
+
114.114.114.114
|
|
30
|
+
TCPIP �ϵ� NetBIOS . . . . . . . : ������
|