/
defaults.go
142 lines (118 loc) · 4.34 KB
/
defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* NETCAP - Traffic Analysis Framework
* Copyright (c) 2017-2020 Philipp Mieden <dreadl0ck [at] protonmail [dot] ch>
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package transform
import (
"log"
"os/exec"
"runtime"
"strings"
)
// constant defaults
const (
// http content types.
octetStream = "application/octet-stream"
// darwin platform name.
platformDarwin = "darwin"
platformWindows = "windows"
platformLinux = "linux"
defaultDisasmCommandMacOS = "hopper"
)
// variable defaults - these can be changed during init depending on the detected platform
var (
// default macOS command to open files from maltego.
defaultOpenCommandDarwin = "open"
// default linux command to open files from maltego
// you could also set it to xdg-open.
defaultOpenCommandLinux = "gio"
defaultOpenTerminalCommandLinux = "gnome-terminal"
)
// update the default linux paths for specific OSes
func initTransformTool() {
if runtime.GOOS == platformLinux {
out, err := exec.Command("uname", "-a").CombinedOutput()
if err != nil {
log.Println(err)
return
}
if strings.Contains(string(out), "kali") {
// prefer codium over xdg-open
if path := findExecutable("codium", true); path != "" {
defaultOpenCommandLinux = path
} else {
// default to use xdg-open
defaultOpenCommandLinux = "xdg-open"
}
// kali uses qterminal
defaultOpenTerminalCommandLinux = "qterminal"
}
}
if runtime.GOOS == platformDarwin {
// use visual studio code to open files if its installed
if path := findExecutable("code", true); path != "" {
defaultOpenCommandDarwin = path
}
}
}
// adds arguments for different programs to the passed in arguments.
func makeLinuxOpenCommand(commandName string, args []string) (string, []string) { //nolint:gocritic //no named results because we want to reuse the values that have been passed in
// ensure that links are always opened with gio on linux
if strings.HasPrefix(args[0], "https://") || strings.HasPrefix(args[0], "http://") {
commandName = "gio"
}
if commandName == "gio" {
args = append([]string{"open"}, args...)
}
return commandName, args
}
// adds arguments for different programs to the passed in arguments.
func makeWindowsOpenCommand(args []string) (string, []string) { //nolint:gocritic //no named results because we want to reuse the values that have been passed in
return "cmd", append(
[]string{"/C"},
append(
[]string{"start"},
args...,
)...,
)
}
// adds arguments for different programs to the passed in arguments.
func makeDarwinOpenCommand(commandName string, args []string) (string, []string) { //nolint:gocritic //no named results because we want to reuse the values that have been passed in
// ensure that links are always opened with open on macOS, so the default browser will handle them
if strings.HasPrefix(args[0], "https://") || strings.HasPrefix(args[0], "http://") {
commandName = "open"
}
return commandName, args
}
// adjust the arguments for the linux command invocation
func makeLinuxOpenTerminalCommand(commandName string, args []string) (string, []string) { //nolint:gocritic //no named results because we want to reuse the values that have been passed in
// gnome-terminal
// xfce4-terminal
// mate-terminal
// etc...
// add the --working-directory= flag to set the path
if strings.HasSuffix(commandName, "-terminal") {
args = []string{"--working-directory=" + strings.Join(args, "")}
}
// qterminal is used in Kali Linux, use workdir flag
if commandName == "qterminal" {
args = []string{"--workdir=" + strings.Join(args, "")}
}
return commandName, args
}
// cmd.exe /K "cd /d H:\path\to\dir"
// note: /d allows to change drive letters
func makeWindowsOpenTerminalCommand(args []string) (string, []string) { //nolint:gocritic //no named results because we want to reuse the values that have been passed in
return "cmd", append(
[]string{"/K"},
"cd /d "+strings.Join(args, " "),
)
}