Validate core file with md5.
This commit is contained in:
parent
bee5d20338
commit
2aa3e5ca1e
|
@ -17,6 +17,8 @@ import PromiseKit
|
|||
|
||||
private let statusItemLengthWithSpeed: CGFloat = 72
|
||||
|
||||
private let MetaCoreMd5 = "WOSHIZIDONGSHENGCHENGDEA"
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
var statusItem: NSStatusItem!
|
||||
|
@ -458,18 +460,30 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
|
||||
if let path = Paths.defaultCorePath(),
|
||||
testMetaCore(path) != nil {
|
||||
testMetaCore(path) != nil,
|
||||
validateDefaultCore() {
|
||||
return path
|
||||
} else {
|
||||
assertionFailure("Meta Core file losted.")
|
||||
return ""
|
||||
return "ERROR"
|
||||
}
|
||||
}()
|
||||
|
||||
if corePath == "ERROR" {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Failure to verify the internal Meta Core.\nDo NOT replace core file in the resources folder."
|
||||
alert.alertStyle = .warning
|
||||
alert.addButton(withTitle: NSLocalizedString("Quit", comment: ""))
|
||||
alert.runModal()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
NSApplication.shared.terminate(nil)
|
||||
}
|
||||
} else {
|
||||
RemoteConfigManager.shared.verifyConfigTask.setLaunchPath(corePath)
|
||||
PrivilegedHelperManager.shared.helper()?.initMetaCore(withPath: corePath)
|
||||
Logger.log("initClashCore finish")
|
||||
}
|
||||
}
|
||||
|
||||
func testMetaCore(_ path: String) -> (version: String, date: Date?)? {
|
||||
guard FileManager.default.fileExists(atPath: path),
|
||||
|
@ -516,6 +530,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
return (version: version, date: date)
|
||||
}
|
||||
|
||||
func validateDefaultCore() -> Bool {
|
||||
guard let path = Paths.defaultCorePath() else { return false }
|
||||
#if DEBUG
|
||||
return true
|
||||
#endif
|
||||
let proc = Process()
|
||||
proc.executableURL = .init(fileURLWithPath: "/sbin/md5")
|
||||
proc.arguments = ["-q", path]
|
||||
let pipe = Pipe()
|
||||
proc.standardOutput = pipe
|
||||
|
||||
try? proc.run()
|
||||
proc.waitUntilExit()
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
guard proc.terminationStatus == 0,
|
||||
let out = String(data: data, encoding: .utf8) else {
|
||||
return false
|
||||
}
|
||||
|
||||
let md5 = out.replacingOccurrences(of: "\n", with: "")
|
||||
return md5 == MetaCoreMd5
|
||||
}
|
||||
|
||||
func chmodX(_ path: String) -> Bool {
|
||||
let proc = Process()
|
||||
proc.executableURL = .init(fileURLWithPath: "/bin/chmod")
|
||||
|
|
|
@ -16,6 +16,10 @@ chmod +x com.metacubex.ClashX.ProxyConfigHelper.meta
|
|||
cp com.metacubex.ClashX.ProxyConfigHelper.meta ../ClashX/Resources/
|
||||
cd ..
|
||||
|
||||
echo "Update meta core md5 to code"
|
||||
sed -i '' "s/WOSHIZIDONGSHENGCHENGDEA/$(md5 -q ClashX/Resources/com.metacubex.ClashX.ProxyConfigHelper.meta)/g" ClashX/AppDelegate.swift
|
||||
|
||||
|
||||
echo "Pod install"
|
||||
pod install
|
||||
echo "delete old files"
|
||||
|
|
Loading…
Reference in New Issue