-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
139 lines (122 loc) · 3.28 KB
/
main.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
package main
import (
"fmt"
"image"
"image/color"
"log"
"os"
"time"
"github.com/hedzr/cmdr"
)
const (
// APPNAME Name for app
APPNAME = "Puzzle - CTFTools"
// VERSION Version for app
VERSION = "0.0.1"
)
// ImageMatrixData - Image Matrix Data
type ImageMatrixData struct {
X, Y int
Name string
Img image.Image
Part string
Status bool
Data string
Buff []uint32
Up, Down []color.RGBA
Left, Right []color.RGBA
// RGB color.RGBA
}
// ImageMatrixRelation - Image Matrix Relation
type ImageMatrixRelation struct {
lImage *ImageMatrixData
rImage *ImageMatrixData
}
var (
reSize = uint(32)
flagMatrix []*ImageMatrixData
imgMatrix [][]*ImageMatrixData
// 碎片宽高
pWidth = 0
pHeight = 0
// 原图
imgSrc = ""
sWidth = 0
sHeight = 0
// 矩阵坐标
m = 0
n = 0
)
func main() {
root := cmdr.Root(APPNAME, VERSION).
Header("[$] Puzzle - Virink <[email protected]>").
Description("", "A tool for puzzle")
rootCmd := root.RootCommand()
// 字典处理
jigsawCmd := root.NewSubCommand().
Titles("j", "jigsaw").
Description("", "Jigsaw Puzzles").
Group("Jigsaw").
Action(func(cmd *cmdr.Command, args []string) (err error) {
jType := cmdr.GetInt("app.jigsaw.type", 1)
reSize = cmdr.GetUint("app.jigsaw.resize", 32)
source := cmdr.GetString("app.jigsaw.source")
part := cmdr.GetString("app.jigsaw.part")
output := cmdr.GetString("app.jigsaw.output")
extColor := cmdr.GetString("app.jigsaw.ext", "#fff")
if _, e := os.Stat(source); os.IsNotExist(e) {
log.Println("Source file is not exist!")
return
}
if _, e := os.Stat(part); os.IsNotExist(e) {
log.Println("Part of puzzles file is not exist!")
return
}
t := time.Now().UnixNano()
os.Remove(output)
log.Printf("[+] Source : %s\n", source)
log.Printf("[+] Part : %s\n", part)
log.Printf("[+] Output : %s\n", output)
log.Printf("[+] ExtColor : %s\n", extColor)
if jType == 1 {
puzzleDiffHash(source, part, output, extColor)
} else if jType == 2 {
// TODO: 无原图拼图,挖坑不填了
puzzleFit(source, part, output)
} else if jType == 3 {
puzzleHash(source, part, output)
} else if jType == 4 {
puzzleDiffRGB(source, part, output)
}
t = time.Now().UnixNano() - t
log.Println(fmt.Sprintf("[+] Success! And use %f s", float64(t)/1e9))
return
})
jigsawCmd.NewFlag(cmdr.OptFlagTypeInt).
Titles("r", "resize").
Description("resize", ``).
DefaultValue(8, "size")
jigsawCmd.NewFlag(cmdr.OptFlagTypeInt).
Titles("t", "type").
Description("1:DiffHash 2:- 3:Hash 4:DiffRGB", ``).
DefaultValue(1, "num")
jigsawCmd.NewFlag(cmdr.OptFlagTypeString).
Titles("s", "source").
Description("Read the source file (*.png)", ``).
DefaultValue("origin.png", "FILE")
jigsawCmd.NewFlag(cmdr.OptFlagTypeString).
Titles("o", "output").
Description("Write the output file (*.db)", ``).
DefaultValue("results.png", "FILE")
jigsawCmd.NewFlag(cmdr.OptFlagTypeBool).
Titles("p", "part").
Description("Part of puzzles file", ``).
DefaultValue("", "FILE")
jigsawCmd.NewFlag(cmdr.OptFlagTypeString).
Titles("e", "ext").
Description("Append ext block", ``).
DefaultValue("#fff", "color")
if err := cmdr.Exec(rootCmd); err != nil {
log.Println("[-]", err)
}
}