adspower-browser 2.1.4 → 2.1.5
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/cli/core/winHideChildProcess.js +108 -0
- package/cli/core/winHideChildProcessLogic.js +61 -0
- package/cli/index.js +3712 -0
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
4
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/core/winHideChildProcessLogic.js
|
|
8
|
+
var require_winHideChildProcessLogic = __commonJS({
|
|
9
|
+
"src/core/winHideChildProcessLogic.js"(exports2, module2) {
|
|
10
|
+
"use strict";
|
|
11
|
+
var path = require("path");
|
|
12
|
+
var CONSOLE_EXECUTABLES = /^(cmd|powershell|pwsh|wmic|tasklist|reg|findstr|where|whoami|systeminfo|netstat|sc|net|chcp|hostname|conhost)(\.exe)?$/i;
|
|
13
|
+
var BROWSER_EXECUTABLES = /^(sunbrowser|flowerbrowser|chrome|chromium|msedge|firefox|brave|opera)(\.exe)?$/i;
|
|
14
|
+
function getExecutableBaseName(command) {
|
|
15
|
+
const trimmed = String(command).trim();
|
|
16
|
+
let executable = trimmed;
|
|
17
|
+
const quotedMatch = trimmed.match(/^"([^"]+)"|^'([^']+)'/);
|
|
18
|
+
if (quotedMatch) {
|
|
19
|
+
executable = quotedMatch[1] || quotedMatch[2];
|
|
20
|
+
} else {
|
|
21
|
+
executable = trimmed.split(/\s+/)[0] || trimmed;
|
|
22
|
+
}
|
|
23
|
+
executable = executable.replace(/^["']|["']$/g, "");
|
|
24
|
+
return path.basename(executable.replace(/\\/g, "/")).toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
function shouldHideForSpawn(command, options) {
|
|
27
|
+
if (options?.windowsHide === false) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const base = getExecutableBaseName(command);
|
|
31
|
+
if (BROWSER_EXECUTABLES.test(base)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (CONSOLE_EXECUTABLES.test(base)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (options?.shell) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (/\.(cmd|bat)$/i.test(base)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function withWindowsHideForExec2(options) {
|
|
46
|
+
if (typeof options === "object" && options !== null && !Array.isArray(options)) {
|
|
47
|
+
if (options.windowsHide === false) {
|
|
48
|
+
return options;
|
|
49
|
+
}
|
|
50
|
+
return { ...options, windowsHide: true };
|
|
51
|
+
}
|
|
52
|
+
return { windowsHide: true };
|
|
53
|
+
}
|
|
54
|
+
function withWindowsHideForSpawn2(command, options) {
|
|
55
|
+
const opts = typeof options === "object" && options !== null && !Array.isArray(options) ? { ...options } : {};
|
|
56
|
+
if (!shouldHideForSpawn(command, opts)) {
|
|
57
|
+
return opts;
|
|
58
|
+
}
|
|
59
|
+
return { ...opts, windowsHide: true };
|
|
60
|
+
}
|
|
61
|
+
module2.exports = {
|
|
62
|
+
CONSOLE_EXECUTABLES,
|
|
63
|
+
BROWSER_EXECUTABLES,
|
|
64
|
+
getExecutableBaseName,
|
|
65
|
+
shouldHideForSpawn,
|
|
66
|
+
withWindowsHideForExec: withWindowsHideForExec2,
|
|
67
|
+
withWindowsHideForSpawn: withWindowsHideForSpawn2
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// src/core/winHideChildProcess.js
|
|
73
|
+
if (process.platform !== "win32") {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
var cp = require("child_process");
|
|
77
|
+
var { withWindowsHideForExec, withWindowsHideForSpawn } = require_winHideChildProcessLogic();
|
|
78
|
+
function normalizeExecArgs(options, callback) {
|
|
79
|
+
if (typeof options === "function") {
|
|
80
|
+
return { options: withWindowsHideForExec({}), callback: options };
|
|
81
|
+
}
|
|
82
|
+
return { options: withWindowsHideForExec(options || {}), callback };
|
|
83
|
+
}
|
|
84
|
+
function normalizeSpawnArgs(command, args, options) {
|
|
85
|
+
if (Array.isArray(args)) {
|
|
86
|
+
return { args, options: withWindowsHideForSpawn(command, options || {}) };
|
|
87
|
+
}
|
|
88
|
+
return { args: [], options: withWindowsHideForSpawn(command, args || {}) };
|
|
89
|
+
}
|
|
90
|
+
var origExec = cp.exec.bind(cp);
|
|
91
|
+
cp.exec = function exec(cmd, options, callback) {
|
|
92
|
+
const { options: opts, callback: cb } = normalizeExecArgs(options, callback);
|
|
93
|
+
return origExec(cmd, opts, cb);
|
|
94
|
+
};
|
|
95
|
+
var origExecSync = cp.execSync.bind(cp);
|
|
96
|
+
cp.execSync = function execSync(cmd, options) {
|
|
97
|
+
return origExecSync(cmd, withWindowsHideForExec(options || {}));
|
|
98
|
+
};
|
|
99
|
+
var origSpawn = cp.spawn.bind(cp);
|
|
100
|
+
cp.spawn = function spawn(command, args, options) {
|
|
101
|
+
const normalized = normalizeSpawnArgs(command, args, options);
|
|
102
|
+
return origSpawn(command, normalized.args, normalized.options);
|
|
103
|
+
};
|
|
104
|
+
var origSpawnSync = cp.spawnSync.bind(cp);
|
|
105
|
+
cp.spawnSync = function spawnSync(command, args, options) {
|
|
106
|
+
const normalized = normalizeSpawnArgs(command, args, options);
|
|
107
|
+
return origSpawnSync(command, normalized.args, normalized.options);
|
|
108
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/core/winHideChildProcessLogic.js
|
|
4
|
+
var path = require("path");
|
|
5
|
+
var CONSOLE_EXECUTABLES = /^(cmd|powershell|pwsh|wmic|tasklist|reg|findstr|where|whoami|systeminfo|netstat|sc|net|chcp|hostname|conhost)(\.exe)?$/i;
|
|
6
|
+
var BROWSER_EXECUTABLES = /^(sunbrowser|flowerbrowser|chrome|chromium|msedge|firefox|brave|opera)(\.exe)?$/i;
|
|
7
|
+
function getExecutableBaseName(command) {
|
|
8
|
+
const trimmed = String(command).trim();
|
|
9
|
+
let executable = trimmed;
|
|
10
|
+
const quotedMatch = trimmed.match(/^"([^"]+)"|^'([^']+)'/);
|
|
11
|
+
if (quotedMatch) {
|
|
12
|
+
executable = quotedMatch[1] || quotedMatch[2];
|
|
13
|
+
} else {
|
|
14
|
+
executable = trimmed.split(/\s+/)[0] || trimmed;
|
|
15
|
+
}
|
|
16
|
+
executable = executable.replace(/^["']|["']$/g, "");
|
|
17
|
+
return path.basename(executable.replace(/\\/g, "/")).toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
function shouldHideForSpawn(command, options) {
|
|
20
|
+
if (options?.windowsHide === false) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const base = getExecutableBaseName(command);
|
|
24
|
+
if (BROWSER_EXECUTABLES.test(base)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (CONSOLE_EXECUTABLES.test(base)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (options?.shell) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (/\.(cmd|bat)$/i.test(base)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
function withWindowsHideForExec(options) {
|
|
39
|
+
if (typeof options === "object" && options !== null && !Array.isArray(options)) {
|
|
40
|
+
if (options.windowsHide === false) {
|
|
41
|
+
return options;
|
|
42
|
+
}
|
|
43
|
+
return { ...options, windowsHide: true };
|
|
44
|
+
}
|
|
45
|
+
return { windowsHide: true };
|
|
46
|
+
}
|
|
47
|
+
function withWindowsHideForSpawn(command, options) {
|
|
48
|
+
const opts = typeof options === "object" && options !== null && !Array.isArray(options) ? { ...options } : {};
|
|
49
|
+
if (!shouldHideForSpawn(command, opts)) {
|
|
50
|
+
return opts;
|
|
51
|
+
}
|
|
52
|
+
return { ...opts, windowsHide: true };
|
|
53
|
+
}
|
|
54
|
+
module.exports = {
|
|
55
|
+
CONSOLE_EXECUTABLES,
|
|
56
|
+
BROWSER_EXECUTABLES,
|
|
57
|
+
getExecutableBaseName,
|
|
58
|
+
shouldHideForSpawn,
|
|
59
|
+
withWindowsHideForExec,
|
|
60
|
+
withWindowsHideForSpawn
|
|
61
|
+
};
|