-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
113 lines (87 loc) · 2.21 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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/atotto/clipboard"
"github.com/esafirm/appdiff/zipper"
)
const (
InfoColor = "\033[1;34m%s\033[0m"
NoticeColor = "\033[1;36m%s\033[0m"
WarningColor = "\033[1;33m%s\033[0m"
ErrorColor = "\033[1;31m%s\033[0m"
DebugColor = "\033[0;36m%s\033[0m"
NewFile = "\033[1;33m[!] %s : New File!\033[0m\n"
Increase = "\033[1;33m[>] %s : %d => %d\033[0m\n"
Decrease = "\033[1;34m[<] %s : %d => %d\033[0m\n"
Same = "\033[1;36m[=] %s : %d => %d\033[0m\n"
)
func main() {
if len(os.Args) == 1 {
fmt.Println("usage: apkdiff <new_apk> <old_apk>")
return
}
firstApk := os.Args[1]
secondApk := os.Args[2]
firstDir, _ := ioutil.TempDir("", "apk")
secondDir, _ := ioutil.TempDir("", "apk")
err := unzip(firstApk, firstDir)
err = unzip(secondApk, secondDir)
if err != nil {
fmt.Println(err)
return
}
files, err := ioutil.ReadDir(firstDir)
if err != nil {
fmt.Println(err)
return
}
allData := make([]string, len(files))
fmt.Println("Comparing files…")
for index, f := range files {
var secondDirFileName = filepath.Join(secondDir, f.Name())
var secondFileInfo, err = os.Stat(secondDirFileName)
var secondSize = int64(0)
if err == nil {
secondSize = secondFileInfo.Size()
}
var name = f.Name()
var firstSize = f.Size()
allData[index] = fmt.Sprintf("%s, %d,, %s, %d, %d\n", name, firstSize, name, secondSize, firstSize-secondSize)
if err != nil {
fmt.Printf(NewFile, name)
continue
}
if firstSize > secondSize {
fmt.Printf(Increase, name, firstSize, secondSize)
} else if firstSize < secondSize {
fmt.Printf(Decrease, name, firstSize, secondSize)
} else {
fmt.Printf(Same, name, firstSize, secondSize)
}
}
copyToClipboard(allData)
}
func copyToClipboard(allData []string) {
var buffer bytes.Buffer
for _, data := range allData {
buffer.WriteString(data)
}
clipboard.WriteAll(buffer.String())
fmt.Println("\n\nAll data has been copied to clipboard!")
}
func unzip(path string, destDir string) error {
absPath, err := filepath.Abs(path)
if err != nil {
return err
}
_, err = zipper.Unzip(absPath, destDir)
if err != nil {
fmt.Println(err)
return err
}
return nil
}