summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/daaku/go.zipexe/zipexe.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-08-06 21:47:05 +0200
committerWim <wim@42.be>2018-08-06 21:47:05 +0200
commit51062863a5c34d81e296cf15c61140911037cf3b (patch)
tree9b5e044672486326c7a0ca8fb26430f37bf4d83c /vendor/github.com/daaku/go.zipexe/zipexe.go
parent4fb4b7aa6c02a54db8ad8dd98e4d321396926c0d (diff)
downloadmatterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.tar.gz
matterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.tar.bz2
matterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.zip
Use mod vendor for vendored directory (backwards compatible)
Diffstat (limited to 'vendor/github.com/daaku/go.zipexe/zipexe.go')
-rw-r--r--vendor/github.com/daaku/go.zipexe/zipexe.go142
1 files changed, 0 insertions, 142 deletions
diff --git a/vendor/github.com/daaku/go.zipexe/zipexe.go b/vendor/github.com/daaku/go.zipexe/zipexe.go
deleted file mode 100644
index 60046062..00000000
--- a/vendor/github.com/daaku/go.zipexe/zipexe.go
+++ /dev/null
@@ -1,142 +0,0 @@
-// Package zipexe attempts to open an executable binary file as a zip file.
-package zipexe
-
-import (
- "archive/zip"
- "debug/elf"
- "debug/macho"
- "debug/pe"
- "errors"
- "io"
- "os"
-)
-
-// Opens a zip file by path.
-func Open(path string) (*zip.Reader, error) {
- _, rd, err := OpenCloser(path)
- return rd, err
-}
-
-// OpenCloser is like Open but returns an additional Closer to avoid leaking open files.
-func OpenCloser(path string) (io.Closer, *zip.Reader, error) {
- file, err := os.Open(path)
- if err != nil {
- return nil, nil, err
- }
- finfo, err := file.Stat()
- if err != nil {
- return nil, nil, err
- }
- zr, err := NewReader(file, finfo.Size())
- if err != nil {
- return nil, nil, err
- }
- return file, zr, nil
-}
-
-// Open a zip file, specially handling various binaries that may have been
-// augmented with zip data.
-func NewReader(rda io.ReaderAt, size int64) (*zip.Reader, error) {
- handlers := []func(io.ReaderAt, int64) (*zip.Reader, error){
- zip.NewReader,
- zipExeReaderMacho,
- zipExeReaderElf,
- zipExeReaderPe,
- }
-
- for _, handler := range handlers {
- zfile, err := handler(rda, size)
- if err == nil {
- return zfile, nil
- }
- }
- return nil, errors.New("Couldn't Open As Executable")
-}
-
-// zipExeReaderMacho treats the file as a Mach-O binary
-// (Mac OS X / Darwin executable) and attempts to find a zip archive.
-func zipExeReaderMacho(rda io.ReaderAt, size int64) (*zip.Reader, error) {
- file, err := macho.NewFile(rda)
- if err != nil {
- return nil, err
- }
-
- var max int64
- for _, load := range file.Loads {
- seg, ok := load.(*macho.Segment)
- if ok {
- // Check if the segment contains a zip file
- if zfile, err := zip.NewReader(seg, int64(seg.Filesz)); err == nil {
- return zfile, nil
- }
-
- // Otherwise move end of file pointer
- end := int64(seg.Offset + seg.Filesz)
- if end > max {
- max = end
- }
- }
- }
-
- // No zip file within binary, try appended to end
- section := io.NewSectionReader(rda, max, size-max)
- return zip.NewReader(section, section.Size())
-}
-
-// zipExeReaderPe treats the file as a Portable Exectuable binary
-// (Windows executable) and attempts to find a zip archive.
-func zipExeReaderPe(rda io.ReaderAt, size int64) (*zip.Reader, error) {
- file, err := pe.NewFile(rda)
- if err != nil {
- return nil, err
- }
-
- var max int64
- for _, sec := range file.Sections {
- // Check if this section has a zip file
- if zfile, err := zip.NewReader(sec, int64(sec.Size)); err == nil {
- return zfile, nil
- }
-
- // Otherwise move end of file pointer
- end := int64(sec.Offset + sec.Size)
- if end > max {
- max = end
- }
- }
-
- // No zip file within binary, try appended to end
- section := io.NewSectionReader(rda, max, size-max)
- return zip.NewReader(section, section.Size())
-}
-
-// zipExeReaderElf treats the file as a ELF binary
-// (linux/BSD/etc... executable) and attempts to find a zip archive.
-func zipExeReaderElf(rda io.ReaderAt, size int64) (*zip.Reader, error) {
- file, err := elf.NewFile(rda)
- if err != nil {
- return nil, err
- }
-
- var max int64
- for _, sect := range file.Sections {
- if sect.Type == elf.SHT_NOBITS {
- continue
- }
-
- // Check if this section has a zip file
- if zfile, err := zip.NewReader(sect, int64(sect.Size)); err == nil {
- return zfile, nil
- }
-
- // Otherwise move end of file pointer
- end := int64(sect.Offset + sect.Size)
- if end > max {
- max = end
- }
- }
-
- // No zip file within binary, try appended to end
- section := io.NewSectionReader(rda, max, size-max)
- return zip.NewReader(section, section.Size())
-}