|
@@ -1,10 +1,15 @@
|
|
|
|
+import { HOST_FILE_HASH_MAP } from "@/constants/constants";
|
|
import { xor } from "lodash-es";
|
|
import { xor } from "lodash-es";
|
|
|
|
|
|
-export default function checkRemote(
|
|
|
|
- exeName: string,
|
|
|
|
- cb: () => Promise<void>
|
|
|
|
-): Promise<void> {
|
|
|
|
- if (typeof window.nodeRequire == "undefined") {
|
|
|
|
|
|
+export function isElectron() {
|
|
|
|
+ return typeof window.nodeRequire != "undefined";
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const fs: typeof import("fs") = isElectron() && window.nodeRequire("fs");
|
|
|
|
+
|
|
|
|
+/** 执行本地exe文件 */
|
|
|
|
+export function execLocal(exeName: string): Promise<void> {
|
|
|
|
+ if (isElectron()) {
|
|
logger({
|
|
logger({
|
|
pgu: "AUTO",
|
|
pgu: "AUTO",
|
|
cnl: ["local", "server"],
|
|
cnl: ["local", "server"],
|
|
@@ -50,7 +55,7 @@ export default function checkRemote(
|
|
);
|
|
);
|
|
if (fs.existsSync(absPath)) {
|
|
if (fs.existsSync(absPath)) {
|
|
try {
|
|
try {
|
|
- await checkRemote([absPath, exeParams].join(" ").trim(), cb);
|
|
|
|
|
|
+ await execLocal([absPath, exeParams].join(" ").trim());
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.log("second try error", absPath);
|
|
console.log("second try error", absPath);
|
|
logger({
|
|
logger({
|
|
@@ -60,25 +65,13 @@ export default function checkRemote(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- await new Promise<void>((resolve2) =>
|
|
|
|
- setTimeout(() => resolve2(), 1000)
|
|
|
|
- );
|
|
|
|
- try {
|
|
|
|
- await cb();
|
|
|
|
- } catch (e) {
|
|
|
|
- console.log("call cb failed", e);
|
|
|
|
- logger({
|
|
|
|
- cnl: ["local", "server"],
|
|
|
|
- dtl: "call cb failed: " + e,
|
|
|
|
- });
|
|
|
|
- } finally {
|
|
|
|
- resolve();
|
|
|
|
- }
|
|
|
|
|
|
+ resolve();
|
|
}
|
|
}
|
|
);
|
|
);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/** 文件路径是否存在 */
|
|
export function fileExists(file: string): boolean {
|
|
export function fileExists(file: string): boolean {
|
|
if (typeof window.nodeRequire == "undefined") {
|
|
if (typeof window.nodeRequire == "undefined") {
|
|
logger({
|
|
logger({
|
|
@@ -88,11 +81,11 @@ export function fileExists(file: string): boolean {
|
|
});
|
|
});
|
|
throw new Error("不在Electron中,调用 fs 失败");
|
|
throw new Error("不在Electron中,调用 fs 失败");
|
|
}
|
|
}
|
|
- // eslint-disable-next-line
|
|
|
|
- return window.nodeRequire("fs").existsSync(file);
|
|
|
|
|
|
+ return fs.existsSync(file);
|
|
}
|
|
}
|
|
|
|
|
|
-export function nodeCheckRemoteDesktop() {
|
|
|
|
|
|
+/** 检测当前运行的进程中是否有“向日葵” */
|
|
|
|
+export function nodeCheckRemoteDesktop(): boolean {
|
|
logger({
|
|
logger({
|
|
pgu: "AUTO",
|
|
pgu: "AUTO",
|
|
cnl: ["local", "server"],
|
|
cnl: ["local", "server"],
|
|
@@ -111,7 +104,8 @@ export function nodeCheckRemoteDesktop() {
|
|
}
|
|
}
|
|
|
|
|
|
let previousAppList: string[] = [];
|
|
let previousAppList: string[] = [];
|
|
-export function nodeCheckProcess() {
|
|
|
|
|
|
+/** 将电脑运行的进程记录到日志 */
|
|
|
|
+export function nodeCheckProcess(): void {
|
|
try {
|
|
try {
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
const appListCP: string = window
|
|
const appListCP: string = window
|
|
@@ -141,3 +135,79 @@ export function nodeCheckProcess() {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/** 检测当前程序包的完整性。 */
|
|
|
|
+export function checkMainExe(): boolean {
|
|
|
|
+ try {
|
|
|
|
+ let iid: string = window.nodeRequire("process").pid;
|
|
|
|
+ const cp: typeof import("child_process") =
|
|
|
|
+ window.nodeRequire("child_process");
|
|
|
|
+ iid = cp
|
|
|
|
+ .execSync(
|
|
|
|
+ `cmd /c chcp 65001>nul && C:\\Windows\\System32\\wbem\\wmic process where ^(processid^=${iid}^) get parentprocessid /value`
|
|
|
|
+ )
|
|
|
|
+ .toString();
|
|
|
|
+ iid = iid.replace("ParentProcessId=", "").trim();
|
|
|
|
+ console.log(iid);
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["local", "console", "server"],
|
|
|
|
+ key: "checkMainExe",
|
|
|
|
+ dtl: `iid1: ${iid}`,
|
|
|
|
+ });
|
|
|
|
+ iid = cp
|
|
|
|
+ .execSync(
|
|
|
|
+ `cmd /c chcp 65001>nul && C:\\Windows\\System32\\wbem\\wmic process where ^(processid^=${iid}^) get parentprocessid /value`
|
|
|
|
+ )
|
|
|
|
+ .toString();
|
|
|
|
+ iid = iid.replace("ParentProcessId=", "").trim();
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["local", "console", "server"],
|
|
|
|
+ key: "checkMainExe",
|
|
|
|
+ dtl: `iid2: ${iid}`,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const executablePathBuffer = cp.execSync(
|
|
|
|
+ `cmd /c chcp 65001>nul && C:\\Windows\\System32\\wbem\\wmic process where ^(processid^=${iid}^) get executablepath /value`
|
|
|
|
+ );
|
|
|
|
+ console.log(executablePathBuffer);
|
|
|
|
+ const encoding = window.nodeRequire("encoding");
|
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
|
|
+ let executablePath: string = encoding
|
|
|
|
+ .convert(executablePathBuffer, "utf8", "gbk")
|
|
|
|
+ .toString();
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["local", "console", "server"],
|
|
|
|
+ key: "checkMainExe",
|
|
|
|
+ dtl: executablePath,
|
|
|
|
+ });
|
|
|
|
+ executablePath = executablePath
|
|
|
|
+ .replace("ExecutablePath=", "")
|
|
|
|
+ .trim()
|
|
|
|
+ .replace(/&/g, "&");
|
|
|
|
+ if (executablePath === eval(`process.env.PORTABLE_EXECUTABLE_FILE`)) {
|
|
|
|
+ const crypto: typeof import("crypto") = window.nodeRequire("crypto");
|
|
|
|
+ const getHash = crypto
|
|
|
|
+ .createHmac("sha256", "abcdefg")
|
|
|
|
+ .update(fs.readFileSync(executablePath))
|
|
|
|
+ .digest("hex");
|
|
|
|
+ console.log("the hash: ", getHash);
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["local", "console", "server"],
|
|
|
|
+ key: "checkMainExe",
|
|
|
|
+ dtl: `the hash: ${getHash}`,
|
|
|
|
+ });
|
|
|
|
+ if (HOST_FILE_HASH_MAP.get(window.location.hostname) === getHash) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // check filepath executablePath md5
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error);
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["local", "console", "server"],
|
|
|
|
+ key: "checkMainExe",
|
|
|
|
+ ejn: JSON.stringify(error),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+}
|