Browse Source

gethash of exe

Michael Wang 3 years ago
parent
commit
623b8e559b
1 changed files with 38 additions and 20 deletions
  1. 38 20
      src/utils/util.js

+ 38 - 20
src/utils/util.js

@@ -73,24 +73,42 @@ export async function downloadFileURL(url, name) {
 }
 }
 
 
 export function checkMainExe() {
 export function checkMainExe() {
-  let iid = window.nodeRequire("process").pid;
-  iid = window
-    .nodeRequire("child_process")
-    .execSync(
-      `cmd /c chcp 65001>nul && wmic process where ^(processid^=${iid}^) get parentprocessid /value`
-    )
-    .toString();
-  const executablePath = window
-    .nodeRequire("child_process")
-    .execSync(
-      `cmd /c chcp 65001>nul && wmic process where ^(processid^=${iid}^) get executablepath`
-    )
-    .toString();
-  const getHash = window
-    .nodeRequire("crypto")
-    .createHmac("sha256", "abcdefg")
-    .update(window.nodeRequire("fs").readFileSync(executablePath))
-    .digest("hex");
-  console.log("the hash: ", getHash);
-  // check filepath executablePath md5
+  try {
+    let iid = window.nodeRequire("process").pid;
+    const cp = 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);
+    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);
+
+    let executablePath = cp.execSync(
+      `cmd /c chcp 65001>nul && C:\\Windows\\System32\\wbem\\wmic process where ^(processid^=${iid}^) get executablepath /value`
+    );
+    console.log(executablePath);
+    const encoding = window.nodeRequire("encoding");
+    executablePath = encoding.convert(executablePath, "utf8", "gbk").toString();
+    console.log(executablePath);
+    executablePath = executablePath.replace("ExecutablePath=", "").trim();
+    if (executablePath === eval(`process.env.PORTABLE_EXECUTABLE_FILE`)) {
+      const getHash = window
+        .nodeRequire("crypto")
+        .createHmac("sha256", "abcdefg")
+        .update(window.nodeRequire("fs").readFileSync(executablePath))
+        .digest("hex");
+      console.log("the hash: ", getHash);
+    }
+    // check filepath executablePath md5
+  } catch (error) {
+    console.log(error);
+  }
 }
 }