diff --git a/import_obfuscation.go b/import_obfuscation.go index 7fddad6..249ccfd 100644 --- a/import_obfuscation.go +++ b/import_obfuscation.go @@ -67,6 +67,7 @@ func appendPrivateNameMap(pkg *goobj2.Package, nameMap map[string]string) error return nil } +// extractDebugObfSrc extracts obfuscated sources from object files if -debugdir flag is enabled. func extractDebugObfSrc(pkgPath string, pkg *goobj2.Package) error { if envGarbleDebugDir == "" { return nil @@ -90,6 +91,7 @@ func extractDebugObfSrc(pkgPath string, pkg *goobj2.Package) error { return err } + // ArchiveHeader.Size incorrect, work around https://github.com/Binject/debug/issues/14 archiveSize, err := strconv.Atoi(archiveMember.ArchiveHeader.Date) if err != nil { return err @@ -122,7 +124,9 @@ func extractDebugObfSrc(pkgPath string, pkg *goobj2.Package) error { if _, err := io.Copy(debugFile, tarReader); err != nil { return err } - debugFile.Close() + if err := debugFile.Close(); err != nil { + return err + } obfuscationTime := header.ModTime.Local() diff --git a/main.go b/main.go index 63d85b2..cef2e83 100644 --- a/main.go +++ b/main.go @@ -738,7 +738,7 @@ func transformCompile(args []string) ([]string, error) { if err := obfSrcTarWriter.WriteHeader(&tar.Header{ Name: name, Mode: 0o755, - ModTime: time.Now(), // Need for restore obfuscation time + ModTime: time.Now(), // Need for restoring obfuscation time Size: int64(obfSrc.Len()), }); err != nil { return nil, err diff --git a/testdata/scripts/debugdir.txt b/testdata/scripts/debugdir.txt index 164d3ad..45dffaf 100644 --- a/testdata/scripts/debugdir.txt +++ b/testdata/scripts/debugdir.txt @@ -1,6 +1,4 @@ env GOPRIVATE=test/main -# Isolate go cache for test reproducibility -env GOCACHE=$WORK/.temp-cache garble -debugdir ./test1 build exists 'test1/test/main/imported/imported.go' 'test1/main/main.go' @@ -10,6 +8,7 @@ exists 'test1/test/main/imported/imported.go' 'test1/main/main.go' [short] stop +# Sources from previous builds should be deleted cp $WORK/test1/main/main.go $WORK/test1/some_file_from_prev_build.go garble -debugdir ./test1 build -v