forked from hahwul/MobileHackersWeapons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-tool.go
214 lines (197 loc) · 6.71 KB
/
add-tool.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"golang.org/x/net/html"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
"strings"
)
/*
template
| [MobileHackersWeapons](https://github.com/hahwul/MobileHackersWeapons) | template | ![](https://img.shields.io/github/stars/hahwul/MobileHackersWeapons) | ![](https://img.shields.io/github/languages/top/hahwul/MobileHackersWeapons) | ![](https://img.shields.io/github/repo-size/hahwul/MobileHackersWeapons)<br>![](https://img.shields.io/github/license/hahwul/MobileHackersWeapons) <br> ![](https://img.shields.io/github/forks/hahwul/MobileHackersWeapons) <br> ![](https://img.shields.io/github/watchers/hahwul/MobileHackersWeapons) |
*/
type Tools struct {
Type, Data, Method, Description string
Install, Update map[string]string
}
func isTitleElement(n *html.Node) bool {
return n.Type == html.ElementNode && n.Data == "title"
}
func traverse(n *html.Node) (string, bool) {
if isTitleElement(n) {
return n.FirstChild.Data, true
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
result, ok := traverse(c)
if ok {
return result, ok
}
}
return "", false
}
func GetHtmlTitle(r io.Reader) (string, bool) {
doc, err := html.Parse(r)
if err != nil {
panic("Fail to parse html")
}
return traverse(doc)
}
func writeJSON(category, name, method, data, udesc string) {
jsonFile, err := os.Open("data.json")
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened data.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
var result map[string]interface{}
install := map[string]string{
"MacOS": "",
"Linux": "",
"Windows": "",
}
update := map[string]string{
"MacOS": "",
"Linux": "",
"Windows": "",
}
json.Unmarshal([]byte(byteValue), &result)
tool := Tools{
Type: category,
Data: data,
Method: method,
Description: udesc,
Install: install,
Update: update,
}
if result[name] != nil {
resultData := result[name].(map[string]interface{})
resultInstall := resultData["Install"].(map[string]interface{})
resultUpdate := resultData["Update"].(map[string]interface{})
tool.Install["MacOS"] = resultInstall["MacOS"].(string)
tool.Install["Linux"] = resultInstall["Linux"].(string)
tool.Install["Windows"] = resultInstall["Windows"].(string)
tool.Update["MacOS"] = resultUpdate["MacOS"].(string)
tool.Update["Linux"] = resultUpdate["Linux"].(string)
tool.Update["Windows"] = resultUpdate["Windows"].(string)
}
result[name] = tool
file, _ := json.MarshalIndent(result, "", " ")
_ = ioutil.WriteFile("data.json", file, 0644)
}
func main() {
repourl := flag.String("url", "", "any url")
first := flag.Bool("isFirst", false, "if you add new type, it use")
flag.Parse()
if flag.NFlag() == 0 {
flag.Usage()
return
}
u, err := url.Parse(*repourl)
if err != nil {
panic(err)
}
if u.Host == "github.com" {
//fmt.Println(u.Path)
name := strings.Split(u.Path, "/")[2]
//fmt.Println(name)
desc := "asdf"
resp, err := http.Get(*repourl)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if title, ok := GetHtmlTitle(resp.Body); ok {
if strings.Contains(string(title), ": ") {
desc = strings.Split(string(title), ": ")[1]
} else {
reader1 := bufio.NewReader(os.Stdin)
fmt.Println("[+] Don't have descriptions / input description")
a, _ := reader1.ReadString('\n')
desc = strings.TrimRight(a, "\r\n")
}
} else {
println("Fail to get HTML title")
}
typeFile, err := os.Open("type.lst")
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened type.lst")
// defer the closing of our jsonFile so that we can parse it later on
defer typeFile.Close()
index := 0
m := make(map[int]string)
reader := bufio.NewReader(typeFile)
for {
line, isPrefix, err := reader.ReadLine()
if isPrefix || err != nil {
break
}
m[index] = string(line)
fmt.Println("[" + strconv.Itoa(index) + "] " + string(line))
index = index + 1
}
var choicetype int
fmt.Println("[+] What is type?")
_, err = fmt.Scan(&choicetype)
fmt.Println(m[choicetype])
reader1 := bufio.NewReader(os.Stdin)
fmt.Println("[+] What is method (e.g. RE, Analysis, Scanner, .etc) ?")
method, _ := reader1.ReadString('\n')
method = strings.TrimRight(method, "\r\n")
writeJSON(m[choicetype], name, method, "| "+m[choicetype]+" | "+method+" | ["+name+"]("+*repourl+") | "+desc+" | ![](https://img.shields.io/github/stars"+u.Path+") | ![](https://img.shields.io/github/languages/top"+u.Path+") |", desc)
} else {
reader := bufio.NewReader(os.Stdin)
fmt.Println("[+] What is name?")
name, _ := reader.ReadString('\n')
name = strings.TrimRight(name, "\r\n")
fmt.Println("[+] Input Description?")
udesc, _ := reader.ReadString('\n')
udesc = strings.TrimRight(udesc, "\r\n")
typeFile, err := os.Open("type.lst")
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened type.lst")
// defer the closing of our jsonFile so that we can parse it later on
defer typeFile.Close()
index := 0
m := make(map[int]string)
readerF := bufio.NewReader(typeFile)
for {
line, isPrefix, err := readerF.ReadLine()
if isPrefix || err != nil {
break
}
m[index] = string(line)
fmt.Println("[" + strconv.Itoa(index) + "] " + string(line))
index = index + 1
}
var choicetype int
fmt.Println("What is type?")
_, err = fmt.Scan(&choicetype)
fmt.Println(m[choicetype])
reader1 := bufio.NewReader(os.Stdin)
fmt.Println("[+] What is method (e.g. RE, Analysis, Scanner, .etc) ?")
method, _ := reader1.ReadString('\n')
method = strings.TrimRight(method, "\r\n")
writeJSON(m[choicetype], name, method, "| "+m[choicetype]+" | "+method+" | ["+name+"]("+*repourl+") | "+udesc+"|![](https://img.shields.io/static/v1?label=&message=it's%20not%20github&color=gray)|![](https://img.shields.io/static/v1?label=&message=it's%20not%20github&color=gray)", udesc)
}
if *first {
fmt.Println("| Type | Name | Description | Popularity | Language |")
fmt.Println("| ---------- | :---------- | :----------: | :----------: | :----------: |")
}
//fmt.Println("| [" + name + "](" + *repourl + ") | " + desc + " | ![](https://img.shields.io/github/stars" + u.Path + ") | ![](https://img.shields.io/github/languages/top" + u.Path + ") | ![](https://img.shields.io/github/repo-size" + u.Path + ")<br>![](https://img.shields.io/github/license" + u.Path + ") <br> ![](https://img.shields.io/github/forks" + u.Path + ") <br> ![](https://img.shields.io/github/watchers" + u.Path + ") |")
}