From aa41b83964f6d267072c48e00b30090b88a56923 Mon Sep 17 00:00:00 2001 From: benny Date: Tue, 18 Jun 2024 18:33:24 +0300 Subject: [PATCH] extracting data from the exe files --- go.mod | 14 +++++++++++ main.go | 1 + packages.go | 68 +++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 66 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 5aa5e07..a3cf352 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,28 @@ module main go 1.22.3 require ( + github.com/barasher/go-exiftool v1.10.0 // indirect + github.com/dsoprea/go-exif v0.0.0-20230826092837-6579e82b732d // indirect + github.com/dsoprea/go-exif/v3 v3.0.1 // indirect + github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect + github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect github.com/dustin/go-humanize v1.0.1 // indirect + github.com/edsrzf/mmap-go v1.1.0 // indirect + github.com/go-errors/errors v1.4.2 // indirect + github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.22 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd // indirect + github.com/saferwall/pe v1.5.3 // indirect + github.com/secDre4mer/pkcs7 v0.0.0-20240322103146-665324a4461d // indirect + golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.7.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect modernc.org/libc v1.50.9 // indirect modernc.org/mathutil v1.6.0 // indirect diff --git a/main.go b/main.go index dfd0006..deebaab 100644 --- a/main.go +++ b/main.go @@ -261,6 +261,7 @@ func upload() http.Handler { fn,_:=os.OpenFile("Data/"+filename, os.O_CREATE, 0666) fn.Write(fileBytes) fn.Close() + getParamsFromExif("Data/"+filename) })} // index creates an HTTP handler that serves the main page with data from the database. diff --git a/packages.go b/packages.go index e15cfd5..5688d64 100644 --- a/packages.go +++ b/packages.go @@ -1,19 +1,27 @@ package main -import( +import ( "fmt" + "log" + "regexp" + "os" + "os/exec" "strconv" ) -type packages struct{ - Id string - Name string - Version string +// packages struct represents a package with its details. +type packages struct { + Id string + Name string + Version string ExtraCommand *string - Tag string - Warning bool - Element *elements + Tag string + Warning bool + Element *elements } + +// ConvertStringsToPackage converts a slice of strings to a packages struct. +// It returns an error if the input slice does not have exactly 6 elements or if the Warning value cannot be parsed as a boolean. func ConvertStringsToPackage(strs []string) (packages, error) { var pkg packages if len(strs) != 6 { @@ -34,18 +42,44 @@ func ConvertStringsToPackage(strs []string) (packages, error) { Warning: warning, }, nil } + +// elements struct represents the elements of a the webpage. type elements struct { - Title string - Header string - Help string - Packagename string + Title string + Header string + Help string + Packagename string Packageversion string - Allow string - Warning string - Explain string + Allow string + Warning string + Explain string } + +// DownloadElements struct represents the elements to be downloaded. type DownloadElements struct { - ID string + ID string Version *string Counter int -} \ No newline at end of file +} + +// Printer struct is an empty struct. Its purpose is not clear from the provided code. +type Printer struct{} + +// getParamsFromExif extracts EXIF parameters from a file at the given path using the exiftool command. +// It returns a map where the keys are the EXIF parameter names and the values are the corresponding EXIF parameter values. +func getParamsFromExif(path string) map[string]string{ + exiftool := os.Getenv("exiftool") + e,_ := exec.Command(exiftool, "-f", path).Output() + tags:=make(map[string]string) + spliter:=regexp.MustCompile(`\r?\n`) + crop:=spliter.Split(string(e),-1) + head := regexp.MustCompile(`\s+:\s`) + for _,c := range crop{ + if(len(c)>1){ + data:=head.Split(c,-1) + log.Println("My Raw Data: ", c) + tags[data[0]]=data[1]} + } + log.Println(tags) + return tags +}