hunter-open-sdk 1.1.2 → 2.0.0-beta.12
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 -0
- package/lib/abilities/activate/index.js +54 -0
- package/lib/abilities/activate/worker.js +24 -0
- package/lib/abilities/erase/index.js +54 -0
- package/lib/abilities/erase/worker.js +24 -0
- package/lib/abilities/getGeneralReport/index.js +54 -0
- package/lib/abilities/getGeneralReport/worker.js +27 -0
- package/lib/abilities/getSaaSReport/index.js +54 -0
- package/lib/abilities/getSaaSReport/worker.js +19 -0
- package/lib/abilities/skip/index.js +54 -0
- package/lib/abilities/skip/worker.js +24 -0
- package/lib/events/driver/command.js +8 -9
- package/lib/events/driver/service.js +24 -35
- package/lib/events/driver/winDriver.js +121 -188
- package/lib/getAndroidSn/index.js +134 -198
- package/lib/helper/deviceHelper.js +19 -37
- package/lib/index.js +12 -6
- package/lib/registerEvent/index.js +149 -247
- package/lib/resources/dll/{libinspectionkit_x64_0.0.7.dll → libinspectionkit_x64_0.2.0.dll} +0 -0
- package/lib/resources/mac/{libinspectionkit_arm64_0.0.7.dylib → libinspectionkit_amd64_0.2.0.dylib} +0 -0
- package/lib/resources/mac/libinspectionkit_arm64_0.2.0.dylib +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.command.js +8 -9
- package/lib/utils/utils.common.js +14 -0
- package/lib/utils/{utils.js → utils.env.js} +19 -18
- package/lib/utils/utils.global.js +166 -42
- package/lib/utils/utils.initDll.js +24 -20
- package/lib/utils/utils.path.js +24 -6
- package/lib/utils/utils.process.js +23 -0
- package/lib/utils/utils.sn.js +31 -47
- package/package.json +16 -14
- package/lib/getGeneralReport/index.js +0 -76
- package/lib/getGeneralReport/worker.js +0 -20
- package/lib/getSaaSReport/index.js +0 -76
- package/lib/getSaaSReport/worker.js +0 -20
- package/lib/resources/mac/libinspectionkit_amd64_0.0.7.dylib +0 -0
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.checkHasDriver = checkHasDriver;
|
|
8
7
|
exports.downloadDriver = downloadDriver;
|
|
9
|
-
var
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
-
var _utils = require("../../utils/utils");
|
|
8
|
+
var _utils = require("../../utils/utils.env");
|
|
13
9
|
var _request = _interopRequireDefault(require("request"));
|
|
14
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
12
|
// import { app } from 'electron'
|
|
16
13
|
// import { command } from '../../utils/utils.command'
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const Sentry = require("@sentry/browser");
|
|
16
|
+
const sudo = require('sudo-prompt');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const childProcess = require('child_process');
|
|
20
|
+
const compressing = require('compressing');
|
|
21
|
+
const exec = childProcess.exec;
|
|
22
|
+
const options = {
|
|
26
23
|
name: 'Electron'
|
|
27
24
|
};
|
|
28
|
-
|
|
25
|
+
const msiStr = 'AppleMobileDeviceService';
|
|
29
26
|
// const reddirPath = 'C:/Program Files (x86)/Common Files/Apple/Apple Application Support'
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const cmdStr = process.platform === 'win32' ? 'tasklist' : 'ps aux';
|
|
28
|
+
const CACHE_PATH = (0, _utils.isDev)() ? path.join(process.cwd(), './cache') : path.join(process.resourcesPath, './cache');
|
|
29
|
+
const filePath = path.join(CACHE_PATH, './iTunesOL_Lite_64_12.10.0.7.zip');
|
|
33
30
|
|
|
34
31
|
// 确保缓存目录存在,避免后续写入流抛出 ENOENT
|
|
35
32
|
try {
|
|
@@ -38,8 +35,8 @@ try {
|
|
|
38
35
|
console.error('创建缓存目录失败:', e);
|
|
39
36
|
Sentry.captureException('创建缓存目录失败:' + JSON.stringify(e));
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
return new Promise(
|
|
38
|
+
const checkProcess = () => {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
43
40
|
exec(cmdStr, function (err, stdout, stderr) {
|
|
44
41
|
// console.log('stdout>>>', stdout)
|
|
45
42
|
console.log('stderr>>>', stderr);
|
|
@@ -47,10 +44,10 @@ var checkProcess = function checkProcess() {
|
|
|
47
44
|
return reject(err);
|
|
48
45
|
}
|
|
49
46
|
if (stdout) {
|
|
50
|
-
|
|
51
|
-
stdout.split('\n').filter(
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
let hasRroess = false;
|
|
48
|
+
stdout.split('\n').filter(line => {
|
|
49
|
+
let processMessage = line.trim().split(/\s+/);
|
|
50
|
+
let processName = processMessage[0];
|
|
54
51
|
// console.log('names.....', processName)
|
|
55
52
|
if (processName.indexOf(msiStr) > -1) {
|
|
56
53
|
hasRroess = true;
|
|
@@ -69,8 +66,8 @@ var checkProcess = function checkProcess() {
|
|
|
69
66
|
// })
|
|
70
67
|
// }
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
return new Promise(
|
|
69
|
+
const checkCache = () => {
|
|
70
|
+
return new Promise(resolve => {
|
|
74
71
|
fs.readFile(filePath, function (err) {
|
|
75
72
|
resolve(err ? false : true);
|
|
76
73
|
});
|
|
@@ -78,54 +75,39 @@ var checkCache = function checkCache() {
|
|
|
78
75
|
};
|
|
79
76
|
|
|
80
77
|
// 轮询检测是否存在进程
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
let processCheckTimer = null;
|
|
79
|
+
const checkProcessTimer = () => {
|
|
83
80
|
// 清除之前的定时器
|
|
84
81
|
if (processCheckTimer) {
|
|
85
82
|
clearTimeout(processCheckTimer);
|
|
86
83
|
}
|
|
87
|
-
processCheckTimer = setTimeout(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
case 2:
|
|
95
|
-
hasDriver = _context.sent;
|
|
96
|
-
if (!hasDriver) {
|
|
97
|
-
_context.next = 6;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
// 检测到驱动,清除定时器并返回
|
|
101
|
-
if (processCheckTimer) {
|
|
102
|
-
clearTimeout(processCheckTimer);
|
|
103
|
-
processCheckTimer = null;
|
|
104
|
-
}
|
|
105
|
-
return _context.abrupt("return");
|
|
106
|
-
case 6:
|
|
107
|
-
// 继续轮询检测
|
|
108
|
-
checkProcessTimer();
|
|
109
|
-
case 7:
|
|
110
|
-
case "end":
|
|
111
|
-
return _context.stop();
|
|
84
|
+
processCheckTimer = setTimeout(async () => {
|
|
85
|
+
let hasDriver = await checkProcess();
|
|
86
|
+
if (hasDriver) {
|
|
87
|
+
// 检测到驱动,清除定时器并返回
|
|
88
|
+
if (processCheckTimer) {
|
|
89
|
+
clearTimeout(processCheckTimer);
|
|
90
|
+
processCheckTimer = null;
|
|
112
91
|
}
|
|
113
|
-
|
|
114
|
-
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// 继续轮询检测
|
|
95
|
+
checkProcessTimer();
|
|
96
|
+
}, 1000);
|
|
115
97
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
98
|
+
const installDriver = () => {
|
|
99
|
+
const AppleApplicationSupport = path.join(CACHE_PATH, './AppleApplicationSupport.msi');
|
|
100
|
+
const AppleApplicationSupport64 = path.join(CACHE_PATH, './AppleApplicationSupport64.msi');
|
|
101
|
+
const AppleMobileDeviceSupport64 = path.join(CACHE_PATH, './AppleMobileDeviceSupport64.msi');
|
|
102
|
+
const Bonjour64 = path.join(CACHE_PATH, './Bonjour64.msi');
|
|
103
|
+
const cmdStr = `start /i /wait ${AppleApplicationSupport} /qn && start /i /wait ${AppleApplicationSupport64} /qn && start /i /wait ${AppleMobileDeviceSupport64} /qn && start /i /wait ${Bonjour64} /qn`;
|
|
122
104
|
console.log('开始安装驱动,命令:', cmdStr);
|
|
123
105
|
console.log('检查安装文件是否存在:');
|
|
124
106
|
console.log('AppleApplicationSupport:', fs.existsSync(AppleApplicationSupport));
|
|
125
107
|
console.log('AppleApplicationSupport64:', fs.existsSync(AppleApplicationSupport64));
|
|
126
108
|
console.log('AppleMobileDeviceSupport64:', fs.existsSync(AppleMobileDeviceSupport64));
|
|
127
109
|
console.log('Bonjour64:', fs.existsSync(Bonjour64));
|
|
128
|
-
return new Promise(
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
129
111
|
sudo.exec(cmdStr, options, function (error, stdout, stderr) {
|
|
130
112
|
console.log('安装 error>>', error);
|
|
131
113
|
console.log('安装 stdout>>>', stdout);
|
|
@@ -143,13 +125,13 @@ var installDriver = function installDriver() {
|
|
|
143
125
|
});
|
|
144
126
|
};
|
|
145
127
|
// 解压文件
|
|
146
|
-
|
|
147
|
-
return new Promise(
|
|
128
|
+
const uncopressingFile = filePath => {
|
|
129
|
+
return new Promise(resolve => {
|
|
148
130
|
console.log('开始解压文件:', filePath);
|
|
149
|
-
compressing.zip.uncompress(filePath, CACHE_PATH).then(
|
|
131
|
+
compressing.zip.uncompress(filePath, CACHE_PATH).then(() => {
|
|
150
132
|
console.log('文件解压成功');
|
|
151
133
|
resolve(true);
|
|
152
|
-
}).catch(
|
|
134
|
+
}).catch(err => {
|
|
153
135
|
console.error('文件解压失败:', err);
|
|
154
136
|
Sentry.captureException('文件解压失败:' + JSON.stringify(err));
|
|
155
137
|
resolve(false);
|
|
@@ -160,165 +142,116 @@ var uncopressingFile = function uncopressingFile(filePath) {
|
|
|
160
142
|
// Promise 版本的 downloadDriver,onProgress 作为参数,成功 resolve,失败 reject
|
|
161
143
|
function downloadDriver(onProgress) {
|
|
162
144
|
console.log('=== downloadDriver 函数被调用 ===');
|
|
163
|
-
console.log('onProgress 参数:',
|
|
164
|
-
return new Promise(
|
|
145
|
+
console.log('onProgress 参数:', typeof onProgress);
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
165
147
|
console.log('=== 开始创建Promise ===');
|
|
166
|
-
|
|
167
|
-
|
|
148
|
+
const url = 'http://ljtools.zhuanstatic.com/download/iTunesDriver/iTunesOL_Lite_64_12.10.0.7.zip';
|
|
149
|
+
const dest = filePath;
|
|
168
150
|
console.log('开始下载驱动文件:', url);
|
|
169
151
|
console.log('目标路径:', dest);
|
|
170
152
|
|
|
171
153
|
// 检查目标目录是否存在
|
|
172
|
-
|
|
154
|
+
const destDir = path.dirname(dest);
|
|
173
155
|
console.log('目标目录:', destDir);
|
|
174
156
|
console.log('目录是否存在:', fs.existsSync(destDir));
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
157
|
+
const fileStream = _fsExtra.default.createWriteStream(dest);
|
|
158
|
+
let received = 0;
|
|
159
|
+
let total = 0;
|
|
178
160
|
|
|
179
161
|
// 进度回调限流:进度变化超过5%时调用
|
|
180
|
-
|
|
181
|
-
|
|
162
|
+
let lastProgressPercent = 0;
|
|
163
|
+
const PROGRESS_THRESHOLD = 5; // 5%阈值
|
|
182
164
|
|
|
183
|
-
|
|
184
|
-
|
|
165
|
+
const throttledProgressCallback = percent => {
|
|
166
|
+
const shouldCall = Math.abs(percent - lastProgressPercent) >= PROGRESS_THRESHOLD;
|
|
185
167
|
if (shouldCall && onProgress) {
|
|
186
168
|
onProgress(percent);
|
|
187
169
|
lastProgressPercent = percent;
|
|
188
|
-
console.log(
|
|
170
|
+
console.log(`下载进度: ${percent}% (${received}/${total})`);
|
|
189
171
|
}
|
|
190
172
|
};
|
|
191
173
|
console.log('=== 开始创建request ===');
|
|
192
|
-
(0, _request.default)(url).on('response',
|
|
174
|
+
(0, _request.default)(url).on('response', response => {
|
|
193
175
|
console.log('下载响应状态:', response.statusCode);
|
|
194
176
|
if (response.statusCode !== 200) {
|
|
195
|
-
reject(new Error(
|
|
177
|
+
reject(new Error(`下载失败: ${response.statusMessage}`));
|
|
196
178
|
return;
|
|
197
179
|
}
|
|
198
180
|
total = parseInt(response.headers['content-length'], 10);
|
|
199
181
|
console.log('文件总大小:', total, 'bytes');
|
|
200
|
-
}).on('data',
|
|
182
|
+
}).on('data', chunk => {
|
|
201
183
|
received += chunk.length;
|
|
202
184
|
if (total) {
|
|
203
|
-
|
|
185
|
+
const percent = Math.round(received / total * 100);
|
|
204
186
|
throttledProgressCallback(percent);
|
|
205
187
|
}
|
|
206
|
-
}).on('error',
|
|
188
|
+
}).on('error', err => {
|
|
207
189
|
console.error('驱动下载失败', err);
|
|
208
190
|
Sentry.captureException('驱动下载失败:' + JSON.stringify(err));
|
|
209
191
|
fileStream.end(); // 确保关闭文件流
|
|
210
192
|
reject(err);
|
|
211
|
-
}).pipe(fileStream).once('close',
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
215
|
-
case 0:
|
|
216
|
-
console.log('=== CLOSE 事件被触发 ===');
|
|
217
|
-
console.log('文件下载完成,开始解压...');
|
|
193
|
+
}).pipe(fileStream).once('close', async () => {
|
|
194
|
+
console.log('=== CLOSE 事件被触发 ===');
|
|
195
|
+
console.log('文件下载完成,开始解压...');
|
|
218
196
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
Sentry.captureException('解压失败');
|
|
243
|
-
reject(new Error('解压失败'));
|
|
244
|
-
}
|
|
245
|
-
_context2.next = 16;
|
|
246
|
-
break;
|
|
247
|
-
case 11:
|
|
248
|
-
_context2.prev = 11;
|
|
249
|
-
_context2.t0 = _context2["catch"](3);
|
|
250
|
-
console.error('解压或安装过程中出错:', _context2.t0);
|
|
251
|
-
Sentry.captureException('解压或安装过程中出错:' + JSON.stringify(_context2.t0));
|
|
252
|
-
reject(_context2.t0);
|
|
253
|
-
case 16:
|
|
254
|
-
case "end":
|
|
255
|
-
return _context2.stop();
|
|
197
|
+
// 确保最后一次进度回调被调用(100%)
|
|
198
|
+
if (onProgress && total) {
|
|
199
|
+
onProgress(100);
|
|
200
|
+
console.log('下载完成: 100%');
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
// 下载完成后解压并安装
|
|
204
|
+
const uncopressing = await uncopressingFile(filePath);
|
|
205
|
+
console.log('解压结果:', uncopressing);
|
|
206
|
+
if (uncopressing) {
|
|
207
|
+
console.log('开始安装驱动...');
|
|
208
|
+
installDriver().then(() => {
|
|
209
|
+
console.log('驱动安装成功');
|
|
210
|
+
resolve();
|
|
211
|
+
}).catch(err => {
|
|
212
|
+
console.error('驱动安装失败:', err);
|
|
213
|
+
Sentry.captureException('驱动安装失败:' + JSON.stringify(err));
|
|
214
|
+
reject(err);
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
console.error('解压失败');
|
|
218
|
+
Sentry.captureException('解压失败');
|
|
219
|
+
reject(new Error('解压失败'));
|
|
256
220
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
221
|
+
} catch (err) {
|
|
222
|
+
console.error('解压或安装过程中出错:', err);
|
|
223
|
+
Sentry.captureException('解压或安装过程中出错:' + JSON.stringify(err));
|
|
224
|
+
reject(err);
|
|
225
|
+
}
|
|
226
|
+
}).once('error', err => {
|
|
259
227
|
console.error('文件流写入错误:', err);
|
|
260
228
|
Sentry.captureException('文件流写入错误:' + JSON.stringify(err));
|
|
261
229
|
reject(err);
|
|
262
230
|
});
|
|
263
231
|
});
|
|
264
232
|
}
|
|
265
|
-
function checkHasDriver() {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return checkCache();
|
|
290
|
-
case 10:
|
|
291
|
-
if (!_context3.sent) {
|
|
292
|
-
_context3.next = 14;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
_context3.t1 = 2;
|
|
296
|
-
_context3.next = 15;
|
|
297
|
-
break;
|
|
298
|
-
case 14:
|
|
299
|
-
_context3.t1 = 0;
|
|
300
|
-
case 15:
|
|
301
|
-
hasCache = _context3.t1;
|
|
302
|
-
state = hasDriver + hasCache;
|
|
303
|
-
_context3.t2 = state;
|
|
304
|
-
_context3.next = _context3.t2 === 3 ? 20 : _context3.t2 === 1 ? 20 : _context3.t2 === 2 ? 21 : 26;
|
|
305
|
-
break;
|
|
306
|
-
case 20:
|
|
307
|
-
return _context3.abrupt("return", true);
|
|
308
|
-
case 21:
|
|
309
|
-
_context3.next = 23;
|
|
310
|
-
return uncopressingFile(filePath);
|
|
311
|
-
case 23:
|
|
312
|
-
uncopressing = _context3.sent;
|
|
313
|
-
if (uncopressing) installDriver();
|
|
314
|
-
return _context3.abrupt("return", true);
|
|
315
|
-
case 26:
|
|
316
|
-
return _context3.abrupt("return", false);
|
|
317
|
-
case 27:
|
|
318
|
-
case "end":
|
|
319
|
-
return _context3.stop();
|
|
320
|
-
}
|
|
321
|
-
}, _callee3);
|
|
322
|
-
}));
|
|
323
|
-
return _checkHasDriver.apply(this, arguments);
|
|
233
|
+
async function checkHasDriver() {
|
|
234
|
+
// 是否存在驱动进程
|
|
235
|
+
const hasDriver = (await checkProcess()) ? 1 : 0;
|
|
236
|
+
// 是否存在安装包
|
|
237
|
+
const hasCache = (await checkCache()) ? 2 : 0;
|
|
238
|
+
const state = hasDriver + hasCache;
|
|
239
|
+
switch (state) {
|
|
240
|
+
// 存在驱动进程 + 存在安装包
|
|
241
|
+
case 3:
|
|
242
|
+
|
|
243
|
+
// 仅存在驱动进程
|
|
244
|
+
case 1:
|
|
245
|
+
return true;
|
|
246
|
+
|
|
247
|
+
// 仅存在安装包 进行解压安装
|
|
248
|
+
case 2:
|
|
249
|
+
const uncopressing = await uncopressingFile(filePath);
|
|
250
|
+
if (uncopressing) installDriver();
|
|
251
|
+
return true;
|
|
252
|
+
|
|
253
|
+
// state = 0,
|
|
254
|
+
default:
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
324
257
|
}
|