diff --git a/.gitignore b/.gitignore index ec919e2..1a240e4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ # vendor/ ipa-medit +lldb-driver.py # goreleaser dist/ diff --git a/pkg/lldb/lldb.go b/pkg/lldb/lldb.go index c0f86a9..a8d6d23 100644 --- a/pkg/lldb/lldb.go +++ b/pkg/lldb/lldb.go @@ -5,11 +5,13 @@ package lldb import ( "bytes" + "crypto/sha256" "io" "os" "os/exec" "os/signal" "path/filepath" + "reflect" "syscall" ) @@ -20,6 +22,25 @@ func fileExists(filepath string) bool { return err == nil } +func calcFileHash(filepath string) []byte { + f, _ := os.Open(filepath) + defer f.Close() + + h := sha256.New() + io.Copy(h, f) + + return h.Sum(nil) +} + +func makePythonFile(filepath string) error { + fp, err := os.Create(filepath) + if err != nil { + return err + } + fp.WriteString(pythonData) + return nil +} + func PreparePythonFile() error { exePath, err := os.Executable() if err != nil { @@ -27,11 +48,13 @@ func PreparePythonFile() error { } pyPath = filepath.Join(filepath.Dir(exePath), "lldb-driver.py") if !fileExists(pyPath) { - fp, err := os.Create(pyPath) - if err != nil { - return err + makePythonFile(pyPath) + } else { + pyDataHash := sha256.Sum256([]byte(pythonData)) + fileHash := calcFileHash(pyPath) + if !reflect.DeepEqual(pyDataHash[:], fileHash) { + makePythonFile(pyPath) } - fp.WriteString(pythonData) } return nil } diff --git a/pkg/lldb/lldb_driver.go b/pkg/lldb/lldb_driver.go index 0c68973..b12aab9 100644 --- a/pkg/lldb/lldb_driver.go +++ b/pkg/lldb/lldb_driver.go @@ -3,8 +3,7 @@ package lldb -const pythonData string = ` -#!/usr/bin/env python3 +const pythonData string = `#!/usr/bin/env python3 # coding: UTF-8 import multiprocessing