Skip to content

Commit bfea504

Browse files
authored
feat(Scan): Password-protected files (#80)
1 parent 9f09802 commit bfea504

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

cmd/scan.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type fileScanner struct {
7777
printer *utils.Printer
7878
showInVT bool
7979
waitForCompletion bool
80+
password string
8081
}
8182

8283
func (s *fileScanner) Do(path interface{}, ds *utils.DoerState) string {
@@ -100,7 +101,13 @@ func (s *fileScanner) Do(path interface{}, ds *utils.DoerState) string {
100101
}
101102
defer f.Close()
102103

103-
analysis, err := s.scanner.ScanFile(f, progressCh)
104+
var analysis *vt.Object
105+
if s.password != "" {
106+
analysis, err = s.scanner.ScanFileWithParameters(
107+
f, progressCh, map[string]string{"password": s.password})
108+
} else {
109+
analysis, err = s.scanner.ScanFile(f, progressCh)
110+
}
104111
if err != nil {
105112
return err.Error()
106113
}
@@ -173,6 +180,7 @@ func NewScanFileCmd() *cobra.Command {
173180
scanner: client.NewFileScanner(),
174181
showInVT: viper.GetBool("open"),
175182
waitForCompletion: viper.GetBool("wait"),
183+
password: viper.GetString("password"),
176184
printer: p,
177185
cli: client}
178186
c.DoWithStringsFromReader(s, argReader)
@@ -182,6 +190,7 @@ func NewScanFileCmd() *cobra.Command {
182190

183191
addThreadsFlag(cmd.Flags())
184192
addOpenInVTFlag(cmd.Flags())
193+
addPasswordFlag(cmd.Flags())
185194
addWaitForCompletionFlag(cmd.Flags())
186195
addIncludeExcludeFlags(cmd.Flags())
187196
cmd.MarkZshCompPositionalArgumentFile(1)
@@ -308,3 +317,9 @@ func addWaitForCompletionFlag(flags *pflag.FlagSet) {
308317
"wait", "w", false,
309318
"Wait until the analysis is completed and show the analysis results")
310319
}
320+
321+
func addPasswordFlag(flags *pflag.FlagSet) {
322+
flags.StringP(
323+
"password", "p", "",
324+
"Password of the protected file")
325+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/VirusTotal/vt-cli
33
go 1.14
44

55
require (
6-
github.com/VirusTotal/vt-go v0.0.0-20220413144842-e010bf48aaee
6+
github.com/VirusTotal/vt-go v0.0.0-20230717142150-8431ff2cc00f
77
github.com/briandowns/spinner v1.7.0
88
github.com/cavaliercoder/grab v2.0.0+incompatible
99
github.com/dustin/go-humanize v1.0.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
1717
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
1818
github.com/VirusTotal/vt-go v0.0.0-20220413144842-e010bf48aaee h1:JDhi0dS8y9QLMJZA7ezLyXHxYaMlyzX6MDkq0SSc304=
1919
github.com/VirusTotal/vt-go v0.0.0-20220413144842-e010bf48aaee/go.mod h1:u1+HeRyl/gQs67eDgVEWNE7+x+zCyXhdtNVrRJR5YPE=
20+
github.com/VirusTotal/vt-go v0.0.0-20230717142150-8431ff2cc00f h1:49xl3zKS625gxmIRCfmwkXcTzB4cr4FcayRw/RcxhZs=
21+
github.com/VirusTotal/vt-go v0.0.0-20230717142150-8431ff2cc00f/go.mod h1:u1+HeRyl/gQs67eDgVEWNE7+x+zCyXhdtNVrRJR5YPE=
2022
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
2123
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
2224
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=

0 commit comments

Comments
 (0)