-
Notifications
You must be signed in to change notification settings - Fork 0
/
microPatcher.go
50 lines (44 loc) · 1.08 KB
/
microPatcher.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
package main
import (
"fmt"
"io/fs"
"math/big"
"os"
"regexp"
"strconv"
"strings"
)
func recursiveMicroPatchDir(name string) {
entries, _ := os.ReadDir(name)
for _, entry := range entries {
if entry.IsDir() {
recursiveMicroPatchDir(name + "/" + entry.Name())
} else {
microFilePatcher(name + "/" + entry.Name())
}
}
}
func microFilePatcher(name string) {
if !strings.HasSuffix(name, ".java") {
return
}
bytez, _ := os.ReadFile(name)
p0, _ := regexp.Compile("[^`0-9A-Za-z\\s{}\"<>.=?:();&,\\\\!'|+-@#$%^*\\]\\[_]")
content := string(bytez)
namePrint := true
for _, s := range strings.Split(content, "") {
if p0.Match([]byte(s)) {
if namePrint {
fmt.Println(name)
namePrint = false
}
char := string(p0.Find([]byte(s)))
charInt := strings.ReplaceAll(strings.ReplaceAll(strconv.QuoteToASCII(char), "\\u", ""), "\"", "")
n := new(big.Int)
n.SetString(charInt, 16)
fmt.Println(char, "->", n.Int64())
content = strings.ReplaceAll(content, "'"+char+"'", strconv.Itoa(int(n.Int64())))
os.WriteFile(name, []byte(content), fs.ModePerm)
}
}
}